| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- 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<TacInspYearBatchArea, TacInspYearBatchAreaParam> 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<TacInspYearBatchArea> list = tacInspYearBatchAreaDao.getObjTreeAreaList(param);
- if (list.size() > 0) {
- BisInspAllNode allNode = new BisInspAllNode();
- Map<String, BisInspAllNode> yearMap = getMap(list);
- allNode.setChildren(new ArrayList<>(yearMap.values()));
- return allNode;
- }
- return new BisInspAllNode();
- }
- Map<String, BisInspAllNode> getMap(List<TacInspYearBatchArea> list) {
- Map<String, BisInspAllNode> 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<BisInspAllNode> batchBisInspAllNodes = getBatch(year, list);
- //循环批次获取组
- for (BisInspAllNode batchBisInspAllNode : batchBisInspAllNodes) {
- String batch = batchBisInspAllNode.getId();
- List<BisInspAllNode> groupBisInspAllNodes = getGroup(year, batch, list);
- //循环组获取行政区代码
- for (BisInspAllNode groupBisInspAllNode : groupBisInspAllNodes) {
- String groupId = groupBisInspAllNode.getId();
- List<BisInspAllNode> groupAddvcdBisInspAllNodes = getGroupAddvcd(year, batch, groupId, list);
- groupBisInspAllNode.setChildren(groupAddvcdBisInspAllNodes);
- }
- batchBisInspAllNode.setChildren(groupBisInspAllNodes);
- }
- bisInspAllNode.setChildren(batchBisInspAllNodes);
- }
- return yearMap;
- }
- //根据年份获取批次
- public List<BisInspAllNode> getBatch(String year, List<TacInspYearBatchArea> list) {
- List<BisInspAllNode> 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<BisInspAllNode> getGroup(String year, String batch, List<TacInspYearBatchArea> list) {
- List<BisInspAllNode> 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<BisInspAllNode> getGroupAddvcd(String year, String batch, String groupId, List<TacInspYearBatchArea> list) {
- List<BisInspAllNode> 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<TacInspYearBatchArea> getAreaListById(TacInspYearBatchAreaParam tacInspYearBatchAreaParam) {
- List<TacInspYearBatchArea> list = tacInspYearBatchAreaDao.getAreaListById(tacInspYearBatchAreaParam);
- return list;
- }
- @Override
- public List<Map<String, String>> areasListByBatch(TacInspYearBatchAreaParam tacInspYearBatchAreaParam) {
- //查询年度下已创建批次以及对应地市;
- List<Map<String, String>> 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<TacInspYearBatchArea> list = tacInspYearBatchAreaDao.findList(tacInspYearBatchAreaParam);
- if (list.size() > 0) {
- Map<String,TacInspYearBatchArea> 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<TacInspYearBatchArea> listByList(Map<String, String> paramMap) {
- PageHelper.startPage(MapUtils.getIntValue(paramMap, "pageNum"), MapUtils.getIntValue(paramMap, "pageSize"));
- String province = olBisInspOrgService.getRlProvince(paramMap.get("orgId"));
- paramMap.put("province",province);
- List<TacInspYearBatchArea> groupList = tacInspYearBatchAreaDao.listByMap(paramMap);
- return new PageInfo<>(groupList);
- }
- }
|