package cn.com.goldenwater.dcproj.service.impl.other; import cn.com.goldenwater.dcproj.dao.*; import cn.com.goldenwater.dcproj.dto.BisInspOtherPblmDto; import cn.com.goldenwater.dcproj.dto.PersAllDto; import cn.com.goldenwater.dcproj.model.*; import cn.com.goldenwater.dcproj.param.*; import cn.com.goldenwater.dcproj.service.BisInspOtherPblmService; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.service.GwComFileService; import cn.com.goldenwater.dcproj.utils.BeanUtil; import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil; import cn.com.goldenwater.id.util.UuidUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; /** * @author lune * @date 2019-7-19 */ @Service @Transactional public class BisInspOtherPblmServiceImpl extends AbstractCrudService implements BisInspOtherPblmService { @Autowired private BisInspOtherPblmDao bisInspOtherPblmDao; @Autowired private AttAdXBaseDao attAdXBaseDao; @Autowired private BisInspAllDao bisInspAllDao; @Autowired private BisInspOtherRgstrDao rgstrDao; @Autowired private BisInspAllObjDao allObjDao; @Autowired private AttOtherBaseDao otherBaseDao; @Autowired private GwComFileService gwComFileService; @Autowired private SupervisionPlanDao supervisionPlanDao; public BisInspOtherPblmServiceImpl(BisInspOtherPblmDao bisInspOtherPblmDao) { super(bisInspOtherPblmDao); this.bisInspOtherPblmDao = bisInspOtherPblmDao; } @Override public int insertIntoData(List> list) { Map areaMap = new HashMap<>(); areaMap.put("黄河流域", "001010"); areaMap.put("长江流域", "001009"); areaMap.put("珠江流域", "001013"); areaMap.put("海河流域", "001012"); areaMap.put("松花江流域", "001014"); areaMap.put("淮河流域", "001011"); areaMap.put("太湖流域", "001015"); Iterator> iterator = list.iterator(); List otherRgstrs = new ArrayList<>(); List pblms = new ArrayList<>(); while (iterator.hasNext()) { LinkedHashMap map = iterator.next(); if (StringUtils.isBlank(String.valueOf(map.get("name")))) { continue; } BisInspOtherPblmDto otherPblmDto = null; try { otherPblmDto = (BisInspOtherPblmDto) ExpAndImpUtil.convertMapToBean(BisInspOtherPblmDto.class, map); } catch (Exception e) { throw new NullPointerException("转换失败"); } String type = type(otherPblmDto.getType()); if (StringUtils.isBlank(type)) { continue; } String name = otherPblmDto.getName(); String adCode = ""; try { if (StringUtils.isNotBlank(otherPblmDto.getProvince())) { adCode = getAdCode(otherPblmDto.getProvince(), "000000000000"); if (StringUtils.isNotBlank(otherPblmDto.getCity())) { adCode = getAdCode(otherPblmDto.getCity(), adCode); if (StringUtils.isNotBlank(otherPblmDto.getCountry())) { adCode = getAdCode(otherPblmDto.getCountry(), adCode); } } } } catch (Exception e) { e.printStackTrace(); } String orgId = ""; if (StringUtils.isNotBlank(otherPblmDto.getOrg())) { orgId = getOrgId(otherPblmDto.getOrg(), areaMap); } if (StringUtils.isNotBlank(otherPblmDto.getPblmNum()) && otherPblmDto.getPblmNum().indexOf(".") > 0) { otherPblmDto.setPblmNum(otherPblmDto.getPblmNum().substring(0, otherPblmDto.getPblmNum().indexOf("."))); } AttOtherBaseParam baseParam = new AttOtherBaseParam(); baseParam.setName(otherPblmDto.getName()); baseParam.setType(type); AttOtherBase base = otherBaseDao.getBy(baseParam); if (base == null) { continue; } base.setAdCode(adCode); base.setAdmOrg(orgId); otherBaseDao.update(base); BisInspOtherRgstrParam fscRgstrParam = new BisInspOtherRgstrParam(); fscRgstrParam.setType(type); fscRgstrParam.setName(name); List rgstrs = rgstrDao.findList(fscRgstrParam); if (rgstrs != null && rgstrs.size() > 1) { throw new NullPointerException("当前对象有多个"); } BisInspOtherRgstr rgstr = null; if (rgstrs == null || rgstrs.size() == 0) { //查询督查对象表 BisInspAllObjParam param = new BisInspAllObjParam(); param.setNm(otherPblmDto.getName()); param.setPtype("9"); BisInspAllObj obj = allObjDao.getBy(param); rgstr = new BisInspOtherRgstr(); rgstr.setId(UuidUtil.uuid()); rgstr.setObjId(obj.getObjId()); rgstr.setState("0"); rgstr.setCenterX(obj.getLttd()); rgstr.setCenterY(obj.getLgtd()); rgstr.setType(type); rgstr.setAdCode(adCode); rgstr.setInTm(new Date()); rgstr.setUpTm(new Date()); rgstr.setName(obj.getNm()); rgstr.setGroupId(obj.getId()); rgstr.setAdmOrg(orgId); rgstr.setDataStat("0"); this.rgstrDao.insert(rgstr); } else { rgstr = rgstrs.get(0); rgstr.setAdCode(adCode); rgstr.setAdmOrg(orgId); this.rgstrDao.update(rgstr); } if (rgstr != null) { otherRgstrs.add(rgstr); if (StringUtils.isNotBlank(otherPblmDto.getFdTime())) { try { otherPblmDto.setFdTm(new SimpleDateFormat("yyyy-MM-dd").parse(otherPblmDto.getFdTime())); } catch (ParseException e) { } } if (StringUtils.isNotBlank(otherPblmDto.getRectTime())) { try { otherPblmDto.setRectTm(new SimpleDateFormat("yyyy-MM-dd").parse(otherPblmDto.getRectTime())); } catch (ParseException e) { } } if (StringUtils.isBlank(otherPblmDto.getAUnit()) || StringUtils.isBlank(otherPblmDto.getPblmNum())) { continue; } BisInspOtherPblm pblm = new BisInspOtherPblm(otherPblmDto); pblm.setPblmIsTrue(pblmIsTrue(otherPblmDto.getPblmIsTrue())); if (StringUtils.isBlank(pblm.getId())) { bisInspOtherPblmDao.update(pblm); } else { pblm.setId(UuidUtil.uuid()); pblm.setRgstrId(rgstr.getId()); pblm.setGroupId(rgstr.getGroupId()); pblm.setPersId(rgstr.getPersId()); pblm.setInTm(new Date()); pblm.setUpTm(new Date()); pblm.setDataStat("0"); pblms.add(pblm); } } } if (pblms.size() == 0) { if (otherRgstrs.size() == 0) { return 1; } return otherRgstrs.size(); } if (pblms.size() > 0) { return this.bisInspOtherPblmDao.insertList(pblms); } return 0; } private String type(String typeName) { if ("河湖".equals(typeName)) { return "0"; } if ("举报调查".equals(typeName)) { return "1"; } return ""; } private String typeName(String type) { if ("0".equals(type)) { return "河湖"; } if ("1".equals(type)) { return "举报调查"; } return ""; } private String pblmIsTrue(String pblmIsTrue) { if ("不属实".equals(pblmIsTrue)) { return "0"; } if ("部分属实".equals(pblmIsTrue)) { return "1"; } if ("属实".equals(pblmIsTrue)) { return "2"; } return "0"; } private String revPblmIsTrue(String pblmIsTrue) { if (StringUtils.isBlank(pblmIsTrue)) { return ""; } if ("0".equals(pblmIsTrue)) { return "不属实"; } if ("1".equals(pblmIsTrue)) { return "部分属实"; } if ("2".equals(pblmIsTrue)) { return "属实"; } return "不属实"; } private String getAdCode(String adName, String adFcode) { AttAdXBaseParam param = new AttAdXBaseParam(); param.setAdName(adName); param.setAdFcode(adFcode); AttAdXBase base = this.attAdXBaseDao.getBy(param); return base.getAdCode(); } private String getOrgId(String orgName, Map areaMap) { for (String key : areaMap.keySet()) { if (key.contains(orgName)) { return areaMap.get(key); } } return ""; } @Override public int updatePblm(BisInspOtherPblm bisInspOtherPblm) { bisInspOtherPblm.setUpTm(new Date()); bisInspOtherPblmDao.update(bisInspOtherPblm); gwComFileService.updateBiz(bisInspOtherPblm.getGwComFiles(), bisInspOtherPblm.getId()); return 0; } @Override public List> findPblmList(FileParam param) { Map areaMap = new HashMap<>(); areaMap.put("001010", "黄河流域"); areaMap.put("001009", "长江流域"); areaMap.put("001013", "珠江流域"); areaMap.put("001012", "海河流域"); areaMap.put("001012", "松花江流域"); areaMap.put("001011", "淮河流域"); areaMap.put("001015", "太湖流域"); List list = this.bisInspOtherPblmDao.findPblmList(param); List> pblmList = new ArrayList<>(); if (list.size() > 0) { int i = 0; for (BisInspOtherPblmDto b : list) { b.setNum(String.valueOf(i++)); b.setType(typeName(b.getType())); b.setPblmIsTrue(revPblmIsTrue(b.getPblmIsTrue())); if (StringUtils.isNotBlank(b.getOrg())) { b.setOrg(getOrgId(b.getOrg(), areaMap)); } if (b.getFdTm() != null) { b.setFdTime(new SimpleDateFormat("yyyy-MM-dd").format(b.getFdTm())); } if (b.getRectTm() != null) { b.setRectTime(new SimpleDateFormat("yyyy-MM-dd").format(b.getRectTm())); } if (StringUtils.isNotBlank(b.getGroupObjId())) { List persAllDtoList = supervisionPlanDao.getPersAllDtoList(b.getGroupObjId(),param.getOrgId(),param.getProvince()); if (persAllDtoList != null) { String checkLead = ""; String checkMemb = ""; for (PersAllDto per : persAllDtoList) { if ("1".equals(per.getPersType())) { checkLead = checkLead + per.getPersName() + ","; } if ("2".equals(per.getPersType())) { checkMemb = checkMemb + per.getPersName() + ","; } } if (checkLead.length() > 0) { b.setCheckLead(checkLead.substring(0, checkLead.length() - 1)); } if (checkMemb.length() > 0) { b.setCheckMemb(checkMemb.substring(0, checkMemb.length() - 1)); } } } if (b.getAdFullName() != null) { if (b.getAdFullName().contains("-")) { String[] split = b.getAdFullName().split("-"); if (split.length == 3) { b.setProvince(split[0]); b.setCity(split[1]); b.setCountry(split[2]); } if (split.length == 2) { b.setProvince(split[0]); b.setCity(split[1]); b.setCountry(""); } } else { b.setProvince(b.getAdFullName()); } } pblmList.add(BeanUtil.transBean2Map(b)); } } return pblmList; } @Override public PageInfo findPageInfo(BisInspOtherPblmParam bisInspOtherPblmParam){ PageHelper.startPage(bisInspOtherPblmParam.getPageNum(), bisInspOtherPblmParam.getPageSize()); List bisInspFscPblms = bisInspOtherPblmDao.findPageList(bisInspOtherPblmParam); PageInfo page = new PageInfo(bisInspFscPblms); return page; } }