Browse Source

老项目恢复服务默认插入区域主管到project_user表

yang 4 years ago
parent
commit
f8876e1952

+ 9 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/library/dao/mapper/PlatformCompanyLiftRelevanceMapper.java

@@ -16,4 +16,13 @@ public interface PlatformCompanyLiftRelevanceMapper extends BaseMapper<PlatformC
     int countCapital(@Param("mtCompanyId") Long mtCompanyId, @Param("projectStatus") String projectStatus);
 
     int countForCompanyLiftRegistrationCode(Long companyId, String registrationCode);
+
+
+    /**
+     * 项目ID查询区域主管ID
+     *
+     * @param projectId
+     * @return
+     */
+    Long getRegionDirectorByProjectId(Long projectId);
 }

+ 47 - 5
lift-business-service/src/main/java/cn/com/ty/lift/business/library/service/PlatformCompanyLiftRelevanceService.java

@@ -9,13 +9,16 @@ import cn.com.ty.lift.business.maintenance.service.MaintenancePlanService;
 import cn.com.ty.lift.business.maintenance.service.MaintenanceService;
 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.ProjectUser;
 import cn.com.ty.lift.business.project.dao.entity.Region;
 import cn.com.ty.lift.business.project.dao.entity.model.request.ProjectRequest;
 import cn.com.ty.lift.business.project.dao.entity.model.response.ProjectDetailResponse;
 import cn.com.ty.lift.business.project.service.ProjectAppService;
 import cn.com.ty.lift.business.project.service.ProjectLiftRelevanceService;
 import cn.com.ty.lift.business.project.service.ProjectService;
+import cn.com.ty.lift.business.project.service.ProjectUserService;
 import cn.com.ty.lift.business.push.service.PushUserService;
+import cn.com.ty.lift.common.constants.ApiConstants;
 import cn.com.ty.lift.common.constants.CommonEnum;
 import cn.com.ty.lift.common.constants.WebSocketConstants;
 import cn.com.ty.lift.common.model.PushMessage;
@@ -69,6 +72,9 @@ public class PlatformCompanyLiftRelevanceService extends ServiceImpl<PlatformCom
     @Resource
     private ProjectAppService projectAppService;
 
+    @Resource
+    private ProjectUserService projectUserService;
+
 
     /**
      * @param id          电梯id
@@ -175,9 +181,19 @@ public class PlatformCompanyLiftRelevanceService extends ServiceImpl<PlatformCom
     public List<PlatformCompanyLiftRelevance> getCompanyLiftList(Long mtCompanyId, Long projectId) {
         //根据项目id和公司id查询电梯列表
         List<ProjectLiftRelevance> liftList = projectLiftRelevanceService.findLiftList(mtCompanyId, projectId);
-        Collection<Long> list = liftList.stream().map(ProjectLiftRelevance::getRelevanceId).collect(Collectors.toList());
-        if (CollUtil.isEmpty(list)) return new ArrayList<>();
-        return baseMapper.selectBatchIds(list);
+
+        List<Long> list = liftList.stream().map(ProjectLiftRelevance::getLiftId).collect(Collectors.toList());
+
+        //查询公司电梯关联和平台电梯关联
+        List<PlatformCompanyLiftRelevance> platformCompanyLiftRelevances = baseMapper.selectList(new QueryWrapper<PlatformCompanyLiftRelevance>()
+                .lambda()
+                .in(PlatformCompanyLiftRelevance::getLiftId, list)
+                .in(PlatformCompanyLiftRelevance::getMtCompanyId, new ArrayList<Long>() {{
+                    add(mtCompanyId);
+                    add(ApiConstants.PLATFORM_COMPANY_ID);
+                }}));
+
+        return platformCompanyLiftRelevances;
     }
 
     /**
@@ -274,6 +290,32 @@ public class PlatformCompanyLiftRelevanceService extends ServiceImpl<PlatformCom
                     //电梯状态设置为正常
                     resultList.forEach(entry -> entry.setLiftCompanyStatus(CommonEnum.LiftStatus.NORMAL.getCode()));
                     boolean ret = updateBatchById(resultList);
+
+                    //查询项目的默认区域主管  老项目恢复需要默认关联区域主管(project_user)
+                    Long regionDirectorId = baseMapper.getRegionDirectorByProjectId(projectId);
+                    if (Objects.isNull(regionDirectorId) || regionDirectorId == 0) {
+                        throw new RuntimeException("项目ID查询区域主管ID失败!");
+                    }
+                    //判断project_user 是否有这个人
+                    ProjectUser projectUser = projectUserService.getBaseMapper().selectOne(new QueryWrapper<ProjectUser>()
+                            .lambda()
+                            .eq(ProjectUser::getMtCompanyId, mtCompanyId)
+                            .eq(ProjectUser::getProjectId, projectId)
+                            .eq(ProjectUser::getUserId, regionDirectorId));
+
+                    if (Objects.isNull(projectUser)) {
+                        projectUser.setProjectId(projectId);
+                        projectUser.setIsMonitor("0");
+                        projectUser.setMtCompanyId(mtCompanyId);
+                        projectUser.setUserId(regionDirectorId);
+                        projectUser.setCreateDate(LocalDateTime.now());
+                        projectUser.setUserRole("REGION_DIRECTOR");
+
+                        if (projectUserService.getBaseMapper().insert(projectUser) != 1) {
+                            throw new RuntimeException("保存区域主管失败!");
+                        }
+                    }
+
                     if (!ret) {
                         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                         return RestResponse.fail(MessageUtils.get("msg.modify.batch.fail"));
@@ -358,7 +400,7 @@ public class PlatformCompanyLiftRelevanceService extends ServiceImpl<PlatformCom
             //解除维保工关联
             projectLiftRelevanceService.update(Wrappers.<ProjectLiftRelevance>update()
                     .set("worker_id", 0)
-                    .eq("mt_company_id",request.getMtCompanyId())
+                    .eq("mt_company_id", request.getMtCompanyId())
                     .eq("lift_id", request.getLiftId()));
         }
         return RestResponse.success(null, MessageUtils.get("msg.modify.success"));
@@ -394,7 +436,7 @@ public class PlatformCompanyLiftRelevanceService extends ServiceImpl<PlatformCom
         projectLiftRelevanceService.update(Wrappers.<ProjectLiftRelevance>update()
                 .set("worker_id", 0)
                 .in("lift_id", liftIds)
-                .eq("mt_company_id",request.getMtCompanyId()));
+                .eq("mt_company_id", request.getMtCompanyId()));
 
         if (!result) {
             return RestResponse.fail(MessageUtils.get("msg.modify.batch.fail"));

+ 11 - 0
lift-business-service/src/main/resources/mapper/lift/PlatformCompanyLiftRelevanceMapper.xml

@@ -35,4 +35,15 @@
 		where pclr.mt_company_id = #{companyId}
 		  and l.registration_code = #{registrationCode};
 	</select>
+
+
+	<select id="getRegionDirectorByProjectId" resultType="long" parameterType="long">
+		SELECT
+			r.user_id
+		FROM
+			project AS p
+		LEFT JOIN region AS r ON p.region_id = r.id
+		WHERE
+			p.id = #{projectId}
+	</select>
 </mapper>