提交 66e88e12 authored 作者: 吕本才's avatar 吕本才

修改上传文件校验

上级 ccd25fe5
package com.wangxiaolu.promotion.service.activity.manage.impl;
import cn.hutool.core.util.ObjectUtil;
import com.wangxiaolu.promotion.common.excel.ReadExcelUtils;
import com.wangxiaolu.promotion.common.redis.RedisKeys;
import com.wangxiaolu.promotion.common.redis.service.RedisCache;
......@@ -7,11 +8,14 @@ import com.wangxiaolu.promotion.domain.activity.dao.ManageEmployeeInfoDao;
import com.wangxiaolu.promotion.domain.activity.wrapperQo.ManageEmployeeWrapper;
import com.wangxiaolu.promotion.domain.manage.dao.EmployeeActivityPlanInfoDao;
import com.wangxiaolu.promotion.domain.manage.dao.EmployeeActivityPlanRecordDao;
import com.wangxiaolu.promotion.domain.user.dao.QinCeClienteleStoreDao;
import com.wangxiaolu.promotion.domain.user.wrapperQo.StoreWrapper;
import com.wangxiaolu.promotion.exception.DataException;
import com.wangxiaolu.promotion.pojo.activity.manage.dto.EmployeeActivityPlanInfoDto;
import com.wangxiaolu.promotion.pojo.activity.manage.dto.EmployeeActivityPlanRecordDto;
import com.wangxiaolu.promotion.pojo.activity.manage.vo.ActivityPlanVo;
import com.wangxiaolu.promotion.pojo.user.dto.ManageEmployeeInfoDto;
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;
......@@ -42,6 +46,8 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
EmployeeActivityPlanInfoDao employeeActivityPlanInfoDao;
@Autowired
ManageEmployeeInfoDao manageEmployeeInfoDao;
@Autowired
QinCeClienteleStoreDao qinCeClienteleStoreDao;
@Transactional(rollbackFor = Exception.class)
@Override
......@@ -66,18 +72,19 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
public void transferActivityPlan(ActivityPlanVo activityPlanVo) {
ManageEmployeeInfoDto oriUser = manageEmployeeInfoDao.selectById(activityPlanVo.getOriginalEmpId());
ManageEmployeeInfoDto tranUser = manageEmployeeInfoDao.selectById(activityPlanVo.getTransferEmpId());
if (Objects.isNull(oriUser) || Objects.isNull(tranUser)){
if (Objects.isNull(oriUser) || Objects.isNull(tranUser)) {
throw new DataException(RCode.CHARGER_ID_ERROR);
}
employeeActivityPlanRecordDao.transfer(oriUser.getId(),tranUser);
employeeActivityPlanInfoDao.transfer(oriUser.getId(),tranUser);
employeeActivityPlanRecordDao.transfer(oriUser.getId(), tranUser);
employeeActivityPlanInfoDao.transfer(oriUser.getId(), tranUser);
}
private void saveActivityPlanInfo(ActivityPlanVo activityPlanVo, EmployeeActivityPlanRecordDto planDto) throws Exception {
// 下载
String filePath = "/home/" + planDto.getExcelFiledId();
downloadExcel(activityPlanVo.getExcelUrl(), filePath);
// 读取
List<EmployeeActivityPlanInfoDto> planInfoDtos = readSheet0(filePath, activityPlanVo, planDto);
// 保存
......@@ -109,11 +116,11 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
}
// 判断是否是城市经理已经的数据,5列数据是城市经理自己的,6列数据是战区顾问批量上传的
if (rows.get(1).size() == 5){
return saveEmployeeOneselfPlan(rows,activityPlanVo,planDto);
}else if (rows.get(1).size() == 6){
return saveDistrictPlan(rows,activityPlanVo,planDto);
}else {
if (rows.get(1).size() == 6) {
return saveEmployeeOneselfPlan(rows, activityPlanVo, planDto);
} else if (rows.get(1).size() == 7) {
return saveDistrictPlan(rows, activityPlanVo, planDto);
} else {
throw new DataException(RCode.API_DATA_ERROR);
}
}
......@@ -122,18 +129,18 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
* 读取表格并进行数据校验
* 上传文件人员:城市经理自己
*/
private List<EmployeeActivityPlanInfoDto> saveEmployeeOneselfPlan(Map<Integer, List<Object>> rows,ActivityPlanVo activityPlanVo, EmployeeActivityPlanRecordDto planDto) throws Exception {
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());
Map<Object, Object> patternMap = redisCache.getAllHash(RedisKeys.TemporaryKeys.TENOIRART_ACTIVITY_PATTERN.getKey());
// 2、校验数据准确性
verifyRowEmployeeOneselfPlan(rows, dealers,patternMap.values(),storeNameDbList);
verifyRowEmployeeOneselfPlan(rows, dealers, patternMap.values(), storeNameDbList);
Map<String,Integer> patternInfoMap = new HashMap<>();
Map<String, Integer> patternInfoMap = new HashMap<>();
for (Map.Entry<Object, Object> entry : patternMap.entrySet()) {
patternInfoMap.put(entry.getValue().toString(),Integer.parseInt((String) entry.getKey()));
patternInfoMap.put(entry.getValue().toString(), Integer.parseInt((String) entry.getKey()));
}
/**
* 3、保存入库
......@@ -154,8 +161,9 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
.setDealerId((String) value.get(1))
.setDealerName((String) dealers.get(value.get(1)))
.setLineName((String) value.get(2))
.setStoreName((String) value.get(3))
.setActivityPattern((String) value.get(4));
.setQinceStoreCode((String) value.get(3))
.setStoreName((String) value.get(4))
.setActivityPattern((String) value.get(5));
planInfoDto.setActivityPatternId(patternInfoMap.get(planInfoDto.getActivityPattern()));
......@@ -168,7 +176,7 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
* 读取表格并进行数据校验
* 上传文件人员:城市顾问批量上传
*/
private List<EmployeeActivityPlanInfoDto> saveDistrictPlan(Map<Integer, List<Object>> rows,ActivityPlanVo activityPlanVo, EmployeeActivityPlanRecordDto planDto) throws Exception {
private List<EmployeeActivityPlanInfoDto> saveDistrictPlan(Map<Integer, List<Object>> rows, ActivityPlanVo activityPlanVo, EmployeeActivityPlanRecordDto planDto) throws Exception {
// 查询当前用户下有效的门店名称列表,用于检查是否存在同名店铺
Set<String> storeNameDbList = employeeActivityPlanInfoDao.findStoreNameByEmployeeId(activityPlanVo.getEmployeeId());
......@@ -180,9 +188,9 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
Map<String, ManageEmployeeInfoDto> employeeInfoMap = employeeInfos.stream().collect(Collectors.toMap(ManageEmployeeInfoDto::getEmployeeNo, o -> o));
Map<String,Integer> patternInfoMap = new HashMap<>();
Map<String, Integer> patternInfoMap = new HashMap<>();
for (Map.Entry<Object, Object> entry : patternMap.entrySet()) {
patternInfoMap.put(entry.getValue().toString(),Integer.parseInt((String) entry.getKey()));
patternInfoMap.put(entry.getValue().toString(), Integer.parseInt((String) entry.getKey()));
}
/**
* 3、保存入库
......@@ -192,8 +200,8 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
for (Map.Entry<Integer, List<Object>> entry : rows.entrySet()) {
List<Object> value = entry.getValue();
ManageEmployeeInfoDto employeeInfo = employeeInfoMap.get((String) value.get(1));
if (Objects.isNull(employeeInfo)){
throw new DataException("工号错误:"+value.get(1));
if (Objects.isNull(employeeInfo)) {
throw new DataException("工号错误:" + value.get(1));
}
EmployeeActivityPlanInfoDto planInfoDto = new EmployeeActivityPlanInfoDto()
......@@ -207,8 +215,9 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
.setDealerId((String) value.get(2))
.setDealerName((String) dealers.get(value.get(2)))
.setLineName((String) value.get(3))
.setStoreName((String) value.get(4))
.setActivityPattern((String) value.get(5));
.setQinceStoreCode((String) value.get(4))
.setStoreName((String) value.get(5))
.setActivityPattern((String) value.get(6));
planInfoDto.setActivityPatternId(patternInfoMap.get(planInfoDto.getActivityPattern()));
......@@ -221,7 +230,7 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
* 校验数据是否规范
* 上传文件人员:城市经理自己
*/
private void verifyRowEmployeeOneselfPlan(Map<Integer, List<Object>> rows, Map<Object, Object> dealers,Collection<Object> patterns,Set<String> storeNameDbSet) throws Exception {
private void verifyRowEmployeeOneselfPlan(Map<Integer, List<Object>> rows, Map<Object, Object> dealers, Collection<Object> patterns, Set<String> storeNameDbSet) throws Exception {
StringBuilder msg = new StringBuilder();
List<String> storeList = new ArrayList<>(storeNameDbSet);
......@@ -235,8 +244,8 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
String city = (String) value.get(0);
if (StringUtils.isBlank(city)) {
sb.append("城市不可为空;");
}else if (!city.contains("市")){
value.set(0,city+"市");
} else if (!city.contains("市")) {
value.set(0, city + "市");
}
if (!dealers.containsKey(((String) value.get(1)).trim())) {
......@@ -247,19 +256,35 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
sb.append("系统名称不可为空;");
}
String storeName = (String) value.get(3);
if (StringUtils.isBlank(storeName)) {
sb.append("店铺名称不可为空;");
} else if (storeList.contains(storeName)) {
sb.append("店铺名称已存在;");
String qinceStoreCode = (String) value.get(3);
String storeName = (String) value.get(4);
if (StringUtils.isBlank(qinceStoreCode)) {
sb.append("勤策店铺编码不可为空;");
if (StringUtils.isBlank(storeName)) {
sb.append("店铺名称不可为空;");
}
} else {
storeList.add(storeName);
// 验证店铺code是否存在
StoreWrapper storeWrap = new StoreWrapper()
.setStoreCode(qinceStoreCode);
QinCeClienteleStoreDto oneStore = qinCeClienteleStoreDao.getOneStore(storeWrap);
if (ObjectUtil.isEmpty(oneStore)) {
sb.append("勤策店铺编码不正确;");
}
if (StringUtils.isBlank(storeName)) {
sb.append("店铺名称不可为空;");
}else{
if (ObjectUtil.isNotEmpty(oneStore.getStoreName()) && !oneStore.getStoreName().equals(storeName)) {
sb.append("店铺名称不正确;");
}
}
}
String pattern = (String) value.get(4);
String pattern = (String) value.get(5);
if (StringUtils.isBlank(pattern)) {
sb.append("活动模式不可为空;");
}else if (!patterns.contains(pattern)){
} else if (!patterns.contains(pattern)) {
patternY = true;
}
......@@ -269,7 +294,7 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
}
if (patternY){
if (patternY) {
msg.append("活动模式列仅限:").append(patterns).append("(需区分大小写)");
}
if (msg.length() > 0) {
......@@ -282,7 +307,7 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
* 校验数据是否规范
* 上传文件人员:城市顾问批量上传
*/
private Set<String> verifyDistrictPlan(Map<Integer, List<Object>> rows, Map<Object, Object> dealers,Collection<Object> patterns,Set<String> storeNameDbSet) throws Exception {
private Set<String> verifyDistrictPlan(Map<Integer, List<Object>> rows, Map<Object, Object> dealers, Collection<Object> patterns, Set<String> storeNameDbSet) throws Exception {
Set<String> employeeNos = new HashSet<>(20);
StringBuilder msg = new StringBuilder();
......@@ -297,13 +322,13 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
String city = (String) value.get(0);
if (StringUtils.isBlank(city)) {
sb.append("城市不可为空;");
}else if (!city.contains("市")){
value.set(0,city+"市");
} else if (!city.contains("市")) {
value.set(0, city + "市");
}
if (StringUtils.isBlank((String) value.get(1))) {
sb.append("门店负责人不可为空;");
}else {
} else {
employeeNos.add((String) value.get(1));
}
......@@ -315,29 +340,42 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
sb.append("系统名称不可为空;");
}
String storeName = (String) value.get(4);
if (StringUtils.isBlank(storeName)) {
sb.append("店铺名称不可为空;");
} else if (storeList.contains(storeName)) {
sb.append("店铺名称已存在;");
String qinceStoreCode = (String) value.get(4);
String storeName = (String) value.get(5);
if (StringUtils.isBlank(qinceStoreCode)) {
sb.append("勤策店铺编码不可为空;");
if (StringUtils.isBlank(storeName)) {
sb.append("店铺名称不可为空;");
}
} else {
storeList.add(storeName);
// 验证店铺code是否存在
StoreWrapper storeWrap = new StoreWrapper()
.setStoreCode(qinceStoreCode);
QinCeClienteleStoreDto oneStore = qinCeClienteleStoreDao.getOneStore(storeWrap);
if (ObjectUtil.isEmpty(oneStore)) {
sb.append("勤策店铺编码不正确;");
}
if (ObjectUtil.isNotEmpty(oneStore.getStoreName()) && !oneStore.getStoreName().equals(storeName)) {
sb.append("店铺名称不正确;");
}
}
String pattern = (String) value.get(5);
String pattern = (String) value.get(6);
if (StringUtils.isBlank(pattern)) {
sb.append("活动模式不可为空;");
}else if (!patterns.contains(pattern)){
} else if (!patterns.contains(pattern)) {
patternY = true;
}
if (sb.length() > 0) {
msg.append("第").append(rowNo).append("行:").append(sb);
}
// entry.setValue(value);
}
if (patternY){
if (patternY) {
msg.append("活动模式列仅限:").append(patterns).append("(需区分大小写)");
}
if (msg.length() > 0) {
......@@ -348,9 +386,4 @@ public class ActivityPlanRecordCoreServiceImpl implements ActivityPlanRecordCore
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论