ソースを参照

feat(care): 优化护理申请相关功能

- 新增护理申请默认状态设置
- 修改护理申请编辑逻辑,增加状态校验
- 优化护理申请查询条件,支持模糊匹配
- 添加 InstanceUtil 工具类,用于对象属性合并
lzm 3 ヶ月 前
コミット
358112e00a

+ 26 - 9
ruoyi-admin/src/main/java/com/ruoyi/web/controller/care/CareApplicationsController.java

@@ -6,6 +6,8 @@ import javax.servlet.http.HttpServletResponse;
 import com.ruoyi.care.domain.CareApplications;
 import com.ruoyi.care.service.ICareApplicationsService;
 import com.ruoyi.common.annotation.DataScope;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.bean.InstanceUtil;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -90,6 +92,16 @@ public class CareApplicationsController extends BaseController
             return AjaxResult.error("当前特困人员在该申请日期已有未完成的护理申请");
         }
         careApplications.setCreateBy(getUserId().toString());
+        //默认的状态
+        if(StringUtils.isBlank(careApplications.getDealStatus())){
+            careApplications.setDealStatus("no_start");
+        }
+        if(StringUtils.isBlank(careApplications.getStatus())){
+            careApplications.setStatus("no_check");
+        }
+        if(StringUtils.isBlank(careApplications.getPayStatus())){
+            careApplications.setPayStatus("dis_pay");
+        }
         return toAjax(careApplicationsService.insertCareApplications(careApplications));
     }
 
@@ -101,16 +113,21 @@ public class CareApplicationsController extends BaseController
     @PutMapping
     public AjaxResult edit(@RequestBody CareApplications careApplications)
     {
-        //判断当前申请日期是否有护理记录或正在进行的护理记录
-        CareApplications careApplications1=new CareApplications();
-        careApplications1.setPersonId(careApplications.getPersonId());
-        careApplications1.setApplyDate(careApplications.getApplyDate());
-        careApplications1.setNotDealStatus("complete");
-        List<CareApplications> lst=careApplicationsService.selectCareApplicationsList(careApplications1);
-        if(lst.size()>0){
-            return AjaxResult.error("当前特困人员在该申请日期已有未完成的护理申请");
+        //查询数据库的护理申请
+        if(StringUtils.isBlank(careApplications.getApplyId().toString())){
+            return AjaxResult.error("修改的数据未提交标识");
         }
-
+        CareApplications oldApp=careApplicationsService.selectCareApplicationsByApplyId(careApplications.getApplyId());
+        //判断数据这个护理申请是否在流程中或者已完成
+        if(!(oldApp.getStatus().equals("no_check") && oldApp.getDealStatus().equals("no_start"))){
+            return AjaxResult.error("当前这条数据已经在流程中,无法进行修改");
+        }
+        //旧数据和新数据进行数据合并
+       /* try {
+            careApplications = InstanceUtil.mergeDeviceProperties(careApplications, oldApp);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException(e);
+        }*/
         careApplications.setUpdateBy(getUserId().toString());
         return toAjax(careApplicationsService.updateCareApplications(careApplications));
     }

+ 92 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/bean/InstanceUtil.java

@@ -0,0 +1,92 @@
+package com.ruoyi.common.utils.bean;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+public class InstanceUtil {
+    public static List<String> types = new ArrayList<String>();
+    static {
+        types.add("java.lang.Integer");
+        types.add("java.lang.Double");
+        types.add("java.lang.Float");
+        types.add("java.lang.Long");
+        types.add("java.lang.Short");
+        types.add("java.lang.Byte");
+        types.add("java.lang.Boolean");
+        types.add("java.lang.Character");
+        types.add("java.lang.String");
+        types.add("int");
+        types.add("double");
+        types.add("long");
+        types.add("short");
+        types.add("byte");
+        types.add("boolean");
+        types.add("char");
+        types.add("float");
+    }
+    /**
+     * 利用反射合并两个实例类,将newProperties中的属性覆盖到preProperties,
+     * 如果newProperties中的属性为空,则保留preProperties中的属性
+     *
+     * 已经支持递归覆盖.对成员变量是Object的成员变量进行递归
+     * 如果成员变量是子类,还可以找它的父类向上覆盖
+     *
+     * @param preDeviceProperties 之前旧的实例属性
+     * @param newDeviceProperties 新的实例属性
+     * @param <T>                 返回合并后的实例属性
+     * @return
+     */
+    public static <T> T mergeDeviceProperties(T preDeviceProperties, T newDeviceProperties) throws IllegalAccessException {
+        if (preDeviceProperties == null) {
+            preDeviceProperties = newDeviceProperties;
+            return preDeviceProperties;
+        }
+        Class tClass = newDeviceProperties.getClass();
+        while (tClass != null) {
+            merge(preDeviceProperties, tClass.cast(newDeviceProperties));
+            tClass = tClass.getSuperclass();
+        }
+        return preDeviceProperties;
+    }
+    private static <T> T merge(T preDeviceProperties, T newDeviceProperties) throws IllegalAccessException {
+        Field[] preFileds = preDeviceProperties.getClass().getDeclaredFields();
+        Field[] newFileds = newDeviceProperties.getClass().getDeclaredFields();
+
+        for (int i = 0; i < preFileds.length; i++) {
+            Field preField = preFileds[i];
+            Field newField = preFileds[i];
+            if (Modifier.isStatic(newField.getModifiers())) {
+                continue;
+            }
+            Field targetField = newFileds[i];
+            if (Modifier.isStatic(targetField.getModifiers())) {
+                continue;
+            }
+
+            preField.setAccessible(true);
+            newField.setAccessible(true);
+
+            if(null != newField.get(newDeviceProperties)){
+                //如果成员变量是个数组,那么遍历数组的每个对象并进行递归合并
+                if(preField.getType().isArray()){
+                    int length = Array.getLength(preField.get(preDeviceProperties));
+                    for(int j=0;j<length;j++){
+                        Object preDeProperty = Array.get(preField.get(preDeviceProperties),j);
+                        Object newDeProperty = Array.get(newField.get(newDeviceProperties),j);
+                        mergeDeviceProperties(preDeProperty,newDeProperty);
+                    }
+                }
+                //如果成员变量不是基本数据类型或者包装类型,则进行递归遍历
+                else if (!types.contains(preField.getType().getName())) {
+                    mergeDeviceProperties(preField.get(preDeviceProperties), newField.get(newDeviceProperties));
+                } else {
+                    preField.set(preDeviceProperties, newField.get(newDeviceProperties));
+                }
+            }
+        }
+        return preDeviceProperties;
+    }
+}

+ 1 - 0
ruoyi-system/src/main/java/com/ruoyi/care/service/impl/CareApplicationsServiceImpl.java

@@ -195,6 +195,7 @@ public class CareApplicationsServiceImpl implements ICareApplicationsService
         careRecordsMapper.insertCareRecords(careRecords2);
 
         careApplications.setStatus("wait_check");
+        careApplications.setDealStatus("in_progress");
         careApplications.setUpdateTime(DateUtils.getNowDate());
         return careApplicationsMapper.updateCareApplications(careApplications);
     }

+ 11 - 1
ruoyi-system/src/main/resources/mapper/care/CareApplicationsMapper.xml

@@ -78,7 +78,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="address != null  and address != ''"> and a.address = #{address}</if>
             <if test="careDays != null  and careDays != ''"> and a.care_days = #{careDays}</if>
             <if test="applyDate != null  and applyDate != ''"> and a.apply_date = #{applyDate}</if>
-            <if test="status != null  and status != ''"> and a.status = #{status}</if>
+            <if test="status != null  and status != ''">
+             and
+             <choose>
+                 <when test="status.contains(','.toString())">
+                     LOCATE(a.status, #{status}) > 0
+                 </when>
+                 <otherwise>
+                     a.status = #{status}
+                 </otherwise>
+             </choose>
+            </if>
             <if test="dealStatus != null  and dealStatus != ''"> and a.deal_status = #{dealStatus}</if>
             <if test="NotDealStatus != null  and NotDealStatus != ''"> and ( a.deal_status =  #{NotDealStatus} or a.deal_status is null )</if>
             <if test="payStatus != null  and payStatus != ''"> and a.pay_status = #{payStatus}</if>

+ 1 - 1
ruoyi-vue/src/views/care/clocks/index.vue

@@ -123,7 +123,7 @@ const props = defineProps({
     required: true
   }
 });
-console.info("=="+props.applyId);
+console.info("=="+props.hasOwnProperty());
 const data = reactive({
   form: {},
   queryParams: {