IncidentController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. String fileUrl = "";
  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. List<PlanFileVo> planFileVos = planFileService.listVo(Wrappers.<PlanFile>lambdaQuery().eq(PlanFile::getPlanId, voOne.get(0).getId()));
  129. if (planFileVos != null && planFileVos.size() > 0) {
  130. fileUrl = planFileVos.get(0).getFileUrl();
  131. }
  132. } else {
  133. map.put("baseTask", null);
  134. }
  135. map.put("planFile", fileUrl);
  136. // 查询处置方案
  137. map.put("task", incidentTaskService.listTaskInfo(id));
  138. List<IncidentProcess> list = iIncidentProcessService.list(Wrappers.<IncidentProcess>lambdaQuery()
  139. .eq(IncidentProcess::getIncidentId, id).orderByAsc(IncidentProcess::getCreateTime));
  140. if (!"dev".equals(env)) {
  141. for (IncidentProcess incidentProcess : list) {
  142. if (incidentProcess.getStatus() == 1) {
  143. // 查询阅读情况
  144. JSONObject o = feignNoticeInfoService.messagePushInfoList("1", "2", incidentProcess.getId());
  145. System.out.println(o);
  146. // 解析
  147. if (ObjectUtil.isNotEmpty(o)) {
  148. Integer total = o.getInt("total");
  149. if (total > 0) {
  150. JSONArray jsonArray = JSONUtil.parseObj(o.getJSONArray("rows").get(0)).getJSONArray("messageReadInfoList");
  151. String unMessage = "";
  152. String message = "";
  153. for (Object o1 : jsonArray) {
  154. JSONObject jsonObject = JSONUtil.parseObj(o1);
  155. if ("0".equals(jsonObject.getStr("readState"))) {
  156. // 未读
  157. unMessage = jsonObject.getStr("nickName") + "、";
  158. } else if ("1".equals(jsonObject.getStr("readState"))) {
  159. // 已读
  160. message = jsonObject.getStr("nickName") + "、";
  161. }
  162. }
  163. // 循环完之后,去除最后一个顿号
  164. if (StrUtil.isNotBlank(unMessage)) {
  165. unMessage = StrUtil.removeSuffix(unMessage, "、") + "未读。";
  166. }
  167. if (StrUtil.isNotBlank(message)) {
  168. message = StrUtil.removeSuffix(message, "、") + "已读。";
  169. }
  170. incidentProcess.setUserRead(unMessage + message);
  171. }
  172. }
  173. }
  174. }
  175. }
  176. map.put("process", list);
  177. return AjaxResult.success(map);
  178. }
  179. /**
  180. * 新增事件基础
  181. */
  182. @ApiOperation("新增事件基础")
  183. // @PreAuthorize("@ss.hasPermi('zhdd:incident:add')")
  184. // @Log(title = "事件基础", businessType = BusinessType.INSERT)
  185. @RepeatSubmit()
  186. @PostMapping()
  187. public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody IncidentBo bo) {
  188. // 新增初始化为预警状态
  189. bo.setStatus(1);
  190. return toAjax(iIncidentService.insertByBo(bo) ? 1 : 0);
  191. }
  192. /**
  193. * 修改事件基础
  194. */
  195. @ApiOperation("修改事件基础")
  196. // @PreAuthorize("@ss.hasPermi('zhdd:incident:edit')")
  197. // @Log(title = "事件基础", businessType = BusinessType.UPDATE)
  198. @RepeatSubmit()
  199. @PutMapping()
  200. public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody IncidentBo bo) {
  201. return toAjax(iIncidentService.updateByBo(bo) ? 1 : 0);
  202. }
  203. /**
  204. * 删除事件基础
  205. */
  206. @ApiOperation("删除事件基础")
  207. // @PreAuthorize("@ss.hasPermi('zhdd:incident:remove')")
  208. @Log(title = "事件基础", businessType = BusinessType.DELETE)
  209. @DeleteMapping("/{ids}")
  210. public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
  211. @PathVariable String[] ids) {
  212. return toAjax(iIncidentService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
  213. }
  214. @ApiOperation("新增事件方案")
  215. @Log(title = "事件方案", businessType = BusinessType.INSERT)
  216. @RepeatSubmit()
  217. @PostMapping("/task")
  218. public AjaxResult<Void> addTask(@Validated(AddGroup.class) @RequestBody IncidentTasksBo bo) {
  219. return toAjax(incidentTaskService.insertByBo(bo) ? 1 : 0);
  220. }
  221. @ApiOperation("删除事件方案")
  222. @Log(title = "事件方案", businessType = BusinessType.DELETE)
  223. @DeleteMapping("/task/{ids}")
  224. public AjaxResult<Void> removeTask(@NotEmpty(message = "主键不能为空")
  225. @PathVariable String[] ids) {
  226. return toAjax(incidentTaskService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
  227. }
  228. @ApiOperation("查询事件-用于首页地图展示")
  229. @GetMapping("/location")
  230. public AjaxResult<Map<String, List<IncidentVo>>> queryIncidentLocation() {
  231. List<IncidentVo> list = iIncidentService.listVo(Wrappers.<Incident>lambdaQuery().in(Incident::getStatus, 1, 2, 3));
  232. Map<Integer, List<IncidentVo>> collect = list.stream().collect(Collectors.groupingBy(IncidentVo::getStatus, Collectors.mapping(a -> a, Collectors.toList())));
  233. Map<String, List<IncidentVo>> result = new HashMap<>();
  234. result.put("预警事件", CollUtil.defaultIfEmpty(collect.get(1), new ArrayList<>()));
  235. result.put("待派发", CollUtil.defaultIfEmpty(collect.get(2), new ArrayList<>()));
  236. result.put("待处置", CollUtil.defaultIfEmpty(collect.get(3), new ArrayList<>()));
  237. return AjaxResult.success(result);
  238. }
  239. @ApiOperation("应急方案导出")
  240. // @Log(title = "应急方案导出", businessType = BusinessType.EXPORT)
  241. @GetMapping("/download")
  242. public void download(@RequestParam String id, HttpServletRequest request, HttpServletResponse response) {
  243. Map<String, Object> map = new HashMap<>();
  244. // 查询处置方案
  245. IncidentTaskVo incidentTaskVo = incidentTaskService.queryById(id);
  246. if (incidentTaskVo != null) {
  247. map.put("taskName", incidentTaskVo.getTaskName());
  248. // 查询事件详情
  249. IncidentVo incidentVo = iIncidentService.queryById(incidentTaskVo.getIncidentId());
  250. if (incidentVo != null) {
  251. map.put("name", incidentVo.getName());
  252. if (ObjectUtil.isNotEmpty(incidentVo.getType())) {
  253. map.put("type", sysDictDataService.selectDictLabel("zhdd_plan_type", Convert.toStr(incidentVo.getType())));
  254. } else {
  255. map.put("type", "-");
  256. }
  257. map.put("createTime", DateUtil.formatDateTime(incidentVo.getCreateTime()));
  258. map.put("addr", incidentVo.getAddr());
  259. if (StrUtil.isNotBlank(incidentVo.getSource())) {
  260. map.put("source", sysDictDataService.selectDictLabel("zhdd_incident_source", incidentVo.getSource()));
  261. } else {
  262. map.put("source", "-");
  263. }
  264. if (ObjectUtil.isNotEmpty(incidentVo.getLevel())) {
  265. map.put("level", sysDictDataService.selectDictLabel("zhdd_incident_level", Convert.toStr(incidentVo.getLevel())));
  266. } else {
  267. map.put("level", "-");
  268. }
  269. }
  270. // 查询方案人员
  271. map.put("incidentPerson", incidentTaskPersonService.listVo(Wrappers.<IncidentTaskPerson>lambdaQuery().eq(IncidentTaskPerson::getIncidentTaskId, id)));
  272. // 查询方案指令
  273. List<IncidentTaskCommandVo> incidentTaskCommandVos = incidentTaskCommandService.listVo(Wrappers.<IncidentTaskCommand>lambdaQuery().eq(IncidentTaskCommand::getIncidentTaskId, id));
  274. for (int i = 0; i < incidentTaskCommandVos.size(); i++) {
  275. incidentTaskCommandVos.get(i).setIndex(i + 1);
  276. }
  277. map.put("incidentCommand", incidentTaskCommandVos);
  278. // 查询处置过程
  279. List<IncidentProcess> incidentProcess = iIncidentProcessService.list(Wrappers.<IncidentProcess>lambdaQuery()
  280. .eq(IncidentProcess::getIncidentId, incidentTaskVo.getIncidentId()).orderByDesc(IncidentProcess::getCreateTime));
  281. if (incidentProcess != null && incidentProcess.size() > 0) {
  282. IncidentProcess processData = incidentProcess.get(0);
  283. map.put("process", DateUtil.formatDateTime(processData.getCreateTime()) + ":" + processData.getDes());
  284. }
  285. }
  286. String fileName = "plan_" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + ".docx";
  287. try {
  288. XWPFDocument doc = WordExportUtil.exportWord07(
  289. "word/incidentTask.docx", map);
  290. FileOutputStream fos = new FileOutputStream(ExcelUtil.getAbsoluteFile(fileName));
  291. doc.write(fos);
  292. // 设置强制下载不打开
  293. response.setContentType("application/force-download");
  294. // 设置文件名
  295. response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);
  296. OutputStream out = response.getOutputStream();
  297. doc.write(out);
  298. out.close();
  299. } catch (Exception e) {
  300. e.printStackTrace();
  301. } finally {
  302. delFileWord(ExcelUtil.getAbsoluteFile(fileName));
  303. }
  304. }
  305. /**
  306. * 删除零时生成的文件
  307. */
  308. public static void delFileWord(String filePath) {
  309. File file = new File(filePath);
  310. file.delete();
  311. }
  312. }