Browse Source

app添加电梯 增加项目关联

别傲 5 years ago
parent
commit
6004f68d09

+ 9 - 8
lift-business-service/src/main/java/cn/com/ty/lift/business/library/service/LiftService.java

@@ -191,26 +191,26 @@ public class LiftService extends ServiceImpl<LiftMapper, Lift> {
     }
 
     /**
-     * @param id          电梯id
+     * @param liftId      电梯id
      * @param mtCompanyId 公司id
      * @return RestResponse 是否成功
      * @description 保存公司电梯关联数据、平台电梯关联数据
      * @date 2020/1/11 4:18 下午
      */
-    public RestResponse saveCompanyLiftInfo(Long id, Long mtCompanyId) {
+    public PlatformCompanyLiftRelevance saveCompanyLiftInfo(Long liftId, Long mtCompanyId) {
         //新增企业电梯关联表
-        PlatformCompanyLiftRelevance ret = platformService.save(id, mtCompanyId);
+        PlatformCompanyLiftRelevance ret = platformService.save(liftId, mtCompanyId);
         if (ObjectUtil.isEmpty(ret)) {
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-            return RestResponse.fail(MessageUtils.get("msg.add.fail"));
+            return null;
         }
         //新增平台电梯关联表
-        PlatformCompanyLiftRelevance liftRelevance = platformService.save(id, ApiConstants.PLATFORM_COMPANY_ID);
+        PlatformCompanyLiftRelevance liftRelevance = platformService.save(liftId, ApiConstants.PLATFORM_COMPANY_ID);
         if (ObjectUtil.isEmpty(liftRelevance)) {
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-            return RestResponse.fail(MessageUtils.get("msg.add.fail"));
+            return null;
         }
-        return RestResponse.success(null, MessageUtils.get("msg.add.success"));
+        return ret;
     }
 
 
@@ -328,7 +328,8 @@ public class LiftService extends ServiceImpl<LiftMapper, Lift> {
                     return RestResponse.fail(MessageUtils.get("msg.add.fail"));
                 }
                 //新增项目电梯关联表
-                ProjectLiftRelevance projectLiftRelevance = projectRelevanceService.save(request, companyLiftEntry.getId(), request.getWorkerId());
+                ProjectLiftRelevance projectLiftRelevance = projectRelevanceService
+                        .save(lift.getId(), request.getProjectId(), companyLiftEntry.getId(), request.getWorkerId(), request.getMtCompanyId());
                 if (Objects.isNull(projectLiftRelevance)) {
                     TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                     return RestResponse.fail(MessageUtils.get("msg.add.fail"));

+ 23 - 1
lift-business-service/src/main/java/cn/com/ty/lift/business/project/service/ProjectAppService.java

@@ -4,6 +4,7 @@ import cn.com.ty.lift.business.capital.dao.entity.model.request.CapitalRepairReq
 import cn.com.ty.lift.business.capital.dao.mapper.CapitalRepairLiftRelevanceMapper;
 import cn.com.ty.lift.business.framework.util.MessageUtils;
 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.maintenance.dao.entity.model.MaintenanceCount;
@@ -12,6 +13,7 @@ import cn.com.ty.lift.business.maintenance.dao.entity.model.response.Maintenance
 import cn.com.ty.lift.business.maintenance.dao.mapper.MaintenancePlanMapper;
 import cn.com.ty.lift.business.maintenance.dao.mapper.MaintenanceRecordMapper;
 import cn.com.ty.lift.business.project.dao.entity.Project;
+import cn.com.ty.lift.business.project.dao.entity.ProjectLiftRelevance;
 import cn.com.ty.lift.business.project.dao.entity.model.ProjectAppUser;
 import cn.com.ty.lift.business.project.dao.entity.model.request.ProjectRequest;
 import cn.com.ty.lift.business.project.dao.entity.model.response.ProjectCompanyResponse;
@@ -29,6 +31,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import javax.annotation.Resource;
 import java.time.LocalDate;
@@ -65,6 +68,9 @@ public class ProjectAppService extends ServiceImpl<ProjectMapper, Project> {
     @Resource
     private CapitalRepairLiftRelevanceMapper capitalRepairLiftRelevanceMapper;
 
+    @Resource
+    private ProjectLiftRelevanceService projectLiftRelevanceService;
+
     @Resource
     private RedisTemplate redisTemplate;
 
@@ -114,7 +120,23 @@ public class ProjectAppService extends ServiceImpl<ProjectMapper, Project> {
         if (!result) {
             return RestResponse.fail(MessageUtils.get("msg.add.fail"));
         }
-        return liftService.saveCompanyLiftInfo(lift.getId(), request.getMtCompanyId());
+        Long liftId = lift.getId();
+        Long mtCompanyId = request.getMtCompanyId();
+        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);
+        if (Objects.isNull(projectLiftRelevance)) {
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return RestResponse.fail(MessageUtils.get("msg.add.fail"));
+        }
+        //新增电梯发送消息
+        liftService.sendAddMessage(liftId, projectLiftRelevance.getProjectId(), mtCompanyId);
+        return RestResponse.success(MessageUtils.get("msg.add.success"));
     }
 
     /**

+ 7 - 6
lift-business-service/src/main/java/cn/com/ty/lift/business/project/service/ProjectLiftRelevanceService.java

@@ -98,22 +98,23 @@ public class ProjectLiftRelevanceService extends ServiceImpl<ProjectLiftRelevanc
     }
 
     /**
-     * @param request  电梯扩展请求
+     * @param liftId   电梯id
+     * @param projectId 项目id
      * @param id       平台企业电梯主键id
      * @param workerId 维保工id
+     * @param mtCompanyId 公司id
      * @return projectLiftEntry
      * @description 新增项目电梯关联数据
      * @date 2019/12/5 2:39 PM
      */
-    public ProjectLiftRelevance save(LiftExtensionRequest request, long id, long workerId) {
-        Lift lift = request.getLift();
+    public ProjectLiftRelevance save(Long liftId, Long projectId, Long id, Long workerId, Long mtCompanyId) {
         //新增项目电梯关联表
         ProjectLiftRelevance projectLiftEntry = new ProjectLiftRelevance();
-        projectLiftEntry.setProjectId(request.getProjectId());
-        projectLiftEntry.setLiftId(lift.getId());
+        projectLiftEntry.setProjectId(projectId);
+        projectLiftEntry.setLiftId(liftId);
         projectLiftEntry.setRelevanceId(id);
         projectLiftEntry.setWorkerId(workerId);
-        projectLiftEntry.setMtCompanyId(request.getMtCompanyId());
+        projectLiftEntry.setMtCompanyId(mtCompanyId);
         return save(projectLiftEntry) ? projectLiftEntry : null;
     }