提交 96c00521 authored 作者: 吕本才's avatar 吕本才

上传活动计划,增加表头验证,优化勤策店铺code和名称校验

上级 66e88e12
......@@ -19,7 +19,6 @@ import com.wangxiaolu.promotion.pojo.user.dto.QinCeClienteleStoreDto;
import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.service.activity.manage.ActivityPlanRecordCoreService;
import org.apache.commons.lang3.StringUtils;
import org.apache.groovy.util.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -82,8 +81,9 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
private void saveActivityPlanInfo(ActivityPlanVo activityPlanVo, EmployeeActivityPlanRecordDto planDto) throws Exception {
// 下载
String filePath = "/home/" + planDto.getExcelFiledId();
downloadExcel(activityPlanVo.getExcelUrl(), filePath);
// String filePath = "/home/" + planDto.getExcelFiledId();
// downloadExcel(activityPlanVo.getExcelUrl(), filePath);
String filePath = "/Users/tumaxiao/学习资料和自媒体/王小卤/02项目/销售-小程序/" + planDto.getExcelFiledId();
// 读取
List<EmployeeActivityPlanInfoDto> planInfoDtos = readSheet0(filePath, activityPlanVo, planDto);
......@@ -111,9 +111,12 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
// 1、解析表格数据
ReadExcelUtils readExcelUtils = new ReadExcelUtils(filePath);
Map<Integer, List<Object>> rows = readExcelUtils.readContent();
String[] headers = readExcelUtils.readTitle();
if (rows.size() <= 0) {
throw new DataException(RCode.API_DATA_ERROR);
}
// 2、校验表头
validateHeader(headers);
// 判断是否是城市经理已经的数据,5列数据是城市经理自己的,6列数据是战区顾问批量上传的
if (rows.get(1).size() == 6) {
......@@ -125,12 +128,32 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
}
}
public void validateHeader(String[] templateHeader) {
StringBuilder msg = new StringBuilder();
if (templateHeader.length < 6) {
msg.append("模板列不正确");
}
String[] expectedHeader = {"执行城市(二级行政单位市)\n例:成都市", "门店负责人-工号\n例:000516", "经销商编码(T100中的编码)\n例:001584", "系统名称\n例:北京华联", "门店编码(勤策-终端编码)\n例:POS00038920", "门店全称(系统名称+分店地址)\n例:北京华联-经华南西店", "活动模式(下拉选择)\n例:单点CP"};
boolean containsGh = templateHeader[1].contains(expectedHeader[1]);
// 包含工号
for (int i = 0; i < templateHeader.length; i++) {
if (i == 1 && containsGh) {
continue;
}
if (!templateHeader[i].contains(expectedHeader[i])) {
msg.append(String.format("第%d列表头是:%s", i + 1, expectedHeader[i]));
}
}
if (msg.toString().length() > 0) {
throw new DataException("模板不正确:" + msg.toString());
}
}
/**
* 读取表格并进行数据校验
* 上传文件人员:城市经理自己
*/
private List<EmployeeActivityPlanInfoDto> saveEmployeeOneselfPlan(Map<Integer, List<Object>> rows, ActivityPlanVo activityPlanVo, EmployeeActivityPlanRecordDto planDto) throws Exception {
// 查询当前用户下有效的门店名称列表,用于检查是否存在同名店铺
Set<String> storeNameDbList = employeeActivityPlanInfoDao.findStoreNameByEmployeeId(activityPlanVo.getEmployeeId());
Map<Object, Object> dealers = redisCache.getAllHash(RedisKeys.UserKeys.DEALER_HAVE_LIST.getKey());
......@@ -187,7 +210,6 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
List<ManageEmployeeInfoDto> employeeInfos = manageEmployeeInfoDao.selectList(new ManageEmployeeWrapper().setEmployeeNos(employeeNos));
Map<String, ManageEmployeeInfoDto> employeeInfoMap = employeeInfos.stream().collect(Collectors.toMap(ManageEmployeeInfoDto::getEmployeeNo, o -> o));
Map<String, Integer> patternInfoMap = new HashMap<>();
for (Map.Entry<Object, Object> entry : patternMap.entrySet()) {
patternInfoMap.put(entry.getValue().toString(), Integer.parseInt((String) entry.getKey()));
......@@ -271,11 +293,10 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
QinCeClienteleStoreDto oneStore = qinCeClienteleStoreDao.getOneStore(storeWrap);
if (ObjectUtil.isEmpty(oneStore)) {
sb.append("勤策店铺编码不正确;");
}
}else{
if (StringUtils.isBlank(storeName)) {
sb.append("店铺名称不可为空;");
}else{
if (ObjectUtil.isNotEmpty(oneStore.getStoreName()) && !oneStore.getStoreName().equals(storeName)) {
}else if (!storeName.equals(oneStore.getStoreName())){
sb.append("店铺名称不正确;");
}
}
......@@ -355,12 +376,16 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
QinCeClienteleStoreDto oneStore = qinCeClienteleStoreDao.getOneStore(storeWrap);
if (ObjectUtil.isEmpty(oneStore)) {
sb.append("勤策店铺编码不正确;");
}
if (ObjectUtil.isNotEmpty(oneStore.getStoreName()) && !oneStore.getStoreName().equals(storeName)) {
}else{
if (StringUtils.isBlank(storeName)) {
sb.append("店铺名称不可为空;");
}else if (!storeName.equals(oneStore.getStoreName())){
sb.append("店铺名称不正确;");
}
}
}
String pattern = (String) value.get(6);
if (StringUtils.isBlank(pattern)) {
sb.append("活动模式不可为空;");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论