package cn.com.goldenwater.dcproj.service.impl.offline; import cn.com.goldenwater.dcproj.constValue.BisInspEnum; 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.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.SimpleDateFormat; import java.util.Date; import java.util.List; /** * 水源地离线填报 * * @author zhangcheng * @date 2019/11/26 16:40 */ @Service @Transactional public class BisInspOffLineWiuqhProcess extends BisInspOffLineProcess { @Autowired BisInspAllObjDao bisInspAllObjDao; @Autowired BisInspPblmDao bisInspPblmDao;//督查问题 @Autowired BisInspWiuqhRgstrDao bisInspWiuqhRgstrDao; @Autowired BisInspWiuqhFarmDao bisInspWiuqhFarmDao; @Autowired BisInspWiuqhWintDao bisInspWiuqhWintDao; @Autowired BisInspWiuqhHyistDao bisInspWiuqhHyistDao; @Autowired BisInspWiuqhIndusDao bisInspWiuqhIndusDao; @Autowired BisInspWiuqhPubwtsDao bisInspWiuqhPubwtsDao; @Autowired AttWiuqhBaseDao attWiuqhBaseDao; @Autowired private GwComFileService gwComFileService;//文件操作 @Value("${getFile.prefix}") public String prefix; @Autowired SupervisionPlanService supervisionPlanService; @Autowired AttWintBaseBDao attWintBaseBDao; @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); //解析水源地填报信息 BisInspOffLineWiuqhRgeister bisInspOffLineSwhsRgeister = om.readValue(bisInspOffLineObj.getRegister(), BisInspOffLineWiuqhRgeister.class); //解析水源地对象 if (bisInspOffLineObj.getBase() != null) { String objId = UuidUtil.uuid(); String groupId = bisInspOffLineObj.getGroupId(); BisInspWiuqhRgstr bisInspWiuqhRgstr = new BisInspWiuqhRgstr(); String regId = objId; String persId = bisInspOffLineObj.getPersId(); AttWiuqhBase attWiuqhBase = om.readValue(bisInspOffLineObj.getBase(), AttWiuqhBase.class); if (StringUtils.isBlank(attWiuqhBase.getRgstrId())) { insertBisInspAllObj(bisInspOffLineObj, groupId, objId, attWiuqhBase); insertWiuqhRgstr(attWiuqhBase, groupId, objId, persId, regId, bisInspWiuqhRgstr); bisInspWiuqhRgstr.setRgstrId(regId); bisInspWiuqhRgstr.setObjId(objId); } else { regId = attWiuqhBase.getRgstrId(); objId = attWiuqhBase.getObjId(); } //青海取水口取水监管情况检查表 insertWiuqhWint(bisInspOffLineSwhsRgeister, regId, persId, bisInspWiuqhRgstr); //农业情况表-青海 insertWiuqhFarm(bisInspOffLineSwhsRgeister, regId, persId, bisInspWiuqhRgstr); insertWiuqhIndus(bisInspOffLineSwhsRgeister, regId, persId, bisInspWiuqhRgstr); insertWiuqhHyist(bisInspOffLineSwhsRgeister, regId, persId, bisInspWiuqhRgstr); insertWiuqhPubwts(bisInspOffLineSwhsRgeister, regId, persId, bisInspWiuqhRgstr); //更新督查 字表状态 bisInspWiuqhRgstrDao.update(bisInspWiuqhRgstr); bisInspOffLineRet.setObjId(objId); bisInspOffLineRet.setRegId(regId); } 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.SWHS.getValue(), bisInspAllObj.getObjId()); } } /** * 添加到督查任务 * * @param groupId * @param objId * @param attSwhsBase */ public void insertBisInspAllObj(BisInspOffLineObj bisInspOffLineObj, String groupId, String objId, AttWiuqhBase attWiuqhBase) { BisInspAllObj bisInspAllObj = new BisInspAllObj(); bisInspAllObj.setId(groupId); bisInspAllObj.setObjId(objId); bisInspAllObj.setNm(attWiuqhBase.getNm()); bisInspAllObj.setCode(attWiuqhBase.getId());//非空字段 bisInspAllObj.setPtype("72"); bisInspAllObj.setOrgId(bisInspOffLineObj.getOrgId()); bisInspAllObj.setAdCode(bisInspOffLineObj.getProvince()); bisInspAllObj.setLgtd(attWiuqhBase.getGdX()); bisInspAllObj.setLttd(attWiuqhBase.getGdY()); bisInspAllObj.setLgtdpc(attWiuqhBase.getCenterX()); bisInspAllObj.setLttdpc(attWiuqhBase.getCenterY()); bisInspAllObjDao.insert(bisInspAllObj); } /** * 插入登记表信息 * * @param bisInspOffLineObj * @param objId * @param om * @param regId * @param bisInspSwhsRgstr * @throws IOException */ public void insertWiuqhRgstr(AttWiuqhBase attWiuqhBase, String groupId, String objId, String persId, String regId, BisInspWiuqhRgstr bisInspWiuqhRgstr) throws IOException { bisInspWiuqhRgstr.setId(regId); bisInspWiuqhRgstr.setObjId(objId); bisInspWiuqhRgstr.setIntm(new Date()); bisInspWiuqhRgstr.setUptm(new Date()); bisInspWiuqhRgstr.setNm(attWiuqhBase.getNm()); bisInspWiuqhRgstr.setAppDep(attWiuqhBase.getAppDep()); bisInspWiuqhRgstr.setAppNo(attWiuqhBase.getAppNo()); bisInspWiuqhRgstr.setLoc(attWiuqhBase.getLoc()); bisInspWiuqhRgstr.setWtAppNo(attWiuqhBase.getWtAppNo()); bisInspWiuqhRgstr.setWtEntm(attWiuqhBase.getWtEntm()); bisInspWiuqhRgstr.setWtMsr(attWiuqhBase.getWtMsr()); bisInspWiuqhRgstr.setWtTm(attWiuqhBase.getWtTm()); bisInspWiuqhRgstr.setWtType(attWiuqhBase.getWtType()); bisInspWiuqhRgstr.setWtUsr(attWiuqhBase.getWtUsr()); //获取取水权人相关信息 bisInspWiuqhRgstrDao.insert(bisInspWiuqhRgstr); } /** * 青海取水口取水监管情况检查表 * * @param bisInspOffLineSwhsRgeister * @param regId * @param bisInspOffLineObj * @param bisInspSwhsRgstr */ public void insertWiuqhWint(BisInspOffLineWiuqhRgeister bisInspOffLineSwhsRgeister, String regId, String persId, BisInspWiuqhRgstr bisInspWiuqhRgstr) { //青海取水口取水监管情况检查表 if (bisInspOffLineSwhsRgeister.getBisInspWiuqhWint() != null) { List bisInspWiuqhWints = bisInspOffLineSwhsRgeister.getBisInspWiuqhWint(); List attWintBaseBS = bisInspOffLineSwhsRgeister.getAttWintBaseB(); for (int i = 0; i < attWintBaseBS.size(); i++) { //循环插入取水口基本信息 //修改取水口的ID AttWintBaseB attWintBaseB = attWintBaseBS.get(i); attWintBaseB.setId(UuidUtil.uuid()); //根据行政区划生成取水口代码 String adCode = attWintBaseB.getAdCode(); String maxObjCode = ""; if (StringUtils.isNotBlank(adCode)) { String objCode = attWintBaseBDao.getMaxObjCode(attWintBaseB.getAdCode()); if (StringUtils.isBlank(objCode)) { maxObjCode = adCode + "0001"; } else { Long a = Long.parseLong(objCode); a++; maxObjCode = String.valueOf(a); } } attWintBaseB.setWintCode(maxObjCode); attWintBaseBDao.insert(attWintBaseB); //插入登记表信息 BisInspWiuqhWint bisInspWiuqhWint = bisInspWiuqhWints.get(i); bisInspWiuqhWint.setId(UuidUtil.uuid()); bisInspWiuqhWint.setRgstrId(regId); bisInspWiuqhWint.setDataStat("0"); //设置取水口信息 bisInspWiuqhWint.setWintId(attWintBaseBS.get(i).getId()); bisInspWiuqhWint.setWintCode(attWintBaseBS.get(i).getWintCode()); bisInspWiuqhWint.setWintName(attWintBaseBS.get(i).getWintName()); bisInspWiuqhWint.setStatus("2"); bisInspWiuqhWintDao.insert(bisInspWiuqhWint); bisInspWiuqhRgstr.setState("2"); } } } /** * 重要饮用水水源管理情况 * * @param bisInspOffLineSwhsRgeister * @param regId * @param bisInspOffLineObj * @param bisInspSwhsRgstr */ public void insertWiuqhFarm(BisInspOffLineWiuqhRgeister bisInspOffLineSwhsRgeister, String regId, String persId, BisInspWiuqhRgstr bisInspWiuqhRgstr) { // BisInspWiuqhFarm bisInspWiuqhFarm = new BisInspWiuqhFarm(); BisInspWiuqhFarmParam bisInspWiuqhFarmParam = new BisInspWiuqhFarmParam(); bisInspWiuqhFarmParam.setRgstrId(regId); bisInspWiuqhFarmDao.deleteBy(bisInspWiuqhFarmParam); if (bisInspOffLineSwhsRgeister.getBisInspWiuqhFarm() != null) { bisInspWiuqhFarm = bisInspOffLineSwhsRgeister.getBisInspWiuqhFarm(); bisInspWiuqhFarm.setId(UuidUtil.uuid()); bisInspWiuqhFarm.setRgstrId(regId); bisInspWiuqhFarm.setDataStat("0"); bisInspWiuqhFarmDao.insert(bisInspWiuqhFarm); } bisInspWiuqhRgstr.setFarmState("2"); } /** * 重要饮用水水源管理情况 * * @param bisInspOffLineSwhsRgeister * @param regId * @param bisInspOffLineObj * @param bisInspSwhsRgstr */ public void insertWiuqhIndus(BisInspOffLineWiuqhRgeister bisInspOffLineSwhsRgeister, String regId, String persId, BisInspWiuqhRgstr bisInspWiuqhRgstr) { // BisInspWiuqhIndus bisInspWiuqhIndus = new BisInspWiuqhIndus(); BisInspWiuqhIndusParam bisInspWiuqhIndusParam = new BisInspWiuqhIndusParam(); bisInspWiuqhIndusParam.setRgstrId(regId); bisInspWiuqhIndusDao.deleteBy(bisInspWiuqhIndusParam); if (bisInspOffLineSwhsRgeister.getBisInspWiuqhIndus() != null) { bisInspWiuqhIndus = bisInspOffLineSwhsRgeister.getBisInspWiuqhIndus(); bisInspWiuqhIndus.setId(UuidUtil.uuid()); bisInspWiuqhIndus.setRgstrId(regId); bisInspWiuqhIndus.setDataStat("0"); bisInspWiuqhIndusDao.insert(bisInspWiuqhIndus); bisInspWiuqhRgstr.setIndusState("2"); } } public void insertWiuqhHyist(BisInspOffLineWiuqhRgeister bisInspOffLineSwhsRgeister, String regId, String persId, BisInspWiuqhRgstr bisInspWiuqhRgstr) { // BisInspWiuqhHyist bisInspWiuqhHyist = new BisInspWiuqhHyist(); BisInspWiuqhHyistParam bisInspWiuqhHyistParam = new BisInspWiuqhHyistParam(); bisInspWiuqhHyistParam.setRgstrId(regId); bisInspWiuqhHyistDao.deleteBy(bisInspWiuqhHyistParam); if (bisInspOffLineSwhsRgeister.getBisInspWiuqhHyist() != null) { bisInspWiuqhHyist = bisInspOffLineSwhsRgeister.getBisInspWiuqhHyist(); bisInspWiuqhHyist.setId(UuidUtil.uuid()); bisInspWiuqhHyist.setRgstrId(regId); bisInspWiuqhHyist.setDataStat("0"); bisInspWiuqhHyistDao.insert(bisInspWiuqhHyist); bisInspWiuqhRgstr.setIndusState("2"); } } public void insertWiuqhPubwts(BisInspOffLineWiuqhRgeister bisInspOffLineSwhsRgeister, String regId, String persId, BisInspWiuqhRgstr bisInspWiuqhRgstr) { // BisInspWiuqhPubwts bisInspWiuqhPubwts = new BisInspWiuqhPubwts(); BisInspWiuqhPubwtsParam bisInspWiuqhPubwtsParam = new BisInspWiuqhPubwtsParam(); bisInspWiuqhPubwtsParam.setRgstrId(regId); bisInspWiuqhPubwtsDao.deleteBy(bisInspWiuqhPubwtsParam); if (bisInspOffLineSwhsRgeister.getBisInspWiuqhPubwts() != null) { bisInspWiuqhPubwts = bisInspOffLineSwhsRgeister.getBisInspWiuqhPubwts(); bisInspWiuqhPubwts.setId(UuidUtil.uuid()); bisInspWiuqhPubwts.setRgstrId(regId); bisInspWiuqhPubwts.setDataStat("0"); bisInspWiuqhPubwtsDao.insert(bisInspWiuqhPubwts); bisInspWiuqhRgstr.setIndusState("2"); } } @Override public BisInspOffLineRetBase getBaseInfo(BisInspOffLine bisInspOffLine) { BisInspOffLineRetBase bisInspOffLineRetBase = new BisInspOffLineRetBase(); AttWiuqhBaseParam attWiuqhBaseParam = new AttWiuqhBaseParam(); attWiuqhBaseParam.setNm(bisInspOffLine.getName()); attWiuqhBaseParam.setAdCode(bisInspOffLine.getAddvcd()); bisInspOffLineRetBase.setBase(attWiuqhBaseDao.findList(attWiuqhBaseParam)); List wiuqhByIdNm = bisInspWiuqhRgstrDao.getWiuqhByIdNm(bisInspOffLine.getGroupId(), bisInspOffLine.getName()); if (null != wiuqhByIdNm && wiuqhByIdNm.size() > 0) { bisInspOffLineRetBase.setRepeat(true); bisInspOffLineRetBase.setRepeatList(wiuqhByIdNm); } else { bisInspOffLineRetBase.setRepeat(false); } return bisInspOffLineRetBase; } }