package cn.com.goldenwater.dcproj.service.impl.tac; import cn.com.goldenwater.dcproj.dao.BisInspAllRlationPersDao; import cn.com.goldenwater.dcproj.dao.TacInspYearBatchAreaDao; import cn.com.goldenwater.dcproj.dao.TacInspYearBatchDao; import cn.com.goldenwater.dcproj.dto.BisInspAllDto; import cn.com.goldenwater.dcproj.dto.TacInspYearBatchAreaDto; import cn.com.goldenwater.dcproj.model.BisInspAllNode; import cn.com.goldenwater.dcproj.model.TacInspYearBatch; import cn.com.goldenwater.dcproj.model.TacInspYearBatchArea; import cn.com.goldenwater.dcproj.param.TacInspYearBatchAreaParam; import cn.com.goldenwater.dcproj.service.OlBisInspOrgService; import cn.com.goldenwater.dcproj.service.TacInspYearBatchAreaService; import cn.com.goldenwater.core.service.AbstractCrudService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.map.HashedMap; 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.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; /** * @author lune * @date 2019-9-6 */ @Service @Transactional public class TacInspYearBatchAreaServiceImpl extends AbstractCrudService implements TacInspYearBatchAreaService { @Autowired private TacInspYearBatchAreaDao tacInspYearBatchAreaDao; @Autowired private TacInspYearBatchDao yearBatchDao; @Autowired private BisInspAllRlationPersDao rlationPersDao; @Autowired private OlBisInspOrgService olBisInspOrgService; public TacInspYearBatchAreaServiceImpl(TacInspYearBatchAreaDao tacInspYearBatchAreaDao) { super(tacInspYearBatchAreaDao); this.tacInspYearBatchAreaDao = tacInspYearBatchAreaDao; } @Override public int deleteYearBatchArearByGroupId(String groupId) { TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam(); areaParam.setGroupId(groupId); tacInspYearBatchAreaDao.deleteBy(areaParam); return 0; } @Override public BisInspAllNode getObjTreeAreaList(TacInspYearBatchAreaParam param) { if (StringUtils.isNotBlank(param.getPersId())) { if ("1".equals(rlationPersDao.get(param.getPersId()).getPersType())) { param.setPersId(""); } } List list = tacInspYearBatchAreaDao.getObjTreeAreaList(param); if (list.size() > 0) { BisInspAllNode allNode = new BisInspAllNode(); Map yearMap = getMap(list); allNode.setChildren(new ArrayList<>(yearMap.values())); return allNode; } return new BisInspAllNode(); } Map getMap(List list) { Map yearMap = new HashedMap(); //获取年份 list.forEach(obj -> { if (!yearMap.keySet().contains(String.valueOf(obj.getYear()) + "年度")) { BisInspAllNode node = new BisInspAllNode(); node.setId(obj.getYear().toString() + "年度"); node.setPnm(String.valueOf(obj.getYear()) + "年度"); node.setPid("root"); yearMap.put(String.valueOf(obj.getYear()) + "年度", node); } }); //根据年份 设置批次 for (BisInspAllNode bisInspAllNode : yearMap.values()) { String year = bisInspAllNode.getId(); List batchBisInspAllNodes = getBatch(year, list); //循环批次获取组 for (BisInspAllNode batchBisInspAllNode : batchBisInspAllNodes) { String batch = batchBisInspAllNode.getId(); List groupBisInspAllNodes = getGroup(year, batch, list); //循环组获取行政区代码 for (BisInspAllNode groupBisInspAllNode : groupBisInspAllNodes) { String groupId = groupBisInspAllNode.getId(); List groupAddvcdBisInspAllNodes = getGroupAddvcd(year, batch, groupId, list); groupBisInspAllNode.setChildren(groupAddvcdBisInspAllNodes); } batchBisInspAllNode.setChildren(groupBisInspAllNodes); } bisInspAllNode.setChildren(batchBisInspAllNodes); } return yearMap; } //根据年份获取批次 public List getBatch(String year, List list) { List batchBisInspAllNodes = new ArrayList<>(); for (TacInspYearBatchArea tacInspYearBatchArea : list) { String yearTemp = tacInspYearBatchArea.getYear().toString() + "年度"; if (yearTemp.equals(year)) { BisInspAllNode bisInspAllNode = new BisInspAllNode(); bisInspAllNode.setPid(year); bisInspAllNode.setId(year + "-" + tacInspYearBatchArea.getBatch().toString()); bisInspAllNode.setPnm(year + "第" + tacInspYearBatchArea.getBatch().toString() + "批次"); if (!batchBisInspAllNodes.contains(bisInspAllNode)) { batchBisInspAllNodes.add(bisInspAllNode); } } } return batchBisInspAllNodes; } //根据批次获取组 public List getGroup(String year, String batch, List list) { List groupBisInspAllNodes = new ArrayList<>(); for (TacInspYearBatchArea tacInspYearBatchArea : list) { String yearTemp = tacInspYearBatchArea.getYear().toString() + "年度"; String batchTemp = yearTemp + "-" + tacInspYearBatchArea.getBatch().toString(); if (yearTemp.equals(year) && batchTemp.equals(batch)) { BisInspAllNode bisInspAllNode = new BisInspAllNode(); bisInspAllNode.setPid(batchTemp); bisInspAllNode.setId(tacInspYearBatchArea.getGroupId()); bisInspAllNode.setPnm("第" + (tacInspYearBatchArea.getGroupNm() == null ? "" : tacInspYearBatchArea.getGroupNm().toString()) + "组"); if (!groupBisInspAllNodes.contains(bisInspAllNode)) { groupBisInspAllNodes.add(bisInspAllNode); } } } return groupBisInspAllNodes; } //根据组获取 行政区 public List getGroupAddvcd(String year, String batch, String groupId, List list) { List groupAddvcdBisInspAllNodes = new ArrayList<>(); for (TacInspYearBatchArea tacInspYearBatchArea : list) { String yearTemp = tacInspYearBatchArea.getYear().toString() + "年度"; String batchTemp = yearTemp + "-" + tacInspYearBatchArea.getBatch().toString(); String groupTemp = tacInspYearBatchArea.getGroupId().toString(); if (yearTemp.equals(year) && batchTemp.equals(batch) && groupTemp.equals(groupId)) { BisInspAllNode bisInspAllNode = new BisInspAllNode(); bisInspAllNode.setPid(groupId); bisInspAllNode.setId(tacInspYearBatchArea.getAdCode().toString()); bisInspAllNode.setPnm(tacInspYearBatchArea.getAdName().toString()); if (!groupAddvcdBisInspAllNodes.contains(bisInspAllNode)) { groupAddvcdBisInspAllNodes.add(bisInspAllNode); } } } return groupAddvcdBisInspAllNodes; } @Override public List getAreaListById(TacInspYearBatchAreaParam tacInspYearBatchAreaParam) { List list = tacInspYearBatchAreaDao.getAreaListById(tacInspYearBatchAreaParam); return list; } @Override public List> areasListByBatch(TacInspYearBatchAreaParam tacInspYearBatchAreaParam) { //查询年度下已创建批次以及对应地市; List> list = tacInspYearBatchAreaDao.areasListByBatch(tacInspYearBatchAreaParam); return list; } @Override public TacInspYearBatchAreaDto getAreaListByBatchId(TacInspYearBatchAreaParam tacInspYearBatchAreaParam) { TacInspYearBatchAreaDto dto = new TacInspYearBatchAreaDto(); if (StringUtils.isBlank(tacInspYearBatchAreaParam.getYearBatchId())) { return dto; } TacInspYearBatch yearBatch = yearBatchDao.get(tacInspYearBatchAreaParam.getYearBatchId()); dto.setYearBatchId(tacInspYearBatchAreaParam.getYearBatchId()); dto.setYear(yearBatch.getYear()); dto.setBatch(yearBatch.getBatch()); List list = tacInspYearBatchAreaDao.findList(tacInspYearBatchAreaParam); if (list.size() > 0) { Map areaList = new HashedMap(); list.forEach(tacInspYearBatchArea -> { if (!areaList.keySet().contains(tacInspYearBatchArea.getGroupId())) { areaList.put(tacInspYearBatchArea.getGroupId(), tacInspYearBatchArea); } else { TacInspYearBatchArea area = areaList.get(tacInspYearBatchArea.getGroupId()); area.setId(area.getId()+","+tacInspYearBatchArea.getId()); area.setAdCode(area.getAdCode() + ","+ tacInspYearBatchArea.getAdCode()); area.setAdName(area.getAdName() + "," + tacInspYearBatchArea.getAdName()); } }); dto.setAreaList(new ArrayList<>(areaList.values())); } return dto; } @Override public PageInfo listByList(Map paramMap) { PageHelper.startPage(MapUtils.getIntValue(paramMap, "pageNum"), MapUtils.getIntValue(paramMap, "pageSize")); String province = olBisInspOrgService.getRlProvince(paramMap.get("orgId")); paramMap.put("province",province); List groupList = tacInspYearBatchAreaDao.listByMap(paramMap); return new PageInfo<>(groupList); } }