Przeglądaj źródła

新增电梯、生成、修改维保计划 消息推送

别傲 5 lat temu
rodzic
commit
fed17d5fb8

+ 15 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/capital/dao/mapper/CommonMapper.java

@@ -0,0 +1,15 @@
+package cn.com.ty.lift.business.capital.dao.mapper;
+
+
+import org.apache.ibatis.annotations.Select;
+
+/**
+ * @author bieao
+ * @date 2020/2/5
+ * @description
+ */
+public interface CommonMapper {
+
+    @Select("select name from user_info where user_id = #{userId}")
+    String queryUserNameById(Long userId);
+}

+ 108 - 2
lift-business-service/src/main/java/cn/com/ty/lift/business/library/service/LiftService.java

@@ -1,5 +1,6 @@
 package cn.com.ty.lift.business.library.service;
 
+import cn.com.ty.lift.business.capital.dao.mapper.CommonMapper;
 import cn.com.ty.lift.business.capital.service.CapitalRepairLiftRelevanceService;
 import cn.com.ty.lift.business.framework.util.MessageUtils;
 import cn.com.ty.lift.business.library.dao.entity.Lift;
@@ -14,13 +15,20 @@ import cn.com.ty.lift.business.library.dao.entity.model.response.LiftResponse;
 import cn.com.ty.lift.business.library.dao.mapper.LiftMapper;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.response.LiftPrintResponse;
 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.Region;
 import cn.com.ty.lift.business.project.service.ProjectLiftRelevanceService;
+import cn.com.ty.lift.business.project.service.ProjectService;
+import cn.com.ty.lift.business.push.service.PushUserService;
 import cn.com.ty.lift.common.base.ExportRequest;
 import cn.com.ty.lift.common.constants.ApiConstants;
 import cn.com.ty.lift.common.constants.CommonEnum;
 import cn.com.ty.lift.common.export.ExportUtils;
+import cn.com.ty.lift.common.model.PushMessage;
+import cn.com.ty.lift.common.model.PushUserInfo;
 import cn.com.ty.lift.common.utils.DateUtils;
+import cn.com.ty.lift.common.utils.SendMessageUtil;
 import cn.com.ty.lift.common.verify.Validate;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import cn.hutool.core.bean.BeanUtil;
@@ -34,6 +42,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.jms.core.JmsMessagingTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
@@ -69,6 +78,18 @@ public class LiftService extends ServiceImpl<LiftMapper, Lift> {
     @Resource
     private LiftHistoryService liftHistoryService;
 
+    @Resource
+    private ProjectService projectService;
+
+    @Resource
+    private PushUserService pushUserService;
+
+    @Resource
+    private JmsMessagingTemplate jmsMessagingTemplate;
+
+    @Resource
+    private CommonMapper commonMapper;
+
     private Map<String, String> paramMap = new HashMap<String, String>() {{
         put("liftCode", "电梯号");
         put("registrationCode", "注册代码");
@@ -187,6 +208,45 @@ public class LiftService extends ServiceImpl<LiftMapper, Lift> {
         return RestResponse.success(null, MessageUtils.get("msg.add.success"));
     }
 
+
+    /**
+     * @param liftId 电梯ID
+     * @param mtCompanyId 公司ID
+     * @return
+     * @description 新增电梯消息推送
+     * @date 2020/5/5 9:26 下午
+     */
+    public void sendAddMessage(Long liftId, Long projectId, Long mtCompanyId) {
+        //消息推送
+        List<Long> userIds = new ArrayList<>();
+        Region region = pushUserService.findRegionByProject(projectId, mtCompanyId);
+        if (Objects.nonNull(region)) {
+            userIds.addAll(region.members());
+        }
+        List<PushUserInfo> director = pushUserService.listEnterpriseAdmin(mtCompanyId);
+        List<PushUserInfo> pushUserInfos = new ArrayList<>(director);
+        if (!userIds.isEmpty()) {
+            List<PushUserInfo> userInfos = pushUserService.listByUserIds(mtCompanyId, userIds);
+            pushUserInfos.addAll(userInfos);
+        }
+        if (!pushUserInfos.isEmpty()) {
+            Optional<Project> project = projectService.getOne(projectId);
+            if (project.isPresent()) {
+                Project p = project.get();
+                String projectName = p.getProjectName();
+                Optional<Lift> lift = getOne(null, liftId);
+                lift.ifPresent(l -> {
+                    String creatorName = commonMapper.queryUserNameById(l.getCreatorId());
+                    PushMessage pushMessage = PushMessage.workCreateLift(creatorName, projectName, l.getDevicePosition(), l.getRegistrationCode());
+                    pushMessage.sendTokenOnPlatform(jmsMessagingTemplate, pushUserInfos);
+                    List<Long> sendToUserIdList = pushUserInfos.stream().map(PushUserInfo::getUserId).collect(Collectors.toList());
+                    //推送pc端
+                    SendMessageUtil.sendMessageToPC(jmsMessagingTemplate, sendToUserIdList, pushMessage.getContent());
+                });
+            }
+        }
+    }
+
     /**
      * @param request 新增电梯数据项
      * @return RestResponse 状态码和返回消息
@@ -245,11 +305,13 @@ public class LiftService extends ServiceImpl<LiftMapper, Lift> {
                     return RestResponse.fail(MessageUtils.get("msg.add.fail"));
                 }
                 //新增项目电梯关联表
-                boolean result = projectRelevanceService.save(request, companyLiftEntry.getId(), request.getWorkerId());
-                if (!result) {
+                ProjectLiftRelevance projectLiftRelevance = projectRelevanceService.save(request, companyLiftEntry.getId(), request.getWorkerId());
+                if (Objects.isNull(projectLiftRelevance)) {
                     TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                     return RestResponse.fail(MessageUtils.get("msg.add.fail"));
                 }
+                //新增电梯发送消息
+                sendAddMessage(id, projectLiftRelevance.getProjectId(), mtCompanyId);
                 break;
             //大修管理入口
             case "2":
@@ -266,6 +328,44 @@ public class LiftService extends ServiceImpl<LiftMapper, Lift> {
         return RestResponse.success(null, MessageUtils.get("msg.add.success"));
     }
 
+    /**
+     * @param projectId 项目ID
+     * @param mtCompanyId 公司ID
+     * @return
+     * @description 更新电梯位置消息推送
+     * @date 2020/5/5 9:26 下午
+     */
+    public void sendModifyMessage(Long liftId, Long projectId, Long mtCompanyId, String devicePosition, String newDevicePosition) {
+        //消息推送
+        List<Long> userIds = new ArrayList<>();
+        Region region = pushUserService.findRegionByProject(projectId, mtCompanyId);
+        if (Objects.nonNull(region)) {
+            userIds.addAll(region.members());
+        }
+        List<PushUserInfo> director = pushUserService.listEnterpriseAdmin(mtCompanyId);
+        List<PushUserInfo> pushUserInfos = new ArrayList<>(director);
+        if (!userIds.isEmpty()) {
+            List<PushUserInfo> userInfos = pushUserService.listByUserIds(mtCompanyId, userIds);
+            pushUserInfos.addAll(userInfos);
+        }
+        if (!pushUserInfos.isEmpty()) {
+            Optional<Project> project = projectService.getOne(projectId);
+            if (project.isPresent()) {
+                Project p = project.get();
+                String projectName = p.getProjectName();
+                Optional<Lift> lift = getOne(null, liftId);
+                lift.ifPresent(l -> {
+                    String updateName = commonMapper.queryUserNameById(l.getUpdateId());
+                    PushMessage pushMessage = PushMessage.workModifyLiftPosition(updateName, projectName, devicePosition, newDevicePosition, l.getRegistrationCode());
+                    pushMessage.sendTokenOnPlatform(jmsMessagingTemplate, pushUserInfos);
+                    List<Long> sendToUserIdList = pushUserInfos.stream().map(PushUserInfo::getUserId).collect(Collectors.toList());
+                    //推送pc端
+                    SendMessageUtil.sendMessageToPC(jmsMessagingTemplate, sendToUserIdList, pushMessage.getContent());
+                });
+            }
+        }
+    }
+
     /**
      * @param request 修改电梯数据项
      * @return RestResponse 状态码和返回消息
@@ -283,6 +383,12 @@ public class LiftService extends ServiceImpl<LiftMapper, Lift> {
             return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
 
         Lift entry = oldLift.get();
+        String devicePosition = entry.getDevicePosition();
+        String newDevicePosition = lift.getDevicePosition();
+        if (!Objects.equals(devicePosition, newDevicePosition)) {
+            //更新电梯定位发送推送消息
+            sendModifyMessage(lift.getId(), request.getProjectId(), request.getMtCompanyId(), devicePosition, newDevicePosition);
+        }
         //生成电梯操作记录
         LiftHistory history = liftHistoryService.createOperaHistory(entry, lift, request.getMtCompanyId());
         if (Objects.nonNull(history)) {

+ 123 - 6
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/service/MaintenancePlanService.java

@@ -1,9 +1,12 @@
 package cn.com.ty.lift.business.maintenance.service;
 
+import cn.com.ty.lift.business.capital.dao.mapper.CommonMapper;
 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.service.LiftService;
 import cn.com.ty.lift.business.maintenance.dao.entity.MaintenancePlan;
-import cn.com.ty.lift.business.maintenance.dao.entity.model.request.*;
+import cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenancePlanRequest;
+import cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtPlanRequest;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.response.LiftPrintResponse;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenancePlanPrintResponse;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenancePlanResponse;
@@ -11,10 +14,16 @@ import cn.com.ty.lift.business.maintenance.dao.entity.model.response.MtPlanRespo
 import cn.com.ty.lift.business.maintenance.dao.mapper.MaintenancePlanMapper;
 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.Region;
+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.push.service.PushUserService;
 import cn.com.ty.lift.common.base.ExportRequest;
 import cn.com.ty.lift.common.export.ExportUtils;
+import cn.com.ty.lift.common.model.PushMessage;
+import cn.com.ty.lift.common.model.PushUserInfo;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -24,6 +33,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.jms.core.JmsMessagingTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -49,9 +59,21 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
     @Resource
     private LiftService liftService;
 
+    @Resource
+    private CommonMapper commonMapper;
+
     @Resource
     private ProjectLiftRelevanceService projectLiftRelevanceService;
 
+    @Resource
+    private ProjectAppService projectAppService;
+
+    @Resource
+    private JmsMessagingTemplate jmsMessagingTemplate;
+
+    @Resource
+    private PushUserService pushUserService;
+
     private Map<String, String> paramMap = new HashMap<String, String>() {{
         put("projectCode", "项目编号");
         put("projectName", "项目名称");
@@ -119,6 +141,78 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
         return Optional.ofNullable(getOne(lambdaQueryWrapper)).orElse(null);
     }
 
+    /**
+     * @param liftId 电梯ID
+     * @param projectId 项目ID
+     * @param mtCompanyId 公司ID
+     * @param interval 保养间隔
+     * @param planDate 保养时间
+     * @param type 保养类型
+     * @param liftCharge 电梯负责人
+     * @param operator 操作人
+     * @return
+     * @description 生成保养计划消息推送
+     * @date 2020/5/5 9:26 下午
+     */
+    public void sendCreateMessage(Long liftId, Long projectId, Long mtCompanyId, int interval, LocalDate planDate, int type, String liftCharge, String operator, Long workerId) {
+        //消息推送
+        List<Long> userIds = new ArrayList<>();
+        Region region = pushUserService.findRegionByProject(projectId, mtCompanyId);
+        if (Objects.nonNull(region)) {
+            userIds.addAll(region.members());
+        }
+        userIds.add(workerId);
+        List<PushUserInfo> pushUserInfos = new ArrayList<>();
+        if (!userIds.isEmpty()) {
+            List<PushUserInfo> userInfos = pushUserService.listByUserIds(mtCompanyId, userIds);
+            pushUserInfos.addAll(userInfos);
+        }
+        if (!pushUserInfos.isEmpty()) {
+            ProjectDetailResponse detail = projectAppService.detail(projectId);
+            Optional<Lift> lift = liftService.getOne(null, liftId);
+            lift.ifPresent(l ->
+                PushMessage.maintainCreatePlan(detail.getAreaName(), detail.getProjectName(), l.getDevicePosition(),
+                        l.getRegistrationCode(), interval, planDate, type, liftCharge, operator).sendTokenOnPlatform(jmsMessagingTemplate, pushUserInfos));
+        }
+    }
+
+    /**
+     * @param liftId 电梯ID
+     * @param projectId 项目ID
+     * @param mtCompanyId 公司ID
+     * @param interval 保养间隔
+     * @param planDate 保养时间
+     * @param type 保养类型
+     * @param liftCharge 电梯负责人
+     * @param operator 操作人
+     * @param workerId 维保工
+     * @return
+     * @description 修改保养计划消息推送
+     * @date 2020/5/8 10:25 上午
+     */
+    public void sendModifyMessage(Long liftId, Long projectId, Long mtCompanyId, int interval, LocalDate planDate, int type, String liftCharge, String operator, Long workerId) {
+        //消息推送
+        List<Long> userIds = new ArrayList<>();
+        Region region = pushUserService.findRegionByProject(projectId, mtCompanyId);
+        if (Objects.nonNull(region)) {
+            userIds.addAll(region.members());
+        }
+        userIds.add(workerId);
+        List<PushUserInfo> pushUserInfos = new ArrayList<>();
+        if (!userIds.isEmpty()) {
+            List<PushUserInfo> userInfos = pushUserService.listByUserIds(mtCompanyId, userIds);
+            pushUserInfos.addAll(userInfos);
+        }
+        if (!pushUserInfos.isEmpty()) {
+            ProjectDetailResponse detail = projectAppService.detail(projectId);
+            Optional<Lift> lift = liftService.getOne(null, liftId);
+            lift.ifPresent(l ->
+                    PushMessage.maintainModifyPlan(detail.getAreaName(), detail.getProjectName(), l.getDevicePosition(),
+                            l.getRegistrationCode(), interval, planDate, type, liftCharge, operator).sendTokenOnPlatform(jmsMessagingTemplate, pushUserInfos));
+        }
+    }
+
+
     /**
      * @param request 电梯列表
      * @return 是否成功
@@ -126,13 +220,27 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
      * @date 2019/12/16 2:14 PM
      */
     public RestResponse insertBatch(MaintenancePlanRequest request) {
-        boolean result = preJudgment(request.getPlanList(), request.getFirstTime());
-        if (!result){
+        List<MaintenancePlan> planList = request.getPlanList();
+        boolean result = preJudgment(planList, request.getFirstTime());
+        if (!result) {
             return RestResponse.fail(MessageUtils.get("msg.error.time"));
         }
         List<MaintenancePlan> resultList = addPlan(request);
         boolean ret = saveBatch(resultList, resultList.size());
         if (ret) {
+            List<MaintenancePlan> messageList = new ArrayList<>();
+            Map<Long, List<MaintenancePlan>> collectMap = resultList.stream().collect(Collectors.groupingBy(MaintenancePlan::getId));
+            for (Map.Entry<Long, List<MaintenancePlan>> entry : collectMap.entrySet()) {
+                MaintenancePlan plan = entry.getValue().get(0);
+                messageList.add(plan);
+            }
+            //生成维保计划发送推送消息
+            for (MaintenancePlan plan : messageList) {
+                String workerName = commonMapper.queryUserNameById(plan.getWorkerId());
+                String creatorName = commonMapper.queryUserNameById(plan.getCreatorId());
+                sendCreateMessage(plan.getLiftId(), plan.getProjectId(),
+                        plan.getMtCompanyId(), request.getInterval(), request.getFirstTime(), plan.getType(), workerName, creatorName, plan.getWorkerId());
+            }
             return RestResponse.success(null, MessageUtils.get("msg.add.success"));
         } else {
             return RestResponse.fail(MessageUtils.get("msg.add.fail"));
@@ -278,12 +386,16 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
         Long mtCompanyId = request.getMtCompanyId();
         //获取电梯id
         Long liftId = request.getLiftId();
+        //获取项目id
+        Long projectId = request.getProjectId();
+        //获取维保工id
+        Long workerId = request.getWorkerId();
         MaintenancePlan plan = new MaintenancePlan();
-        plan.setProjectId(request.getProjectId());
+        plan.setProjectId(projectId);
         plan.setMtCompanyId(mtCompanyId);
         plan.setLiftId(liftId);
-        plan.setWorkerId(request.getWorkerId());
-        Optional<Project> optional = projectService.getOne(request.getProjectId());
+        plan.setWorkerId(workerId);
+        Optional<Project> optional = projectService.getOne(projectId);
         Project project = new Project();
         if (optional.isPresent()) project = optional.get();
         if (ObjectUtil.isEmpty(project)) return false;
@@ -336,6 +448,11 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
             //按照修改时间重新生成计划
             plans = generatePlan(plan, periods, updateInterval, updateTime, endDate);
         }
+        MaintenancePlan newPlan = plans.get(0);
+        String workerName = commonMapper.queryUserNameById(workerId);
+        String creatorName = commonMapper.queryUserNameById(plan.getCreatorId());
+        //发送修改计划消息推送
+        sendModifyMessage(liftId, projectId, mtCompanyId, interval, newPlan.getPlanDate(), newPlan.getType(), workerName, creatorName, workerId);
         return saveBatch(plans, plans.size());
     }
 

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

@@ -77,7 +77,7 @@ public class ProjectLiftRelevanceService extends ServiceImpl<ProjectLiftRelevanc
      * @description 新增项目电梯关联数据
      * @date 2019/12/5 2:39 PM
      */
-    public boolean save(LiftExtensionRequest request, long id, long workerId) {
+    public ProjectLiftRelevance save(LiftExtensionRequest request, long id, long workerId) {
         Lift lift = request.getLift();
         //新增项目电梯关联表
         ProjectLiftRelevance projectLiftEntry = new ProjectLiftRelevance();
@@ -86,7 +86,7 @@ public class ProjectLiftRelevanceService extends ServiceImpl<ProjectLiftRelevanc
         projectLiftEntry.setRelevanceId(id);
         projectLiftEntry.setWorkerId(workerId);
         projectLiftEntry.setMtCompanyId(request.getMtCompanyId());
-        return save(projectLiftEntry);
+        return save(projectLiftEntry) ? projectLiftEntry : null;
     }
 
     /**