123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- package com.ruoyi.zhdd.service.impl;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.convert.Convert;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.json.JSONArray;
- import cn.hutool.json.JSONObject;
- import cn.hutool.json.JSONUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.ruoyi.common.constant.Constants;
- import com.ruoyi.common.core.domain.entity.SysDept;
- import com.ruoyi.common.core.domain.entity.SysUser;
- import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
- import com.ruoyi.common.core.page.PagePlus;
- import com.ruoyi.common.core.page.TableDataInfo;
- import com.ruoyi.common.exception.ServiceException;
- import com.ruoyi.common.utils.PageUtils;
- import com.ruoyi.common.utils.RedisUtils;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.system.service.ISysDeptService;
- import com.ruoyi.system.service.ISysUserService;
- import com.ruoyi.zhdd.domain.Incident;
- import com.ruoyi.zhdd.domain.IncidentProcess;
- import com.ruoyi.zhdd.domain.IncidentTask;
- import com.ruoyi.zhdd.domain.IncidentUser;
- import com.ruoyi.zhdd.domain.Plan;
- import com.ruoyi.zhdd.domain.bo.BacklogMessageUpdateBo;
- import com.ruoyi.zhdd.domain.bo.IncidentBo;
- import com.ruoyi.zhdd.domain.bo.MessagePushUser;
- import com.ruoyi.zhdd.domain.vo.IncidentVo;
- import com.ruoyi.zhdd.domain.vo.PlanTaskVo;
- import com.ruoyi.zhdd.domain.vo.PlanVo;
- import com.ruoyi.zhdd.feign.FeignBacklogInfoService;
- import com.ruoyi.zhdd.mapper.IncidentMapper;
- import com.ruoyi.zhdd.service.IIncidentProcessService;
- import com.ruoyi.zhdd.service.IIncidentService;
- import com.ruoyi.zhdd.service.IIncidentTaskService;
- import com.ruoyi.zhdd.service.IPlanService;
- import com.ruoyi.zhdd.service.IPlanTaskService;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.sql.Timestamp;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collection;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * 事件基础Service业务层处理
- *
- * @author xitong
- * @date 2021-09-28
- */
- @Service
- @Slf4j
- public class IncidentServiceImpl extends ServicePlusImpl<IncidentMapper, Incident, IncidentVo> implements IIncidentService {
- @Autowired
- private IIncidentProcessService incidentProcessService;
- @Autowired
- private ISysUserService sysUserService;
- @Autowired
- private ISysDeptService sysDeptService;
- @Autowired
- private IIncidentTaskService incidentTaskService;
- @Autowired
- private FeignBacklogInfoService feignBacklogInfoService;
- @Autowired
- private IPlanService iPlanService;
- @Autowired
- private IPlanTaskService planTaskService;
- @Override
- public IncidentVo queryById(String id) {
- return getVoById(id);
- }
- @Override
- public TableDataInfo<IncidentVo> queryPageList(IncidentBo bo) {
- PagePlus<Incident, IncidentVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo));
- return PageUtils.buildDataInfo(result);
- }
- @Override
- public List<IncidentVo> queryList(IncidentBo bo) {
- return listVo(buildQueryWrapper(bo));
- }
- private LambdaQueryWrapper<Incident> buildQueryWrapper(IncidentBo bo) {
- Map<String, Object> params = bo.getParams();
- LambdaQueryWrapper<Incident> lqw = Wrappers.lambdaQuery();
- lqw.eq(bo.getType() != null, Incident::getType, bo.getType());
- lqw.eq(bo.getLevel() != null, Incident::getLevel, bo.getLevel());
- lqw.eq(StringUtils.isNotBlank(bo.getAddr()), Incident::getAddr, bo.getAddr());
- lqw.eq(StringUtils.isNotBlank(bo.getLocations()), Incident::getLocations, bo.getLocations());
- lqw.eq(StringUtils.isNotBlank(bo.getCreateDept()), Incident::getCreateDept, bo.getCreateDept());
- lqw.eq(StringUtils.isNotBlank(bo.getSource()), Incident::getSource, bo.getSource());
- lqw.eq(StringUtils.isNotBlank(bo.getDes()), Incident::getDes, bo.getDes());
- lqw.eq(StringUtils.isNotBlank(bo.getPic()), Incident::getPic, bo.getPic());
- lqw.eq(StringUtils.isNotBlank(bo.getVideo()), Incident::getVideo, bo.getVideo());
- lqw.eq(StringUtils.isNotBlank(bo.getExpr1()), Incident::getExpr1, bo.getExpr1());
- lqw.eq(StringUtils.isNotBlank(bo.getExpr2()), Incident::getExpr2, bo.getExpr2());
- lqw.eq(StringUtils.isNotBlank(bo.getExprJson()), Incident::getExprJson, bo.getExprJson());
- lqw.like(StringUtils.isNotBlank(bo.getName()), Incident::getName, bo.getName());
- lqw.eq(bo.getStatus() != null, Incident::getStatus, bo.getStatus());
- if (StrUtil.isNotBlank(bo.getStatuss())) {
- lqw.in(Incident::getStatus, Arrays.stream(bo.getStatuss().split(",")).map(Integer::parseInt).collect(Collectors.toList()));
- }
- lqw.eq(bo.getMadinDept() != null, Incident::getMadinDept, bo.getMadinDept());
- lqw.eq(StringUtils.isNotBlank(bo.getAssistDept()), Incident::getAssistDept, bo.getAssistDept());
- if (params.get("beginTime") != null && params.get("endTime") != null) {
- lqw.between(Incident::getCreateTime, Timestamp.valueOf(Convert.toStr(params.get("beginTime")) + " 00:00:00"), Timestamp.valueOf(Convert.toStr(params.get("endTime")) + " 23:59:59"));
- }
- lqw.in(bo.getLevels() != null && bo.getLevels().size() > 0, Incident::getLevel, bo.getLevels());
- if (bo.getIds() != null && bo.getIds().size() > 0) {
- lqw.in(Incident::getId, bo.getIds());
- }
- lqw.orderByDesc(Incident::getCreateTime);
- return lqw;
- }
- @Override
- public String insertByBo(IncidentBo bo) {
- Incident add = BeanUtil.toBean(bo, Incident.class);
- add.setExprJson(JSONUtil.toJsonStr(bo.getMessagePushUsers()));
- boolean save = save(add);
- JSONObject jsonObject = new JSONObject();
- jsonObject.set("des", "事件接报");
- jsonObject.set("incidentId", add.getId());
- jsonObject.set("incidentStatus", 2);
- RedisUtils.publish(Constants.PROCESS_RECORD, jsonObject, msg -> {
- log.info("事件处置详情消息 => " + msg);
- });
- return add.getId();
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Boolean updateByBo(IncidentBo bo) {
- bo.setCreateBy(null);
- bo.setCreateDept(null);
- bo.setAssistDept(StrUtil.nullToEmpty(bo.getAssistDept()));
- bo.setAssistTaskUser(StrUtil.nullToEmpty(bo.getAssistTaskUser()));
- bo.setAssistDeptUser(StrUtil.nullToEmpty(bo.getAssistDeptUser()));
- // 是否为状态变更
- boolean flag;
- // 查询变更前信息
- IncidentVo beforeInfo = getVoById(bo.getId());
- log.info("事件变更前信息:{}", beforeInfo);
- log.info("事件变更后信息:{}", bo);
- if (beforeInfo != null) {
- flag = !(beforeInfo.getStatus().equals(bo.getStatus()));
- } else {
- throw new ServiceException("事件不存在!");
- }
- Incident update = BeanUtil.toBean(bo, Incident.class);
- // 待删除事件用户关系的array
- JSONArray removeJsonArray = new JSONArray();
- // 待新增事件用户关系的array
- JSONArray saveJsonArray = new JSONArray();
- // 待发送消息的jsonObject
- JSONObject sendJsonObject = new JSONObject();
- if (flag && bo.getStatus() == 3) {
- // 第一次派发(只派发给主办人员)
- // 待处置状态
- if (StrUtil.isBlank(bo.getMadinDept())) {
- throw new ServiceException("请选择主办单位!");
- }
- if (StrUtil.isBlank(bo.getMadinTaskUser())) {
- throw new ServiceException("请选择主办单位处置人员!");
- }
- // 冗余主办
- SysDept sysDept = sysDeptService.selectDeptById(bo.getMadinDept());
- if (sysDept != null) {
- update.setMadinDeptText(sysDept.getDeptName());
- }
- // 组装人员数据
- // 主办单位处置人员
- for (MessagePushUser messagePushUser : JSONUtil.toList(bo.getMadinTaskUser(), MessagePushUser.class)) {
- IncidentUser save = new IncidentUser();
- save.setIncidentId(bo.getId());
- save.setUserId(messagePushUser.getUserId());
- save.setSource("2");
- saveJsonArray.add(save);
- }
- // 主办单位通知人员
- if (StrUtil.isNotBlank(bo.getMadinDeptUser())) {
- for (MessagePushUser messagePushUser : JSONUtil.toList(bo.getMadinDeptUser(), MessagePushUser.class)) {
- IncidentUser save = new IncidentUser();
- save.setIncidentId(bo.getId());
- save.setUserId(messagePushUser.getUserId());
- save.setSource("6");
- saveJsonArray.add(save);
- }
- }
- } else if (!flag
- && bo.getStatus() == 3
- && (!StrUtil.equals(bo.getAssistDept(), beforeInfo.getAssistDept())
- // || !StrUtil.equals(bo.getCommander(), beforeInfo.getCommander())
- || !StrUtil.equals(bo.getAssistTaskUser(), beforeInfo.getAssistTaskUser())
- || !StrUtil.equals(bo.getAssistDeptUser(), beforeInfo.getAssistDeptUser()))) {
- // 协办部门派发或再次对协办修改
- // 重新冗余协办部门、总指挥
- /*if (StrUtil.isBlank(bo.getCommander())) {
- throw new ServiceException("请选择总指挥!");
- }*/
- if (StrUtil.isNotBlank(bo.getCommander())) {
- SysUser commanderText = sysUserService.selectUserById(bo.getCommander());
- if (commanderText != null) {
- update.setCommanderText(commanderText.getNickName());
- }
- }
- if (StrUtil.isBlank(bo.getAssistDept())) {
- update.setAssistDeptText("");
- } else {
- // 增加了协办单位后,协办的处置人员非空
- if (StrUtil.isBlank(bo.getAssistTaskUser())) {
- throw new ServiceException("请选择协办单位处置人员!");
- }
- if (!StrUtil.equals(beforeInfo.getAssistDept(), bo.getAssistDept())) {
- List<SysDept> sysDepts = sysDeptService.listByIds(Arrays.asList(bo.getAssistDept().split(",")));
- if (sysDepts != null && sysDepts.size() > 0) {
- update.setAssistDeptText(sysDepts.stream().map(SysDept::getDeptName).collect(Collectors.joining(",")));
- }
- }
- }
- // 分析变更的派发对象
- // 变更的总指挥(目前需求:总指挥不能变更)
- String oldCommander = beforeInfo.getCommander();
- String newCommander = bo.getCommander();
- /*if (StrUtil.isNotBlank(oldCommander) && !StrUtil.equals(oldCommander, newCommander)) {
- // 删除关系
- IncidentUser remove = new IncidentUser();
- remove.setIncidentId(bo.getId());
- remove.setUserId(oldCommander);
- remove.setSource("5");
- removeJsonArray.add(remove);
- }*/
- // 将总指挥加入到关系
- if (StrUtil.isNotBlank(newCommander) && !StrUtil.equals(oldCommander, newCommander)) {
- IncidentUser save = new IncidentUser();
- save.setIncidentId(bo.getId());
- save.setUserId(newCommander);
- save.setSource("5");
- saveJsonArray.add(save);
- }
- // 变更的协办处置人员
- List<MessagePushUser> oldAssistTaskUser = JSONUtil.toList(StrUtil.blankToDefault(beforeInfo.getAssistTaskUser(), "[]"), MessagePushUser.class);
- List<MessagePushUser> newAssistTaskUser = JSONUtil.toList(StrUtil.blankToDefault(bo.getAssistTaskUser(), "[]"), MessagePushUser.class);
- List<MessagePushUser> removeAssistTaskUser = CollUtil.subtractToList(oldAssistTaskUser, newAssistTaskUser);
- List<MessagePushUser> addAssistTaskUser = CollUtil.subtractToList(newAssistTaskUser, oldAssistTaskUser);
- for (MessagePushUser messagePushUser : removeAssistTaskUser) {
- // 删除关系
- IncidentUser remove = new IncidentUser();
- remove.setIncidentId(bo.getId());
- remove.setUserId(messagePushUser.getUserId());
- remove.setSource("4");
- removeJsonArray.add(remove);
- }
- for (MessagePushUser messagePushUser : addAssistTaskUser) {
- IncidentUser save = new IncidentUser();
- save.setIncidentId(bo.getId());
- save.setUserId(messagePushUser.getUserId());
- save.setSource("4");
- saveJsonArray.add(save);
- }
- // 变更的协办通知人员
- List<MessagePushUser> oldAssistDeptUser = JSONUtil.toList(StrUtil.blankToDefault(beforeInfo.getAssistDeptUser(), "[]"), MessagePushUser.class);
- List<MessagePushUser> newAssistDeptUser = JSONUtil.toList(StrUtil.blankToDefault(bo.getAssistDeptUser(), "[]"), MessagePushUser.class);
- List<MessagePushUser> removeAssistDeptUser = CollUtil.subtractToList(oldAssistDeptUser, newAssistDeptUser);
- List<MessagePushUser> addAssistDeptUser = CollUtil.subtractToList(newAssistDeptUser, oldAssistDeptUser);
- for (MessagePushUser messagePushUser : removeAssistDeptUser) {
- // 删除关系
- IncidentUser remove = new IncidentUser();
- remove.setIncidentId(bo.getId());
- remove.setUserId(messagePushUser.getUserId());
- remove.setSource("6");
- removeJsonArray.add(remove);
- }
- for (MessagePushUser messagePushUser : addAssistDeptUser) {
- IncidentUser save = new IncidentUser();
- save.setIncidentId(bo.getId());
- save.setUserId(messagePushUser.getUserId());
- save.setSource("6");
- saveJsonArray.add(save);
- }
- if (addAssistDeptUser.size() > 0 || addAssistTaskUser.size() > 0) {
- sendJsonObject.set("des", "再次派发总指挥及协办部门");
- sendJsonObject.set("incidentStatus", bo.getStatus());
- sendJsonObject.set("incidentId", bo.getId());
- sendJsonObject.set("messagePushUsers", CollUtil.unionDistinct(addAssistDeptUser, addAssistTaskUser));
- RedisUtils.publish(Constants.NOTICE_PUSH_SINGLE, sendJsonObject);
- }
- } else if (flag && bo.getStatus() == 4) {
- // 将待办变成已办
- // 查询待办的处置方案
- List<IncidentTask> taskList = incidentTaskService.list(Wrappers.<IncidentTask>lambdaQuery()
- .in(IncidentTask::getSendFlag, "2", "3")
- .eq(IncidentTask::getTaskSend, "1")
- .eq(IncidentTask::getBackLogFlag, "0"));
- if (taskList != null && taskList.size() > 0) {
- List<String> TaskIds = taskList.stream().map(IncidentTask::getId).collect(Collectors.toList());
- // 更新task中状态
- incidentTaskService.update(Wrappers.<IncidentTask>lambdaUpdate()
- .set(IncidentTask::getBackLogFlag, "1")
- .in(IncidentTask::getSendFlag, "2", "3")
- .eq(IncidentTask::getTaskSend, "1")
- .eq(IncidentTask::getBackLogFlag, "0"));
- // 去日志中找到相应的日志,更改待办变为已办
- List<IncidentProcess> processList = incidentProcessService.list(Wrappers.<IncidentProcess>lambdaQuery()
- .in(IncidentProcess::getTaskId, TaskIds)
- .in(IncidentProcess::getStatus, 2, 3));
- // 组装需要调用已办接口的数据
- if (processList != null && processList.size() > 0) {
- List<BacklogMessageUpdateBo> list = new ArrayList<>();
- for (IncidentProcess incidentProcess : processList) {
- BacklogMessageUpdateBo messageUpdateBo = new BacklogMessageUpdateBo();
- messageUpdateBo.setUuid(incidentProcess.getId());
- incidentProcess.setDes(incidentProcess.getDes().replace("【待办】", "【已办】"));
- list.add(messageUpdateBo);
- }
- Object o = feignBacklogInfoService.backlogMessageUpdate(list);
- log.info("消息待办办结返回结果:{}", o);
- incidentProcessService.updateBatchById(processList);
- }
- }
- }
- // 更新事件信息
- boolean b = updateById(update);
- if (removeJsonArray.size() > 0) {
- log.info("需要移除的用户事件关系:{}", removeJsonArray);
- RedisUtils.publish(Constants.INCIDENT_USER_DELETE, removeJsonArray);
- }
- if (saveJsonArray.size() > 0) {
- log.info("需要新增的用户事件关系:{}", saveJsonArray);
- RedisUtils.publish(Constants.INCIDENT_USER_BATCH, saveJsonArray);
- }
- if (flag) {
- if (bo.getStatus() == 3) {
- // 第一次派发给主办部门时
- RedisUtils.publish(Constants.NOTICE_PUSH, 1 + "A" + update.getId());
- return b;
- }
- // 事件状态的变更,将发送到处置日志中
- sendJsonObject.set("incidentId", update.getId());
- sendJsonObject.set("incidentStatus", update.getStatus());
- RedisUtils.publish(Constants.PROCESS_RECORD, sendJsonObject);
- }
- return b;
- }
- @Override
- public Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid) {
- if (isValid) {
- //TODO 做一些业务上的校验,判断是否需要校验
- }
- return removeByIds(ids);
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public void savePlanAndCreate(IncidentBo bo) {
- Incident update = BeanUtil.toBean(bo, Incident.class);
- boolean b = updateById(update);
- if (b) {
- // 根据预案生成处置方案
- List<PlanVo> voOne = iPlanService.listVo(Wrappers.<Plan>lambdaQuery().eq(Plan::getType, bo.getType()).eq(Plan::getCreateDept, bo.getPlanDept()));
- if (voOne != null && voOne.size() > 0) {
- Map<Integer, List<PlanTaskVo>> integerListMap = planTaskService.queryPlanTaskByPlanId(voOne.get(0).getId());
- if (integerListMap != null) {
- List<PlanTaskVo> planTaskVos = integerListMap.get(bo.getLevel());
- if (planTaskVos != null) {
- List<IncidentTask> incidentTaskList = new ArrayList<>();
- for (PlanTaskVo planTaskVo : planTaskVos) {
- IncidentTask task = new IncidentTask();
- task.setIncidentId(bo.getId());
- task.setTaskName(planTaskVo.getTaskName() + ":" + planTaskVo.getTaskDes());
- task.setSendFlag("1");
- incidentTaskList.add(task);
- }
- incidentTaskService.saveAll(incidentTaskList);
- }
- }
- }
- }
- }
- }
|