50fce6434b7f0c2ca6fafb7cb9accee41a6c046f.svn-base 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package cn.com.goldenwater.dcproj.service.impl.tac;
  2. import cn.com.goldenwater.dcproj.dao.BisInspAllRlationPersDao;
  3. import cn.com.goldenwater.dcproj.dao.TacInspYearBatchAreaDao;
  4. import cn.com.goldenwater.dcproj.dao.TacInspYearBatchDao;
  5. import cn.com.goldenwater.dcproj.dto.BisInspAllDto;
  6. import cn.com.goldenwater.dcproj.dto.TacInspYearBatchAreaDto;
  7. import cn.com.goldenwater.dcproj.model.BisInspAllNode;
  8. import cn.com.goldenwater.dcproj.model.TacInspYearBatch;
  9. import cn.com.goldenwater.dcproj.model.TacInspYearBatchArea;
  10. import cn.com.goldenwater.dcproj.param.TacInspYearBatchAreaParam;
  11. import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
  12. import cn.com.goldenwater.dcproj.service.TacInspYearBatchAreaService;
  13. import cn.com.goldenwater.core.service.AbstractCrudService;
  14. import com.github.pagehelper.PageHelper;
  15. import com.github.pagehelper.PageInfo;
  16. import org.apache.commons.collections.MapUtils;
  17. import org.apache.commons.collections.map.HashedMap;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Service;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import java.util.ArrayList;
  23. import java.util.LinkedHashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. /**
  27. * @author lune
  28. * @date 2019-9-6
  29. */
  30. @Service
  31. @Transactional
  32. public class TacInspYearBatchAreaServiceImpl extends AbstractCrudService<TacInspYearBatchArea, TacInspYearBatchAreaParam> implements TacInspYearBatchAreaService {
  33. @Autowired
  34. private TacInspYearBatchAreaDao tacInspYearBatchAreaDao;
  35. @Autowired
  36. private TacInspYearBatchDao yearBatchDao;
  37. @Autowired
  38. private BisInspAllRlationPersDao rlationPersDao;
  39. @Autowired
  40. private OlBisInspOrgService olBisInspOrgService;
  41. public TacInspYearBatchAreaServiceImpl(TacInspYearBatchAreaDao tacInspYearBatchAreaDao) {
  42. super(tacInspYearBatchAreaDao);
  43. this.tacInspYearBatchAreaDao = tacInspYearBatchAreaDao;
  44. }
  45. @Override
  46. public int deleteYearBatchArearByGroupId(String groupId) {
  47. TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
  48. areaParam.setGroupId(groupId);
  49. tacInspYearBatchAreaDao.deleteBy(areaParam);
  50. return 0;
  51. }
  52. @Override
  53. public BisInspAllNode getObjTreeAreaList(TacInspYearBatchAreaParam param) {
  54. if (StringUtils.isNotBlank(param.getPersId())) {
  55. if ("1".equals(rlationPersDao.get(param.getPersId()).getPersType())) {
  56. param.setPersId("");
  57. }
  58. }
  59. List<TacInspYearBatchArea> list = tacInspYearBatchAreaDao.getObjTreeAreaList(param);
  60. if (list.size() > 0) {
  61. BisInspAllNode allNode = new BisInspAllNode();
  62. Map<String, BisInspAllNode> yearMap = getMap(list);
  63. allNode.setChildren(new ArrayList<>(yearMap.values()));
  64. return allNode;
  65. }
  66. return new BisInspAllNode();
  67. }
  68. Map<String, BisInspAllNode> getMap(List<TacInspYearBatchArea> list) {
  69. Map<String, BisInspAllNode> yearMap = new HashedMap();
  70. //获取年份
  71. list.forEach(obj -> {
  72. if (!yearMap.keySet().contains(String.valueOf(obj.getYear()) + "年度")) {
  73. BisInspAllNode node = new BisInspAllNode();
  74. node.setId(obj.getYear().toString() + "年度");
  75. node.setPnm(String.valueOf(obj.getYear()) + "年度");
  76. node.setPid("root");
  77. yearMap.put(String.valueOf(obj.getYear()) + "年度", node);
  78. }
  79. });
  80. //根据年份 设置批次
  81. for (BisInspAllNode bisInspAllNode : yearMap.values()) {
  82. String year = bisInspAllNode.getId();
  83. List<BisInspAllNode> batchBisInspAllNodes = getBatch(year, list);
  84. //循环批次获取组
  85. for (BisInspAllNode batchBisInspAllNode : batchBisInspAllNodes) {
  86. String batch = batchBisInspAllNode.getId();
  87. List<BisInspAllNode> groupBisInspAllNodes = getGroup(year, batch, list);
  88. //循环组获取行政区代码
  89. for (BisInspAllNode groupBisInspAllNode : groupBisInspAllNodes) {
  90. String groupId = groupBisInspAllNode.getId();
  91. List<BisInspAllNode> groupAddvcdBisInspAllNodes = getGroupAddvcd(year, batch, groupId, list);
  92. groupBisInspAllNode.setChildren(groupAddvcdBisInspAllNodes);
  93. }
  94. batchBisInspAllNode.setChildren(groupBisInspAllNodes);
  95. }
  96. bisInspAllNode.setChildren(batchBisInspAllNodes);
  97. }
  98. return yearMap;
  99. }
  100. //根据年份获取批次
  101. public List<BisInspAllNode> getBatch(String year, List<TacInspYearBatchArea> list) {
  102. List<BisInspAllNode> batchBisInspAllNodes = new ArrayList<>();
  103. for (TacInspYearBatchArea tacInspYearBatchArea : list) {
  104. String yearTemp = tacInspYearBatchArea.getYear().toString() + "年度";
  105. if (yearTemp.equals(year)) {
  106. BisInspAllNode bisInspAllNode = new BisInspAllNode();
  107. bisInspAllNode.setPid(year);
  108. bisInspAllNode.setId(year + "-" + tacInspYearBatchArea.getBatch().toString());
  109. bisInspAllNode.setPnm(year + "第" + tacInspYearBatchArea.getBatch().toString() + "批次");
  110. if (!batchBisInspAllNodes.contains(bisInspAllNode)) {
  111. batchBisInspAllNodes.add(bisInspAllNode);
  112. }
  113. }
  114. }
  115. return batchBisInspAllNodes;
  116. }
  117. //根据批次获取组
  118. public List<BisInspAllNode> getGroup(String year, String batch, List<TacInspYearBatchArea> list) {
  119. List<BisInspAllNode> groupBisInspAllNodes = new ArrayList<>();
  120. for (TacInspYearBatchArea tacInspYearBatchArea : list) {
  121. String yearTemp = tacInspYearBatchArea.getYear().toString() + "年度";
  122. String batchTemp = yearTemp + "-" + tacInspYearBatchArea.getBatch().toString();
  123. if (yearTemp.equals(year) && batchTemp.equals(batch)) {
  124. BisInspAllNode bisInspAllNode = new BisInspAllNode();
  125. bisInspAllNode.setPid(batchTemp);
  126. bisInspAllNode.setId(tacInspYearBatchArea.getGroupId());
  127. bisInspAllNode.setPnm("第" + (tacInspYearBatchArea.getGroupNm() == null ? "" : tacInspYearBatchArea.getGroupNm().toString()) + "组");
  128. if (!groupBisInspAllNodes.contains(bisInspAllNode)) {
  129. groupBisInspAllNodes.add(bisInspAllNode);
  130. }
  131. }
  132. }
  133. return groupBisInspAllNodes;
  134. }
  135. //根据组获取 行政区
  136. public List<BisInspAllNode> getGroupAddvcd(String year, String batch, String groupId, List<TacInspYearBatchArea> list) {
  137. List<BisInspAllNode> groupAddvcdBisInspAllNodes = new ArrayList<>();
  138. for (TacInspYearBatchArea tacInspYearBatchArea : list) {
  139. String yearTemp = tacInspYearBatchArea.getYear().toString() + "年度";
  140. String batchTemp = yearTemp + "-" + tacInspYearBatchArea.getBatch().toString();
  141. String groupTemp = tacInspYearBatchArea.getGroupId().toString();
  142. if (yearTemp.equals(year) && batchTemp.equals(batch) && groupTemp.equals(groupId)) {
  143. BisInspAllNode bisInspAllNode = new BisInspAllNode();
  144. bisInspAllNode.setPid(groupId);
  145. bisInspAllNode.setId(tacInspYearBatchArea.getAdCode().toString());
  146. bisInspAllNode.setPnm(tacInspYearBatchArea.getAdName().toString());
  147. if (!groupAddvcdBisInspAllNodes.contains(bisInspAllNode)) {
  148. groupAddvcdBisInspAllNodes.add(bisInspAllNode);
  149. }
  150. }
  151. }
  152. return groupAddvcdBisInspAllNodes;
  153. }
  154. @Override
  155. public List<TacInspYearBatchArea> getAreaListById(TacInspYearBatchAreaParam tacInspYearBatchAreaParam) {
  156. List<TacInspYearBatchArea> list = tacInspYearBatchAreaDao.getAreaListById(tacInspYearBatchAreaParam);
  157. return list;
  158. }
  159. @Override
  160. public List<Map<String, String>> areasListByBatch(TacInspYearBatchAreaParam tacInspYearBatchAreaParam) {
  161. //查询年度下已创建批次以及对应地市;
  162. List<Map<String, String>> list = tacInspYearBatchAreaDao.areasListByBatch(tacInspYearBatchAreaParam);
  163. return list;
  164. }
  165. @Override
  166. public TacInspYearBatchAreaDto getAreaListByBatchId(TacInspYearBatchAreaParam tacInspYearBatchAreaParam) {
  167. TacInspYearBatchAreaDto dto = new TacInspYearBatchAreaDto();
  168. if (StringUtils.isBlank(tacInspYearBatchAreaParam.getYearBatchId())) {
  169. return dto;
  170. }
  171. TacInspYearBatch yearBatch = yearBatchDao.get(tacInspYearBatchAreaParam.getYearBatchId());
  172. dto.setYearBatchId(tacInspYearBatchAreaParam.getYearBatchId());
  173. dto.setYear(yearBatch.getYear());
  174. dto.setBatch(yearBatch.getBatch());
  175. List<TacInspYearBatchArea> list = tacInspYearBatchAreaDao.findList(tacInspYearBatchAreaParam);
  176. if (list.size() > 0) {
  177. Map<String,TacInspYearBatchArea> areaList = new HashedMap();
  178. list.forEach(tacInspYearBatchArea -> {
  179. if (!areaList.keySet().contains(tacInspYearBatchArea.getGroupId())) {
  180. areaList.put(tacInspYearBatchArea.getGroupId(), tacInspYearBatchArea);
  181. } else {
  182. TacInspYearBatchArea area = areaList.get(tacInspYearBatchArea.getGroupId());
  183. area.setId(area.getId()+","+tacInspYearBatchArea.getId());
  184. area.setAdCode(area.getAdCode() + ","+ tacInspYearBatchArea.getAdCode());
  185. area.setAdName(area.getAdName() + "," + tacInspYearBatchArea.getAdName());
  186. }
  187. });
  188. dto.setAreaList(new ArrayList<>(areaList.values()));
  189. }
  190. return dto;
  191. }
  192. @Override
  193. public PageInfo<TacInspYearBatchArea> listByList(Map<String, String> paramMap) {
  194. PageHelper.startPage(MapUtils.getIntValue(paramMap, "pageNum"), MapUtils.getIntValue(paramMap, "pageSize"));
  195. String province = olBisInspOrgService.getRlProvince(paramMap.get("orgId"));
  196. paramMap.put("province",province);
  197. List<TacInspYearBatchArea> groupList = tacInspYearBatchAreaDao.listByMap(paramMap);
  198. return new PageInfo<>(groupList);
  199. }
  200. }