IncidentController.java 28 KB

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