package cn.com.goldenwater.dcproj.controller.keyreg; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import cn.com.goldenwater.dcproj.constValue.SplitValue; import cn.com.goldenwater.dcproj.dao.AttMampuInfoDao; import cn.com.goldenwater.dcproj.dao.BisInspKeyRegisterSectionDao; import cn.com.goldenwater.dcproj.dao.BisInspPblmDao; import cn.com.goldenwater.dcproj.dao.ObjKeyPblmRelDao; import cn.com.goldenwater.dcproj.dto.ObjKeyCate; import cn.com.goldenwater.dcproj.dto.ObjKeyDic; import cn.com.goldenwater.dcproj.model.*; import cn.com.goldenwater.dcproj.param.*; import cn.com.goldenwater.dcproj.service.BisInspPblmService; import cn.com.goldenwater.dcproj.service.GwComFileService; import cn.com.goldenwater.dcproj.service.ObjKeyPblmRelService; import cn.com.goldenwater.dcproj.service.ObjKeyPblmsService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * @author lune * @date 2019-4-25 */ @Api(value = "172 问题与标准库关系管理", tags = "172 问题与标准库关系管理") @RestController @RequestMapping("/obj/key/pblm") public class ObjKeyPblmRelController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private ObjKeyPblmRelService objKeyPblmRelService; @Autowired private ObjKeyPblmRelDao objKeyPblmRelDao; @Autowired private ObjKeyPblmsService objKeyPblmsService; @Autowired private BisInspPblmDao pblmDao; @Autowired private AttMampuInfoDao mampuInfoDao; @Autowired private GwComFileService gwComFileService; @Autowired private BisInspKeyRegisterSectionDao bisInspKeyRegisterSectionDao; // @Autowired // private BisInspKeysafqhRegisterUniService bisInspKeysafqhRegisterUniService; @ApiOperation(value = "根据ID获取172 问题与标准库关系管理") @RequestMapping(value = "/list", method = RequestMethod.POST) public BaseResponse> list(@RequestBody ObjKeyPblmRelParam pblmRelParam) { ObjParam objParam = new ObjParam(); objParam.setProType(pblmRelParam.getProType()); pblmRelParam.setProType(getProType(objParam)); List keyPblmRels = objKeyPblmRelService.findList(pblmRelParam); return buildSuccessResponse(keyPblmRels); } @ApiOperation(value = "根据ID获取172 问题标准库管理(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { ObjKeyPblms objKeyPblms = objKeyPblmsService.get(id); return buildSuccessResponse(objKeyPblms); } @Autowired private BisInspPblmService bisInspPblmService; @ApiOperation(value = "根据问题id获取172问题详情,type=1为水利工程建设,2为水利工程运行") @RequestMapping(value = "/getPblm/{pblmId}/{type}", method = RequestMethod.GET) public BaseResponse getPblm(@ApiParam(name = "pblmId", value = "pblmId", required = true) @PathVariable String pblmId, @ApiParam(name = "type", value = "type", required = true) @PathVariable String type) { String pType = "7"; if ("1".equals(type)) { pType = "4"; } KeyRegPblm objKeyPblms = pblmDao.getOnePblm(pblmId, pType); objKeyPblms = bisInspPblmService.convertRegPblm(objKeyPblms); List comFiles = gwComFileService.findFileByBiz(objKeyPblms.getPblmId()); objKeyPblms.setGwComFiles(comFiles); ObjParam objParam = new ObjParam(); objParam.setProType(type); objKeyPblms.setProjectName(getProType(objParam)); //水利工程运行需要获取几级单位 switch (type) { case "2": String regId = objKeyPblms.getRegid(); AttMampuInfo attMampuInfo = mampuInfoDao.get(regId); if (attMampuInfo != null) { String thirdName = ""; String secondName = ""; String firstName = ""; if ("3".equals(attMampuInfo.getLev())) { thirdName = attMampuInfo.getNm(); objKeyPblms.setLocalDepartType("三级管理单位"); attMampuInfo = mampuInfoDao.get(attMampuInfo.getPid()); if (attMampuInfo != null) { secondName = attMampuInfo.getNm(); attMampuInfo = mampuInfoDao.get(attMampuInfo.getPid()); if (attMampuInfo != null) { firstName = attMampuInfo.getNm(); } } } else if ("2".equals(attMampuInfo.getLev())) { secondName = attMampuInfo.getNm(); objKeyPblms.setLocalDepartType("二级管理单位"); attMampuInfo = mampuInfoDao.get(attMampuInfo.getPid()); if (attMampuInfo != null) { firstName = attMampuInfo.getNm(); } } else if ("1".equals(attMampuInfo.getLev())) { firstName = attMampuInfo.getNm(); objKeyPblms.setLocalDepartType("一级管理单位"); } objKeyPblms.setFirstName(firstName); objKeyPblms.setSecondName(secondName); objKeyPblms.setThirdName(thirdName); } break; // case "99": // BisInspKeyRegisterSection keyRegisterSection = bisInspKeyRegisterSectionDao.findSecByUnitId(objKeyPblms.getRegid()); // if (keyRegisterSection != null) { // objKeyPblms.setSecName(keyRegisterSection.getNm()); // } // break; // case "100": // BisInspKeyRegisterSection keyRegisterSection = bisInspKeyRegisterSectionDao.findSecByUnitId(objKeyPblms.getRegid()); // if (keyRegisterSection != null) { // objKeyPblms.setSecName(keyRegisterSection.getNm()); // } // break; default: BisInspKeyRegisterSection keyRegisterSection = bisInspKeyRegisterSectionDao.findSecByUnitId(objKeyPblms.getRegid()); if (keyRegisterSection != null) { objKeyPblms.setSecName(keyRegisterSection.getNm()); } } return buildSuccessResponse(objKeyPblms); } @ApiOperation(value = "获取172问题类型分组") @RequestMapping(value = "/convertGroup", method = RequestMethod.POST) public BaseResponse> convertGroup(@RequestBody ObjKeyPblmRelParam pblmRelParam) { ObjParam objParam = new ObjParam(); objParam.setProType(pblmRelParam.getProType()); pblmRelParam.setPtype(pblmRelParam.getProType()); pblmRelParam.setProType(getProType(objParam)); List keyPblmRels = objKeyPblmRelService.convertGroup(pblmRelParam); for (ObjKeyPblmRel keyPblmRel : keyPblmRels) { pblmRelParam.setPblmPoint(keyPblmRel.getPblmPoint()); List keyPblmRelsBak = objKeyPblmRelService.findList(pblmRelParam); List relDicList = new ArrayList<>(); for (ObjKeyPblmRel keyPblmRel1 : keyPblmRelsBak) { PblmRelDic relDic = new PblmRelDic(); relDic.setPblmSn(keyPblmRel1.getPblmSn()); relDic.setPblmAttachName(keyPblmRel1.getPblmAttachName()); relDic.setPblmAttach(keyPblmRel1.getPblmAttach()); relDicList.add(relDic); } keyPblmRel.setPblmRelDics(relDicList); } if ("违规行为".equals(pblmRelParam.getPblmType())) { Collections.reverse(keyPblmRels); } return buildSuccessResponse(keyPblmRels); } @ApiOperation(value = "根据工程类型和单位性质查找对应的问题类别,如合同问题,违规行为等") @RequestMapping(value = "/listPblmType", method = RequestMethod.POST) public BaseResponse> listPblmType(@RequestBody KeyRegParam keyRegPatam) { ObjParam objParam = new ObjParam(); objParam.setProType(keyRegPatam.getProType()); keyRegPatam.setPtype(keyRegPatam.getProType()); keyRegPatam.setProType(getProType(objParam)); List keyPblmRels = objKeyPblmRelDao.findPblmType(keyRegPatam); return buildSuccessResponse(keyPblmRels); } @ApiOperation(value = "根据工程类型和单位性质查找对应的问题类别,如合同问题,违规行为等,包含子类问题分组") @RequestMapping(value = "/listPblmContainGroup", method = RequestMethod.POST) public BaseResponse> listPblmContainGroup(@RequestBody KeyRegParam keyRegPatam) { ObjParam objParam = new ObjParam(); objParam.setProType(keyRegPatam.getProType()); keyRegPatam.setProType(getProType(objParam)); List keyPblmRels = objKeyPblmRelDao.findPblmType(keyRegPatam); List kegPlbmGroups = new ArrayList(); for (ObjKeyPblmRel pblmRel : keyPblmRels) { KegPlbmGroup kegPlbmGroup = new KegPlbmGroup(); ObjKeyPblmRelParam pblmRelParam = new ObjKeyPblmRelParam(); pblmRelParam.setProType(keyRegPatam.getProType()); pblmRelParam.setOrgType(keyRegPatam.getOrgType()); pblmRelParam.setPblmType(pblmRel.getPblmType()); List keyPblmRelsss = objKeyPblmRelService.convertGroup(pblmRelParam); kegPlbmGroup.setKeyPblmRels(keyPblmRelsss); kegPlbmGroup.setPblmType(pblmRel.getPblmType()); kegPlbmGroups.add(kegPlbmGroup); } return buildSuccessResponse(kegPlbmGroups); } @ApiOperation(value = "根据项目类型获取172单位性质,1水利工程建设,2水利工程运行") @RequestMapping(value = "/listProType", method = RequestMethod.POST) public BaseResponse> listProType(@RequestBody ObjParam objParam) { List keyPblmRels = objKeyPblmRelDao.findProType(getProType(objParam)); return buildSuccessResponse(keyPblmRels); } private String getProType(ObjParam objParam) { String proType = "水利工程建设"; if (objParam != null) { if ("2".equals(objParam.getProType())) { proType = "水利工程运行"; } } return proType; } @ApiOperation("172工程问题清单,根据工程附件范围和问题序号范围查找相关问题,改接口必须通过上下文传参") @RequestMapping(value = "/pblmsList", method = RequestMethod.POST) public BaseResponse pblmsList(@RequestBody KeyPblmParams keyPblmParams) { List keyPblmsListAll = new ArrayList<>(); if (StringUtils.isNotBlank(keyPblmParams.getProType())) { ObjParam objParam = new ObjParam(); objParam.setProType(keyPblmParams.getProType()); keyPblmParams.setAttachType(getProType(objParam)); } List keyDicList = new ArrayList<>(); String attach = keyPblmParams.getAttach(); if (attach.contains(SplitValue.DOUHAO_SPLIT)) { String[] arrays = attach.split(SplitValue.DOUHAO_SPLIT); String[] snes = keyPblmParams.getSn().split(SplitValue.DOUHAO_SPLIT); for (int i = 0; i < arrays.length; i++) { keyPblmsListAll.addAll(findObjKeys(arrays[i], snes[i], keyPblmParams)); } } else { keyPblmsListAll.addAll(findObjKeys(attach, keyPblmParams.getSn(), keyPblmParams)); } keyDicList = convertTree(keyPblmsListAll, ""); if (!"v3".equals(keyPblmParams.getVersion())) { return buildSuccessResponse(keyDicList); } if ("工程缺陷".equals(keyPblmParams.getPblmType())) { return buildSuccessResponse(changeQueXian(keyPblmsListAll, keyDicList)); } List keyDicClassList = new ArrayList<>(); ObjKeyDicClass keyDicClass = new ObjKeyDicClass(); keyDicClass.setClassName(""); keyDicClass.setKeyDicList(keyDicList); keyDicClassList.add(keyDicClass); return buildSuccessResponse(keyDicClassList); } @ApiOperation("172工程问题清单,根据工程附件范围和问题序号范围查找相关问题,改接口必须通过上下文传参") @RequestMapping(value = "/v2/pblmsList", method = RequestMethod.POST) public BaseResponse pblmsList_v2(@RequestBody KeyPblmParams keyPblmParams) { List keyPblmsListAll = new ArrayList<>(); if (StringUtils.isNotBlank(keyPblmParams.getProType())) { ObjParam objParam = new ObjParam(); objParam.setProType(keyPblmParams.getProType()); keyPblmParams.setAttachType(getProType(objParam)); } List keyDicList = new ArrayList<>(); String attach = keyPblmParams.getAttach(); if (attach.contains(SplitValue.DOUHAO_SPLIT)) { String[] arrays = attach.split(SplitValue.DOUHAO_SPLIT); String[] snes = keyPblmParams.getSn().split(SplitValue.DOUHAO_SPLIT); for (int i = 0; i < arrays.length; i++) { keyPblmsListAll.addAll(findObjKeys(arrays[i], snes[i], keyPblmParams)); } } else { keyPblmsListAll.addAll(findObjKeys(attach, keyPblmParams.getSn(), keyPblmParams)); } keyDicList = convertTree(keyPblmsListAll, "v2"); if (!"v3".equals(keyPblmParams.getVersion())) { return buildSuccessResponse(keyDicList); } if ("工程缺陷".equals(keyPblmParams.getPblmType())) { return buildSuccessResponse(changeQueXian(keyPblmsListAll, keyDicList)); } List keyDicClassList = new ArrayList<>(); ObjKeyDicClass keyDicClass = new ObjKeyDicClass(); keyDicClass.setClassName(""); keyDicClass.setKeyDicList(keyDicList); keyDicClassList.add(keyDicClass); return buildSuccessResponse(keyDicList); } private List changeQueXian(List keyPblmsListAll, List keyDicList) { List quexianList = new ArrayList(); for (int i = 0; i < keyPblmsListAll.size(); i++) { ObjKeyPblms keyPblms = keyPblmsListAll.get(i); ObjKeyDicClass keyDic_quexian = new ObjKeyDicClass(); keyDic_quexian.setClassName(keyPblms.getClassName()); if (StringUtils.isNotBlank(keyPblms.getClassName()) && !quexianList.contains(keyDic_quexian)) { quexianList.add(keyDic_quexian); } } for (ObjKeyDicClass keyDicClass : quexianList) { List objKeyDicList = new ArrayList<>(); for (ObjKeyDic keyDic : keyDicList) { if (keyDicClass.getClassName().equals(keyDic.getClassName())) { objKeyDicList.add(keyDic); } } keyDicClass.setKeyDicList(objKeyDicList); } return quexianList; } private List convertTree(List keyPblmsListAll, String version) { List objKeyDics = new ArrayList<>(); for (int i = 0; i < keyPblmsListAll.size(); i++) { ObjKeyPblms keyPblms = keyPblmsListAll.get(i); ObjKeyDic keyDic = new ObjKeyDic(); keyDic.setCheckPoint(keyPblms.getCheckPoint()); keyDic.setClassName(keyPblms.getClassName()); if (!objKeyDics.contains(keyDic)) { objKeyDics.add(keyDic); } } if ("v2".equals(version)) { for (ObjKeyDic objKeyDic : objKeyDics) { List keyCateList = new ArrayList<>(); for (ObjKeyPblms keyPblms : keyPblmsListAll) { if (objKeyDic.getCheckPoint().equals(keyPblms.getCheckPoint())) { ObjKeyCate keyCate = new ObjKeyCate(); keyCate.setCheckPoint(objKeyDic.getCheckPoint()); keyCate.setInspPblmCate(keyPblms.getInspPblmCate()); keyCate.setPblmCateName(getCateName(keyPblms.getInspPblmCate())); if (!keyCateList.contains(keyCate)) { keyCateList.add(keyCate); } } } objKeyDic.setKeyCateList(keyCateList); for (ObjKeyCate keyCate : objKeyDic.getKeyCateList()) { List keyPblmsList = new ArrayList<>(); for (ObjKeyPblms keyPblms : keyPblmsListAll) { if (keyCate.getCheckPoint().equals(keyPblms.getCheckPoint()) && keyCate.getInspPblmCate().equals(keyPblms.getInspPblmCate())) { keyPblmsList.add(keyPblms); } } keyCate.setKeyDicList(keyPblmsList); } } } else { for (ObjKeyDic objKeyDic : objKeyDics) { List keyPblmsList = new ArrayList<>(); for (ObjKeyPblms keyPblms : keyPblmsListAll) { if (objKeyDic.getCheckPoint().equals(keyPblms.getCheckPoint())) { keyPblmsList.add(keyPblms); } } objKeyDic.setKeyDicList(keyPblmsList); } } return objKeyDics; } private String getCateName(String cate) { if ("0".equals(cate)) { return "一般"; } if ("1".equals(cate)) { return "较重"; } if ("2".equals(cate)) { return "严重"; } if ("3".equals(cate)) { return "特别严重"; } return ""; } private List findObjKeys(String attach, String sn, KeyPblmParams keyPblmParams) { ObjKeyPblmsParam pblmsParam = new ObjKeyPblmsParam(); if (StringUtils.isNotBlank(attach)) { String[] attaches = attach.split(SplitValue.HENG_SPLIT); if (attaches.length == 2) { pblmsParam.setAttach(attaches[0].trim()); pblmsParam.setSheet(attaches[1].trim()); } else { pblmsParam.setAttach(attaches[0].trim()); } pblmsParam.setCheckPoint(keyPblmParams.getCheckPoint()); pblmsParam.setAttachType(keyPblmParams.getAttachType()); pblmsParam.setSheetName(keyPblmParams.getSheetName()); pblmsParam.setInspPblmsName(keyPblmParams.getInspPblmsName()); pblmsParam.setPblmType(keyPblmParams.getPblmType()); pblmsParam.setClassName(keyPblmParams.getClassName()); String snStr = ""; if (StringUtils.isNotBlank(sn)) { if (sn.contains(SplitValue.HENG_SPLIT)) { String[] snes = sn.split(SplitValue.HENG_SPLIT); if (snes.length == 2) { int start = Integer.parseInt(snes[0]); int end = Integer.parseInt(snes[1]); for (int i = start; i <= end; i++) { snStr += i + SplitValue.DOUHAO_SPLIT; } } else { snStr = snes[0]; } if (snStr.endsWith(SplitValue.DOUHAO_SPLIT)) { snStr = snStr.substring(0, snStr.length() - 1); } pblmsParam.setSn(snStr); } else { pblmsParam.setSn(sn); } } } pblmsParam.setPblmDesc(keyPblmParams.getPblmDesc()); List keyPblmsList = objKeyPblmsService.findKeyPblms(pblmsParam); return keyPblmsList; } }