IncidentController.java 17 KB

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