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.AttRsBaseParam; import cn.com.goldenwater.dcproj.param.AttWuntBaseParam; import cn.com.goldenwater.dcproj.param.BisInspAllObjParam; import cn.com.goldenwater.dcproj.param.BisInspRsfcoqhPresParam; 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.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 zhangcheng * @date 2019/11/26 17:54 */ @Service @Transactional public class BisInspOffLineRsfcoqhProcess extends BisInspOffLineProcess { @Autowired BisInspAllObjDao bisInspAllObjDao; @Autowired BisInspPblmDao bisInspPblmDao;//督查问题 @Autowired AttRsBaseDao attRsBaseDao;//水库基本信息 @Autowired SupervisionPlanService supervisionPlanService; @Autowired BisInspRsfcoqhRgstrDao bisInspRsfcoqhRgstrDao; @Autowired BisInspRsfcoqhPresDao bisInspRsfcoqhPresDao; @Value("${getFile.prefix}") public String prefix; @Autowired BisInspRsvrRgstrDao bisInspRsvrRgstrDao; @Override public BisInspOffLineRet process(BisInspOffLineObj bisInspOffLineObj, String fileDir) throws IOException { BisInspOffLineRet bisInspOffLineRet = new BisInspOffLineRet(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); ObjectMapper om = new ObjectMapper(); om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); //解析青海-水库防洪调度督查 BisInspOffLineRsfcoqhRgeister bisInspOffLineRsfcoqhRgeister = om.readValue(bisInspOffLineObj.getRegister(), BisInspOffLineRsfcoqhRgeister.class); //解析水库基本信息对象 if (bisInspOffLineObj.getBase() != null) { //添加到督查任务 String objId = UuidUtil.uuid(); String groupId = bisInspOffLineObj.getGroupId(); String regId = objId; String persId = bisInspOffLineObj.getPersId(); AttRsBase attRsBase = om.readValue(bisInspOffLineObj.getBase(), AttRsBase.class); BisInspRsfcoqhRgstr bisInspRsfcoqhRgstr = new BisInspRsfcoqhRgstr(); if (StringUtils.isNotBlank(attRsBase.getRgstrId())) { regId = attRsBase.getRgstrId(); objId = attRsBase.getObjId(); bisInspRsfcoqhRgstr.setId(regId); bisInspRsfcoqhRgstr.setObjId(objId); bisInspRsfcoqhRgstr.setState("1"); } else { //添加到督查任务 insertBisInspAllObj(bisInspOffLineObj, groupId, objId, attRsBase); bisInspRsfcoqhRgstr.setRgstrId(regId); bisInspRsfcoqhRgstr.setObjId(objId); bisInspRsfcoqhRgstr.setId(regId); //插入登记表信息 insertRsfcoqhRgstr(attRsBase, bisInspRsfcoqhRgstr, om); } //水库安全度汛检查表 insertRsfcoqhPres(bisInspOffLineRsfcoqhRgeister, regId, persId, bisInspRsfcoqhRgstr); bisInspRsfcoqhRgstrDao.update(bisInspRsfcoqhRgstr); bisInspOffLineRet.setRegId(regId); bisInspOffLineRet.setObjId(objId); } return bisInspOffLineRet; } /** * 删除任务及登记表信息 * * @param groupId * @param nm */ 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.RSFCOQH.getValue(), bisInspAllObj.getObjId()); } } /** * 添加到督查任务 * * @param groupId * @param objId * @param attAdBase */ public void insertBisInspAllObj(BisInspOffLineObj bisInspOffLineObj, String groupId, String objId, AttRsBase attRsBase) { BisInspAllObj bisInspAllObj = new BisInspAllObj(); bisInspAllObj.setId(groupId); bisInspAllObj.setObjId(objId); bisInspAllObj.setNm(attRsBase.getRsName()); bisInspAllObj.setCode(attRsBase.getRsCode());//非空字段 bisInspAllObj.setPtype("96"); bisInspAllObj.setOrgId(bisInspOffLineObj.getOrgId()); bisInspAllObj.setAdCode(bisInspOffLineObj.getProvince()); 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); bisInspAllObj.setObjAdCode(attRsBase.getRsAdmCode()); bisInspAllObjDao.insert(bisInspAllObj); } /** * 插入登记表信息 * * @param bisInspOffLineObj * @param objId * @param om * @param regId * @param bisInspSvwtWuntRgstr * @throws IOException */ public void insertRsfcoqhRgstr(AttRsBase attRsBase, BisInspRsfcoqhRgstr bisInspRsfcoqhRgstr, ObjectMapper om) { bisInspRsfcoqhRgstr.setRsCode(attRsBase.getRsCode()); bisInspRsfcoqhRgstr.setRsName(attRsBase.getRsName()); if (attRsBase.getRegCode() != null) { bisInspRsfcoqhRgstr.setHasDamRegCode("1"); bisInspRsfcoqhRgstr.setDamRegCode(attRsBase.getRegCode()); } else { bisInspRsfcoqhRgstr.setHasDamRegCode("2"); } bisInspRsfcoqhRgstr.setAdCode(attRsBase.getAdmDiv()); bisInspRsfcoqhRgstr.setLocation(attRsBase.getLocation()); bisInspRsfcoqhRgstr.setHystSite(attRsBase.getLocation()); bisInspRsfcoqhRgstr.setCenterX(attRsBase.getCenterX() == null ? 0 : Double.parseDouble(attRsBase.getCenterX())); bisInspRsfcoqhRgstr.setCenterY(attRsBase.getCenterY() == null ? 0 : Double.parseDouble(attRsBase.getCenterY())); bisInspRsfcoqhRgstr.setGdX(attRsBase.getCenterXGd() == null ? 0 : Double.parseDouble(attRsBase.getCenterXGd())); bisInspRsfcoqhRgstr.setGdY(attRsBase.getCenterYGd() == null ? 0 : Double.parseDouble(attRsBase.getCenterYGd())); bisInspRsfcoqhRgstr.setRsAdmCode(attRsBase.getRsAdmCode()); bisInspRsfcoqhRgstr.setRsAdmName(attRsBase.getRsAdmName()); bisInspRsfcoqhRgstr.setEngScal(attRsBase.getEngScal()); bisInspRsfcoqhRgstr.setDamType(attRsBase.getDamType()); bisInspRsfcoqhRgstr.setTotCap(attRsBase.getTotCap()); bisInspRsfcoqhRgstr.setDamSizeHig(attRsBase.getDamSizeHig()); bisInspRsfcoqhRgstr.setDataStat("0"); if (org.apache.commons.lang3.StringUtils.isNotBlank(attRsBase.getCompDateStr())) { try { // 不是时间格式会报错,判断一下,不是时间格式就不赋给它了 if (checkIsDate(attRsBase.getCompDateStr())) { bisInspRsfcoqhRgstr.setResCreateTime(new SimpleDateFormat(SplitValue.TIME_SPLIT).parse(attRsBase.getCompDateStr())); } } catch (ParseException e) { e.printStackTrace(); } } bisInspRsfcoqhRgstr.setIntm(new Date()); bisInspRsfcoqhRgstr.setUptm(new Date()); bisInspRsfcoqhRgstr.setState("1"); //添加注册登记表 if (StringUtils.isNotBlank(attRsBase.getRgstrId())) { bisInspRsfcoqhRgstrDao.update(bisInspRsfcoqhRgstr); } else { bisInspRsfcoqhRgstrDao.insert(bisInspRsfcoqhRgstr); } } /** * 插入水库安全度汛检查表 */ public void insertRsfcoqhPres(BisInspOffLineRsfcoqhRgeister bisInspOffLineRsfcoqhRgeister, String regId, String persId, BisInspRsfcoqhRgstr bisInspRsfcoqhRgstr) { // BIS_INSP_RSFCOQH_PRES BisInspRsfcoqhPres bisInspRsfcoqhPres = bisInspOffLineRsfcoqhRgeister.getBisInspRsfcoqhPres(); BisInspRsfcoqhPresParam bisInspRsfcoqhPresParam = new BisInspRsfcoqhPresParam(); bisInspRsfcoqhPresParam.setRgstrId(regId); bisInspRsfcoqhPresDao.deleteBy(bisInspRsfcoqhPresParam); bisInspRsfcoqhPres.setId(UuidUtil.uuid()); bisInspRsfcoqhPres.setRgstrId(regId); bisInspRsfcoqhPres.setDataStat("0"); bisInspRsfcoqhPres.setPersId(persId); bisInspRsfcoqhPresDao.insert(bisInspRsfcoqhPres); bisInspRsfcoqhRgstr.setPresState("1"); } @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 bisInspRsfcoqhRgstrs = bisInspRsfcoqhRgstrDao.getRsvrByIdNm(bisInspOffLine.getGroupId(), bisInspOffLine.getName()); if (null != bisInspRsfcoqhRgstrs && bisInspRsfcoqhRgstrs.size() > 0) { bisInspOffLineRetBase.setRepeat(true); bisInspOffLineRetBase.setRepeatList(bisInspRsfcoqhRgstrs); } else { bisInspOffLineRetBase.setRepeat(false); } return bisInspOffLineRetBase; } }