Commit 9f7867a7 authored by zhaobiyan's avatar zhaobiyan

兑换信息导入

parent 64378e69
...@@ -91,11 +91,11 @@ public class RedeemRewardController { ...@@ -91,11 +91,11 @@ public class RedeemRewardController {
public void importTemplate(HttpServletResponse response) throws IOException { public void importTemplate(HttpServletResponse response) throws IOException {
// 手动创建导出 demo // 手动创建导出 demo
List<RedeemInfoImportExcelVO> list = Arrays.asList( List<RedeemInfoImportExcelVO> list = Arrays.asList(
RedeemInfoImportExcelVO.builder().id(1111L).redeemType("上门领取").courierCompany("顺丰空运").expenses(BigDecimal.valueOf(11.11)) RedeemInfoImportExcelVO.builder().id(String.valueOf(11111)).redeemType("上门领取").courierCompany("顺丰空运").expenses(BigDecimal.valueOf(11.11))
.currency("人民币").expressDate(new Date()).expressNo("SDSD212212").remark("备注备注").expressSender("系统管理员") .currency("人民币").expressDate("2024-01-01 11:22:33").expressNo("SDSD212212").remark("备注备注").expressSender("系统管理员")
.build(), .build(),
RedeemInfoImportExcelVO.builder().id(2222L).redeemType("包邮到家").courierCompany("顺丰空运").expenses(BigDecimal.valueOf(11.11)) RedeemInfoImportExcelVO.builder().id(String.valueOf(11111)).redeemType("包邮到家").courierCompany("顺丰空运").expenses(BigDecimal.valueOf(11.11))
.currency("美元").expressDate(new Date()).expressNo("SDSD212212").remark("备注备注").expressSender("系统管理员") .currency("美元").expressDate("2024-01-01 11:22:33").expressNo("SDSD212212").remark("备注备注").expressSender("系统管理员")
.build()); .build());
// 输出 // 输出
ExcelUtils.write(response, "兑换信息导入模板.xls", "兑换信息", RedeemInfoImportExcelVO.class, list); ExcelUtils.write(response, "兑换信息导入模板.xls", "兑换信息", RedeemInfoImportExcelVO.class, list);
......
package cn.iocoder.yudao.module.reward.service.redeem; package cn.iocoder.yudao.module.reward.service.redeem;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO; import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO;
...@@ -33,6 +34,7 @@ import java.util.*; ...@@ -33,6 +34,7 @@ import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cn.hutool.core.date.DatePattern.NORM_DATETIME_PATTERN;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.download.DownloadTypeEnum.REWARD_REDEEM_RECORD; import static cn.iocoder.yudao.module.system.enums.download.DownloadTypeEnum.REWARD_REDEEM_RECORD;
...@@ -104,7 +106,7 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper, ...@@ -104,7 +106,7 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
@Override @Override
public Boolean verify(RewardRedeemVerifyReqVO request) { public Boolean verify(RewardRedeemVerifyReqVO request) {
if (!checkVerifyParam(request)){ if (!checkVerifyParam(request)) {
throw exception(ErrorCodeConstants.REWARD_REDEEM_VERIFY_NO_PARAM); throw exception(ErrorCodeConstants.REWARD_REDEEM_VERIFY_NO_PARAM);
} }
LambdaUpdateWrapper<RewardRedeemDO> wrapper = Wrappers.lambdaUpdate(); LambdaUpdateWrapper<RewardRedeemDO> wrapper = Wrappers.lambdaUpdate();
...@@ -190,6 +192,7 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper, ...@@ -190,6 +192,7 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
public List<RewardRedeemPageRespVO> exportList(RewardRedeemPageReqVO request) { public List<RewardRedeemPageRespVO> exportList(RewardRedeemPageReqVO request) {
return rewardRedeemMapper.exportList(request); return rewardRedeemMapper.exportList(request);
} }
@Override @Override
public Integer exportCount(RewardRedeemPageReqVO request) { public Integer exportCount(RewardRedeemPageReqVO request) {
return rewardRedeemMapper.pageCount(request); return rewardRedeemMapper.pageCount(request);
...@@ -207,14 +210,14 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper, ...@@ -207,14 +210,14 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
Map<String, CurrencyRespDTO> titleZhCurrencyMap = allCurrency.stream().collect(Collectors.toMap(CurrencyRespDTO::getTitleZh, Function.identity(), (c1, c2) -> c1)); Map<String, CurrencyRespDTO> titleZhCurrencyMap = allCurrency.stream().collect(Collectors.toMap(CurrencyRespDTO::getTitleZh, Function.identity(), (c1, c2) -> c1));
Map<String, CurrencyRespDTO> titleEnCurrencyMap = allCurrency.stream().collect(Collectors.toMap(CurrencyRespDTO::getTitleEn, Function.identity(), (c1, c2) -> c1)); Map<String, CurrencyRespDTO> titleEnCurrencyMap = allCurrency.stream().collect(Collectors.toMap(CurrencyRespDTO::getTitleEn, Function.identity(), (c1, c2) -> c1));
Map<String, ExpressRespDTO> nameExpressMap = expressApi.getAllExpress().stream().collect(Collectors.toMap(ExpressRespDTO::getCompanyName, Function.identity(), (c1, c2) -> c1)); Map<String, ExpressRespDTO> nameExpressMap = expressApi.getAllExpress().stream().collect(Collectors.toMap(ExpressRespDTO::getCompanyName, Function.identity(), (c1, c2) -> c1));
Map<String, String> failedInfo = validate(dataList,titleZhCurrencyMap,titleEnCurrencyMap, nameExpressMap); Map<String, String> failedInfo = validate(dataList, titleZhCurrencyMap, titleEnCurrencyMap, nameExpressMap);
if (MapUtil.isNotEmpty(failedInfo)) { if (MapUtil.isNotEmpty(failedInfo)) {
return RecordInfoImportRespVO.builder().redeemIdFailedMap(failedInfo).build(); return RecordInfoImportRespVO.builder().redeemIdFailedMap(failedInfo).build();
} }
List<RewardRedeemDO> saveDataList = dataList.stream().map(data -> { List<RewardRedeemDO> saveDataList = dataList.stream().map(data -> {
RewardRedeemDO rewardRedeemDO = new RewardRedeemDO(); RewardRedeemDO rewardRedeemDO = new RewardRedeemDO();
rewardRedeemDO.setId(data.getId()); rewardRedeemDO.setId(Long.parseLong(data.getId()));
DictDataRespDTO redeemTypeDict = DictFrameworkUtils.parseDictDataFromCacheWithMultiLang("way_of_receiving", data.getRedeemType()); DictDataRespDTO redeemTypeDict = DictFrameworkUtils.parseDictDataFromCacheWithMultiLang("way_of_receiving", data.getRedeemType());
rewardRedeemDO.setRedeemType(Integer.parseInt(redeemTypeDict.getValue())); rewardRedeemDO.setRedeemType(Integer.parseInt(redeemTypeDict.getValue()));
rewardRedeemDO.setExpenses(data.getExpenses()); rewardRedeemDO.setExpenses(data.getExpenses());
...@@ -225,7 +228,7 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper, ...@@ -225,7 +228,7 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
rewardRedeemDO.setCurrency(Optional.ofNullable(currencyRespDTO).map(CurrencyRespDTO::getId).orElse(null)); rewardRedeemDO.setCurrency(Optional.ofNullable(currencyRespDTO).map(CurrencyRespDTO::getId).orElse(null));
rewardRedeemDO.setCourierCompany(nameExpressMap.get(data.getCourierCompany()).getId()); rewardRedeemDO.setCourierCompany(nameExpressMap.get(data.getCourierCompany()).getId());
rewardRedeemDO.setExpressNo(data.getExpressNo()); rewardRedeemDO.setExpressNo(data.getExpressNo());
rewardRedeemDO.setExpressDate(data.getExpressDate()); rewardRedeemDO.setExpressDate(DateUtil.parse(data.getExpressDate(), NORM_DATETIME_PATTERN));
rewardRedeemDO.setExpressSender(data.getExpressSender()); rewardRedeemDO.setExpressSender(data.getExpressSender());
rewardRedeemDO.setRemark(data.getRemark()); rewardRedeemDO.setRemark(data.getRemark());
return rewardRedeemDO; return rewardRedeemDO;
...@@ -243,23 +246,36 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper, ...@@ -243,23 +246,36 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
.collect(Collectors.toMap(RewardRedeemDO::getId, Function.identity(), (c1, c2) -> c1)); .collect(Collectors.toMap(RewardRedeemDO::getId, Function.identity(), (c1, c2) -> c1));
Map<String, String> failedInfoMap = new HashMap<>(); Map<String, String> failedInfoMap = new HashMap<>();
dataList.forEach(data -> { dataList.forEach(data -> {
RewardRedeemDO rewardRedeemDO = idRewardRedeemDOMap.get(data.getId()); long id ;
try {
id = Long.parseLong(data.getId());
}catch (Exception e) {
failedInfoMap.put(data.getId() == null ? "" : data.getId(), I18nMessage.getMessage("reward.redeem.not.exist"));
return;
}
try {
DateUtil.parse(data.getExpressDate(), NORM_DATETIME_PATTERN);
} catch (Exception e) {
failedInfoMap.put(data.getId() == null ? "" : data.getId(), I18nMessage.getMessage("date.format.error"));
return;
}
RewardRedeemDO rewardRedeemDO = idRewardRedeemDOMap.get(id);
if (rewardRedeemDO == null) { if (rewardRedeemDO == null) {
failedInfoMap.put(data.getId() == null ? "" : String.valueOf(data.getId()), I18nMessage.getMessage("reward.redeem.not.exist")); failedInfoMap.put(data.getId() == null ? "" : data.getId(), I18nMessage.getMessage("reward.redeem.not.exist"));
return; return;
} }
if (rewardRedeemDO.getStatus() != RewardRedeemStatusEnum.REDEEMING.getValue()) { if (rewardRedeemDO.getStatus() != RewardRedeemStatusEnum.REDEEMING.getValue()) {
failedInfoMap.put(String.valueOf(rewardRedeemDO.getId()), I18nMessage.getMessage("reward.redeem.status.error")); failedInfoMap.put(data.getId(), I18nMessage.getMessage("reward.redeem.status.error"));
return; return;
} }
DictDataRespDTO redeemTypeDict = DictFrameworkUtils.parseDictDataFromCacheWithMultiLang("way_of_receiving", data.getRedeemType()); DictDataRespDTO redeemTypeDict = DictFrameworkUtils.parseDictDataFromCacheWithMultiLang("way_of_receiving", data.getRedeemType());
if (redeemTypeDict == null) { if (redeemTypeDict == null) {
failedInfoMap.put(String.valueOf(rewardRedeemDO.getId()), I18nMessage.getMessage("dict.unknown.error", "way_of_receiving", data.getRedeemType())); failedInfoMap.put(data.getId(), I18nMessage.getMessage("dict.unknown.error", "way_of_receiving", data.getRedeemType()));
return; return;
} }
ExpressRespDTO expressRespDTO = nameExpressMap.get(data.getCourierCompany()); ExpressRespDTO expressRespDTO = nameExpressMap.get(data.getCourierCompany());
if (expressRespDTO == null) { if (expressRespDTO == null) {
failedInfoMap.put(String.valueOf(rewardRedeemDO.getId()), I18nMessage.getMessage("express.not.exist")); failedInfoMap.put(data.getId(), I18nMessage.getMessage("express.not.exist"));
return; return;
} }
CurrencyRespDTO currencyRespDTO = titleZhCurrencyMap.get(data.getCurrency()); CurrencyRespDTO currencyRespDTO = titleZhCurrencyMap.get(data.getCurrency());
...@@ -267,22 +283,21 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper, ...@@ -267,22 +283,21 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
currencyRespDTO = titleEnCurrencyMap.get(data.getCurrency()); currencyRespDTO = titleEnCurrencyMap.get(data.getCurrency());
} }
if (currencyRespDTO == null && StringUtils.isNotBlank(data.getCurrency())) { if (currencyRespDTO == null && StringUtils.isNotBlank(data.getCurrency())) {
failedInfoMap.put(String.valueOf(rewardRedeemDO.getId()), I18nMessage.getMessage("currency.not.exist")); failedInfoMap.put(data.getId(), I18nMessage.getMessage("currency.not.exist"));
return; return;
} }
if (!canVerify(RewardRedeemVerifyDTO.builder() if (!canVerify(RewardRedeemVerifyDTO.builder()
.id(data.getId()) .id(Long.parseLong(data.getId()))
.redeemType(Integer.parseInt(redeemTypeDict.getValue())) .redeemType(Integer.parseInt(redeemTypeDict.getValue()))
.status(rewardRedeemDO.getStatus()) .status(rewardRedeemDO.getStatus())
.expense(data.getExpenses()) .expense(data.getExpenses())
.currency(Optional.ofNullable(currencyRespDTO).map(CurrencyRespDTO::getId).orElse(null)) .currency(Optional.ofNullable(currencyRespDTO).map(CurrencyRespDTO::getId).orElse(null))
.courierCompany(expressRespDTO.getId()) .courierCompany(expressRespDTO.getId())
.expressSender(data.getExpressSender()) .expressSender(data.getExpressSender())
.expressDate(data.getExpressDate()) .expressDate(DateUtil.parse(data.getExpressDate(), NORM_DATETIME_PATTERN))
.expressNo(data.getExpressNo()) .expressNo(data.getExpressNo())
.recipientAddress(rewardRedeemDO.getRecipientAddress()).build())) { .recipientAddress(rewardRedeemDO.getRecipientAddress()).build())) {
failedInfoMap.put(String.valueOf(rewardRedeemDO.getId()), I18nMessage.getMessage("reward.redeem.verify.no.param")); failedInfoMap.put(String.valueOf(rewardRedeemDO.getId()), I18nMessage.getMessage("reward.redeem.verify.no.param"));
return;
} }
}); });
return failedInfoMap; return failedInfoMap;
...@@ -293,7 +308,7 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper, ...@@ -293,7 +308,7 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
wrapper.in(RewardRedeemDO::getId, request.getIds()); wrapper.in(RewardRedeemDO::getId, request.getIds());
Map<Long, RewardRedeemDO> idRewardRedeemMap = this.list(wrapper).stream() Map<Long, RewardRedeemDO> idRewardRedeemMap = this.list(wrapper).stream()
.collect(Collectors.toMap(RewardRedeemDO::getId, Function.identity(), (c1, c2) -> c1)); .collect(Collectors.toMap(RewardRedeemDO::getId, Function.identity(), (c1, c2) -> c1));
List<Long> errorIds = idRewardRedeemMap.keySet().stream().filter(id -> { return idRewardRedeemMap.keySet().stream().filter(id -> {
RewardRedeemDO rewardRedeemDO = idRewardRedeemMap.get(id); RewardRedeemDO rewardRedeemDO = idRewardRedeemMap.get(id);
if (rewardRedeemDO == null) { if (rewardRedeemDO == null) {
return true; return true;
...@@ -311,7 +326,6 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper, ...@@ -311,7 +326,6 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
.expressSender(rewardRedeemDO.getExpressSender()) .expressSender(rewardRedeemDO.getExpressSender())
.build()); .build());
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return errorIds;
} }
private boolean checkVerifyParam(RewardRedeemVerifyReqVO request) { private boolean checkVerifyParam(RewardRedeemVerifyReqVO request) {
......
package cn.iocoder.yudao.module.reward.vo.reward; package cn.iocoder.yudao.module.reward.vo.reward;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
...@@ -9,9 +8,6 @@ import lombok.NoArgsConstructor; ...@@ -9,9 +8,6 @@ import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Data @Data
@Builder @Builder
...@@ -20,7 +16,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ ...@@ -20,7 +16,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Accessors(chain = false) @Accessors(chain = false)
public class RedeemInfoImportExcelVO { public class RedeemInfoImportExcelVO {
@ExcelProperty("兑换记录ID/Redeem ID") @ExcelProperty("兑换记录ID/Redeem ID")
private Long id; private String id;
@ExcelProperty("兑换方式/Redeem Method") @ExcelProperty("兑换方式/Redeem Method")
private String redeemType; private String redeemType;
@ExcelProperty("费用/fee") @ExcelProperty("费用/fee")
...@@ -32,8 +28,7 @@ public class RedeemInfoImportExcelVO { ...@@ -32,8 +28,7 @@ public class RedeemInfoImportExcelVO {
@ExcelProperty("快递单号/Express NO") @ExcelProperty("快递单号/Express NO")
private String expressNo; private String expressNo;
@ExcelProperty(value = "快递日期/Delivery Date") @ExcelProperty(value = "快递日期/Delivery Date")
@DateTimeFormat(value = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private String expressDate;
private Date expressDate;
@ExcelProperty("快递寄出人/Sender") @ExcelProperty("快递寄出人/Sender")
private String expressSender; private String expressSender;
@ExcelProperty("备注/Remark") @ExcelProperty("备注/Remark")
......
...@@ -1020,3 +1020,4 @@ redeem.import.max.count = allow maximum number of imports is {} ...@@ -1020,3 +1020,4 @@ redeem.import.max.count = allow maximum number of imports is {}
dict.unknown.error = Not in dict {0}: {1} dict.unknown.error = Not in dict {0}: {1}
express.not.exist = express not exist express.not.exist = express not exist
currency.not.exist = currency not exist currency.not.exist = currency not exist
date.format.error = date format error, for example : 2024-01-01 12:11:11
\ No newline at end of file
...@@ -1024,3 +1024,4 @@ redeem.import.max.count = \u5141\u8BB8\u7684\u6700\u5927\u5BFC\u5165\u6761\u6570 ...@@ -1024,3 +1024,4 @@ redeem.import.max.count = \u5141\u8BB8\u7684\u6700\u5927\u5BFC\u5165\u6761\u6570
dict.unknown.error = \u4E0D\u5728{0}\u5B57\u5178\u4E2D: {1} dict.unknown.error = \u4E0D\u5728{0}\u5B57\u5178\u4E2D: {1}
express.not.exist = \u5FEB\u9012\u516C\u53F8\u4E0D\u5B58\u5728 express.not.exist = \u5FEB\u9012\u516C\u53F8\u4E0D\u5B58\u5728
currency.not.exist = \u5E01\u79CD\u4E0D\u5B58\u5728 currency.not.exist = \u5E01\u79CD\u4E0D\u5B58\u5728
date.format.error = \u65E5\u671F\u683C\u5F0F\u4E0D\u6B63\u786E, \u6B63\u786E\u683C\u5F0F\u53C2\u8003: 2024-01-01 12:11:11
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment