qa-prevention-gwj/src/main/java/com/zcloud/controller/hiddenApi/HiddenApiController.java

1466 lines
68 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.zcloud.controller.hiddenApi;
import com.alibaba.fastjson.JSON;
import com.zcloud.aspect.DockAnnotation;
import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.entity.system.Department;
import com.zcloud.entity.system.Dictionaries;
import com.zcloud.service.announcement.TemplateAnnounService;
import com.zcloud.service.bus.*;
import com.zcloud.service.hiddenApi.*;
import com.zcloud.service.inspection.SafetyEnvironmentalService;
import com.zcloud.service.system.DepartmentService;
import com.zcloud.service.system.DictionariesService;
import com.zcloud.service.system.FHlogService;
import com.zcloud.service.system.UsersService;
import com.zcloud.util.*;
import com.zcloud.util.event.DeviceHiddenEvent;
import com.zcloud.util.message.MessageService;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 说明:隐患 作者guoyuepeng
* 如果修改请修改相关文档
*/
@Controller
@RequestMapping("/hiddenApi")
public class HiddenApiController extends BaseController {
@Autowired
private HiddenApiService hiddenApiService;
@Autowired
private DepartmentService departmentService; // 部门信息
@Autowired
private ImgFilesService imgFilesService; //附件信息
@Autowired
private HiddenRegionService hiddenRegionService; // 隐患区域维护
@Autowired
private HiddenExamineApiService hiddenExamineApiService; //隐患审核 隐患的审核步骤的人员的信息的记录
@Autowired
private HiddenUserApiService hiddenUserApiService; // 隐患相关人员信息
@Autowired
private RecordItemService recordItemService; //清单检查记录
@Autowired
private HiddenSchemeApiService hiddenSchemeApiService;
@Autowired
private HiddenCheckApiService hiddenCheckApiService; //隐患验收人
@Autowired
private UsersService usersService;
@Autowired
private FHlogService FHLOG;//日志记录
@Resource
private ApplicationContext applicationContext;
@Autowired
private SafetyEnvironmentalService safetyenvironmentalService;
@Autowired
private DictionariesService dictionariesService;
@Autowired
private MessageService messageService;
/**
* 暂时没有修改的内容
*/
@Autowired
private HiddenService hiddenService;
@Autowired
private NoticeCorpUtil noticeUtil;
@Autowired
private HiddenSchemeService hiddenSchemeService;
@Autowired
private HiddenUserService hiddenUserService; // 隐患相关人员信息
@Autowired
private HiddenCheckService hiddenCheckService;
@Autowired
private HiddenExamineService hiddenExamineService;
/**
* 添加隐患信息,以后都会使用这一个接口
* 如果就修改,请通知
* <p>
* 问题:暂存的问题 已经完成
* 所有的参数是否是必填
* 返回参数有固定信息
*
* @return
* @throws Exception
*/
@RequestMapping(value = "/addHidden")
@RequiresPermissions("hidden:add")
@ResponseBody
@DockAnnotation
public Object addHiddenApi() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
/** 必填选项
* SOURCE 隐患来源
* HIDDENDESCR 隐患描述
* DISCOVERYTIME 发现时间 2022-08-17 10:08
* RECTIFICATIONTYPE 整改类型( 1 立即整改 2 限期整改)
* HIDDENLEVEL 隐患级别 字典 5e7cf8620ba54ad89719d0be62133c7a编码
* CONFIRM_USER 隐患确认人
* HIDDENTYPE 隐患类型, 字典 3babc15144444bdc8d763d0af2bdfff6 ,编码
* ISRELEVANT 是否相关方1是2否 默认否
* 如果是清单的时候
* RISK_UNIT 风险单元
* IDENTIFICATION 辨识部位
* RISK_DESCR 存在风险
* RISK_POSITION 风险点位置
* LEVEL 风险分级
* CHECK_CONTENT 检查内容
*
* 如果是立即整改
* RECTIFYDESCR 整改描述
*
* 隐患图片 ,隐患视频 自己通过上传附件上传,暂时不处理
*/
/** 缺少必填参数:RISK_UNIT IDENTIFICATION RISK_POSITION 暂存 */
String serl = "SOURCE,HIDDENDESCR,DISCOVERYTIME,RECTIFICATIONTYPE,HIDDENLEVEL," +
"HIDDENTYPE,ISRELEVANT";
if ("2".equals(pd.getString("SOURCE")) || "6".equals(pd.getString("SOURCE"))) {//如果是清单检查,需要填入其他必填项
// serl +=",RISK_UNIT,IDENTIFICATION,RISK_DESCR,RISK_POSITION,LEVEL,CHECK_CONTENT";
serl += ",RISK_DESCR,LEVEL,CHECK_CONTENT";
}
if (!Tools.isEmpty(pd.getString("HIDDENPART"))) { // 如果用户选择或者填入隐患部位,就需要知道是选择的还是手填的
serl += ",hiddenPartType";
}
if ("1".equals(pd.getString("RECTIFICATIONTYPE"))) { //如果用户立即整改。就需要填入整改描述
serl += ",RECTIFYDESCR";
}
Integer code = HasAllRequired.hasAllRequired(pd, serl);
if (code != 000000) {
return ResultCodeConstant.resMap(code);
}
/** 需要我必填的 */
pd.put("HIDDEN_ID", this.get32UUID());
if ("0".equals(pd.getString("STATE"))) { //在上传隐患清单的时候,需要暂存信息,其他清单全部都是待确认
pd.put("STATE", "0");
} else {
pd.put("STATE", "-2");
}
pd.put("CREATOR", Jurisdiction.getUSER_ID());
pd.put("CREATTIME", DateUtil.date2Str(new Date()));
pd.put("ISDELETE", "0");
pd.put("ISCONFIRM", "0"); //
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
/** 处理 隐患 部位的方法 .如果用户填入的隐患部位是输入的 */
if ("value".equals(pd.getString("hiddenPartType"))) {
PageData hiddenRegion = hiddenRegionService.saveHidden(pd.getString("HIDDENPART"));
pd.put("saveHidden",JSON.toJSONString(hiddenRegion));
pd.put("HIDDENPART", hiddenRegion.getString("HIDDENREGION_ID"));
}
/** 隐患的主要负责人 一条隐患 多个隐患发现人 ,把多个信息填入这个张表中 */
PageData saveRectificationo = hiddenUserApiService.saveRectificationo(pd.getString("findCreator"), pd.getString("HIDDEN_ID"), "1", Jurisdiction.getUSER_ID());
pd.put("saveRectificationo",JSON.toJSONString(saveRectificationo));
/** 初始化隐患确认信息 记录隐患发现人的隐患等级等信息 */
PageData saveConfirm = hiddenExamineApiService.saveConfirm(pd, "0");
pd.put("saveConfirm",JSON.toJSONString(saveConfirm));
/* 隐患的立即整改 填入整改信息,其他的信息是一样的 */
if ("1".equals(pd.getString("RECTIFICATIONTYPE"))) {
pd.put("RECTIFICATIONTIME", DateUtil.getDay()); // 整改时间
pd.put("RECTIFICATIONOR", Jurisdiction.getUSER_ID()); // 整改人
pd.put("RECTIFICATIONDEPT", Jurisdiction.getDEPARTMENT_ID()); // 整改部门
pd.put("STATE", "-2");
}
/** 重大隐患管理 , 如果是重大隐患,隐患确认必须是部门负责人*/
if (pd.getString("HIDDENLEVEL").equals("jdyh001") || pd.getString("HIDDENLEVEL").equals("hiddenLevel2002")) {
//判断是否是重大隐患
PageData loginDeptPd = new PageData();
loginDeptPd.put("DEPARTMENT_ID", Jurisdiction.getDEPARTMENT_ID());
PageData longinfoUserDept = departmentService.findById(loginDeptPd);//获取登录人部门信息
if (Tools.isEmpty(longinfoUserDept) || Tools.isEmpty(longinfoUserDept.getString("HEADMAN"))) {
// 查看部门是否有负责人
return ResultCodeConstant.resMap(000201); //所在部门未维护部门负责人
} else {
//如何维护了,隐患确认人就要成为部门负责人
pd.put("CONFIRM_USER", longinfoUserDept.getString("HEADMAN"));//通过名字查询用户获取出ID
}
}
pd.put("saveApi",JSON.toJSONString(pd));
hiddenApiService.saveApi(pd);
/* 发送隐患的通知公告 */
Map<String, Object> notRepr = new HashMap<>();
notRepr.put("hiddendescr", pd.getString("HIDDENDESCR"));//
if (pd.getString("HIDDENLEVEL").equals("jdyh001") || pd.getString("HIDDENLEVEL").equals("hiddenLevel2002")) {
notRepr.put("params2", "重大隐患管理 - 发现隐患部门责任人确认");//
} else {
notRepr.put("params2", "隐患确认");//
}
notRepr.put("params3", "确认");//
messageService.sendMessageByParameter("HIDDEN_MAIL_001", "友情提示:有一条隐患需要确认", Jurisdiction.getCORPINFO_ID(), pd.getString("CONFIRM_USER"), pd.getString("HIDDEN_ID"),
pd.getString("HIDDENDESCR"), "隐患确认", "确认", "", "");
/**
* 可以为空的
* POSITIONDESC 隐患位置描述
* HIDDENPART 隐患部位 (可以手写,如果传入,就要传入 hiddenPartType)
* hiddenPartType(select选择的传入id,value输入的)
* 隐患位置信息
* LONGITUDE 经度 LATITUDE 纬度(自己的地图)
* findCreator ,多个隐患发现人的时候填写逗号分割, (去除自己)
* 整改部门 , RECTIFICATIONDEPT
* 整改人, RECTIFICATIONOR
* 整改期限 RECTIFICATIONDEADLINE
*
*/
map.put("result", errInfo);
map.put("pd", pd);
map.put("dockData",JSON.toJSONString(pd));
return map;
}
/**
* 业务 是否删除隐患照片以及视频
* 删除
* 1.当隐患是隐患清单检出的时候,产出隐患清单检查记录
* 当隐患是 消防检查的时候 删除记录
* 安环环保检查的时候删除什么
*
* @throws Exception
*/
@RequestMapping(value = "/deleteHiddenApi")
@RequiresPermissions("hidden:delete")
@ResponseBody
public Object deleteHiddenApi() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Integer code = 000000;
PageData pd = new PageData();
pd = this.getPageData();
/** 必填项隐患id **/
String serl = "HIDDEN_ID";
code = HasAllRequired.hasAllRequired(pd, serl);
if (code != 000000) {
return ResultCodeConstant.resMap(code);
}
PageData hidden = hiddenApiService.findById(pd);
if ("4".equals(hidden.getString("SOURCE")) || "5".equals(hidden.getString("SOURCE"))) { //安环环保检查的隐患暂时不让删除,业务逻辑暂时没有
return ResultCodeConstant.resMap(000202);
}
Integer deleteHidden = hiddenApiService.deleteApi(pd.getString("HIDDEN_ID")); //修改隐患的状态
map.put("deleteHidden", deleteHidden);
/** 隐患相关人员 */
Integer deleteHiddenUserType = hiddenUserApiService.deleteByHidden(pd.getString("HIDDEN_ID"));
map.put("deleteHiddenUserType", deleteHiddenUserType);
/** 删除隐患流程信息 */
Integer deleteHiddenExaType = hiddenExamineApiService.deleteByHiddenId(pd);
map.put("deleteHiddenExaType", deleteHiddenExaType);
/**
* 删除清单记录 * 修改安全环保检查信息 * 修改消防检查信息
*/
if ("2".equals(pd.getString("SOURCE"))) { //删除清单记录
PageData ri = new PageData();
ri.put("ISNORMAL", "0");
ri.put("CHECKRECORD_ID", pd.get("CHECKRECORD_ID"));
ri.put("LISTMANAGER_ID", pd.get("LISTMANAGER_ID"));
ri.put("LISTCHECKITEM_ID", pd.get("RISKITEM_ID"));
Integer deleterecordItemType = recordItemService.editIsnormal(ri);
map.put("deleterecordItemType", deleterecordItemType);
}
applicationContext.publishEvent(new DeviceHiddenEvent(new Object(), pd.getString("HIDDEN_ID"), "1"));
return ResultCodeConstant.resMap(code, map);
}
/**
* 根据隐患id获取数据
*
* @return
* @throws Exception
*/
@RequestMapping(value = "/getHiddenById")
@RequiresPermissions("hidden:list")
@ResponseBody
public Object getHiddenById() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Integer code = 000000;
PageData pd = new PageData();
pd = this.getPageData();
/** 必填项隐患id 隐患来源 **/
String serl = "HIDDEN_ID";
code = HasAllRequired.hasAllRequired(pd, serl);
if (code != 000000) {
return ResultCodeConstant.resMap(code);
}
PageData hidden = hiddenApiService.findById(pd);
PageData hs = hiddenSchemeApiService.findByHdId(pd);/* * 查询整改方案 */
map.put("hs", hs);
List<PageData> checkAllList = hiddenCheckApiService.listAll(pd); // 全部隐患验收信息
if (checkAllList != null && checkAllList.size() > 0) {
PageData pd3 = new PageData();
pd3.put("TYPE", 5);
for (PageData check : checkAllList) {
pd3.put("FOREIGN_KEY", check.get("HIDDENCHECK_ID"));
check.put("cImgs", imgFilesService.listAll(pd3));// 验收图片
}
}
map.put("checkList", checkAllList);
List<PageData> hiddenExa = hiddenExamineApiService.listAllByHiddenId(pd.getString("HIDDEN_ID")); //隐患的流程信息
map.put("hiddenExa", hiddenExa); // //特殊审批信息
for (PageData pageData : hiddenExa) {
if ("0".equals(pageData.getString("TYPE"))) {
hidden.put("editUserName", pageData.getString("editUserName"));
hidden.put("editDeptName", pageData.getString("editDeptName"));
hidden.put("editLevelName", pageData.getString("editLevelName"));
hidden.put("editRectificationDeadline", pageData.getString("spare3"));
}
}
map.put("hidden", hidden);
List<PageData> hiddenFindPeople = hiddenUserApiService.listAll(pd);// 隐患相关人员信息 --隐患发现人
map.put("hiddenFindPeople", hiddenFindPeople); // //特殊审批信息
if (hidden != null) {
List<PageData> imgListAll = imgFilesService.getListByKeyAndType(pd.getString("HIDDEN_ID"));
Map<String, List<PageData>> imgMapListAll = new HashMap<>(imgListAll.size());
for (PageData pageData : imgListAll) {
List<PageData> img = new ArrayList<>();
if (imgMapListAll.containsKey(pageData.getString("TYPE"))) {
img = imgMapListAll.get(pageData.getString("TYPE"));
}
img.add(pageData);
imgMapListAll.put(pageData.getString("TYPE"), img);
}
map.put("hiddenVideo", imgMapListAll.get("102"));// 隐患视频
if (imgMapListAll.containsKey("102")) {
if (imgMapListAll.get("102").size() > 0) {
map.put("hiddenVideoSrc", imgMapListAll.get("102").get(0).getString("FILEPATH"));// 隐患视频
}
}
map.put("hImgs", imgMapListAll.get("3"));// 隐患图片
map.put("rImgs", imgMapListAll.get("4"));// 整改图片
map.put("fcImgs", imgMapListAll.get("50"));// 安全环保检查验收图片
map.put("majorinforPdf", imgMapListAll.get("106"));// 重大隐患临时处置信息
map.put("majorapprovedPdf", imgMapListAll.get("107"));// 港股分公司安委会办公室副主任核定 - 安委会或党委会决议记录
map.put("reportPdf", imgMapListAll.get("108"));//隐患调查报告
map.put("resolutionPdf", imgMapListAll.get("109"));//安委会或党委会决议记录
map.put("rectificationPdf", imgMapListAll.get("110"));//较大隐患整改 - 临时处置措施
map.put("processPdf", imgMapListAll.get("111"));//较大隐患整改 - 隐患整改过程记录
map.put("supplementPdf", imgMapListAll.get("112"));//较大隐患整改 - 补充重大隐患信息(确认时)
map.put("safetyofficePdf", imgMapListAll.get("113"));//较大隐患整改 - 安委会办公室会议记录(分公司核实时)
map.put("sImgs", imgMapListAll.get("8"));// 方案图片
}
if (pd.getString("HIDDENLEVEL").equals("jdyh001") || pd.getString("HIDDENLEVEL").equals("hiddenLevel2002")) {//判断是否是重大隐患
// List<PageData> resultslist = hiddenMajorService.findById(pd);
}
/**隐患的整改方案 **/
return ResultCodeConstant.resMap(code, map);
}
/**
* 确认隐患
*
* @param
* @throws Exception
*/
@RequestMapping(value = "/confirmHidden")
@RequiresPermissions("hidden:edit")
@ResponseBody
@DockAnnotation(isAdd = true)
public Object confirmHidden() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Integer code = 000000;
PageData pd = new PageData();
pd = this.getPageData();
String HIDDENLEVEL = pd.getString("HIDDENLEVEL"); // 隐患级别
String RECTIFICATIONOR = pd.getString("RECTIFICATIONOR");//整改负责人
String RECTIFICATIONDEADLINE = pd.getString("RECTIFICATIONDEADLINE"); //整改完成期限
String RECTIFICATIONDEPT = pd.getString("RECTIFICATIONDEPT"); //整改负责人部门
/** 必填项隐患id ,隐患等级 整改部门 ,整改人 整改期限**/
/** isEmis **/
String serl = "HIDDEN_ID,HIDDENLEVEL";//是否立即整改 1 是 2 否
if (!"hiddenLevel1001".equals(pd.getString("HIDDENLEVEL"))) {
serl = "RECTIFICATIONTYPE";//是否立即整改 1 是 2 否
if ("2".equals(pd.getString("RECTIFICATIONTYPE"))) {
serl += ",RECTIFICATIONDEPT,RECTIFICATIONOR,RECTIFICATIONDEADLINE";
}
}
code = HasAllRequired.hasAllRequired(pd, serl);
if (code != 000000) {
return ResultCodeConstant.resMap(code);
}
PageData hidden = hiddenApiService.findById(pd); //获取隐患信息
// 386 ~ 409
if (!"-2".equals(hidden.getString("STATE"))) {
return ResultCodeConstant.resMap(000203);
}
if ("1".equals(pd.getString("isEmis"))) { //确认的时候如果是emis隐患,就上传emis系统,然后删除隐患
code = hiddenApiService.goEmis(pd);
return ResultCodeConstant.resMap(code); //隐患走到这就完成了
}
if ("hiddenLevel1001".equals(pd.getString("HIDDENLEVEL")) ||
"1".equals(hidden.get("RECTIFICATIONTYPE").toString())) {
// 如果是忽略隐患 或者是立即整改
pd.put("STATE", "4");
// 隐患状态修改成整改完成
// 验收人是确认人
// 整改人是提交人
PageData userPd = new PageData();
userPd.put("USER_ID", hidden.getString("CREATOR"));
PageData creatopUser = usersService.findById(userPd);
pd.put("RECTIFICATIONDEPT", creatopUser.getString("DEPARTMENT_ID"));//整改部门
pd.put("RECTIFICATIONOR", hidden.getString("CREATOR"));//整改人
pd.put("RECTIFICATIONTIME", DateUtil.date2Str(new Date(), "yyyy-MM-dd"));//整改时间
pd.put("CHECKDEPT", Jurisdiction.getDEPARTMENT_ID());//验收部门
pd.put("CHECKOR", Jurisdiction.getUSER_ID());//验收人
pd.put("CHECKTIME", DateUtil.date2Str(new Date()));//验收时间
applicationContext.publishEvent(new DeviceHiddenEvent(new Object(), pd.getString("HIDDEN_ID"), "0"));//消防检查的通知
} else {
pd.put("STATE", "1");
}
// 4 2 无整改人
hidden.put("HIDDENLEVEL",HIDDENLEVEL);
hidden.put("RECTIFICATIONOR",RECTIFICATIONOR);
hidden.put("RECTIFICATIONDEADLINE",RECTIFICATIONDEADLINE);
hidden.put("RECTIFICATIONDEPT",RECTIFICATIONDEPT);
PageData pageData = hiddenExamineApiService.saveConfirm(hidden, "4"); //添加隐患处理流程
pd.put("pageData", JSON.toJSONString(pageData));
PageData confirm = hiddenApiService.confirmHidden(pd); //确认
pd.put("confirm", JSON.toJSONString(confirm));
if (Tools.notEmpty(pd.getString("RECTIFICATIONOR")) && !hidden.getString("RECTIFICATIONTYPE").equals("1")) {
messageService.sendMessageByParameter("HIDDEN_MAIL_002", "友情提示:有一条隐患需要整改",
hidden.getString("CORPINFO_ID"), pd.getString("USER_ID"), hidden.getString("HIDDEN_ID"),
hidden.getString("HIDDENDESCR"), "隐患整改", "整改", "", "");
} else if ("1".equals(hidden.getString("RECTIFICATIONTYPE"))) {
messageService.sendMessageByParameter("HIDDEN_MAIL_003", "友情提示:有一条隐患已验收",
hidden.getString("CORPINFO_ID"), pd.getString("USER_ID"), hidden.getString("HIDDEN_ID"),
hidden.getString("HIDDENDESCR"), "通过", "整改", "", "");
}
map.put("dockData",JSON.toJSONString(pd));
return ResultCodeConstant.resMap(code, map);
}
/**
* 隐患确认的时候打回
*
* @return
* @throws Exception
*/
@RequestMapping(value = "/repulseHidden")
@RequiresPermissions("hidden:list")
@ResponseBody
@DockAnnotation
public Object repulseHidden() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Integer code = 000000;
PageData pd = new PageData();
pd = this.getPageData();
/** 必填项隐患id ,驳回意见 **/
String serl = "HIDDEN_ID,REJECTOPINION";
code = HasAllRequired.hasAllRequired(pd, serl);
if (code != 000000) {
return ResultCodeConstant.resMap(code);
}
PageData hidden = hiddenApiService.findById(pd); //获取隐患信息
if (!"-2".equals(hidden.getString("STATE"))) {
return ResultCodeConstant.resMap(000204);
}
hiddenApiService.repulseConfirm(pd.getString("HIDDEN_ID"));
PageData before = new PageData();//
before.put("TYPE", "6"); //.0.隐患开始数据;1.特殊审核;2.延期审核 3.验收打回。4.隐患确认记录,.5重大隐患修改6确认时打回;
before.put("STATE", "16");//是否通过审核 ,1未通过。2通过 -1初始16隐患确认打回
before.put("HIDDEN_ID", pd.get("HIDDEN_ID"));
before.put("HIDDENEXAMINE_ID", UuidUtil.get32UUID());
before.put("CREATOR", Jurisdiction.getUSER_ID());
before.put("CREATTIME", DateUtil.date2Str(new Date()));
before.put("OPERATOR", Jurisdiction.getUSER_ID());
before.put("OPERATTIME", DateUtil.date2Str(new Date()));
before.put("REPULSE_CAUSE", pd.getString("REJECTOPINION"));
before = hiddenExamineApiService.save(before);
pd.put("before",JSON.toJSONString(before));
List<PageData> hiddenUserList = hiddenUserApiService.getListByHiddenId(pd.getString("HIDDEN_ID"));
for (PageData pageData : hiddenUserList) {
messageService.sendMessageByParameter("HIDDEN_MAIL_001", "友情提示:有一条隐患被打回",
Jurisdiction.getCORPINFO_ID(), pageData.getString("USER_ID"), pd.getString("HIDDEN_ID"),
pd.getString("HIDDENDESCR"), "上报", "查看", "", "");
}
map.put("dockData",JSON.toJSONString(pd));
return ResultCodeConstant.resMap(code, map);
}
/**
* 隐患整改
*
* @return
* @throws Exception
*/
@RequestMapping(value = "/rectify")
@RequiresPermissions("hidden:list")
@ResponseBody
@DockAnnotation(isAdd = true)
public Object rectify() throws Exception {
/**
* 修改隐患信息
* 删除隐患应急方案
* 删除隐患整改方案
* 保持整改方案
* 给验收人发送站内信
* 多个验收人
*/
Map<String, Object> map = new HashMap<String, Object>();
Integer code = 000000;
PageData pd = new PageData();
pd = this.getPageData();
// 清理隐患整改 表 bus_hiddencheck
// 清理隐患整改 表 bus_hiddenscheme
/** 必填项隐患id ,是否正常整改**/
String serl = "HIDDEN_ID,IS_NORMAL";
if ("1".equals(pd.getString("IS_NORMAL"))) {
/** 必填项隐患id 整改描述 整改时间,整改方案状态 ,投入资金 ,验收人部门 ,验收人,其他验收人 **/
serl += ",RECTIFYDESCR,INVESTMENT_FUNDS,RECTIFICATIONTIME,CHECKDEPT,CHECKOR,OTHER";
hiddenSchemeService.deleteHd(pd);
hiddenCheckService.delete(pd);
} else { ////如果是不是正常整改
return ResultCodeConstant.resMap(000216);
// return this.unableRectify();
}
code = HasAllRequired.hasAllRequired(pd, serl);
if (code != 000000) {
return ResultCodeConstant.resMap(code);
}
PageData hidden = hiddenApiService.findById(pd); //获取隐患信息
/** 整改,修改隐患信息 **/
int hiddenupdateSate = hiddenApiService.rectify(pd.getString("HIDDEN_ID"), pd.getString("RECTIFYDESCR"),
pd.getString("RECTIFICATIONTIME"), pd.getString("HAVESCHEME"), pd.getString("INVESTMENT_FUNDS"));
map.put("hiddenupdateSate", hiddenupdateSate);
if ("1".equals(pd.getString("HAVESCHEME"))) { //如果有整改方案 添加上整改方案
pd.put("HIDDENSCHEME_ID", this.get32UUID());
pd.put("CREATOR", Jurisdiction.getUSER_ID());
pd.put("CREATTIME", DateUtil.date2Str(new Date()));
pd.put("OPERATOR", Jurisdiction.getUSER_ID());
pd.put("OPERATTIME", DateUtil.date2Str(new Date()));
pd.put("ISDELETE", "0"); // 是否删除 1 删除 0未删除
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
int hiddenSchemeState = hiddenSchemeApiService.save(pd);
map.put("hiddenSchemeState", hiddenSchemeState);
}
/** 隐患验收信息 **/
PageData hiddenCheck = hiddenCheckApiService.saveHiddenCheck(pd.getString("CHECKOR"), pd.getString("CHECKDEPT"), pd.getString("OTHER"), pd.getString("HIDDEN_ID"), hidden.getString("HIDDENDESCR"));
pd.put("hiddenCheck",JSON.toJSONString(hiddenCheck));
/** 隐患延时申请的要通过 **/
PageData exam = hiddenExamineApiService.saveRectify(pd.getString("HIDDEN_ID")); //添加隐患整改记录
pd.put("exam", JSON.toJSONString(exam));
List<PageData> hiddenUserList = hiddenUserApiService.getListByHiddenId(pd.getString("HIDDEN_ID"));
for (PageData pageData : hiddenUserList) {
if ("2".equals(pageData.getString("TYPE")) && "-1".equals(pageData.getString("STATE"))) { //延期审核 没有审批的
hiddenExamineApiService.adoptExamine(pageData.getString("HIDDENEXAMINE_ID"), "整改完成");
}
}
map.put("hiddenCheckState", hiddenCheck.get("retint"));
map.put("dockData",JSON.toJSONString(pd));
return ResultCodeConstant.resMap(code, map);
}
/**
* 隐患整改 --无法整改
*
* @return
* @throws Exception
*/
@RequestMapping(value = "/unableRectify")
@RequiresPermissions("hidden:list")
@ResponseBody
@DockAnnotation(isAdd = true)
public Object
unableRectify() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Integer code = 000000;
PageData pd = new PageData();
pd = this.getPageData();
/** 隐患ID ,无法整改原因 **/
String serl = "HIDDEN_ID,disposalPlan";
code = HasAllRequired.hasAllRequired(pd, serl);
if (code != 000000) {
return ResultCodeConstant.resMap(code);
}
// 无法整改得 隐患一会删除填写得正常得信息
hiddenSchemeService.deleteHd(pd);
hiddenCheckService.delete(pd);
// hiddenExamineService.deleteByHiddenId(pd); //如果验收打回删除隐患相关信息
// 删除
PageData hidden = hiddenApiService.findById(pd);
hiddenApiService.unableRectify(pd.getString("HIDDEN_ID")); //修改隐患状态,变成 待处理特殊隐患
PageData examine = new PageData();
examine.put("TYPE", "1");
examine.put("STATE", "-1");
examine.put("EXAMINE", pd.getString("disposalPlan")); //临时措施
examine.put("HIDDEN_ID", pd.getString("HIDDEN_ID"));
examine.put("HIDDENEXAMINE_ID", UuidUtil.get32UUID());
examine.put("CREATOR", Jurisdiction.getUSER_ID());
examine.put("CREATTIME", DateUtil.date2Str(new Date()));
examine.put("OPERATOR", Jurisdiction.getUSER_ID());
examine.put("OPERATTIME", DateUtil.date2Str(new Date()));
examine = hiddenExamineApiService.save(examine);
pd.put("examine",JSON.toJSONString(examine));
messageService.sendMessageByParameter("HIDDEN_MAIL_005", "友情提示:有一条隐患需要特殊审核",
hidden.getString("CORPINFO_ID"), hidden.getString("CONFIRM_USER"), hidden.getString("HIDDEN_ID"),
hidden.getString("HIDDENDESCR"), "特殊处置审核", "审核", "", "");
map.put("msg", "隐患特殊处理申请成功。请通知隐患确认人进行特殊处理确认操作!");
/** 暂时没有整理 **/
if (Tools.notEmpty(hidden.getString("INSPECTION_ID"))) { //安全环保检查验收
pd.put("ACCEPTSTEP", 6);
List<PageData> list = hiddenService.listOtherNotAccept(pd); //获取没有验收的隐患
PageData inspection = new PageData();
if (list.size() == 0) {
inspection.put("INSPECTION_ID", pd.getString("INSPECTION_ID"));
inspection.put("OPERATOR", Jurisdiction.getUSER_ID());
inspection.put("OPERATTIME", DateUtil.date2Str(new Date()));
inspection.put("INSPECTION_STATUS", "6"); // 已验收
safetyenvironmentalService.editStatus(inspection);
inspection.put("HIDDEN_vector", pd.getString("HIDDEN_ID"));
}
inspection.put("INSPECTION_ID", pd.getString("INSPECTION_ID"));
inspection.put("OPERATOR", Jurisdiction.getUSER_ID());
inspection.put("HIDDEN_vector", pd.getString("HIDDEN_ID"));
noticeUtil.SE_ThreeStepUtil(inspection);
}
map.put("dockData",JSON.toJSONString(pd));
return ResultCodeConstant.resMap(code, map);
}
/**
* 延时申请
*
* @param
* @throws Exception
*/
@RequestMapping(value = "/delayed")
@RequiresPermissions("hidden:list")
@ResponseBody
@DockAnnotation(isAdd = true)
public Object delayed() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
Integer code = 000000;
/** 延期时间 , 处置方案**/
String serl = "HIDDEN_ID,DELAY_TIME,disposalPlan";
code = HasAllRequired.hasAllRequired(pd, serl);
if (code != 000000) {
return ResultCodeConstant.resMap(code);
}
PageData examine = new PageData();
examine.put("TYPE", "2");
examine.put("STATE", "-1");
examine.put("CREATTIME", DateUtil.date2Str(new Date()));
examine.put("EXAMINE", pd.getString("TEMPORARY_MEASURES")); //临时措施
examine.put("DISPOSAL_PLAN", pd.getString("disposalPlan")); //临时措施
examine.put("DELAY_TIME", pd.getString("DELAY_TIME")); //申请延期日期
examine.put("HIDDEN_ID", pd.getString("HIDDEN_ID"));
PageData hidden = hiddenApiService.findById(pd);
MultipartFile file = null;
if (file != null) {
String suffixName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase();
if (!"pdf".equals(suffixName) && !"jpg".equals(suffixName) && !"jpeg".equals(suffixName) && !"png".equals(suffixName) && !"mp4".equals(suffixName)) {
errInfo = "fail";
map.put("result", errInfo);
map.put("msg", "文件格式不正确!");
return map;
}
String ffile = DateUtil.getDays();
String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
Smb.sshSftp(file, fileName, Const.FILEPATHYHTP + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
examine.put("DISPOSAL_FILE", Const.FILEPATHYHTP + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
}
examine = hiddenExamineApiService.save(examine);
pd.put("examine",JSON.toJSONString(examine));
messageService.sendMessageByParameter("HIDDEN_MAIL_007", "友情提示:有一条隐患需要延期审核",
hidden.getString("CORPINFO_ID"), pd.getString("USER_ID"), hidden.getString("HIDDEN_ID"),
hidden.getString("HIDDENDESCR"), "延期审核", "审核", "", "");
map.put("msg", "隐患延期申成功。请通知隐患确认人进行延期确认操作!");
map.put("dockData",JSON.toJSONString(pd));
return ResultCodeConstant.resMap(code, map);
}
/**
* 验收隐患
*
* @param
* @throws Exception
*/
@RequestMapping(value = "/check")
@ResponseBody
@DockAnnotation(isAdd = true)
public Object check() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Integer code = 000000;
PageData pd = new PageData();
pd = this.getPageData();
/** 必填项隐患id ,是否合格 1合格2不合格,验收描述 ,验收时间 **/
String serl = "HIDDEN_ID,ISQUALIFIED";
if ("1".equals(pd.getString("ISQUALIFIED"))) {
serl += ",CHECKDESCR,CHECK_TIME";
} else {
serl += ",CONTENT";
}
code = HasAllRequired.hasAllRequired(pd, serl);
if (code != 000000) {
return ResultCodeConstant.resMap(code);
}
/*** 主表中验收人没用了*/
PageData hidden = hiddenApiService.findById(pd);
PageData check = new PageData();
if ("1".equals(pd.getString("ISQUALIFIED"))) { //验收合格
/** 获取所有的验收信息 ,隐患验收人是否全部验收 **/
int checkCount = 0;//已经验收的人数
List<PageData> hiddenCheckList = hiddenCheckApiService.findByHidden(pd.getString("HIDDEN_ID"));//这条隐患的全部验收人
if (hiddenCheckList.size() == 0) {
return ResultCodeConstant.resMap(000220, map);
}
Map<String, String> hiddenCheckMap = new HashMap<>();
int count = 1;
for (PageData pageData : hiddenCheckList) {
if ("1".equals(pageData.getString("STATUS"))) {
checkCount++; //以前验收的++
}
if (Jurisdiction.getUSER_ID().equals(pageData.getString("USER_ID"))) {
check = pageData;
PageData exampd = hiddenCheckApiService.checkHidden(pd.getString("HIDDEN_ID"), pageData.getString("HIDDENCHECK_ID"), pd.getString("CHECKDESCR"), pd.getString("CHECK_TIME"), Jurisdiction.getDEPARTMENT_ID(), Jurisdiction.getUSER_ID());
hiddenCheckMap.put("exampd"+count, JSON.toJSONString(exampd));
count++;
checkCount++; //本次的++
}
}
pd.put("hiddenCheckMap", JSON.toJSONString(hiddenCheckMap));
if (hiddenCheckList.size() != 0) {
if (checkCount != hiddenCheckList.size()) { //还有没有验收的人
return ResultCodeConstant.resMap(000203, map);
}
}
hiddenApiService.check(pd.getString("HIDDEN_ID"), pd.getString("CHECK_TIME")); //验收隐患
//给隐患整改人发送信息
applicationContext.publishEvent(new DeviceHiddenEvent(new Object(), pd.getString("HIDDEN_ID"), "0"));//消防检查的通知
/** 暂时没有整理 **/
if (Tools.notEmpty(pd.getString("INSPECTION_ID"))) { //安全环保检查验收
pd.put("ACCEPTSTEP", 6);
List<PageData> list = hiddenService.listOtherNotAccept(pd);
PageData inspection = new PageData();
if (list.size() == 0) {
inspection.put("INSPECTION_ID", pd.getString("INSPECTION_ID"));
inspection.put("OPERATOR", Jurisdiction.getUSER_ID());
inspection.put("OPERATTIME", DateUtil.date2Str(new Date()));
inspection.put("INSPECTION_STATUS", "6"); // 已验收
safetyenvironmentalService.editStatus(inspection);
inspection.put("HIDDEN_vector", pd.getString("HIDDEN_ID"));
}
inspection.put("INSPECTION_ID", pd.getString("INSPECTION_ID"));
inspection.put("OPERATOR", Jurisdiction.getUSER_ID());
inspection.put("HIDDEN_vector", pd.getString("HIDDEN_ID"));
noticeUtil.SE_ThreeStepUtil(inspection);
}
} else { //验收不合格 删除隐患。需要删除所有验收信息
/** 删除验收图片 **/
PageData hiddenCheck = new PageData();
hiddenCheck.put("FOREIGN_KEY", pd.get("HIDDEN_ID"));
hiddenCheck.put("TYPE", "4");
List<PageData> checkImgList = imgFilesService.listAll(hiddenCheck);
for (PageData pageData : checkImgList) {
imgFilesService.delete(pageData);
if (Tools.notEmpty(pageData.getString("FILEPATH"))) {
Smb.deleteFile(pageData.getString("FILEPATH"));
}
}
/** 删除所有验收人数据。**/
hiddenCheckApiService.deleteByHiddenId(pd.getString("HIDDEN_ID"));
/** 验收打回 **/
hiddenApiService.repulseCheck(pd.getString("HIDDEN_ID"));
/** 记录打回 **/
PageData exam = hiddenExamineApiService.saveRepulseCheck(pd.getString("HIDDEN_ID"), pd.getString("CONTENT"));
pd.put("exam",JSON.toJSONString(exam));
/** 给隐患整改人发送站内信**/
messageService.sendMessageByParameter("HIDDEN_MAIL_002", "友情提示:有一条隐患被打回",
hidden.getString("CORPINFO_ID"), pd.getString("USER_ID"), hidden.getString("HIDDEN_ID"),
hidden.getString("HIDDENDESCR"), "整改", "重新整改", "", "");
}
map.put("check", check);
map.put("dockData",JSON.toJSONString(pd));
return ResultCodeConstant.resMap(code, map);
}
/**
* 过去隐患列表
*
* @param page
* @return
* @throws Exception
*/
@RequestMapping(value = "/getList")
@RequiresPermissions("hidden:list")
@ResponseBody
public Object getList(Page page) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
if (!Jurisdiction.getIS_MAIN().equals("1")) { //主账号
pd.put("queryUserId", Jurisdiction.getUSER_ID());
}
if ("confirm".equals(pd.getString("hiddenVueType"))) { // 确认隐患
if (!"1".equals(Jurisdiction.getIS_MAIN())) {
pd.put("CONFIRM_USER", Jurisdiction.getUSER_ID());
}
}
if ("rectify".equals(pd.getString("hiddenVueType"))) { // 整改隐患
if (!"1".equals(Jurisdiction.getIS_MAIN())) {
pd.put("SELFUSERID", Jurisdiction.getUSER_ID());
}
}
if ("check".equals(pd.getString("hiddenVueType"))) { // 验收隐患 只显示我验收的隐患
pd.put("checkUser", Jurisdiction.getUSER_ID());
}
if ("list".equals(pd.getString("hiddenVueType"))) { // 整改隐患
pd = Jurisdiction.getUserDataJurisdiction(pd);
}
/*上方的条件选择都是 condform */
/**
* 1。权限管理就是可以查看关于我的隐患
* 隐患发现人,隐患确认人,隐患整改人,隐患验收人
* bus_hidden_user 隐患发现人 ; bus_hidden CONFIRM_USER 隐患确认人 ;bus_hidden RECTIFICATIONOR 隐患整改人; bus_hiddencheck 隐患验收人
*/
page.setPd(pd);
List<PageData> varList = hiddenApiService.getList(page); // 列出Hidden列表
/** 隐患发现人,隐患验收人 验收时间**/
String[] hiddenIds = new String[varList.size()];
for (int i = 0; i < varList.size(); i++) {
hiddenIds[i] = varList.get(i).getString("HIDDEN_ID");
}
List<PageData> hiddenUserList = new ArrayList<>(); // 隐患发现人
List<PageData> hiddenCheckUserList = new ArrayList<>(); // 隐患验收人
if (varList.size() != 0) {
hiddenUserList = hiddenUserApiService.getListByHiddenIds(hiddenIds); // 隐患发现人
hiddenCheckUserList = hiddenCheckApiService.getListByHiddenIds(hiddenIds); // 隐患验收人
}
Map<String, String> hiddenUserMap = new HashMap<>(); // key hiddenId val:隐患发现人名字
Map<String, String> hiddenCheckUserMap = new HashMap<>(); // key hiddenId val:隐患验收人
for (PageData pageData : hiddenUserList) {
String valName = "";
if (hiddenUserMap.containsKey(pageData.getString("HIDDEN_ID"))) {
valName = hiddenUserMap.get(pageData.getString("HIDDEN_ID"));
}
valName += pageData.getString("NAME") + ",";
hiddenUserMap.put(pageData.getString("HIDDEN_ID"), valName);
}
for (PageData pageData : hiddenCheckUserList) {
String valName = "";
if (hiddenCheckUserMap.containsKey(pageData.getString("HIDDEN_ID"))) {
valName = hiddenCheckUserMap.get(pageData.getString("HIDDEN_ID"));
}
valName += pageData.getString("NAME") + ",";
hiddenCheckUserMap.put(pageData.getString("HIDDEN_ID"), valName);
}
for (PageData pageData : varList) {
String hiddenId = pageData.getString("HIDDEN_ID");
if (hiddenUserMap.containsKey(hiddenId)) {
String names = hiddenUserMap.get(hiddenId);
pageData.put("userNames", names.substring(0, (names.length() - 1)));
}
if (hiddenCheckUserMap.containsKey(hiddenId)) {
String names = hiddenCheckUserMap.get(hiddenId);
pageData.put("checkNames", names.substring(0, (names.length() - 1)));
}
}
map.put("varList", varList);
map.put("page", page);
map.put("result", errInfo);
return map;
}
/**
* 导出到excel
*
* @param
* @throws Exception
*/
@RequestMapping(value = "/excel")
// // @RequiresPermissions("toExcel")
public ModelAndView exportExcel() throws Exception {
ModelAndView mv = new ModelAndView();
PageData pd = new PageData();
pd = this.getPageData();
String dicParentId = "5e7cf8620ba54ad89719d0be62133c7a";
List<Dictionaries> dicList = dictionariesService.listSubDictByParentId(dicParentId);// 字典
Map<String, String> dicMap = new HashMap<>();
for (Dictionaries pageData : dicList) {
dicMap.put(pageData.getBIANMA(), pageData.getNAME());
}
// 隐患类型
String typeParentId = "3babc15144444bdc8d763d0af2bdfff6";
List<Dictionaries> typeList = dictionariesService.listSubDictByParentId(typeParentId);// 字典
Map<String, String> typeMap = new HashMap<>();
for (Dictionaries pageData : typeList) {
typeMap.put(pageData.getBIANMA(), pageData.getNAME());
}
// 隐患类型
String levelParentId = "5e7cf8620ba54ad89719d0be62133c7a";
List<Dictionaries> levelList = dictionariesService.listSubDictByParentId(levelParentId);// 字典
Map<String, String> levelMap = new HashMap<>();
for (Dictionaries pageData : levelList) {
levelMap.put(pageData.getBIANMA(), pageData.getNAME());
List<Dictionaries> levelList1 = dictionariesService.listSubDictByParentId(pageData.getDICTIONARIES_ID());
for (Dictionaries pageData1 : levelList1) {
levelMap.put(pageData1.getBIANMA(), pageData1.getNAME());
}
}
PageData corpIdPd = new PageData();
corpIdPd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());// CORPINFO_ID
Map<String, String> userMap = new HashMap<>();// 查看企业下的所有用户根据用户id匹配信息
List<PageData> userList = usersService.listAllUser(corpIdPd);
for (PageData pageData : userList) {
userMap.put(pageData.getString("USER_ID"), pageData.getString("NAME"));
}
Map<String, String> deparMap = new HashMap<>();
List<PageData> deparList = departmentService.listAll(corpIdPd);// 查看企业下的所有部门根据部门id匹配信息
for (PageData pageData : deparList) {
deparMap.put(pageData.getString("DEPARTMENT_ID"), pageData.getString("NAME"));
}
Map<String, String> sourceMap = new HashMap<>();
sourceMap.put("1", "隐患快报");
sourceMap.put("2", "隐患排查");
sourceMap.put("3", "隐患排查");
sourceMap.put("4", "安全环保检查(监管端)");
sourceMap.put("5", "安全环保检查(企业端)");
Map<String, String> stateMap = new HashMap<>();
stateMap.put("-2", "待确认");
stateMap.put("-1", "已过期");
stateMap.put("0", "未提交");
stateMap.put("1", "未整改");
stateMap.put("2", "已整改");
stateMap.put("3", "已复查");
stateMap.put("4", "已验收");
stateMap.put("5", "忽略隐患");
stateMap.put("6", "重大隐患");
stateMap.put("7", "待处理的特殊隐患");
stateMap.put("8", "已处理的特殊隐患");
stateMap.put("10", "验收打回");
Map<String, String> rectifType = new HashMap<>();
rectifType.put("1", "立即整改");
rectifType.put("2", "限期整改");
Map<String, Object> haveschemeMap = new HashMap<>();
haveschemeMap.put("0", "无");
haveschemeMap.put("1", "有");
Map<String, Object> ysStatusMap = new HashMap<>();
ysStatusMap.put("0", "否");
ysStatusMap.put("1", "是");
Map<String, Object> dataMap = new HashMap<String, Object>();// 传给导出页面的数据
List<String> imgKeyId = new ArrayList<>();// 需要查询图片的id标识信息
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 企业id
String KEYWORDS = pd.getString("KEYWORDS"); // 关键词检索条件
if (Tools.notEmpty(KEYWORDS))
pd.put("KEYWORDS", KEYWORDS.trim());
String ISQUALIFIED = pd.getString("ISQUALIFIED"); // 关键词检索条件
if (Tools.notEmpty(ISQUALIFIED))
pd.put("ISQUALIFIED", ISQUALIFIED.trim());
String HIDDENLEVELE = pd.getString("HIDDENLEVELE"); // 关键词检索条件
if (Tools.notEmpty(HIDDENLEVELE))
pd.put("HIDDENLEVELE", HIDDENLEVELE.trim());
String STARTTIME = pd.getString("STARTTIME"); // 关键词检索条件
if (Tools.notEmpty(STARTTIME))
pd.put("STARTTIME", STARTTIME.trim());
String STATE = pd.getString("STATE"); // 关键词检索条件
if (Tools.notEmpty(STATE))
pd.put("STATE", STATE.trim());
String ENDTIME = pd.getString("ENDTIME"); // 关键词检索条件
if (Tools.notEmpty(ENDTIME))
pd.put("ENDTIME", ENDTIME + " 23:59:59");
String DISPOSESTATE = pd.getString("DISPOSESTATE"); // 关键词检索条件
if (Tools.notEmpty(DISPOSESTATE)) {
pd.put("DISPOSESTATE", DISPOSESTATE.trim());
pd.put("SELFUSERID", Jurisdiction.getUSER_ID());
pd.put("USERDEPT", Jurisdiction.getDEPARTMENT_ID());
}
String IS_SELF = pd.getString("IS_SELF"); // 关键词检索条件
if (IS_SELF != null && IS_SELF.equals("1"))
pd.put("SELF_USER_ID", Jurisdiction.getUSER_ID());
// 查看隐患信息
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
if (!Jurisdiction.getIS_MAIN().equals("1")) { //主账号
pd.put("queryUserId", Jurisdiction.getUSER_ID());
}
List<PageData> varOList = hiddenService.listAll(pd); //导出查询修改不查0、5、7、8、100、101、102 较大、忽略、重大隐患
varOList = hiddenUserService.getHiddebFind(varOList);
for (PageData pageData : varOList) {
imgKeyId.add(pageData.getString("HIDDEN_ID"));
}
// 查询整改方案
List<PageData> schemeList = hiddenSchemeService.listAll(corpIdPd);
Map<String, PageData> schemeMap = new HashMap<>();
for (PageData pageData : schemeList) {
schemeMap.put(pageData.getString("HIDDEN_ID"), pageData);
// imgKeyId.add(pageData.getString("HIDDEN_ID"));
imgKeyId.add(pageData.getString("HIDDENSCHEME_ID"));
}
// 验收信息
List<PageData> checkList = hiddenCheckService.listAll(corpIdPd);
Map<String, List<PageData>> checkMap = new HashMap<>();
Integer checkMaxCount = 1;
for (PageData pageData : checkList) {
Integer checkCount = 1;
List<PageData> vaList = new ArrayList<>();
if (checkMap.containsKey(pageData.get("HIDDEN_ID"))) {
vaList = checkMap.get(pageData.get("HIDDEN_ID"));
checkCount = vaList.size();
if (checkMaxCount < checkCount) {
checkMaxCount = checkCount;
}
}
vaList.add(pageData);
checkMap.put(pageData.get("HIDDEN_ID").toString(), vaList);
imgKeyId.add(pageData.getString("HIDDENCHECK_ID"));
}
String[] imgId = new String[imgKeyId.size()];
for (int i = 0; i < imgKeyId.size(); i++) {
imgId[i] = imgKeyId.get(i);
}
PageData imgpd2 = new PageData();
imgpd2.put("ArrayDATA_IDS", imgId);
List<PageData> imgList = imgFilesService.listAllByIds(imgpd2);
Map<String, Integer> imgCount = new HashMap<>();
Integer imgTypeMaxCount1 = 1, imgTypeMaxCount2 = 1, imgTypeMaxCount3 = 1, imgTypeMaxCount4 = 1,
imgTypeMaxCount5 = 1, imgTypeMaxCount6 = 1, imgTypeMaxCount7 = 1, imgTypeMaxCount8 = 1;
Map<String, List<String>> imgMap = new HashMap<>();
for (int i = 0; i < imgList.size(); i++) {
if (Tools.isEmpty(imgList.get(i).get("TYPE"))) {
continue;
}
if (Tools.isEmpty(imgList.get(i).get("FOREIGN_KEY"))) {
continue;
}
List<String> list = new ArrayList<>();
String key = imgList.get(i).getString("FOREIGN_KEY") + ";" + imgList.get(i).get("TYPE");
if (imgMap.containsKey(key)) {
list = imgMap.get(key);
}
list.add(imgList.get(i).getString("FILEPATH"));
imgMap.put(key, list);
String imgType = imgList.get(i).get("TYPE").toString();
Integer count = 1;
if (imgCount.containsKey(key)) {
count = imgCount.get(key) + 1;
}
if ("1".equals(imgType)) {
if (imgTypeMaxCount1 < count) {
imgTypeMaxCount1 = count;
}
}
if ("2".equals(imgType)) {
if (imgTypeMaxCount2 < count) {
imgTypeMaxCount2 = count;
}
}
if ("3".equals(imgType)) {
if (imgTypeMaxCount3 < count) {
imgTypeMaxCount3 = count;
}
}
if ("4".equals(imgType)) {
if (imgTypeMaxCount4 < count) {
imgTypeMaxCount4 = count;
}
}
if ("5".equals(imgType)) {
if (imgTypeMaxCount5 < count) {
imgTypeMaxCount5 = count;
}
}
if ("6".equals(imgType)) {
if (imgTypeMaxCount6 < count) {
imgTypeMaxCount6 = count;
}
}
if ("7".equals(imgType)) {
if (imgTypeMaxCount7 < count) {
imgTypeMaxCount7 = count;
}
}
if ("8".equals(imgType)) {
if (imgTypeMaxCount8 < count) {
imgTypeMaxCount8 = count;
}
}
imgCount.put(key, count);
}
List<PageData> varList = new ArrayList<PageData>();
for (PageData pageData : varOList) {
int count = 0;
PageData vpd = new PageData();
String hidId = pageData.getString("HIDDEN_ID");
vpd.put("var" + (1 + count), sourceMap.get(pageData.getString("SOURCE")));
// vpd.put("var" + (2 + count), pageData.getString("RISK_UNIT"));
// vpd.put("var" + (3 + count), pageData.getString("IDENTIFICATION"));
// vpd.put("var" + (4 + count), pageData.getString("RISK_DESCR"));
// vpd.put("var" + (5 + count), pageData.getString("LEVEL"));
// vpd.put("var" + (6 + count), pageData.getString("CHECK_CONTENT"));
vpd.put("var" + (2 + count), levelMap.get(pageData.getString("HIDDENLEVEL")));
vpd.put("var" + (3 + count), pageData.getString("HIDDENTYPENAME"));
vpd.put("var" + (4 + count), stateMap.get(pageData.getString("STATE")));
vpd.put("var" + (5 + count), pageData.getString("HIDDENDESCR"));
vpd.put("var" + (6 + count), pageData.getString("HIDDENPARTNAME"));
vpd.put("var" + (7 + count), pageData.getString("POSITIONDESC"));
vpd.put("var" + (8 + count), pageData.getString("findDeptNames"));
vpd.put("var" + (9 + count), pageData.getString("findUserNames"));
vpd.put("var" + (10 + count), pageData.getString("CREATTIME"));
vpd.put("var" + (11 + count), rectifType.get(pageData.getString("RECTIFICATIONTYPE")));
vpd.put("var" + (12 + count), pageData.getString("conUserName"));//确认人
vpd.put("var" + (13 + count), pageData.getString("CONFIRM_TIME")); //确认时间
vpd.put("var" + (14 + count), pageData.getString("RECTIFICATIONDEADLINE"));
List<String> yhImg = imgMap.get(pageData.getString("HIDDEN_ID") + ";3");
for (int i = 0; i < imgTypeMaxCount3; i++) {
if (null != yhImg) {
if (i < yhImg.size()) {
vpd.put("img" + (15 + i), yhImg.get(i));
} else {
vpd.put("img" + (15 + i), "");
}
} else {
vpd.put("img" + (15 + i), "");
}
}
count += imgTypeMaxCount3;
vpd.put("var" + (15 + count), pageData.getString("RECTIFYDESCR"));// 整改描述
vpd.put("var" + (16 + count), deparMap.get(pageData.getString("RECTIFICATIONDEPT")));// 整改部门
vpd.put("var" + (16 + count), deparMap.get(pageData.getString("RECTIFICATIONDEPT")));// 整改部门
vpd.put("var" + (17 + count), userMap.get(pageData.getString("RECTIFICATIONOR")));// 整改人
vpd.put("var" + (18 + count), pageData.getString("RECTIFICATIONTIME"));// 整改时间
List<String> zgImg = imgMap.get(hidId + ";4");// 整改后图片
for (int i = 0; i < imgTypeMaxCount4; i++) {
if (null != zgImg) {
if (i < zgImg.size()) {
vpd.put("img" + (19 + count + i), zgImg.get(i));
} else {
vpd.put("img" + (19 + count + i), "");
}
} else {
vpd.put("img" + (19 + count + i), "");
}
}
count += imgTypeMaxCount4;
vpd.put("var" + (19 + count), haveschemeMap.get(pageData.getString("HAVESCHEME")));// 整改方案
if (schemeMap.containsKey(hidId)) {
// count += imgTypeMaxCount8;
if (checkMap.containsKey(hidId)) {
List<PageData> check = checkMap.get(hidId);
for (PageData pageData2 : check) {
vpd.put("var" + (20 + count), pageData2.getString("CHECKDESCR"));// 验收描述
if ("1".equals(pageData2.getString("STATUS"))) {
vpd.put("var" + (21 + count), "是");// 是否合格
} else {
vpd.put("var" + (21 + count), "否");// 是否合格
}
vpd.put("var" + (22 + count), pageData2.getString("CHECKDEPTNAME"));// 验收部门
vpd.put("var" + (23 + count), pageData2.getString("CHECKORNAME"));// 验收人
vpd.put("var" + (24 + count), pageData2.getString("CHECK_TIME"));// 验收时间
List<PageData> yanshoutupian = imgFilesService.getListByKeyAndType(pageData2.get("HIDDENCHECK_ID").toString(), "5");
// vpd.put("img" + (25 + count), pageData2.getString("CHECK_TIME"));// 验收图片
for (int i = 0; i < yanshoutupian.size(); i++) {
vpd.put("img" + (25 + count + i), yanshoutupian.get(i).get("FILEPATH"));
}
}
}
}
varList.add(vpd);
}
List<String> titles = new ArrayList<String>();
titles.add("隐患来源"); // 1
titles.add("隐患级别"); // 2
titles.add("隐患类型"); // 3
titles.add("隐患状态"); // 4 ~~~~~~~~~~~~~
titles.add("隐患描述"); // 5
titles.add("隐患部位"); // 6
titles.add("隐患位置描述"); // 7 ~~~~~~~~~~~~~
titles.add("隐患发现部门"); // 8
titles.add("发现人"); // 9
titles.add("发现时间"); // 10
titles.add("隐患处置"); // 13
titles.add("确认人"); // 11***
titles.add("确认时间"); // 12 ***
titles.add("整改期限"); // 14
for (int i = 0; i < imgTypeMaxCount3; i++) {
titles.add("隐患图片"); // 14*
}
titles.add("整改描述");
titles.add("整改部门");
titles.add("整改人");
titles.add("整改时间");
for (int i = 0; i < imgTypeMaxCount4; i++) {
titles.add("整改后图片"); // 11
}
titles.add("整改方案");
titles.add("验收描述");
titles.add("是否合格");
titles.add("验收部门");
titles.add("验收人");
titles.add("验收时间");
for (int j = 0; j < 4; j++) {
titles.add("验收图片");
}
// titles.add("排查日期");
// titles.add("隐患清单");
// titles.add("治理标准要求");
// titles.add("治理方法");
// titles.add("经费和物资的落实");
// titles.add("负责治理人员");
// titles.add("工时安排");
// titles.add("时限要求");
// titles.add("应急预案附件");
// titles.add("工作要求");
// titles.add("其他事项");
/*for (int i = 0; i < imgTypeMaxCount8; i++) {
titles.add("方案图片"); // 11
}*/
/*for (int i = 0; i < checkMaxCount; i++) {
titles.add("验收描述");
titles.add("是否合格");
titles.add("验收部门");
titles.add("验收人");
titles.add("验收时间");
*//*for (int j = 0; j < imgTypeMaxCount5; j++) {
titles.add("验收图片");
}*//*
}*/
dataMap.put("titles", titles);
dataMap.put("varList", varList);
HiddenExcelImgForServerView erv2 = new HiddenExcelImgForServerView();
mv = new ModelAndView(erv2, dataMap);
return mv;
}
@RequestMapping(value = "/getCountExcel")
public void exportExcels(HttpServletResponse response) throws Exception {
PageData pd = new PageData();
pd = this.getPageData();
//这里进入开始获取数据阶段 首先拿到所有部门数据
String url ="department_list.html?DEPARTMENT_ID=";
List<Department> departments = departmentService.listAllDepartment(Jurisdiction.getCORPINFO_ID(), url);
//装船部 zcb id集合 89f3d30c4031432da53b75bed442ced8
List<String> zcbdepartmentIds = new ArrayList<>();
//保障部 bzb id集合 fcae9cc13a354be699d85d6aea3b3450
List<String> bzbdepartmentIds = new ArrayList<>();
//卸车部 xcb id集合 aad337cf728b4cc2b63e210caf4e185f
List<String> xcbdepartmentIds = new ArrayList<>();
//安监部 ajb id集合 4c4b7bc93e3347978f5a3e1f0c4a0b56
List<String> ajbdepartmentIds = new ArrayList<>();
//开始处理数据 扔进对应结合中
for(Department department:departments){
if(StringUtils.equals("89f3d30c4031432da53b75bed442ced8",department.getDEPARTMENT_ID())){
zcbdepartmentIds = getIdsList(department,zcbdepartmentIds);
}
if(StringUtils.equals("fcae9cc13a354be699d85d6aea3b3450",department.getDEPARTMENT_ID())){
bzbdepartmentIds = getIdsList(department,bzbdepartmentIds);
}
if(StringUtils.equals("aad337cf728b4cc2b63e210caf4e185f",department.getDEPARTMENT_ID())){
xcbdepartmentIds = getIdsList(department,xcbdepartmentIds);
}
if(StringUtils.equals("4c4b7bc93e3347978f5a3e1f0c4a0b56",department.getDEPARTMENT_ID())){
ajbdepartmentIds = getIdsList(department,ajbdepartmentIds);
}
}
//处理日期 类型 年 季度 月
String type = pd.getString("type");
String year = pd.getString("year");
String num = pd.getString("num");
String startTime = "";
String endTime = "";
//年
if(StringUtils.equals("1",type)){
startTime = year+"-01-01 00:00:00";
endTime = year+"-12-31 23:59:59";
}
//季度
if(StringUtils.equals("2",type)){
switch (num){
case "1" :
startTime = year+"-01-01 00:00:00";
endTime = year+"-03-31 23:59:59";
break;
case "2" :
startTime = year+"-04-01 00:00:00";
endTime = year+"-06-30 23:59:59";
break;
case "3" :
startTime = year+"-07-01 00:00:00";
endTime = year+"-09-30 23:59:59";
break;
case "4" :
startTime = year+"-10-01 00:00:00";
endTime = year+"-12-31 23:59:59";
break;
}
}
//月
if(StringUtils.equals("3",type)){
startTime = year+"-01 00:00:00";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 解析字符串为LocalDateTime
LocalDateTime dateTime = LocalDateTime.parse(startTime, formatter);
LocalDate localDate = dateTime.toLocalDate();
LocalDate lastDayOfMonth = localDate.with(java.time.temporal.TemporalAdjusters.lastDayOfMonth());
// 将LocalDateTime转换为ZonedDateTime如果需要的话
ZonedDateTime zonedDateTime = lastDayOfMonth.atStartOfDay(ZoneId.of("Asia/Shanghai"));
// 定义日期格式化器(仅日期部分)
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// 格式化ZonedDateTime对象为仅包含日期的字符串
String formattedDate = dateFormatter.format(zonedDateTime);
endTime = formattedDate+" 23:59:59";
}
//前置搜索条件处理完毕
pd.put("zcbdepartmentIds",zcbdepartmentIds);
pd.put("bzbdepartmentIds",bzbdepartmentIds);
pd.put("xcbdepartmentIds",xcbdepartmentIds);
pd.put("ajbdepartmentIds",ajbdepartmentIds);
pd.put("startTime",startTime);
pd.put("endTime",endTime);
//这里获取数据 获取指定日期范围内和指定部门集合创建的隐患总数
Map<String,Object> map = hiddenService.getExcelMap(pd);
//年
if(StringUtils.equals("1",type)){
map.put("type","统计年度:");
map.put("num",year+"年");
}
//季度
if(StringUtils.equals("2",type)){
map.put("type","统计季度:");
map.put("num",year+"年第"+num+"季度");
}
//月
if(StringUtils.equals("3",type)){
map.put("type","统计月度:");
map.put("num",year+"年第"+num+"月");
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
String date =sdf.format(new Date());
map.put("date","填表日期:"+date);
//开始执行模板填充数据
String excelFilePath = "C:\\Users\\Administrator\\Desktop\\隐患统计.xlsx"; // 替换为你的Excel文件路径
//正则
String regex = "\\{\\{.*?\\}\\}";
Pattern pattern = Pattern.compile(regex);
try (FileInputStream inputStream = new FileInputStream(new File(excelFilePath));
Workbook workbook = new XSSFWorkbook(inputStream)) {
Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表
for (Row row : sheet) {
for (Cell cell : row) {
String fileurl = cell.getStringCellValue();
Matcher matcher = pattern.matcher(fileurl);
if (matcher.matches()) {
String key = fileurl.substring(2, fileurl.length() - 2);
String value = map.get(key).toString();
cell.setCellValue(value);
}
}
}
try (OutputStream outputStream = response.getOutputStream()) {
workbook.write(outputStream);
workbook.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Excel文件导出成功");
}
}
public List<String> getIdsList(Department department,List<String> ids){
ids.add(department.getDEPARTMENT_ID());
for(Department dept :department.getSubDepartment() ){
if(dept.getSubDepartment().size()>0){
getIdsList(dept,ids);
}else {
ids.add(dept.getDEPARTMENT_ID());
}
}
return ids;
}
}