|
@@ -1,20 +1,37 @@
|
|
|
package com.platform.service.fill.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
import com.platform.common.bean.AbstractPageResultBean;
|
|
|
+import com.platform.common.cache.ConfigCache;
|
|
|
+import com.platform.common.constant.RedisKeyConstants;
|
|
|
+import com.platform.common.util.*;
|
|
|
import com.platform.dao.bean.MyPage;
|
|
|
-import com.github.pagehelper.PageHelper;
|
|
|
-import com.platform.dao.vo.query.fill.FillGatherTaskVO;
|
|
|
import com.platform.dao.dto.fill.FillGatherTaskDTO;
|
|
|
-import com.platform.dao.entity.fill.FillGatherTask;
|
|
|
-import com.platform.dao.mapper.fill.FillGatherTaskMapper;
|
|
|
+import com.platform.dao.dto.fill.FillGatherTaskDetailDTO;
|
|
|
+import com.platform.dao.entity.fill.*;
|
|
|
+import com.platform.dao.entity.upms.SysUser;
|
|
|
+import com.platform.dao.enums.*;
|
|
|
+import com.platform.dao.mapper.fill.*;
|
|
|
+import com.platform.dao.mapper.upms.SysUserMapper;
|
|
|
+import com.platform.dao.util.MessageTemplateUtil;
|
|
|
+import com.platform.dao.vo.query.fill.FillGatherTaskVO;
|
|
|
+import com.platform.dao.vo.query.fill.FillInfoVO;
|
|
|
+import com.platform.service.base.impl.BaseServiceImpl;
|
|
|
+import com.platform.service.event.WorkplaceBacklogEvent;
|
|
|
import com.platform.service.fill.FillGatherTaskService;
|
|
|
+import com.platform.service.util.SendMessageUtils;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.platform.service.base.impl.BaseServiceImpl;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
import tk.mybatis.mapper.weekend.Weekend;
|
|
|
import tk.mybatis.mapper.weekend.WeekendCriteria;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* @Description 巡检任务表 service 实现类
|
|
@@ -26,6 +43,11 @@ import java.util.List;
|
|
|
@Service("fillGatherTaskService")
|
|
|
public class FillGatherTaskServiceImpl extends BaseServiceImpl<FillGatherTaskMapper, FillGatherTask, FillGatherTaskDTO> implements FillGatherTaskService {
|
|
|
|
|
|
+ private final FillGatherInfoMapper fillGatherInfoMapper;
|
|
|
+ private final FillInfoMapper fillInfoMapper;
|
|
|
+ private final FillGatherTaskDetailMapper fillGatherTaskDetailMapper;
|
|
|
+ private final SysUserMapper sysUserMapper;
|
|
|
+ private final FillUpdateRecordMapper fillUpdateRecordMapper;
|
|
|
@Override
|
|
|
public int batchDelete(List<String> ids) {
|
|
|
Weekend<FillGatherTask> weekend = new Weekend<>(FillGatherTask.class);
|
|
@@ -47,4 +69,263 @@ public class FillGatherTaskServiceImpl extends BaseServiceImpl<FillGatherTaskMap
|
|
|
return new MyPage(mapper.selectList(record));
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public FillGatherTask saveModelByDTO(FillGatherTaskDTO model) {
|
|
|
+ model.setTotalNum(model.getSbIds().size());
|
|
|
+ model.setWaitNum(model.getTotalNum());
|
|
|
+ FillGatherTask task = super.saveModelByDTO(model);
|
|
|
+ // 1、获取巡检内容
|
|
|
+ String content = getContentByGatherId(model.getGatherId());
|
|
|
+ // 2、根据设备IDs,生成内容列表并保存
|
|
|
+ saveDetails(content,model.getSbIds(),task.getId());
|
|
|
+ // 3、通知相关人员(巡检人和主管)
|
|
|
+ sendMessageToChecker(task,1);
|
|
|
+ sendMessageToChecker(task,2);
|
|
|
+ // 4、启动超时监控预警信息
|
|
|
+ int initMin = model.getRequireHour()*60;
|
|
|
+ int hours = model.getWarningHour() == null ? initMin + 120 : model.getWarningHour()*60 + initMin;
|
|
|
+ RedisUtils.setString(RedisKeyConstants.EXPIRE_BUSINESS_KEY_FILL_PREFIX + RedisKeyConstants.EXPIRE_BUSINESS_SEP + task.getId(), task.getId(), hours, TimeUnit.MINUTES);
|
|
|
+ return task;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handlePauseTask(FillGatherTaskDTO model) {
|
|
|
+ FillGatherTask task = mapper.selectByPrimaryKey(model.getId());
|
|
|
+ boolean overTimeFlag = Boolean.FALSE;
|
|
|
+ // 修改任务状态
|
|
|
+ FillGatherTask updTask = new FillGatherTask();
|
|
|
+ FillUpdateRecord record = new FillUpdateRecord();
|
|
|
+ record.setUpdateUserId(task.getCheckLeader());
|
|
|
+ record.setTaskId(task.getId());
|
|
|
+ record.setCreatedUserId(task.getChecker());
|
|
|
+ record.setCreatedTime(LocalDateTime.now());
|
|
|
+ record.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ if(model.getPauseType() == 1){
|
|
|
+ record.setType(FillUpdateRecordTypeEnum.PAUSE.getValue());
|
|
|
+ updTask.setStatus(FillGatherTaskStatusEnum.PAUSE.getValue());
|
|
|
+ }else if(model.getPauseType() == 2){
|
|
|
+ // 取消暂停
|
|
|
+ overTimeFlag = Boolean.TRUE;
|
|
|
+ updTask.setRequireHour(model.getRequireHour());
|
|
|
+ updTask.setStatus(FillGatherTaskStatusEnum.PROCESSING.getValue());
|
|
|
+ record.setType(FillUpdateRecordTypeEnum.PAUSE_END.getValue());
|
|
|
+ }
|
|
|
+ updTask.setUpdateTime(LocalDateTime.now());
|
|
|
+ updTask.setUpdateUserId(SecurityUtils.getUserInfo().getUserId());
|
|
|
+ updTask.setUpdateUserName(SecurityUtils.getUserInfo().getUsername());
|
|
|
+ mapper.updateByPrimaryKeySelective(updTask);
|
|
|
+ // 添加修改记录
|
|
|
+ fillUpdateRecordMapper.insert(record);
|
|
|
+ // 启动超时监控
|
|
|
+ if(overTimeFlag){
|
|
|
+ RedisUtils.setString(RedisKeyConstants.EXPIRE_BUSINESS_KEY_FILL_PREFIX + RedisKeyConstants.EXPIRE_BUSINESS_SEP + task.getId(), task.getId(), model.getRequireHour()*60, TimeUnit.MINUTES);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void overTimeTask(FillGatherTaskDTO model) {
|
|
|
+ FillGatherTask task = mapper.selectByPrimaryKey(model.getId());
|
|
|
+ // 修正巡检任务状态
|
|
|
+ FillGatherTask updTask = new FillGatherTask();
|
|
|
+ updTask.setId(model.getId());
|
|
|
+ updTask.setStatus(FillGatherTaskStatusEnum.LATE.getValue());
|
|
|
+ updTask.setLateHistoryHours(task.getLateHistoryHours() == null ? model.getExtrahours() : task.getLateHistoryHours() + model.getExtrahours());
|
|
|
+ updTask.setRequireHour(task.getRequireHour() + model.getExtrahours());
|
|
|
+ updTask.setUpdateTime(LocalDateTime.now());
|
|
|
+ updTask.setUpdateUserId(SecurityUtils.getUserInfo().getUserId());
|
|
|
+ updTask.setUpdateUserName(SecurityUtils.getUserInfo().getUsername());
|
|
|
+ // 保存巡检更新记录
|
|
|
+ FillUpdateRecord record = new FillUpdateRecord();
|
|
|
+ record.setUpdateUserId(task.getCheckLeader());
|
|
|
+ record.setTaskId(task.getId());
|
|
|
+ record.setCreatedUserId(task.getChecker());
|
|
|
+ record.setCreatedTime(LocalDateTime.now());
|
|
|
+ record.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ record.setLateHour(model.getExtrahours());
|
|
|
+ record.setType(FillUpdateRecordTypeEnum.LATE.getValue());
|
|
|
+ fillUpdateRecordMapper.insert(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void dispatchTask(FillGatherTaskDTO model) {
|
|
|
+ FillGatherTask task = mapper.selectByPrimaryKey(model.getId());
|
|
|
+ FillGatherTask updTask = new FillGatherTask();
|
|
|
+ updTask.setId(task.getId());
|
|
|
+ updTask.setTaskType(2);
|
|
|
+ updTask.setStatus(FillGatherTaskStatusEnum.PROCESSING.getValue());
|
|
|
+ updTask.setChecker(model.getAnotherChecker());
|
|
|
+ updTask.setUpdateUserName(SecurityUtils.getUserInfo().getUsername());
|
|
|
+ updTask.setUpdateUserId(SecurityUtils.getUserInfo().getUserId());
|
|
|
+ updTask.setRequireHour(model.getRequireHour());
|
|
|
+ updTask.setUpdateTime(LocalDateTime.now());
|
|
|
+ mapper.updateByPrimaryKeySelective(updTask);
|
|
|
+ // 记录
|
|
|
+ FillUpdateRecord record = new FillUpdateRecord();
|
|
|
+ record.setUpdateUserId(task.getCheckLeader());
|
|
|
+ record.setTaskId(task.getId());
|
|
|
+ record.setCreatedUserId(updTask.getChecker());
|
|
|
+ record.setCreatedTime(LocalDateTime.now());
|
|
|
+ record.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ record.setType(FillUpdateRecordTypeEnum.DISPATCH.getValue());
|
|
|
+ fillUpdateRecordMapper.insert(record);
|
|
|
+ // 给被转派人发送信息
|
|
|
+ sendMessageToChecker(updTask,1);
|
|
|
+ // 启动超时监控
|
|
|
+ int initMin = task.getWarningHour()*60;
|
|
|
+ int hours = initMin + model.getRequireHour()*60;
|
|
|
+ RedisUtils.setString(RedisKeyConstants.EXPIRE_BUSINESS_KEY_FILL_PREFIX + RedisKeyConstants.EXPIRE_BUSINESS_SEP + task.getId(), task.getId(), hours, TimeUnit.MINUTES);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handleFillInfo(FillGatherTaskDTO model) {
|
|
|
+ // 已填报数据
|
|
|
+ FillGatherTask task = mapper.selectByPrimaryKey(model.getId());
|
|
|
+ FillGatherTask updTask = new FillGatherTask();
|
|
|
+ int waitNum = task.getTotalNum() - getFilledDataNum(model.getDetails());
|
|
|
+ updTask.setId(task.getId());
|
|
|
+ updTask.setWaitNum(waitNum);
|
|
|
+ if(waitNum == 0){
|
|
|
+ updTask.setStatus(FillGatherTaskStatusEnum.COMPLETED.getValue());
|
|
|
+ }
|
|
|
+ mapper.updateByPrimaryKeySelective(updTask);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存填报内容
|
|
|
+ * @param details
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private int getFilledDataNum(List<FillGatherTaskDetailDTO> details){
|
|
|
+ int num = 0;
|
|
|
+ for(FillGatherTaskDetailDTO detail : details){
|
|
|
+ FillGatherTaskDetail updDetail = new FillGatherTaskDetail();
|
|
|
+ updDetail.setId(detail.getId());
|
|
|
+ // 判断是否完成填报
|
|
|
+ isCompleted(detail.getContent());
|
|
|
+ updDetail.setContent(detail.getContent());
|
|
|
+ updDetail.setUpdateUserName(SecurityUtils.getUserInfo().getUsername());
|
|
|
+ updDetail.setUpdateUserId(SecurityUtils.getUserInfo().getUserId());
|
|
|
+ updDetail.setUpdateTime(LocalDateTime.now());
|
|
|
+ if(isCompleted(detail.getContent())){
|
|
|
+ updDetail.setStatus(1);
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+ fillGatherTaskDetailMapper.updateByPrimaryKeySelective(updDetail);
|
|
|
+ }
|
|
|
+ return num;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单项是否完成填报
|
|
|
+ * @param content
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean isCompleted(String content){
|
|
|
+ boolean flag = Boolean.TRUE;
|
|
|
+ JSONArray array = JSON.parseArray(content);
|
|
|
+ for(int i=0;i<array.size();i++){
|
|
|
+ JSONObject jsonObject = array.getJSONObject(i);
|
|
|
+ if(StringUtils.isBlank(jsonObject.getString("fillValue"))){
|
|
|
+ flag = Boolean.FALSE;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FillGatherTaskVO getVOById(String id) {
|
|
|
+ FillGatherTask task = mapper.selectByPrimaryKey(id);
|
|
|
+ FillGatherTaskVO vo = BeanConverterUtil.copyObjectProperties(task,FillGatherTaskVO.class);
|
|
|
+ vo.setDetails(fillGatherTaskDetailMapper.selectVOByTaskId(id));
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 给巡检人发送消息
|
|
|
+ * @param task
|
|
|
+ * @param type 1 巡检人 2 巡检主管
|
|
|
+ */
|
|
|
+ private void sendMessageToChecker(FillGatherTask task,Integer type){
|
|
|
+ SysUser user = null; // 用户
|
|
|
+ String info = ""; // 站内信内容
|
|
|
+ String[] values = new String[]{"你有一条巡检任务!","请知悉"}; // 默认是巡检人
|
|
|
+ switch (type){
|
|
|
+ case 1 :
|
|
|
+ user = sysUserMapper.selectByPrimaryKey(task.getChecker());
|
|
|
+ info = MessageTemplateUtil.getFillGatherTaskNoticeForChecker(task.getName());
|
|
|
+ break;
|
|
|
+ case 2 :
|
|
|
+ user = sysUserMapper.selectByPrimaryKey(task.getCheckLeader());
|
|
|
+ info = MessageTemplateUtil.getFillGatherTaskNoticeForLeader(task.getName(),user.getRealName());
|
|
|
+ values = new String[]{"你有一条待监管的巡检任务!","请知悉"};
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // 1、站内信
|
|
|
+ SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.FILL_TASK.getValue(), WorkplaceBacklogDetailTypeEnum.FILL_TASK_NOTICE.getValue(),
|
|
|
+ task.getId(), info, task.getId(), ListUtils.newArrayList(user.getUserId()), ListUtils.newArrayList(user.getEmail())));
|
|
|
+ // 2、微信
|
|
|
+ String wechatTemplateId = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_NOTICE_SUCCESS_WECHAT_TEMPLATE_ID.name());
|
|
|
+ String detailUrl = "pages/repair-detail/repair-detail?detailId=" + task.getId();
|
|
|
+ SendMessageUtils.sendWechatNew(ListUtils.newArrayList(user.getWxOpenId()),detailUrl,values,wechatTemplateId);
|
|
|
+ // 3、短信
|
|
|
+ SendMessageUtils.sendCommonSms(ListUtils.newArrayList(user.getPhone()),info);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取巡检标准json
|
|
|
+ * @param gatherId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getContentByGatherId(String gatherId){
|
|
|
+ List<FillInfoVO> contents = new ArrayList<>();
|
|
|
+ List<FillGatherInfo> infos = fillGatherInfoMapper.select(new FillGatherInfo().setGatherId(gatherId));
|
|
|
+ for(FillGatherInfo info : infos){
|
|
|
+ FillInfo fillInfo = fillInfoMapper.selectByPrimaryKey(info.getInfoId());
|
|
|
+ FillInfoVO vo = new FillInfoVO();
|
|
|
+ vo.setName(fillInfo.getName());
|
|
|
+ vo.setRemark(fillInfo.getRemark());
|
|
|
+ vo.setSelectValue(fillInfo.getSelectValue());
|
|
|
+ vo.setType(fillInfo.getType());
|
|
|
+ contents.add(vo);
|
|
|
+ }
|
|
|
+ return JsonUtils.objectToJson(contents);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ List<FillInfoVO> contents = new ArrayList<>();
|
|
|
+ for(int i=0;i<3;i++){
|
|
|
+ FillInfoVO vo = new FillInfoVO();
|
|
|
+ vo.setName("12");
|
|
|
+ vo.setRemark("12");
|
|
|
+ vo.setSelectValue("[\"value\" : \"正常\",\"value\" : \"不良\" ]");
|
|
|
+ vo.setType(1);
|
|
|
+ vo.setFillValue("");
|
|
|
+ contents.add(vo);
|
|
|
+ }
|
|
|
+ System.out.println(JsonUtils.objectToJson(contents));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存巡检具体填报项
|
|
|
+ * @param content
|
|
|
+ * @param sbIds
|
|
|
+ * @param taskId
|
|
|
+ */
|
|
|
+ private void saveDetails(String content,List<String> sbIds,String taskId){
|
|
|
+ List<FillGatherTaskDetail> details = new ArrayList<>();
|
|
|
+ for(String sbId : sbIds){
|
|
|
+ FillGatherTaskDetail detail = new FillGatherTaskDetail();
|
|
|
+ detail.setContent(content);
|
|
|
+ detail.setCreatedTime(LocalDateTime.now());
|
|
|
+ detail.setCreatedUserId(SecurityUtils.getUserInfo().getUserId());
|
|
|
+ detail.setCreatedUserName(SecurityUtils.getUserInfo().getUsername());
|
|
|
+ detail.setSbId(sbId);
|
|
|
+ detail.setTaskId(taskId);
|
|
|
+ detail.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ details.add(detail);
|
|
|
+ }
|
|
|
+ fillGatherTaskDetailMapper.insertListforComplex(details);
|
|
|
+ }
|
|
|
+}
|