Sfoglia il codice sorgente

Merge branch 'feature-wcz' of lift-manager/lift-server into develop

wucizhong 5 anni fa
parent
commit
430f1581c4

+ 35 - 12
lift-business-service/src/main/java/cn/com/ty/lift/business/emergency/controller/EmergencyRepairController.java

@@ -20,6 +20,7 @@ import cn.com.ty.lift.business.evaluation.service.EvaluationService;
 import cn.com.ty.lift.common.utils.Judge;
 import cn.com.ty.lift.common.utils.Judger;
 import cn.com.xwy.boot.web.dto.RestResponse;
+import cn.hutool.core.collection.IterUtil;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -68,33 +69,55 @@ public class EmergencyRepairController {
         RepairResponse result = emergencyRepairService.selectByIdWithInfo(request);
 
         if(null != result){
-            //查询相关的急修费用
+            //急修费用
             result.setErRecordCosts(erRecordCostService.listByErRecordId(id));
             //急修图片
             result.setErRecordImgs(erRecordImgService.listByErRecordId(id));
             //评价
             result.setEvaluation(evaluationService.findByRecord(id));
             //故障信息
-            result.setFaultParts(fetchFault(result.getFaultPart()));
-            result.setFaultReasons(fetchFault(result.getFaultReason()));
-            result.setFaultNatures(fetchFault(result.getFaultNature()));
-            result.setFaultHandles(fetchFault(result.getFaultHandle()));
-            result.setFaultDuties(fetchFault(result.getFaultDuty()));
+            fillFault(result);
         }
         return RestResponse.success(result);
     }
 
     /**
-     * 把ids字符串拆分,查询出故障信息list
-     * @param idStr ids字符串
-     * @return Collection<LiftFault>
+     * 解析故障项id字符串,查询出相关的故障项
+     * @param result RepairResponse
      */
-    private Collection<LiftFault> fetchFault(String idStr){
+    private void fillFault(RepairResponse result){
+        List<Long> partIds = splitIds(result.getFaultPart());
+        List<Long> reasonIds = splitIds(result.getFaultReason());
+        List<Long> natureIds = splitIds(result.getFaultNature());
+        List<Long> handleIds = splitIds(result.getFaultHandle());
+        List<Long> dutyIds = splitIds(result.getFaultDuty());
+        List<Long> faultIds = new ArrayList<>();
+        faultIds.addAll(partIds);
+        faultIds.addAll(reasonIds);
+        faultIds.addAll(natureIds);
+        faultIds.addAll(handleIds);
+        faultIds.addAll(dutyIds);
+        Collection<LiftFault> liftFaults = liftFaultService.listByIds(faultIds);
+        if(IterUtil.isNotEmpty(liftFaults)){
+            result.setFaultParts(liftFaults.stream().filter(lf -> (partIds.contains(lf.getId()))).collect(Collectors.toList()));
+            result.setFaultReasons(liftFaults.stream().filter(lf -> (reasonIds.contains(lf.getId()))).collect(Collectors.toList()));
+            result.setFaultNatures(liftFaults.stream().filter(lf -> (natureIds.contains(lf.getId()))).collect(Collectors.toList()));
+            result.setFaultHandles(liftFaults.stream().filter(lf -> (handleIds.contains(lf.getId()))).collect(Collectors.toList()));
+            result.setFaultDuties(liftFaults.stream().filter(lf -> (dutyIds.contains(lf.getId()))).collect(Collectors.toList()));
+        }
+    }
+
+    /**
+     * 拆分故障项id字符串,组装成List<Long>
+     * @param idStr ids
+     * @return List<Long>
+     */
+    private List<Long> splitIds(String idStr){
         if(StrUtil.isEmpty(idStr)){
-            return null;
+            return Collections.EMPTY_LIST;
         }
         List<Long> ids = Arrays.asList(idStr.split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
-        return liftFaultService.listByIds(ids);
+        return ids;
     }
     /**
      * 新增急修

+ 12 - 5
lift-business-service/src/main/java/cn/com/ty/lift/business/framework/aspect/ControllerAspect.java

@@ -1,6 +1,5 @@
 package cn.com.ty.lift.business.framework.aspect;
 
-import cn.com.ty.lift.business.framework.BusinessBasicException;
 import cn.com.ty.lift.common.utils.Judge;
 import cn.com.ty.lift.common.utils.Judger;
 import cn.com.xwy.boot.web.dto.RestResponse;
@@ -36,6 +35,9 @@ public class ControllerAspect {
     private static final String classMethod = head + "CLASS_METHOD : ";
     private static final String args = head + "ARGS         : ";
     private static final String resp = head + "RESPONSE     : ";
+    private static final String exception = head + "EXCEPTION    : ";
+    private static final boolean printAll = false;
+    private static final int printLength = 1000;
 
     @Pointcut("execution(* cn.com.ty.lift.business.*.controller..*(..))")
     public void controllerPointCut() {
@@ -59,15 +61,20 @@ public class ControllerAspect {
     @AfterReturning(returning = "response", pointcut = "controllerPointCut()")
     public void doAfterReturning(RestResponse response) throws Throwable {
         // Processes the request and returns the content
-        log.info(resp + JSONUtil.parse(response));
+        String res = JSONUtil.toJsonPrettyStr(response);
+        if(!printAll && null != res){
+            int length = res.length();
+            res = length > printLength ? res.substring(0, printLength) + "\n... "+ (length - printLength) +" characters omitted." : res;
+        }
+        log.info(resp + "\n" + res);
         log.info(line);
     }
 
     @AfterThrowing(throwing = "ex", pointcut = "controllerPointCut()")
-    public void doAfterThrowing(BusinessBasicException ex) throws Throwable {
+    public void doAfterThrowing(Exception ex) throws Throwable {
         final String msg = ex.getMessage();
-        // Processes the request and returns the content
-        log.info(resp +  ex.addSuffix(msg).replace("()", ""));
+        // Processes the exception
+        log.error(exception + msg);
         log.info(line);
     }
 

+ 11 - 3
lift-enterprise-service/src/main/java/cn/com/ty/lift/enterprise/common/ControllerAspect.java

@@ -35,6 +35,9 @@ public class ControllerAspect {
     private static final String classMethod = head + "CLASS_METHOD : ";
     private static final String args = head + "ARGS         : ";
     private static final String resp = head + "RESPONSE     : ";
+    private static final String exception = head + "EXCEPTION    : ";
+    private static final boolean printAll = true;
+    private static final int printLength = 1000;
 
     @Pointcut("execution(* cn.com.ty.lift.enterprise.*.controller..*(..))")
     public void controllerPointCut() {
@@ -58,15 +61,20 @@ public class ControllerAspect {
     @AfterReturning(returning = "response", pointcut = "controllerPointCut()")
     public void doAfterReturning(RestResponse response) throws Throwable {
         // Processes the request and returns the content
-        log.info(resp + JSONUtil.parse(response));
+        String res = JSONUtil.toJsonPrettyStr(response);
+        if(!printAll && null != res){
+            int length = res.length();
+            res = length > printLength ? res.substring(0, printLength) + "\n... "+ (length - printLength) +" characters omitted." : res;
+        }
+        log.info(resp + "\n" + res);
         log.info(line);
     }
 
     @AfterThrowing(throwing = "ex", pointcut = "controllerPointCut()")
     public void doAfterThrowing(EnterpriseBasicException ex) throws Throwable {
         final String msg = ex.getMessage();
-        // Processes the request and returns the content
-        log.info(resp + ex.addSuffix(msg).replace("()", ""));
+        // Processes the exception
+        log.error(exception + msg);
         log.info(line);
     }