|
|
|
@ -6,7 +6,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.foreverwin.mesnac.common.constant.Constants;
|
|
|
|
|
import com.foreverwin.mesnac.common.enums.HandleEnum;
|
|
|
|
|
import com.foreverwin.mesnac.common.helper.NextNumberHelper;
|
|
|
|
|
import com.foreverwin.mesnac.common.model.Message;
|
|
|
|
|
import com.foreverwin.mesnac.common.service.AnomalyService;
|
|
|
|
|
import com.foreverwin.mesnac.common.service.MessageService;
|
|
|
|
|
import com.foreverwin.mesnac.common.util.ActiveMQUtil;
|
|
|
|
|
import com.foreverwin.mesnac.common.util.StringUtil;
|
|
|
|
|
import com.foreverwin.mesnac.equip.mapper.ResourceInspectTaskMapper;
|
|
|
|
|
import com.foreverwin.mesnac.equip.mapper.ResourceRepairTaskMapper;
|
|
|
|
|
import com.foreverwin.mesnac.equip.model.ResourceInspectTask;
|
|
|
|
@ -15,14 +19,20 @@ import com.foreverwin.mesnac.equip.model.ResourceRepairTask;
|
|
|
|
|
import com.foreverwin.mesnac.equip.service.ResourceInspectPlanService;
|
|
|
|
|
import com.foreverwin.mesnac.equip.service.ResourceInspectTaskSpareService;
|
|
|
|
|
import com.foreverwin.mesnac.equip.service.ResourceRepairTaskService;
|
|
|
|
|
import com.foreverwin.mesnac.listener.mapper.UsrMapper;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.mapper.MessageTypeMapper;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.mapper.NcCodeMapper;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.mapper.NwaUserMapper;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.mapper.UserGroupMapper;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.model.DataField;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.model.MessageType;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.model.NwaUser;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.model.UserGroup;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.service.DataFieldListService;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.service.NcCodeService;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.service.NwaUserService;
|
|
|
|
|
import com.foreverwin.mesnac.meapi.service.ResrceService;
|
|
|
|
|
import com.foreverwin.modular.core.exception.BaseException;
|
|
|
|
|
import com.foreverwin.modular.core.exception.BusinessException;
|
|
|
|
|
import com.foreverwin.modular.core.util.CommonMethods;
|
|
|
|
|
import com.foreverwin.modular.core.util.FrontPage;
|
|
|
|
@ -34,10 +44,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
@ -77,6 +84,16 @@ public class ResourceRepairTaskServiceImpl extends ServiceImpl<ResourceRepairTas
|
|
|
|
|
private ResourceInspectPlanService resourceInspectPlanService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private NcCodeMapper ncCodeMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MessageTypeMapper messageTypeMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserGroupMapper userGroupMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private UsrMapper usrMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ActiveMQUtil activeMQUtil;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MessageService messageService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public HashMap<String, Object> init() {
|
|
|
|
@ -155,6 +172,7 @@ public class ResourceRepairTaskServiceImpl extends ServiceImpl<ResourceRepairTas
|
|
|
|
|
resourceRepairTask.setCreateUser(reportUser);
|
|
|
|
|
resourceRepairTask.setCreatedDateTime(LocalDateTime.now());
|
|
|
|
|
resourceRepairTaskService.save(resourceRepairTask);
|
|
|
|
|
this.createAndSendMessage(resourceRepairTask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -381,6 +399,101 @@ public class ResourceRepairTaskServiceImpl extends ServiceImpl<ResourceRepairTas
|
|
|
|
|
return resourceRepairTaskService.updateById(resourceRepairTask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void createAndSendMessage(ResourceRepairTask resourceRepairTask) {
|
|
|
|
|
String site = CommonMethods.getSite();
|
|
|
|
|
String user = CommonMethods.getUser();
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
Message message = new Message();
|
|
|
|
|
message.setHandle(UUID.randomUUID().toString());
|
|
|
|
|
message.setSite(site);
|
|
|
|
|
message.setObjectBo(resourceRepairTask.getHandle());
|
|
|
|
|
message.setType(Constants.REPAIR_TYPE);
|
|
|
|
|
//根据用户组找到对应的消息内容
|
|
|
|
|
MessageType messageType = messageTypeMapper.findMessageTypeByUserGroup(site, resourceRepairTask.getAnother());
|
|
|
|
|
if(messageType == null){
|
|
|
|
|
throw new BaseException("根据发送的用户组找不到对应的消息类型,请维护。");
|
|
|
|
|
}
|
|
|
|
|
message.setMessageType(messageType.getMessageType());
|
|
|
|
|
message.setSendUserGroup(resourceRepairTask.getAnother());
|
|
|
|
|
//格式化消息内容
|
|
|
|
|
String messageContent = this.formatMessage(resourceRepairTask, messageType.getMessageType(), site);
|
|
|
|
|
message.setContent(messageContent);
|
|
|
|
|
message.setResponseDateTime(LocalDateTime.now());
|
|
|
|
|
|
|
|
|
|
// message.setUpUserGroup(message.getSendUserGroup()+"_SJ");
|
|
|
|
|
//得到升级的时间和等级
|
|
|
|
|
UserGroup customFieldByGroup = userGroupMapper.getCustomFieldByGroup(site, message.getSendUserGroup());
|
|
|
|
|
// if(customFieldByGroup != null && !StringUtil.isBlank(customFieldByGroup.getMessageNoticeTime())){
|
|
|
|
|
// message.setUpDateTime(message.getResponseDateTime().plusMinutes(Integer.parseInt(customFieldByGroup.getMessageNoticeTime())));
|
|
|
|
|
// }else{
|
|
|
|
|
// throw new BaseException("该用户组没有维护升级的时间,请维护。");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if(customFieldByGroup != null && !StringUtil.isBlank(customFieldByGroup.getMessageNoticeLevel())){
|
|
|
|
|
message.setGrade(Double.parseDouble(customFieldByGroup.getMessageNoticeLevel()));
|
|
|
|
|
}else{
|
|
|
|
|
throw new BaseException("该用户组没有维护等级,请维护。");
|
|
|
|
|
}
|
|
|
|
|
// MessageType messageTypeUp = messageTypeMapper.findMessageTypeByUserGroup(site, message.getUpUserGroup());
|
|
|
|
|
// //得到升级的消息类型
|
|
|
|
|
// if(messageTypeUp == null){
|
|
|
|
|
// throw new BaseException("用户组"+message.getSendUserGroup()+"的升级用户没有维护消息类型");
|
|
|
|
|
// }
|
|
|
|
|
// message.setUpMessageType(messageTypeUp.getMessageType());
|
|
|
|
|
message.setNode(Constants.RESOURCE_REPAIR_MESSAGE_REPORT);
|
|
|
|
|
|
|
|
|
|
message.setStatus("Y");
|
|
|
|
|
message.setCreatedUser(user);
|
|
|
|
|
message.setCreatedDateTime(now);
|
|
|
|
|
message.setModifiedUser(user);
|
|
|
|
|
message.setModifiedDateTime(now);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//发送消息
|
|
|
|
|
List<NwaUser> nwaUsers = nwaUserService.checkUserGroup(site,message.getSendUserGroup());
|
|
|
|
|
if(nwaUsers != null && nwaUsers.size() <= 0){
|
|
|
|
|
throw new BaseException("消息发送失败,发送的用户组下面没有用户");
|
|
|
|
|
}
|
|
|
|
|
List<String> customFieldByUserId = usrMapper.findCustomFieldByUserId(site, nwaUsers);
|
|
|
|
|
if(customFieldByUserId != null && customFieldByUserId.size() <= 0){
|
|
|
|
|
throw new BaseException("消息发送失败,发送的用户组下面的用户的自定义数据没有维护");
|
|
|
|
|
}
|
|
|
|
|
StringBuilder sendUsers = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < Objects.requireNonNull(customFieldByUserId).size(); i++) {
|
|
|
|
|
if(i == (customFieldByUserId.size() - 1)){
|
|
|
|
|
sendUsers.append(customFieldByUserId.get(i));
|
|
|
|
|
}else{
|
|
|
|
|
sendUsers.append(customFieldByUserId.get(i)).append("|");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
activeMQUtil.wechatSendMessage(sendUsers.toString(),message.getContent());
|
|
|
|
|
messageService.saveOrUpdate(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String formatMessage(ResourceRepairTask resourceRepairTask, String messageType, String site) {
|
|
|
|
|
/*
|
|
|
|
|
* 找到对应的消息内容
|
|
|
|
|
*/
|
|
|
|
|
MessageType messageTypeEntity = new MessageType();
|
|
|
|
|
messageTypeEntity.setSite(site);
|
|
|
|
|
messageTypeEntity.setMessageType(messageType);
|
|
|
|
|
QueryWrapper<MessageType> messageTypeQueryWrapper = new QueryWrapper<MessageType>();
|
|
|
|
|
messageTypeQueryWrapper.setEntity(messageTypeEntity);
|
|
|
|
|
MessageType sendMessageType = messageTypeMapper.selectOne(messageTypeQueryWrapper);
|
|
|
|
|
if(sendMessageType == null){
|
|
|
|
|
throw new BaseException("维修提报找不到要发送的消息类型");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 把消息内容中,对应的map的key替换为 resourceRepairTask中对应的字段(变量)
|
|
|
|
|
*/
|
|
|
|
|
Map<String, String> replaceMessageMap = resourceRepairTaskMapper.findReplaceMessageByResourceRepairTask(resourceRepairTask);
|
|
|
|
|
String messageBody = sendMessageType.getBody();
|
|
|
|
|
//格式化之后的消息
|
|
|
|
|
return com.foreverwin.mesnac.meapi.util.StringUtils.format(messageBody, replaceMessageMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|