IncidentController.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. package com.ruoyi.web.controller.zhdd;
  2. import cn.afterturn.easypoi.entity.ImageEntity;
  3. import cn.afterturn.easypoi.word.WordExportUtil;
  4. import cn.hutool.core.collection.CollUtil;
  5. import cn.hutool.core.convert.Convert;
  6. import cn.hutool.core.date.DateUtil;
  7. import cn.hutool.core.io.FileUtil;
  8. import cn.hutool.core.util.ObjectUtil;
  9. import cn.hutool.core.util.StrUtil;
  10. import cn.hutool.http.HttpStatus;
  11. import cn.hutool.json.JSONArray;
  12. import cn.hutool.json.JSONObject;
  13. import cn.hutool.json.JSONUtil;
  14. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  15. import com.ruoyi.common.annotation.Log;
  16. import com.ruoyi.common.annotation.RepeatSubmit;
  17. import com.ruoyi.common.annotation.Security;
  18. import com.ruoyi.common.config.RuoYiConfig;
  19. import com.ruoyi.common.constant.Constants;
  20. import com.ruoyi.common.core.controller.BaseController;
  21. import com.ruoyi.common.core.domain.AjaxResult;
  22. import com.ruoyi.common.core.domain.TreeSelect;
  23. import com.ruoyi.common.core.domain.entity.SysDept;
  24. import com.ruoyi.common.core.domain.entity.SysUser;
  25. import com.ruoyi.common.core.domain.model.LoginUser;
  26. import com.ruoyi.common.core.page.TableDataInfo;
  27. import com.ruoyi.common.core.validate.AddGroup;
  28. import com.ruoyi.common.core.validate.EditGroup;
  29. import com.ruoyi.common.core.validate.QueryGroup;
  30. import com.ruoyi.common.enums.BusinessType;
  31. import com.ruoyi.common.utils.RedisUtils;
  32. import com.ruoyi.common.utils.StringUtils;
  33. import com.ruoyi.common.utils.UserUtil;
  34. import com.ruoyi.common.utils.poi.ExcelUtil;
  35. import com.ruoyi.system.service.ISysDeptService;
  36. import com.ruoyi.system.service.ISysDictDataService;
  37. import com.ruoyi.system.service.ISysUserService;
  38. import com.ruoyi.zhdd.domain.Incident;
  39. import com.ruoyi.zhdd.domain.IncidentProcess;
  40. import com.ruoyi.zhdd.domain.IncidentTask;
  41. import com.ruoyi.zhdd.domain.IncidentUser;
  42. import com.ruoyi.zhdd.domain.Plan;
  43. import com.ruoyi.zhdd.domain.PlanFile;
  44. import com.ruoyi.zhdd.domain.bo.IncidentBo;
  45. import com.ruoyi.zhdd.domain.bo.IncidentTasksBo;
  46. import com.ruoyi.zhdd.domain.bo.MessagePushUser;
  47. import com.ruoyi.zhdd.domain.vo.IncidentTaskVo;
  48. import com.ruoyi.zhdd.domain.vo.IncidentVo;
  49. import com.ruoyi.zhdd.domain.vo.PlanFileVo;
  50. import com.ruoyi.zhdd.domain.vo.PlanVo;
  51. import com.ruoyi.zhdd.feign.FeignNoticeInfoService;
  52. import com.ruoyi.zhdd.service.IIncidentProcessService;
  53. import com.ruoyi.zhdd.service.IIncidentService;
  54. import com.ruoyi.zhdd.service.IIncidentTaskService;
  55. import com.ruoyi.zhdd.service.IIncidentUserService;
  56. import com.ruoyi.zhdd.service.IPlanFileService;
  57. import com.ruoyi.zhdd.service.IPlanService;
  58. import com.ruoyi.zhdd.service.IPlanTaskService;
  59. import com.ruoyi.zhdd.service.IResourceDetailService;
  60. import io.swagger.annotations.Api;
  61. import io.swagger.annotations.ApiOperation;
  62. import lombok.RequiredArgsConstructor;
  63. import lombok.extern.slf4j.Slf4j;
  64. import org.apache.poi.xwpf.usermodel.XWPFDocument;
  65. import org.springframework.beans.factory.annotation.Autowired;
  66. import org.springframework.beans.factory.annotation.Value;
  67. import org.springframework.validation.annotation.Validated;
  68. import org.springframework.web.bind.annotation.*;
  69. import javax.servlet.http.HttpServletRequest;
  70. import javax.servlet.http.HttpServletResponse;
  71. import javax.validation.constraints.NotEmpty;
  72. import javax.validation.constraints.NotNull;
  73. import java.io.File;
  74. import java.io.FileOutputStream;
  75. import java.io.OutputStream;
  76. import java.util.*;
  77. import java.util.stream.Collectors;
  78. /**
  79. * 事件基础Controller
  80. *
  81. * @author xitong
  82. * @date 2021-09-28
  83. */
  84. @Validated
  85. @Api(value = "事件基础控制器", tags = {"事件基础管理"})
  86. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  87. @RestController
  88. @RequestMapping("/zhdd/incident")
  89. @Slf4j
  90. public class IncidentController extends BaseController {
  91. private final IIncidentService iIncidentService;
  92. private final IIncidentTaskService incidentTaskService;
  93. private final IIncidentProcessService processService;
  94. private final IPlanTaskService planTaskService;
  95. private final IPlanService planService;
  96. private final IPlanFileService planFileService;
  97. private final ISysDictDataService sysDictDataService;
  98. private final FeignNoticeInfoService feignNoticeInfoService;
  99. private final IResourceDetailService resourceDetailService;
  100. private final ISysUserService sysUserService;
  101. private final ISysDeptService sysDeptService;
  102. private final IIncidentUserService incidentUserService;
  103. @Value("${spring.profiles.active}")
  104. private String env;
  105. public static final String NEW_LINE = "\r\n";
  106. /**
  107. * 查询事件基础列表
  108. */
  109. @ApiOperation("查询事件基础列表")
  110. @GetMapping("/list")
  111. @Security
  112. public TableDataInfo<IncidentVo> list(@Validated(QueryGroup.class) IncidentBo bo) {
  113. if ("app".equals(bo.getQuerySource())) {
  114. bo.setStatus(3);
  115. }
  116. if (StrUtil.isNotBlank(bo.getStatuss())) {
  117. bo.setStatuss(bo.getStatuss().replace("-", ""));
  118. }
  119. // 根据当前用户的角色及部门筛选可以查询到的事件
  120. LoginUser cacheLoginUser = UserUtil.getCacheLoginUser();
  121. // 查询角色如果包含admin的,直接查询全部
  122. Set<String> userRole = cacheLoginUser.getUserRole();
  123. boolean admin = CollUtil.containsAny(userRole, CollUtil.newHashSet("admin"));
  124. if (!admin) {
  125. // 查询当前用户和哪些事件相关
  126. List<Object> objects = incidentUserService.listObjs(Wrappers.<IncidentUser>lambdaQuery().select(IncidentUser::getIncidentId).eq(IncidentUser::getUserId, cacheLoginUser.getUserId()));
  127. if (objects.size() == 0) {
  128. TableDataInfo<IncidentVo> rspData = new TableDataInfo<>();
  129. rspData.setCode(HttpStatus.HTTP_OK);
  130. rspData.setMsg("查询成功");
  131. rspData.setRows(Collections.emptyList());
  132. rspData.setTotal(0);
  133. rspData.setPageSize(bo.getPageSize());
  134. rspData.setPageNum(bo.getPageNum());
  135. return rspData;
  136. }
  137. HashSet<Object> incidentIdSet = CollUtil.newHashSet(objects);
  138. bo.setIds(incidentIdSet);
  139. }
  140. return iIncidentService.queryPageList(bo);
  141. }
  142. /**
  143. * 获取事件基础详细信息
  144. */
  145. @ApiOperation("获取事件基础详细信息")
  146. @GetMapping("/{id}")
  147. // @Security
  148. public AjaxResult<Map<String, Object>> getInfo(@NotNull(message = "主键不能为空")
  149. @PathVariable("id") String id) {
  150. Map<String, Object> map = new HashMap<>();
  151. List<PlanFileVo> planFileVos = new ArrayList<>();
  152. IncidentVo incidentVo = iIncidentService.queryById(id);
  153. if (incidentVo == null) {
  154. return AjaxResult.success(map);
  155. }
  156. // 查询上报人、上报组织信息
  157. SysUser sysUser = sysUserService.selectUserByUserName(incidentVo.getCreateBy());
  158. if (sysUser != null) {
  159. incidentVo.setCreateBy(sysUser.getNickName());
  160. }
  161. SysDept sysDept = sysDeptService.selectDeptById(incidentVo.getCreateDept());
  162. if (sysDept != null) {
  163. incidentVo.setCreateDept(sysDept.getDeptName());
  164. }
  165. // 组装主办和协办部门数据树
  166. List<TreeSelect> madinList = new ArrayList<>();
  167. if (StrUtil.isNotBlank(incidentVo.getMadinDept())) {
  168. TreeSelect madin = new TreeSelect();
  169. madin.setId(incidentVo.getMadinDept());
  170. madin.setLabel(incidentVo.getMadinDeptText());
  171. madinList.add(madin);
  172. }
  173. incidentVo.setMadinDeptList(madinList);
  174. List<TreeSelect> assistList = new ArrayList<>();
  175. if (StrUtil.isNotBlank(incidentVo.getAssistDept())) {
  176. for (int i = 0; i < incidentVo.getAssistDept().split(",").length; i++) {
  177. TreeSelect assist = new TreeSelect();
  178. assist.setId(incidentVo.getAssistDept().split(",")[i]);
  179. if (incidentVo.getAssistDept().split(",").length == incidentVo.getAssistDeptText().split(",").length) {
  180. assist.setLabel(incidentVo.getAssistDeptText().split(",")[i]);
  181. }
  182. assistList.add(assist);
  183. }
  184. }
  185. incidentVo.setAssistDeptList(assistList);
  186. // 查询所属预案
  187. List<PlanVo> voOne = planService.listVo(Wrappers.<Plan>lambdaQuery().eq(Plan::getType, incidentVo.getType()).eq(Plan::getCreateDept, incidentVo.getPlanDept()));
  188. if (voOne != null && voOne.size() > 0) {
  189. map.put("baseTask", planTaskService.queryPlanTaskByPlanId(voOne.get(0).getId()));
  190. // 查询预案附件
  191. planFileVos = planFileService.listVo(Wrappers.<PlanFile>lambdaQuery().eq(PlanFile::getPlanId, voOne.get(0).getId()));
  192. } else {
  193. map.put("baseTask", null);
  194. }
  195. map.put("planFile", planFileVos);
  196. // 查询处置方案
  197. List<IncidentTaskVo> incidentTaskVos = incidentTaskService.listTaskInfo(id);
  198. map.put("task", incidentTaskVos);
  199. // 查询应急资源待办的发送时间
  200. Date resourceSendTime = null;
  201. Optional<IncidentTaskVo> any = incidentTaskVos.stream().filter(a -> StrUtil.equals(a.getSendFlag(), "3") && StrUtil.equals(a.getTaskSend(), "1")).findAny();
  202. if (any.isPresent()) {
  203. resourceSendTime = any.get().getCreateTime();
  204. }
  205. // 查询有没有发送过指令
  206. Optional<IncidentTaskVo> sendAny = incidentTaskVos.stream().filter(a -> StrUtil.equals(a.getTaskSend(), "1")).findAny();
  207. map.put("taskSendFlag", sendAny.isPresent());
  208. map.put("resourceSendTime", resourceSendTime);
  209. List<IncidentProcess> list = processService.list(Wrappers.<IncidentProcess>lambdaQuery()
  210. .eq(IncidentProcess::getIncidentId, id)
  211. // .in(IncidentProcess::getIncidentStatus, 3, 4, 5)
  212. .orderByAsc(IncidentProcess::getCreateTime));
  213. String distributeTime = "";
  214. String dealTime = "";
  215. String dealEndTime = "";
  216. if (!"dev".equals(env)) {
  217. for (IncidentProcess incidentProcess : list) {
  218. // 处理首次派发和首页处理的时间
  219. if (StrUtil.isBlank(distributeTime) && incidentProcess.getIncidentStatus() == 2 && StrUtil.contains(incidentProcess.getDes(), "事件派发")) {
  220. distributeTime = DateUtil.formatDateTime(incidentProcess.getCreateTime());
  221. }
  222. if (StrUtil.isBlank(dealTime) && incidentProcess.getIncidentStatus() == 3) {
  223. dealTime = DateUtil.formatDateTime(incidentProcess.getCreateTime());
  224. }
  225. if (StrUtil.isBlank(dealEndTime) && incidentProcess.getIncidentStatus() == 6 && StrUtil.contains(incidentProcess.getDes(), "事件办结")) {
  226. dealEndTime = DateUtil.formatDateTime(incidentProcess.getCreateTime());
  227. }
  228. if (incidentProcess.getStatus() == 1) {
  229. // 查询阅读情况
  230. JSONObject o = feignNoticeInfoService.messagePushInfoList("1", "2", incidentProcess.getId());
  231. log.info("查询消息阅读情况:{}", o);
  232. // 解析
  233. if (ObjectUtil.isNotEmpty(o)) {
  234. Integer total = o.getInt("total");
  235. if (total != null && total > 0) {
  236. JSONArray jsonArray = JSONUtil.parseObj(o.getJSONArray("rows").get(0)).getJSONArray("messageReadInfoList");
  237. StringBuilder unMessage = new StringBuilder();
  238. StringBuilder message = new StringBuilder();
  239. for (Object o1 : jsonArray) {
  240. JSONObject jsonObject = JSONUtil.parseObj(o1);
  241. if ("0".equals(jsonObject.getStr("readState"))) {
  242. // 未读
  243. unMessage.append(jsonObject.getStr("nickName")).append("、");
  244. } else if ("1".equals(jsonObject.getStr("readState"))) {
  245. // 已读
  246. message.append(jsonObject.getStr("nickName")).append("、");
  247. }
  248. }
  249. // 循环完之后,去除最后一个顿号
  250. incidentProcess.setUserRead(message.toString());
  251. incidentProcess.setUserUnRead(unMessage.toString());
  252. }
  253. }
  254. }
  255. }
  256. }
  257. map.put("process", list);
  258. // 物资使用情况
  259. map.put("resource", resourceDetailService.queryResourceAvailable(id));
  260. incidentVo.setDistributeTime(distributeTime);
  261. incidentVo.setDealTime(dealTime);
  262. incidentVo.setDealEndTime(dealEndTime);
  263. map.put("baseInfo", incidentVo);
  264. return AjaxResult.success(map);
  265. }
  266. @ApiOperation("获取事件执行日志详细信息")
  267. @GetMapping("/process/{id}")
  268. public AjaxResult<Map<String, Object>> getProcessInfo(@NotNull(message = "主键不能为空")
  269. @PathVariable("id") String id) {
  270. Map<String, Object> map = new HashMap<>();
  271. List<IncidentProcess> list = processService.list(Wrappers.<IncidentProcess>lambdaQuery()
  272. .eq(IncidentProcess::getIncidentId, id)
  273. .orderByAsc(IncidentProcess::getCreateTime));
  274. if (!"dev".equals(env)) {
  275. for (IncidentProcess incidentProcess : list) {
  276. if (incidentProcess.getStatus() == 1) {
  277. // 查询阅读情况
  278. JSONObject o = feignNoticeInfoService.messagePushInfoList("1", "2", incidentProcess.getId());
  279. // 解析
  280. if (ObjectUtil.isNotEmpty(o)) {
  281. Integer total = o.getInt("total");
  282. if (total != null && total > 0) {
  283. JSONArray jsonArray = JSONUtil.parseObj(o.getJSONArray("rows").get(0)).getJSONArray("messageReadInfoList");
  284. StringBuilder unMessage = new StringBuilder();
  285. StringBuilder message = new StringBuilder();
  286. for (Object o1 : jsonArray) {
  287. JSONObject jsonObject = JSONUtil.parseObj(o1);
  288. if ("0".equals(jsonObject.getStr("status"))) {
  289. // 未读
  290. unMessage.append(jsonObject.getStr("nickName")).append("、");
  291. } else if ("1".equals(jsonObject.getStr("status"))) {
  292. // 已读
  293. message.append(jsonObject.getStr("nickName")).append("、");
  294. }
  295. }
  296. // 循环完之后,去除最后一个顿号
  297. incidentProcess.setUserRead(message.toString());
  298. incidentProcess.setUserUnRead(unMessage.toString());
  299. }
  300. }
  301. }
  302. }
  303. }
  304. map.put("process", list);
  305. return AjaxResult.success(map);
  306. }
  307. /**
  308. * 新增事件基础
  309. */
  310. @ApiOperation("新增事件基础")
  311. // @Log(title = "事件基础", businessType = BusinessType.INSERT)
  312. @RepeatSubmit()
  313. @PostMapping()
  314. @Security
  315. public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody IncidentBo bo) {
  316. // 新增初始化为待派发状态
  317. bo.setStatus(2);
  318. LoginUser cacheLoginUser = UserUtil.getCacheLoginUser();
  319. bo.setCreateBy(cacheLoginUser.getUsername());
  320. bo.setCreateDept(cacheLoginUser.getUser().getDeptId());
  321. bo.setExpr1(cacheLoginUser.getUser().getPhonenumber());
  322. String id = iIncidentService.insertByBo(bo);
  323. // 待新增事件用户关系的array
  324. JSONArray saveJsonArray = new JSONArray();
  325. IncidentUser save = new IncidentUser();
  326. save.setIncidentId(id);
  327. save.setUserId(cacheLoginUser.getUserId());
  328. save.setSource("1");
  329. saveJsonArray.add(save);
  330. RedisUtils.publish(Constants.INCIDENT_USER_BATCH, saveJsonArray);
  331. return toAjax(true);
  332. }
  333. /**
  334. * 修改事件基础
  335. */
  336. @ApiOperation("修改事件基础")
  337. @RepeatSubmit()
  338. @PutMapping()
  339. @Security
  340. public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody IncidentBo bo) {
  341. return toAjax(iIncidentService.updateByBo(bo) ? 1 : 0);
  342. }
  343. /**
  344. * 删除事件基础
  345. */
  346. @ApiOperation("删除事件基础")
  347. @Log(title = "事件基础", businessType = BusinessType.DELETE)
  348. @DeleteMapping("/{ids}")
  349. public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
  350. @PathVariable String[] ids) {
  351. return toAjax(iIncidentService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
  352. }
  353. @ApiOperation("新增事件方案")
  354. // @Log(title = "事件方案", businessType = BusinessType.INSERT)
  355. @RepeatSubmit()
  356. @PostMapping("/task")
  357. public AjaxResult<Void> addTask(@Validated(AddGroup.class) @RequestBody IncidentTasksBo bo) {
  358. return toAjax(incidentTaskService.insertByBo(bo) ? 1 : 0);
  359. }
  360. @ApiOperation("删除事件方案")
  361. // @Log(title = "事件方案", businessType = BusinessType.DELETE)
  362. @DeleteMapping("/task/{ids}")
  363. public AjaxResult<Void> removeTask(@NotEmpty(message = "主键不能为空")
  364. @PathVariable String[] ids) {
  365. return toAjax(incidentTaskService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
  366. }
  367. @ApiOperation("事件方案发送")
  368. @RepeatSubmit()
  369. @PostMapping("/taskSend")
  370. public AjaxResult<Void> taskSend(@RequestBody IncidentTasksBo bo) {
  371. return toAjax(incidentTaskService.taskSend(bo) ? 1 : 0);
  372. }
  373. @ApiOperation("查询事件-用于首页地图展示")
  374. @GetMapping("/location")
  375. public AjaxResult<Map<String, List<IncidentVo>>> queryIncidentLocation() {
  376. List<IncidentVo> list = iIncidentService.listVo(Wrappers.<Incident>lambdaQuery().in(Incident::getStatus, 1, 2, 3));
  377. Map<Integer, List<IncidentVo>> collect = list.stream().collect(Collectors.groupingBy(IncidentVo::getStatus, Collectors.mapping(a -> a, Collectors.toList())));
  378. Map<String, List<IncidentVo>> result = new HashMap<>();
  379. result.put("预警事件", CollUtil.defaultIfEmpty(collect.get(2), new ArrayList<>()));
  380. // result.put("待派发", CollUtil.defaultIfEmpty(collect.get(2), new ArrayList<>()));
  381. result.put("处置", CollUtil.defaultIfEmpty(collect.get(3), new ArrayList<>()));
  382. return AjaxResult.success(result);
  383. }
  384. @ApiOperation("事件报告导出")
  385. @GetMapping("/download")
  386. public void download(@RequestParam String id, HttpServletRequest request, HttpServletResponse response) {
  387. // id为事件id
  388. Map<String, Object> map = new HashMap<>();
  389. IncidentVo incidentVo = iIncidentService.queryById(id);
  390. if (incidentVo != null) {
  391. map.put("name", incidentVo.getName());
  392. map.put("nowDate", DateUtil.today());
  393. if (ObjectUtil.isNotEmpty(incidentVo.getType())) {
  394. map.put("type", sysDictDataService.selectDictLabel("zhdd_incident_type", Convert.toStr(incidentVo.getType())));
  395. } else {
  396. map.put("type", "-");
  397. }
  398. map.put("createTime", DateUtil.formatDateTime(incidentVo.getCreateTime()));
  399. map.put("addr", incidentVo.getAddr());
  400. map.put("commanderText", StrUtil.blankToDefault(incidentVo.getCommanderText(), "无"));
  401. map.put("madinDeptText", StrUtil.blankToDefault(incidentVo.getMadinDeptText(), "部门无"));
  402. map.put("assistDeptText", StrUtil.blankToDefault(incidentVo.getAssistDeptText(), "部门无"));
  403. // 解析主办部门和协办部门人员
  404. String madinTaskUser = incidentVo.getMadinTaskUser();
  405. if (StrUtil.isNotBlank(madinTaskUser)) {
  406. List<MessagePushUser> messagePushUsers = JSONUtil.toList(madinTaskUser, MessagePushUser.class);
  407. map.put("madinDeptUser", messagePushUsers.stream().map(MessagePushUser::getNickName).collect(Collectors.joining(",")));
  408. } else {
  409. map.put("madinDeptUser", "人员无");
  410. }
  411. String assistTaskUser = incidentVo.getAssistTaskUser();
  412. if (StrUtil.isNotBlank(assistTaskUser)) {
  413. List<MessagePushUser> messagePushUsers = JSONUtil.toList(assistTaskUser, MessagePushUser.class);
  414. map.put("assistDeptUser", messagePushUsers.stream().map(MessagePushUser::getNickName).collect(Collectors.joining(",")));
  415. } else {
  416. map.put("assistDeptUser", "人员无");
  417. }
  418. map.put("conclusionDeal", StrUtil.blankToDefault(incidentVo.getConclusionDeal(), "无"));
  419. map.put("conclusion", StrUtil.blankToDefault(incidentVo.getConclusion(), "无"));
  420. /*if (StrUtil.isNotBlank(incidentVo.getSource())) {
  421. map.put("source", sysDictDataService.selectDictLabel("zhdd_incident_source", incidentVo.getSource()));
  422. } else {
  423. map.put("source", "-");
  424. }*/
  425. if (ObjectUtil.isNotEmpty(incidentVo.getLevel())) {
  426. map.put("level", sysDictDataService.selectDictLabel("zhdd_incident_level", Convert.toStr(incidentVo.getLevel())) + "级");
  427. } else {
  428. map.put("level", "-");
  429. }
  430. // 组装事件图片
  431. List<String> picList = StrUtil.split(incidentVo.getPic(), ",");
  432. List<ImageEntity> pics = new ArrayList<>();
  433. for (String s : picList) {
  434. ImageEntity imageEntity = new ImageEntity();
  435. imageEntity.setType(ImageEntity.Data);
  436. imageEntity.setHeight(300);
  437. imageEntity.setWidth(550);
  438. log.info("图片相对地址:{}", s);
  439. // 本地资源路径
  440. String localPath = RuoYiConfig.getProfile();
  441. // 数据库资源地址
  442. String downloadPath = localPath + StringUtils.substringAfter(s, Constants.RESOURCE_PREFIX);
  443. try {
  444. imageEntity.setData(FileUtil.readBytes(downloadPath));
  445. } catch (Exception e) {
  446. log.info("读取图片失败:{}", e.getMessage());
  447. continue;
  448. }
  449. pics.add(imageEntity);
  450. }
  451. // 查询处置过程
  452. List<IncidentProcess> incidentProcess = processService.list(Wrappers.<IncidentProcess>lambdaQuery()
  453. .eq(IncidentProcess::getIncidentId, id).orderByAsc(IncidentProcess::getCreateTime));
  454. Map<String, List<IncidentProcess>> processCollect = incidentProcess.stream().filter(a -> StrUtil.isNotBlank(a.getTaskId())).collect(Collectors.groupingBy(IncidentProcess::getTaskId));
  455. // 查询处置方案
  456. List<IncidentTaskVo> incidentTasks = incidentTaskService.listTaskInfo(id);
  457. if (incidentTasks != null && incidentTasks.size() > 0) {
  458. StringBuilder tasks = new StringBuilder();
  459. for (int i = 0; i < incidentTasks.size(); i++) {
  460. tasks.append(i + 1).append("、");
  461. // .append(incidentTasks.get(i).getTaskName()).append(NEW_LINE)
  462. // 查询指令对应的处置过程
  463. List<IncidentProcess> processList = processCollect.get(incidentTasks.get(i).getId());
  464. if (processList != null && processList.size() > 0) {
  465. String collect = processList.stream().map(IncidentProcess::getDes).collect(Collectors.joining(NEW_LINE + "\t"));
  466. tasks.append(collect).append(NEW_LINE).append("\t");
  467. String picCollect = processList.stream().map(IncidentProcess::getPic).collect(Collectors.joining(","));
  468. for (String s : StrUtil.split(picCollect, ",")) {
  469. ImageEntity imageEntity = new ImageEntity();
  470. imageEntity.setType(ImageEntity.Data);
  471. imageEntity.setHeight(300);
  472. imageEntity.setWidth(550);
  473. log.info("图片相对地址:{}", s);
  474. // 本地资源路径
  475. String localPath = RuoYiConfig.getProfile();
  476. // 数据库资源地址
  477. String downloadPath = localPath + StringUtils.substringAfter(s, Constants.RESOURCE_PREFIX);
  478. try {
  479. imageEntity.setData(FileUtil.readBytes(downloadPath));
  480. } catch (Exception e) {
  481. log.info("读取图片失败:{}", e.getMessage());
  482. continue;
  483. }
  484. pics.add(imageEntity);
  485. }
  486. }
  487. }
  488. map.put("tasks", tasks.toString());
  489. } else {
  490. map.put("tasks", "无");
  491. }
  492. map.put("pics", pics);
  493. }
  494. String fileName = "incident_" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + ".docx";
  495. try {
  496. XWPFDocument doc = WordExportUtil.exportWord07(
  497. "word/incidentDetail.docx", map);
  498. FileOutputStream fos = new FileOutputStream(ExcelUtil.getAbsoluteFile(fileName));
  499. doc.write(fos);
  500. // 设置强制下载不打开
  501. response.setContentType("application/force-download");
  502. // 设置文件名
  503. response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);
  504. OutputStream out = response.getOutputStream();
  505. doc.write(out);
  506. out.close();
  507. } catch (Exception e) {
  508. e.printStackTrace();
  509. } finally {
  510. delFileWord(ExcelUtil.getAbsoluteFile(fileName));
  511. }
  512. }
  513. @ApiOperation("事件执行日志导出")
  514. @GetMapping("/processDownload")
  515. public void processDownload(@RequestParam String id, HttpServletRequest request, HttpServletResponse response) {
  516. // id为事件id
  517. Map<String, Object> map = new HashMap<>();
  518. IncidentVo incidentVo = iIncidentService.queryById(id);
  519. if (incidentVo != null) {
  520. map.put("name", incidentVo.getName());
  521. // 查询处置过程
  522. List<IncidentProcess> incidentProcess = processService.list(Wrappers.<IncidentProcess>lambdaQuery()
  523. .eq(IncidentProcess::getIncidentId, id).orderByAsc(IncidentProcess::getCreateTime));
  524. for (IncidentProcess process : incidentProcess) {
  525. process.setCreateTimeText(DateUtil.formatDateTime(process.getCreateTime()));
  526. }
  527. map.put("process", incidentProcess);
  528. }
  529. String fileName = "incident_log_" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + ".docx";
  530. try {
  531. XWPFDocument doc = WordExportUtil.exportWord07(
  532. "word/incidentProcess.docx", map);
  533. FileOutputStream fos = new FileOutputStream(ExcelUtil.getAbsoluteFile(fileName));
  534. doc.write(fos);
  535. // 设置强制下载不打开
  536. response.setContentType("application/force-download");
  537. // 设置文件名
  538. response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);
  539. OutputStream out = response.getOutputStream();
  540. doc.write(out);
  541. out.close();
  542. } catch (Exception e) {
  543. e.printStackTrace();
  544. } finally {
  545. delFileWord(ExcelUtil.getAbsoluteFile(fileName));
  546. }
  547. }
  548. @ApiOperation("查询历史事件以及对应的方案")
  549. @RepeatSubmit()
  550. @GetMapping("/history")
  551. public TableDataInfo<IncidentVo> history(IncidentBo bo) {
  552. return iIncidentService.queryHistory(bo);
  553. }
  554. @ApiOperation("复制事件应急方案")
  555. @RepeatSubmit()
  556. @PostMapping("/copyTask")
  557. public AjaxResult<Void> copyTask(@RequestBody JSONObject jsonObject) {
  558. String oldId = jsonObject.getStr("oldIncidentId");
  559. String newId = jsonObject.getStr("newIncidentId");
  560. if (StrUtil.hasBlank(oldId, newId)) {
  561. return AjaxResult.error("参数存在空值!");
  562. }
  563. return toAjax(incidentTaskService.copyTask(oldId, newId) ? 1 : 0);
  564. }
  565. @ApiOperation("查询事件处置方案是否办结")
  566. @RepeatSubmit()
  567. @GetMapping("/queryTaskFinish")
  568. public AjaxResult queryTaskFinish(@RequestParam String taskId) {
  569. IncidentTaskVo voOne = incidentTaskService.getVoOne(Wrappers.<IncidentTask>lambdaQuery()
  570. .eq(IncidentTask::getId, taskId)
  571. .in(IncidentTask::getSendFlag, "2", "3")
  572. .eq(IncidentTask::getTaskSend, "1")
  573. .eq(IncidentTask::getBackLogFlag, "0"));
  574. if (voOne != null) {
  575. return AjaxResult.success(true);
  576. } else {
  577. return AjaxResult.success(false);
  578. }
  579. }
  580. @ApiOperation("待办消息办结")
  581. @RepeatSubmit()
  582. @PostMapping("/backLogFinish")
  583. public AjaxResult<Void> backLogFinish(@RequestBody JSONObject jsonObject) {
  584. String id = jsonObject.getStr("taskId");
  585. if (StrUtil.isBlank(id)) {
  586. return AjaxResult.error("参数存在空值!");
  587. }
  588. return toAjax(processService.backLogFinish(id) ? 1 : 0);
  589. }
  590. /**
  591. * 删除零时生成的文件
  592. */
  593. public static void delFileWord(String filePath) {
  594. File file = new File(filePath);
  595. file.delete();
  596. }
  597. public static void main(String[] args) {
  598. Set<String> set = new HashSet<>();
  599. set.add("common");
  600. set.add("read");
  601. System.out.println(CollUtil.containsAny(set, CollUtil.newHashSet("admin", "update")));
  602. }
  603. }