123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- package com.ruoyi.web.controller.zhdd;
- import cn.afterturn.easypoi.word.WordExportUtil;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.util.ObjectUtil;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.json.JSONArray;
- import cn.hutool.json.JSONObject;
- import cn.hutool.json.JSONUtil;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.ruoyi.common.annotation.Log;
- import com.ruoyi.common.annotation.RepeatSubmit;
- import com.ruoyi.common.annotation.Security;
- import com.ruoyi.common.constant.Constants;
- import com.ruoyi.common.core.controller.BaseController;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.common.core.domain.TreeSelect;
- import com.ruoyi.common.core.domain.entity.SysDept;
- import com.ruoyi.common.core.domain.entity.SysUser;
- import com.ruoyi.common.core.domain.model.LoginUser;
- import com.ruoyi.common.core.page.TableDataInfo;
- import com.ruoyi.common.core.validate.AddGroup;
- import com.ruoyi.common.core.validate.EditGroup;
- import com.ruoyi.common.core.validate.QueryGroup;
- import com.ruoyi.common.enums.BusinessType;
- import com.ruoyi.common.utils.RedisUtils;
- import com.ruoyi.common.utils.UserUtil;
- import com.ruoyi.common.utils.poi.ExcelUtil;
- import com.ruoyi.system.service.ISysDeptService;
- import com.ruoyi.system.service.ISysDictDataService;
- import com.ruoyi.system.service.ISysUserService;
- import com.ruoyi.zhdd.domain.Incident;
- import com.ruoyi.zhdd.domain.IncidentProcess;
- import com.ruoyi.zhdd.domain.IncidentTask;
- import com.ruoyi.zhdd.domain.Plan;
- import com.ruoyi.zhdd.domain.PlanFile;
- import com.ruoyi.zhdd.domain.bo.IncidentBo;
- import com.ruoyi.zhdd.domain.bo.IncidentTasksBo;
- import com.ruoyi.zhdd.domain.bo.MessagePushUser;
- import com.ruoyi.zhdd.domain.vo.IncidentTaskVo;
- import com.ruoyi.zhdd.domain.vo.IncidentVo;
- import com.ruoyi.zhdd.domain.vo.PlanFileVo;
- import com.ruoyi.zhdd.domain.vo.PlanVo;
- import com.ruoyi.zhdd.feign.FeignNoticeInfoService;
- import com.ruoyi.zhdd.service.IIncidentProcessService;
- import com.ruoyi.zhdd.service.IIncidentService;
- import com.ruoyi.zhdd.service.IIncidentTaskService;
- import com.ruoyi.zhdd.service.IPlanFileService;
- import com.ruoyi.zhdd.service.IPlanService;
- import com.ruoyi.zhdd.service.IPlanTaskService;
- import com.ruoyi.zhdd.service.IResourceDetailService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.poi.xwpf.usermodel.XWPFDocument;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.validation.constraints.NotEmpty;
- import javax.validation.constraints.NotNull;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.OutputStream;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * 事件基础Controller
- *
- * @author xitong
- * @date 2021-09-28
- */
- @Validated
- @Api(value = "事件基础控制器", tags = {"事件基础管理"})
- @RequiredArgsConstructor(onConstructor_ = @Autowired)
- @RestController
- @RequestMapping("/zhdd/incident")
- @Slf4j
- public class IncidentController extends BaseController {
- private final IIncidentService iIncidentService;
- private final IIncidentTaskService incidentTaskService;
- private final IIncidentProcessService processService;
- private final IPlanTaskService planTaskService;
- private final IPlanService planService;
- private final IPlanFileService planFileService;
- private final ISysDictDataService sysDictDataService;
- private final FeignNoticeInfoService feignNoticeInfoService;
- private final IResourceDetailService resourceDetailService;
- private final ISysUserService sysUserService;
- private final ISysDeptService sysDeptService;
- @Value("${spring.profiles.active}")
- private String env;
- /**
- * 查询事件基础列表
- */
- @ApiOperation("查询事件基础列表")
- // @PreAuthorize("@ss.hasPermi('zhdd:incident:list')")
- @GetMapping("/list")
- @Security
- public TableDataInfo<IncidentVo> list(@Validated(QueryGroup.class) IncidentBo bo) {
- if ("app".equals(bo.getQuerySource())) {
- bo.setStatus(3);
- }
- if (StrUtil.isNotBlank(bo.getStatuss())) {
- bo.setStatuss(bo.getStatuss().replace("-", ""));
- }
- return iIncidentService.queryPageList(bo);
- }
- /**
- * 获取事件基础详细信息
- */
- @ApiOperation("获取事件基础详细信息")
- @GetMapping("/{id}")
- // @Security
- public AjaxResult<Map<String, Object>> getInfo(@NotNull(message = "主键不能为空")
- @PathVariable("id") String id) {
- Map<String, Object> map = new HashMap<>();
- List<PlanFileVo> planFileVos = new ArrayList<>();
- IncidentVo incidentVo = iIncidentService.queryById(id);
- if (incidentVo == null) {
- return AjaxResult.success(map);
- }
- // 查询上报人、上报组织信息
- SysUser sysUser = sysUserService.selectUserByUserName(incidentVo.getCreateBy());
- if (sysUser != null) {
- incidentVo.setCreateBy(sysUser.getNickName());
- }
- SysDept sysDept = sysDeptService.selectDeptById(incidentVo.getCreateDept());
- if (sysDept != null) {
- incidentVo.setCreateDept(sysDept.getDeptName());
- }
- // 组装主办和协办部门数据树
- List<TreeSelect> madinList = new ArrayList<>();
- if (StrUtil.isNotBlank(incidentVo.getMadinDept())) {
- TreeSelect madin = new TreeSelect();
- madin.setId(incidentVo.getMadinDept());
- madin.setLabel(incidentVo.getMadinDeptText());
- madinList.add(madin);
- }
- incidentVo.setMadinDeptList(madinList);
- List<TreeSelect> assistList = new ArrayList<>();
- if (StrUtil.isNotBlank(incidentVo.getAssistDept())) {
- for (int i = 0; i < incidentVo.getAssistDept().split(",").length; i++) {
- TreeSelect assist = new TreeSelect();
- assist.setId(incidentVo.getAssistDept().split(",")[i]);
- if (incidentVo.getAssistDept().split(",").length == incidentVo.getAssistDeptText().split(",").length) {
- assist.setLabel(incidentVo.getAssistDeptText().split(",")[i]);
- }
- assistList.add(assist);
- }
- }
- incidentVo.setAssistDeptList(assistList);
- map.put("baseInfo", incidentVo);
- // 查询所属预案
- List<PlanVo> voOne = planService.listVo(Wrappers.<Plan>lambdaQuery().eq(Plan::getType, incidentVo.getType()).eq(Plan::getCreateDept, incidentVo.getPlanDept()));
- if (voOne != null && voOne.size() > 0) {
- map.put("baseTask", planTaskService.queryPlanTaskByPlanId(voOne.get(0).getId()));
- // 查询预案附件
- planFileVos = planFileService.listVo(Wrappers.<PlanFile>lambdaQuery().eq(PlanFile::getPlanId, voOne.get(0).getId()));
- } else {
- map.put("baseTask", null);
- }
- map.put("planFile", planFileVos);
- // 查询处置方案
- map.put("task", incidentTaskService.listTaskInfo(id));
- List<IncidentProcess> list = processService.list(Wrappers.<IncidentProcess>lambdaQuery()
- .eq(IncidentProcess::getIncidentId, id)
- // .in(IncidentProcess::getIncidentStatus, 3, 4, 5)
- .orderByAsc(IncidentProcess::getCreateTime));
- if (!"dev".equals(env)) {
- for (IncidentProcess incidentProcess : list) {
- if (incidentProcess.getStatus() == 1) {
- // 查询阅读情况
- JSONObject o = feignNoticeInfoService.messagePushInfoList("1", "2", incidentProcess.getId());
- // 解析
- if (ObjectUtil.isNotEmpty(o)) {
- Integer total = o.getInt("total");
- if (total > 0) {
- JSONArray jsonArray = JSONUtil.parseObj(o.getJSONArray("rows").get(0)).getJSONArray("messageReadInfoList");
- StringBuilder unMessage = new StringBuilder();
- StringBuilder message = new StringBuilder();
- for (Object o1 : jsonArray) {
- JSONObject jsonObject = JSONUtil.parseObj(o1);
- if ("0".equals(jsonObject.getStr("readState"))) {
- // 未读
- unMessage.append(jsonObject.getStr("nickName")).append("、");
- } else if ("1".equals(jsonObject.getStr("readState"))) {
- // 已读
- message.append(jsonObject.getStr("nickName")).append("、");
- }
- }
- // 循环完之后,去除最后一个顿号
- incidentProcess.setUserRead(message.toString());
- incidentProcess.setUserUnRead(unMessage.toString());
- }
- }
- }
- }
- }
- map.put("process", list);
- // 物资使用情况
- map.put("resource", resourceDetailService.queryResourceAvailable(id));
- return AjaxResult.success(map);
- }
- /**
- * 新增事件基础
- */
- @ApiOperation("新增事件基础")
- // @Log(title = "事件基础", businessType = BusinessType.INSERT)
- @RepeatSubmit()
- @PostMapping()
- @Security
- public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody IncidentBo bo) {
- // 新增初始化为预警状态
- bo.setStatus(2);
- LoginUser cacheLoginUser = UserUtil.getCacheLoginUser();
- bo.setCreateBy(cacheLoginUser.getUsername());
- bo.setCreateDept(cacheLoginUser.getUser().getDeptId());
- bo.setExpr1(cacheLoginUser.getUser().getPhonenumber());
- String id = iIncidentService.insertByBo(bo);
- JSONObject jsonObject = new JSONObject();
- jsonObject.set("incidentId", id);
- jsonObject.set("userId", cacheLoginUser.getUserId());
- jsonObject.set("source", "1");
- RedisUtils.publish(Constants.INCIDENT_USER, jsonObject, msg -> {
- log.info("保存事件人员关系 => " + msg);
- });
- return toAjax(true);
- }
- /**
- * 修改事件基础
- */
- @ApiOperation("修改事件基础")
- // @PreAuthorize("@ss.hasPermi('zhdd:incident:edit')")
- // @Log(title = "事件基础", businessType = BusinessType.UPDATE)
- @RepeatSubmit()
- @PutMapping()
- @Security
- public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody IncidentBo bo) {
- return toAjax(iIncidentService.updateByBo(bo) ? 1 : 0);
- }
- /**
- * 删除事件基础
- */
- @ApiOperation("删除事件基础")
- // @PreAuthorize("@ss.hasPermi('zhdd:incident:remove')")
- @Log(title = "事件基础", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
- @PathVariable String[] ids) {
- return toAjax(iIncidentService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
- }
- @ApiOperation("新增事件方案")
- // @Log(title = "事件方案", businessType = BusinessType.INSERT)
- @RepeatSubmit()
- @PostMapping("/task")
- public AjaxResult<Void> addTask(@Validated(AddGroup.class) @RequestBody IncidentTasksBo bo) {
- return toAjax(incidentTaskService.insertByBo(bo) ? 1 : 0);
- }
- @ApiOperation("删除事件方案")
- // @Log(title = "事件方案", businessType = BusinessType.DELETE)
- @DeleteMapping("/task/{ids}")
- public AjaxResult<Void> removeTask(@NotEmpty(message = "主键不能为空")
- @PathVariable String[] ids) {
- return toAjax(incidentTaskService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
- }
- @ApiOperation("事件方案发送")
- @RepeatSubmit()
- @PostMapping("/taskSend")
- public AjaxResult<Void> taskSend(@RequestBody IncidentTasksBo bo) {
- return toAjax(incidentTaskService.taskSend(bo) ? 1 : 0);
- }
- @ApiOperation("查询事件-用于首页地图展示")
- @GetMapping("/location")
- public AjaxResult<Map<String, List<IncidentVo>>> queryIncidentLocation() {
- List<IncidentVo> list = iIncidentService.listVo(Wrappers.<Incident>lambdaQuery().in(Incident::getStatus, 1, 2, 3));
- Map<Integer, List<IncidentVo>> collect = list.stream().collect(Collectors.groupingBy(IncidentVo::getStatus, Collectors.mapping(a -> a, Collectors.toList())));
- Map<String, List<IncidentVo>> result = new HashMap<>();
- result.put("预警事件", CollUtil.defaultIfEmpty(collect.get(2), new ArrayList<>()));
- // result.put("待派发", CollUtil.defaultIfEmpty(collect.get(2), new ArrayList<>()));
- result.put("处置", CollUtil.defaultIfEmpty(collect.get(3), new ArrayList<>()));
- return AjaxResult.success(result);
- }
- @ApiOperation("事件报告导出")
- @GetMapping("/download")
- public void download(@RequestParam String id, HttpServletRequest request, HttpServletResponse response) {
- // id为事件id
- Map<String, Object> map = new HashMap<>();
- IncidentVo incidentVo = iIncidentService.queryById(id);
- if (incidentVo != null) {
- map.put("name", incidentVo.getName());
- /*if (ObjectUtil.isNotEmpty(incidentVo.getType())) {
- map.put("type", sysDictDataService.selectDictLabel("zhdd_plan_type", Convert.toStr(incidentVo.getType())));
- } else {
- map.put("type", "-");
- }*/
- map.put("createTime", DateUtil.formatDateTime(incidentVo.getCreateTime()));
- map.put("addr", incidentVo.getAddr());
- map.put("commanderText", StrUtil.blankToDefault(incidentVo.getCommanderText(), "无"));
- map.put("madinDeptText", StrUtil.blankToDefault(incidentVo.getMadinDeptText(), "部门无"));
- map.put("assistDeptText", StrUtil.blankToDefault(incidentVo.getAssistDeptText(), "部门无"));
- // 解析主办部门和协办部门人员
- String madinDeptUser = incidentVo.getMadinDeptUser();
- if (StrUtil.isNotBlank(madinDeptUser)) {
- List<MessagePushUser> messagePushUsers = JSONUtil.toList(madinDeptUser, MessagePushUser.class);
- map.put("madinDeptUser", messagePushUsers.stream().map(MessagePushUser::getNickName).collect(Collectors.joining(",")));
- } else {
- map.put("madinDeptUser", "人员无");
- }
- String assistDeptUser = incidentVo.getAssistDeptUser();
- if (StrUtil.isNotBlank(assistDeptUser)) {
- List<MessagePushUser> messagePushUsers = JSONUtil.toList(assistDeptUser, MessagePushUser.class);
- map.put("assistDeptUser", messagePushUsers.stream().map(MessagePushUser::getNickName).collect(Collectors.joining(",")));
- } else {
- map.put("assistDeptUser", "人员无");
- }
- map.put("conclusionDeal", StrUtil.blankToDefault(incidentVo.getConclusionDeal(), "无"));
- map.put("conclusion", StrUtil.blankToDefault(incidentVo.getConclusion(), "无"));
- /*if (StrUtil.isNotBlank(incidentVo.getSource())) {
- map.put("source", sysDictDataService.selectDictLabel("zhdd_incident_source", incidentVo.getSource()));
- } else {
- map.put("source", "-");
- }
- if (ObjectUtil.isNotEmpty(incidentVo.getLevel())) {
- map.put("level", sysDictDataService.selectDictLabel("zhdd_incident_level", Convert.toStr(incidentVo.getLevel())));
- } else {
- map.put("level", "-");
- }*/
- // 查询处置方案
- List<IncidentTaskVo> incidentTasks = incidentTaskService.listTaskInfo(id);
- if (incidentTasks != null && incidentTasks.size() > 0) {
- StringBuilder tasks = new StringBuilder();
- for (int i = 0; i < incidentTasks.size(); i++) {
- tasks.append(i + 1).append("、").append(incidentTasks.get(i).getTaskName()).append("\r");
- }
- map.put("tasks", tasks.toString());
- } else {
- map.put("tasks", "无");
- }
- // 查询处置过程
- List<IncidentProcess> incidentProcess = processService.list(Wrappers.<IncidentProcess>lambdaQuery()
- .eq(IncidentProcess::getIncidentId, id).orderByAsc(IncidentProcess::getCreateTime));
- if (incidentProcess != null && incidentProcess.size() > 0) {
- StringBuilder processs = new StringBuilder();
- for (int i = 0; i < incidentProcess.size(); i++) {
- processs.append(i + 1).append("、").append(incidentProcess.get(i).getDes()).append("\r");
- }
- map.put("processs", processs.toString());
- } else {
- map.put("processs", "无");
- }
- }
- String fileName = "incident_" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + ".docx";
- try {
- XWPFDocument doc = WordExportUtil.exportWord07(
- "word/incidentDetail.docx", map);
- FileOutputStream fos = new FileOutputStream(ExcelUtil.getAbsoluteFile(fileName));
- doc.write(fos);
- // 设置强制下载不打开
- response.setContentType("application/force-download");
- // 设置文件名
- response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);
- OutputStream out = response.getOutputStream();
- doc.write(out);
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- delFileWord(ExcelUtil.getAbsoluteFile(fileName));
- }
- }
- @ApiOperation("事件执行日志导出")
- @GetMapping("/processDownload")
- public void processDownload(@RequestParam String id, HttpServletRequest request, HttpServletResponse response) {
- // id为事件id
- Map<String, Object> map = new HashMap<>();
- IncidentVo incidentVo = iIncidentService.queryById(id);
- if (incidentVo != null) {
- map.put("name", incidentVo.getName());
- // 查询处置过程
- List<IncidentProcess> incidentProcess = processService.list(Wrappers.<IncidentProcess>lambdaQuery()
- .eq(IncidentProcess::getIncidentId, id).orderByAsc(IncidentProcess::getCreateTime));
- for (IncidentProcess process : incidentProcess) {
- process.setCreateTimeText(DateUtil.formatDateTime(process.getCreateTime()));
- }
- map.put("process", incidentProcess);
- }
- String fileName = "incident_log_" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + ".docx";
- try {
- XWPFDocument doc = WordExportUtil.exportWord07(
- "word/incidentProcess.docx", map);
- FileOutputStream fos = new FileOutputStream(ExcelUtil.getAbsoluteFile(fileName));
- doc.write(fos);
- // 设置强制下载不打开
- response.setContentType("application/force-download");
- // 设置文件名
- response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);
- OutputStream out = response.getOutputStream();
- doc.write(out);
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- delFileWord(ExcelUtil.getAbsoluteFile(fileName));
- }
- }
- @ApiOperation("复制事件应急方案")
- @RepeatSubmit()
- @PostMapping("/copyTask")
- public AjaxResult<Void> copyTask(@RequestBody JSONObject jsonObject) {
- String oldId = jsonObject.getStr("oldIncidentId");
- String newId = jsonObject.getStr("newIncidentId");
- if (StrUtil.hasBlank(oldId, newId)) {
- return AjaxResult.error("参数存在空值!");
- }
- return toAjax(incidentTaskService.copyTask(oldId, newId) ? 1 : 0);
- }
- @ApiOperation("查询事件处置方案是否办结")
- @RepeatSubmit()
- @GetMapping("/queryTaskFinish")
- public AjaxResult queryTaskFinish(@RequestParam String taskId) {
- IncidentTaskVo voOne = incidentTaskService.getVoOne(Wrappers.<IncidentTask>lambdaQuery()
- .eq(IncidentTask::getId, taskId)
- .in(IncidentTask::getSendFlag, "2", "3")
- .eq(IncidentTask::getTaskSend, "1")
- .eq(IncidentTask::getBackLogFlag, "0"));
- if (voOne != null) {
- return AjaxResult.success(true);
- } else {
- return AjaxResult.success(false);
- }
- }
- @ApiOperation("待办消息办结")
- @RepeatSubmit()
- @PostMapping("/backLogFinish")
- public AjaxResult<Void> backLogFinish(@RequestBody JSONObject jsonObject) {
- String id = jsonObject.getStr("taskId");
- if (StrUtil.isBlank(id)) {
- return AjaxResult.error("参数存在空值!");
- }
- return toAjax(processService.backLogFinish(id) ? 1 : 0);
- }
- /**
- * 删除零时生成的文件
- */
- public static void delFileWord(String filePath) {
- File file = new File(filePath);
- file.delete();
- }
- }
|