IncidentController.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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. /**
  106. * 查询事件基础列表
  107. */
  108. @ApiOperation("查询事件基础列表")
  109. // @PreAuthorize("@ss.hasPermi('zhdd:incident:list')")
  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. return rspData;
  134. }
  135. HashSet<Object> incidentIdSet = CollUtil.newHashSet(objects);
  136. bo.setIds(incidentIdSet);
  137. }
  138. return iIncidentService.queryPageList(bo);
  139. }
  140. /**
  141. * 获取事件基础详细信息
  142. */
  143. @ApiOperation("获取事件基础详细信息")
  144. @GetMapping("/{id}")
  145. // @Security
  146. public AjaxResult<Map<String, Object>> getInfo(@NotNull(message = "主键不能为空")
  147. @PathVariable("id") String id) {
  148. Map<String, Object> map = new HashMap<>();
  149. List<PlanFileVo> planFileVos = new ArrayList<>();
  150. IncidentVo incidentVo = iIncidentService.queryById(id);
  151. if (incidentVo == null) {
  152. return AjaxResult.success(map);
  153. }
  154. // 查询上报人、上报组织信息
  155. SysUser sysUser = sysUserService.selectUserByUserName(incidentVo.getCreateBy());
  156. if (sysUser != null) {
  157. incidentVo.setCreateBy(sysUser.getNickName());
  158. }
  159. SysDept sysDept = sysDeptService.selectDeptById(incidentVo.getCreateDept());
  160. if (sysDept != null) {
  161. incidentVo.setCreateDept(sysDept.getDeptName());
  162. }
  163. // 组装主办和协办部门数据树
  164. List<TreeSelect> madinList = new ArrayList<>();
  165. if (StrUtil.isNotBlank(incidentVo.getMadinDept())) {
  166. TreeSelect madin = new TreeSelect();
  167. madin.setId(incidentVo.getMadinDept());
  168. madin.setLabel(incidentVo.getMadinDeptText());
  169. madinList.add(madin);
  170. }
  171. incidentVo.setMadinDeptList(madinList);
  172. List<TreeSelect> assistList = new ArrayList<>();
  173. if (StrUtil.isNotBlank(incidentVo.getAssistDept())) {
  174. for (int i = 0; i < incidentVo.getAssistDept().split(",").length; i++) {
  175. TreeSelect assist = new TreeSelect();
  176. assist.setId(incidentVo.getAssistDept().split(",")[i]);
  177. if (incidentVo.getAssistDept().split(",").length == incidentVo.getAssistDeptText().split(",").length) {
  178. assist.setLabel(incidentVo.getAssistDeptText().split(",")[i]);
  179. }
  180. assistList.add(assist);
  181. }
  182. }
  183. incidentVo.setAssistDeptList(assistList);
  184. // 查询所属预案
  185. List<PlanVo> voOne = planService.listVo(Wrappers.<Plan>lambdaQuery().eq(Plan::getType, incidentVo.getType()).eq(Plan::getCreateDept, incidentVo.getPlanDept()));
  186. if (voOne != null && voOne.size() > 0) {
  187. map.put("baseTask", planTaskService.queryPlanTaskByPlanId(voOne.get(0).getId()));
  188. // 查询预案附件
  189. planFileVos = planFileService.listVo(Wrappers.<PlanFile>lambdaQuery().eq(PlanFile::getPlanId, voOne.get(0).getId()));
  190. } else {
  191. map.put("baseTask", null);
  192. }
  193. map.put("planFile", planFileVos);
  194. // 查询处置方案
  195. map.put("task", incidentTaskService.listTaskInfo(id));
  196. List<IncidentProcess> list = processService.list(Wrappers.<IncidentProcess>lambdaQuery()
  197. .eq(IncidentProcess::getIncidentId, id)
  198. // .in(IncidentProcess::getIncidentStatus, 3, 4, 5)
  199. .orderByAsc(IncidentProcess::getCreateTime));
  200. String distributeTime = "";
  201. String dealTime = "";
  202. if (!"dev".equals(env)) {
  203. for (IncidentProcess incidentProcess : list) {
  204. // 处理首次派发和首页处理的时间
  205. if (StrUtil.isBlank(distributeTime) && incidentProcess.getIncidentStatus() == 2 && StrUtil.contains(incidentProcess.getDes(), "事件派发")) {
  206. distributeTime = DateUtil.formatDateTime(incidentProcess.getCreateTime());
  207. }
  208. if (StrUtil.isBlank(dealTime) && incidentProcess.getIncidentStatus() == 3 && !StrUtil.contains(incidentProcess.getDes(), "再次派发")) {
  209. dealTime = DateUtil.formatDateTime(incidentProcess.getCreateTime());
  210. }
  211. if (incidentProcess.getStatus() == 1) {
  212. // 查询阅读情况
  213. JSONObject o = feignNoticeInfoService.messagePushInfoList("1", "2", incidentProcess.getId());
  214. log.info("查询消息阅读情况:{}", o);
  215. // 解析
  216. if (ObjectUtil.isNotEmpty(o)) {
  217. Integer total = o.getInt("total");
  218. if (total != null && total > 0) {
  219. JSONArray jsonArray = JSONUtil.parseObj(o.getJSONArray("rows").get(0)).getJSONArray("messageReadInfoList");
  220. StringBuilder unMessage = new StringBuilder();
  221. StringBuilder message = new StringBuilder();
  222. for (Object o1 : jsonArray) {
  223. JSONObject jsonObject = JSONUtil.parseObj(o1);
  224. if ("0".equals(jsonObject.getStr("readState"))) {
  225. // 未读
  226. unMessage.append(jsonObject.getStr("nickName")).append("、");
  227. } else if ("1".equals(jsonObject.getStr("readState"))) {
  228. // 已读
  229. message.append(jsonObject.getStr("nickName")).append("、");
  230. }
  231. }
  232. // 循环完之后,去除最后一个顿号
  233. incidentProcess.setUserRead(message.toString());
  234. incidentProcess.setUserUnRead(unMessage.toString());
  235. }
  236. }
  237. }
  238. }
  239. }
  240. map.put("process", list);
  241. // 物资使用情况
  242. map.put("resource", resourceDetailService.queryResourceAvailable(id));
  243. incidentVo.setDistributeTime(distributeTime);
  244. incidentVo.setDealTime(dealTime);
  245. map.put("baseInfo", incidentVo);
  246. return AjaxResult.success(map);
  247. }
  248. @ApiOperation("获取事件执行日志详细信息")
  249. @GetMapping("/process/{id}")
  250. public AjaxResult<Map<String, Object>> getProcessInfo(@NotNull(message = "主键不能为空")
  251. @PathVariable("id") String id) {
  252. Map<String, Object> map = new HashMap<>();
  253. List<IncidentProcess> list = processService.list(Wrappers.<IncidentProcess>lambdaQuery()
  254. .eq(IncidentProcess::getIncidentId, id)
  255. .orderByAsc(IncidentProcess::getCreateTime));
  256. String distributeTime = "";
  257. String dealTime = "";
  258. if (!"dev".equals(env)) {
  259. for (IncidentProcess incidentProcess : list) {
  260. // 处理首次派发和首页处理的时间
  261. if (StrUtil.isBlank(distributeTime) && incidentProcess.getIncidentStatus() == 2 && StrUtil.contains(incidentProcess.getDes(), "事件派发")) {
  262. distributeTime = DateUtil.formatDateTime(incidentProcess.getCreateTime());
  263. }
  264. if (StrUtil.isBlank(dealTime) && incidentProcess.getIncidentStatus() == 3 && !StrUtil.contains(incidentProcess.getDes(), "再次派发")) {
  265. dealTime = DateUtil.formatDateTime(incidentProcess.getCreateTime());
  266. }
  267. if (incidentProcess.getStatus() == 1) {
  268. // 查询阅读情况
  269. JSONObject o = feignNoticeInfoService.messagePushInfoList("1", "2", incidentProcess.getId());
  270. // 解析
  271. if (ObjectUtil.isNotEmpty(o)) {
  272. Integer total = o.getInt("total");
  273. if (total != null && total > 0) {
  274. JSONArray jsonArray = JSONUtil.parseObj(o.getJSONArray("rows").get(0)).getJSONArray("messageReadInfoList");
  275. StringBuilder unMessage = new StringBuilder();
  276. StringBuilder message = new StringBuilder();
  277. for (Object o1 : jsonArray) {
  278. JSONObject jsonObject = JSONUtil.parseObj(o1);
  279. if ("0".equals(jsonObject.getStr("readState"))) {
  280. // 未读
  281. unMessage.append(jsonObject.getStr("nickName")).append("、");
  282. } else if ("1".equals(jsonObject.getStr("readState"))) {
  283. // 已读
  284. message.append(jsonObject.getStr("nickName")).append("、");
  285. }
  286. }
  287. // 循环完之后,去除最后一个顿号
  288. incidentProcess.setUserRead(message.toString());
  289. incidentProcess.setUserUnRead(unMessage.toString());
  290. }
  291. }
  292. }
  293. }
  294. }
  295. map.put("process", list);
  296. return AjaxResult.success(map);
  297. }
  298. /**
  299. * 新增事件基础
  300. */
  301. @ApiOperation("新增事件基础")
  302. // @Log(title = "事件基础", businessType = BusinessType.INSERT)
  303. @RepeatSubmit()
  304. @PostMapping()
  305. @Security
  306. public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody IncidentBo bo) {
  307. // 新增初始化为待派发状态
  308. bo.setStatus(2);
  309. LoginUser cacheLoginUser = UserUtil.getCacheLoginUser();
  310. bo.setCreateBy(cacheLoginUser.getUsername());
  311. bo.setCreateDept(cacheLoginUser.getUser().getDeptId());
  312. bo.setExpr1(cacheLoginUser.getUser().getPhonenumber());
  313. String id = iIncidentService.insertByBo(bo);
  314. // 待新增事件用户关系的array
  315. JSONArray saveJsonArray = new JSONArray();
  316. IncidentUser save = new IncidentUser();
  317. save.setIncidentId(id);
  318. save.setUserId(cacheLoginUser.getUserId());
  319. save.setSource("1");
  320. saveJsonArray.add(save);
  321. RedisUtils.publish(Constants.INCIDENT_USER_BATCH, saveJsonArray);
  322. return toAjax(true);
  323. }
  324. /**
  325. * 修改事件基础
  326. */
  327. @ApiOperation("修改事件基础")
  328. // @PreAuthorize("@ss.hasPermi('zhdd:incident:edit')")
  329. // @Log(title = "事件基础", businessType = BusinessType.UPDATE)
  330. @RepeatSubmit()
  331. @PutMapping()
  332. @Security
  333. public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody IncidentBo bo) {
  334. return toAjax(iIncidentService.updateByBo(bo) ? 1 : 0);
  335. }
  336. /**
  337. * 删除事件基础
  338. */
  339. @ApiOperation("删除事件基础")
  340. // @PreAuthorize("@ss.hasPermi('zhdd:incident:remove')")
  341. @Log(title = "事件基础", businessType = BusinessType.DELETE)
  342. @DeleteMapping("/{ids}")
  343. public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
  344. @PathVariable String[] ids) {
  345. return toAjax(iIncidentService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
  346. }
  347. @ApiOperation("新增事件方案")
  348. // @Log(title = "事件方案", businessType = BusinessType.INSERT)
  349. @RepeatSubmit()
  350. @PostMapping("/task")
  351. public AjaxResult<Void> addTask(@Validated(AddGroup.class) @RequestBody IncidentTasksBo bo) {
  352. return toAjax(incidentTaskService.insertByBo(bo) ? 1 : 0);
  353. }
  354. @ApiOperation("删除事件方案")
  355. // @Log(title = "事件方案", businessType = BusinessType.DELETE)
  356. @DeleteMapping("/task/{ids}")
  357. public AjaxResult<Void> removeTask(@NotEmpty(message = "主键不能为空")
  358. @PathVariable String[] ids) {
  359. return toAjax(incidentTaskService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
  360. }
  361. @ApiOperation("事件方案发送")
  362. @RepeatSubmit()
  363. @PostMapping("/taskSend")
  364. public AjaxResult<Void> taskSend(@RequestBody IncidentTasksBo bo) {
  365. return toAjax(incidentTaskService.taskSend(bo) ? 1 : 0);
  366. }
  367. @ApiOperation("查询事件-用于首页地图展示")
  368. @GetMapping("/location")
  369. public AjaxResult<Map<String, List<IncidentVo>>> queryIncidentLocation() {
  370. List<IncidentVo> list = iIncidentService.listVo(Wrappers.<Incident>lambdaQuery().in(Incident::getStatus, 1, 2, 3));
  371. Map<Integer, List<IncidentVo>> collect = list.stream().collect(Collectors.groupingBy(IncidentVo::getStatus, Collectors.mapping(a -> a, Collectors.toList())));
  372. Map<String, List<IncidentVo>> result = new HashMap<>();
  373. result.put("预警事件", CollUtil.defaultIfEmpty(collect.get(2), new ArrayList<>()));
  374. // result.put("待派发", CollUtil.defaultIfEmpty(collect.get(2), new ArrayList<>()));
  375. result.put("处置", CollUtil.defaultIfEmpty(collect.get(3), new ArrayList<>()));
  376. return AjaxResult.success(result);
  377. }
  378. @ApiOperation("事件报告导出")
  379. @GetMapping("/download")
  380. public void download(@RequestParam String id, HttpServletRequest request, HttpServletResponse response) {
  381. // id为事件id
  382. Map<String, Object> map = new HashMap<>();
  383. IncidentVo incidentVo = iIncidentService.queryById(id);
  384. if (incidentVo != null) {
  385. map.put("name", incidentVo.getName());
  386. map.put("nowDate", DateUtil.today());
  387. if (ObjectUtil.isNotEmpty(incidentVo.getType())) {
  388. map.put("type", sysDictDataService.selectDictLabel("zhdd_incident_type", Convert.toStr(incidentVo.getType())));
  389. } else {
  390. map.put("type", "-");
  391. }
  392. map.put("createTime", DateUtil.formatDateTime(incidentVo.getCreateTime()));
  393. map.put("addr", incidentVo.getAddr());
  394. map.put("commanderText", StrUtil.blankToDefault(incidentVo.getCommanderText(), "无"));
  395. map.put("madinDeptText", StrUtil.blankToDefault(incidentVo.getMadinDeptText(), "部门无"));
  396. map.put("assistDeptText", StrUtil.blankToDefault(incidentVo.getAssistDeptText(), "部门无"));
  397. // 解析主办部门和协办部门人员
  398. String madinTaskUser = incidentVo.getMadinTaskUser();
  399. if (StrUtil.isNotBlank(madinTaskUser)) {
  400. List<MessagePushUser> messagePushUsers = JSONUtil.toList(madinTaskUser, MessagePushUser.class);
  401. map.put("madinDeptUser", messagePushUsers.stream().map(MessagePushUser::getNickName).collect(Collectors.joining(",")));
  402. } else {
  403. map.put("madinDeptUser", "人员无");
  404. }
  405. String assistTaskUser = incidentVo.getAssistTaskUser();
  406. if (StrUtil.isNotBlank(assistTaskUser)) {
  407. List<MessagePushUser> messagePushUsers = JSONUtil.toList(assistTaskUser, MessagePushUser.class);
  408. map.put("assistDeptUser", messagePushUsers.stream().map(MessagePushUser::getNickName).collect(Collectors.joining(",")));
  409. } else {
  410. map.put("assistDeptUser", "人员无");
  411. }
  412. map.put("conclusionDeal", StrUtil.blankToDefault(incidentVo.getConclusionDeal(), "无"));
  413. map.put("conclusion", StrUtil.blankToDefault(incidentVo.getConclusion(), "无"));
  414. /*if (StrUtil.isNotBlank(incidentVo.getSource())) {
  415. map.put("source", sysDictDataService.selectDictLabel("zhdd_incident_source", incidentVo.getSource()));
  416. } else {
  417. map.put("source", "-");
  418. }*/
  419. if (ObjectUtil.isNotEmpty(incidentVo.getLevel())) {
  420. map.put("level", sysDictDataService.selectDictLabel("zhdd_incident_level", Convert.toStr(incidentVo.getLevel())) + "级");
  421. } else {
  422. map.put("level", "-");
  423. }
  424. // 组装事件图片
  425. List<String> picList = StrUtil.split(incidentVo.getPic(), ",");
  426. List<ImageEntity> pics = new ArrayList<>();
  427. for (String s : picList) {
  428. ImageEntity imageEntity = new ImageEntity();
  429. imageEntity.setType(ImageEntity.Data);
  430. imageEntity.setHeight(300);
  431. imageEntity.setWidth(550);
  432. log.info("图片相对地址:{}", s);
  433. // 本地资源路径
  434. String localPath = RuoYiConfig.getProfile();
  435. // 数据库资源地址
  436. String downloadPath = localPath + StringUtils.substringAfter(s, Constants.RESOURCE_PREFIX);
  437. try {
  438. imageEntity.setData(FileUtil.readBytes(downloadPath));
  439. } catch (Exception e) {
  440. log.info("读取图片失败:{}", e.getMessage());
  441. continue;
  442. }
  443. pics.add(imageEntity);
  444. }
  445. map.put("pics", pics);
  446. // 查询处置过程
  447. List<IncidentProcess> incidentProcess = processService.list(Wrappers.<IncidentProcess>lambdaQuery()
  448. .eq(IncidentProcess::getIncidentId, id).orderByAsc(IncidentProcess::getCreateTime));
  449. Map<String, List<IncidentProcess>> processCollect = incidentProcess.stream().filter(a -> StrUtil.isNotBlank(a.getTaskId())).collect(Collectors.groupingBy(IncidentProcess::getTaskId));
  450. // 查询处置方案
  451. List<IncidentTaskVo> incidentTasks = incidentTaskService.listTaskInfo(id);
  452. if (incidentTasks != null && incidentTasks.size() > 0) {
  453. StringBuilder tasks = new StringBuilder();
  454. for (int i = 0; i < incidentTasks.size(); i++) {
  455. tasks.append(i + 1).append("、").append(incidentTasks.get(i).getTaskName()).append("\r");
  456. // 查询指令对应的处置过程
  457. List<IncidentProcess> processList = processCollect.get(incidentTasks.get(i).getId());
  458. if (processList != null && processList.size() > 0) {
  459. String collect = processList.stream().map(IncidentProcess::getDes).collect(Collectors.joining("\r "));
  460. tasks.append(" ").append(collect).append("\r ");
  461. }
  462. }
  463. map.put("tasks", tasks.toString());
  464. } else {
  465. map.put("tasks", "无");
  466. }
  467. }
  468. String fileName = "incident_" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + ".docx";
  469. try {
  470. XWPFDocument doc = WordExportUtil.exportWord07(
  471. "word/incidentDetail.docx", map);
  472. FileOutputStream fos = new FileOutputStream(ExcelUtil.getAbsoluteFile(fileName));
  473. doc.write(fos);
  474. // 设置强制下载不打开
  475. response.setContentType("application/force-download");
  476. // 设置文件名
  477. response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);
  478. OutputStream out = response.getOutputStream();
  479. doc.write(out);
  480. out.close();
  481. } catch (Exception e) {
  482. e.printStackTrace();
  483. } finally {
  484. delFileWord(ExcelUtil.getAbsoluteFile(fileName));
  485. }
  486. }
  487. @ApiOperation("事件执行日志导出")
  488. @GetMapping("/processDownload")
  489. public void processDownload(@RequestParam String id, HttpServletRequest request, HttpServletResponse response) {
  490. // id为事件id
  491. Map<String, Object> map = new HashMap<>();
  492. IncidentVo incidentVo = iIncidentService.queryById(id);
  493. if (incidentVo != null) {
  494. map.put("name", incidentVo.getName());
  495. // 查询处置过程
  496. List<IncidentProcess> incidentProcess = processService.list(Wrappers.<IncidentProcess>lambdaQuery()
  497. .eq(IncidentProcess::getIncidentId, id).orderByAsc(IncidentProcess::getCreateTime));
  498. for (IncidentProcess process : incidentProcess) {
  499. process.setCreateTimeText(DateUtil.formatDateTime(process.getCreateTime()));
  500. }
  501. map.put("process", incidentProcess);
  502. }
  503. String fileName = "incident_log_" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + ".docx";
  504. try {
  505. XWPFDocument doc = WordExportUtil.exportWord07(
  506. "word/incidentProcess.docx", map);
  507. FileOutputStream fos = new FileOutputStream(ExcelUtil.getAbsoluteFile(fileName));
  508. doc.write(fos);
  509. // 设置强制下载不打开
  510. response.setContentType("application/force-download");
  511. // 设置文件名
  512. response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);
  513. OutputStream out = response.getOutputStream();
  514. doc.write(out);
  515. out.close();
  516. } catch (Exception e) {
  517. e.printStackTrace();
  518. } finally {
  519. delFileWord(ExcelUtil.getAbsoluteFile(fileName));
  520. }
  521. }
  522. @ApiOperation("复制事件应急方案")
  523. @RepeatSubmit()
  524. @PostMapping("/copyTask")
  525. public AjaxResult<Void> copyTask(@RequestBody JSONObject jsonObject) {
  526. String oldId = jsonObject.getStr("oldIncidentId");
  527. String newId = jsonObject.getStr("newIncidentId");
  528. if (StrUtil.hasBlank(oldId, newId)) {
  529. return AjaxResult.error("参数存在空值!");
  530. }
  531. return toAjax(incidentTaskService.copyTask(oldId, newId) ? 1 : 0);
  532. }
  533. @ApiOperation("查询事件处置方案是否办结")
  534. @RepeatSubmit()
  535. @GetMapping("/queryTaskFinish")
  536. public AjaxResult queryTaskFinish(@RequestParam String taskId) {
  537. IncidentTaskVo voOne = incidentTaskService.getVoOne(Wrappers.<IncidentTask>lambdaQuery()
  538. .eq(IncidentTask::getId, taskId)
  539. .in(IncidentTask::getSendFlag, "2", "3")
  540. .eq(IncidentTask::getTaskSend, "1")
  541. .eq(IncidentTask::getBackLogFlag, "0"));
  542. if (voOne != null) {
  543. return AjaxResult.success(true);
  544. } else {
  545. return AjaxResult.success(false);
  546. }
  547. }
  548. @ApiOperation("待办消息办结")
  549. @RepeatSubmit()
  550. @PostMapping("/backLogFinish")
  551. public AjaxResult<Void> backLogFinish(@RequestBody JSONObject jsonObject) {
  552. String id = jsonObject.getStr("taskId");
  553. if (StrUtil.isBlank(id)) {
  554. return AjaxResult.error("参数存在空值!");
  555. }
  556. return toAjax(processService.backLogFinish(id) ? 1 : 0);
  557. }
  558. /**
  559. * 删除零时生成的文件
  560. */
  561. public static void delFileWord(String filePath) {
  562. File file = new File(filePath);
  563. file.delete();
  564. }
  565. public static void main(String[] args) {
  566. Set<String> set = new HashSet<>();
  567. set.add("common");
  568. set.add("read");
  569. System.out.println(CollUtil.containsAny(set, CollUtil.newHashSet("admin", "update")));
  570. }
  571. }