package cn.com.goldenwater.dcproj.service.impl; 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.BisInspWintuRgstrVo; import cn.com.goldenwater.dcproj.model.*; import cn.com.goldenwater.dcproj.param.*; import cn.com.goldenwater.dcproj.service.BisInspObjStrategy; import cn.com.goldenwater.dcproj.service.BisInspWintuRgstrService; import cn.com.goldenwater.dcproj.utils.AdLevelUtil; import cn.com.goldenwater.dcproj.utils.GeoUtil; import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil; import cn.com.goldenwater.dcproj.utils.impexcel.WintuFieldFromatExp; import cn.com.goldenwater.id.util.UuidUtil; import cn.com.goldenwater.util.common.InspPblmUtils; 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.BeanUtils; 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.*; import static cn.com.goldenwater.dcproj.utils.impexcel.field.ExcelFieldLists.bisInspRgstrArrays; import static cn.com.goldenwater.dcproj.utils.impexcel.field.ExcelFieldLists.bisInspWintuMendLiftArrays; /** * @author lune * @date 2020-7-15 */ @Service @Transactional(rollbackFor = Exception.class) public class BisInspWintuRgstrServiceImpl extends AbstractCrudService implements BisInspWintuRgstrService, BisInspObjStrategy { @Autowired private BisInspWintuRgstrDao bisInspWintuRgstrDao; @Autowired private AttWintBaseDao attWintBaseDao; @Autowired private BisInspPblmDao bisInspPblmDao; @Autowired private BisInspAllObjDao bisInspAllObjDao; @Autowired private BisInspWintRgstrMendLiftDao bisInspWintRgstrMendLiftDao; @Autowired private BisInspWintRgstrChkInDao bisInspWintRgstrChkInDao; @Value("${export.templatePath}") private String templatePath; public BisInspWintuRgstrServiceImpl(BisInspWintuRgstrDao bisInspWintuRgstrDao) { super(bisInspWintuRgstrDao); this.bisInspWintuRgstrDao = bisInspWintuRgstrDao; } public String getAdCode(String regid) { return null; } @Override public PageInfo findWintuPage(TypeParam param) { 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 = bisInspWintuRgstrDao.findWintuPage(param); list = InspPblmUtils.changeList(list); return new PageInfo(list); } @Override public PageInfo findObjPageByType(TypeParam typeParam, HttpServletResponse response) { return this.findWintuPage(typeParam); } @Override public Object findObjListByType(TypeParam typeParam) { List list = bisInspWintuRgstrDao.findWintuPage(typeParam); return InspPblmUtils.changeList(list); } @Override public String getType() { return BisInspEnum.WINTU.getValue(); } @Override public void insertObj(BisInspAllObj bisInspAllObj, String persId) { AttWintBase attWintBase = attWintBaseDao.get(bisInspAllObj.getCode()); BisInspWintuRgstr rgstr = new BisInspWintuRgstr(); BeanUtils.copyProperties(attWintBase, rgstr); rgstr.setId(UuidUtil.uuid()); rgstr.setWinId(attWintBase.getId()); rgstr.setWinName(attWintBase.getWintName()); rgstr.setObjId(bisInspAllObj.getObjId()); rgstr.setInTm(new Date()); rgstr.setUpTm(new Date()); rgstr.setChkInStat(StateEnum.NOWASTSTATE.getKey()); rgstr.setMendLiftStat(StateEnum.NOWASTSTATE.getKey()); rgstr.setWiuLoc(attWintBase.getWintPos()); rgstr.setCenterX(attWintBase.getWainLong()); rgstr.setCenterY(attWintBase.getWainLat()); if (rgstr.getCenterX() != null && rgstr.getCenterY() != null) { Map map = GeoUtil.wgs84togcj02(rgstr.getCenterX(), rgstr.getCenterY()); rgstr.setGdX(map.get("lon")); rgstr.setGdY(map.get("lat")); } rgstr.setPersId(persId); bisInspWintuRgstrDao.insert(rgstr); } @Override public void cleanObjData(String objId) { BisInspWintuRgstrParam wintuRgstrParam = new BisInspWintuRgstrParam(); wintuRgstrParam.setObjId(objId); List list = this.bisInspWintuRgstrDao.findList(wintuRgstrParam); if (CollectionUtils.isNotEmpty(list)) { String id = list.get(0).getId(); //删除问题 BisInspPblmParam bisInspPblmParam = new BisInspPblmParam(); bisInspPblmParam.setObjId(objId); bisInspPblmParam.setObjType(BisInspEnum.WINTU.getValue()); this.bisInspPblmDao.deleteBy(bisInspPblmParam); //删除对象名录表 BisInspAllObjParam bisInspAllObjParam = new BisInspAllObjParam(); bisInspAllObjParam.setObjId(objId); this.bisInspAllObjDao.deleteBy(bisInspAllObjParam); BisInspWintRgstrMendLiftParam mendLiftParam = new BisInspWintRgstrMendLiftParam(); mendLiftParam.setRgstrId(id); bisInspWintRgstrMendLiftDao.deleteBy(mendLiftParam); BisInspWintRgstrChkInParam chkInParam = new BisInspWintRgstrChkInParam(); chkInParam.setRgstrId(id); bisInspWintRgstrChkInDao.deleteBy(chkInParam); } } /** * 获取取水许可信息 * * @param id 登记表ID * @return */ @Override public Aqsxkspqk findPermissionInfo(String id) { return bisInspWintuRgstrDao.findPermissionInfo(id); } /** * 获取问题信息 * * @param id 登记表ID * @return */ @Override public Aqsxkspqk findIssueInfo(String id) { return bisInspWintuRgstrDao.findIssueInfo(id); } @Override public void downloadTemplate(HttpServletResponse response, TypeParam param) throws Exception { List bisInspWintuRgstrVos = new ArrayList(); // 模板路径 String filePath = templatePath + File.separator + "pblmQysdc_tb.xls"; // SHEET名称 String sheetName = "取用水督查填报"; // startRow int startRow = 2; if (StringUtils.isBlank(param.getPlnaId())) { List> list = new ArrayList<>(); ExpAndImpUtil.download(response, list, filePath, startRow, sheetName); } List list = bisInspWintuRgstrDao.findWintuPage(param); list = InspPblmUtils.changeList(list); for (BisInspRgstrDto bisInspRgstrDto : list) { BisInspWintuRgstrVo vo = new BisInspWintuRgstrVo(); //登记表 vo.setBisInspRgstrDto(bisInspRgstrDto); String rgstrId = bisInspRgstrDto.getRgstrId(); //整改提升 BisInspWintRgstrMendLiftParam mendLiftParam = new BisInspWintRgstrMendLiftParam(); mendLiftParam.setRgstrId(rgstrId); BisInspWintRgstrMendLift mendLift = bisInspWintRgstrMendLiftDao.getBy(mendLiftParam); vo.setBisInspWintRgstrMendLift(mendLift); bisInspWintuRgstrVos.add(vo); } List> dataList = new LinkedList<>(); for (BisInspWintuRgstrVo vo : bisInspWintuRgstrVos) { Map map = new HashMap<>(); BisInspRgstrDto bisInspRgstrDto = vo.getBisInspRgstrDto(); ExpAndImpUtil.convertBeanToMap(bisInspRgstrDto, bisInspRgstrArrays, map, WintuFieldFromatExp.class); //整改提升 BisInspWintRgstrMendLift bisInspWintRgstrMendLift = vo.getBisInspWintRgstrMendLift(); ExpAndImpUtil.convertBeanToMap(bisInspWintRgstrMendLift, bisInspWintuMendLiftArrays, map, WintuFieldFromatExp.class); dataList.add(map); } ExpAndImpUtil.download(response, dataList, filePath, startRow, sheetName); } @Override public void insertIntoData(List> showDataList, FileParam param) throws Exception { String persId = param.getPersId(); for (LinkedHashMap map : showDataList) { String rgstrId = ""; BisInspRgstrDto bisInspRgstrDto = (BisInspRgstrDto) ExpAndImpUtil.convertMapToBean(BisInspRgstrDto.class, map); if (StringUtils.isNotBlank(bisInspRgstrDto.getRgstrId())) { rgstrId = bisInspRgstrDto.getRgstrId(); BisInspWintuRgstr wintuRgstr = new BisInspWintuRgstr(); BeanUtils.copyProperties(bisInspRgstrDto, wintuRgstr); wintuRgstr.setPersId(persId); wintuRgstr.setUpTm(new Date()); wintuRgstr.setId(rgstrId); bisInspWintuRgstrDao.update(wintuRgstr); } else { String id = UuidUtil.uuid(); rgstrId = id; BisInspWintuRgstr wintuRgstr = new BisInspWintuRgstr(); BeanUtils.copyProperties(bisInspRgstrDto, wintuRgstr); AttWintBaseParam attWintBaseParam = new AttWintBaseParam(); attWintBaseParam.setWintName(bisInspRgstrDto.getNm()); List attWintBases = attWintBaseDao.findList(attWintBaseParam); if (CollectionUtils.isEmpty(attWintBases)) { continue; } AttWintBase attWintBase = attWintBases.get(0); BeanUtils.copyProperties(attWintBase, wintuRgstr); String ObjUuid = UuidUtil.uuid(); BisInspAllObj bisInspAllObj = new BisInspAllObj(); bisInspAllObj.setCode(attWintBase.getId()); bisInspAllObj.setId(param.getGroupId()); bisInspAllObj.setNm(attWintBase.getWintName()); bisInspAllObj.setLgtd(attWintBase.getWainLong()); bisInspAllObj.setLttd(attWintBase.getWainLat()); bisInspAllObj.setObjId(ObjUuid); bisInspAllObj.setPtype("31"); bisInspAllObjDao.insert(bisInspAllObj); wintuRgstr.setId(rgstrId); wintuRgstr.setWinName(bisInspRgstrDto.getNm()); wintuRgstr.setPersId(persId); wintuRgstr.setInTm(new Date()); wintuRgstr.setUpTm(new Date()); wintuRgstr.setObjId(ObjUuid); bisInspWintuRgstrDao.insert(wintuRgstr); } if (StringUtils.isBlank(rgstrId)) { continue; } BisInspWintRgstrMendLift mendLift = (BisInspWintRgstrMendLift) ExpAndImpUtil.convertMapToBean(BisInspWintRgstrMendLift.class, map); BisInspWintRgstrMendLiftParam mendLiftParam = new BisInspWintRgstrMendLiftParam(); mendLiftParam.setRgstrId(rgstrId); List mendLiftList = bisInspWintRgstrMendLiftDao.findList(mendLiftParam); if (CollectionUtils.isNotEmpty(mendLiftList)) { mendLift.setId(mendLiftList.get(0).getId()); mendLift.setUptm(new Date()); mendLift.setRecPersId(persId); bisInspWintRgstrMendLiftDao.update(mendLift); } else { mendLift.setId(UuidUtil.uuid()); mendLift.setUptm(new Date()); mendLift.setIntm(new Date()); mendLift.setRecPersId(persId); bisInspWintRgstrMendLiftDao.insert(mendLift); } } } }