模板
表结构
HSGD_BASE_GROUP_CUSTOMER_IMPORT_RECORD
HSGD_BASE_GROUP_CUSTOMER_IMPORT_COMPLETION
HSGD_BASE_GROUP_CUSTOMER_NOT_IMPORT_RECORD
代码
package com.zhgd.base.controller.api;
import com.zhgd.base.service.IZhgdSrBaseGroupCustomerImportService;
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.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* 描述 掌柜组织改版:1-导入组织人员
*
* @author
* @version 1.0.0
* @date 2021/10/11 16:07:20
*/
@RestController
@Api(tags = "Zhgd Sr Base Group Import Customer Controller")
@RequestMapping(value = "/api/srBaseGroupCustomerImport")
@Slf4j
public class ApiZhgdSrBaseGroupCustomerImportController {
@Resource
private IZhgdSrBaseGroupCustomerImportService iZhgdSrBaseGroupCustomerImportService;
@ApiOperation(value = "掌柜组织改版导入组织人员接口", response = String.class, notes = "Import Base Group Customer")
@PostMapping(value = "/11202/v1/importBaseGroupCustomer")
public ResponseResult<List<String>> importBaseGroupCustomer(@RequestParam("importFile") MultipartFile importFile){
String importFileName = importFile != null ? importFile.getOriginalFilename() : "--";
log.info("[掌柜组织改版]导入部门组织人员,导入文件名:{}",importFileName);
ResponseResult<List<String>> result = new ResponseResult<>();
result.setData(iZhgdSrBaseGroupCustomerImportService.importBaseGroupCustomerProcess(importFile));
log.info("[掌柜组织改版]导入部门组织人员,导入文件名:{}", JsonUtil.toJSONString(result));
return result;
}
// @ApiOperation(value = "掌柜组织改版 初始化组织人员上下级关系接口", response = String.class, notes = "Initialize Base Group Customer Relation")
// @PostMapping(value = "/11203/v1/initializeBaseGroupCustomerRelation")
// public ResponseResult<Boolean> initializeBaseGroupCustomerRelation(HttpServletRequest request){
// log.info("[掌柜组织改版]初始化组织人员上下级关系,开始...");
// ResponseResult<Boolean> result = new ResponseResult<>();
// result.setData(iZhgdSrBaseGroupCustomerImportService.initializeBaseGroupCustomerRelationProcess());
// log.info("[掌柜组织改版]初始化组织人员上下级关系,响应结果:{}", JsonUtil.toJSONString(result));
// return result;
// }
}
package com.zhgd.base.service;
import com.zhgd.base.entity.HsgdBaseGroupCustomerImportRecord;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
public interface IZhgdSrBaseGroupCustomerImportService {
void batchInsertAll(List<HsgdBaseGroupCustomerImportRecord> recordList);
List<String> importBaseGroupCustomerProcess(MultipartFile importFile);
Boolean initializeBaseGroupCustomerRelationProcess();
void insert(HsgdBaseGroupCustomerImportRecord record);
}
package com.zhgd.base.service.impl;
import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.PageHelper;
import com.zhgd.base.domain.model.ZhgdSrGroupCustomerImportModel;
import com.zhgd.base.domain.vo.HsgdBaseGroupCustomerSimpleVO;
import com.zhgd.base.domain.vo.HsgdBaseGroupLevelNameVO;
import com.zhgd.base.domain.vo.HsgdBaseGroupSimpleVO;
import com.zhgd.base.entity.*;
import com.zhgd.base.enums.HsgdBaseGroupLevelEnum;
import com.zhgd.base.listener.ZhgdSrBaseGroupCustomerImportExcelListener;
import com.zhgd.base.mapper.HsgdBaseGroupCustomerImportCompletionMapper;
import com.zhgd.base.mapper.HsgdBaseGroupCustomerImportRecordMapper;
import com.zhgd.base.mapper.HsgdBaseGroupCustomerMapper;
import com.zhgd.base.mapper.HsgdBaseGroupMapper;
import com.zhgd.base.service.*;
import com.zhgd.common.util.StringUtil;
import com.zhgd.common.util.UUIDUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ObjectUtils;
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.function.Function;
import java.util.stream.Collectors;
@Service
@Slf4j
public class ZhgdSrBaseGroupCustomerImportServiceImpl implements IZhgdSrBaseGroupCustomerImportService {
private final String SYSTEM_USER_NAME = "system";
@Resource
private HsgdBaseGroupCustomerImportRecordMapper hsgdBaseGroupCustomerImportRecordMapper;
@Resource
private HsgdBaseGroupCustomerImportCompletionMapper hsgdBaseGroupCustomerImportCompletionMapper;
@Resource
private IZhgdSrBaseGroupImportCustomerHandleService iZhgdSrBaseGroupImportCustomerHandleService;
@Resource
private HsgdBaseGroupCustomerMapper hsgdBaseGroupCustomerMapper;
@Resource
private HsgdBaseGroupMapper hsgdBaseGroupMapper;
@Resource
private IZhgdSrBaseGroupImportService iZhgdSrBaseGroupImportService;
@Resource
private IHsgdBaseGroupCustomerService iHsgdBaseGroupCustomerService;
@Resource
private IHsgdBaseGroupCustomerNotImportRecordService iHsgdBaseGroupCustomerNotImportRecordService;
@Transactional(rollbackFor = Exception.class)
@Override
public void batchInsertAll(List<HsgdBaseGroupCustomerImportRecord> recordList) {
hsgdBaseGroupCustomerImportRecordMapper.insertAll(recordList);
}
@Override
public void insert(HsgdBaseGroupCustomerImportRecord record) {
hsgdBaseGroupCustomerImportRecordMapper.insert(record);
}
@Override
public List<String> importBaseGroupCustomerProcess(MultipartFile importFile) {
List<String> importResultList = new ArrayList<>();
try {
String batchNo = UUIDUtils.getUUID();
ZhgdSrBaseGroupCustomerImportExcelListener listener = new ZhgdSrBaseGroupCustomerImportExcelListener(iZhgdSrBaseGroupImportCustomerHandleService, batchNo);
EasyExcel.read(importFile.getInputStream(), ZhgdSrGroupCustomerImportModel.class, listener).sheet(0).doRead();
// 2、文件校验(待处理)
// 3、组织数据
int totalRecord = this.organizeAndSaveBaseGroupCustomerCompletionData(batchNo);
this.saveBaseGroupCustomerData(batchNo,totalRecord);
} catch (Exception e) {
log.info("导入异常", e);
importResultList.add("导入异常 :" + e.getMessage());
return importResultList;
}
importResultList.add("执行完成,请检查是否全部导入成功!");
return importResultList;
}
@Override
public Boolean initializeBaseGroupCustomerRelationProcess() {
return null;
}
private int organizeAndSaveBaseGroupCustomerCompletionData(String batchNo) {
int importDataTotal = hsgdBaseGroupCustomerImportRecordMapper.countImportBaseGroupCustomerDataTotalByBatchNo(batchNo);
if (importDataTotal > 0) {
// 每页记录数
int pageSize = 120, startPage = 1;
// 总页数
int totalPage = importDataTotal % pageSize == 0 ? (importDataTotal / pageSize) : (importDataTotal / pageSize + 1);
for (int pageN = 0; pageN < totalPage; pageN++) {
PageHelper.startPage(startPage + pageN, pageSize, false);
List<HsgdBaseGroupCustomerImportRecord> list = hsgdBaseGroupCustomerImportRecordMapper.selectListByBatchNo(batchNo);
if (CollectionUtils.isNotEmpty(list)) {
List<HsgdBaseGroupCustomerImportCompletion> completionList = new ArrayList<>();
HsgdBaseGroupCustomerImportCompletion completion;
for (int i = 0, listSize = list.size(); i < listSize; i++) {
HsgdBaseGroupCustomerImportRecord record = list.get(i);
completion = new HsgdBaseGroupCustomerImportCompletion();
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());
}
BeanUtils.copyProperties(record, completion);
completionList.add(completion);
}
iZhgdSrBaseGroupImportCustomerHandleService.insertAllImportCompletion(completionList);
}
}
}
return importDataTotal;
}
private void saveBaseGroupCustomerData(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;
HsgdBaseGroupSimpleVO groupSimpleVo = null;
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<HsgdBaseGroupCustomerImportCompletion> completionPageList = hsgdBaseGroupCustomerImportCompletionMapper.selectListByBatchNo(batchNo);
if(CollectionUtils.isNotEmpty(completionPageList)){
List<Long> customerIdList = completionPageList.stream().map(HsgdBaseGroupCustomerImportCompletion::getCustomerId).collect(Collectors.toList());
List<HsgdBaseGroupCustomerSimpleVO> customerSiList = hsgdBaseGroupCustomerImportCompletionMapper.querySrCustomerInfoByIds(customerIdList);
List<HsgdBaseGroupCustomerSimpleVO> customerDealerList = hsgdBaseGroupCustomerImportCompletionMapper.queryDealerCustomerInfoByIds(customerIdList);
Map<Long,HsgdBaseGroupCustomerSimpleVO> customerSiMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(customerSiList)) {
Map<Long, HsgdBaseGroupCustomerSimpleVO> srCustomerSiMap = customerSiList.stream().collect(Collectors.toMap(HsgdBaseGroupCustomerSimpleVO::getCustomerId, Function.identity(), (key1, key2) -> key2));
customerSiMap.putAll(srCustomerSiMap);
}
if (CollectionUtils.isNotEmpty(customerDealerList)) {
Map<Long, HsgdBaseGroupCustomerSimpleVO> dealerCustomerSiMap = customerDealerList.stream().collect(Collectors.toMap(HsgdBaseGroupCustomerSimpleVO::getCustomerId, Function.identity(), (key1, key2) -> key2));
customerSiMap.putAll(dealerCustomerSiMap);
}
List<HsgdBaseGroupCustomer> groupCustomerList = new ArrayList<>();
HsgdBaseGroupCustomer baseGroupCustomer;
List<HsgdBaseGroupCustomerNotImportRecord> errorRecordList = new ArrayList<>();
HsgdBaseGroupCustomerNotImportRecord notImportRecord;
Map<Long,HsgdBaseGroupCustomerImportCompletion> completionMap = completionPageList.stream().collect(Collectors.toMap(HsgdBaseGroupCustomerImportCompletion::getId,Function.identity(),(key1,key2)->key2));
for (HsgdBaseGroupCustomerImportCompletion completionVO : completionPageList){
HsgdBaseGroupCustomerSimpleVO customerVo = customerSiMap.get(completionVO.getCustomerId());
Long importId = completionVO.getId();
if(customerSiMap.containsKey(completionVO.getCustomerId())){
if (HsgdBaseGroupLevelEnum.ONE.getGroupLevel().equals(completionVO.getGroupLevel())) {
oneMapKey = completionVO.getLevelOneGroup();
if (groupOneLevelMap.get(oneMapKey) == null) {
this.queryOneLevelGroup(oneMapKey, groupOneLevelMap, completionVO);
}
if (groupOneLevelMap.get(oneMapKey) != null) {
groupSimpleVo = groupOneLevelMap.get(oneMapKey);
baseGroupCustomer = this.createHsgdBaseGroupCutomerData(groupSimpleVo, customerVo, nowDate,importId);
groupCustomerList.add(baseGroupCustomer);
} else {
notImportRecord = new HsgdBaseGroupCustomerNotImportRecord();
BeanUtils.copyProperties(completionVO, notImportRecord);
errorRecordList.add(notImportRecord);
}
}
else if (HsgdBaseGroupLevelEnum.TWO.getGroupLevel().equals(completionVO.getGroupLevel())) {
oneMapKey = completionVO.getLevelOneGroup();
twoMapKey = completionVO.getLevelTwoGroup();
if(groupOneLevelMap.get(oneMapKey) == null){
this.queryOneLevelGroup(oneMapKey, groupOneLevelMap, completionVO);
}
if(groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) == null){
this.queryTwoLevelGroup(twoMapKey, groupTwoLevelMap, completionVO);
}
if(groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) != null){
groupSimpleVo = groupTwoLevelMap.get(twoMapKey);
baseGroupCustomer = this.createHsgdBaseGroupCutomerData(groupSimpleVo,customerVo,nowDate,importId);
groupCustomerList.add(baseGroupCustomer);
}else{
notImportRecord = new HsgdBaseGroupCustomerNotImportRecord();
BeanUtils.copyProperties(completionVO, notImportRecord);
errorRecordList.add(notImportRecord);
}
}
else if (HsgdBaseGroupLevelEnum.THREE.getGroupLevel().equals(completionVO.getGroupLevel())) {
oneMapKey = completionVO.getLevelOneGroup();
twoMapKey = completionVO.getLevelTwoGroup();
threeMapKey = completionVO.getLevelThreeGroup();
if(groupOneLevelMap.get(oneMapKey) == null){
this.queryOneLevelGroup(oneMapKey, groupOneLevelMap, completionVO);
}
if(groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) == null){
this.queryTwoLevelGroup(twoMapKey, groupTwoLevelMap, completionVO);
}
if(groupTwoLevelMap.get(twoMapKey) != null && groupThreeLevelMap.get(threeMapKey) == null){
this.queryThreeLevelGroup(threeMapKey, groupThreeLevelMap, completionVO);
}
if(groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) != null && groupThreeLevelMap.get(threeMapKey) != null){
groupSimpleVo = groupThreeLevelMap.get(threeMapKey);
baseGroupCustomer = this.createHsgdBaseGroupCutomerData(groupSimpleVo,customerVo,nowDate,importId);
groupCustomerList.add(baseGroupCustomer);
}else{
notImportRecord = new HsgdBaseGroupCustomerNotImportRecord();
BeanUtils.copyProperties(completionVO, notImportRecord);
errorRecordList.add(notImportRecord);
}
}
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.queryOneLevelGroup(oneMapKey, groupOneLevelMap, completionVO);
}
if(groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) == null){
this.queryTwoLevelGroup(twoMapKey, groupTwoLevelMap, completionVO);
}
if(groupTwoLevelMap.get(twoMapKey) != null && groupThreeLevelMap.get(threeMapKey) == null){
this.queryThreeLevelGroup(threeMapKey, groupThreeLevelMap, completionVO);
}
if(groupThreeLevelMap.get(threeMapKey) != null && groupFourLevelMap.get(fourMapKey) == null){
parentId = groupThreeLevelMap.get(threeMapKey).getGroupId();
this.queryFourLevelGroup(fourMapKey, groupFourLevelMap, completionVO,parentId);
}
if(groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) != null
&& groupThreeLevelMap.get(threeMapKey) != null && groupFourLevelMap.get(fourMapKey) != null){
groupSimpleVo = groupFourLevelMap.get(fourMapKey);
baseGroupCustomer = this.createHsgdBaseGroupCutomerData(groupSimpleVo,customerVo,nowDate,importId);
groupCustomerList.add(baseGroupCustomer);
}else{
notImportRecord = new HsgdBaseGroupCustomerNotImportRecord();
BeanUtils.copyProperties(completionVO, notImportRecord);
errorRecordList.add(notImportRecord);
}
}
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.queryOneLevelGroup(oneMapKey, groupOneLevelMap, completionVO);
}
if(groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) == null){
this.queryTwoLevelGroup(twoMapKey, groupTwoLevelMap, completionVO);
}
if(groupTwoLevelMap.get(twoMapKey) != null && groupThreeLevelMap.get(threeMapKey) == null){
this.queryThreeLevelGroup(threeMapKey, groupThreeLevelMap, completionVO);
}
if(groupThreeLevelMap.get(threeMapKey) != null && groupFourLevelMap.get(fourMapKey) == null){
parentId = groupThreeLevelMap.get(threeMapKey).getGroupId();
this.queryFourLevelGroup(fourMapKey, groupFourLevelMap, completionVO,parentId);
}
if(groupFourLevelMap.get(fourMapKey) != null && groupFiveLevelMap.get(fiveMapKey) == null){
parentId = groupFourLevelMap.get(fourMapKey).getGroupId();
this.queryFiveLevelGroup(fiveMapKey, groupFiveLevelMap, completionVO,parentId);
}
if (groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) != null && groupThreeLevelMap.get(threeMapKey) != null &&
groupFourLevelMap.get(fourMapKey) != null && groupFiveLevelMap.get(fiveMapKey) != null) {
groupSimpleVo = groupFiveLevelMap.get(fiveMapKey);
baseGroupCustomer = this.createHsgdBaseGroupCutomerData(groupSimpleVo, customerVo, nowDate,importId);
groupCustomerList.add(baseGroupCustomer);
}else{
notImportRecord = new HsgdBaseGroupCustomerNotImportRecord();
BeanUtils.copyProperties(completionVO, notImportRecord);
errorRecordList.add(notImportRecord);
}
}
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.queryOneLevelGroup(oneMapKey, groupOneLevelMap, completionVO);
}
if(groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) == null){
this.queryTwoLevelGroup(twoMapKey, groupTwoLevelMap, completionVO);
}
if(groupTwoLevelMap.get(twoMapKey) != null && groupThreeLevelMap.get(threeMapKey) == null){
this.queryThreeLevelGroup(threeMapKey, groupThreeLevelMap, completionVO);
}
if(groupThreeLevelMap.get(threeMapKey) != null && groupFourLevelMap.get(fourMapKey) == null){
parentId = groupThreeLevelMap.get(threeMapKey).getGroupId();
this.queryFourLevelGroup(fourMapKey, groupFourLevelMap, completionVO,parentId);
}
if(groupFourLevelMap.get(fourMapKey) != null && groupFiveLevelMap.get(fiveMapKey) == null){
parentId = groupFourLevelMap.get(fourMapKey).getGroupId();
this.queryFiveLevelGroup(fiveMapKey, groupFiveLevelMap, completionVO,parentId);
}
if(groupFiveLevelMap.get(fiveMapKey) != null && groupSixLevelMap.get(sixMapKey) == null){
parentId = groupFiveLevelMap.get(fiveMapKey).getGroupId();
this.querySixLevelGroup(sixMapKey, groupSixLevelMap, completionVO,parentId);
}
if(groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) != null && groupThreeLevelMap.get(threeMapKey) != null &&
groupFourLevelMap.get(fourMapKey) != null && groupFiveLevelMap.get(fiveMapKey) != null && groupSixLevelMap.get(sixMapKey) != null ){
groupSimpleVo = groupSixLevelMap.get(sixMapKey);
baseGroupCustomer = this.createHsgdBaseGroupCutomerData(groupSimpleVo,customerVo,nowDate,importId);
groupCustomerList.add(baseGroupCustomer);
}else{
notImportRecord = new HsgdBaseGroupCustomerNotImportRecord();
BeanUtils.copyProperties(completionVO, notImportRecord);
errorRecordList.add(notImportRecord);
}
}
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.queryOneLevelGroup(oneMapKey, groupOneLevelMap, completionVO);
}
if(groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) == null){
this.queryTwoLevelGroup(twoMapKey, groupTwoLevelMap, completionVO);
}
if(groupTwoLevelMap.get(twoMapKey) != null && groupThreeLevelMap.get(threeMapKey) == null){
this.queryThreeLevelGroup(threeMapKey, groupThreeLevelMap, completionVO);
}
if(groupThreeLevelMap.get(threeMapKey) != null && groupFourLevelMap.get(fourMapKey) == null){
parentId = groupThreeLevelMap.get(threeMapKey).getGroupId();
this.queryFourLevelGroup(fourMapKey, groupFourLevelMap, completionVO,parentId);
}
if(groupFourLevelMap.get(fourMapKey) != null && groupFiveLevelMap.get(fiveMapKey) == null){
parentId = groupFourLevelMap.get(fourMapKey).getGroupId();
this.queryFiveLevelGroup(fiveMapKey, groupFiveLevelMap, completionVO,parentId);
}
if(groupFiveLevelMap.get(fiveMapKey) != null && groupSixLevelMap.get(sixMapKey) == null){
parentId = groupFiveLevelMap.get(fiveMapKey).getGroupId();
this.querySixLevelGroup(sixMapKey, groupSixLevelMap, completionVO,parentId);
}
if(groupSixLevelMap.get(sixMapKey) != null && groupSevenLevelMap.get(sevenMapKey) == null){
parentId = groupSixLevelMap.get(sixMapKey) .getGroupId();
this.querySevenLevelGroup(sevenMapKey, groupSevenLevelMap, completionVO,parentId);
}
if(groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) != null && groupThreeLevelMap.get(threeMapKey) != null &&
groupFourLevelMap.get(fourMapKey) != null && groupFiveLevelMap.get(fiveMapKey) != null && groupSixLevelMap.get(sixMapKey) != null
&& groupSevenLevelMap.get(sevenMapKey) != null){
groupSimpleVo = groupSevenLevelMap.get(sevenMapKey);
baseGroupCustomer = this.createHsgdBaseGroupCutomerData(groupSimpleVo,customerVo,nowDate,importId);
groupCustomerList.add(baseGroupCustomer);
}else{
notImportRecord = new HsgdBaseGroupCustomerNotImportRecord();
BeanUtils.copyProperties(completionVO, notImportRecord);
errorRecordList.add(notImportRecord);
}
}
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.queryOneLevelGroup(oneMapKey, groupOneLevelMap, completionVO);
}
if(groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) == null){
this.queryTwoLevelGroup(twoMapKey, groupTwoLevelMap, completionVO);
}
if(groupTwoLevelMap.get(twoMapKey) != null && groupThreeLevelMap.get(threeMapKey) == null){
this.queryThreeLevelGroup(threeMapKey, groupThreeLevelMap, completionVO);
}
if(groupThreeLevelMap.get(threeMapKey) != null && groupFourLevelMap.get(fourMapKey) == null){
parentId = groupThreeLevelMap.get(threeMapKey).getGroupId();
this.queryFourLevelGroup(fourMapKey, groupFourLevelMap, completionVO,parentId);
}
if(groupFourLevelMap.get(fourMapKey) != null && groupFiveLevelMap.get(fiveMapKey) == null){
parentId = groupFourLevelMap.get(fourMapKey).getGroupId();
this.queryFiveLevelGroup(fiveMapKey, groupFiveLevelMap, completionVO,parentId);
}
if(groupFiveLevelMap.get(fiveMapKey) != null && groupSixLevelMap.get(sixMapKey) == null){
parentId = groupFiveLevelMap.get(fiveMapKey).getGroupId();
this.querySixLevelGroup(sixMapKey, groupSixLevelMap, completionVO,parentId);
}
if(groupSixLevelMap.get(sixMapKey) != null && groupSevenLevelMap.get(sevenMapKey) == null){
parentId = groupSixLevelMap.get(sixMapKey) .getGroupId();
this.querySevenLevelGroup(sevenMapKey, groupSevenLevelMap, completionVO,parentId);
}
if( groupSevenLevelMap.get(sevenMapKey) != null && groupEightLevelMap.get(eightMapKey) == null){
parentId = groupSevenLevelMap.get(sevenMapKey).getGroupId();
this.queryEightLevelGroup(eightMapKey, groupEightLevelMap, completionVO,parentId);
}
if(groupOneLevelMap.get(oneMapKey) != null && groupTwoLevelMap.get(twoMapKey) != null && groupThreeLevelMap.get(threeMapKey) != null &&
groupFourLevelMap.get(fourMapKey) != null && groupFiveLevelMap.get(fiveMapKey) != null && groupSixLevelMap.get(sixMapKey) != null
&& groupSevenLevelMap.get(sevenMapKey) != null && groupEightLevelMap.get(eightMapKey) != null){
groupSimpleVo = groupEightLevelMap.get(eightMapKey);
baseGroupCustomer = this.createHsgdBaseGroupCutomerData(groupSimpleVo,customerVo,nowDate,importId);
groupCustomerList.add(baseGroupCustomer);
}else{
notImportRecord = new HsgdBaseGroupCustomerNotImportRecord();
BeanUtils.copyProperties(completionVO, notImportRecord);
errorRecordList.add(notImportRecord);
}
}
}else{
notImportRecord = new HsgdBaseGroupCustomerNotImportRecord();
BeanUtils.copyProperties(completionVO, notImportRecord);
errorRecordList.add(notImportRecord);
}
}
if(CollectionUtils.isNotEmpty(groupCustomerList)){
List<Long> customerIds = groupCustomerList.stream().map(HsgdBaseGroupCustomer::getCustomerId).collect(Collectors.toList());
List<HsgdBaseGroupCustomer> groupCustomerIdList = iHsgdBaseGroupCustomerService.selectListByCustomerId(customerIds);
List<String> existsList = groupCustomerIdList.stream().map(e -> e.getCustomerId() + "-" + e.getGroupId() ).collect(Collectors.toList());
List<HsgdBaseGroupCustomer> needInsertGroupCustomerList = new ArrayList<>();
for (HsgdBaseGroupCustomer customer : groupCustomerList){
if(!existsList.contains(customer.getCustomerId() + "-" + customer.getGroupId())){
needInsertGroupCustomerList.add(customer);
}else{
HsgdBaseGroupCustomerImportCompletion comRecord = completionMap.get(customer.getImportId());
notImportRecord = new HsgdBaseGroupCustomerNotImportRecord();
BeanUtils.copyProperties(comRecord, notImportRecord);
errorRecordList.add(notImportRecord);
}
}
if(CollectionUtils.isNotEmpty(needInsertGroupCustomerList)){
iHsgdBaseGroupCustomerService.saveBatch(needInsertGroupCustomerList);
}
}
if(CollectionUtils.isNotEmpty(errorRecordList)){
iHsgdBaseGroupCustomerNotImportRecordService.saveBatch(errorRecordList);
}
}
}
}
}
private HsgdBaseGroupCustomer createHsgdBaseGroupCutomerData(HsgdBaseGroupSimpleVO oneSimpleVo, HsgdBaseGroupCustomerSimpleVO customerVo, Date nowDate,Long importCustomerComId) {
HsgdBaseGroupCustomer hsgdBaseGroupCustomer = new HsgdBaseGroupCustomer();
hsgdBaseGroupCustomer.setGroupId(oneSimpleVo.getGroupId());
hsgdBaseGroupCustomer.setType(customerVo.getCustomerType());
hsgdBaseGroupCustomer.setBusType(Integer.parseInt(customerVo.getBusType()));
hsgdBaseGroupCustomer.setCustomerId(customerVo.getCustomerId());
hsgdBaseGroupCustomer.setPoiCode(customerVo.getPoiCode());
hsgdBaseGroupCustomer.setStatus(1);
hsgdBaseGroupCustomer.setCreated(nowDate);
hsgdBaseGroupCustomer.setCreatedBy(SYSTEM_USER_NAME);
hsgdBaseGroupCustomer.setCreatedById(-1L);
hsgdBaseGroupCustomer.setUpdated(nowDate);
hsgdBaseGroupCustomer.setUpdatedBy(SYSTEM_USER_NAME);
hsgdBaseGroupCustomer.setUpdatedById(-1L);
hsgdBaseGroupCustomer.setImportId(importCustomerComId);
return hsgdBaseGroupCustomer;
}
private HsgdBaseGroupSimpleVO queryOneLevelGroup(String oneMapKey, Map<String, HsgdBaseGroupSimpleVO> groupOneLevelMap, HsgdBaseGroupCustomerImportCompletion completionVO) {
HsgdBaseGroupSimpleVO oneSimpleVo = iZhgdSrBaseGroupImportService.getGroupSimpleByGroupNameAndLevel(completionVO.getLevelOneGroup(), HsgdBaseGroupLevelEnum.ONE.getGroupLevel());
if (oneSimpleVo != null) {
groupOneLevelMap.put(oneMapKey, oneSimpleVo);
}
return oneSimpleVo;
}
private HsgdBaseGroupSimpleVO queryTwoLevelGroup(String twoMapKey, Map<String, HsgdBaseGroupSimpleVO> groupTwoLevelMap, HsgdBaseGroupCustomerImportCompletion completionVO) {
HsgdBaseGroupSimpleVO twoSimpleVo = iZhgdSrBaseGroupImportService.getGroupSimpleByGroupNameAndLevel(completionVO.getLevelTwoGroup(), HsgdBaseGroupLevelEnum.TWO.getGroupLevel());
if (twoSimpleVo != null) {
groupTwoLevelMap.put(twoMapKey, twoSimpleVo);
}
return twoSimpleVo;
}
private HsgdBaseGroupSimpleVO queryThreeLevelGroup(String threeMapKey, Map<String, HsgdBaseGroupSimpleVO> groupThreeLevelMap, HsgdBaseGroupCustomerImportCompletion completionVO) {
HsgdBaseGroupSimpleVO threeSimpleVo = iZhgdSrBaseGroupImportService.getGroupSimpleByGroupNameAndLevel(completionVO.getLevelThreeGroup(), HsgdBaseGroupLevelEnum.THREE.getGroupLevel());
if (threeSimpleVo != null) {
groupThreeLevelMap.put(threeMapKey, threeSimpleVo);
}
return threeSimpleVo;
}
private HsgdBaseGroupSimpleVO queryFourLevelGroup(String fourMapKey, Map<String, HsgdBaseGroupSimpleVO> groupFourLevelMap, HsgdBaseGroupCustomerImportCompletion completionVO, Long parentId) {
HsgdBaseGroupSimpleVO fourSimpleVo = iZhgdSrBaseGroupImportService.getGroupSimpleByGroupNameAndLevelAndParentId(completionVO.getLevelFourGroup(), HsgdBaseGroupLevelEnum.FOUR.getGroupLevel(), parentId);
if (fourSimpleVo != null) {
groupFourLevelMap.put(fourMapKey, fourSimpleVo);
}
return fourSimpleVo;
}
private HsgdBaseGroupSimpleVO queryFiveLevelGroup(String fiveMapKey, Map<String, HsgdBaseGroupSimpleVO> groupFiveLevelMap, HsgdBaseGroupCustomerImportCompletion completionVO, Long parentId) {
HsgdBaseGroupSimpleVO fiveSimpleVo = iZhgdSrBaseGroupImportService.getGroupSimpleByGroupNameAndLevelAndParentId(completionVO.getLevelFiveGroup(), HsgdBaseGroupLevelEnum.FIVE.getGroupLevel(), parentId);
if (fiveSimpleVo != null) {
groupFiveLevelMap.put(fiveMapKey, fiveSimpleVo);
}
return fiveSimpleVo;
}
private HsgdBaseGroupSimpleVO querySixLevelGroup(String sixMapKey, Map<String, HsgdBaseGroupSimpleVO> groupSixLevelMap, HsgdBaseGroupCustomerImportCompletion completionVO, Long parentId) {
HsgdBaseGroupSimpleVO sixSimpleVo = iZhgdSrBaseGroupImportService.getGroupSimpleByGroupNameAndLevelAndParentId(completionVO.getLevelSixGroup(),HsgdBaseGroupLevelEnum.SIX.getGroupLevel(), parentId);
if(sixSimpleVo != null){
groupSixLevelMap.put(sixMapKey,sixSimpleVo);
}
return sixSimpleVo;
}
private HsgdBaseGroupSimpleVO querySevenLevelGroup(String sevenMapKey, Map<String, HsgdBaseGroupSimpleVO> groupSevenLevelMap, HsgdBaseGroupCustomerImportCompletion completionVO, Long parentId) {
HsgdBaseGroupSimpleVO sevenSimpleVo = iZhgdSrBaseGroupImportService.getGroupSimpleByGroupNameAndLevelAndParentId(completionVO.getLevelSevenGroup(), HsgdBaseGroupLevelEnum.SEVEN.getGroupLevel(),parentId);
if (sevenSimpleVo != null) {
groupSevenLevelMap.put(sevenMapKey, sevenSimpleVo);
}
return sevenSimpleVo;
}
private HsgdBaseGroupSimpleVO queryEightLevelGroup(String eightMapKey, Map<String, HsgdBaseGroupSimpleVO> groupEightLevelMap, HsgdBaseGroupCustomerImportCompletion completionVO, Long parentId) {
HsgdBaseGroupSimpleVO eightSimpleVo = iZhgdSrBaseGroupImportService.getGroupSimpleByGroupNameAndLevelAndParentId(completionVO.getLevelEightGroup(), HsgdBaseGroupLevelEnum.EIGHT.getGroupLevel(), parentId);
if (eightSimpleVo != null) {
groupEightLevelMap.put(eightMapKey, eightSimpleVo);
}
return eightSimpleVo;
}
}
package com.zhgd.base.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhgd.base.entity.HsgdBaseGroupCustomerImportRecord;
import com.zhgd.base.entity.HsgdBaseGroupImportRecord;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @desc 组织部门人员导入记录 Mapper
*
* @author
* @version 1.0
* @date 2021-10-12 10:15:35
*/
@Repository
public interface HsgdBaseGroupCustomerImportRecordMapper extends BaseMapper<HsgdBaseGroupCustomerImportRecord> {
/**
* 组织部门人员导入记录 批量插入数据集
* @param param
* @return Boolean
*/
Boolean insertAll(@Param("paramList") List<HsgdBaseGroupCustomerImportRecord> param);
int countImportBaseGroupCustomerDataTotalByBatchNo(String batchNo);
List<HsgdBaseGroupCustomerImportRecord> selectListByBatchNo(String batchNo);
}
HsgdBaseGroupCustomerImportRecordMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhgd.base.mapper.HsgdBaseGroupCustomerImportRecordMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.zhgd.base.entity.HsgdBaseGroupCustomerImportRecord">
<id column="ID" property="id" jdbcType="BIGINT"/>
<result column="LEVEL_ONE_GROUP" property="levelOneGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_TWO_GROUP" property="levelTwoGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_THREE_GROUP" property="levelThreeGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_FOUR_GROUP" property="levelFourGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_FIVE_GROUP" property="levelFiveGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_SIX_GROUP" property="levelSixGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_SEVEN_GROUP" property="levelSevenGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_EIGHT_GROUP" property="levelEightGroup" jdbcType="VARCHAR"/>
<result column="CUSTOMER_ID" property="customerId" jdbcType="BIGINT"/>
<result column="POI_CODE" property="poiCode" jdbcType="BIGINT"/>
<result column="CREATED" property="created" jdbcType="TIMESTAMP"/>
<result column="CREATED_BY" property="createdBy" jdbcType="VARCHAR"/>
<result column="UPDATED" property="updated" jdbcType="TIMESTAMP"/>
<result column="UPDATED_BY" property="updatedBy" jdbcType="VARCHAR"/>
<result column="BATCH_NO" property="batchNo" jdbcType="VARCHAR"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
ID, LEVEL_ONE_GROUP, LEVEL_TWO_GROUP, LEVEL_THREE_GROUP, LEVEL_FOUR_GROUP, LEVEL_FIVE_GROUP, LEVEL_SIX_GROUP, LEVEL_SEVEN_GROUP, LEVEL_EIGHT_GROUP, CUSTOMER_ID, POI_CODE, CREATED, CREATED_BY, UPDATED, UPDATED_BY, BATCH_NO
</sql>
<insert id="insertAll" parameterType="com.zhgd.base.entity.HsgdBaseGroupCustomerImportRecord" >
insert into HSGD_BASE_GROUP_CUSTOMER_IMPORT_RECORD
<trim prefix="(" suffix=")" suffixOverrides="," >
LEVEL_ONE_GROUP,
LEVEL_TWO_GROUP,
LEVEL_THREE_GROUP,
LEVEL_FOUR_GROUP,
LEVEL_FIVE_GROUP,
LEVEL_SIX_GROUP,
LEVEL_SEVEN_GROUP,
LEVEL_EIGHT_GROUP,
CUSTOMER_ID,
POI_CODE,
CREATED,
CREATED_BY,
UPDATED,
UPDATED_BY,
BATCH_NO,
</trim>
VALUES
<foreach collection="paramList" separator="," item="param" index="index">
<trim prefix="(" suffix=")" suffixOverrides="," >
#{param.levelOneGroup, jdbcType=VARCHAR},
#{param.levelTwoGroup, jdbcType=VARCHAR},
#{param.levelThreeGroup, jdbcType=VARCHAR},
#{param.levelFourGroup, jdbcType=VARCHAR},
#{param.levelFiveGroup, jdbcType=VARCHAR},
#{param.levelSixGroup, jdbcType=VARCHAR},
#{param.levelSevenGroup, jdbcType=VARCHAR},
#{param.levelEightGroup, jdbcType=VARCHAR},
#{param.customerId, jdbcType=BIGINT},
#{param.poiCode, jdbcType=BIGINT},
#{param.created, jdbcType=TIMESTAMP},
#{param.createdBy, jdbcType=VARCHAR},
#{param.updated, jdbcType=TIMESTAMP},
#{param.updatedBy, jdbcType=VARCHAR},
#{param.batchNo, jdbcType=VARCHAR},
</trim>
</foreach>
</insert>
<select id="countImportBaseGroupCustomerDataTotalByBatchNo" resultType="java.lang.Integer">
SELECT COUNT(1) FROM HSGD_BASE_GROUP_CUSTOMER_IMPORT_RECORD WITH(NOLOCK) WHERE BATCH_NO = #{batchNo}
</select>
<select id="selectListByBatchNo" resultType="com.zhgd.base.entity.HsgdBaseGroupCustomerImportRecord">
SELECT
<include refid="Base_Column_List"/>
FROM HSGD_BASE_GROUP_CUSTOMER_IMPORT_RECORD WITH(NOLOCK)
WHERE BATCH_NO = #{batchNo}
ORDER BY LEVEL_ONE_GROUP,LEVEL_TWO_GROUP,LEVEL_THREE_GROUP,LEVEL_FOUR_GROUP,LEVEL_FIVE_GROUP,LEVEL_SIX_GROUP,LEVEL_SEVEN_GROUP,LEVEL_EIGHT_GROUP
</select>
</mapper>
package com.zhgd.base.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhgd.base.domain.vo.HsgdBaseGroupCustomerSimpleVO;
import com.zhgd.base.entity.HsgdBaseGroupCustomerImportCompletion;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @desc 组织部门人员导入记录补全表 Mapper
*
* @author
* @version 1.0
* @date 2021-10-13 14:29:30
*/
@Repository
public interface HsgdBaseGroupCustomerImportCompletionMapper extends BaseMapper<HsgdBaseGroupCustomerImportCompletion> {
/**
* 组织部门人员导入记录补全表 批量插入数据集
* @param param
* @return Boolean
*/
Boolean insertAll(@Param("paramList") List<HsgdBaseGroupCustomerImportCompletion> param);
List<HsgdBaseGroupCustomerImportCompletion> selectListByBatchNo(String batchNo);
List<HsgdBaseGroupCustomerSimpleVO> querySrCustomerInfoByIds(@Param("list") List<Long> customerIdList);
List<HsgdBaseGroupCustomerSimpleVO> queryDealerCustomerInfoByIds(List<Long> customerIdList);
}
HsgdBaseGroupCustomerImportCompletionMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhgd.base.mapper.HsgdBaseGroupCustomerImportCompletionMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.zhgd.base.entity.HsgdBaseGroupCustomerImportCompletion">
<id column="ID" property="id" jdbcType="BIGINT"/>
<result column="LEVEL_ONE_GROUP" property="levelOneGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_TWO_GROUP" property="levelTwoGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_THREE_GROUP" property="levelThreeGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_FOUR_GROUP" property="levelFourGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_FIVE_GROUP" property="levelFiveGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_SIX_GROUP" property="levelSixGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_SEVEN_GROUP" property="levelSevenGroup" jdbcType="VARCHAR"/>
<result column="LEVEL_EIGHT_GROUP" property="levelEightGroup" jdbcType="VARCHAR"/>
<result column="CUSTOMER_ID" property="customerId" jdbcType="BIGINT"/>
<result column="POI_CODE" property="poiCode" jdbcType="BIGINT"/>
<result column="CREATED" property="created" jdbcType="TIMESTAMP"/>
<result column="CREATED_BY" property="createdBy" jdbcType="VARCHAR"/>
<result column="UPDATED" property="updated" jdbcType="TIMESTAMP"/>
<result column="UPDATED_BY" property="updatedBy" jdbcType="VARCHAR"/>
<result column="BATCH_NO" property="batchNo" jdbcType="VARCHAR"/>
<result column="GROUP_LEVEL" property="groupLevel" jdbcType="INTEGER"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
ID, LEVEL_ONE_GROUP, LEVEL_TWO_GROUP, LEVEL_THREE_GROUP, LEVEL_FOUR_GROUP, LEVEL_FIVE_GROUP, LEVEL_SIX_GROUP, LEVEL_SEVEN_GROUP, LEVEL_EIGHT_GROUP, CUSTOMER_ID, POI_CODE, CREATED, CREATED_BY, UPDATED, UPDATED_BY, BATCH_NO,GROUP_LEVEL
</sql>
<insert id="insertAll" parameterType="com.zhgd.base.entity.HsgdBaseGroupCustomerImportCompletion" >
insert into HSGD_BASE_GROUP_CUSTOMER_IMPORT_COMPLETION
<trim prefix="(" suffix=")" suffixOverrides="," >
LEVEL_ONE_GROUP,
LEVEL_TWO_GROUP,
LEVEL_THREE_GROUP,
LEVEL_FOUR_GROUP,
LEVEL_FIVE_GROUP,
LEVEL_SIX_GROUP,
LEVEL_SEVEN_GROUP,
LEVEL_EIGHT_GROUP,
CUSTOMER_ID,
POI_CODE,
CREATED,
CREATED_BY,
UPDATED,
UPDATED_BY,
BATCH_NO,
GROUP_LEVEL,
</trim>
VALUES
<foreach collection="paramList" separator="," item="param" index="index">
<trim prefix="(" suffix=")" suffixOverrides="," >
#{param.levelOneGroup, jdbcType=VARCHAR},
#{param.levelTwoGroup, jdbcType=VARCHAR},
#{param.levelThreeGroup, jdbcType=VARCHAR},
#{param.levelFourGroup, jdbcType=VARCHAR},
#{param.levelFiveGroup, jdbcType=VARCHAR},
#{param.levelSixGroup, jdbcType=VARCHAR},
#{param.levelSevenGroup, jdbcType=VARCHAR},
#{param.levelEightGroup, jdbcType=VARCHAR},
#{param.customerId, jdbcType=BIGINT},
#{param.poiCode, jdbcType=BIGINT},
#{param.created, jdbcType=TIMESTAMP},
#{param.createdBy, jdbcType=VARCHAR},
#{param.updated, jdbcType=TIMESTAMP},
#{param.updatedBy, jdbcType=VARCHAR},
#{param.batchNo, jdbcType=VARCHAR},
#{param.groupLevel, jdbcType=INTEGER},
</trim>
</foreach>
</insert>
<select id="selectListByBatchNo" resultType="com.zhgd.base.entity.HsgdBaseGroupCustomerImportCompletion">
SELECT
<include refid="Base_Column_List"/>
FROM HSGD_BASE_GROUP_CUSTOMER_IMPORT_COMPLETION WITH(NOLOCK)
WHERE BATCH_NO = #{batchNo}
ORDER BY LEVEL_ONE_GROUP,LEVEL_TWO_GROUP,LEVEL_THREE_GROUP,LEVEL_FOUR_GROUP,LEVEL_FIVE_GROUP,LEVEL_SIX_GROUP,LEVEL_SEVEN_GROUP,LEVEL_EIGHT_GROUP
</select>
<select id="querySrCustomerInfoByIds" resultType="com.zhgd.base.domain.vo.HsgdBaseGroupCustomerSimpleVO">
SELECT
businessInfo.CUSTOMER_ID AS customerId,
1 AS customerType,
businessInfo.BUS_TYPE AS busType,
wsCustomer.ORG_ID AS poiCode
FROM CRM_BUSINESS_INFO businessInfo WITH(NOLOCK)
LEFT JOIN CRM_WS_CUSTOMER wsCustomer WITH(NOLOCK) ON businessInfo.CUSTOMER_ID = wsCustomer.CUSTOMER_ID
WHERE
businessInfo.BUS_STATUS = 1
AND wsCustomer.CUST_STATUS = 1
AND businessInfo.CUSTOMER_ID IN
<foreach collection="list" item="custoemrId" separator="," open="(" close=")">
#{custoemrId}
</foreach>
</select>
<select id="queryDealerCustomerInfoByIds"
resultType="com.zhgd.base.domain.vo.HsgdBaseGroupCustomerSimpleVO">
SELECT
wsCustomer.CUSTOMER_ID AS customerId,
2 AS customerType,
CASE WHEN poiInfo.POI_TYPE = 'saler'
THEN 1
WHEN poiInfo.POI_TYPE = 'dealer' AND poiInfo.DEALER_SOURCE_TYPE = '经销商'
THEN 3
WHEN poiInfo.POI_TYPE = 'dealer' AND poiInfo.DEALER_SOURCE_TYPE = '镇村通伙伴'
THEN 2
END
AS busType,
wsCustomer.ORG_ID AS poiCode
FROM CRM_WS_CUSTOMER wsCustomer WITH(NOLOCK)
LEFT JOIN CRM_POI_INFO poiInfo WITH(NOLOCK) ON poiInfo.POI_CODE = wsCustomer.ORG_ID
WHERE
poiInfo.STATUS = 1
AND wsCustomer.CUST_STATUS = 1
AND wsCustomer.CUSTOMER_ID IN
<foreach collection="list" item="custoemrId" separator="," open="(" close=")">
#{custoemrId}
</foreach>
AND poiInfo.POI_TYPE IN ('dealer','saler')
</select>
</mapper>
package com.zhgd.base.service;
import com.zhgd.base.domain.model.ZhgdSrGroupCustomerImportModel;
import com.zhgd.base.entity.HsgdBaseGroupCustomerImportCompletion;
import java.util.List;
public interface IZhgdSrBaseGroupImportCustomerHandleService {
void saveSrBaseGroupCustomerImportDataList(List<ZhgdSrGroupCustomerImportModel> dataList);
void saveSrBaseGroupCustomerImportData(ZhgdSrGroupCustomerImportModel data);
void insertAllImportCompletion(List<HsgdBaseGroupCustomerImportCompletion> completionList);
}
package com.zhgd.base.service.impl;
import com.zhgd.base.domain.model.ZhgdSrGroupCustomerImportModel;
import com.zhgd.base.entity.HsgdBaseGroupCustomerImportCompletion;
import com.zhgd.base.entity.HsgdBaseGroupCustomerImportRecord;
import com.zhgd.base.entity.HsgdBaseGroupImportRecord;
import com.zhgd.base.mapper.HsgdBaseGroupCustomerImportCompletionMapper;
import com.zhgd.base.service.IZhgdSrBaseGroupCustomerImportService;
import com.zhgd.base.service.IZhgdSrBaseGroupImportCustomerHandleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
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 ZhgdSrBaseGroupImportCustomerHandleServiceImpl implements IZhgdSrBaseGroupImportCustomerHandleService {
@Resource
private IZhgdSrBaseGroupCustomerImportService iZhgdSrBaseGroupCustomerImportService;
@Resource
private HsgdBaseGroupCustomerImportCompletionMapper hsgdBaseGroupCustomerImportCompletionMapper;
@Override
public void saveSrBaseGroupCustomerImportDataList(List<ZhgdSrGroupCustomerImportModel> dataList) {
Date nowDate = new Date();
final String userName = "system";
if(CollectionUtils.isNotEmpty(dataList)){
List<HsgdBaseGroupCustomerImportRecord> recordList = new ArrayList();
HsgdBaseGroupCustomerImportRecord record = null;
for (int i=0,len = dataList.size();i< len;i++){
ZhgdSrGroupCustomerImportModel importModel = dataList.get(i);
record = new HsgdBaseGroupCustomerImportRecord();
BeanUtils.copyProperties(importModel,record);
record.setCreated(nowDate);
record.setCreatedBy(userName);
record.setUpdated(nowDate);
record.setUpdatedBy(userName);
if(StringUtils.isNotBlank(importModel.getCustomerID()) && NumberUtils.isNumber(importModel.getCustomerID())){
record.setCustomerId(Long.parseLong(importModel.getCustomerID()));
}
if(StringUtils.isNotBlank(importModel.getPoiCode()) && NumberUtils.isNumber(importModel.getPoiCode())){
record.setPoiCode(Long.parseLong(importModel.getPoiCode()));
}
recordList.add(record);
};
iZhgdSrBaseGroupCustomerImportService.batchInsertAll(recordList);
}
}
@Override
public void saveSrBaseGroupCustomerImportData(ZhgdSrGroupCustomerImportModel data) {
Date nowDate = new Date();
final String userName = "system";
if(data != null){
HsgdBaseGroupCustomerImportRecord record = new HsgdBaseGroupCustomerImportRecord();
BeanUtils.copyProperties(data,record);
record.setCreated(nowDate);
record.setCreatedBy(userName);
record.setUpdated(nowDate);
record.setUpdatedBy(userName);
if(StringUtils.isNotBlank(data.getCustomerID()) && NumberUtils.isNumber(data.getCustomerID())){
record.setCustomerId(Long.parseLong(data.getCustomerID()));
}
if(StringUtils.isNotBlank(data.getPoiCode()) && NumberUtils.isNumber(data.getPoiCode())){
record.setPoiCode(Long.parseLong(data.getPoiCode()));
}
iZhgdSrBaseGroupCustomerImportService.insert(record);
}
}
@Override
@Transactional
public void insertAllImportCompletion(List<HsgdBaseGroupCustomerImportCompletion> completionList) {
hsgdBaseGroupCustomerImportCompletionMapper.insertAll(completionList);
}
}
package com.zhgd.base.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zhgd.base.entity.HsgdBaseGroupCustomer;
import java.util.List;
/**
* @desc 部门关联用户表 服务
*
* @author
* @version 1.0
* @date 2021-10-14 16:55:50
*/
public interface IHsgdBaseGroupCustomerService extends IService<HsgdBaseGroupCustomer> {
/**
* 部门关联用户表 批量新增重写
* @param param model集合
* @return Boolean
*/
Boolean saveBatch(List<HsgdBaseGroupCustomer> param);
long countExistsGroupCustomer(Long customerId, Long groupId);
void insert(HsgdBaseGroupCustomer customer);
List<HsgdBaseGroupCustomer> selectListByCustomerId(List<Long> customerIds);
}
package com.zhgd.base.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhgd.base.entity.HsgdBaseGroupCustomer;
import com.zhgd.base.mapper.HsgdBaseGroupCustomerMapper;
import com.zhgd.base.service.IHsgdBaseGroupCustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @desc 部门关联用户表 服务实现
*
* @author
* @version 1.0
* @date 2021-10-14 16:55:50
*/
@Service
@Slf4j
public class HsgdBaseGroupCustomerServiceImpl extends ServiceImpl<HsgdBaseGroupCustomerMapper, HsgdBaseGroupCustomer> implements IHsgdBaseGroupCustomerService {
/**
* 部门关联用户表 批量新增重写
* @param param model集合
* @return Boolean
*/
@Transactional(rollbackFor = Exception.class)
@Override
public Boolean saveBatch(List<HsgdBaseGroupCustomer> param) {
return this.getBaseMapper().insertAll(param);
}
@Override
public long countExistsGroupCustomer(Long customerId, Long groupId) {
QueryWrapper<HsgdBaseGroupCustomer> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("CUSTOMER_ID",customerId);
queryWrapper.eq("GROUP_ID",groupId);
queryWrapper.eq("STATUS",1);
long count = this.getBaseMapper().selectCount(queryWrapper);
return count;
}
@Override
public void insert(HsgdBaseGroupCustomer customer) {
this.getBaseMapper().insert(customer);
}
@Override
public List<HsgdBaseGroupCustomer> selectListByCustomerId(List<Long> customerIds) {
QueryWrapper<HsgdBaseGroupCustomer> queryWrapper = new QueryWrapper<>();
queryWrapper.in("CUSTOMER_ID",customerIds);
queryWrapper.eq("STATUS",1);
return this.getBaseMapper().selectList(queryWrapper);
}
}
导入之后
HSGD_BASE_GROUP_CUSTOMER_IMPORT_RECORD
HSGD_BASE_GROUP_CUSTOMER_IMPORT_COMPLETION
HSGD_BASE_GROUP_CUSTOMER_NOT_IMPORT_RECORD