| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- package cn.com.goldenwater.dcproj.service.impl.tac;
- import cn.com.goldenwater.core.service.AbstractCrudService;
- import cn.com.goldenwater.dcproj.dao.*;
- import cn.com.goldenwater.dcproj.dto.TacCountDto;
- import cn.com.goldenwater.dcproj.model.*;
- import cn.com.goldenwater.dcproj.param.*;
- import cn.com.goldenwater.dcproj.service.TacInspPersAreaPrisService;
- import cn.com.goldenwater.dcproj.utils.InspUtils;
- import cn.com.goldenwater.id.util.UuidUtil;
- 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.Date;
- import java.util.List;
- import java.util.Map;
- /**
- * @author lune
- * @date 2019-9-6
- */
- @Service
- @Transactional
- public class TacInspPersAreaPrisServiceImpl extends AbstractCrudService<TacInspPersAreaPris, TacInspPersAreaPrisParam> implements TacInspPersAreaPrisService {
- @Autowired
- private TacInspPersAreaPrisDao tacInspPersAreaPrisDao;
- @Autowired
- private TacWorkerBDao tacWorkerBDao;
- @Autowired
- private TacTacInspPersPrisLtsDao ltsDao;
- @Autowired
- private TacInspYearBatchDao yearBatchDao;
- @Autowired
- private TacInspYearBatchAreaDao areaDao;
- @Autowired
- private TacInspYearBatchGroupDao tacInspYearBatchGroupDao;
- @Autowired
- private TacInspYearBatchGroupPersDao groupPersDao;
- @Autowired
- private AttAdXBaseDao attAdXBaseDao;
- public TacInspPersAreaPrisServiceImpl(TacInspPersAreaPrisDao tacInspPersAreaPrisDao) {
- super(tacInspPersAreaPrisDao);
- this.tacInspPersAreaPrisDao = tacInspPersAreaPrisDao;
- }
- @Override
- public TacInspPersAreaPris getAreaPris(String id, String yearBatchId, String province) {
- TacWorkerBParam bParam = new TacWorkerBParam();
- bParam.setYearBatchId(yearBatchId);
- bParam.setGroupType(InspUtils.setOrgIds("1"));
- //获取库表
- bParam.setProvince(province);
- List<TacCountDto> comList = tacWorkerBDao.countByRole(bParam);
- bParam.setGroupType(InspUtils.setOrgIds("7"));
- List<TacCountDto> proList = tacWorkerBDao.countByRole(bParam);
- bParam.setGroupType(InspUtils.setOrgIds("4"));
- List<TacCountDto> goldList = tacWorkerBDao.countByRole(bParam);
- bParam.setGroupType(InspUtils.setOrgIds("5"));
- List<TacCountDto> redList = tacWorkerBDao.countByRole(bParam);
- if (StringUtils.isBlank(id) || "null".equals(id)) {
- TacInspPersAreaPris pris = new TacInspPersAreaPris();
- pris.setCommList(comList);
- pris.setProList(proList);
- pris.setGoldList(goldList);
- pris.setRedList(redList);
- return pris;
- }
- //获取规则id
- TacInspPersAreaPris pris = tacInspPersAreaPrisDao.get(id);
- TacTacInspPersPrisLtsParam ltsParam = new TacTacInspPersPrisLtsParam();
- if ("1".equals(String.valueOf(pris.getIsNew()))) {
- bParam.setNewSize(pris.getNewSize());
- List<TacCountDto> newList = tacWorkerBDao.countByRoleNew(bParam);
- getSelectCount(newList, ltsParam, "8");
- pris.setNewList(newList);
- }
- ltsParam.setPersPrisId(id);
- getSelectCount(comList, ltsParam, "1");
- getSelectCount(proList, ltsParam, "7");
- getSelectCount(goldList, ltsParam, "4");
- getSelectCount(redList, ltsParam, "5");
- pris.setCommList(comList);
- pris.setProList(proList);
- pris.setGoldList(goldList);
- pris.setRedList(redList);
- return pris;
- }
- private void getSelectCount(List<TacCountDto> list, TacTacInspPersPrisLtsParam ltsParam, String type) {
- ltsParam.setTenetType(type);
- TacTacInspPersPrisLts lts = ltsDao.getBy(ltsParam);
- if (lts == null) {
- return;
- }
- for (TacCountDto tacCountDto : list) {
- if ("20".equals(tacCountDto.getCode())) {
- tacCountDto.setSelectCount(String.valueOf(lts.getSpecialSize() == null ? 0 : lts.getSpecialSize()));
- }
- if ("19".equals(tacCountDto.getCode())) {
- tacCountDto.setSelectCount(String.valueOf(lts.getAssistantSize() == null ? 0 : lts.getAssistantSize()));
- }
- if ("11".equals(tacCountDto.getCode())) {
- tacCountDto.setSelectCount(String.valueOf(lts.getEarlyTisSize() == null ? 0 : lts.getEarlyTisSize()));
- }
- if ("12".equals(tacCountDto.getCode())) {
- tacCountDto.setSelectCount(String.valueOf(lts.getDevemanageTisSize() == null ? 0 : lts.getDevemanageTisSize()));
- }
- if ("13".equals(tacCountDto.getCode())) {
- tacCountDto.setSelectCount(String.valueOf(lts.getPlanTisSize() == null ? 0 : lts.getPlanTisSize()));
- }
- if ("14".equals(tacCountDto.getCode())) {
- tacCountDto.setSelectCount(String.valueOf(lts.getFinanceTisSize() == null ? 0 : lts.getFinanceTisSize()));
- }
- if ("15".equals(tacCountDto.getCode())) {
- tacCountDto.setSelectCount(String.valueOf(lts.getQualityTisSize() == null ? 0 : lts.getQualityTisSize()));
- }
- if ("16".equals(tacCountDto.getCode())) {
- tacCountDto.setSelectCount(String.valueOf(lts.getSafetyTisSize() == null ? 0 : lts.getSafetyTisSize()));
- }
- }
- }
- private TacTacInspPersPrisLts setLtsCount(List<TacCountDto> list, TacTacInspPersPrisLts lts, TacInspPersAreaPris tacInspPersAreaPris, String type) {
- if (lts == null) {
- lts = new TacTacInspPersPrisLts();
- lts.setId(UuidUtil.uuid());
- lts.setInTm(new Date());
- lts.setUpTm(new Date());
- lts.setPersPrisId(tacInspPersAreaPris.getId());
- lts.setPersId(tacInspPersAreaPris.getPersId());
- lts.setTenetType(type);
- }
- Long total = new Long(0);
- for (TacCountDto tacCountDto : list) {
- if (StringUtils.isNotBlank(tacCountDto.getSelectCount()) && !"null".equals(tacCountDto.getSelectCount())) {
- total += Long.valueOf(tacCountDto.getSelectCount());
- if ("20".equals(tacCountDto.getCode())) {
- lts.setSpecialSize(Long.valueOf(tacCountDto.getSelectCount()));
- }
- if ("19".equals(tacCountDto.getCode())) {
- lts.setAssistantSize(Long.valueOf(tacCountDto.getSelectCount()));
- }
- if ("11".equals(tacCountDto.getCode())) {
- lts.setEarlyTisSize(Long.valueOf(tacCountDto.getSelectCount()));
- }
- if ("12".equals(tacCountDto.getCode())) {
- lts.setDevemanageTisSize(Long.valueOf(tacCountDto.getSelectCount()));
- }
- if ("13".equals(tacCountDto.getCode())) {
- lts.setPlanTisSize(Long.valueOf(tacCountDto.getSelectCount()));
- }
- if ("14".equals(tacCountDto.getCode())) {
- lts.setFinanceTisSize(Long.valueOf(tacCountDto.getSelectCount()));
- }
- if ("15".equals(tacCountDto.getCode())) {
- lts.setQualityTisSize(Long.valueOf(tacCountDto.getSelectCount()));
- }
- if ("16".equals(tacCountDto.getCode())) {
- lts.setSafetyTisSize(Long.valueOf(tacCountDto.getSelectCount()));
- }
- }
- }
- lts.setTotalSize(total);
- return lts;
- }
- @Override
- public int insertPris(TacInspPersAreaPris tacInspPersAreaPris) {
- TacInspYearBatch batch = yearBatchDao.get(tacInspPersAreaPris.getYearBatchId());
- tacInspPersAreaPris.setYear(batch.getYear());
- tacInspPersAreaPris.setBatch(batch.getBatch());
- this.tacInspPersAreaPrisDao.insert(tacInspPersAreaPris);
- if (tacInspPersAreaPris.getCommList() != null && tacInspPersAreaPris.getCommList().size() > 0) {
- TacTacInspPersPrisLts lts = setLtsCount(tacInspPersAreaPris.getCommList(), null, tacInspPersAreaPris, "1");
- ltsDao.insert(lts);
- }
- if (tacInspPersAreaPris.getProList() != null && tacInspPersAreaPris.getProList().size() > 0) {
- TacTacInspPersPrisLts lts = setLtsCount(tacInspPersAreaPris.getProList(), null, tacInspPersAreaPris, "7");
- ltsDao.insert(lts);
- }
- if ("1".equals(tacInspPersAreaPris.getIsPick())) {
- if (tacInspPersAreaPris.getGoldList() != null && tacInspPersAreaPris.getGoldList().size() > 0) {
- TacTacInspPersPrisLts lts = setLtsCount(tacInspPersAreaPris.getGoldList(), null, tacInspPersAreaPris, "4");
- ltsDao.insert(lts);
- }
- if (tacInspPersAreaPris.getRedList() != null && tacInspPersAreaPris.getRedList().size() > 0) {
- TacTacInspPersPrisLts lts = setLtsCount(tacInspPersAreaPris.getRedList(), null, tacInspPersAreaPris, "5");
- ltsDao.insert(lts);
- }
- }
- if ("1".equals(tacInspPersAreaPris.getIsNew()) && tacInspPersAreaPris.getNewList().size() > 0) {
- TacTacInspPersPrisLts lts = setLtsCount(tacInspPersAreaPris.getNewList(), null, tacInspPersAreaPris, "8");
- ltsDao.insert(lts);
- }
- return 0;
- }
- @Override
- public int updatePris(TacInspPersAreaPris tacInspPersAreaPris) {
- TacInspYearBatch batch = yearBatchDao.get(tacInspPersAreaPris.getYearBatchId());
- tacInspPersAreaPris.setYear(batch.getYear());
- tacInspPersAreaPris.setBatch(batch.getBatch());
- this.tacInspPersAreaPrisDao.update(tacInspPersAreaPris);
- TacTacInspPersPrisLtsParam ltsParam = new TacTacInspPersPrisLtsParam();
- ltsParam.setPersPrisId(tacInspPersAreaPris.getId());
- if (tacInspPersAreaPris.getCommList() != null && tacInspPersAreaPris.getCommList().size() > 0) {
- ltsParam.setTenetType("1");
- TacTacInspPersPrisLts lts = ltsDao.getBy(ltsParam);
- if (lts == null) {
- lts = setLtsCount(tacInspPersAreaPris.getCommList(), null, tacInspPersAreaPris, "1");
- ltsDao.insert(lts);
- } else {
- setLtsCount(tacInspPersAreaPris.getCommList(), lts, tacInspPersAreaPris, "1");
- ltsDao.update(lts);
- }
- }
- if (tacInspPersAreaPris.getProList() != null && tacInspPersAreaPris.getProList().size() > 0) {
- ltsParam.setTenetType("7");
- TacTacInspPersPrisLts lts = ltsDao.getBy(ltsParam);
- if (lts == null) {
- lts = setLtsCount(tacInspPersAreaPris.getProList(), null, tacInspPersAreaPris, "7");
- ltsDao.insert(lts);
- } else {
- setLtsCount(tacInspPersAreaPris.getProList(), lts, tacInspPersAreaPris, "7");
- ltsDao.update(lts);
- }
- }
- if ("1".equals(tacInspPersAreaPris.getIsPick())) {
- if (tacInspPersAreaPris.getGoldList() != null && tacInspPersAreaPris.getGoldList().size() > 0) {
- ltsParam.setTenetType("4");
- TacTacInspPersPrisLts lts = ltsDao.getBy(ltsParam);
- if (lts == null) {
- lts = setLtsCount(tacInspPersAreaPris.getGoldList(), null, tacInspPersAreaPris, "4");
- ltsDao.insert(lts);
- } else {
- setLtsCount(tacInspPersAreaPris.getGoldList(), lts, tacInspPersAreaPris, "4");
- ltsDao.update(lts);
- }
- }
- if (tacInspPersAreaPris.getRedList() != null && tacInspPersAreaPris.getRedList().size() > 0) {
- ltsParam.setTenetType("5");
- TacTacInspPersPrisLts lts = ltsDao.getBy(ltsParam);
- if (lts == null) {
- lts = setLtsCount(tacInspPersAreaPris.getRedList(), null, tacInspPersAreaPris, "5");
- ltsDao.insert(lts);
- } else {
- setLtsCount(tacInspPersAreaPris.getRedList(), lts, tacInspPersAreaPris, "5");
- ltsDao.update(lts);
- }
- }
- } else {
- ltsParam.setTenetType("4");
- ltsDao.deleteBy(ltsParam);
- ltsParam.setTenetType("5");
- ltsDao.deleteBy(ltsParam);
- }
- if ("1".equals(tacInspPersAreaPris.getIsNew()) && tacInspPersAreaPris.getNewList().size() > 0) {
- ltsParam.setTenetType("8");
- TacTacInspPersPrisLts lts = ltsDao.getBy(ltsParam);
- if (lts == null) {
- lts = setLtsCount(tacInspPersAreaPris.getNewList(), null, tacInspPersAreaPris, "8");
- ltsDao.insert(lts);
- } else {
- setLtsCount(tacInspPersAreaPris.getNewList(), lts, tacInspPersAreaPris, "8");
- ltsDao.update(lts);
- }
- } else {
- ltsParam.setTenetType("8");
- ltsDao.deleteBy(ltsParam);
- }
- return 0;
- }
- @Override
- public TacInspPersAreaPris getPersAreaPris(String id, String province) {
- TacInspPersAreaPris areaPris = this.tacInspPersAreaPrisDao.get(id);
- if (areaPris == null) {
- return null;
- }
- TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
- areaParam.setYearBatchId(areaPris.getYearBatchId());
- areaParam.setProvince(province);
- List<TacInspYearBatchArea> list = areaDao.findList(areaParam);
- 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());
- }
- });
- areaPris.setAreaList(new ArrayList<>(areaList.values()));
- return areaPris;
- }
- @Override
- public int updatePersAreaPris(TacInspPersAreaPris areaPris) {
- if (StringUtils.isNotBlank(areaPris.getId())) {
- tacInspPersAreaPrisDao.update(areaPris);
- }
- List<TacInspYearBatchArea> list = new ArrayList<>();
- if (areaPris.getAreaList() != null) {
- list = areaPris.getAreaList();
- }
- // Map<String,TacInspYearBatchArea> map = list.stream().collect(Collectors.toMap(TacInspYearBatchArea::getAdName, Function.identity()));
- Map<String, List<TacInspYearBatchArea>> map = new HashedMap();
- //adName重复判断
- list.forEach(area -> {
- if (map.containsKey(area.getAdName())) {
- map.get(area.getAdName()).add(area);
- } else {
- List<TacInspYearBatchArea> areaList = new ArrayList<>();
- areaList.add(area);
- map.put(area.getAdName(), areaList);
- }
- });
- for (Map<String, String> stringMap : areaPris.getAdNames()) {
- String adName = stringMap.get("adName");
- if (map.containsKey(adName)) {
- List<TacInspYearBatchArea> areaList = map.get(adName);
- if (areaList.size() > 0) {
- areaList.remove(0);
- continue;
- }
- }
- TacInspYearBatchGroup group = new TacInspYearBatchGroup();
- group.setId(UuidUtil.uuid());
- group.setYearBatchId(areaPris.getYearBatchId());
- group.setTenet(areaPris.getId());
- group.setInTm(new Date());
- TacInspYearBatchGroupParam groupParam = new TacInspYearBatchGroupParam();
- groupParam.setYearBatchId(areaPris.getYearBatchId());
- String groupNum = this.tacInspYearBatchGroupDao.getMaxGourpNum(groupParam);
- if (StringUtils.isBlank(groupNum)) {
- group.setGroupNm(1L);
- } else {
- group.setGroupNm(Long.parseLong(groupNum) + 1);
- }
- group.setYear(areaPris.getYear());
- group.setBatch(areaPris.getBatch());
- group.setProvince(areaPris.getProvince());
- group.setConfirmer("0");
- tacInspYearBatchGroupDao.insert(group);
- //新增
- if (adName.contains(",")) {
- // String [] ads = area.getAdCode().split(",");
- String[] adNames = adName.split(",");
- for (int i = 0; i < adNames.length; i++) {
- AttAdXBaseParam adXBaseParam = new AttAdXBaseParam();
- adXBaseParam.setAdName(adNames[i]);
- AttAdXBase attAdXBase = attAdXBaseDao.getByName(adXBaseParam);
- if (attAdXBase == null) {
- continue;
- }
- TacInspYearBatchArea batchArea = new TacInspYearBatchArea();
- batchArea.setId(UuidUtil.uuid());
- batchArea.setGroupId(group.getId());
- batchArea.setYearBatchId(group.getYearBatchId());
- batchArea.setAdCode(attAdXBase.getAdCode());
- batchArea.setAdName(adNames[i]);
- batchArea.setGroupNm(group.getGroupNm());
- batchArea.setBatch(areaPris.getBatch());
- batchArea.setYear(areaPris.getYear());
- batchArea.setInTm(new Date());
- batchArea.setUpTm(new Date());
- batchArea.setProvince(areaPris.getProvince());
- areaDao.insert(batchArea);
- }
- } else {
- AttAdXBaseParam adXBaseParam = new AttAdXBaseParam();
- adXBaseParam.setAdName(adName);
- AttAdXBase attAdXBase = attAdXBaseDao.getByName(adXBaseParam);
- if (attAdXBase == null) {
- continue;
- }
- TacInspYearBatchArea batchArea = new TacInspYearBatchArea();
- batchArea.setId(UuidUtil.uuid());
- batchArea.setGroupId(group.getId());
- batchArea.setYearBatchId(group.getYearBatchId());
- batchArea.setGroupNm(group.getGroupNm());
- batchArea.setAdCode(attAdXBase.getAdCode());
- batchArea.setAdName(adName);
- batchArea.setBatch(areaPris.getBatch());
- batchArea.setYear(areaPris.getYear());
- batchArea.setInTm(new Date());
- batchArea.setUpTm(new Date());
- batchArea.setProvince(areaPris.getProvince());
- areaDao.insert(batchArea);
- }
- }
- //删除组与区域
- if (map.size() > 0) {
- TacInspYearBatchGroupPersParam groupPersParam = new TacInspYearBatchGroupPersParam();
- for (String key : map.keySet()) {
- List<TacInspYearBatchArea> areaList = map.get(key);
- if (areaList == null || areaList.isEmpty()) {
- continue;
- }
- for (TacInspYearBatchArea area : areaList) {
- tacInspYearBatchGroupDao.delete(area.getGroupId());
- groupPersParam.setGroupId(area.getGroupId());
- groupPersDao.deleteBy(groupPersParam);
- if (area.getId().contains(",")) {
- for (String id : area.getId().split(",")) {
- areaDao.delete(id);
- }
- } else {
- areaDao.delete(area.getId());
- }
- }
- }
- }
- TacInspYearBatch batch = new TacInspYearBatch();
- batch.setId(areaPris.getYearBatchId());
- batch.setIsAreaGroup("1");
- yearBatchDao.update(batch);
- return 0;
- }
- @Override
- public TacInspPersAreaPris getByYearBatchId(String yearBatchId) {
- TacInspPersAreaPrisParam persAreaPrisParam = new TacInspPersAreaPrisParam();
- persAreaPrisParam.setYearBatchId(yearBatchId);
- List<TacInspPersAreaPris> list = tacInspPersAreaPrisDao.findList(persAreaPrisParam);
- if (list.size() > 0) {
- return list.get(0);
- }
- return null;
- }
- }
|