package cn.com.goldenwater.dcproj.service.impl.rsfco; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.constValue.BisInspEnum; import cn.com.goldenwater.dcproj.constValue.SplitValue; import cn.com.goldenwater.dcproj.constValue.StateEnum; import cn.com.goldenwater.dcproj.dao.*; import cn.com.goldenwater.dcproj.dto.BisInspRgstrDto; import cn.com.goldenwater.dcproj.dto.BisInspRsfcoRgstrVo; import cn.com.goldenwater.dcproj.model.*; import cn.com.goldenwater.dcproj.param.*; import cn.com.goldenwater.dcproj.service.*; import cn.com.goldenwater.dcproj.utils.AdLevelUtil; import cn.com.goldenwater.dcproj.utils.BeanUtil; import cn.com.goldenwater.dcproj.utils.Builder; import cn.com.goldenwater.dcproj.utils.InspPblmUtils; import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil; import cn.com.goldenwater.dcproj.utils.impexcel.field.ExcelFieldLists; import cn.com.goldenwater.dcproj.utils.impexcel.format.RsfcoFieldFromatExp; import cn.com.goldenwater.id.util.UuidUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.apache.commons.collections.CollectionUtils; 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 javax.servlet.http.HttpServletResponse; import java.io.File; import java.util.*; /** * @author lune * @date 2020-4-21 */ @Service @Transactional public class BisInspRsfcoRgstrServiceImpl extends AbstractCrudService implements BisInspRsfcoRgstrService, BisInspObjStrategy { @Autowired private BisInspRsfcoRgstrDao bisInspRsfcoRgstrDao; @Autowired private BisInspPblmDao bisInspPblmDao; @Autowired private AttRsBaseDao attRsBaseDao; @Autowired private AttAdXBaseDao attAdXBaseDao; @Autowired private BisInspAllObjDao bisInspAllObjDao; @Autowired private AttRsBaseCrrctDao attRsBaseCrrctDao; @Autowired private BisInspRsfcoRgstrBaseDao bisInspRsfcoRgstrBaseDao; @Autowired private BisInspRsfcoRgstrFlliDao bisInspRsfcoRgstrFlliDao; @Autowired private BisInspRsfcoRgstrAoeparoDao bisInspRsfcoRgstrAoeparoDao; @Autowired private BisInspRsfcoRgstrBaseInfoService bisInspRsfcoRgstrBaseInfoService; @Autowired private BisInspRsfcoRgstrFcsService bisInspRsfcoRgstrFcsService; @Autowired private BisInspRsfcoRgstrTflwliiService bisInspRsfcoRgstrTflwliiService; @Value("${export.templatePath}") private String templatePath; public BisInspRsfcoRgstrServiceImpl(BisInspRsfcoRgstrDao bisInspRsfcoRgstrDao) { super(bisInspRsfcoRgstrDao); this.bisInspRsfcoRgstrDao = bisInspRsfcoRgstrDao; } @Override public void insertObj(BisInspAllObj bisInspAllObj, String persId) { AttRsBaseParam baseParam = new AttRsBaseParam(); baseParam.setRsCode(bisInspAllObj.getCode()); AttRsBase attRsBase = attRsBaseDao.getBy(baseParam); BisInspRsfcoRgstr rgstr = new BisInspRsfcoRgstr(); rgstr.setId(UuidUtil.uuid()); rgstr.setObjId(bisInspAllObj.getObjId()); rgstr.setRsCode(attRsBase.getRsCode()); rgstr.setRsName(bisInspAllObj.getNm()); rgstr.setHasDamRegCode("1"); rgstr.setDamRegCode(attRsBase.getRegCode()); rgstr.setAdCode(attRsBase.getAdmDiv()); rgstr.setLocation(attRsBase.getLocation()); rgstr.setHystSite(attRsBase.getRsLoc()); rgstr.setCompDateStr(attRsBase.getCompDateStr()); if (attRsBase.getCenterYGd() != null) { rgstr.setGdY(Double.parseDouble(attRsBase.getCenterYGd())); } if (attRsBase.getCenterXGd() != null) { rgstr.setGdX(Double.parseDouble(attRsBase.getCenterXGd())); } if (attRsBase.getCenterX() != null) { rgstr.setCenterX(Double.parseDouble(attRsBase.getCenterX())); } if (attRsBase.getCenterY() != null) { rgstr.setCenterY(Double.parseDouble(attRsBase.getCenterY())); } rgstr.setRsAdmCode(attRsBase.getRsAdmCode()); rgstr.setRsAdmName(attRsBase.getRsAdmName()); rgstr.setEngScal(attRsBase.getEngScal()); rgstr.setDamType(attRsBase.getDamType()); rgstr.setTotCap(attRsBase.getTotCap()); rgstr.setDamSizeHig(attRsBase.getDamSizeHig()); rgstr.setResCreateTime(attRsBase.getCompDate()); rgstr.setPresState(StateEnum.NOWASTSTATE.getKey()); rgstr.setRunManageState(StateEnum.NOWASTSTATE.getKey()); rgstr.setProjectState(StateEnum.NOWASTSTATE.getKey()); rgstr.setState(StateEnum.NOWASTSTATE.getKey()); Date date = new Date(); rgstr.setIntm(date); rgstr.setUptm(date); bisInspRsfcoRgstrDao.insert(rgstr); // bisInspRsfcoRgstrBaseInfoService.insert(Builder.of(BisInspRsfcoRgstrBaseInfoParam::new).with(BisInspRsfcoRgstrBaseInfoParam::setRgstrId, rgstr.getId()).build()); // bisInspRsfcoRgstrFcsService.insert(Builder.of(BisInspRsfcoRgstrFcsParam::new).with(BisInspRsfcoRgstrFcsParam::setRgstrId, rgstr.getId()).build()); // bisInspRsfcoRgstrTflwliiService.insert(Builder.of(BisInspRsfcoRgstrTflwliiParam::new).with(BisInspRsfcoRgstrTflwliiParam::setRgstrId, rgstr.getId()).build()); } @Override public String getType() { return BisInspEnum.RSFCO.getValue(); } @Override public void cleanObjData(String objId) { BisInspRsfcoRgstrParam rsfcoRgstrParam = new BisInspRsfcoRgstrParam(); rsfcoRgstrParam.setObjId(objId); List list = this.bisInspRsfcoRgstrDao.findList(rsfcoRgstrParam); if (list.size() > 0) { String id = list.get(0).getId(); BisInspPblmParam bisInspPblmParam = new BisInspPblmParam(); bisInspPblmParam.setObjId(objId); bisInspPblmParam.setObjType(BisInspEnum.RSFCO.getValue()); this.bisInspPblmDao.deleteBy(bisInspPblmParam);//删除问题 BisInspRsfcoRgstrBaseParam baseParam = new BisInspRsfcoRgstrBaseParam(); baseParam.setRgstrId(id); bisInspRsfcoRgstrBaseDao.deleteBy(baseParam); BisInspRsfcoRgstrFlliParam flliParam = new BisInspRsfcoRgstrFlliParam(); flliParam.setRgstrId(id); bisInspRsfcoRgstrFlliDao.deleteBy(flliParam); bisInspRsfcoRgstrBaseInfoService.deleteBy(Builder.of(BisInspRsfcoRgstrBaseInfoParam::new).with(BisInspRsfcoRgstrBaseInfoParam::setRgstrId, id).build()); bisInspRsfcoRgstrFcsService.deleteBy(Builder.of(BisInspRsfcoRgstrFcsParam::new).with(BisInspRsfcoRgstrFcsParam::setRgstrId, id).build()); bisInspRsfcoRgstrTflwliiService.deleteBy(Builder.of(BisInspRsfcoRgstrTflwliiParam::new).with(BisInspRsfcoRgstrTflwliiParam::setRgstrId, id).build()); BisInspRsfcoRgstrAoeparoParam aoeparoParam = new BisInspRsfcoRgstrAoeparoParam(); aoeparoParam.setRgstrId(id); bisInspRsfcoRgstrAoeparoDao.deleteBy(aoeparoParam); this.bisInspRsfcoRgstrDao.delete(id);//删除水库登记表 BisInspAllObjParam bisInspAllObjParam = new BisInspAllObjParam(); bisInspAllObjParam.setObjId(objId); this.bisInspAllObjDao.deleteBy(bisInspAllObjParam);//删除对象名录表 AttRsBaseCrrctParam attRsBaseCrrctParam = new AttRsBaseCrrctParam(); attRsBaseCrrctParam.setObjId(objId); attRsBaseCrrctDao.deleteBy(attRsBaseCrrctParam); } } @Override public PageInfo findObjPageByType(TypeParam typeParam, HttpServletResponse response) { return findRsfcoPage(typeParam, response); } @Override public Object findObjListByType(TypeParam typeParam) { if (StringUtils.isNotBlank(typeParam.getAdCode())) { typeParam.setAdCode(String.valueOf(AdLevelUtil.SubAd(typeParam.getAdCode()).get(SplitValue.SUBAD))); } List list = bisInspRsfcoRgstrDao.findRsfcoList(typeParam); list = InspPblmUtils.changeList(list); return list; } @Override public PageInfo findRsfcoPage(TypeParam param, HttpServletResponse response) { if (StringUtils.isNotBlank(param.getAdCode())) { param.setAdCode(String.valueOf(AdLevelUtil.SubAd(param.getAdCode()).get(SplitValue.SUBAD))); } if (StringUtils.isNotBlank(param.getAdCodes())) { param.setAdCodes(AdLevelUtil.getListAddvcd(param.getAdCodes())); } PageHelper.startPage(param); List list = bisInspRsfcoRgstrDao.findRsfcoList(param); list = InspPblmUtils.changeList(list); return new PageInfo(list); } @Override public void downloadTemplate(HttpServletResponse response, TypeParam param) throws Exception { // 模板路径 String filePath = templatePath + File.separator + "pblmSkfh_tb.xls"; // SHEET名称 String sheetName = "水库防洪填报表"; // 文件名称带后缀 String fileName = sheetName + ".xls"; // startRow int startRow = 2; if (StringUtils.isBlank(param.getPlnaId())) { List> list = new ArrayList<>(); ExpAndImpUtil.download(response, list, filePath, startRow, sheetName); } //获取水库登记表 List rsfcoList = bisInspRsfcoRgstrDao.findRsfcoList(param); rsfcoList = InspPblmUtils.changeList(rsfcoList); List bisInspRsfcoRgstrVoList = new ArrayList(); //赋值其他参数 setRsfcoRgstrVoList(rsfcoList, bisInspRsfcoRgstrVoList); //数据转换为Map List> dataList = rsfcoRgsteListConvertMap(bisInspRsfcoRgstrVoList); ExpAndImpUtil.download(response, dataList, filePath, startRow, sheetName); } private List> rsfcoRgsteListConvertMap(List bisInspRsfcoRgstrVoList) { List> dataList = new LinkedList<>(); bisInspRsfcoRgstrVoList.forEach(vo -> { Map map = new HashMap<>(); //登记表 BisInspRgstrDto bisInspRgstrDto = vo.getBisInspRgstrDto(); ExpAndImpUtil.convertBeanToMap(bisInspRgstrDto, ExcelFieldLists.bisInspRgstrArrays, map, RsfcoFieldFromatExp.class); //水库防洪调度存在问题原因分析及整改意见管理 BisInspRsfcoRgstrAoeparo bisInspRsfcoRgstrAoeparo = vo.getBisInspRsfcoRgstrAoeparo(); ExpAndImpUtil.convertBeanToMap(bisInspRsfcoRgstrAoeparo, ExcelFieldLists.bisInspRsfcoRgstrAoeparoArrays, map, RsfcoFieldFromatExp.class); //水库防洪调度总体情况管理 BisInspRsfcoRgstrBase bisInspRsfcoRgstrBase = vo.getBisInspRsfcoRgstrBase(); ExpAndImpUtil.convertBeanToMap(bisInspRsfcoRgstrBase, ExcelFieldLists.bisInspRsfcoRgstrBaseArrays, map, RsfcoFieldFromatExp.class); //水库防洪调度和汛限水位执行管理 BisInspRsfcoRgstrFlli bisInspRsfcoRgstrFlli = vo.getBisInspRsfcoRgstrFlli(); ExpAndImpUtil.convertBeanToMap(bisInspRsfcoRgstrFlli, ExcelFieldLists.bisInspRsfcoRgstrFlliArrays, map, RsfcoFieldFromatExp.class); dataList.add(map); }); return dataList; } private void setRsfcoRgstrVoList(List rsfcoList, List bisInspRsfcoRgstrVoList) { rsfcoList.forEach(rsfcoDto -> { BisInspRsfcoRgstrVo bisVo = new BisInspRsfcoRgstrVo(); //登记表 bisVo.setBisInspRgstrDto(rsfcoDto); String rgstrId = rsfcoDto.getRgstrId(); //水库防洪调度总体情况管理 BisInspRsfcoRgstrBaseParam baseParam = new BisInspRsfcoRgstrBaseParam(); baseParam.setRgstrId(rgstrId); BisInspRsfcoRgstrBase base = bisInspRsfcoRgstrBaseDao.getBy(baseParam); bisVo.setBisInspRsfcoRgstrBase(base); //水库防洪调度和汛限水位执行管理 BisInspRsfcoRgstrFlliParam flliParam = new BisInspRsfcoRgstrFlliParam(); flliParam.setRgstrId(rgstrId); BisInspRsfcoRgstrFlli flli = bisInspRsfcoRgstrFlliDao.getBy(flliParam); bisVo.setBisInspRsfcoRgstrFlli(flli); //水库防洪调度存在问题原因分析及整改意见管理 BisInspRsfcoRgstrAoeparoParam aoeparoParam = new BisInspRsfcoRgstrAoeparoParam(); aoeparoParam.setRgstrId(rgstrId); BisInspRsfcoRgstrAoeparo aoeparo = bisInspRsfcoRgstrAoeparoDao.getBy(aoeparoParam); bisVo.setBisInspRsfcoRgstrAoeparo(aoeparo); bisInspRsfcoRgstrVoList.add(bisVo); }); } @Override public int insertIntoData(List> list, FileParam param) throws Exception { for (LinkedHashMap map : list) { String persId = param.getPersId(); //修改登记表 BisInspRgstrDto bisInspRgstrDto = (BisInspRgstrDto) ExpAndImpUtil.convertMapToBean(BisInspRgstrDto.class, map); String rgstrId = ""; if (StringUtils.isNotBlank(bisInspRgstrDto.getRgstrId())) { rgstrId = bisInspRgstrDto.getRgstrId(); BisInspRsfcoRgstr bisInspRsfcoRgstr = new BisInspRsfcoRgstr(); BeanUtil.copyObject1(bisInspRgstrDto, bisInspRsfcoRgstr); bisInspRsfcoRgstr.setRsName(bisInspRgstrDto.getNm()); bisInspRsfcoRgstr.setUptm(new Date()); bisInspRsfcoRgstr.setRecPersId(persId); bisInspRsfcoRgstr.setId(rgstrId); bisInspRsfcoRgstr.setLocation(bisInspRgstrDto.getProvince() + bisInspRgstrDto.getCity() + bisInspRgstrDto.getCountry()); bisInspRsfcoRgstrDao.update(bisInspRsfcoRgstr); } else { String id = UuidUtil.uuid(); rgstrId = id; BisInspRsfcoRgstr bisInspRsfcoRgstr = new BisInspRsfcoRgstr(); BeanUtil.copyObject1(bisInspRgstrDto, bisInspRsfcoRgstr); AttRsBaseParam attRsBaseParam = new AttRsBaseParam(); attRsBaseParam.setRsName(bisInspRgstrDto.getNm()); List baseList = attRsBaseDao.findList(attRsBaseParam); if (CollectionUtils.isEmpty(baseList)) { continue; } AttRsBase attRsBase = baseList.get(0); String ObjUuid = UuidUtil.uuid(); BisInspAllObj bisInspAllObj = new BisInspAllObj(); bisInspAllObj.setCode(attRsBase.getRsCode()); bisInspAllObj.setId(param.getGroupId()); bisInspAllObj.setNm(attRsBase.getRsName()); bisInspAllObj.setLgtd(Double.parseDouble(attRsBase.getCenterXGd())); bisInspAllObj.setLttd(Double.parseDouble(attRsBase.getCenterYGd())); bisInspAllObj.setObjId(ObjUuid); bisInspAllObj.setPtype("26"); bisInspAllObjDao.insert(bisInspAllObj); BeanUtil.copyObject1(attRsBase, bisInspRsfcoRgstr); String adCode = attRsBase.getAdmDiv(); bisInspRsfcoRgstr.setAdCode(adCode); bisInspRsfcoRgstr.setId(id); bisInspRsfcoRgstr.setHasDamRegCode("1"); bisInspRsfcoRgstr.setRecPersId(persId); bisInspRsfcoRgstr.setObjId(ObjUuid); bisInspRsfcoRgstr.setIntm(new Date()); bisInspRsfcoRgstr.setUptm(new Date()); bisInspRsfcoRgstrDao.insert(bisInspRsfcoRgstr); } //水库防洪调度总体情况管理 insertRsfcoRgstrBse(map, persId, rgstrId); //水库防洪调度和汛限水位执行管理 insertRsfcoRgstrFlli(map, persId, rgstrId); //水库防洪调度存在问题原因分析及整改意见管理 insertRsfcoRgstrAoeparo(map, persId, rgstrId); } return 0; } private void insertRsfcoRgstrAoeparo(LinkedHashMap map, String persId, String rgstrId) throws IllegalAccessException, InstantiationException { if (StringUtils.isNotBlank(rgstrId)) { //水库防洪调度存在问题原因分析及整改意见管理 BisInspRsfcoRgstrAoeparo aoeparo = (BisInspRsfcoRgstrAoeparo) ExpAndImpUtil.convertMapToBean(BisInspRsfcoRgstrAoeparo.class, map); BisInspRsfcoRgstrAoeparoParam aoeparoParam = new BisInspRsfcoRgstrAoeparoParam(); aoeparoParam.setRgstrId(rgstrId); List aoeparoList = bisInspRsfcoRgstrAoeparoDao.findList(aoeparoParam); if (CollectionUtils.isEmpty(aoeparoList)) { aoeparo.setId(UuidUtil.uuid()); aoeparo.setRecPersId(persId); aoeparo.setRgstrId(rgstrId); aoeparo.setIntm(new Date()); aoeparo.setUptm(new Date()); bisInspRsfcoRgstrAoeparoDao.insert(aoeparo); } else { aoeparo.setId(aoeparoList.get(0).getId()); aoeparo.setRecPersId(persId); aoeparo.setRgstrId(rgstrId); aoeparo.setUptm(new Date()); bisInspRsfcoRgstrAoeparoDao.update(aoeparo); } } } private void insertRsfcoRgstrFlli(LinkedHashMap map, String persId, String rgstrId) throws IllegalAccessException, InstantiationException { if (StringUtils.isNotBlank(rgstrId)) { //水库防洪调度和汛限水位执行管理 BisInspRsfcoRgstrFlli flli = (BisInspRsfcoRgstrFlli) ExpAndImpUtil.convertMapToBean(BisInspRsfcoRgstrFlli.class, map); BisInspRsfcoRgstrFlliParam flliParam = new BisInspRsfcoRgstrFlliParam(); flliParam.setRgstrId(rgstrId); List flliList = bisInspRsfcoRgstrFlliDao.findList(flliParam); if (CollectionUtils.isEmpty(flliList)) { flli.setId(UuidUtil.uuid()); flli.setRecPersId(persId); flli.setIntm(new Date()); flli.setUptm(new Date()); flli.setRgstrId(rgstrId); bisInspRsfcoRgstrFlliDao.insert(flli); } else { flli.setId(flliList.get(0).getId()); flli.setRecPersId(persId); flli.setUptm(new Date()); bisInspRsfcoRgstrFlliDao.update(flli); } } } private void insertRsfcoRgstrBse(LinkedHashMap map, String persId, String rgstrId) throws IllegalAccessException, InstantiationException { if (StringUtils.isNotBlank(rgstrId)) { //水库防洪调度总体情况管理 BisInspRsfcoRgstrBase base = (BisInspRsfcoRgstrBase) ExpAndImpUtil.convertMapToBean(BisInspRsfcoRgstrBase.class, map); BisInspRsfcoRgstrBaseParam baseParam = new BisInspRsfcoRgstrBaseParam(); baseParam.setRgstrId(rgstrId); List baseList = bisInspRsfcoRgstrBaseDao.findList(baseParam); if (CollectionUtils.isEmpty(baseList)) { base.setId(UuidUtil.uuid()); base.setIntm(new Date()); base.setUptm(new Date()); base.setRecPersId(persId); base.setRgstrId(rgstrId); bisInspRsfcoRgstrBaseDao.insert(base); } else { base.setId(baseList.get(0).getId()); base.setUptm(new Date()); base.setRecPersId(persId); bisInspRsfcoRgstrBaseDao.update(base); } } } @Override public BisInspRsfcoRgstr get(String key) { BisInspRsfcoRgstr rgstr = super.get(key); if (rgstr != null) { if (rgstr.getAdCode() != null && rgstr.getAdCode().length() == 6) { rgstr.setAdCode(rgstr.getAdCode() + "000000"); } AttAdXBase adXBase = attAdXBaseDao.get(rgstr.getAdCode()); if (adXBase != null) { rgstr.setLocation(adXBase.getAdFullName()); } } return rgstr; } }