|
@@ -1,9 +1,172 @@
|
|
|
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.entity.upms.SysUser;
|
|
|
+import com.platform.dao.enums.*;
|
|
|
+import com.platform.dao.util.MessageTemplateUtil;
|
|
|
+import com.platform.dao.vo.SysUserVO;
|
|
|
+import com.platform.dao.vo.sb.SbInfoVO;
|
|
|
+import com.platform.service.event.WorkplaceBacklogEvent;
|
|
|
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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RepairApplicationForm submitRepair(RepairApplicationFormDTO model) {
|
|
|
+ RepairApplicationForm applicationForm = super.submitRepair(model);
|
|
|
+ SbInfoVO sbInfoVO = sbInfoService.getById(applicationForm.getSbId());
|
|
|
+ // 默认的提交审核后的审核人,就是维修主管的角色,每家不同自行实现
|
|
|
+ SysUserVO userVO;
|
|
|
+ SysUserDTO query = new SysUserDTO();
|
|
|
+ query.setRoleCode(SysRoleCodeEnum.REPAIR_EXAMINE.name());
|
|
|
+ List<SysUserVO> users = sysUserService.selectDeptRoleUser(query);
|
|
|
+ if (CollectionUtil.isNotEmpty(users)) {
|
|
|
+ userVO = users.get(0);
|
|
|
+ } else {
|
|
|
+ throw new BusinessException("审核角色:REPAIR_EXAMINE未绑定用户,REPAIR_EXAMINE为维修单最终验收人,请设置用户");
|
|
|
+ }
|
|
|
+ applicationForm.setCheckUserId(userVO.getUserId());
|
|
|
+ repairApplicationFormMapper.updateByPrimaryKeySelective(applicationForm);
|
|
|
+ // 发送邮件和通知
|
|
|
+ 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=" + applicationForm.getNo();
|
|
|
+ SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_EXAMINE.getValue(),
|
|
|
+ applicationForm.getId(), MessageTemplateUtil.getFreemarkerHtmlContentCheck(repairUrl, BeanConverterUtil.copyObjectProperties(applicationForm, RepairApplicationFormDTO.class), sbInfoVO),
|
|
|
+ applicationForm.getId(), ListUtils.newArrayList(userVO.getUserId()), ListUtils.newArrayList(userVO.getEmail())));
|
|
|
+ return applicationForm;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RepairApplicationFormDTO verifyRefused(RepairApplicationFormDTO model) {
|
|
|
+ RepairApplicationFormDTO dto = super.verifyRefused(model);
|
|
|
+ SysUser noticeUser = sysUserService.getModelById(dto.getRepairUserId());
|
|
|
+ SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_BACK.getValue(),
|
|
|
+ dto.getId(), MessageTemplateUtil.getRepairBack(dto.getNo()),
|
|
|
+ dto.getId(), ListUtils.newArrayList(dto.getRepairUserId()), ListUtils.newArrayList(noticeUser.getEmail())));
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
}
|