package cn.com.goldenwater.dcproj.service.impl.offline; import cn.com.goldenwater.dcproj.constValue.BisInspEnum; import cn.com.goldenwater.dcproj.constValue.SplitValue; import cn.com.goldenwater.dcproj.dao.*; import cn.com.goldenwater.dcproj.model.*; import cn.com.goldenwater.dcproj.param.*; import cn.com.goldenwater.dcproj.service.GwComFileService; import cn.com.goldenwater.dcproj.service.SupervisionPlanService; import cn.com.goldenwater.dcproj.utils.AdLevelUtil; import cn.com.goldenwater.id.util.UuidUtil; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import static cn.com.goldenwater.dcproj.utils.impexcel.ImpUtil.checkIsDate; /** * @author lhc 大中型水库离线填报 * @date 2020/3/16 13:40 */ @Service @Transactional public class BisInspOffLineRsmlProcess extends BisInspOffLineProcess { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired AttRsBaseDao attRsBaseDao;//水库基本信息 @Autowired BisInspPblmDao bisInspPblmDao;//督查问题 @Autowired private GwComFileService gwComFileService;//文件操作 @Autowired private BisInspRsmlRgstrDao bisInspRsmlRgstrDao; @Autowired private BisInspAllObjDao bisInspAllObjDao; @Autowired private BisInspRsmlRgstrPresDao bisInspRsmlRgstrPresDao; @Autowired private BisInspRsmlRgstrSafeDao bisInspRsmlRgstrSafeDao; @Autowired private BisInspRsmlRgstrProjectDao bisInspRsmlRgstrProjectDao; @Autowired private BisInspRsmlRgstrRunManageDao bisInspRsmlRgstrRunManageDao; @Value("${getFile.prefix}") public String prefix; @Autowired SupervisionPlanService supervisionPlanService; @Override public BisInspOffLineRet process(BisInspOffLineObj bisInspOffLineObj, String fileDir) throws IOException { BisInspOffLineRet bisInspOffLineRet = new BisInspOffLineRet(); ObjectMapper om = new ObjectMapper(); om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); //解析大中水库填报信息 BisInspOffLineRsmlRgeister bisInspOffLineRsmlRgeister = om.readValue(bisInspOffLineObj.getRegister(), BisInspOffLineRsmlRgeister.class); //解析大中水库基本信息对象 if (bisInspOffLineObj.getBase() != null) { BisInspRsmlRgstr bisInspRsmlRgstr = new BisInspRsmlRgstr(); String objId = UuidUtil.uuid(); String regId = objId; BisInspOffLineRsml bisInspOffLineRsml = bisInspOffLineRsmlRgeister.getBisInspOffLineRsml(); if (null != bisInspOffLineRsml && StringUtils.isNotBlank(bisInspOffLineRsml.getRgstrId())) { bisInspOffLineRsmlRgeister.setRgstrId(bisInspOffLineRsml.getRgstrId()); regId = bisInspOffLineRsml.getRgstrId(); bisInspOffLineRsmlRgeister.setObjId(bisInspOffLineRsml.getObjId()); objId = bisInspOffLineRsml.getObjId(); bisInspRsmlRgstr.setObjId(objId); bisInspRsmlRgstr.setRgstrId(regId); bisInspRsmlRgstr.setState("1"); } else { //添加到督查任务 String goupId = bisInspOffLineObj.getGroupId(); AttRsBase attRsBase = om.readValue(bisInspOffLineObj.getBase(), AttRsBase.class); insertBisInspAllObj(bisInspOffLineObj, attRsBase, objId, goupId); bisInspRsmlRgstr.setRgstrId(regId); bisInspRsmlRgstr.setObjId(objId); //插入登记表信息 insertBisInspRsmlRgstr(attRsBase, bisInspRsmlRgstr, om); } //插入三个责任人信息 insertBisInspRsmlRgstrPres(bisInspOffLineRsmlRgeister, bisInspRsmlRgstr, bisInspOffLineRsml); //水库安全管理三级责任人 insertBisInspPresSafe(bisInspOffLineRsmlRgeister, bisInspRsmlRgstr, bisInspOffLineRsml); //运行情况 insertBisInspRsmlRgstrRunManage(bisInspOffLineRsmlRgeister, bisInspRsmlRgstr, bisInspOffLineRsml); //水库工程实体 insertBisInspRsmlRgstrProject(bisInspOffLineRsmlRgeister, bisInspRsmlRgstr, bisInspOffLineRsml); bisInspRsmlRgstrDao.update(bisInspRsmlRgstr);//更新各个填报项目状态 bisInspOffLineRet.setObjId(objId); bisInspOffLineRet.setRegId(regId); } return bisInspOffLineRet; } /** * 删除任务及登记表信息 * * @param bisInspOffLineObj */ public void delRgstrData(BisInspOffLineObj bisInspOffLineObj) { //登记表查找重复数据,然后删除 BisInspAllObjParam bisInspAllObjParam = new BisInspAllObjParam(); bisInspAllObjParam.setId(bisInspOffLineObj.getGroupId()); bisInspAllObjParam.setNm(bisInspOffLineObj.getNm()); List bisInspAllObjs = bisInspAllObjDao.findList(bisInspAllObjParam); for (BisInspAllObj bisInspAllObj : bisInspAllObjs) { //删除登记表 //删除登记表关联的各个填报表数据 supervisionPlanService.cleanObjDataByObjId(BisInspEnum.RSML.getValue(), bisInspAllObj.getObjId()); } } /** * 插入小水库督查任务信息 * * @param attRsBase 对象基本信息 * @param objId 督查对象ID * @param groupId 督查组ID */ public void insertBisInspAllObj(BisInspOffLineObj bisInspOffLineObj, AttRsBase attRsBase, String objId, String groupId) { BisInspAllObj bisInspAllObj = new BisInspAllObj(); bisInspAllObj.setId(groupId); bisInspAllObj.setObjId(objId); bisInspAllObj.setOrgId(bisInspOffLineObj.getOrgId()); bisInspAllObj.setAdCode(bisInspOffLineObj.getProvince()); bisInspAllObj.setNm(attRsBase.getRsName()); bisInspAllObj.setCode(attRsBase.getRsCode()); bisInspAllObj.setPtype("22"); bisInspAllObj.setLttd(StringUtils.isNotBlank(attRsBase.getCenterXGd()) ? Double.parseDouble(attRsBase.getCenterXGd()) : 0); bisInspAllObj.setLgtd(StringUtils.isNotBlank(attRsBase.getCenterYGd()) ? Double.parseDouble(attRsBase.getCenterYGd()) : 0); bisInspAllObj.setLttdpc(StringUtils.isNotBlank(attRsBase.getCenterX()) ? Double.parseDouble(attRsBase.getCenterX()) : 0); bisInspAllObj.setLgtdpc(StringUtils.isNotBlank(attRsBase.getCenterY()) ? Double.parseDouble(attRsBase.getCenterY()) : 0); bisInspAllObjDao.insert(bisInspAllObj); } /** * 插入大中水库登记信息 * * @param attRsBase 对象基本信息 * @param bisInspRsmlRgstr 注册信息 * @param om 转换对象 * @throws IOException */ public void insertBisInspRsmlRgstr(AttRsBase attRsBase, BisInspRsmlRgstr bisInspRsmlRgstr, ObjectMapper om) { bisInspRsmlRgstr.setRgstrId(bisInspRsmlRgstr.getRgstrId()); bisInspRsmlRgstr.setObjId(bisInspRsmlRgstr.getObjId()); bisInspRsmlRgstr.setRsCode(attRsBase.getRsCode()); bisInspRsmlRgstr.setRsName(attRsBase.getRsName()); bisInspRsmlRgstr.setId(bisInspRsmlRgstr.getRgstrId()); if (attRsBase.getRegCode() != null) { bisInspRsmlRgstr.setHasDamRegCode("1"); bisInspRsmlRgstr.setDamRegCode(attRsBase.getRegCode()); } else { bisInspRsmlRgstr.setHasDamRegCode("2"); } bisInspRsmlRgstr.setAdCode(attRsBase.getAdmDiv()); bisInspRsmlRgstr.setLocation(attRsBase.getLocation()); bisInspRsmlRgstr.setHystSite(attRsBase.getLocation()); bisInspRsmlRgstr.setCenterX(attRsBase.getCenterX() == null ? 0 : Double.parseDouble(attRsBase.getCenterX())); bisInspRsmlRgstr.setCenterY(attRsBase.getCenterY() == null ? 0 : Double.parseDouble(attRsBase.getCenterY())); bisInspRsmlRgstr.setGdX(attRsBase.getCenterXGd() == null ? 0 : Double.parseDouble(attRsBase.getCenterXGd())); bisInspRsmlRgstr.setGdY(attRsBase.getCenterYGd() == null ? 0 : Double.parseDouble(attRsBase.getCenterYGd())); bisInspRsmlRgstr.setRsAdmCode(attRsBase.getRsAdmCode()); bisInspRsmlRgstr.setRsAdmName(attRsBase.getRsAdmName()); bisInspRsmlRgstr.setEngScal(attRsBase.getEngScal()); bisInspRsmlRgstr.setRsClass(attRsBase.getRsClass()); bisInspRsmlRgstr.setDamType(attRsBase.getDamType()); bisInspRsmlRgstr.setTotCap(attRsBase.getTotCap()); bisInspRsmlRgstr.setDamSizeHig(attRsBase.getDamSizeHig()); bisInspRsmlRgstr.setDesFlStag(attRsBase.getDesFlStag()); bisInspRsmlRgstr.setFlConTopStag(attRsBase.getFlConTopStag()); bisInspRsmlRgstr.setImpdDt(attRsBase.getImpdDt()); bisInspRsmlRgstr.setRnfcImpdDt(attRsBase.getRnfcImpdDt()); if (org.apache.commons.lang3.StringUtils.isNotBlank(attRsBase.getCompDateStr())) { try { // 不是时间格式会报错,判断一下,不是时间格式就不赋给它了 if (checkIsDate(attRsBase.getCompDateStr())) { bisInspRsmlRgstr.setResCreateTime(new SimpleDateFormat(SplitValue.TIME_SPLIT).parse(attRsBase.getCompDateStr())); } } catch (ParseException e) { e.printStackTrace(); } } bisInspRsmlRgstr.setIntm(new Date()); bisInspRsmlRgstr.setUptm(new Date()); bisInspRsmlRgstr.setState("1"); //添加注册登记表 bisInspRsmlRgstrDao.insert(bisInspRsmlRgstr); } /** * 插入三个责任人信息 * * @param bisInspOffLineRsmlRgeister 三个责任人信息 * @param bisInspRsmlRgstr */ public void insertBisInspRsmlRgstrPres(BisInspOffLineRsmlRgeister bisInspOffLineRsmlRgeister, BisInspRsmlRgstr bisInspRsmlRgstr, BisInspOffLineRsml bisInspOffLineRsml) { if (null != bisInspOffLineRsml && StringUtils.isNotBlank(bisInspOffLineRsml.getRgstrId())) { if (null != bisInspOffLineRsml.getBasePresExt() && bisInspOffLineRsml.getBasePresExt()) { if (null != bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrPres()) { BisInspRsmlRgstrPres bisInspRsmlRgstrPres = bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrPres(); bisInspRsmlRgstrPres.setRgstrId(bisInspOffLineRsml.getRgstrId()); BisInspRsmlRgstrPresParam bisInspBasePresExtParam = new BisInspRsmlRgstrPresParam(); bisInspBasePresExtParam.setRgstrId(bisInspOffLineRsml.getRgstrId()); List bisInspBasePresExts = bisInspRsmlRgstrPresDao.findList(bisInspBasePresExtParam); //找到dutyId if (bisInspBasePresExts != null && bisInspBasePresExts.size() > 0) { bisInspRsmlRgstrPres.setId(bisInspBasePresExts.get(0).getId()); bisInspRsmlRgstrPresDao.update(bisInspRsmlRgstrPres); } else { bisInspRsmlRgstrPres.setId(UuidUtil.uuid()); bisInspRsmlRgstrPresDao.insert(bisInspRsmlRgstrPres); } //更新状态 bisInspRsmlRgstr.setPresState("2"); } } } else { BisInspRsmlRgstrPres bisInspRsmlRgstrPres = null; if (bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrPres() != null) { bisInspRsmlRgstrPres = bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrPres(); //更新状态 bisInspRsmlRgstr.setPresState("2"); } else { bisInspRsmlRgstrPres = new BisInspRsmlRgstrPres(); bisInspRsmlRgstr.setPresState("1"); } bisInspRsmlRgstrPres.setRgstrId(bisInspRsmlRgstr.getRgstrId()); bisInspRsmlRgstrPres.setId(UuidUtil.uuid()); bisInspRsmlRgstrPresDao.insert(bisInspRsmlRgstrPres); } } /** * 插入政府三级管理责任人 * * @param bisInspOffLineRsmlRgeister 三个责任人信息 * @param bisInspRsmlRgstr */ public void insertBisInspPresSafe(BisInspOffLineRsmlRgeister bisInspOffLineRsmlRgeister, BisInspRsmlRgstr bisInspRsmlRgstr, BisInspOffLineRsml bisInspOffLineRsml) { if (null != bisInspOffLineRsml && StringUtils.isNotBlank(bisInspOffLineRsml.getRgstrId())) { if (null != bisInspOffLineRsml.getPresSafe() && bisInspOffLineRsml.getPresSafe()) { if (null != bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrSafe()) { BisInspRsmlRgstrSafe bisInspRsmlRgstrSafe = bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrSafe(); bisInspRsmlRgstrSafe.setRgstrId(bisInspOffLineRsml.getRgstrId()); BisInspRsmlRgstrSafeParam bisInspRsmlRgstrSafeParam = new BisInspRsmlRgstrSafeParam(); bisInspRsmlRgstrSafeParam.setRgstrId(bisInspOffLineRsml.getRgstrId()); List bisInspRsmlRgstrSafes = bisInspRsmlRgstrSafeDao.findList(bisInspRsmlRgstrSafeParam); //找到dutyId if (bisInspRsmlRgstrSafes != null && bisInspRsmlRgstrSafes.size() > 0) { bisInspRsmlRgstrSafe.setId(bisInspRsmlRgstrSafes.get(0).getId()); bisInspRsmlRgstrSafeDao.update(bisInspRsmlRgstrSafe); } else { bisInspRsmlRgstrSafe.setId(UuidUtil.uuid()); bisInspRsmlRgstrSafeDao.insert(bisInspRsmlRgstrSafe); } //更新状态 bisInspRsmlRgstr.setSafeStat("2"); } } } else { BisInspRsmlRgstrSafe bisInspRsmlRgstrSafe = null; if (bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrSafe() != null) { bisInspRsmlRgstrSafe = bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrSafe(); //更新状态 bisInspRsmlRgstr.setSafeStat("2"); } else { bisInspRsmlRgstrSafe = new BisInspRsmlRgstrSafe(); bisInspRsmlRgstr.setSafeStat("1"); } bisInspRsmlRgstrSafe.setRgstrId(bisInspRsmlRgstr.getRgstrId()); bisInspRsmlRgstrSafe.setId(UuidUtil.uuid()); bisInspRsmlRgstrSafeDao.insert(bisInspRsmlRgstrSafe); } } /** * 插入运行情况信息 * * @param bisInspOffLineRsmlRgeister 运行情况信息 * @param bisInspRsmlRgstr */ public void insertBisInspRsmlRgstrRunManage(BisInspOffLineRsmlRgeister bisInspOffLineRsmlRgeister, BisInspRsmlRgstr bisInspRsmlRgstr, BisInspOffLineRsml bisInspOffLineRsml) { if (null != bisInspOffLineRsml && StringUtils.isNotBlank(bisInspOffLineRsml.getRgstrId())) { if (null != bisInspOffLineRsml.getSafeExtManage() && bisInspOffLineRsml.getSafeExtManage()) { if (null != bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrRunManage()) { BisInspRsmlRgstrRunManage bisInspRsmlRgstrRunManage = bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrRunManage(); bisInspRsmlRgstrRunManage.setRgstrId(bisInspOffLineRsml.getRgstrId()); //找到对应的ID update BisInspRsmlRgstrRunManageParam bisInspSafeExtManageParam = new BisInspRsmlRgstrRunManageParam(); bisInspSafeExtManageParam.setRgstrId(bisInspOffLineRsml.getRgstrId()); List bisInspRsmlRgstrRunManages = bisInspRsmlRgstrRunManageDao.findList(bisInspSafeExtManageParam); if (bisInspRsmlRgstrRunManages != null && bisInspRsmlRgstrRunManages.size() > 0) { bisInspRsmlRgstrRunManage.setId(bisInspRsmlRgstrRunManages.get(0).getId()); if (null != bisInspOffLineRsml.getSafeExtManage() && bisInspOffLineRsml.getSafeExtManage()) { bisInspRsmlRgstrRunManageDao.update(bisInspRsmlRgstrRunManage); } } else { bisInspRsmlRgstrRunManage.setId(UuidUtil.uuid()); bisInspRsmlRgstrRunManageDao.insert(bisInspRsmlRgstrRunManage); } bisInspRsmlRgstr.setRunManageState("2"); //更新状态 } } } else { BisInspRsmlRgstrRunManage bisInspRsmlRgstrRunManage = null; if (bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrRunManage() != null) { bisInspRsmlRgstrRunManage = bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrRunManage(); bisInspRsmlRgstr.setRunManageState("2"); //更新状态 } else { bisInspRsmlRgstrRunManage = new BisInspRsmlRgstrRunManage(); bisInspRsmlRgstr.setRunManageState("1"); } bisInspRsmlRgstrRunManage.setRgstrId(bisInspRsmlRgstr.getRgstrId()); bisInspRsmlRgstrRunManage.setId(UuidUtil.uuid()); bisInspRsmlRgstrRunManageDao.insert(bisInspRsmlRgstrRunManage); } } /** * 插入水库工程实体信息 * * @param bisInspOffLineRsmlRgeister 三个责任人信息 * @param bisInspRsmlRgstr */ public void insertBisInspRsmlRgstrProject(BisInspOffLineRsmlRgeister bisInspOffLineRsmlRgeister, BisInspRsmlRgstr bisInspRsmlRgstr, BisInspOffLineRsml bisInspOffLineRsml) { if (null != bisInspOffLineRsml && StringUtils.isNotBlank(bisInspOffLineRsml.getRgstrId())) { if (null != bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrProject()) { BisInspRsmlRgstrProject bisInspRsmlRgstrProject = bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrProject(); bisInspRsmlRgstrProject.setRgstrId(bisInspOffLineRsml.getRgstrId()); //找到对应的ID update BisInspRsmlRgstrProjectParam bisInspRsmlRgstrProjectParam = new BisInspRsmlRgstrProjectParam(); bisInspRsmlRgstrProjectParam.setRgstrId(bisInspOffLineRsml.getRgstrId()); List bisInspRsmlRgstrProjects = bisInspRsmlRgstrProjectDao.findList(bisInspRsmlRgstrProjectParam); if (bisInspRsmlRgstrProjects != null && bisInspRsmlRgstrProjects.size() > 0) { bisInspRsmlRgstrProject.setId(bisInspRsmlRgstrProjects.get(0).getId()); if (null != bisInspOffLineRsml.getRsvrProject() && bisInspOffLineRsml.getRsvrProject()) { bisInspRsmlRgstrProjectDao.update(bisInspRsmlRgstrProject); } } else { bisInspRsmlRgstrProject.setId(UuidUtil.uuid()); bisInspRsmlRgstrProjectDao.insert(bisInspRsmlRgstrProject); } bisInspRsmlRgstr.setProjectState("2"); } } else { BisInspRsmlRgstrProject bisInspRsmlRgstrProject = null; if (bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrProject() != null) { bisInspRsmlRgstrProject = bisInspOffLineRsmlRgeister.getBisInspRsmlRgstrProject();//更新状态 bisInspRsmlRgstr.setProjectState("2"); } else { bisInspRsmlRgstrProject = new BisInspRsmlRgstrProject(); bisInspRsmlRgstr.setProjectState("1"); } bisInspRsmlRgstrProject.setRgstrId(bisInspRsmlRgstr.getRgstrId()); bisInspRsmlRgstrProject.setId(UuidUtil.uuid()); bisInspRsmlRgstrProjectDao.insert(bisInspRsmlRgstrProject); } } @Override public BisInspOffLineRetBase getBaseInfo(BisInspOffLine bisInspOffLine) { BisInspOffLineRetBase bisInspOffLineRetBase = new BisInspOffLineRetBase(); AttRsBaseParam attRsBaseParam = new AttRsBaseParam(); attRsBaseParam.setRsName(bisInspOffLine.getName()); attRsBaseParam.setAdmDiv(AdLevelUtil.getAddvcd(bisInspOffLine.getAddvcd())); bisInspOffLineRetBase.setBase(attRsBaseDao.findList(attRsBaseParam)); //判断登记表是否有重复对象 List bisInspRsmlRgstrs = bisInspRsmlRgstrDao.getRsmlByIdNm(bisInspOffLine.getGroupId(), bisInspOffLine.getName()); if (null != bisInspRsmlRgstrs && bisInspRsmlRgstrs.size() > 0) { bisInspOffLineRetBase.setRepeat(true); bisInspOffLineRetBase.setRepeatList(bisInspRsmlRgstrs); } else { bisInspOffLineRetBase.setRepeat(false); } return bisInspOffLineRetBase; } }