IncidentController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. package com.ruoyi.web.controller.zhdd;
  2. import cn.afterturn.easypoi.word.WordExportUtil;
  3. import cn.hutool.core.collection.CollUtil;
  4. import cn.hutool.core.convert.Convert;
  5. import cn.hutool.core.date.DateUtil;
  6. import cn.hutool.core.util.ObjectUtil;
  7. import cn.hutool.core.util.StrUtil;
  8. import cn.hutool.json.JSONArray;
  9. import cn.hutool.json.JSONObject;
  10. import cn.hutool.json.JSONUtil;
  11. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  12. import com.ruoyi.common.annotation.Log;
  13. import com.ruoyi.common.annotation.RepeatSubmit;
  14. import com.ruoyi.common.core.controller.BaseController;
  15. import com.ruoyi.common.core.domain.AjaxResult;
  16. import com.ruoyi.common.core.page.TableDataInfo;
  17. import com.ruoyi.common.core.validate.AddGroup;
  18. import com.ruoyi.common.core.validate.EditGroup;
  19. import com.ruoyi.common.core.validate.QueryGroup;
  20. import com.ruoyi.common.enums.BusinessType;
  21. import com.ruoyi.common.utils.poi.ExcelUtil;
  22. import com.ruoyi.system.service.ISysDictDataService;
  23. import com.ruoyi.zhdd.domain.Incident;
  24. import com.ruoyi.zhdd.domain.IncidentProcess;
  25. import com.ruoyi.zhdd.domain.IncidentTaskCommand;
  26. import com.ruoyi.zhdd.domain.IncidentTaskPerson;
  27. import com.ruoyi.zhdd.domain.Plan;
  28. import com.ruoyi.zhdd.domain.PlanFile;
  29. import com.ruoyi.zhdd.domain.bo.IncidentBo;
  30. import com.ruoyi.zhdd.domain.bo.IncidentTasksBo;
  31. import com.ruoyi.zhdd.domain.vo.IncidentTaskCommandVo;
  32. import com.ruoyi.zhdd.domain.vo.IncidentTaskVo;
  33. import com.ruoyi.zhdd.domain.vo.IncidentVo;
  34. import com.ruoyi.zhdd.domain.vo.PlanFileVo;
  35. import com.ruoyi.zhdd.domain.vo.PlanVo;
  36. import com.ruoyi.zhdd.feign.FeignNoticeInfoService;
  37. import com.ruoyi.zhdd.service.IIncidentProcessService;
  38. import com.ruoyi.zhdd.service.IIncidentService;
  39. import com.ruoyi.zhdd.service.IIncidentTaskCommandService;
  40. import com.ruoyi.zhdd.service.IIncidentTaskPersonService;
  41. import com.ruoyi.zhdd.service.IIncidentTaskService;
  42. import com.ruoyi.zhdd.service.IPlanFileService;
  43. import com.ruoyi.zhdd.service.IPlanService;
  44. import com.ruoyi.zhdd.service.IPlanTaskService;
  45. import io.swagger.annotations.Api;
  46. import io.swagger.annotations.ApiOperation;
  47. import lombok.RequiredArgsConstructor;
  48. import org.apache.poi.xwpf.usermodel.XWPFDocument;
  49. import org.springframework.beans.factory.annotation.Autowired;
  50. import org.springframework.beans.factory.annotation.Value;
  51. import org.springframework.validation.annotation.Validated;
  52. import org.springframework.web.bind.annotation.*;
  53. import javax.servlet.http.HttpServletRequest;
  54. import javax.servlet.http.HttpServletResponse;
  55. import javax.validation.constraints.NotEmpty;
  56. import javax.validation.constraints.NotNull;
  57. import java.io.File;
  58. import java.io.FileOutputStream;
  59. import java.io.OutputStream;
  60. import java.util.ArrayList;
  61. import java.util.Arrays;
  62. import java.util.Date;
  63. import java.util.HashMap;
  64. import java.util.List;
  65. import java.util.Map;
  66. import java.util.stream.Collectors;
  67. /**
  68. * 事件基础Controller
  69. *
  70. * @author xitong
  71. * @date 2021-09-28
  72. */
  73. @Validated
  74. @Api(value = "事件基础控制器", tags = {"事件基础管理"})
  75. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  76. @RestController
  77. @RequestMapping("/zhdd/incident")
  78. public class IncidentController extends BaseController {
  79. private final IIncidentService iIncidentService;
  80. private final IIncidentTaskService incidentTaskService;
  81. private final IIncidentTaskPersonService incidentTaskPersonService;
  82. private final IIncidentTaskCommandService incidentTaskCommandService;
  83. private final IIncidentProcessService iIncidentProcessService;
  84. private final IPlanTaskService planTaskService;
  85. private final IPlanService planService;
  86. private final IPlanFileService planFileService;
  87. private final ISysDictDataService sysDictDataService;
  88. private final FeignNoticeInfoService feignNoticeInfoService;
  89. @Value("${spring.profiles.active}")
  90. private String env;
  91. /**
  92. * 查询事件基础列表
  93. */
  94. @ApiOperation("查询事件基础列表")
  95. // @PreAuthorize("@ss.hasPermi('zhdd:incident:list')")
  96. @GetMapping("/list")
  97. public TableDataInfo<IncidentVo> list(@Validated(QueryGroup.class) IncidentBo bo) {
  98. return iIncidentService.queryPageList(bo);
  99. }
  100. /**
  101. * 导出事件基础列表
  102. */
  103. @ApiOperation("导出事件基础列表")
  104. // @PreAuthorize("@ss.hasPermi('zhdd:incident:export')")
  105. // @Log(title = "事件基础", businessType = BusinessType.EXPORT)
  106. @GetMapping("/export")
  107. public void export(@Validated IncidentBo bo, HttpServletResponse response) {
  108. List<IncidentVo> list = iIncidentService.queryList(bo);
  109. ExcelUtil.exportExcel(list, "事件基础", IncidentVo.class, response);
  110. }
  111. /**
  112. * 获取事件基础详细信息
  113. */
  114. @ApiOperation("获取事件基础详细信息")
  115. // @PreAuthorize("@ss.hasPermi('zhdd:incident:query')")
  116. @GetMapping("/{id}")
  117. public AjaxResult<Map<String, Object>> getInfo(@NotNull(message = "主键不能为空")
  118. @PathVariable("id") String id) {
  119. Map<String, Object> map = new HashMap<>();
  120. List<PlanFileVo> planFileVos = new ArrayList<>();
  121. IncidentVo incidentVo = iIncidentService.queryById(id);
  122. map.put("baseInfo", incidentVo);
  123. // 查询所属预案
  124. List<PlanVo> voOne = planService.listVo(Wrappers.<Plan>lambdaQuery().eq(Plan::getType, incidentVo.getType()).eq(Plan::getCreateDept, incidentVo.getCreateDept()));
  125. if (voOne != null && voOne.size() > 0) {
  126. map.put("baseTask", planTaskService.queryPlanTaskByPlanId(voOne.get(0).getId()));
  127. // 查询预案附件
  128. planFileVos = planFileService.listVo(Wrappers.<PlanFile>lambdaQuery().eq(PlanFile::getPlanId, voOne.get(0).getId()));
  129. } else {
  130. map.put("baseTask", null);
  131. }
  132. map.put("planFile", planFileVos);
  133. // 查询处置方案
  134. map.put("task", incidentTaskService.listTaskInfo(id));
  135. List<IncidentProcess> list = iIncidentProcessService.list(Wrappers.<IncidentProcess>lambdaQuery()
  136. .eq(IncidentProcess::getIncidentId, id).orderByAsc(IncidentProcess::getCreateTime));
  137. if (!"dev".equals(env)) {
  138. for (IncidentProcess incidentProcess : list) {
  139. if (incidentProcess.getStatus() == 1) {
  140. // 查询阅读情况
  141. JSONObject o = feignNoticeInfoService.messagePushInfoList("1", "2", incidentProcess.getId());
  142. // 解析
  143. if (ObjectUtil.isNotEmpty(o)) {
  144. Integer total = o.getInt("total");
  145. if (total > 0) {
  146. JSONArray jsonArray = JSONUtil.parseObj(o.getJSONArray("rows").get(0)).getJSONArray("messageReadInfoList");
  147. String unMessage = "";
  148. String message = "";
  149. for (Object o1 : jsonArray) {
  150. JSONObject jsonObject = JSONUtil.parseObj(o1);
  151. if ("0".equals(jsonObject.getStr("readState"))) {
  152. // 未读
  153. unMessage = jsonObject.getStr("nickName") + "、";
  154. } else if ("1".equals(jsonObject.getStr("readState"))) {
  155. // 已读
  156. message = jsonObject.getStr("nickName") + "、";
  157. }
  158. }
  159. // 循环完之后,去除最后一个顿号
  160. if (StrUtil.isNotBlank(unMessage)) {
  161. unMessage = StrUtil.removeSuffix(unMessage, "、");
  162. }
  163. if (StrUtil.isNotBlank(message)) {
  164. message = StrUtil.removeSuffix(message, "、");
  165. }
  166. incidentProcess.setUserRead(message);
  167. incidentProcess.setUserUnRead(unMessage);
  168. }
  169. }
  170. }
  171. }
  172. }
  173. map.put("process", list);
  174. return AjaxResult.success(map);
  175. }
  176. /**
  177. * 新增事件基础
  178. */
  179. @ApiOperation("新增事件基础")
  180. // @PreAuthorize("@ss.hasPermi('zhdd:incident:add')")
  181. // @Log(title = "事件基础", businessType = BusinessType.INSERT)
  182. @RepeatSubmit()
  183. @PostMapping()
  184. public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody IncidentBo bo) {
  185. // 新增初始化为预警状态
  186. bo.setStatus(1);
  187. return toAjax(iIncidentService.insertByBo(bo) ? 1 : 0);
  188. }
  189. /**
  190. * 修改事件基础
  191. */
  192. @ApiOperation("修改事件基础")
  193. // @PreAuthorize("@ss.hasPermi('zhdd:incident:edit')")
  194. // @Log(title = "事件基础", businessType = BusinessType.UPDATE)
  195. @RepeatSubmit()
  196. @PutMapping()
  197. public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody IncidentBo bo) {
  198. return toAjax(iIncidentService.updateByBo(bo) ? 1 : 0);
  199. }
  200. /**
  201. * 删除事件基础
  202. */
  203. @ApiOperation("删除事件基础")
  204. // @PreAuthorize("@ss.hasPermi('zhdd:incident:remove')")
  205. @Log(title = "事件基础", businessType = BusinessType.DELETE)
  206. @DeleteMapping("/{ids}")
  207. public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
  208. @PathVariable String[] ids) {
  209. return toAjax(iIncidentService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
  210. }
  211. @ApiOperation("新增事件方案")
  212. // @Log(title = "事件方案", businessType = BusinessType.INSERT)
  213. @RepeatSubmit()
  214. @PostMapping("/task")
  215. public AjaxResult<Void> addTask(@Validated(AddGroup.class) @RequestBody IncidentTasksBo bo) {
  216. return toAjax(incidentTaskService.insertByBo(bo) ? 1 : 0);
  217. }
  218. @ApiOperation("删除事件方案")
  219. // @Log(title = "事件方案", businessType = BusinessType.DELETE)
  220. @DeleteMapping("/task/{ids}")
  221. public AjaxResult<Void> removeTask(@NotEmpty(message = "主键不能为空")
  222. @PathVariable String[] ids) {
  223. return toAjax(incidentTaskService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
  224. }
  225. @ApiOperation("查询事件-用于首页地图展示")
  226. @GetMapping("/location")
  227. public AjaxResult<Map<String, List<IncidentVo>>> queryIncidentLocation() {
  228. List<IncidentVo> list = iIncidentService.listVo(Wrappers.<Incident>lambdaQuery().in(Incident::getStatus, 1, 2, 3));
  229. Map<Integer, List<IncidentVo>> collect = list.stream().collect(Collectors.groupingBy(IncidentVo::getStatus, Collectors.mapping(a -> a, Collectors.toList())));
  230. Map<String, List<IncidentVo>> result = new HashMap<>();
  231. result.put("预警事件", CollUtil.defaultIfEmpty(collect.get(1), new ArrayList<>()));
  232. result.put("待派发", CollUtil.defaultIfEmpty(collect.get(2), new ArrayList<>()));
  233. result.put("待处置", CollUtil.defaultIfEmpty(collect.get(3), new ArrayList<>()));
  234. return AjaxResult.success(result);
  235. }
  236. @ApiOperation("应急方案导出")
  237. // @Log(title = "应急方案导出", businessType = BusinessType.EXPORT)
  238. @GetMapping("/download")
  239. public void download(@RequestParam String id, HttpServletRequest request, HttpServletResponse response) {
  240. Map<String, Object> map = new HashMap<>();
  241. // 查询处置方案
  242. IncidentTaskVo incidentTaskVo = incidentTaskService.queryById(id);
  243. if (incidentTaskVo != null) {
  244. map.put("taskName", incidentTaskVo.getTaskName());
  245. // 查询事件详情
  246. IncidentVo incidentVo = iIncidentService.queryById(incidentTaskVo.getIncidentId());
  247. if (incidentVo != null) {
  248. map.put("name", incidentVo.getName());
  249. if (ObjectUtil.isNotEmpty(incidentVo.getType())) {
  250. map.put("type", sysDictDataService.selectDictLabel("zhdd_plan_type", Convert.toStr(incidentVo.getType())));
  251. } else {
  252. map.put("type", "-");
  253. }
  254. map.put("createTime", DateUtil.formatDateTime(incidentVo.getCreateTime()));
  255. map.put("addr", incidentVo.getAddr());
  256. if (StrUtil.isNotBlank(incidentVo.getSource())) {
  257. map.put("source", sysDictDataService.selectDictLabel("zhdd_incident_source", incidentVo.getSource()));
  258. } else {
  259. map.put("source", "-");
  260. }
  261. if (ObjectUtil.isNotEmpty(incidentVo.getLevel())) {
  262. map.put("level", sysDictDataService.selectDictLabel("zhdd_incident_level", Convert.toStr(incidentVo.getLevel())));
  263. } else {
  264. map.put("level", "-");
  265. }
  266. }
  267. // 查询方案人员
  268. map.put("incidentPerson", incidentTaskPersonService.listVo(Wrappers.<IncidentTaskPerson>lambdaQuery().eq(IncidentTaskPerson::getIncidentTaskId, id)));
  269. // 查询方案指令
  270. List<IncidentTaskCommandVo> incidentTaskCommandVos = incidentTaskCommandService.listVo(Wrappers.<IncidentTaskCommand>lambdaQuery().eq(IncidentTaskCommand::getIncidentTaskId, id));
  271. for (int i = 0; i < incidentTaskCommandVos.size(); i++) {
  272. incidentTaskCommandVos.get(i).setIndex(i + 1);
  273. }
  274. map.put("incidentCommand", incidentTaskCommandVos);
  275. // 查询处置过程
  276. List<IncidentProcess> incidentProcess = iIncidentProcessService.list(Wrappers.<IncidentProcess>lambdaQuery()
  277. .eq(IncidentProcess::getIncidentId, incidentTaskVo.getIncidentId()).orderByDesc(IncidentProcess::getCreateTime));
  278. if (incidentProcess != null && incidentProcess.size() > 0) {
  279. IncidentProcess processData = incidentProcess.get(0);
  280. map.put("process", DateUtil.formatDateTime(processData.getCreateTime()) + ":" + processData.getDes());
  281. }
  282. }
  283. String fileName = "plan_" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + ".docx";
  284. try {
  285. XWPFDocument doc = WordExportUtil.exportWord07(
  286. "word/incidentTask.docx", map);
  287. FileOutputStream fos = new FileOutputStream(ExcelUtil.getAbsoluteFile(fileName));
  288. doc.write(fos);
  289. // 设置强制下载不打开
  290. response.setContentType("application/force-download");
  291. // 设置文件名
  292. response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);
  293. OutputStream out = response.getOutputStream();
  294. doc.write(out);
  295. out.close();
  296. } catch (Exception e) {
  297. e.printStackTrace();
  298. } finally {
  299. delFileWord(ExcelUtil.getAbsoluteFile(fileName));
  300. }
  301. }
  302. /**
  303. * 删除零时生成的文件
  304. */
  305. public static void delFileWord(String filePath) {
  306. File file = new File(filePath);
  307. file.delete();
  308. }
  309. }