Browse Source

[chg] 下次年检计划时间和上次时间比较验证

wcz 5 years ago
parent
commit
f0b99f3f72

+ 24 - 20
lift-business-service/src/main/java/cn/com/ty/lift/business/annualinspection/controller/AnnualInspectionController.java

@@ -36,6 +36,7 @@ import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.OutputStream;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
@@ -57,7 +58,9 @@ public class AnnualInspectionController {
     private AnnualInspectionService annualInspectionService;
     private LiftService             liftService;
 
-    private Map<String, String> headerAlias;
+    private Map<String, String>     headerAlias;
+    //最大年检间隔
+    private static final int inspection_interval = 365;
 
     @PostConstruct
     public void initHeaderAlias() {
@@ -135,6 +138,13 @@ public class AnnualInspectionController {
     public RestResponse confirm(@Ver @RequestBody AnnualInspection entity){
         long count = annualInspectionService.countConfirm(entity.getLiftId(), entity.getMtCompanyId(), entity.getPlanDate());
         Verify.nogt0(count, "年检计划已存在");
+
+        AnnualInspection current = annualInspectionService.findCurrentConfirm(entity.getLiftId(), entity.getMtCompanyId());
+        if(null != current){
+            LocalDate deadline = current.getPlanDate().plusDays(inspection_interval);
+            Verify.notTrue(deadline.isBefore(entity.getPlanDate()), "上次年检" + current.getPlanDate() + ",计划年检设置" + deadline + "之前有效");
+        }
+
         entity.setStatus(0);
         entity.setStepStatus(1);
         entity.setStepName(1);
@@ -177,7 +187,6 @@ public class AnnualInspectionController {
         old.setIsCheckGoverner(entity.getIsCheckGoverner());
         old.setLoadInspectionSetting(entity.getLoadInspectionSetting());
 
-        old.setStatus(0);
         old.setStepStatus(1);
         old.setStepName(1);
         boolean ai = annualInspectionService.saveOrUpdate(old);
@@ -196,7 +205,7 @@ public class AnnualInspectionController {
         Integer oldStepName = old.getStepName();
         Integer oldStepStatus = old.getStepStatus();
         Integer stepStatus = entity.getStepStatus();
-        Verify.isTrue(oldStepName == 1, "请进行第一阶段操作");
+        Verify.isTrue(oldStepName == 1, "请先完成确认操作再进行第一阶段");
         Verify.isTrue(oldStepStatus == 1 || oldStepStatus == 2, "请进行第一阶段操作");
         Verify.isTrue(stepStatus == 2, "请进行第一阶段操作");
 
@@ -204,7 +213,6 @@ public class AnnualInspectionController {
         old.setSelfcheckDate(entity.getSelfcheckDate());
         old.setStepStatus(entity.getStepStatus());
 
-        old.setStatus(0);
         old.setStepName(2);//流转到阶段2
 
         boolean ai = annualInspectionService.saveOrUpdate(old);
@@ -222,7 +230,7 @@ public class AnnualInspectionController {
         Verify.notNull(old, Verify.Inspection.confirm);
         Integer oldStepName = old.getStepName();
         Integer oldStepStatus = old.getStepStatus();
-        Verify.isTrue(oldStepName == 1 || oldStepName == 2, "请进行第二阶段操作");
+        Verify.isTrue(oldStepName == 1 || oldStepName == 2, "请先完成第一阶段再进行第二阶段");
         Verify.isTrue(oldStepStatus == 2 || oldStepStatus == 3, "请进行第二阶段操作");
 
         old.setCheckDate(entity.getCheckDate());
@@ -230,7 +238,6 @@ public class AnnualInspectionController {
         old.setOperator(entity.getOperator());
         old.setTelephone(entity.getTelephone());
 
-        old.setStatus(0);
         old.setStepStatus(3);
         old.setStepName(3);//流转到阶段3
 
@@ -254,23 +261,25 @@ public class AnnualInspectionController {
         Integer oldStepName = old.getStepName();
         Integer oldStepStatus = old.getStepStatus();
         Integer stepStatus = entity.getStepStatus();
-        Verify.isTrue(oldStepName == 2 || oldStepName == 3, "请进行第三阶段操作");
+        Verify.isTrue(oldStepName == 2 || oldStepName == 3, "请先完成第二阶段再进行第三阶段");
         Verify.isTrue(oldStepStatus >= 3 && oldStepStatus <= 7, "请进行第三阶段操作");
         Verify.isTrue(stepStatus >= 4 && stepStatus <= 7, "请进行第三阶段操作");
 
-        old.setCheckResultImg(entity.getCheckResultImg());
+        LocalDate deadline = old.getPlanDate().plusDays(inspection_interval);
+        Verify.notTrue(deadline.isBefore(entity.getNextInspectionTime()), "上次年检" + old.getPlanDate() + ",下次年检设置" + deadline + "之前有效");
+
         old.setStepStatus(entity.getStepStatus());
+        old.setCheckResultImg(entity.getCheckResultImg());
         old.setNextInspectionTime(entity.getNextInspectionTime());
 
-        old.setStatus(0);
         //企业文员确认检验结果-整改 --> 回到第二阶段
-        if(stepStatus == 4) {
-            old.setStepName(3);
-        }else if(stepStatus == 5 || stepStatus == 7){
+        if(stepStatus == 5 || stepStatus == 7){
             old.setStepName(4);//流转到阶段4
         } else if(stepStatus == 6){
             old.setStepStatus(3);
             old.setStepName(2);//转回阶段2
+            old.setCheckResultImg(null);
+            old.setNextInspectionTime(null);
         }
         return annualInspectionService.stepThree(old, entity.getProjectId(), entity.getIsCheckGoverner(), entity.getLoadInspectionSetting());
     }
@@ -288,7 +297,7 @@ public class AnnualInspectionController {
         Integer oldStepName = old.getStepName();
         Integer oldStepStatus = old.getStepStatus();
         Integer stepStatus = entity.getStepStatus();
-        Verify.isTrue(oldStepName == 3 || oldStepName == 4, "请进行第三阶段操作");
+        Verify.isTrue(oldStepName == 3 || oldStepName == 4, "请先完成第三阶段再进行第四阶段");
         Verify.isTrue(oldStepStatus >= 5 && oldStepStatus <= 10, "请进行第四阶段操作");
         Verify.isTrue(stepStatus >= 8 && stepStatus <= 10, "请进行第四阶段操作");
 
@@ -296,19 +305,14 @@ public class AnnualInspectionController {
         old.setAnnualInspectionImg(entity.getAnnualInspectionImg());
         old.setCertificateImgUrl(entity.getCertificateImgUrl());
 
-
-        if(stepStatus == 8){
-            old.setStatus(0);//未完成
-        } else if(stepStatus == 9){
+        if(stepStatus == 9){
             old.setStatus(1);//已完成
+            old.setFinishTime(LocalDateTime.now());
         } else if(stepStatus == 10){
             old.setStatus(2);//超期
-        }
-        if(stepStatus == 9 || stepStatus == 10){
             old.setFinishTime(LocalDateTime.now());
         }
         old.setStepName(4);
-
         return annualInspectionService.stepFour(old);
     }
     /**

+ 6 - 4
lift-business-service/src/main/java/cn/com/ty/lift/business/annualinspection/entity/AnnualInspection.java

@@ -6,6 +6,7 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
+import javax.validation.constraints.FutureOrPresent;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import javax.validation.constraints.NotNull;
@@ -34,34 +35,35 @@ public class AnnualInspection extends BaseEntity {
      * 电梯ID
      */
     @NotNull(message = "电梯不能为空")
-    @Min(value = 1,message = "电梯有误")
+    @Min(value = 1,message = "电梯ID有误")
     private Long liftId;
 
     /**
      * 公司ID
      */
     @NotNull(message = "维保公司不能为空")
-    @Min(value = 1,message = "维保公司有误")
+    @Min(value = 1,message = "维保公司ID有误")
     private Long mtCompanyId;
 
     /**
      * 计划年检时间
      */
     @NotNull(message = "计划年检时间不能为空")
+    @FutureOrPresent(message = "计划年检时间不得晚于标准北京时间")
     private LocalDate planDate;
 
     /**
      * 是否检查限速器(0 否;1 是;默认0)
      */
     @NotNull(message = "请设置是否检查限速器")
-    @Max(value = 1,message = "是否检查限速器有误")
+    @Max(value = 1,message = "检查限速器设置值有误")
     private Integer isCheckGoverner;
 
     /**
      * 是否荷载年检设置(0 否;1 是;默认0)
      */
     @NotNull(message = "请设置是否荷载年检设置")
-    @Max(value = 1, message = "荷载年检设置有误")
+    @Max(value = 1, message = "荷载年检设置有误")
     private Integer loadInspectionSetting;
 
     /**

+ 23 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/annualinspection/service/AnnualInspectionService.java

@@ -94,6 +94,13 @@ public class AnnualInspectionService extends ServiceImpl<AnnualInspectionMapper,
         return baseMapper.pageByLift(request.getPage(), request);
     }
 
+    /**
+     * 根据电梯,维保公司和计划年检日期查询年检记录
+     * @param liftId 电梯
+     * @param mtCompanyId 维保公司
+     * @param planDate 计划年检日期
+     * @return long
+     */
     public long countConfirm(Long liftId, Long mtCompanyId, LocalDate planDate) {
         LambdaQueryWrapper<AnnualInspection> lambdaQueryWrapper = Wrappers
                 .<AnnualInspection>lambdaQuery()
@@ -103,6 +110,22 @@ public class AnnualInspectionService extends ServiceImpl<AnnualInspectionMapper,
         return count(lambdaQueryWrapper);
     }
 
+    /**
+     * 根据电梯和维保公司查询最近的一次年检记录
+     * @param liftId 电梯
+     * @param mtCompanyId 维保公司
+     * @return AnnualInspection
+     */
+    public AnnualInspection findCurrentConfirm(Long liftId, Long mtCompanyId){
+        LambdaQueryWrapper<AnnualInspection> lambdaQueryWrapper = Wrappers
+                .<AnnualInspection>lambdaQuery()
+                .eq(AnnualInspection::getLiftId, liftId)
+                .eq(AnnualInspection::getMtCompanyId, mtCompanyId)
+                .orderByDesc(AnnualInspection::getPlanDate)
+                .last("LIMIT 1");
+        return getOne(lambdaQueryWrapper);
+    }
+
     private void rollback(){
         //强制手动事务回滚
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();

+ 3 - 15
lift-common/src/main/java/cn.com.ty.lift.common/verify/Verification.java

@@ -1739,16 +1739,6 @@ public class Verification {
             }
         }
     }
-
-    /**
-     * the prefix string of the log.
-     */
-    private String logPrefix = "###| ";
-    /**
-     * the line string of the log.
-     */
-    private String logLine = "============================================================";
-
     /**
      * the format of the {@code info} level log.
      *
@@ -1759,11 +1749,9 @@ public class Verification {
      * @param result     the result of invoke the method.
      */
     private void info(Field verifyField, Object value, MethodHandle methodHandle) {
-        log.info(logLine);
-        log.info("{}FIELD       : {}", logPrefix, verifyField);
-        log.info("{}FIELD_VALUE : {}", logPrefix, value);
-        log.info("{}METHOD      : (false) {}", logPrefix, methodHandle);
-        log.info(logLine);
+        log.info("###| FIELD       : {}", verifyField);
+        log.info("###| FIELD_VALUE : {}", value);
+        log.info("###| METHOD      : (false) {}", methodHandle);
     }
 
     /**