模板
表结构
HSGD_BASE_GROUP_IMPORT_RECORD
HSGD_BASE_GROUP_IMPORT_COMPLETION
HSGD_BASE_GROUP_NOT_IMPORT_RECORD
代码
package com.zhgd.base.controller.api; import com.zhgd.base.service.IZhgdSrBaseGroupImportService; import com.zhgd.common.util.JsonUtil; import com.zhgd.common.web.ResponseResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.util.List; /** * 描述 掌柜组织改版:1-导入组织部门 * * @author wangzhizhong * @version 1.0.0 * @date 2021/10/11 16:07:20 */ @RestController @Api(tags = "Zhgd Sr Base Group Import Controller") @RequestMapping(value = "/api/srBaseGroupImport") @Slf4j public class ApiZhgdSrBaseGroupImportController { @Resource private IZhgdSrBaseGroupImportService iZhgdSrBaseGroupImportService; @ApiOperation(value = "掌柜组织改版导入组织接口-V2版本", response = String.class, notes = "Import Base Group V2") @PostMapping(value = "/11201/v2/importBaseGroup") public ResponseResult<List<String>> importBaseGroupV2(@RequestParam("importFile") MultipartFile importFile){ String importFileName1 = importFile != null ? importFile.getOriginalFilename() : "--"; log.info("[掌柜组织改版]导入部门组织,导入文件名:{}",importFileName1); ResponseResult<List<String>> result = new ResponseResult<>(); result.setData(iZhgdSrBaseGroupImportService.importBaseGroupProcessV2(importFile)); log.info("[掌柜组织改版]导入部门组织,导入文件名:{}", JsonUtil.toJSONString(result)); return result; } }
public interface IZhgdSrBaseGroupImportService { void batchInsertAll(List<HsgdBaseGroupImportRecord> recordList); List<String> importBaseGroupProcess(MultipartFile importFile); void insert(HsgdBaseGroupImportRecord record); HsgdBaseGroupSimpleVO getGroupSimpleByGroupNameAndLevel(String levelGroupName, Integer groupLevel); HsgdBaseGroupSimpleVO getGroupSimpleByGroupNameAndParentIdAndLevel(String levelGroupName, Long groupId, Integer groupLevel); List<String> importBaseGroupProcessV2(MultipartFile importFile); HsgdBaseGroupSimpleVO getGroupSimpleByGroupNameAndLevelAndParentId(String levelGroupName, Integer groupLevel,Long parentId); }
package com.zhgd.base.service.impl; import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.github.pagehelper.PageHelper; import com.zhgd.base.domain.model.ZhgdSrGroupImportModel; import com.zhgd.base.domain.vo.HsgdBaseGroupSimpleVO; import com.zhgd.base.entity.*; import com.zhgd.base.enums.HsgdBaseGroupLevelEnum; import com.zhgd.base.listener.ZhgdSrBaseGroupImportExcelListener; import com.zhgd.base.mapper.*; import com.zhgd.base.service.IHsgdBaseGroupNotImportRecordService; import com.zhgd.base.service.IZhgdSrBaseGroupImportHandleService; import com.zhgd.base.service.IZhgdSrBaseGroupImportService; import com.zhgd.common.util.JsonUtil; import com.zhgd.common.util.UUIDUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @Service @Slf4j public class ZhgdSrBaseGroupImportServiceImpl implements IZhgdSrBaseGroupImportService { private final String SYSTEM_USER_NAME = "system"; @Resource private IZhgdSrBaseGroupImportHandleService iZhgdSrBaseGroupImportHandleService; @Resource private HsgdBaseGroupImportRecordMapper hsgdBaseGroupImportRecordMapper; @Resource private HsgdBaseGroupMapper hsgdBaseGroupMapper; @Resource private HsgdBaseGroupInfoMapper hsgdBaseGroupInfoMapper; @Resource private HsgdBaseGroupLabelDictMapper hsgdBaseGroupLabelDictMapper; @Resource private HsgdBaseGroupLabelMapper hsgdBaseGroupLabelMapper; @Resource private HsgdBaseGroupRegionMapper hsgdBaseGroupRegionMapper; @Resource private CrmRegionMapper crmRegionMapper; @Resource private HsgdBaseGroupImportCompletionMapper hsgdBaseGroupImportCompletionMapper; @Resource private IHsgdBaseGroupNotImportRecordService iHsgdBaseGroupNotImportRecordService; /** * 导入流程 V1 * @param importFile * @return */ @Override public List<String> importBaseGroupProcess(MultipartFile importFile) { List<String> importResultList = new ArrayList<>(); try { String batchNo = UUIDUtils.getUUID(); // 1、导入数据 ZhgdSrBaseGroupImportExcelListener listener = new ZhgdSrBaseGroupImportExcelListener(iZhgdSrBaseGroupImportHandleService, batchNo); EasyExcel.read(importFile.getInputStream(), ZhgdSrGroupImportModel.class, listener).sheet(0).doRead(); // 2、文件校验(待处理) // 3、组织数据 int totalRecord = this.organizeAndSaveBaseGroupCompletionData(batchNo); this.saveBaseGroupData(batchNo,totalRecord); } catch (Exception e) { log.info("组织改版组织导入异常", e); importResultList.add("导入异常!" + e.getMessage()); return importResultList; } importResultList.add("导入成功!"); return importResultList; } private int organizeAndSaveBaseGroupCompletionData(String batchNo) { int importDataTotal = hsgdBaseGroupImportRecordMapper.countImportBaseGroupDataTotalByBatchNo(batchNo); if (importDataTotal > 0) { // 每页记录数 int pageSize = 500, startPage = 1; // 总页数 int totalPage = importDataTotal % pageSize == 0 ? (importDataTotal / pageSize) : (importDataTotal / pageSize + 1); String groupOneLevel = ""; String groupTwoLevel = ""; String groupThreeLevel = ""; String groupFourLevel = ""; String groupFiveLevel = ""; String groupSixLevel = ""; String groupSevenLevel = ""; for (int pageN = 0; pageN < totalPage; pageN++) { PageHelper.startPage(startPage + pageN, pageSize, false); List<HsgdBaseGroupImportRecord> list = hsgdBaseGroupImportRecordMapper.selectListByBatchNo(batchNo); if (CollectionUtils.isNotEmpty(list)) { List<HsgdBaseGroupImportCompletion> completionList = new ArrayList<>(); HsgdBaseGroupImportCompletion completion; for (int i = 0, listSize = list.size(); i < listSize; i++) { HsgdBaseGroupImportRecord record = list.get(i); completion = new HsgdBaseGroupImportCompletion(); if (StringUtils.isNotBlank(record.getLevelOneGroup())) { groupOneLevel = record.getLevelOneGroup(); completion.setGroupLevel(HsgdBaseGroupLevelEnum.ONE.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelTwoGroup())) { groupTwoLevel = record.getLevelTwoGroup(); record.setLevelOneGroup(groupOneLevel); completion.setGroupLevel(HsgdBaseGroupLevelEnum.TWO.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelThreeGroup())) { groupThreeLevel = record.getLevelThreeGroup(); record.setLevelOneGroup(groupOneLevel); record.setLevelTwoGroup(groupTwoLevel); completion.setGroupLevel(HsgdBaseGroupLevelEnum.THREE.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelFourGroup())) { groupFourLevel = record.getLevelFourGroup(); record.setLevelOneGroup(groupOneLevel); record.setLevelTwoGroup(groupTwoLevel); record.setLevelThreeGroup(groupThreeLevel); completion.setGroupLevel(HsgdBaseGroupLevelEnum.FOUR.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelFiveGroup())) { groupFiveLevel = record.getLevelFiveGroup(); record.setLevelOneGroup(groupOneLevel); record.setLevelTwoGroup(groupTwoLevel); record.setLevelThreeGroup(groupThreeLevel); record.setLevelFourGroup(groupFourLevel); completion.setGroupLevel(HsgdBaseGroupLevelEnum.FIVE.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelSixGroup())) { groupSixLevel = record.getLevelSixGroup(); record.setLevelOneGroup(groupOneLevel); record.setLevelTwoGroup(groupTwoLevel); record.setLevelThreeGroup(groupThreeLevel); record.setLevelFourGroup(groupFourLevel); record.setLevelFiveGroup(groupFiveLevel); completion.setGroupLevel(HsgdBaseGroupLevelEnum.SIX.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelSevenGroup())) { groupSevenLevel = record.getLevelSevenGroup(); record.setLevelOneGroup(groupOneLevel); record.setLevelTwoGroup(groupTwoLevel); record.setLevelThreeGroup(groupThreeLevel); record.setLevelFourGroup(groupFourLevel); record.setLevelFiveGroup(groupFiveLevel); record.setLevelSixGroup(groupSixLevel); completion.setGroupLevel(HsgdBaseGroupLevelEnum.SEVEN.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelEightGroup())) { record.setLevelOneGroup(groupOneLevel); record.setLevelTwoGroup(groupTwoLevel); record.setLevelThreeGroup(groupThreeLevel); record.setLevelFourGroup(groupFourLevel); record.setLevelFiveGroup(groupFiveLevel); record.setLevelSixGroup(groupSixLevel); record.setLevelSevenGroup(groupSevenLevel); completion.setGroupLevel(HsgdBaseGroupLevelEnum.EIGHT.getGroupLevel()); } BeanUtils.copyProperties(record, completion); completionList.add(completion); } iZhgdSrBaseGroupImportHandleService.insertAllImportCompletion(completionList); } } } return importDataTotal; } private void saveBaseGroupData(String batchNo,int totalRecord ) { if(totalRecord > 0) { // 每页记录数 int pageSize = 500, startPage = 1; // 总页数 int totalPage = totalRecord % pageSize == 0 ? (totalRecord / pageSize) : (totalRecord / pageSize + 1); Date nowDate = new Date(); Long parentId ; Map<String, HsgdBaseGroupSimpleVO> groupOneLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupTwoLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupThreeLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupFourLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupFiveLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupSixLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupSevenLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupEightLevelMap = new HashMap<>(); Map<String, Long> labelMap = this.getGroupLabelMap(); Map<String,CrmRegion> regionMap = new HashMap<>(); for (int pageN = 0; pageN < totalPage; pageN++) { PageHelper.startPage(startPage + pageN, pageSize, false); List<HsgdBaseGroupImportCompletion> importCompletionList = hsgdBaseGroupImportCompletionMapper.selectListByBatchNo(batchNo); if(CollectionUtils.isNotEmpty(importCompletionList)){ List<HsgdBaseGroupNotImportRecord> errorRecordList = new ArrayList<>(); HsgdBaseGroupNotImportRecord notImportRecord; this.getPageAllRegionToRegionMap(regionMap,importCompletionList); for (HsgdBaseGroupImportCompletion completionVO : importCompletionList){ try { if (HsgdBaseGroupLevelEnum.ONE.getGroupLevel().equals(completionVO.getGroupLevel())) { if (groupOneLevelMap.get(completionVO.getLevelOneGroup()) == null) { HsgdBaseGroupSimpleVO simpleOneVO = this.getGroupSimpleByGroupNameAndLevel(completionVO.getLevelOneGroup(), completionVO.getGroupLevel()); if (simpleOneVO != null) { groupOneLevelMap.put(completionVO.getLevelOneGroup(), simpleOneVO); } else { simpleOneVO = this.generatorGroupLevel(completionVO, nowDate, labelMap, regionMap, 0L); groupOneLevelMap.put(completionVO.getLevelOneGroup(), simpleOneVO); } } } else if (HsgdBaseGroupLevelEnum.TWO.getGroupLevel().equals(completionVO.getGroupLevel())) { HsgdBaseGroupSimpleVO oneSiVO = groupOneLevelMap.get(completionVO.getLevelOneGroup()); parentId = oneSiVO.getGroupId(); if (groupTwoLevelMap.get(completionVO.getLevelTwoGroup()) == null) { HsgdBaseGroupSimpleVO simpleTwoVO = this.getGroupSimpleByGroupNameAndLevel(completionVO.getLevelTwoGroup(), completionVO.getGroupLevel()); if (simpleTwoVO != null) { groupTwoLevelMap.put(completionVO.getLevelTwoGroup(), simpleTwoVO); } else { simpleTwoVO = this.generatorGroupLevel(completionVO, nowDate, labelMap, regionMap, parentId); groupTwoLevelMap.put(completionVO.getLevelTwoGroup(), simpleTwoVO); } } } else if (HsgdBaseGroupLevelEnum.THREE.getGroupLevel().equals(completionVO.getGroupLevel())) { HsgdBaseGroupSimpleVO twoSiVO = groupTwoLevelMap.get(completionVO.getLevelTwoGroup()); parentId = twoSiVO.getGroupId(); if (groupThreeLevelMap.get(completionVO.getLevelThreeGroup()) == null) { HsgdBaseGroupSimpleVO simpleThreeVO = this.getGroupSimpleByGroupNameAndLevel(completionVO.getLevelThreeGroup(), completionVO.getGroupLevel()); if (simpleThreeVO != null) { groupThreeLevelMap.put(completionVO.getLevelThreeGroup(), simpleThreeVO); } else { simpleThreeVO = this.generatorGroupLevel(completionVO, nowDate, labelMap, regionMap, parentId); groupThreeLevelMap.put(completionVO.getLevelThreeGroup(), simpleThreeVO); } } } else if (HsgdBaseGroupLevelEnum.FOUR.getGroupLevel().equals(completionVO.getGroupLevel())) { HsgdBaseGroupSimpleVO threeSiVO = groupThreeLevelMap.get(completionVO.getLevelThreeGroup()); parentId = threeSiVO.getGroupId(); if (groupFourLevelMap.get(completionVO.getLevelFourGroup()) == null) { HsgdBaseGroupSimpleVO simplefourVO = this.getGroupSimpleByGroupNameAndLevel(completionVO.getLevelFourGroup(), completionVO.getGroupLevel()); if (simplefourVO != null) { groupFourLevelMap.put(completionVO.getLevelFourGroup(), simplefourVO); } else { simplefourVO = this.generatorGroupLevel(completionVO, nowDate, labelMap, regionMap, parentId); groupFourLevelMap.put(completionVO.getLevelFourGroup(), simplefourVO); } } } else if (HsgdBaseGroupLevelEnum.FIVE.getGroupLevel().equals(completionVO.getGroupLevel())) { HsgdBaseGroupSimpleVO fourSiVO = groupFourLevelMap.get(completionVO.getLevelFourGroup()); parentId = fourSiVO.getGroupId(); String fiveKey = completionVO.getLevelFourGroup() + "-" + completionVO.getLevelFiveGroup(); if (groupFiveLevelMap.get(fiveKey) == null) { HsgdBaseGroupSimpleVO simplefourVO = this.getGroupSimpleByGroupNameAndParentIdAndLevel(completionVO.getLevelFiveGroup(), parentId, completionVO.getGroupLevel()); if (simplefourVO != null) { groupFiveLevelMap.put(fiveKey, simplefourVO); } else { simplefourVO = this.generatorGroupLevel(completionVO, nowDate, labelMap, regionMap, parentId); groupFiveLevelMap.put(fiveKey, simplefourVO); } } } else if (HsgdBaseGroupLevelEnum.SIX.getGroupLevel().equals(completionVO.getGroupLevel())) { HsgdBaseGroupSimpleVO fiveSiVO = groupFiveLevelMap.get(completionVO.getLevelFourGroup() + "-" + completionVO.getLevelFiveGroup()); parentId = fiveSiVO.getGroupId(); String sixKey = completionVO.getLevelFiveGroup() + "-" + completionVO.getLevelSixGroup(); if (groupSixLevelMap.get(sixKey) == null) { HsgdBaseGroupSimpleVO simplefourVO = this.getGroupSimpleByGroupNameAndParentIdAndLevel(completionVO.getLevelSixGroup(), parentId, completionVO.getGroupLevel()); if (simplefourVO != null) { groupSixLevelMap.put(sixKey, simplefourVO); } else { simplefourVO = this.generatorGroupLevel(completionVO, nowDate, labelMap, regionMap, parentId); groupSixLevelMap.put(sixKey, simplefourVO); } } } else if (HsgdBaseGroupLevelEnum.SEVEN.getGroupLevel().equals(completionVO.getGroupLevel())) { HsgdBaseGroupSimpleVO sixSiVO = groupSixLevelMap.get(completionVO.getLevelFiveGroup() + "-" + completionVO.getLevelSixGroup()); parentId = sixSiVO.getGroupId(); String sevenKey = completionVO.getLevelSixGroup() + "-" + completionVO.getLevelSevenGroup(); if (groupSevenLevelMap.get(sevenKey) == null) { HsgdBaseGroupSimpleVO simplefourVO = this.getGroupSimpleByGroupNameAndParentIdAndLevel(completionVO.getLevelSixGroup(), parentId, completionVO.getGroupLevel()); if (simplefourVO != null) { groupSevenLevelMap.put(sevenKey, simplefourVO); } else { simplefourVO = this.generatorGroupLevel(completionVO, nowDate, labelMap, regionMap, parentId); groupSevenLevelMap.put(sevenKey, simplefourVO); } } } else if (HsgdBaseGroupLevelEnum.EIGHT.getGroupLevel().equals(completionVO.getGroupLevel())) { HsgdBaseGroupSimpleVO sevenSiVO = groupSevenLevelMap.get(completionVO.getLevelSixGroup() + "-" + completionVO.getLevelSevenGroup()); parentId = sevenSiVO.getGroupId(); String eightKey = completionVO.getLevelSevenGroup() + "-" + completionVO.getLevelEightGroup(); if (groupEightLevelMap.get(eightKey) == null) { HsgdBaseGroupSimpleVO simplefourVO = this.getGroupSimpleByGroupNameAndParentIdAndLevel(completionVO.getLevelEightGroup(), sevenSiVO.getGroupId(), completionVO.getGroupLevel()); if (simplefourVO != null) { groupEightLevelMap.put(eightKey, simplefourVO); } else { simplefourVO = this.generatorGroupLevel(completionVO, nowDate, labelMap, regionMap, parentId); groupEightLevelMap.put(eightKey, simplefourVO); } } } } catch (Exception e) { log.info("组织{}导入失败", JsonUtil.toJSONString(completionVO)); log.info("组织"+JsonUtil.toJSONString(completionVO)+"导入失败",e); notImportRecord = new HsgdBaseGroupNotImportRecord(); BeanUtils.copyProperties(completionVO,notImportRecord); errorRecordList.add(notImportRecord); } } if(CollectionUtils.isNotEmpty(errorRecordList)){ iHsgdBaseGroupNotImportRecordService.saveBatch(errorRecordList); } } } } } @Override public List<String> importBaseGroupProcessV2(MultipartFile importFile) { List<String> importResultList = new ArrayList<>(); try { // 批次号 String batchNo = UUIDUtils.getUUID(); // 1、导入数据 ZhgdSrBaseGroupImportExcelListener listener = new ZhgdSrBaseGroupImportExcelListener(iZhgdSrBaseGroupImportHandleService, batchNo); EasyExcel.read(importFile.getInputStream(), ZhgdSrGroupImportModel.class, listener).sheet(0).doRead(); // 2、组织整理数据 int totalRecord = this.organizeAndSaveBaseGroupCompletionDataV2(batchNo); // 3、保存组织数据 this.saveBaseGroupDataV2(batchNo,totalRecord); } catch (Exception e) { log.info("组织改版组织导入异常", e); importResultList.add("导入异常 :" + e.getMessage()); return importResultList; } importResultList.add("执行完成,请检查是否全部导入成功!"); return importResultList; } private int organizeAndSaveBaseGroupCompletionDataV2(String batchNo) { int importDataTotal = hsgdBaseGroupImportRecordMapper.countImportBaseGroupDataTotalByBatchNo(batchNo); if (importDataTotal > 0) { // 每页记录数,起始页 int pageSize = 120, startPage = 1; // 总页数 int totalPage = importDataTotal % pageSize == 0 ? (importDataTotal / pageSize) : (importDataTotal / pageSize + 1); String groupOneLevel = ""; String groupTwoLevel = ""; String groupThreeLevel = ""; String groupFourLevel = ""; String groupFiveLevel = ""; String groupSixLevel = ""; String groupSevenLevel = ""; String groupEightLevel = ""; String groupRecordRe = ""; int groupOneSort = 0; int groupTwoSort = 0; int groupThreeSort = 0; int groupFourSort = 0; int groupFiveSort = 0; int groupSixSort = 0; int groupSevenSort = 0; int groupEightSort = 0; for (int pageN = 0; pageN < totalPage; pageN++) { PageHelper.startPage(startPage + pageN, pageSize, false); List<HsgdBaseGroupImportRecord> list = hsgdBaseGroupImportRecordMapper.selectListByBatchNo(batchNo); if (CollectionUtils.isNotEmpty(list)) { List<HsgdBaseGroupImportCompletion> completionList = new ArrayList<>(); HsgdBaseGroupImportCompletion completion; for (int i = 0, listSize = list.size(); i < listSize; i++) { HsgdBaseGroupImportRecord record = list.get(i); completion = new HsgdBaseGroupImportCompletion(); BeanUtils.copyProperties(record, completion); if (StringUtils.isNotBlank(record.getLevelOneGroup())) { completion.setGroupLevel(HsgdBaseGroupLevelEnum.ONE.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelTwoGroup())) { completion.setGroupLevel(HsgdBaseGroupLevelEnum.TWO.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelThreeGroup())) { completion.setGroupLevel(HsgdBaseGroupLevelEnum.THREE.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelFourGroup())) { completion.setGroupLevel(HsgdBaseGroupLevelEnum.FOUR.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelFiveGroup())) { completion.setGroupLevel(HsgdBaseGroupLevelEnum.FIVE.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelSixGroup())) { completion.setGroupLevel(HsgdBaseGroupLevelEnum.SIX.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelSevenGroup())) { completion.setGroupLevel(HsgdBaseGroupLevelEnum.SEVEN.getGroupLevel()); } if (StringUtils.isNotBlank(record.getLevelEightGroup())) { completion.setGroupLevel(HsgdBaseGroupLevelEnum.EIGHT.getGroupLevel()); } if (HsgdBaseGroupLevelEnum.ONE.getGroupLevel().equals(completion.getGroupLevel())) { groupRecordRe = completion.getLevelOneGroup(); if (! groupOneLevel.equals(groupRecordRe)) { groupOneSort = groupOneSort + 1; groupOneLevel = groupRecordRe; groupTwoSort = 0; groupThreeSort = 0; groupFourSort = 0; groupFiveSort = 0; groupSixSort = 0; groupSevenSort = 0; groupEightSort = 0; completion.setGroupSort(groupOneSort); }else{ completion.setGroupSort(groupOneSort); } } else if (HsgdBaseGroupLevelEnum.TWO.getGroupLevel().equals(completion.getGroupLevel())) { groupRecordRe = completion.getLevelTwoGroup(); if (! groupTwoLevel.equals(groupRecordRe)) { groupTwoSort = groupTwoSort + 1; groupTwoLevel = groupRecordRe; groupThreeSort = 0; groupFourSort = 0; groupFiveSort = 0; groupSixSort = 0; groupSevenSort = 0; groupEightSort = 0; completion.setGroupSort(groupTwoSort); }else{ completion.setGroupSort(groupTwoSort); } } else if (HsgdBaseGroupLevelEnum.THREE.getGroupLevel().equals(completion.getGroupLevel())) { groupRecordRe = completion.getLevelThreeGroup(); if (! groupThreeLevel.equals(groupRecordRe)) { groupThreeSort = groupThreeSort + 1; groupThreeLevel = groupRecordRe; groupFourSort = 0; groupFiveSort = 0; groupSixSort = 0; groupSevenSort = 0; groupEightSort = 0; completion.setGroupSort(groupThreeSort); }else{ completion.setGroupSort(groupThreeSort); } } else if (HsgdBaseGroupLevelEnum.FOUR.getGroupLevel().equals(completion.getGroupLevel())) { groupRecordRe = completion.getLevelFourGroup(); if (! groupFourLevel.equals(groupRecordRe)) { groupFourSort = groupFourSort + 1; groupFourLevel = groupRecordRe; groupFiveSort = 0; groupSixSort = 0; groupSevenSort = 0; groupEightSort = 0; completion.setGroupSort(groupFourSort); }else{ completion.setGroupSort(groupFourSort); } } else if (HsgdBaseGroupLevelEnum.FIVE.getGroupLevel().equals(completion.getGroupLevel())) { groupRecordRe = completion.getLevelFiveGroup(); if (! groupFiveLevel.equals(groupRecordRe)) { groupFiveSort = groupFiveSort + 1; groupFiveLevel = groupRecordRe; groupSixSort = 0; groupSevenSort = 0; groupEightSort = 0; completion.setGroupSort(groupFiveSort); }else{ completion.setGroupSort(groupFiveSort); } } else if (HsgdBaseGroupLevelEnum.SIX.getGroupLevel().equals(completion.getGroupLevel())) { groupRecordRe = completion.getLevelSixGroup(); if (! groupSixLevel.equals(groupRecordRe)) { groupSixSort = groupSixSort + 1; groupSixLevel = groupRecordRe; groupSevenSort = 0; groupEightSort = 0; completion.setGroupSort(groupSixSort); }else{ completion.setGroupSort(groupSixSort); } } else if (HsgdBaseGroupLevelEnum.SEVEN.getGroupLevel().equals(completion.getGroupLevel())) { groupRecordRe = completion.getLevelSevenGroup(); if (! groupSevenLevel.equals(groupRecordRe)) { groupSevenSort = groupSevenSort + 1; groupSevenLevel = groupRecordRe; groupEightSort = 0; completion.setGroupSort(groupSevenSort); }else{ completion.setGroupSort(groupSevenSort); } } else if (HsgdBaseGroupLevelEnum.EIGHT.getGroupLevel().equals(completion.getGroupLevel())) { groupRecordRe = completion.getLevelEightGroup(); if (! groupEightLevel.equals(groupRecordRe)) { groupEightSort = groupEightSort + 1; groupEightLevel = groupRecordRe; completion.setGroupSort(groupEightSort); }else{ completion.setGroupSort(groupEightSort); } } completionList.add(completion); } iZhgdSrBaseGroupImportHandleService.insertAllImportCompletion(completionList); } } } return importDataTotal; } private void saveBaseGroupDataV2(String batchNo, int totalRecord) { if(totalRecord > 0) { int pageSize = 120, startPage = 1; int totalPage = totalRecord % pageSize == 0 ? (totalRecord / pageSize) : (totalRecord / pageSize + 1); Date nowDate = new Date(); Long parentId; String oneMapKey, twoMapKey, threeMapKey, fourMapKey, fiveMapKey, sixMapKey, sevenMapKey, eightMapKey; Map<String, CrmRegion> regionMap = new HashMap<>(); Map<String, Long> labelMap = this.getGroupLabelMap(); Map<String, HsgdBaseGroupSimpleVO> groupOneLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupTwoLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupThreeLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupFourLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupFiveLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupSixLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupSevenLevelMap = new HashMap<>(); Map<String, HsgdBaseGroupSimpleVO> groupEightLevelMap = new HashMap<>(); for (int pageN = 0; pageN < totalPage; pageN++) { PageHelper.startPage(startPage + pageN, pageSize, false); List<HsgdBaseGroupImportCompletion> importCompletionList = hsgdBaseGroupImportCompletionMapper.selectListByBatchNoV2(batchNo); if(CollectionUtils.isNotEmpty(importCompletionList)){ List<HsgdBaseGroupNotImportRecord> errorRecordList = new ArrayList<>(); HsgdBaseGroupNotImportRecord notImportRecord; this.getPageAllRegionToRegionMap(regionMap,importCompletionList); for (HsgdBaseGroupImportCompletion completionVO : importCompletionList) { try { // 一级部门 if (HsgdBaseGroupLevelEnum.ONE.getGroupLevel().equals(completionVO.getGroupLevel())) { oneMapKey = completionVO.getLevelOneGroup(); if (groupOneLevelMap.get(oneMapKey) == null) { this.handleOneLevelGroup(nowDate, regionMap, groupOneLevelMap, labelMap, oneMapKey, completionVO); } } else if (HsgdBaseGroupLevelEnum.TWO.getGroupLevel().equals(completionVO.getGroupLevel())) { oneMapKey = completionVO.getLevelOneGroup(); twoMapKey = completionVO.getLevelTwoGroup(); if (groupOneLevelMap.get(oneMapKey) == null) { this.handleOneLevelGroup(nowDate, regionMap, groupOneLevelMap, labelMap, oneMapKey, completionVO); } if (groupTwoLevelMap.get(twoMapKey) == null) { parentId = groupOneLevelMap.get(oneMapKey).getGroupId(); this.handleTwoLevelGroup(parentId, nowDate, regionMap, groupTwoLevelMap, labelMap, twoMapKey, completionVO); } } else if (HsgdBaseGroupLevelEnum.THREE.getGroupLevel().equals(completionVO.getGroupLevel())) { oneMapKey = completionVO.getLevelOneGroup(); twoMapKey = completionVO.getLevelTwoGroup(); threeMapKey = completionVO.getLevelThreeGroup(); if (groupOneLevelMap.get(oneMapKey) == null) { this.handleOneLevelGroup(nowDate, regionMap, groupOneLevelMap, labelMap, oneMapKey, completionVO); } if(groupTwoLevelMap.get(twoMapKey) == null){ parentId = groupOneLevelMap.get(oneMapKey).getGroupId(); this.handleTwoLevelGroup(parentId, nowDate, regionMap, groupTwoLevelMap, labelMap, twoMapKey, completionVO); } if (groupThreeLevelMap.get(threeMapKey) == null) { parentId = groupTwoLevelMap.get(twoMapKey).getGroupId(); this.handleThreeLevelGroup(parentId, nowDate, regionMap, groupThreeLevelMap, labelMap, threeMapKey, completionVO); } } else if (HsgdBaseGroupLevelEnum.FOUR.getGroupLevel().equals(completionVO.getGroupLevel())) { oneMapKey = completionVO.getLevelOneGroup(); twoMapKey = completionVO.getLevelTwoGroup(); threeMapKey = completionVO.getLevelThreeGroup(); fourMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup(); if (groupOneLevelMap.get(oneMapKey) == null) { this.handleOneLevelGroup(nowDate, regionMap, groupOneLevelMap, labelMap, oneMapKey, completionVO); } if(groupTwoLevelMap.get(twoMapKey) == null){ parentId = groupOneLevelMap.get(oneMapKey).getGroupId(); this.handleTwoLevelGroup(parentId, nowDate, regionMap, groupTwoLevelMap, labelMap, twoMapKey, completionVO); } if (groupThreeLevelMap.get(threeMapKey) == null) { parentId = groupTwoLevelMap.get(twoMapKey).getGroupId(); this.handleThreeLevelGroup(parentId, nowDate, regionMap, groupThreeLevelMap, labelMap, threeMapKey, completionVO); } if(groupFourLevelMap.get(fourMapKey) == null){ parentId = groupThreeLevelMap.get(threeMapKey).getGroupId(); this.handleFourLevelGroup(parentId, nowDate, regionMap, groupFourLevelMap, labelMap, fourMapKey, completionVO); } } else if (HsgdBaseGroupLevelEnum.FIVE.getGroupLevel().equals(completionVO.getGroupLevel())) { oneMapKey = completionVO.getLevelOneGroup(); twoMapKey = completionVO.getLevelTwoGroup(); threeMapKey = completionVO.getLevelThreeGroup(); fourMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup(); fiveMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup() + "-" + completionVO.getLevelFiveGroup(); if (groupOneLevelMap.get(oneMapKey) == null) { this.handleOneLevelGroup(nowDate, regionMap, groupOneLevelMap, labelMap, oneMapKey, completionVO); } if(groupTwoLevelMap.get(twoMapKey) == null){ parentId = groupOneLevelMap.get(oneMapKey).getGroupId(); this.handleTwoLevelGroup(parentId, nowDate, regionMap, groupTwoLevelMap, labelMap, twoMapKey, completionVO); } if (groupThreeLevelMap.get(threeMapKey) == null) { parentId = groupTwoLevelMap.get(twoMapKey).getGroupId(); this.handleThreeLevelGroup(parentId, nowDate, regionMap, groupThreeLevelMap, labelMap, threeMapKey, completionVO); } if(groupFourLevelMap.get(fourMapKey) == null){ parentId = groupThreeLevelMap.get(threeMapKey).getGroupId(); this.handleFourLevelGroup(parentId, nowDate, regionMap, groupFourLevelMap, labelMap, fourMapKey, completionVO); } if(groupFiveLevelMap.get(fiveMapKey) == null){ parentId = groupFourLevelMap.get(fourMapKey).getGroupId(); this.handleFiveLevelGroup(parentId, nowDate, regionMap, groupFiveLevelMap, labelMap, fiveMapKey, completionVO); } } else if (HsgdBaseGroupLevelEnum.SIX.getGroupLevel().equals(completionVO.getGroupLevel())) { oneMapKey = completionVO.getLevelOneGroup(); twoMapKey = completionVO.getLevelTwoGroup(); threeMapKey = completionVO.getLevelThreeGroup(); fourMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup(); fiveMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup() + "-" + completionVO.getLevelFiveGroup(); sixMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup() + "-" + completionVO.getLevelFiveGroup() + "-" + completionVO.getLevelSixGroup(); if (groupOneLevelMap.get(oneMapKey) == null) { this.handleOneLevelGroup(nowDate, regionMap, groupOneLevelMap, labelMap, oneMapKey, completionVO); } if(groupTwoLevelMap.get(twoMapKey) == null){ parentId = groupOneLevelMap.get(oneMapKey).getGroupId(); this.handleTwoLevelGroup(parentId, nowDate, regionMap, groupTwoLevelMap, labelMap, twoMapKey, completionVO); } if (groupThreeLevelMap.get(threeMapKey) == null) { parentId = groupTwoLevelMap.get(twoMapKey).getGroupId(); this.handleThreeLevelGroup(parentId, nowDate, regionMap, groupThreeLevelMap, labelMap, threeMapKey, completionVO); } if(groupFourLevelMap.get(fourMapKey) == null){ parentId = groupThreeLevelMap.get(threeMapKey).getGroupId(); this.handleFourLevelGroup(parentId, nowDate, regionMap, groupFourLevelMap, labelMap, fourMapKey, completionVO); } if(groupFiveLevelMap.get(fiveMapKey) == null){ parentId = groupFourLevelMap.get(fourMapKey).getGroupId(); this.handleFiveLevelGroup(parentId, nowDate, regionMap, groupFiveLevelMap, labelMap, fiveMapKey, completionVO); } if(groupSixLevelMap.get(sixMapKey) == null){ parentId = groupFiveLevelMap.get(fiveMapKey).getGroupId(); this.handleSixLevelGroup(parentId, nowDate, regionMap, groupSixLevelMap, labelMap, sixMapKey, completionVO); } } else if (HsgdBaseGroupLevelEnum.SEVEN.getGroupLevel().equals(completionVO.getGroupLevel())) { oneMapKey = completionVO.getLevelOneGroup(); twoMapKey = completionVO.getLevelTwoGroup(); threeMapKey = completionVO.getLevelThreeGroup(); fourMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup(); fiveMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup() + "-" + completionVO.getLevelFiveGroup(); sixMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup() + "-" + completionVO.getLevelFiveGroup() + "-" + completionVO.getLevelSixGroup(); sevenMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup() + "-" + completionVO.getLevelFiveGroup() + "-" + completionVO.getLevelSixGroup() + "-" + completionVO.getLevelSevenGroup(); if (groupOneLevelMap.get(oneMapKey) == null) { this.handleOneLevelGroup(nowDate, regionMap, groupOneLevelMap, labelMap, oneMapKey, completionVO); } if(groupTwoLevelMap.get(twoMapKey) == null){ parentId = groupOneLevelMap.get(oneMapKey).getGroupId(); this.handleTwoLevelGroup(parentId, nowDate, regionMap, groupTwoLevelMap, labelMap, twoMapKey, completionVO); } if (groupThreeLevelMap.get(threeMapKey) == null) { parentId = groupTwoLevelMap.get(twoMapKey).getGroupId(); this.handleThreeLevelGroup(parentId, nowDate, regionMap, groupThreeLevelMap, labelMap, threeMapKey, completionVO); } if(groupFourLevelMap.get(fourMapKey) == null){ parentId = groupThreeLevelMap.get(threeMapKey).getGroupId(); this.handleFourLevelGroup(parentId, nowDate, regionMap, groupFourLevelMap, labelMap, fourMapKey, completionVO); } if(groupFiveLevelMap.get(fiveMapKey) == null){ parentId = groupFourLevelMap.get(fourMapKey).getGroupId(); this.handleFiveLevelGroup(parentId, nowDate, regionMap, groupFiveLevelMap, labelMap, fiveMapKey, completionVO); } if(groupSixLevelMap.get(sixMapKey) == null){ parentId = groupFiveLevelMap.get(fiveMapKey).getGroupId(); this.handleSixLevelGroup(parentId, nowDate, regionMap, groupSixLevelMap, labelMap, sixMapKey, completionVO); } if(groupSevenLevelMap.get(sevenMapKey) == null){ parentId = groupSixLevelMap.get(sixMapKey).getGroupId(); this.handleSevenLevelGroup(parentId, nowDate, regionMap, groupSevenLevelMap, labelMap, sevenMapKey, completionVO); } } else if (HsgdBaseGroupLevelEnum.EIGHT.getGroupLevel().equals(completionVO.getGroupLevel())) { oneMapKey = completionVO.getLevelOneGroup(); twoMapKey = completionVO.getLevelTwoGroup(); threeMapKey = completionVO.getLevelThreeGroup(); fourMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup(); fiveMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup() + "-" + completionVO.getLevelFiveGroup(); sixMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup() + "-" + completionVO.getLevelFiveGroup() + "-" + completionVO.getLevelSixGroup(); sevenMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup() + "-" + completionVO.getLevelFiveGroup() + "-" + completionVO.getLevelSixGroup() + "-" + completionVO.getLevelSevenGroup(); eightMapKey = completionVO.getLevelThreeGroup() + "-" + completionVO.getLevelFourGroup() + "-" + completionVO.getLevelFiveGroup() + "-" + completionVO.getLevelSixGroup() + "-" + completionVO.getLevelSevenGroup() + "-" + completionVO.getLevelEightGroup(); if (groupOneLevelMap.get(oneMapKey) == null) { this.handleOneLevelGroup(nowDate, regionMap, groupOneLevelMap, labelMap, oneMapKey, completionVO); } if(groupTwoLevelMap.get(twoMapKey) == null){ parentId = groupOneLevelMap.get(oneMapKey).getGroupId(); this.handleTwoLevelGroup(parentId, nowDate, regionMap, groupTwoLevelMap, labelMap, twoMapKey, completionVO); } if (groupThreeLevelMap.get(threeMapKey) == null) { parentId = groupTwoLevelMap.get(twoMapKey).getGroupId(); this.handleThreeLevelGroup(parentId, nowDate, regionMap, groupThreeLevelMap, labelMap, threeMapKey, completionVO); } if(groupFourLevelMap.get(fourMapKey) == null){ parentId = groupThreeLevelMap.get(threeMapKey).getGroupId(); this.handleFourLevelGroup(parentId, nowDate, regionMap, groupFourLevelMap, labelMap, fourMapKey, completionVO); } if(groupFiveLevelMap.get(fiveMapKey) == null){ parentId = groupFourLevelMap.get(fourMapKey).getGroupId(); this.handleFiveLevelGroup(parentId, nowDate, regionMap, groupFiveLevelMap, labelMap, fiveMapKey, completionVO); } if(groupSixLevelMap.get(sixMapKey) == null){ parentId = groupFiveLevelMap.get(fiveMapKey).getGroupId(); this.handleSixLevelGroup(parentId, nowDate, regionMap, groupSixLevelMap, labelMap, sixMapKey, completionVO); } if(groupSevenLevelMap.get(sevenMapKey) == null){ parentId = groupSixLevelMap.get(sixMapKey).getGroupId(); this.handleSevenLevelGroup(parentId, nowDate, regionMap, groupSevenLevelMap, labelMap, sevenMapKey, completionVO); } if(groupEightLevelMap.get(eightMapKey) == null){ parentId = groupSevenLevelMap.get(sevenMapKey).getGroupId(); this.handleEightLevelGroup(parentId, nowDate, regionMap, groupEightLevelMap, labelMap, eightMapKey, completionVO); } } } catch (Exception e) { log.info("组织"+JsonUtil.toJSONString(completionVO)+"导入失败",e); log.info("组织{}导入失败", JsonUtil.toJSONString(completionVO)); notImportRecord = new HsgdBaseGroupNotImportRecord(); BeanUtils.copyProperties(completionVO,notImportRecord); errorRecordList.add(notImportRecord); } } if(CollectionUtils.isNotEmpty(errorRecordList)){ iHsgdBaseGroupNotImportRecordService.saveBatch(errorRecordList); } } } } } @Override public void insert(HsgdBaseGroupImportRecord record) { hsgdBaseGroupImportRecordMapper.insert(record); } @Override @Transactional(rollbackFor = Exception.class) public void batchInsertAll(List<HsgdBaseGroupImportRecord> recordList) { hsgdBaseGroupImportRecordMapper.insertAll(recordList); } private void getPageAllRegionToRegionMap(Map<String, CrmRegion> regionMap, List<HsgdBaseGroupImportCompletion> importCompletionList) { if (CollectionUtils.isNotEmpty(importCompletionList)) { List<String> regionInfoList = new ArrayList<>(); for (HsgdBaseGroupImportCompletion completionData : importCompletionList) { if(StringUtils.isNotBlank(completionData.getGroupRegion())){ List<String> regionList = Arrays.asList(completionData.getGroupRegion().split(",")); for ( String regionCode : regionList){ if(regionMap.get(regionCode) == null){ regionInfoList.add(regionCode); } } } } if(CollectionUtils.isNotEmpty(regionInfoList)){ List<CrmRegion> regions = crmRegionMapper.selectCrmRegionsByCodes(regionInfoList); for ( CrmRegion crmRegion : regions){ regionMap.put(crmRegion.getRegionCode(),crmRegion); } } } } @Override public HsgdBaseGroupSimpleVO getGroupSimpleByGroupNameAndParentIdAndLevel(String levelGroupName, Long groupId, Integer groupLevel) { return hsgdBaseGroupMapper.getGroupSimpleByGroupNameAndParentIdAndLevel(levelGroupName,groupId, groupLevel); } private HsgdBaseGroupSimpleVO generatorGroupLevel(HsgdBaseGroupImportCompletion completionVO, Date nowDate, Map<String, Long> labelMap, Map<String, CrmRegion> regionMap, Long parentId) { HsgdBaseGroupSimpleVO resultVo = new HsgdBaseGroupSimpleVO(); Long parentIdTop = 0L; Integer recordStatus = 1; Integer level = completionVO.getGroupLevel(); // 表HSGD_BASE_GROUP HsgdBaseGroup hsgdBaseGroup = new HsgdBaseGroup(); hsgdBaseGroup.setGroupName(this.getGroupNameByLevel(completionVO)); if(HsgdBaseGroupLevelEnum.ONE.getGroupLevel().equals(level)){ hsgdBaseGroup.setParentId(parentIdTop); }else { hsgdBaseGroup.setParentId(parentId); } hsgdBaseGroup.setStatus(recordStatus); hsgdBaseGroup.setCreated(nowDate); hsgdBaseGroup.setCreatedBy(SYSTEM_USER_NAME); hsgdBaseGroup.setUpdated(nowDate); hsgdBaseGroup.setUpdatedBy(SYSTEM_USER_NAME); hsgdBaseGroupMapper.insert(hsgdBaseGroup); long groupId = hsgdBaseGroup.getId(); resultVo.setGroupId(groupId); resultVo.setGroupName(hsgdBaseGroup.getGroupName()); resultVo.setParentId(hsgdBaseGroup.getParentId()); resultVo.setGroupLevel(level); // 表HSGD_BASE_GROUP_INFO HsgdBaseGroupInfo hsgdBaseGroupInfo = new HsgdBaseGroupInfo(); hsgdBaseGroupInfo.setGroupId(groupId); hsgdBaseGroupInfo.setStatus(recordStatus); hsgdBaseGroupInfo.setGroupLevel(completionVO.getGroupLevel()); hsgdBaseGroupInfo.setGroupLevelInfo(getGroupLevelInfoByLevel(completionVO)); hsgdBaseGroupInfo.setRegionFlag(0); if(StringUtils.isNotBlank(completionVO.getGroupRegion())){ hsgdBaseGroupInfo.setRegionFlag(1); } hsgdBaseGroupInfo.setCustomerNumber(0); hsgdBaseGroupInfo.setEmployeeNumber(0); hsgdBaseGroupInfo.setCreated(nowDate); hsgdBaseGroupInfo.setCreatedBy(SYSTEM_USER_NAME); hsgdBaseGroupInfo.setUpdated(nowDate); hsgdBaseGroupInfo.setUpdatedBy(SYSTEM_USER_NAME); hsgdBaseGroupInfoMapper.insert(hsgdBaseGroupInfo); // 表 HSGD_BASE_GROUP_LABEL if(StringUtils.isNotBlank(completionVO.getGroupLabel())){ HsgdBaseGroupLabel hsgdBaseGroupLabel = new HsgdBaseGroupLabel(); hsgdBaseGroupLabel.setGroupId(groupId); hsgdBaseGroupLabel.setLabelId(labelMap.get(completionVO.getGroupLabel())); hsgdBaseGroupLabel.setCreated(nowDate); hsgdBaseGroupLabel.setCreatedBy(SYSTEM_USER_NAME); hsgdBaseGroupLabel.setUpdated(nowDate); hsgdBaseGroupLabel.setUpdatedBy(SYSTEM_USER_NAME); hsgdBaseGroupLabelMapper.insert(hsgdBaseGroupLabel); } if(StringUtils.isNotBlank(completionVO.getGroupRegion())){ List<String> regionCodeList = Arrays.asList(completionVO.getGroupRegion().split(",")); List<HsgdBaseGroupRegion> regionList = new ArrayList<>(); HsgdBaseGroupRegion region = null; for (String regionCode : regionCodeList ){ region = new HsgdBaseGroupRegion(); region.setGroupId(groupId); region.setGroupName(hsgdBaseGroup.getGroupName()); region.setStatus(recordStatus); CrmRegion crmRegion = regionMap.get(regionCode); if(crmRegion !=null){ region.setProvinceCode(crmRegion.getProvinceCode()); region.setCityCode(crmRegion.getCityCode()); region.setCountyCode(crmRegion.getCountyCode()); } region.setRegionCode(regionCode); region.setStatus(recordStatus); region.setCreated(nowDate); region.setCreatedBy(SYSTEM_USER_NAME); region.setUpdated(nowDate); region.setUpdatedBy(SYSTEM_USER_NAME); regionList.add(region); } hsgdBaseGroupRegionMapper.batchInsert(regionList); } return resultVo; } @Override public HsgdBaseGroupSimpleVO getGroupSimpleByGroupNameAndLevel(String levelGroupName, Integer groupLevel) { return hsgdBaseGroupMapper.selectByGroupNameAndLevel(levelGroupName, groupLevel); } @Override public HsgdBaseGroupSimpleVO getGroupSimpleByGroupNameAndLevelAndParentId(String levelGroupName, Integer groupLevel,Long parentId) { return hsgdBaseGroupMapper.selectByGroupNameAndLevelAndParentId(levelGroupName, groupLevel,parentId); } public Map<String,Long> getGroupLabelMap(){ QueryWrapper<HsgdBaseGroupLabelDict> queryWrapper = new QueryWrapper<>(); queryWrapper.orderByAsc("ID"); List<HsgdBaseGroupLabelDict> labelList = hsgdBaseGroupLabelDictMapper.selectList(queryWrapper); Map<String,Long> labelMap = labelList.stream().collect(Collectors.toMap(HsgdBaseGroupLabelDict::getLabelName,HsgdBaseGroupLabelDict::getId,(key1,key2)-> key2)); return labelMap; } private HsgdBaseGroupSimpleVO generatorGroupLevelNew(HsgdBaseGroupImportCompletion completionVO, Date nowDate, Map<String, Long> labelMap, Map<String, CrmRegion> regionMap, Long parentId,Integer groupLevel) { HsgdBaseGroupSimpleVO resultVo = new HsgdBaseGroupSimpleVO(); Integer recordStatus = 1; Integer createSource = 1; Long userId = -1L; // 表HSGD_BASE_GROUP HsgdBaseGroup hsgdBaseGroup = new HsgdBaseGroup(); hsgdBaseGroup.setGroupName(this.getGroupNameByLevelNew(completionVO, groupLevel)); hsgdBaseGroup.setParentId(parentId); hsgdBaseGroup.setStatus(recordStatus); hsgdBaseGroup.setCreated(nowDate); hsgdBaseGroup.setCreatedBy(SYSTEM_USER_NAME); hsgdBaseGroup.setCreatedById(userId); hsgdBaseGroup.setCreatedSource(createSource); hsgdBaseGroup.setUpdated(nowDate); hsgdBaseGroup.setUpdatedBy(SYSTEM_USER_NAME); hsgdBaseGroup.setUpdatedById(userId); hsgdBaseGroup.setUpdatedSource(createSource); hsgdBaseGroupMapper.insert(hsgdBaseGroup); long groupId = hsgdBaseGroup.getId(); resultVo.setGroupId(groupId); resultVo.setGroupName(hsgdBaseGroup.getGroupName()); resultVo.setParentId(hsgdBaseGroup.getParentId()); resultVo.setGroupLevel(groupLevel); // 表HSGD_BASE_GROUP_INFO HsgdBaseGroupInfo hsgdBaseGroupInfo = new HsgdBaseGroupInfo(); hsgdBaseGroupInfo.setGroupId(groupId); hsgdBaseGroupInfo.setGroupLevelInfo(getGroupLevelInfoByLevelNew(completionVO,groupLevel)); hsgdBaseGroupInfo.setRegionFlag(0); if(completionVO.getGroupLevel().equals(groupLevel)) { if (StringUtils.isNotBlank(completionVO.getGroupRegion())) { hsgdBaseGroupInfo.setRegionFlag(1); } } hsgdBaseGroupInfo.setStatus(recordStatus); hsgdBaseGroupInfo.setCustomerNumber(0); hsgdBaseGroupInfo.setEmployeeNumber(0); hsgdBaseGroupInfo.setCreated(nowDate); hsgdBaseGroupInfo.setCreatedBy(SYSTEM_USER_NAME); hsgdBaseGroupInfo.setCreatedById(userId); hsgdBaseGroupInfo.setUpdated(nowDate); hsgdBaseGroupInfo.setUpdatedBy(SYSTEM_USER_NAME); hsgdBaseGroupInfo.setUpdatedById(userId); hsgdBaseGroupInfo.setGroupLevel(groupLevel); hsgdBaseGroupInfoMapper.insert(hsgdBaseGroupInfo); if(completionVO.getGroupLevel().equals(groupLevel)){ // 表 HSGD_BASE_GROUP_LABEL if(StringUtils.isNotBlank(completionVO.getGroupLabel())){ HsgdBaseGroupLabel hsgdBaseGroupLabel = new HsgdBaseGroupLabel(); hsgdBaseGroupLabel.setGroupId(groupId); hsgdBaseGroupLabel.setLabelId(labelMap.get(completionVO.getGroupLabel())); hsgdBaseGroupLabel.setCreated(nowDate); hsgdBaseGroupLabel.setCreatedBy(SYSTEM_USER_NAME); hsgdBaseGroupLabel.setCreatedById(userId); hsgdBaseGroupLabel.setUpdated(nowDate); hsgdBaseGroupLabel.setUpdatedBy(SYSTEM_USER_NAME); hsgdBaseGroupLabel.setUpdatedById(userId); hsgdBaseGroupLabelMapper.insert(hsgdBaseGroupLabel); } if (StringUtils.isNotBlank(completionVO.getGroupRegion())) { List<String> regionCodeList = Arrays.asList(completionVO.getGroupRegion().split(",")); List<HsgdBaseGroupRegion> regionList = new ArrayList<>(); HsgdBaseGroupRegion region; for (String regionCode : regionCodeList) { region = new HsgdBaseGroupRegion(); region.setGroupName(hsgdBaseGroup.getGroupName()); region.setGroupId(groupId); region.setRegionCode(regionCode); CrmRegion crmRegion = regionMap.get(regionCode); if (crmRegion != null) { region.setProvinceCode(crmRegion.getProvinceCode()); region.setCityCode(crmRegion.getCityCode()); region.setCountyCode(crmRegion.getCountyCode()); } region.setStatus(recordStatus); region.setCreated(nowDate); region.setCreatedBy(SYSTEM_USER_NAME); region.setCreatedById(userId); region.setUpdated(nowDate); region.setUpdatedBy(SYSTEM_USER_NAME); region.setUpdatedById(userId); regionList.add(region); } hsgdBaseGroupRegionMapper.batchInsert(regionList); } } return resultVo; } public String getGroupNameByLevel(HsgdBaseGroupImportCompletion completionVO) { Integer level = completionVO.getGroupLevel(); String groupName = ""; if (HsgdBaseGroupLevelEnum.ONE.getGroupLevel().equals(level)) { groupName = completionVO.getLevelOneGroup(); } else if (HsgdBaseGroupLevelEnum.TWO.getGroupLevel().equals(level)) { groupName = completionVO.getLevelTwoGroup(); } else if (HsgdBaseGroupLevelEnum.THREE.getGroupLevel().equals(level)) { groupName = completionVO.getLevelThreeGroup(); } else if (HsgdBaseGroupLevelEnum.FOUR.getGroupLevel().equals(level)) { groupName = completionVO.getLevelFourGroup(); } else if (HsgdBaseGroupLevelEnum.FIVE.getGroupLevel().equals(level)) { groupName = completionVO.getLevelFiveGroup(); } else if (HsgdBaseGroupLevelEnum.SIX.getGroupLevel().equals(level)) { groupName = completionVO.getLevelSixGroup(); } else if (HsgdBaseGroupLevelEnum.SEVEN.getGroupLevel().equals(level)) { groupName = completionVO.getLevelSevenGroup(); } else if (HsgdBaseGroupLevelEnum.EIGHT.getGroupLevel().equals(level)) { groupName = completionVO.getLevelEightGroup(); } return groupName; } public String getGroupNameByLevelNew(HsgdBaseGroupImportCompletion completionVO,Integer groupLevel) { Integer level = groupLevel; String groupName = ""; if (HsgdBaseGroupLevelEnum.ONE.getGroupLevel().equals(level)) { groupName = completionVO.getLevelOneGroup(); } else if (HsgdBaseGroupLevelEnum.TWO.getGroupLevel().equals(level)) { groupName = completionVO.getLevelTwoGroup(); } else if (HsgdBaseGroupLevelEnum.THREE.getGroupLevel().equals(level)) { groupName = completionVO.getLevelThreeGroup(); } else if (HsgdBaseGroupLevelEnum.FOUR.getGroupLevel().equals(level)) { groupName = completionVO.getLevelFourGroup(); } else if (HsgdBaseGroupLevelEnum.FIVE.getGroupLevel().equals(level)) { groupName = completionVO.getLevelFiveGroup(); } else if (HsgdBaseGroupLevelEnum.SIX.getGroupLevel().equals(level)) { groupName = completionVO.getLevelSixGroup(); } else if (HsgdBaseGroupLevelEnum.SEVEN.getGroupLevel().equals(level)) { groupName = completionVO.getLevelSevenGroup(); } else if (HsgdBaseGroupLevelEnum.EIGHT.getGroupLevel().equals(level)) { groupName = completionVO.getLevelEightGroup(); } return groupName; } public String getGroupLevelInfoByLevel(HsgdBaseGroupImportCompletion completionVO) { Integer level = completionVO.getGroupLevel(); String groupLevelInfoName = ""; if (HsgdBaseGroupLevelEnum.ONE.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup(); } else if (HsgdBaseGroupLevelEnum.TWO.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup(); } else if (HsgdBaseGroupLevelEnum.THREE.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup() + "->" + completionVO.getLevelThreeGroup(); } else if (HsgdBaseGroupLevelEnum.FOUR.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup() + "->" + completionVO.getLevelThreeGroup() + "->" + completionVO.getLevelFourGroup(); } else if (HsgdBaseGroupLevelEnum.FIVE.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup() + "->" + completionVO.getLevelThreeGroup() + "->" + completionVO.getLevelFourGroup() + "->" + completionVO.getLevelFiveGroup(); } else if (HsgdBaseGroupLevelEnum.SIX.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup() + "->" + completionVO.getLevelThreeGroup() + "->" + completionVO.getLevelFourGroup() + "->" + completionVO.getLevelFiveGroup() + "->" + completionVO.getLevelSixGroup(); } else if (HsgdBaseGroupLevelEnum.SEVEN.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup() + "->" + completionVO.getLevelThreeGroup() + "->" + completionVO.getLevelFourGroup() + "->" + completionVO.getLevelFiveGroup() + "->" + completionVO.getLevelSixGroup() + "->" + completionVO.getLevelSevenGroup(); } else if (HsgdBaseGroupLevelEnum.EIGHT.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup() + "->" + completionVO.getLevelThreeGroup() + "->" + completionVO.getLevelFourGroup() + "->" + completionVO.getLevelFiveGroup() + "->" + completionVO.getLevelSixGroup() + "->" + completionVO.getLevelSevenGroup() + "->" + completionVO.getLevelEightGroup(); } return groupLevelInfoName; } public String getGroupLevelInfoByLevelNew(HsgdBaseGroupImportCompletion completionVO,Integer groupLevel) { Integer level = groupLevel; String groupLevelInfoName = ""; if (HsgdBaseGroupLevelEnum.ONE.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup(); } else if (HsgdBaseGroupLevelEnum.TWO.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup(); } else if (HsgdBaseGroupLevelEnum.THREE.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup() + "->" + completionVO.getLevelThreeGroup(); } else if (HsgdBaseGroupLevelEnum.FOUR.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup() + "->" + completionVO.getLevelThreeGroup() + "->" + completionVO.getLevelFourGroup(); } else if (HsgdBaseGroupLevelEnum.FIVE.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup() + "->" + completionVO.getLevelThreeGroup() + "->" + completionVO.getLevelFourGroup() + "->" + completionVO.getLevelFiveGroup(); } else if (HsgdBaseGroupLevelEnum.SIX.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup() + "->" + completionVO.getLevelThreeGroup() + "->" + completionVO.getLevelFourGroup() + "->" + completionVO.getLevelFiveGroup() + "->" + completionVO.getLevelSixGroup(); } else if (HsgdBaseGroupLevelEnum.SEVEN.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup() + "->" + completionVO.getLevelThreeGroup() + "->" + completionVO.getLevelFourGroup() + "->" + completionVO.getLevelFiveGroup() + "->" + completionVO.getLevelSixGroup() + "->" + completionVO.getLevelSevenGroup(); } else if (HsgdBaseGroupLevelEnum.EIGHT.getGroupLevel().equals(level)) { groupLevelInfoName = completionVO.getLevelOneGroup() + "->" + completionVO.getLevelTwoGroup() + "->" + completionVO.getLevelThreeGroup() + "->" + completionVO.getLevelFourGroup() + "->" + completionVO.getLevelFiveGroup() + "->" + completionVO.getLevelSixGroup() + "->" + completionVO.getLevelSevenGroup() + "->" + completionVO.getLevelEightGroup(); } return groupLevelInfoName; } /** * 生成一级组织 */ private void handleOneLevelGroup(Date nowDate, Map<String, CrmRegion> regionMap, Map<String, HsgdBaseGroupSimpleVO> groupOneLevelMap, Map<String, Long> labelMap, String oneMapKey, HsgdBaseGroupImportCompletion completionVO) { HsgdBaseGroupSimpleVO simpleOneVO = this.getGroupSimpleByGroupNameAndLevel(completionVO.getLevelOneGroup(), HsgdBaseGroupLevelEnum.ONE.getGroupLevel()); if (simpleOneVO != null) { this.updateGroupLabelAndRegion(simpleOneVO,completionVO,labelMap,regionMap,nowDate,HsgdBaseGroupLevelEnum.ONE.getGroupLevel()); groupOneLevelMap.put(oneMapKey, simpleOneVO); } else { simpleOneVO = this.generatorGroupLevelNew(completionVO, nowDate, labelMap, regionMap, null, HsgdBaseGroupLevelEnum.ONE.getGroupLevel()); groupOneLevelMap.put(oneMapKey, simpleOneVO); } } // 生成二级组织 private void handleTwoLevelGroup(Long parentId, Date nowDate, Map<String, CrmRegion> regionMap, Map<String, HsgdBaseGroupSimpleVO> groupTwoLevelMap, Map<String, Long> labelMap, String twoMapKey, HsgdBaseGroupImportCompletion completionVO) { HsgdBaseGroupSimpleVO simpleTwoVO = this.getGroupSimpleByGroupNameAndLevel(completionVO.getLevelTwoGroup(), HsgdBaseGroupLevelEnum.TWO.getGroupLevel()); if (simpleTwoVO != null) { this.updateGroupLabelAndRegion(simpleTwoVO,completionVO,labelMap,regionMap,nowDate,HsgdBaseGroupLevelEnum.TWO.getGroupLevel()); groupTwoLevelMap.put(twoMapKey, simpleTwoVO); } else { simpleTwoVO = this.generatorGroupLevelNew(completionVO, nowDate, labelMap, regionMap, parentId, HsgdBaseGroupLevelEnum.TWO.getGroupLevel()); groupTwoLevelMap.put(twoMapKey, simpleTwoVO); } } // 生成三级组织 private void handleThreeLevelGroup(Long parentId, Date nowDate, Map<String, CrmRegion> regionMap, Map<String, HsgdBaseGroupSimpleVO> groupThreeLevelMap, Map<String, Long> labelMap, String threeMapKey, HsgdBaseGroupImportCompletion completionVO) { HsgdBaseGroupSimpleVO simpleThreeVO = this.getGroupSimpleByGroupNameAndLevel(completionVO.getLevelThreeGroup(), HsgdBaseGroupLevelEnum.THREE.getGroupLevel()); if (simpleThreeVO != null) { this.updateGroupLabelAndRegion(simpleThreeVO,completionVO,labelMap,regionMap,nowDate,HsgdBaseGroupLevelEnum.THREE.getGroupLevel()); groupThreeLevelMap.put(threeMapKey, simpleThreeVO); } else { simpleThreeVO = this.generatorGroupLevelNew(completionVO, nowDate, labelMap, regionMap, parentId, HsgdBaseGroupLevelEnum.THREE.getGroupLevel()); groupThreeLevelMap.put(threeMapKey, simpleThreeVO); } } // 生成四级组织 private void handleFourLevelGroup(Long parentId, Date nowDate, Map<String, CrmRegion> regionMap, Map<String, HsgdBaseGroupSimpleVO> groupFourLevelMap, Map<String, Long> labelMap, String fourMapKey, HsgdBaseGroupImportCompletion completionVO) { HsgdBaseGroupSimpleVO simpleFourVO = this.getGroupSimpleByGroupNameAndLevelAndParentId(completionVO.getLevelFourGroup(), HsgdBaseGroupLevelEnum.FOUR.getGroupLevel(),parentId); if (simpleFourVO != null) { this.updateGroupLabelAndRegion(simpleFourVO,completionVO,labelMap,regionMap,nowDate,HsgdBaseGroupLevelEnum.FOUR.getGroupLevel()); groupFourLevelMap.put(fourMapKey, simpleFourVO); } else { simpleFourVO = this.generatorGroupLevelNew(completionVO, nowDate, labelMap, regionMap, parentId, HsgdBaseGroupLevelEnum.FOUR.getGroupLevel()); groupFourLevelMap.put(fourMapKey, simpleFourVO); } } // 生成五级组织 private void handleFiveLevelGroup(Long parentId, Date nowDate, Map<String, CrmRegion> regionMap, Map<String, HsgdBaseGroupSimpleVO> groupFiveLevelMap, Map<String, Long> labelMap, String fiveMapKey, HsgdBaseGroupImportCompletion completionVO) { HsgdBaseGroupSimpleVO simpleFiveVO = this.getGroupSimpleByGroupNameAndLevelAndParentId(completionVO.getLevelFiveGroup(), HsgdBaseGroupLevelEnum.FIVE.getGroupLevel(),parentId); if (simpleFiveVO != null) { this.updateGroupLabelAndRegion(simpleFiveVO,completionVO,labelMap,regionMap,nowDate,HsgdBaseGroupLevelEnum.FIVE.getGroupLevel()); groupFiveLevelMap.put(fiveMapKey, simpleFiveVO); } else { simpleFiveVO = this.generatorGroupLevelNew(completionVO, nowDate, labelMap, regionMap, parentId, HsgdBaseGroupLevelEnum.FIVE.getGroupLevel()); groupFiveLevelMap.put(fiveMapKey, simpleFiveVO); } } // 生成六级组织 private void handleSixLevelGroup(Long parentId, Date nowDate, Map<String, CrmRegion> regionMap, Map<String, HsgdBaseGroupSimpleVO> groupSixLevelMap, Map<String, Long> labelMap, String sixMapKey, HsgdBaseGroupImportCompletion completionVO) { HsgdBaseGroupSimpleVO simpleSixVO = this.getGroupSimpleByGroupNameAndLevelAndParentId(completionVO.getLevelSixGroup(), HsgdBaseGroupLevelEnum.SIX.getGroupLevel(), parentId); if (simpleSixVO != null) { this.updateGroupLabelAndRegion(simpleSixVO,completionVO,labelMap,regionMap,nowDate,HsgdBaseGroupLevelEnum.SIX.getGroupLevel()); groupSixLevelMap.put(sixMapKey, simpleSixVO); } else { simpleSixVO = this.generatorGroupLevelNew(completionVO, nowDate, labelMap, regionMap, parentId, HsgdBaseGroupLevelEnum.SIX.getGroupLevel()); groupSixLevelMap.put(sixMapKey, simpleSixVO); } } // 生成七级组织 private void handleSevenLevelGroup(Long parentId, Date nowDate, Map<String, CrmRegion> regionMap, Map<String, HsgdBaseGroupSimpleVO> groupSevenLevelMap, Map<String, Long> labelMap, String sevenMapKey, HsgdBaseGroupImportCompletion completionVO) { HsgdBaseGroupSimpleVO simpleSevenVO = this.getGroupSimpleByGroupNameAndLevelAndParentId(completionVO.getLevelSevenGroup(), HsgdBaseGroupLevelEnum.SEVEN.getGroupLevel(), parentId); if (simpleSevenVO != null) { this.updateGroupLabelAndRegion(simpleSevenVO,completionVO,labelMap,regionMap,nowDate,HsgdBaseGroupLevelEnum.SEVEN.getGroupLevel()); groupSevenLevelMap.put(sevenMapKey, simpleSevenVO); } else { simpleSevenVO = this.generatorGroupLevelNew(completionVO, nowDate, labelMap, regionMap, parentId, HsgdBaseGroupLevelEnum.SEVEN.getGroupLevel()); groupSevenLevelMap.put(sevenMapKey, simpleSevenVO); } } // 生成八级组织 private void handleEightLevelGroup(Long parentId, Date nowDate, Map<String, CrmRegion> regionMap, Map<String, HsgdBaseGroupSimpleVO> groupEightLevelMap, Map<String, Long> labelMap, String eightMapKey, HsgdBaseGroupImportCompletion completionVO) { HsgdBaseGroupSimpleVO simpleEightVO = this.getGroupSimpleByGroupNameAndLevelAndParentId(completionVO.getLevelEightGroup(), HsgdBaseGroupLevelEnum.EIGHT.getGroupLevel(), parentId); if (simpleEightVO != null) { this.updateGroupLabelAndRegion(simpleEightVO,completionVO,labelMap,regionMap,nowDate,HsgdBaseGroupLevelEnum.EIGHT.getGroupLevel()); groupEightLevelMap.put(eightMapKey, simpleEightVO); } else { simpleEightVO = this.generatorGroupLevelNew(completionVO, nowDate, labelMap, regionMap, parentId, HsgdBaseGroupLevelEnum.EIGHT.getGroupLevel()); groupEightLevelMap.put(eightMapKey, simpleEightVO); } } private void updateGroupLabelAndRegion(HsgdBaseGroupSimpleVO simpleOneVO, HsgdBaseGroupImportCompletion completionVO, Map<String, Long> labelMap, Map<String, CrmRegion> regionMap,Date nowDate,Integer groupLvel) { // 表 HSGD_BASE_GROUP_LABEL Long userId = -1L; Integer recordStatus = 1; Long groupId = simpleOneVO.getGroupId(); if(completionVO.getGroupLevel().equals(groupLvel)){ if(StringUtils.isNotBlank(completionVO.getGroupLabel())){ QueryWrapper<HsgdBaseGroupLabel> queryWrapper = new QueryWrapper(); queryWrapper.eq("GROUP_ID",groupId); Long labelCount = hsgdBaseGroupLabelMapper.selectCount(queryWrapper); if (labelCount > 0) { UpdateWrapper<HsgdBaseGroupLabel> updateWrapper = new UpdateWrapper(); updateWrapper.eq("GROUP_ID",groupId); HsgdBaseGroupLabel updateLabel = new HsgdBaseGroupLabel(); updateLabel.setLabelId(labelMap.get(completionVO.getGroupLabel())); updateLabel.setUpdated(nowDate); updateLabel.setUpdatedBy(SYSTEM_USER_NAME); updateLabel.setUpdatedById(userId); hsgdBaseGroupLabelMapper.update(updateLabel,updateWrapper); } else { HsgdBaseGroupLabel hsgdBaseGroupLabel = new HsgdBaseGroupLabel(); hsgdBaseGroupLabel.setGroupId(groupId); hsgdBaseGroupLabel.setLabelId(labelMap.get(completionVO.getGroupLabel())); hsgdBaseGroupLabel.setCreated(nowDate); hsgdBaseGroupLabel.setCreatedBy(SYSTEM_USER_NAME); hsgdBaseGroupLabel.setCreatedById(userId); hsgdBaseGroupLabel.setUpdated(nowDate); hsgdBaseGroupLabel.setUpdatedBy(SYSTEM_USER_NAME); hsgdBaseGroupLabel.setUpdatedById(userId); hsgdBaseGroupLabelMapper.insert(hsgdBaseGroupLabel); } } if (StringUtils.isNotBlank(completionVO.getGroupRegion())) { List<String> regionCodeList = Arrays.asList(completionVO.getGroupRegion().split(",")); List<HsgdBaseGroupRegion> regionList = new ArrayList<>(); HsgdBaseGroupRegion region; for (String regionCode : regionCodeList) { region = new HsgdBaseGroupRegion(); region.setGroupName(simpleOneVO.getGroupName()); region.setGroupId(groupId); region.setRegionCode(regionCode); CrmRegion crmRegion = regionMap.get(regionCode); if (crmRegion != null) { region.setProvinceCode(crmRegion.getProvinceCode()); region.setCityCode(crmRegion.getCityCode()); region.setCountyCode(crmRegion.getCountyCode()); } region.setStatus(recordStatus); region.setCreated(nowDate); region.setCreatedBy(SYSTEM_USER_NAME); region.setCreatedById(userId); region.setUpdated(nowDate); region.setUpdatedBy(SYSTEM_USER_NAME); region.setUpdatedById(userId); regionList.add(region); } QueryWrapper<HsgdBaseGroupRegion> queryWrapper = new QueryWrapper(); queryWrapper.eq("GROUP_ID",groupId); queryWrapper.eq("STATUS",1); Long existsRegionNum = hsgdBaseGroupRegionMapper.selectCount(queryWrapper); if(existsRegionNum > 0){ UpdateWrapper<HsgdBaseGroupRegion> updateWrapper = new UpdateWrapper(); updateWrapper.eq("GROUP_ID",groupId); HsgdBaseGroupRegion updateRegion = new HsgdBaseGroupRegion(); updateRegion.setStatus(0); updateRegion.setUpdated(nowDate); updateRegion.setUpdatedBy(SYSTEM_USER_NAME); updateRegion.setUpdatedById(userId); hsgdBaseGroupRegionMapper.update(updateRegion,updateWrapper); } hsgdBaseGroupRegionMapper.batchInsert(regionList); } } } }
package com.zhgd.base.listener; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; import com.zhgd.base.domain.model.ZhgdSrGroupImportModel; import com.zhgd.base.service.IZhgdSrBaseGroupImportHandleService; import com.zhgd.common.util.JsonUtil; import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; import java.util.List; @Slf4j public class ZhgdSrBaseGroupImportExcelListener extends AnalysisEventListener<ZhgdSrGroupImportModel> { private List<ZhgdSrGroupImportModel> dataList = new ArrayList<>(); private static final int BATCH_COUNT = 120; private IZhgdSrBaseGroupImportHandleService iZhgdSrBaseGroupImportHandleService; private String batchNo; public ZhgdSrBaseGroupImportExcelListener(IZhgdSrBaseGroupImportHandleService iZhgdSrBaseGroupImportHandleService,String batchNo) { this.iZhgdSrBaseGroupImportHandleService = iZhgdSrBaseGroupImportHandleService; this.batchNo = batchNo; } @Override public void invoke(ZhgdSrGroupImportModel model, AnalysisContext analysisContext) { log.debug("读取数据:{}", JsonUtil.toJSONString(model)); model.setBatchNo(batchNo); dataList.add(model); if(dataList.size() >= BATCH_COUNT){ iZhgdSrBaseGroupImportHandleService.saveSrBaseGroupImportDataList(dataList); dataList.clear(); } } @Override public void doAfterAllAnalysed(AnalysisContext analysisContext) { iZhgdSrBaseGroupImportHandleService.saveSrBaseGroupImportDataList(dataList); dataList.clear(); } }
package com.zhgd.base.service; import com.zhgd.base.domain.model.ZhgdSrGroupImportModel; import com.zhgd.base.entity.HsgdBaseGroupImportCompletion; import java.util.List; public interface IZhgdSrBaseGroupImportHandleService { void saveSrBaseGroupImportDataList(List<ZhgdSrGroupImportModel> dataList); void saveSrBaseGroupImportData(ZhgdSrGroupImportModel dataList); void insertAllImportCompletion(List<HsgdBaseGroupImportCompletion> completionList); }
package com.zhgd.base.service.impl; import com.zhgd.base.domain.model.ZhgdSrGroupImportModel; import com.zhgd.base.entity.HsgdBaseGroupImportCompletion; import com.zhgd.base.entity.HsgdBaseGroupImportRecord; import com.zhgd.base.mapper.HsgdBaseGroupImportCompletionMapper; import com.zhgd.base.service.IZhgdSrBaseGroupImportHandleService; import com.zhgd.base.service.IZhgdSrBaseGroupImportService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; import java.util.List; @Service @Slf4j public class ZhgdSrBaseGroupImportHandleServiceImpl implements IZhgdSrBaseGroupImportHandleService { @Resource private IZhgdSrBaseGroupImportService iZhgdSrBaseGroupImportService; @Resource private HsgdBaseGroupImportCompletionMapper hsgdBaseGroupImportCompletionMapper; @Override public void saveSrBaseGroupImportDataList(List<ZhgdSrGroupImportModel> dataList) { Date nowDate = new Date(); final String userName = "system"; if(CollectionUtils.isNotEmpty(dataList)){ List<HsgdBaseGroupImportRecord> recordList = new ArrayList(); HsgdBaseGroupImportRecord record = null; for (int i=0,len = dataList.size();i< len;i++){ ZhgdSrGroupImportModel importModel = dataList.get(i); record = new HsgdBaseGroupImportRecord(); BeanUtils.copyProperties(importModel,record); record.setCreated(nowDate); record.setCreatedBy(userName); record.setUpdated(nowDate); record.setUpdatedBy(userName); recordList.add(record); }; iZhgdSrBaseGroupImportService.batchInsertAll(recordList); } } @Override public void saveSrBaseGroupImportData(ZhgdSrGroupImportModel data) { Date nowDate = new Date(); final String userName = "system"; if(data != null){ HsgdBaseGroupImportRecord record = new HsgdBaseGroupImportRecord(); BeanUtils.copyProperties(data,record); record.setCreated(nowDate); record.setCreatedBy(userName); record.setUpdated(nowDate); record.setUpdatedBy(userName); iZhgdSrBaseGroupImportService.insert(record); } } @Transactional @Override public void insertAllImportCompletion(List<HsgdBaseGroupImportCompletion> completionList) { hsgdBaseGroupImportCompletionMapper.insertAll(completionList); } }
导入之后
HSGD_BASE_GROUP_IMPORT_RECORD
HSGD_BASE_GROUP_IMPORT_COMPLETION