xiongchao 3 years ago
parent
commit
de9d999d77

+ 1 - 1
platform-dao/src/main/resources/mapper/sb/SbInfoMapper.xml

@@ -12,7 +12,7 @@ param_list,
 name, model_id,
         is_child,
         is_show,
-is_financing,
+        is_financing,
         type_id, level, initial_value, current_value, cut_value,
         producer_id, source_type, source_sb_id, parent_id, unit, position_id,
         use_area,

+ 15 - 9
platform-service/src/main/java/com/platform/service/event/EventListenerBean.java

@@ -54,9 +54,11 @@ public class EventListenerBean {
         backlog.setTaskCreateTime(now);
         workplaceBacklogMapper.insertSelective(backlog);
         List<String> userIds = model.getUserIds();
-        List<WorkplaceBacklogUser> backlogUsers = userIds.stream().map(userId ->
-                new WorkplaceBacklogUser(IdGeneratorUtils.getObjectId(), userId, backlog.getId(), now)).collect(Collectors.toList());
-        workplaceBacklogUserMapper.insertListforComplex(backlogUsers);
+        if(CollectionUtil.isNotEmpty(userIds)){
+            List<WorkplaceBacklogUser> backlogUsers = userIds.stream().map(userId ->
+                    new WorkplaceBacklogUser(IdGeneratorUtils.getObjectId(), userId, backlog.getId(), now)).collect(Collectors.toList());
+            workplaceBacklogUserMapper.insertListforComplex(backlogUsers);
+        }
         List<String> mails = model.getEmails();
         if (CollectionUtil.isNotEmpty(mails)) {
             mails.forEach(item -> {
@@ -82,13 +84,17 @@ public class EventListenerBean {
             backlog.setStatus(WorkplaceBacklogStatusEnum.WORKPLACE_BACKLOG_STATUS_WAITING.getValue());
             backlog.setTaskCreateTime(now);
             List<String> userIds = logDTO.getUserIds();
-            List<WorkplaceBacklogUser> backlogUsers = userIds.stream().map(userId ->
-                    new WorkplaceBacklogUser(IdGeneratorUtils.getObjectId(), userId, backlog.getId(), now)).collect(Collectors.toList());
-            logUsers.addAll(backlogUsers);
-            logList.add(backlog);
+            if(CollectionUtil.isNotEmpty(userIds)) {
+                List<WorkplaceBacklogUser> backlogUsers = userIds.stream().map(userId ->
+                        new WorkplaceBacklogUser(IdGeneratorUtils.getObjectId(), userId, backlog.getId(), now)).collect(Collectors.toList());
+                logUsers.addAll(backlogUsers);
+                logList.add(backlog);
+            }
         });
-        workplaceBacklogMapper.insertListforComplex(logList);
-        workplaceBacklogUserMapper.insertListforComplex(logUsers);
+        if(CollectionUtil.isNotEmpty(logList)) {
+            workplaceBacklogMapper.insertListforComplex(logList);
+            workplaceBacklogUserMapper.insertListforComplex(logUsers);
+        }
     }
 
 

+ 83 - 40
platform-service/src/main/java/com/platform/service/redis/impl/RedisTaskService.java

@@ -10,6 +10,7 @@ import com.platform.dao.dto.repair.RepairApplicationFormDTO;
 import com.platform.dao.dto.upms.SysUserDTO;
 import com.platform.dao.entity.repair.RepairApplicationForm;
 import com.platform.dao.entity.sb.SbInfo;
+import com.platform.dao.entity.upms.SysConfig;
 import com.platform.dao.entity.upms.SysUser;
 import com.platform.dao.enums.*;
 import com.platform.dao.util.MessageTemplateUtil;
@@ -18,6 +19,7 @@ import com.platform.dao.vo.sb.SbInfoVO;
 import com.platform.service.event.WorkplaceBacklogEvent;
 import com.platform.service.repair.RepairApplicationFormService;
 import com.platform.service.sb.SbInfoService;
+import com.platform.service.upms.SysConfigService;
 import com.platform.service.upms.SysUserService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -56,6 +58,8 @@ public class RedisTaskService extends KeyExpirationEventMessageListener {
     @Resource
     private SysUserService sysUserService;
 
+    @Resource
+    private SysConfigService sysConfigService;
     /**
      * @param listenerContainer
      */
@@ -133,68 +137,77 @@ public class RedisTaskService extends KeyExpirationEventMessageListener {
             if(repairApplicationForm.getStatus().compareTo(RepairApplicationFormStatusEnum.PROCESSING.getValue())>0){
                 return;
             }
+            if(StringUtils.isBlank(sbInfoVO.getPositionId())){
+                logger.info("设备车间未设置,无法发送维修超时预警,设备Id" + sbInfoVO.getId());
+                return;
+            }
+            // 超过3个小时没修好
             if(expiredKeyArr[0].equalsIgnoreCase(RedisKeyConstants.EXPIRE_BUSINESS_KEY_REPAIR_OVERTIME_STEP_FIRST)){
-
                 // 更新维修单状态为维修超时
                 repairApplicationForm.setRepairOvertime(true);
                 repairApplicationFormService.modModelByPrimaryKey(repairApplicationForm);
-
-                logger.info("超时3小时发送给牛工");
-                List<SysUser> userList = sysUserService.getRepairUser(new SysUserDTO());
-                List<SysUser> filterUsers = userList.stream().filter(item -> item.getWorkFlag()).collect(Collectors.toList());
-                if (CollectionUtil.isEmpty(filterUsers)) {
-                    filterUsers = userList.stream().filter(item -> item.getIdentityType().equals(SysUserIdentityType.WXZGMANAGER.getValue())).collect(Collectors.toList());
-                }
-                if (CollectionUtil.isEmpty(filterUsers)) {
-                    logger.info("超时3小时发送给牛工,维修主管领导身份未设置,无法发送消息,设备编号:" + sbInfoVO.getNo());
+                logger.info("处理第一阶段维修过期");
+                SysConfig sysConfig = sysConfigService.getByCode(SysConfigEnum.REPAIR_OVERTIME_MINUTE_FIRST.toString());
+                String description = sysConfig.getDescription();
+                if(StringUtils.isBlank(description)){
                     return;
-                }else{
-                    SysUser user = filterUsers.get(0);
-                    // 通过给当天值班维修人员
-                    sendMessage(repairId, repairApplicationForm,BeanConverterUtil.copyObjectProperties(user, SysUserVO.class),sbInfoVO, "repairEmailOverTimeFirst.ftl");
+                }
+                String[] arr = description.split(";");
+                List<String> emailList = new ArrayList<String>();
+                for(String a: arr){
+                    if(a.split(",")[0].equals(sbInfoVO.getPositionId())){
+                        sendMessage(repairId, repairApplicationForm,a.split(",")[1],sbInfoVO, "repairEmailOverTimeFirst.ftl");
+                    }
                 }
                 return;
             }
-            // 超过8个小时没修好,升级给相工,通过角色来查询
+            // 超过8个小时没修好
             if(expiredKeyArr[0].equalsIgnoreCase(RedisKeyConstants.EXPIRE_BUSINESS_KEY_REPAIR_OVERTIME_STEP_SECOND)){
-                logger.info("处理第二阶段过期,发送消息给牛");
-                List<SysUser> userList = sysUserService.getRepairUser(new SysUserDTO());
-                List<SysUser> filterUsers = userList.stream().filter(item -> item.getWorkFlag()).collect(Collectors.toList());
-                if (CollectionUtil.isEmpty(filterUsers)) {
-                    filterUsers = userList.stream().filter(item -> item.getIdentityType().equals(SysUserIdentityType.WXZGMANAGER.getValue())).collect(Collectors.toList());
-                }
-                if (CollectionUtil.isEmpty(filterUsers)) {
-                    logger.info("处理第三阶段过期,维修主管领导身份未设置,无法发送消息,设备编号:" + sbInfoVO.getNo());
+                logger.info("处理第二阶段维修过期");
+                SysConfig sysConfig = sysConfigService.getByCode(SysConfigEnum.REPAIR_OVERTIME_MINUTE_SECOND.toString());
+                String description = sysConfig.getDescription();
+                if(StringUtils.isBlank(description)){
                     return;
-                }else{
-                    SysUser user = filterUsers.get(0);
-                    // 通过给当天值班维修人员
-                    sendMessage(repairId, repairApplicationForm,BeanConverterUtil.copyObjectProperties(user, SysUserVO.class),sbInfoVO, "repairEmailOverTimeSecond.ftl");
+                }
+                String[] arr = description.split(";");
+                List<String> emailList = new ArrayList<String>();
+                for(String a: arr){
+                    if(a.split(",")[0].equals(sbInfoVO.getPositionId())){
+                        sendMessage(repairId, repairApplicationForm,a.split(",")[1],sbInfoVO, "repairEmailOverTimeSecond.ftl");
+                    }
                 }
                 return;
             }
 
-            // 超时超过24 没修好,升级给田总,通过角色来查询
+            // 超时超过24
             if(expiredKeyArr[0].equalsIgnoreCase(RedisKeyConstants.EXPIRE_BUSINESS_KEY_REPAIR_OVERTIME_STEP_THIRD)){
-                logger.info("处理第二阶段过期,发送消息给牛");
-                List<SysUser> userList = sysUserService.getRepairUser(new SysUserDTO());
-                List<SysUser> filterUsers = userList.stream().filter(item -> item.getWorkFlag()).collect(Collectors.toList());
-                if (CollectionUtil.isEmpty(filterUsers)) {
-                    filterUsers = userList.stream().filter(item -> item.getIdentityType().equals(SysUserIdentityType.WXZGMANAGER.getValue())).collect(Collectors.toList());
-                }
-                if (CollectionUtil.isEmpty(filterUsers)) {
-                    logger.info("处理第三阶段过期,维修主管领导身份未设置,无法发送消息,设备编号:" + sbInfoVO.getNo());
+                logger.info("处理第二阶段维修过期");
+                SysConfig sysConfig = sysConfigService.getByCode(SysConfigEnum.REPAIR_OVERTIME_MINUTE_THIRD.toString());
+                String description = sysConfig.getDescription();
+                if(StringUtils.isBlank(description)){
                     return;
-                }else{
-                    SysUser user = filterUsers.get(0);
-                    // 通过给当天值班维修人员
-                    sendMessage(repairId, repairApplicationForm,BeanConverterUtil.copyObjectProperties(user, SysUserVO.class),sbInfoVO, "repairEmailOverTimeThird.ftl");
+                }
+                String[] arr = description.split(";");
+                List<String> emailList = new ArrayList<String>();
+                for(String a: arr){
+                    if(a.split(",")[0].equals(sbInfoVO.getPositionId())){
+                        sendMessage(repairId, repairApplicationForm,a.split(",")[1],sbInfoVO, "repairEmailOverTimeThird.ftl");
+                    }
                 }
                 return;
             }
         }
     }
 
+    /**
+     * 给系统用户发生通知和邮件
+     *
+     * @param repairId
+     * @param repairApplicationForm
+     * @param user
+     * @param sbInfoVO
+     * @param templateFileName
+     */
     public void sendMessage(String repairId, RepairApplicationForm repairApplicationForm, SysUserVO user, SbInfoVO sbInfoVO, String templateFileName ){
         String domain = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.SYSTEM_DOMAIN.name());
         if(StringUtils.isBlank(domain)){
@@ -214,4 +227,34 @@ public class RedisTaskService extends KeyExpirationEventMessageListener {
                 )
         );
     }
+
+    /**
+     * 给指定邮箱发送邮件
+     *
+     *
+     * @param repairId
+     * @param repairApplicationForm
+     * @param email
+     * @param sbInfoVO
+     * @param templateFileName
+     */
+    public void sendMessage(String repairId, RepairApplicationForm repairApplicationForm, String email, SbInfoVO sbInfoVO, String templateFileName ){
+        String domain = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.SYSTEM_DOMAIN.name());
+        if(StringUtils.isBlank(domain)){
+            throw new BusinessException("请先设置系统域名地址,系统管理-》系统参数配置-》SYSTEM_DOMAIN");
+        }
+        if(!domain.endsWith("/")){
+            domain = domain + "/";
+        }
+        String repairUrl = domain + "repair/application/form/check?no=" + repairApplicationForm.getNo();
+        SpringContextHolder.publishEvent(
+                new WorkplaceBacklogEvent(
+                        WorkplaceBacklogTypeEnum.REPAIR.getValue(),
+                        WorkplaceBacklogDetailTypeEnum.REPAIR_APPLICATION.getValue(),
+                        repairId,
+                        MessageTemplateUtil.getFreemarkerHtmlContent(repairUrl, BeanConverterUtil.copyObjectProperties(repairApplicationForm, RepairApplicationFormDTO.class),sbInfoVO, templateFileName),
+                        repairId, null, ListUtils.newArrayList(email)
+                )
+        );
+    }
 }

+ 2 - 1
platform-service/src/main/java/com/platform/service/repair/impl/RepairApplicationFormServiceImpl.java

@@ -24,6 +24,7 @@ import com.platform.dao.entity.repair.RepairCheck;
 import com.platform.dao.entity.repair.RepairForm;
 import com.platform.dao.entity.sb.SbInfo;
 import com.platform.dao.entity.sb.SbInspectionFill;
+import com.platform.dao.entity.upms.SysConfig;
 import com.platform.dao.entity.upms.SysFile;
 import com.platform.dao.entity.upms.SysUser;
 import com.platform.dao.enums.*;
@@ -46,6 +47,7 @@ import com.platform.service.event.WorkplaceBacklogEvent;
 import com.platform.service.repair.RepairApplicationFormService;
 import com.platform.service.repair.RepairFormService;
 import com.platform.service.sb.SbInfoService;
+import com.platform.service.upms.SysConfigService;
 import com.platform.service.upms.SysUserDeptService;
 import com.platform.service.upms.SysUserService;
 import com.platform.service.wechat.util.WeChatMessageUtil;
@@ -89,7 +91,6 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
     private final SysFileMapper sysFileMapper;
     private final SysUserMapper userMapper;
 
-
     @Override
     public int batchDelete(List<String> ids) {
         // 判断是否允许删除

+ 0 - 2
platform-service/src/main/java/com/platform/service/sb/impl/SbPositionServiceImpl.java

@@ -81,8 +81,6 @@ public class SbPositionServiceImpl extends BaseServiceImpl<SbPositionMapper, SbP
             String code = IdGeneratorUtils.getStrNum("", ++i);
             model.setCode(code);
         }
-        int count = mapper.selectCount(new SbPosition());
-        model.setNo(IdGeneratorUtils.getPositionNo(++count));
         SbPosition sbPosition = super.saveModelByDTO(model);
         if (parent != null) {
             mapper.updateByPrimaryKeySelective(new SbPosition().setId(parentId).setUpdateTime(LocalDateTime.now()));

+ 5 - 0
platform-service/src/main/java/com/platform/service/upms/impl/SysConfigServiceImpl.java

@@ -9,6 +9,7 @@ import com.platform.common.util.BeanConverterUtil;
 import com.platform.common.util.RedisUtils;
 import com.platform.dao.dto.upms.SysConfigDTO;
 import com.platform.dao.entity.upms.SysConfig;
+import com.platform.dao.enums.SysConfigEnum;
 import com.platform.dao.mapper.upms.SysConfigMapper;
 import com.platform.service.base.impl.BaseServiceImpl;
 import com.platform.service.upms.SysConfigService;
@@ -101,6 +102,10 @@ public class SysConfigServiceImpl extends BaseServiceImpl<SysConfigMapper, SysCo
         return result;
     }
 
+    public static void main(String[] args) {
+        System.out.println(SysConfigEnum.REPAIR_OVERTIME_MINUTE_FIRST.toString());
+    }
+
     @Override
     public SysConfig getByCode(String code) {
         Weekend<SysConfig> weekend = new Weekend<>(SysConfig.class);