Commit 9f7867a7 authored by zhaobiyan's avatar zhaobiyan

兑换信息导入

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