Parcourir la source

维修模式-派工模式

guarantee-lsq il y a 2 ans
Parent
commit
94ed21ebf3

+ 2 - 0
platform-dao/src/main/java/com/platform/dao/dto/repair/RepairApplicationFormDTO.java

@@ -335,4 +335,6 @@ public class RepairApplicationFormDTO extends BaseDTO implements Serializable {
     private String queryRepairUserId;
 
     private List<Integer> statusList;
+
+    private String dispatchUserId;
 }

+ 5 - 0
platform-dao/src/main/java/com/platform/dao/dto/upms/SysUserDTO.java

@@ -237,4 +237,9 @@ public class SysUserDTO extends BaseDTO implements Serializable {
     private Boolean workFlag;
 
     private String email;
+
+    /**
+     * 获取角色专用 1 代表根据创建时间升序
+     */
+    private Integer orderByFlag;
 }

+ 10 - 0
platform-dao/src/main/java/com/platform/dao/entity/repair/RepairApplicationForm.java

@@ -240,6 +240,16 @@ public class RepairApplicationForm implements Serializable {
      * 类型
      */
     private Integer type;
+
+    /**
+     * 分配人ID
+     */
+    private String dispatchUserId;
+
+    /**
+     * 分配时间
+     */
+    private LocalDateTime dispatchTime;
     /**
      * 报修人
      */

+ 4 - 0
platform-dao/src/main/java/com/platform/dao/enums/SysRoleCodeEnum.java

@@ -135,6 +135,10 @@ public enum SysRoleCodeEnum {
      * 报修单最后审核人员
      */
     REPAIR_EXAMINE,
+    /**
+     * 报修派工角色
+     */
+    REPAIR_DISPATCH,
     ;
 
 }

+ 9 - 2
platform-dao/src/main/resources/mapper/upms/SysUserMapper.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.platform.dao.mapper.upms.SysUserMapper">
+<mapper namespace="com.platform.dao.mapper.upms.SysUserMapper" xmlns:c="http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 
     <select id="selectVOByKeyword" resultType="com.platform.dao.vo.SysUserVO"
             parameterType="com.platform.dao.dto.upms.SysUserDTO">
@@ -70,7 +70,14 @@
                 #{item}
             </foreach>
         </if>
-        order by u.update_time desc
+        <choose>
+            <when test="orderByFlag != null and orderByFlag == 1">
+                order by u.created_time asc
+            </when>
+            <otherwise>
+                order by u.update_time desc
+            </otherwise>
+        </choose>
     </select>
 
     <select id="selectUserNameById" resultType="java.lang.String" parameterType="java.lang.Object">

+ 19 - 34
platform-service/src/main/java/com/platform/service/repair/impl/RepairApplicationFormServiceImpl.java

@@ -144,46 +144,21 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
     @Override
     public MyVOPage<RepairApplicationFormVO> selectPageInfoVO(RepairApplicationFormDTO record, int pageNum, int pageSize) {
         PageHelper.startPage(pageNum, pageSize);
-
-        /*if (record.getSearchType() != null) {
-            // 获取报修人
-            if (record.getSearchType() == 1) {
-                if (record.getFilter() != null && DataFilterTypeEnum.SELF.getValue() == record.getFilter().intValue()) {
-                    UserInfo userInfo = SecurityUtils.getUserInfo();
-                    record.setUserId(userInfo.getUserId());
-                }
-            }
-            // 获取维修人,包括第二维修人
-            if (record.getSearchType() == 2) {
-                if (record.getFilter() != null && DataFilterTypeEnum.SELF.getValue() == record.getFilter().intValue()) {
-                    UserInfo userInfo = SecurityUtils.getUserInfo();
-                    record.setRepairUserId(userInfo.getUserId());
-                }
-            }
-            // 获取验收人
-            if (record.getSearchType() == 3) {
-                if (record.getFilter() != null && DataFilterTypeEnum.SELF.getValue() == record.getFilter().intValue()) {
-                    UserInfo userInfo = SecurityUtils.getUserInfo();
-                    record.setCheckUserId(userInfo.getUserId());
-                }
-            }
-        }*/
-
         UserInfo userInfo = SecurityUtils.getUserInfo();
         record.setRepairUserId(userInfo.getUserId());
-        // 排除超级用户
-        String userNames = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_SUPER_USERS.name());
-        if(StringUtils.isBlank(userNames)){
-            throw new DeniedException("请设置维修菜单的超级用户");
-        }
-        if(userNames.contains(userInfo.getUsername())){
-            record.setRepairUserId(null);
-        }
+        String repairModel = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_STRATEGY_MODEL.name()); // 维修模式
         if(record.getSearchType() != null){
             List<Integer> statusList = new ArrayList<>();
             if(record.getSearchType() == 1){ // 待分配
                 statusList.add(RepairApplicationFormStatusEnum.NOT_ALLOCATED.getValue());
-                record.setRepairUserId(null);
+                switch (repairModel){
+                    case CommonConstants.REPAIR_STRATEGY_MODEL_BASE:
+                        record.setRepairUserId(null);
+                        break;
+                    case CommonConstants.REPAIR_STRATEGY_MODEL_DISPATCH:
+                        record.setDispatchUserId(SecurityUtils.getUserInfo().getUserId());
+                        break;
+                }
             }
             if(record.getSearchType() == 2){ // 待维修
                 statusList.add(RepairApplicationFormStatusEnum.PROCESSING.getValue());
@@ -207,6 +182,16 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
             }
             record.setStatusList(statusList);
         }
+        // 排除超级用户
+        String userNames = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_SUPER_USERS.name()); // 超级用户
+        if(StringUtils.isBlank(userNames)){
+            throw new DeniedException("请设置维修菜单的超级用户");
+        }
+        // 维修模式为派工的情况
+        if(userNames.contains(userInfo.getUsername())){
+            record.setRepairUserId(null);
+            record.setDispatchUserId(null);
+        }
         return new MyVOPage<>(mapper.selectPageList(record));
     }
 

+ 6 - 13
platform-service/src/main/java/com/platform/service/repair/strategy/AbstractRepairBaseStrategy.java

@@ -127,23 +127,16 @@ public abstract class AbstractRepairBaseStrategy implements RepairBaseStrategy{
         if (!RepairApplicationFormStatusEnum.NOT_ALLOCATED.getValue().equals(applicationForm.getStatus()) && !RepairApplicationFormStatusEnum.REBACK.getValue().equals(applicationForm.getStatus())) {
             throw new BusinessException("该状态不允许接收任务");
         }
-        model.setRepairStartTime(applicationForm.getRepairStartTime());
-        model.setApplyTime(applicationForm.getApplyTime());
-        model.setNo(applicationForm.getNo());
-        model.setUserId(applicationForm.getUserId());
         SbInfo sbInfo = sbInfoService.getModelById(applicationForm.getSbId());
         if (sbInfo == null) {
             throw new BusinessException("设备不存在,无法接收");
         }
-        /*if (sbInfo.getRepairUser() == null) {
-            throw new BusinessException("设备的第一维修人未设置,无法接受任务");
-        }
-        if (sbInfo.getRepairUserSecond() == null) {
-            throw new BusinessException("设备的第二维修人未设置,无法接受任务");
-        }
-        if (!SecurityUtils.isRole(SysRoleCodeEnum.MM.name()) && !SecurityUtils.isRole(SysRoleCodeEnum.Maintenance.name())) {
-            throw new BusinessException("您不是维修人或维修主管,无法接受任务");
-        }*/
+        model.setRepairStartTime(applicationForm.getRepairStartTime());
+        model.setApplyTime(applicationForm.getApplyTime());
+        model.setNo(applicationForm.getNo());
+        model.setUserId(applicationForm.getUserId());
+        model.setDispatchUserId(applicationForm.getDispatchUserId());
+        model.setRepairDispatchList(applicationForm.getRepairDispatchList());
         return model;
     }
 

+ 120 - 0
platform-service/src/main/java/com/platform/service/repair/strategy/impl/AllocateRepairBaseStrategy.java

@@ -1,9 +1,129 @@
 package com.platform.service.repair.strategy.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
+import com.platform.common.cache.ConfigCache;
+import com.platform.common.exception.BusinessException;
+import com.platform.common.exception.DeniedException;
+import com.platform.common.model.UserInfo;
+import com.platform.common.util.*;
+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.enums.RepairApplicationFormStatusEnum;
+import com.platform.dao.enums.SysConfigEnum;
+import com.platform.dao.enums.SysRoleCodeEnum;
+import com.platform.dao.vo.SysUserVO;
 import com.platform.service.repair.strategy.AbstractRepairBaseStrategy;
 import org.springframework.stereotype.Component;
 
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+
 @Component
 public class AllocateRepairBaseStrategy extends AbstractRepairBaseStrategy {
 
+    @Override
+    public RepairApplicationForm callRepair(RepairApplicationFormDTO model) {
+        RepairApplicationForm form = super.callRepair(model);
+        // 根据自身需要将任务推送通知还是派送到具体主管手上
+        SysUserDTO query = new SysUserDTO();
+        query.setOrderByFlag(1);
+        query.setRoleCode(SysRoleCodeEnum.REPAIR_DISPATCH.name());
+        List<SysUserVO> users = sysUserService.selectDeptRoleUser(query);
+        String dispatchUserId = "";
+        if (CollectionUtil.isNotEmpty(users)) {
+            int size = users.size()-1;
+            if(size == 0){ // 就他一个,直接就给他了
+                dispatchUserId = users.get(0).getUserId();
+            }else{
+                String key = SysRoleCodeEnum.REPAIR_DISPATCH.name() + "_dispatchIndex";
+                // 平均派发任务
+                String dispatchIndex = RedisUtils.getString(key);
+                int indexNum = 0;
+                if(!StringUtils.isBlank(dispatchIndex)){
+                    indexNum = Integer.parseInt(dispatchIndex);
+                }
+                indexNum = indexNum == size ? 0 : indexNum; // 从头再来
+                dispatchUserId = users.get(indexNum).getUserId();
+                indexNum++;
+                RedisUtils.del(key);
+                RedisUtils.setString(key,indexNum+"");
+            }
+        } else {
+            throw new BusinessException("派工角色:REPAIR_DISPATCH未绑定用户,REPAIR_DISPATCH为维修单派发人,请设置用户");
+        }
+        RepairApplicationForm updForm = new RepairApplicationForm();
+        updForm.setId(form.getId());
+        //updForm.setDispatchTime(LocalDateTime.now());
+        updForm.setDispatchUserId(dispatchUserId);
+        repairApplicationFormMapper.updateByPrimaryKeySelective(updForm);
+        // 这里的基础模式是,维修人员自主接收,我们获取需要需要派送的信息Ids集合
+        List<String> openIds = new ArrayList<>();
+        List<String> userIds = new ArrayList<>();
+        List<String> mails = new ArrayList<>();
+        List<String> receiverList = new ArrayList<>();
+
+        // 发送短信通知给所有维修,且必须是正式环境
+        SysUserDTO sysUserDTO = new SysUserDTO();
+        sysUserDTO.setRoleCode(SysRoleCodeEnum.Maintenance.name());
+        List<SysUserVO> sysUserVOList = sysUserService.getDeptChildrenRoleUser(sysUserDTO);
+        if (CollectionUtil.isNotEmpty(sysUserVOList)) {
+            for (SysUserVO sysUserVO : sysUserVOList) {
+                // 站内信需要用户id
+                userIds.add(sysUserVO.getUserId());
+                if (StringUtils.isNotBlank(sysUserVO.getWxOpenid())) {
+                    // 微信id
+                    openIds.add(sysUserVO.getWxOpenid());
+                }
+                if (StringUtils.isNotBlank(sysUserVO.getPhone())) {
+                    // 手机
+                    receiverList.add(sysUserVO.getPhone());
+                }
+                if (StringUtils.isNotBlank(sysUserVO.getEmail())) {
+                    // 邮箱
+                    mails.add(sysUserVO.getEmail());
+                }
+            }
+        }
+        model = BeanConverterUtil.copyObjectProperties(form,RepairApplicationFormDTO.class);
+        SbInfo sb = sbInfoService.getModelById(model.getSbId());
+        // 推送站内信和邮箱,根据业务需要
+        sendWorkplaceAndEmail(mails,userIds,model,sb);
+        // 推送微信
+        sendWechat(openIds,model,sb);
+        // 短信
+        sendSms(receiverList,model,sb);
+        // 启动超时监控
+        overTimeListen(form.getId());
+        return form;
+    }
+
+    @Override
+    public RepairApplicationFormDTO sendRepair(RepairApplicationFormDTO model) {
+        RepairApplicationFormDTO superModel = super.sendRepair(model);
+        // 自己派工
+        UserInfo userInfo = SecurityUtils.getUserInfo();
+        String userNames = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_SUPER_USERS.name()); // 超级用户
+        if(StringUtils.isNotBlank(userNames) && !userNames.contains(userInfo.getUsername())){
+            // 非超级用户,判断是否具有审核派工权限
+            if(!userInfo.getUserId().equals(model.getDispatchUserId())){
+                throw new DeniedException("您不具有派工权限");
+            }
+        }
+        RepairApplicationForm applicationForm = new RepairApplicationForm();
+        applicationForm.setId(model.getId());
+        applicationForm.setRepairUserId(superModel.getRepairUserId());
+        applicationForm.setStatus(RepairApplicationFormStatusEnum.PROCESSING.getValue());
+        if (superModel.getRepairStartTime() == null) {
+            applicationForm.setRepairStartTime(LocalDateTime.now());
+        }
+        applicationForm.setReceiveMinutes(DateUtils.getDurationHours(superModel.getApplyTime(), applicationForm.getRepairStartTime()));
+        applicationForm.setUpdateTime(LocalDateTime.now());
+        repairApplicationFormMapper.updateByPrimaryKeySelective(applicationForm);
+        // 给报修人发送消息
+        sendMessageToRepairCaller(superModel.getId(),superModel.getNo(),superModel.getUserId());
+        return model;
+    }
 }