ce0790b14838eefc62ec77550258aa3dc329cb04.svn-base 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. package cn.com.goldenwater.dcproj.service.impl.tac;
  2. import cn.com.goldenwater.core.service.AbstractCrudService;
  3. import cn.com.goldenwater.dcproj.dao.*;
  4. import cn.com.goldenwater.dcproj.dto.TacCountDto;
  5. import cn.com.goldenwater.dcproj.model.*;
  6. import cn.com.goldenwater.dcproj.param.*;
  7. import cn.com.goldenwater.dcproj.service.TacInspPersAreaPrisService;
  8. import cn.com.goldenwater.dcproj.utils.AdLevelUtil;
  9. import cn.com.goldenwater.dcproj.utils.InspUtils;
  10. import cn.com.goldenwater.id.util.UuidUtil;
  11. import org.apache.commons.collections.map.HashedMap;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import java.util.ArrayList;
  17. import java.util.Date;
  18. import java.util.List;
  19. import java.util.Map;
  20. /**
  21. * @author lune
  22. * @date 2019-9-6
  23. */
  24. @Service
  25. @Transactional
  26. public class TacInspPersAreaPrisServiceImpl extends AbstractCrudService<TacInspPersAreaPris, TacInspPersAreaPrisParam> implements TacInspPersAreaPrisService {
  27. @Autowired
  28. private TacInspPersAreaPrisDao tacInspPersAreaPrisDao;
  29. @Autowired
  30. private TacWorkerBDao tacWorkerBDao;
  31. @Autowired
  32. private TacTacInspPersPrisLtsDao ltsDao;
  33. @Autowired
  34. private TacInspYearBatchDao yearBatchDao;
  35. @Autowired
  36. private TacInspYearBatchAreaDao areaDao;
  37. @Autowired
  38. private TacInspYearBatchGroupDao tacInspYearBatchGroupDao;
  39. @Autowired
  40. private TacInspYearBatchGroupPersDao groupPersDao;
  41. @Autowired
  42. private AttAdXBaseDao attAdXBaseDao;
  43. public TacInspPersAreaPrisServiceImpl(TacInspPersAreaPrisDao tacInspPersAreaPrisDao) {
  44. super(tacInspPersAreaPrisDao);
  45. this.tacInspPersAreaPrisDao = tacInspPersAreaPrisDao;
  46. }
  47. @Override
  48. public TacInspPersAreaPris getAreaPris(String id, String yearBatchId, String province) {
  49. TacWorkerBParam bParam = new TacWorkerBParam();
  50. bParam.setYearBatchId(yearBatchId);
  51. bParam.setGroupType(InspUtils.setOrgIds("1"));
  52. //获取库表
  53. bParam.setProvince(province);
  54. List<TacCountDto> comList = tacWorkerBDao.countByRole(bParam);
  55. bParam.setGroupType(InspUtils.setOrgIds("7"));
  56. List<TacCountDto> proList = tacWorkerBDao.countByRole(bParam);
  57. bParam.setGroupType(InspUtils.setOrgIds("4"));
  58. List<TacCountDto> goldList = tacWorkerBDao.countByRole(bParam);
  59. bParam.setGroupType(InspUtils.setOrgIds("5"));
  60. List<TacCountDto> redList = tacWorkerBDao.countByRole(bParam);
  61. if (StringUtils.isBlank(id) || "null".equals(id)) {
  62. TacInspPersAreaPris pris = new TacInspPersAreaPris();
  63. pris.setCommList(comList);
  64. pris.setProList(proList);
  65. pris.setGoldList(goldList);
  66. pris.setRedList(redList);
  67. return pris;
  68. }
  69. //获取规则id
  70. TacInspPersAreaPris pris = tacInspPersAreaPrisDao.get(id);
  71. TacTacInspPersPrisLtsParam ltsParam = new TacTacInspPersPrisLtsParam();
  72. if ("1".equals(String.valueOf(pris.getIsNew()))) {
  73. bParam.setNewSize(pris.getNewSize());
  74. List<TacCountDto> newList = tacWorkerBDao.countByRoleNew(bParam);
  75. getSelectCount(newList, ltsParam, "8");
  76. pris.setNewList(newList);
  77. }
  78. ltsParam.setPersPrisId(id);
  79. getSelectCount(comList, ltsParam, "1");
  80. getSelectCount(proList, ltsParam, "7");
  81. getSelectCount(goldList, ltsParam, "4");
  82. getSelectCount(redList, ltsParam, "5");
  83. pris.setCommList(comList);
  84. pris.setProList(proList);
  85. pris.setGoldList(goldList);
  86. pris.setRedList(redList);
  87. return pris;
  88. }
  89. private void getSelectCount(List<TacCountDto> list, TacTacInspPersPrisLtsParam ltsParam, String type) {
  90. ltsParam.setTenetType(type);
  91. TacTacInspPersPrisLts lts = ltsDao.getBy(ltsParam);
  92. if (lts == null) {
  93. return;
  94. }
  95. for (TacCountDto tacCountDto : list) {
  96. if ("20".equals(tacCountDto.getCode())) {
  97. tacCountDto.setSelectCount(String.valueOf(lts.getSpecialSize() == null ? 0 : lts.getSpecialSize()));
  98. }
  99. if ("19".equals(tacCountDto.getCode())) {
  100. tacCountDto.setSelectCount(String.valueOf(lts.getAssistantSize() == null ? 0 : lts.getAssistantSize()));
  101. }
  102. if ("11".equals(tacCountDto.getCode())) {
  103. tacCountDto.setSelectCount(String.valueOf(lts.getEarlyTisSize() == null ? 0 : lts.getEarlyTisSize()));
  104. }
  105. if ("12".equals(tacCountDto.getCode())) {
  106. tacCountDto.setSelectCount(String.valueOf(lts.getDevemanageTisSize() == null ? 0 : lts.getDevemanageTisSize()));
  107. }
  108. if ("13".equals(tacCountDto.getCode())) {
  109. tacCountDto.setSelectCount(String.valueOf(lts.getPlanTisSize() == null ? 0 : lts.getPlanTisSize()));
  110. }
  111. if ("14".equals(tacCountDto.getCode())) {
  112. tacCountDto.setSelectCount(String.valueOf(lts.getFinanceTisSize() == null ? 0 : lts.getFinanceTisSize()));
  113. }
  114. if ("15".equals(tacCountDto.getCode())) {
  115. tacCountDto.setSelectCount(String.valueOf(lts.getQualityTisSize() == null ? 0 : lts.getQualityTisSize()));
  116. }
  117. if ("16".equals(tacCountDto.getCode())) {
  118. tacCountDto.setSelectCount(String.valueOf(lts.getSafetyTisSize() == null ? 0 : lts.getSafetyTisSize()));
  119. }
  120. }
  121. }
  122. private TacTacInspPersPrisLts setLtsCount(List<TacCountDto> list, TacTacInspPersPrisLts lts, TacInspPersAreaPris tacInspPersAreaPris, String type) {
  123. if (lts == null) {
  124. lts = new TacTacInspPersPrisLts();
  125. lts.setId(UuidUtil.uuid());
  126. lts.setInTm(new Date());
  127. lts.setUpTm(new Date());
  128. lts.setPersPrisId(tacInspPersAreaPris.getId());
  129. lts.setPersId(tacInspPersAreaPris.getPersId());
  130. lts.setTenetType(type);
  131. }
  132. Long total = new Long(0);
  133. for (TacCountDto tacCountDto : list) {
  134. if (StringUtils.isNotBlank(tacCountDto.getSelectCount()) && !"null".equals(tacCountDto.getSelectCount())) {
  135. total += Long.valueOf(tacCountDto.getSelectCount());
  136. if ("20".equals(tacCountDto.getCode())) {
  137. lts.setSpecialSize(Long.valueOf(tacCountDto.getSelectCount()));
  138. }
  139. if ("19".equals(tacCountDto.getCode())) {
  140. lts.setAssistantSize(Long.valueOf(tacCountDto.getSelectCount()));
  141. }
  142. if ("11".equals(tacCountDto.getCode())) {
  143. lts.setEarlyTisSize(Long.valueOf(tacCountDto.getSelectCount()));
  144. }
  145. if ("12".equals(tacCountDto.getCode())) {
  146. lts.setDevemanageTisSize(Long.valueOf(tacCountDto.getSelectCount()));
  147. }
  148. if ("13".equals(tacCountDto.getCode())) {
  149. lts.setPlanTisSize(Long.valueOf(tacCountDto.getSelectCount()));
  150. }
  151. if ("14".equals(tacCountDto.getCode())) {
  152. lts.setFinanceTisSize(Long.valueOf(tacCountDto.getSelectCount()));
  153. }
  154. if ("15".equals(tacCountDto.getCode())) {
  155. lts.setQualityTisSize(Long.valueOf(tacCountDto.getSelectCount()));
  156. }
  157. if ("16".equals(tacCountDto.getCode())) {
  158. lts.setSafetyTisSize(Long.valueOf(tacCountDto.getSelectCount()));
  159. }
  160. }
  161. }
  162. lts.setTotalSize(total);
  163. return lts;
  164. }
  165. @Override
  166. public int insertPris(TacInspPersAreaPris tacInspPersAreaPris) {
  167. TacInspYearBatch batch = yearBatchDao.get(tacInspPersAreaPris.getYearBatchId());
  168. tacInspPersAreaPris.setYear(batch.getYear());
  169. tacInspPersAreaPris.setBatch(batch.getBatch());
  170. this.tacInspPersAreaPrisDao.insert(tacInspPersAreaPris);
  171. if (tacInspPersAreaPris.getCommList() != null && tacInspPersAreaPris.getCommList().size() > 0) {
  172. TacTacInspPersPrisLts lts = setLtsCount(tacInspPersAreaPris.getCommList(), null, tacInspPersAreaPris, "1");
  173. ltsDao.insert(lts);
  174. }
  175. if (tacInspPersAreaPris.getProList() != null && tacInspPersAreaPris.getProList().size() > 0) {
  176. TacTacInspPersPrisLts lts = setLtsCount(tacInspPersAreaPris.getProList(), null, tacInspPersAreaPris, "7");
  177. ltsDao.insert(lts);
  178. }
  179. if ("1".equals(tacInspPersAreaPris.getIsPick())) {
  180. if (tacInspPersAreaPris.getGoldList() != null && tacInspPersAreaPris.getGoldList().size() > 0) {
  181. TacTacInspPersPrisLts lts = setLtsCount(tacInspPersAreaPris.getGoldList(), null, tacInspPersAreaPris, "4");
  182. ltsDao.insert(lts);
  183. }
  184. if (tacInspPersAreaPris.getRedList() != null && tacInspPersAreaPris.getRedList().size() > 0) {
  185. TacTacInspPersPrisLts lts = setLtsCount(tacInspPersAreaPris.getRedList(), null, tacInspPersAreaPris, "5");
  186. ltsDao.insert(lts);
  187. }
  188. }
  189. if ("1".equals(tacInspPersAreaPris.getIsNew()) && tacInspPersAreaPris.getNewList().size() > 0) {
  190. TacTacInspPersPrisLts lts = setLtsCount(tacInspPersAreaPris.getNewList(), null, tacInspPersAreaPris, "8");
  191. ltsDao.insert(lts);
  192. }
  193. return 0;
  194. }
  195. @Override
  196. public int updatePris(TacInspPersAreaPris tacInspPersAreaPris) {
  197. TacInspYearBatch batch = yearBatchDao.get(tacInspPersAreaPris.getYearBatchId());
  198. tacInspPersAreaPris.setYear(batch.getYear());
  199. tacInspPersAreaPris.setBatch(batch.getBatch());
  200. this.tacInspPersAreaPrisDao.update(tacInspPersAreaPris);
  201. TacTacInspPersPrisLtsParam ltsParam = new TacTacInspPersPrisLtsParam();
  202. ltsParam.setPersPrisId(tacInspPersAreaPris.getId());
  203. if (tacInspPersAreaPris.getCommList() != null && tacInspPersAreaPris.getCommList().size() > 0) {
  204. ltsParam.setTenetType("1");
  205. TacTacInspPersPrisLts lts = ltsDao.getBy(ltsParam);
  206. if (lts == null) {
  207. lts = setLtsCount(tacInspPersAreaPris.getCommList(), null, tacInspPersAreaPris, "1");
  208. ltsDao.insert(lts);
  209. } else {
  210. setLtsCount(tacInspPersAreaPris.getCommList(), lts, tacInspPersAreaPris, "1");
  211. ltsDao.update(lts);
  212. }
  213. }
  214. if (tacInspPersAreaPris.getProList() != null && tacInspPersAreaPris.getProList().size() > 0) {
  215. ltsParam.setTenetType("7");
  216. TacTacInspPersPrisLts lts = ltsDao.getBy(ltsParam);
  217. if (lts == null) {
  218. lts = setLtsCount(tacInspPersAreaPris.getProList(), null, tacInspPersAreaPris, "7");
  219. ltsDao.insert(lts);
  220. } else {
  221. setLtsCount(tacInspPersAreaPris.getProList(), lts, tacInspPersAreaPris, "7");
  222. ltsDao.update(lts);
  223. }
  224. }
  225. if ("1".equals(tacInspPersAreaPris.getIsPick())) {
  226. if (tacInspPersAreaPris.getGoldList() != null && tacInspPersAreaPris.getGoldList().size() > 0) {
  227. ltsParam.setTenetType("4");
  228. TacTacInspPersPrisLts lts = ltsDao.getBy(ltsParam);
  229. if (lts == null) {
  230. lts = setLtsCount(tacInspPersAreaPris.getGoldList(), null, tacInspPersAreaPris, "4");
  231. ltsDao.insert(lts);
  232. } else {
  233. setLtsCount(tacInspPersAreaPris.getGoldList(), lts, tacInspPersAreaPris, "4");
  234. ltsDao.update(lts);
  235. }
  236. }
  237. if (tacInspPersAreaPris.getRedList() != null && tacInspPersAreaPris.getRedList().size() > 0) {
  238. ltsParam.setTenetType("5");
  239. TacTacInspPersPrisLts lts = ltsDao.getBy(ltsParam);
  240. if (lts == null) {
  241. lts = setLtsCount(tacInspPersAreaPris.getRedList(), null, tacInspPersAreaPris, "5");
  242. ltsDao.insert(lts);
  243. } else {
  244. setLtsCount(tacInspPersAreaPris.getRedList(), lts, tacInspPersAreaPris, "5");
  245. ltsDao.update(lts);
  246. }
  247. }
  248. } else {
  249. ltsParam.setTenetType("4");
  250. ltsDao.deleteBy(ltsParam);
  251. ltsParam.setTenetType("5");
  252. ltsDao.deleteBy(ltsParam);
  253. }
  254. if ("1".equals(tacInspPersAreaPris.getIsNew()) && tacInspPersAreaPris.getNewList().size() > 0) {
  255. ltsParam.setTenetType("8");
  256. TacTacInspPersPrisLts lts = ltsDao.getBy(ltsParam);
  257. if (lts == null) {
  258. lts = setLtsCount(tacInspPersAreaPris.getNewList(), null, tacInspPersAreaPris, "8");
  259. ltsDao.insert(lts);
  260. } else {
  261. setLtsCount(tacInspPersAreaPris.getNewList(), lts, tacInspPersAreaPris, "8");
  262. ltsDao.update(lts);
  263. }
  264. } else {
  265. ltsParam.setTenetType("8");
  266. ltsDao.deleteBy(ltsParam);
  267. }
  268. return 0;
  269. }
  270. @Override
  271. public TacInspPersAreaPris getPersAreaPris(String id, String province) {
  272. TacInspPersAreaPris areaPris = this.tacInspPersAreaPrisDao.get(id);
  273. if (areaPris == null) {
  274. return null;
  275. }
  276. TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
  277. areaParam.setYearBatchId(areaPris.getYearBatchId());
  278. areaParam.setProvince(province);
  279. List<TacInspYearBatchArea> list = areaDao.findList(areaParam);
  280. Map<String, TacInspYearBatchArea> areaList = new HashedMap();
  281. list.forEach(tacInspYearBatchArea -> {
  282. if (!areaList.keySet().contains(tacInspYearBatchArea.getGroupId())) {
  283. areaList.put(tacInspYearBatchArea.getGroupId(), tacInspYearBatchArea);
  284. } else {
  285. TacInspYearBatchArea area = areaList.get(tacInspYearBatchArea.getGroupId());
  286. area.setId(area.getId() + "," + tacInspYearBatchArea.getId());
  287. area.setAdCode(area.getAdCode() + "," + tacInspYearBatchArea.getAdCode());
  288. area.setAdName(area.getAdName() + "," + tacInspYearBatchArea.getAdName());
  289. }
  290. });
  291. areaPris.setAreaList(new ArrayList<>(areaList.values()));
  292. return areaPris;
  293. }
  294. @Override
  295. public int updatePersAreaPris(TacInspPersAreaPris areaPris) {
  296. if (StringUtils.isNotBlank(areaPris.getId())) {
  297. tacInspPersAreaPrisDao.update(areaPris);
  298. }
  299. List<TacInspYearBatchArea> list = new ArrayList<>();
  300. if (areaPris.getAreaList() != null) {
  301. list = areaPris.getAreaList();
  302. }
  303. // Map<String,TacInspYearBatchArea> map = list.stream().collect(Collectors.toMap(TacInspYearBatchArea::getAdName, Function.identity()));
  304. Map<String, List<TacInspYearBatchArea>> map = new HashedMap();
  305. //adName重复判断
  306. list.forEach(area -> {
  307. if (map.containsKey(area.getAdName())) {
  308. map.get(area.getAdName()).add(area);
  309. } else {
  310. List<TacInspYearBatchArea> areaList = new ArrayList<>();
  311. areaList.add(area);
  312. map.put(area.getAdName(), areaList);
  313. }
  314. });
  315. for (Map<String, String> stringMap : areaPris.getAdNames()) {
  316. String adName = stringMap.get("adName");
  317. if (map.containsKey(adName)) {
  318. List<TacInspYearBatchArea> areaList = map.get(adName);
  319. if (areaList.size() > 0) {
  320. areaList.remove(0);
  321. continue;
  322. }
  323. }
  324. TacInspYearBatchGroup group = new TacInspYearBatchGroup();
  325. group.setId(UuidUtil.uuid());
  326. group.setYearBatchId(areaPris.getYearBatchId());
  327. group.setTenet(areaPris.getId());
  328. group.setInTm(new Date());
  329. TacInspYearBatchGroupParam groupParam = new TacInspYearBatchGroupParam();
  330. groupParam.setYearBatchId(areaPris.getYearBatchId());
  331. String groupNum = this.tacInspYearBatchGroupDao.getMaxGourpNum(groupParam);
  332. if (StringUtils.isBlank(groupNum)) {
  333. group.setGroupNm(1L);
  334. } else {
  335. group.setGroupNm(Long.parseLong(groupNum) + 1);
  336. }
  337. group.setYear(areaPris.getYear());
  338. group.setBatch(areaPris.getBatch());
  339. group.setProvince(areaPris.getProvince());
  340. group.setConfirmer("0");
  341. tacInspYearBatchGroupDao.insert(group);
  342. //新增
  343. if (adName.contains(",")) {
  344. // String [] ads = area.getAdCode().split(",");
  345. String[] adNames = adName.split(",");
  346. for (int i = 0; i < adNames.length; i++) {
  347. AttAdXBaseParam adXBaseParam = new AttAdXBaseParam();
  348. adXBaseParam.setAdName(adNames[i]);
  349. AttAdXBase attAdXBase = attAdXBaseDao.getByName(adXBaseParam);
  350. if (attAdXBase == null) {
  351. continue;
  352. }
  353. TacInspYearBatchArea batchArea = new TacInspYearBatchArea();
  354. batchArea.setId(UuidUtil.uuid());
  355. batchArea.setGroupId(group.getId());
  356. batchArea.setYearBatchId(group.getYearBatchId());
  357. batchArea.setAdCode(attAdXBase.getAdCode());
  358. batchArea.setAdName(adNames[i]);
  359. batchArea.setGroupNm(group.getGroupNm());
  360. batchArea.setBatch(areaPris.getBatch());
  361. batchArea.setYear(areaPris.getYear());
  362. batchArea.setInTm(new Date());
  363. batchArea.setUpTm(new Date());
  364. batchArea.setProvince(areaPris.getProvince());
  365. areaDao.insert(batchArea);
  366. }
  367. } else {
  368. AttAdXBaseParam adXBaseParam = new AttAdXBaseParam();
  369. adXBaseParam.setAdName(adName);
  370. adXBaseParam.setAdCode(AdLevelUtil.getAddvcd(areaPris.getProvince()));
  371. AttAdXBase attAdXBase = attAdXBaseDao.getByName(adXBaseParam);
  372. if (attAdXBase == null) {
  373. continue;
  374. }
  375. TacInspYearBatchArea batchArea = new TacInspYearBatchArea();
  376. batchArea.setId(UuidUtil.uuid());
  377. batchArea.setGroupId(group.getId());
  378. batchArea.setYearBatchId(group.getYearBatchId());
  379. batchArea.setGroupNm(group.getGroupNm());
  380. batchArea.setAdCode(attAdXBase.getAdCode());
  381. batchArea.setAdName(adName);
  382. batchArea.setBatch(areaPris.getBatch());
  383. batchArea.setYear(areaPris.getYear());
  384. batchArea.setInTm(new Date());
  385. batchArea.setUpTm(new Date());
  386. batchArea.setProvince(areaPris.getProvince());
  387. areaDao.insert(batchArea);
  388. }
  389. }
  390. //删除组与区域
  391. if (map.size() > 0) {
  392. TacInspYearBatchGroupPersParam groupPersParam = new TacInspYearBatchGroupPersParam();
  393. for (String key : map.keySet()) {
  394. List<TacInspYearBatchArea> areaList = map.get(key);
  395. if (areaList == null || areaList.isEmpty()) {
  396. continue;
  397. }
  398. for (TacInspYearBatchArea area : areaList) {
  399. tacInspYearBatchGroupDao.delete(area.getGroupId());
  400. groupPersParam.setGroupId(area.getGroupId());
  401. groupPersDao.deleteBy(groupPersParam);
  402. if (area.getId().contains(",")) {
  403. for (String id : area.getId().split(",")) {
  404. areaDao.delete(id);
  405. }
  406. } else {
  407. areaDao.delete(area.getId());
  408. }
  409. }
  410. }
  411. }
  412. TacInspYearBatch batch = new TacInspYearBatch();
  413. batch.setId(areaPris.getYearBatchId());
  414. batch.setIsAreaGroup("1");
  415. yearBatchDao.update(batch);
  416. return 0;
  417. }
  418. @Override
  419. public TacInspPersAreaPris getByYearBatchId(String yearBatchId) {
  420. TacInspPersAreaPrisParam persAreaPrisParam = new TacInspPersAreaPrisParam();
  421. persAreaPrisParam.setYearBatchId(yearBatchId);
  422. List<TacInspPersAreaPris> list = tacInspPersAreaPrisDao.findList(persAreaPrisParam);
  423. if (list.size() > 0) {
  424. return list.get(0);
  425. }
  426. return null;
  427. }
  428. }