|
|
@ -14,9 +14,9 @@ import com.qs.serve.modules.baz.entity.BazVisitInfo; |
|
|
|
import com.qs.serve.modules.baz.service.BazVisitInfoService; |
|
|
|
import com.qs.serve.modules.bms.common.MasterUserType; |
|
|
|
import com.qs.serve.modules.bms.controller.my.BmsChannelPointMyController; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsChannel; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsRegion; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsRegion2; |
|
|
|
import com.qs.serve.modules.bms.entity.*; |
|
|
|
import com.qs.serve.modules.bms.entity.bo.BmsChannel4ExcelBo; |
|
|
|
import com.qs.serve.modules.bms.entity.bo.BmsChannelPoint4ExcelBo; |
|
|
|
import com.qs.serve.modules.bms.entity.bo.BmsChannelPointBo; |
|
|
|
import com.qs.serve.modules.bms.entity.bo.BmsChannelPointMapInfoBo; |
|
|
|
import com.qs.serve.modules.bms.entity.so.BmsPointVisitSo; |
|
|
@ -34,11 +34,11 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.security.access.prepost.PreAuthorize; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import com.qs.serve.modules.bms.entity.BmsChannelPoint; |
|
|
|
|
|
|
|
import javax.validation.Valid; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -230,6 +230,243 @@ public class BmsChannelPointController { |
|
|
|
return R.isTrue(result); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 导入 |
|
|
|
* @param param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@PostMapping("/importExcel") |
|
|
|
@SysLog(module = SystemModule.BASE, title = "渠道站点", biz = BizType.INSERT) |
|
|
|
@PreAuthorize("hasRole('bms:channelPoint:insert')") |
|
|
|
public R<?> importExcel(@RequestBody @Valid List<BmsChannelPoint4ExcelBo> param){ |
|
|
|
param.forEach(a->{ |
|
|
|
a.setErrorInfo(""); |
|
|
|
if(!StringUtils.hasText(a.getChannelCode())){ |
|
|
|
a.setErrorInfo(a.getErrorInfo()+"渠道编码不能为空;"); |
|
|
|
} |
|
|
|
if(!StringUtils.hasText(a.getPointName())){ |
|
|
|
a.setErrorInfo(a.getErrorInfo()+"网点名称不能为空;"); |
|
|
|
} |
|
|
|
if(!StringUtils.hasText(a.getAddress())){ |
|
|
|
a.setErrorInfo(a.getErrorInfo()+"网点地址不能为空;"); |
|
|
|
} |
|
|
|
if(!StringUtils.hasText(a.getPointLevel())){ |
|
|
|
a.setErrorInfo(a.getErrorInfo()+"网点等级不能为空;"); |
|
|
|
} |
|
|
|
if(!StringUtils.hasText(a.getPointType())){ |
|
|
|
a.setErrorInfo(a.getErrorInfo()+"网点类型不能为空;"); |
|
|
|
} |
|
|
|
if(!StringUtils.hasText(a.getBizRegionCode())){ |
|
|
|
a.setErrorInfo(a.getErrorInfo()+"行政区域编码不能为空;"); |
|
|
|
} |
|
|
|
if(!StringUtils.hasText(a.getShopArea())){ |
|
|
|
a.setErrorInfo(a.getErrorInfo()+"店铺面积不能为空;"); |
|
|
|
} |
|
|
|
if(a.getCountCheckstand()==null){ |
|
|
|
a.setErrorInfo(a.getErrorInfo()+"收银台数量不能为空;"); |
|
|
|
} |
|
|
|
if(a.getCostFlag()==null){ |
|
|
|
a.setErrorInfo(a.getErrorInfo()+"是否可投放费用不能为空;"); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
List<BmsChannelPoint4ExcelBo> saveList = param.stream().filter(a->a.getType().equals("1")).collect(Collectors.toList()); |
|
|
|
List<BmsChannelPoint4ExcelBo> updateList = param.stream().filter(a->a.getType().equals("2")).collect(Collectors.toList()); |
|
|
|
List<BmsChannelPoint4ExcelBo> deleteList = param.stream().filter(a->a.getType().equals("3")).collect(Collectors.toList()); |
|
|
|
|
|
|
|
/** ------------------------------- 查渠道列表 ------------------------------------------------ */ |
|
|
|
List<String> channelCodes = new ArrayList<>(); |
|
|
|
channelCodes.addAll(saveList.stream().filter(a->a.getChannelCode()!=null).map(a->a.getChannelCode()).collect(Collectors.toList())); |
|
|
|
channelCodes.addAll(updateList.stream().filter(a->a.getChannelCode()!=null).map(a->a.getChannelCode()).collect(Collectors.toList())); |
|
|
|
channelCodes = channelCodes.stream().distinct().collect(Collectors.toList()); |
|
|
|
List<BmsChannel> channelList = new ArrayList<>(); |
|
|
|
if(channelCodes.size()>0){ |
|
|
|
LambdaQueryWrapper<BmsChannel> channelLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
channelLambdaQueryWrapper.in(BmsChannel::getChannelCode,channelCodes); |
|
|
|
channelList = bmsChannelService.list(channelLambdaQueryWrapper); |
|
|
|
List<String> existChannelCode = channelList.stream().map(a -> a.getChannelCode()).collect(Collectors.toList()); |
|
|
|
if(channelList.size()<channelCodes.size()) { |
|
|
|
param.forEach(a -> { |
|
|
|
if(!existChannelCode.contains(a.getChannelCode())){ |
|
|
|
a.setErrorInfo(a.getErrorInfo()+"不存在该渠道编码;"); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
Map<String,BmsChannel> codeToChannaledId = channelList.stream().collect(Collectors.toMap(BmsChannel::getChannelCode, a->a)); |
|
|
|
/** ----------------------------------------------------------------------------------- */ |
|
|
|
/** ------------------------------- 查行政区域列表 ------------------------------------------------ */ |
|
|
|
List<String> bizRegionCodes = new ArrayList<>(); |
|
|
|
bizRegionCodes.addAll(saveList.stream().filter(a->a.getBizRegionCode()!=null).map(a->a.getBizRegionCode()).collect(Collectors.toList())); |
|
|
|
bizRegionCodes.addAll(updateList.stream().filter(a->a.getBizRegionCode()!=null).map(a->a.getBizRegionCode()).collect(Collectors.toList())); |
|
|
|
bizRegionCodes = bizRegionCodes.stream().distinct().collect(Collectors.toList()); |
|
|
|
List<BmsRegion2> region2List = new ArrayList<>(); |
|
|
|
if(bizRegionCodes.size()>0){ |
|
|
|
LambdaQueryWrapper<BmsRegion2> region2LambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
region2LambdaQueryWrapper.in(BmsRegion2::getCode,bizRegionCodes); |
|
|
|
region2List = bmsRegion2Service.list(region2LambdaQueryWrapper); |
|
|
|
List<String> existRegion2Code = region2List.stream().map(a -> a.getCode()).collect(Collectors.toList()); |
|
|
|
if(region2List.size()<bizRegionCodes.size()) { |
|
|
|
param.forEach(a -> { |
|
|
|
if(!existRegion2Code.contains(a.getBizRegionCode())){ |
|
|
|
a.setErrorInfo(a.getErrorInfo()+"不存在该行政区域编码;"); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
Map<String,BmsRegion2> codeToBizRegion = region2List.stream().collect(Collectors.toMap(BmsRegion2::getCode, a->a)); |
|
|
|
|
|
|
|
/** ----------------------------------------------------------------------------------- */ |
|
|
|
/** ------------------------------- 校验新增 ------------------------------------------------ */ |
|
|
|
|
|
|
|
if(saveList.size()>0) { |
|
|
|
List<String> saveCodes = saveList.stream().filter(a->StringUtils.hasText(a.getPointCode())).map(a->a.getPointCode()).distinct().collect(Collectors.toList()); |
|
|
|
if(saveCodes.size()>0) { |
|
|
|
LambdaQueryWrapper<BmsChannelPoint> checkSavePointCodeLqw = new LambdaQueryWrapper<>(); |
|
|
|
checkSavePointCodeLqw.in(BmsChannelPoint::getPointCode, saveCodes); |
|
|
|
List<BmsChannelPoint> checkSavePointList = bmsChannelPointService.list(checkSavePointCodeLqw); |
|
|
|
if (checkSavePointList.size() > 0) { |
|
|
|
List<String> existSaveCodes = checkSavePointList.stream().map(a -> a.getPointCode()).collect(Collectors.toList()); |
|
|
|
param.forEach(a -> { |
|
|
|
if (a.getType().equals("1")) { |
|
|
|
if (existSaveCodes.contains(a.getPointCode())) { |
|
|
|
a.setErrorInfo(a.getErrorInfo() + "新增已存在网点编码;"); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
/** ----------------------------------------------------------------------------------- */ |
|
|
|
/** ------------------------------- 校验更新 ------------------------------------------------ */ |
|
|
|
if(updateList.size()>0) { |
|
|
|
List<String> updateCheckCodes = updateList.stream().filter(a -> StringUtils.hasText(a.getPointCode())).map(a -> a.getPointCode()).distinct().collect(Collectors.toList()); |
|
|
|
if(updateCheckCodes.size()==0){ |
|
|
|
param.forEach(a -> { |
|
|
|
if (a.getType().equals("2")) { |
|
|
|
a.setErrorInfo(a.getErrorInfo() + "更新不存在网点编码;"); |
|
|
|
} |
|
|
|
}); |
|
|
|
}else { |
|
|
|
LambdaQueryWrapper<BmsChannelPoint> checkUpdategetPointCodeLqw = new LambdaQueryWrapper<>(); |
|
|
|
checkUpdategetPointCodeLqw.in(BmsChannelPoint::getPointCode, updateCheckCodes); |
|
|
|
List<BmsChannelPoint> checkUpdateChannelList = bmsChannelPointService.list(checkUpdategetPointCodeLqw); |
|
|
|
List<String> existSaveCodes = checkUpdateChannelList.stream().map(a -> a.getPointCode()).collect(Collectors.toList()); |
|
|
|
param.forEach(a -> { |
|
|
|
if (a.getType().equals("2")) { |
|
|
|
if (!existSaveCodes.contains(a.getPointCode())) { |
|
|
|
a.setErrorInfo(a.getErrorInfo() + "更新不存在网点编码;"); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
/** ----------------------------------------------------------------------------------- */ |
|
|
|
/** ------------------------------- 删除更新 ------------------------------------------------ */ |
|
|
|
if(deleteList.size()>0) { |
|
|
|
List<String> deleteCheckCodes = deleteList.stream().filter(a -> StringUtils.hasText(a.getPointCode())).map(a -> a.getPointCode()).distinct().collect(Collectors.toList()); |
|
|
|
if(deleteCheckCodes.size()==0){ |
|
|
|
param.forEach(a -> { |
|
|
|
if (a.getType().equals("3")) { |
|
|
|
a.setErrorInfo(a.getErrorInfo() + "删除不存在网点编码;"); |
|
|
|
} |
|
|
|
}); |
|
|
|
}else { |
|
|
|
LambdaQueryWrapper<BmsChannelPoint> checkdeleteChannelCode = new LambdaQueryWrapper<>(); |
|
|
|
checkdeleteChannelCode.in(BmsChannelPoint::getPointCode, deleteCheckCodes); |
|
|
|
List<BmsChannelPoint> checkdeleteChannelList = bmsChannelPointService.list(checkdeleteChannelCode); |
|
|
|
if (checkdeleteChannelList.size() > 0) { |
|
|
|
List<String> existSaveCodes = checkdeleteChannelList.stream().map(a -> a.getPointCode()).collect(Collectors.toList()); |
|
|
|
param.forEach(a -> { |
|
|
|
if (a.getType().equals("3")) { |
|
|
|
if (!existSaveCodes.contains(a.getPointCode())) { |
|
|
|
a.setErrorInfo(a.getErrorInfo() + "删除不存在网点编码;"); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** ----------------------------------------------------------------------------------- */ |
|
|
|
/** ------------------------------- 返回错误 ------------------------------------------- */ |
|
|
|
if(param.stream().filter(a->a.getErrorInfo().length()>0).count()>0) { |
|
|
|
return R.ok(param, "导入失败,请打开EXCEL查询错误详情!"); |
|
|
|
} |
|
|
|
|
|
|
|
/** ----------------------------------------------------------------------------------- */ |
|
|
|
/** ------------------------------- 保存新增 ------------------------------------------------ */ |
|
|
|
if(saveList.size()>0) { |
|
|
|
List<BmsChannelPoint> saveBmsChannels = saveList.stream().map(a->{ |
|
|
|
BmsChannelPoint bmsChannelPoint = new BmsChannelPoint(); |
|
|
|
CopierUtil.copy(a, bmsChannelPoint); |
|
|
|
if(!StringUtils.hasText(bmsChannelPoint.getPointCode())){ |
|
|
|
bmsChannelPoint.setPointCode("D"+StringUtils.genShortId()); |
|
|
|
} |
|
|
|
BmsChannel channel = codeToChannaledId.get(a.getChannelCode()); |
|
|
|
BmsRegion2 region2 = codeToBizRegion.get(a.getBizRegionCode()); |
|
|
|
bmsChannelPoint.setChannelId(channel.getId()); |
|
|
|
bmsChannelPoint.setChannelName(channel.getChannelName()); |
|
|
|
bmsChannelPoint.setChannelType(channel.getChannelType()); |
|
|
|
bmsChannelPoint.setBizRegionId(region2.getId()); |
|
|
|
bmsChannelPoint.setBizRegionPath(region2.getPathNames()); |
|
|
|
bmsChannelPoint.setBizRegionPathIds(region2.getPathIds()); |
|
|
|
return bmsChannelPoint; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
bmsChannelPointService.saveBatch(saveBmsChannels); |
|
|
|
} |
|
|
|
/** ----------------------------------------------------------------------------------- */ |
|
|
|
/** ------------------------------- 更新数据 ------------------------------------------------ */ |
|
|
|
if(updateList.size()>0) { |
|
|
|
List<BmsChannelPoint> updateBmsChannelPoints = updateList.stream().map(a -> { |
|
|
|
BmsChannelPoint bmsChannelPoint = new BmsChannelPoint(); |
|
|
|
CopierUtil.copy(a, bmsChannelPoint); |
|
|
|
BmsChannel channel = codeToChannaledId.get(a.getChannelCode()); |
|
|
|
BmsRegion2 region2 = codeToBizRegion.get(a.getBizRegionCode()); |
|
|
|
bmsChannelPoint.setChannelId(channel.getId()); |
|
|
|
bmsChannelPoint.setChannelName(channel.getChannelName()); |
|
|
|
bmsChannelPoint.setChannelType(channel.getChannelType()); |
|
|
|
bmsChannelPoint.setBizRegionId(region2.getId()); |
|
|
|
bmsChannelPoint.setBizRegionPath(region2.getPathNames()); |
|
|
|
bmsChannelPoint.setBizRegionPathIds(region2.getPathIds()); |
|
|
|
return bmsChannelPoint; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
List<String> updateCodes = updateBmsChannelPoints.stream().map(a -> a.getPointCode()).collect(Collectors.toList()); |
|
|
|
LambdaQueryWrapper<BmsChannelPoint> bmsChannelLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
bmsChannelLambdaQueryWrapper.in(BmsChannelPoint::getPointCode, updateCodes); |
|
|
|
List<BmsChannelPoint> oriBmsChannelList = bmsChannelPointService.list(bmsChannelLambdaQueryWrapper); |
|
|
|
Map<String, Long> codeToChannelId = oriBmsChannelList.stream().collect(Collectors.toMap(BmsChannelPoint::getPointCode, BmsChannelPoint::getId)); |
|
|
|
updateBmsChannelPoints = updateBmsChannelPoints.stream().map(a -> { |
|
|
|
a.setId(codeToChannelId.get(a.getPointCode())); |
|
|
|
return a; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
bmsChannelPointService.updateBatchById(updateBmsChannelPoints); |
|
|
|
} |
|
|
|
|
|
|
|
/** ----------------------------------------------------------------------------------- */ |
|
|
|
/** ------------------------------- 删除数据 ------------------------------------------------ */ |
|
|
|
if(deleteList.size()>0) { |
|
|
|
List<BmsChannelPoint> deleteBmsChannelPoints = updateList.stream().map(a -> { |
|
|
|
BmsChannelPoint bmsChannel = new BmsChannelPoint(); |
|
|
|
CopierUtil.copy(a, bmsChannel); |
|
|
|
return bmsChannel; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
List<String> updateCodes = deleteBmsChannelPoints.stream().map(a -> a.getPointCode()).collect(Collectors.toList()); |
|
|
|
LambdaQueryWrapper<BmsChannelPoint> bmsChannelLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
bmsChannelLambdaQueryWrapper.in(BmsChannelPoint::getPointCode, updateCodes); |
|
|
|
List<BmsChannelPoint> oriBmsChannelList = bmsChannelPointService.list(bmsChannelLambdaQueryWrapper); |
|
|
|
Map<String, Long> codeToChannelId = oriBmsChannelList.stream().collect(Collectors.toMap(BmsChannelPoint::getPointCode, BmsChannelPoint::getId)); |
|
|
|
deleteBmsChannelPoints = deleteBmsChannelPoints.stream().map(a -> { |
|
|
|
a.setId(codeToChannelId.get(a.getPointCode())); |
|
|
|
return a; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
List<Long> deleteIds = deleteBmsChannelPoints.stream().map(a -> a.getId()).collect(Collectors.toList()); |
|
|
|
bmsChannelPointService.removeBatchByIds(deleteIds); |
|
|
|
} |
|
|
|
/** ----------------------------------------------------------------------------------- */ |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 删除 |
|
|
|
* @param id |
|
|
|