فهرست منبع

新增操作证时判断用户在数据库中是否已存在操作证,存在的话就批量更新操作证,不存在就新增操作证

wang-hai-cheng 4 سال پیش
والد
کامیت
3cc56d7eb2

+ 5 - 0
lift-common/src/main/java/cn.com.ty.lift.common/constants/ApiConstants.java

@@ -353,4 +353,9 @@ public class ApiConstants {
         int QUERY_REPAIR_EVALUATE_AUTH = 1;//查询急修评价权限
         int QUERY_MAINTENANCE_EVALUATE_AUTH = 2;//查询维保评价权限
     }
+
+    public interface LiftCertificate {
+        Integer NULL = 0;
+        Integer AUDIT = 1;
+    }
 }

+ 28 - 6
lift-enterprise-service/src/main/java/cn/com/ty/lift/enterprise/oa/controller/LiftCertificateController.java

@@ -1,5 +1,6 @@
 package cn.com.ty.lift.enterprise.oa.controller;
 
+import cn.com.ty.lift.common.constants.ApiConstants;
 import cn.com.ty.lift.common.model.CountPage;
 import cn.com.ty.lift.common.utils.ValuePool;
 import cn.com.ty.lift.common.verify.Val;
@@ -11,6 +12,7 @@ import cn.com.ty.lift.enterprise.oa.entity.LiftCertificate;
 import cn.com.ty.lift.enterprise.oa.service.LiftCertificateService;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -19,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
+import java.util.List;
 
 
 /**
@@ -117,14 +120,33 @@ public class LiftCertificateController {
     public RestResponse add(@Valid @RequestBody LiftCertificate entity) {
         Long ownerId = entity.getOwnerId();
         Long mtCompanyId = entity.getMtCompanyId();
-
-        int count = liftCertificateService.countByUserAndMtCompany(ownerId, mtCompanyId);
-        Validate.notTrue(count > 0, ValuePool.LIFT_CERT_HAD_EXIST);
-        entity.setStatus(1);
-
-        boolean result = liftCertificateService.saveOrUpdate(entity);
+//        int count = liftCertificateService.countByUserAndMtCompany(ownerId, mtCompanyId);
+        List<LiftCertificate> list = liftCertificateService.list(Wrappers.<LiftCertificate>lambdaQuery().
+                eq(LiftCertificate::getOwnerId, ownerId).
+                eq(LiftCertificate::getMtCompanyId, mtCompanyId).
+                ne(LiftCertificate::getStatus, ApiConstants.LiftCertificate.NULL));
+        boolean result;
+        if (list.size() > 0) {
+            log.debug("操作证数量大于0,批量更新操作证信息");
+            list.forEach(l -> {
+                l.setCode(entity.getCode());
+                l.setIssuanceAgency(entity.getIssuanceAgency());
+                l.setExpirationDate(entity.getExpirationDate());
+                l.setCertificateType(entity.getCertificateType());
+                l.setFirstImgUrl(entity.getFirstImgUrl());
+                l.setSecondImgUrl(entity.getSecondImgUrl());
+                l.setStatus(ApiConstants.LiftCertificate.AUDIT);
+            });
+            result = liftCertificateService.updateBatchById(list);
+        } else {
+            log.debug("没有操作证,设置操作证状态为待审核,保存操作证");
+            entity.setStatus(ApiConstants.LiftCertificate.AUDIT);
+            result = liftCertificateService.saveOrUpdate(entity);
+        }
+//        Validate.notTrue(list.size() > 0, ValuePool.LIFT_CERT_HAD_EXIST);
         return RestResponse.success(result);
 
+
     }
     @PostMapping("findByUser")
     @Validation(fields = {"ownerId","mtCompanyId"})