0480d2cc99dc9caae474dd59302e2daddffe4dce.svn-base 20 KB

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