Explorar o código

修复bug:app端电梯校验问题

别傲 %!s(int64=5) %!d(string=hai) anos
pai
achega
99a2fc9616

+ 40 - 11
lift-business-service/src/main/java/cn/com/ty/lift/business/project/service/ProjectAppService.java

@@ -7,6 +7,7 @@ import cn.com.ty.lift.business.library.dao.entity.Lift;
 import cn.com.ty.lift.business.library.dao.entity.PlatformCompanyLiftRelevance;
 import cn.com.ty.lift.business.library.dao.entity.model.request.LiftExtensionRequest;
 import cn.com.ty.lift.business.library.service.LiftService;
+import cn.com.ty.lift.business.library.service.PlatformCompanyLiftRelevanceService;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.MaintenanceCount;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceRecordRequest;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenanceAppResponse;
@@ -25,6 +26,7 @@ import cn.com.ty.lift.business.project.dao.mapper.ProjectMapper;
 import cn.com.ty.lift.business.project.dao.mapper.ProjectUserMapper;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
@@ -76,6 +78,9 @@ public class ProjectAppService extends ServiceImpl<ProjectMapper, Project> {
     @Resource
     private MaintenanceService maintenanceService;
 
+    @Resource
+    private PlatformCompanyLiftRelevanceService platformService;
+
     /**
      * @param request 公司id
      * @return RestResponse 项目列表
@@ -109,6 +114,27 @@ public class ProjectAppService extends ServiceImpl<ProjectMapper, Project> {
         return baseMapper.findListByProjectId(request.getPage(), request);
     }
 
+    /**
+     * @param mtCompanyId      公司id
+     * @param registrationCode 注册代码
+     * @return RestResponse 判断结果
+     * @description 新增电梯前置判断条件
+     * @date 2019/12/20 2:31 PM
+     */
+    public boolean preJudgment(Long mtCompanyId, String registrationCode) {
+        //查询电梯表是否有该电梯
+        Optional<Lift> lift = liftService.getOne(registrationCode, null);
+        Long liftId = lift.map(Lift::getId).orElse(null);
+        if (ObjectUtil.isNotEmpty(liftId)) {
+            Map<String, Object> paramMap = new HashMap<>(2);
+            paramMap.put("liftId", liftId);
+            paramMap.put("mtCompanyId", mtCompanyId);
+            //查询该公司下是否有此电梯
+            boolean result = platformService.findCompanyLiftExist(paramMap);
+            return !result;
+        } else return true;
+    }
+
     /**
      * @param request 新增电梯数据项
      * @return RestResponse 状态码和返回消息
@@ -117,13 +143,25 @@ public class ProjectAppService extends ServiceImpl<ProjectMapper, Project> {
      */
     @Transactional(rollbackFor = Exception.class)
     public RestResponse add(LiftExtensionRequest request) {
+        Long mtCompanyId = request.getMtCompanyId();
         Lift lift = request.getLift();
+        if (!preJudgment(mtCompanyId, lift.getRegistrationCode()))
+            return RestResponse.fail(MessageUtils.get("msg.lift.exist"));
+
         boolean result = liftService.save(lift);
         if (!result) {
             return RestResponse.fail(MessageUtils.get("msg.add.fail"));
         }
         Long liftId = lift.getId();
-        Long mtCompanyId = request.getMtCompanyId();
+        //判断当前公司台量是否大于企业设置的台量
+        if (!maintenanceService.judge(mtCompanyId))
+            return RestResponse.fail(MessageUtils.get("msg.limit.num"));
+
+        PlatformCompanyLiftRelevance companyLiftEntry = liftService.saveCompanyLiftInfo(liftId, mtCompanyId);
+        if (Objects.isNull(companyLiftEntry)) {
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return RestResponse.fail(MessageUtils.get("msg.add.fail"));
+        }
         Long projectId = request.getProjectId();
         Optional<Project> optional = projectService.getOne(projectId);
         int num = 0;
@@ -136,15 +174,6 @@ public class ProjectAppService extends ServiceImpl<ProjectMapper, Project> {
         if (currentNum >= num) {
             return RestResponse.fail(MessageUtils.get("msg.project.limit.num"));
         }
-        //判断当前公司台量是否大于企业设置的台量
-        if (!maintenanceService.judge(mtCompanyId))
-            return RestResponse.fail(MessageUtils.get("msg.limit.num"));
-
-        PlatformCompanyLiftRelevance companyLiftEntry = liftService.saveCompanyLiftInfo(liftId, mtCompanyId);
-        if (Objects.isNull(companyLiftEntry)) {
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-            return RestResponse.fail(MessageUtils.get("msg.add.fail"));
-        }
         //新增项目电梯关联表
         ProjectLiftRelevance projectLiftRelevance = projectLiftRelevanceService
                 .save(lift.getId(), request.getProjectId(), companyLiftEntry.getId(), request.getWorkerId(), mtCompanyId);
@@ -154,7 +183,7 @@ public class ProjectAppService extends ServiceImpl<ProjectMapper, Project> {
         }
         //新增电梯发送消息
         liftService.sendAddMessage(liftId, projectLiftRelevance.getProjectId(), mtCompanyId);
-        return RestResponse.success(MessageUtils.get("msg.add.success"));
+        return RestResponse.success(null, MessageUtils.get("msg.add.success"));
     }
 
     /**