package com.ruoyi.project.tr.hiddenDangerCheck.controller; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.util.StringUtil; import com.ruoyi.common.constant.TrHiddenDangerCheckConstants; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.security.ShiroUtils; import com.ruoyi.doublePrevention.entity.PreventRiskDangerConfirmLog; import com.ruoyi.doublePrevention.entity.PreventRiskDangerInfo; import com.ruoyi.doublePrevention.service.RiskService; import com.ruoyi.doublePrevention.service.baseService.PreventRiskDangerConfirmLogService; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.framework.web.controller.BaseController; import com.ruoyi.framework.web.domain.AjaxResult; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.framework.web.service.JpushService; import com.ruoyi.project.system.user.domain.User; import com.ruoyi.project.system.user.service.IUserService; import com.ruoyi.project.tr.JpushMsg.domain.JpushMsg; import com.ruoyi.project.tr.JpushMsg.service.IJpushMsgService; import com.ruoyi.project.tr.hiddenDangerCheckPoint.domain.HiddenDangerCheckPoint; import com.ruoyi.project.tr.hiddenDangerCheckPoint.service.IHiddenDangerCheckPointService; import org.apache.commons.lang3.ObjectUtils; import org.apache.ibatis.javassist.expr.NewArray; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 隐患核查Controller * * * @date 2020-05-08 */ @Controller @RequestMapping("/tr/hiddenDangerCheck/dangerExamine") public class DangerExamineController extends BaseController { private String prefix = "tr/hiddenDangerCheck/dangerExamine"; @Autowired private IHiddenDangerCheckPointService hiddenDangerCheckPointService; @Autowired private IUserService userService; @Autowired JpushService jpushService; @Autowired private PreventRiskDangerConfirmLogService confirmLogService; @Autowired private RiskService riskService; @GetMapping() public String dangerExamine() { return prefix + "/dangerExamine"; } @GetMapping("/listByCompanyId/{companyId}") public String listByCompanyId(@PathVariable("companyId") Long companyId, ModelMap mmap) { mmap.put("companyId", companyId); return prefix + "/dangerExamineListByCompanyId"; } /** * 查询隐患核查列表 */ @PostMapping("/listByCompanyId") @ResponseBody public TableDataInfo listByCompanyId(String companyId,HiddenDangerCheckPoint hiddenDangerCheckPoint) { User userQuery = new User(); userQuery.setCompanyId(Long.valueOf(companyId)); List userList = userService.selectUserList(userQuery); List userIdList = new ArrayList<>(); for (User user : userList){ userIdList.add(user.getUserId()); } if(userIdList.size()==0){ return getDataTable(new ArrayList()); } hiddenDangerCheckPoint.setExamineUserIdList(userIdList);//隐患整改人ID 为登陆账号companyId下的userId的 // hiddenDangerCheckPoint.setExamineStatus(TrHiddenDangerCheckConstants.EXAMINE_STATUS_NOT_EXAMINE);/** 核查状态(待核查) */ startPage(); List list = hiddenDangerCheckPointService.selectHiddenDangerCheckPointList(hiddenDangerCheckPoint); for (HiddenDangerCheckPoint dangerCheck : list) { List logsByDangerCheckPointId = confirmLogService.getLogsByDangerCheckPointId(dangerCheck.getId()); if (logsByDangerCheckPointId.size() > 0){ dangerCheck.setConfirmLogList(logsByDangerCheckPointId); } } return getDataTable(list); } /** * 查询隐患核查列表 */ @PostMapping("/list") @ResponseBody public TableDataInfo list(HiddenDangerCheckPoint hiddenDangerCheckPoint) { startPage(); hiddenDangerCheckPoint.setExamineUserId(getSysUser().getUserId());//核查人为本登录帐号userId的 List list = hiddenDangerCheckPointService.selectHiddenDangerCheckPointList(hiddenDangerCheckPoint); for (HiddenDangerCheckPoint dangerCheck : list) { List logsByDangerCheckPointId = confirmLogService.getLogsByDangerCheckPointId(dangerCheck.getId()); if (logsByDangerCheckPointId.size() > 0){ dangerCheck.setConfirmLogList(logsByDangerCheckPointId); } } return getDataTable(list); } /** * 隐患核查--下一个核查人 */ @Log(title = "隐患核查--核查") @GetMapping("/editNextConfirm/{id}") public String editNextConfirm(@PathVariable("id") Long id, ModelMap mmap) { //隐患排查实体 HiddenDangerCheckPoint hiddenDangerCheckPoint = hiddenDangerCheckPointService.selectHiddenDangerCheckPointById(Long.valueOf(id)); mmap.put("hdcp", hiddenDangerCheckPoint); //获取所在公司人员信息 User sysUser = getSysUser(); if (sysUser != null && sysUser.getCompanyId() != null) { User userTemp = new User(); userTemp.setCompanyId(sysUser.getCompanyId()); List userList = userService.selectUserList(userTemp); mmap.put("userList", userList); } return prefix + "/editNextConfirm"; } /** * 隐患核查--下一个核查人 */ @Log(title = "隐患核查--下一个核查人") @PostMapping("/editNextConfirmSave") @ResponseBody public AjaxResult editNextConfirmSave(HiddenDangerCheckPoint hdcp) { //获取当前更新用户信息 User sysUser = getSysUser(); if(ObjectUtils.isEmpty(hdcp.getId())){ return AjaxResult.error("id不能为空"); } // examine_user_id , 核查人id if(ObjectUtils.isEmpty(hdcp.getExamineUserId())){ return AjaxResult.error("核查人Id不能为空"); } // examine_user_name if(ObjectUtils.isEmpty(hdcp.getExamineUserName())){ return AjaxResult.error("核查人姓名不能为空"); } int i = confirmLogService.saveConfirmLog(hdcp); if (i < 1){ return AjaxResult.error("操作失败"); } return toAjax(i); } /** * 隐患核查--核查 */ @Log(title = "隐患核查--核查") @GetMapping("/editDangerExamine/{id}") public String editDangerExamine(@PathVariable("id") Long id, ModelMap mmap) { //隐患排查实体 HiddenDangerCheckPoint hiddenDangerCheckPoint = hiddenDangerCheckPointService.selectHiddenDangerCheckPointById(Long.valueOf(id)); mmap.put("hdcp", hiddenDangerCheckPoint); //获取所在公司人员信息 User sysUser = getSysUser(); if (sysUser != null && sysUser.getCompanyId() != null) { User userTemp = new User(); userTemp.setCompanyId(sysUser.getCompanyId()); List userList = userService.selectUserList(userTemp); mmap.put("userList", userList); } return prefix + "/editDangerExamine"; } /** * 隐患核查--保存 * */ @Log(title = "隐患核查--保存", businessType = BusinessType.UPDATE) @PostMapping("/editDangerExamineSave") @ResponseBody public AjaxResult editDangerExamineSave(HiddenDangerCheckPoint hiddenDangerCheckPoint) { //获取当前更新用户信息 User sysUser = getSysUser(); // todo-2024 hiddenDangerCheckPoint.setUpdateBy(ShiroUtils.getLoginName()); hiddenDangerCheckPoint.setUpdateTime(DateUtils.getNowDate()); hiddenDangerCheckPoint.setExamineCreateTime(DateUtils.getNowDate());//设置核查时间 hiddenDangerCheckPoint.setExamineStatus(TrHiddenDangerCheckConstants.EXAMINE_STATUS_ALREADY_EXAMINE);//核查状态(已核查) if(!StringUtil.isEmpty(hiddenDangerCheckPoint.getDangerLevel())){ if(("0".equals(hiddenDangerCheckPoint.getDangerLevel())) ||("1".equals(hiddenDangerCheckPoint.getDangerLevel()))){//0 一般隐患 1 重大隐患 hiddenDangerCheckPoint.setRectifyStatus(TrHiddenDangerCheckConstants.RECTIFY_STATUS_NOT_RECTIFY);//整改状态(未整改) hiddenDangerCheckPoint.setStage(TrHiddenDangerCheckConstants.DANGER_STAGE_PLAN_RECTIFY);//隐患整改阶段(数据进入到隐患整改阶段) }else if(("2".equals(hiddenDangerCheckPoint.getDangerLevel()))){ //2 不是隐患 hiddenDangerCheckPoint.setWhetherDanger(TrHiddenDangerCheckConstants.WHETHER_DANGER_NOT);//是否为隐患(正常) } } int i = hiddenDangerCheckPointService.updateHiddenDangerCheckPoint(hiddenDangerCheckPoint); if(hiddenDangerCheckPoint.getRectifyDeadlineTime()!=null) { rectifyRemindJPush(hiddenDangerCheckPoint); } //此处插入隐患附属表 20250623 位置变更注释掉 //HiddenDangerCheckPoint hiddenDangerCheckPointById = hiddenDangerCheckPointService.getHiddenDangerCheckPointById(hiddenDangerCheckPoint.getId()); // int result = riskService.insertDangerInfo(hiddenDangerCheckPoint.getId(), hiddenDangerCheckPoint); // if (result< 1){ // throw new RuntimeException("添加隐患附属信息失败"); // } HiddenDangerCheckPoint hdcp = hiddenDangerCheckPointService.getHiddenDangerCheckPointById(hiddenDangerCheckPoint.getId()); int confirmResult = confirmLogService.saveConfirmLog(hdcp); if (confirmResult < 1){ return AjaxResult.error("操作失败"); } hiddenDangerCheckPointService.getTaskCountTotal(getSysUser().getUserId());//查询未执行任务总数量并推送 return toAjax(i); } //整改任务发布时 推送 /** * @param hiddenDangerCheckPoint */ public void rectifyRemindJPush(HiddenDangerCheckPoint hiddenDangerCheckPoint) { HiddenDangerCheckPoint whole = hiddenDangerCheckPointService.selectHiddenDangerCheckPointById(hiddenDangerCheckPoint.getId()); String title = "您有一项隐患待整改"; String content = "【隐患整改任务】您有一项隐患待整改,(隐患描述:"+whole.getDangerDescription()+"), 需要在" + "(" + DateUtils.parseDateToStr("yyyy-MM-dd", whole.getRectifyDeadlineTime())+")," + "之前整改完成。"; Map extrasMap = new HashMap(); extrasMap.put("message", "这是一个整改待处理通知"); extrasMap.put("methodType", "goToRectify"); extrasMap.put("hiddenDangerCheckPoint", JSONObject.toJSONString(whole)); //大文本通知栏样式 jpushService.sendPushByAndroidBigText(title, content, 1, content, extrasMap, whole.getRectifyUserId().toString()); } /** * 隐患核查--查看 */ @Log(title = "隐患核查--查看") @GetMapping("/detailDangerExamine/{id}") public String detailDangerExamine(@PathVariable("id") Long id, ModelMap mmap) { //隐患排查实体 HiddenDangerCheckPoint hiddenDangerCheckPoint = hiddenDangerCheckPointService.selectHiddenDangerCheckPointById(Long.valueOf(id)); PreventRiskDangerInfo dangerInfo = riskService.getDangerInfoById(hiddenDangerCheckPoint.getId()); if (ObjectUtils.isNotEmpty(dangerInfo)){ hiddenDangerCheckPoint.setHazardCode(dangerInfo.getHazardCode()); hiddenDangerCheckPoint.setDangerSrc(dangerInfo.getDangerSrc()); hiddenDangerCheckPoint.setDangerReason(dangerInfo.getDangerReason()); hiddenDangerCheckPoint.setHazardDangerType(dangerInfo.getHazardDangerType()); hiddenDangerCheckPoint.setDangerResult(dangerInfo.getDangerResult()); } mmap.put("hdcp", hiddenDangerCheckPoint); return prefix + "/detailDangerExamine"; } }