Commit 928f6ae4 authored by zhaobiyan's avatar zhaobiyan

兑换记录导出接口

parent 75a26330
package cn.iocoder.yudao.framework.apollo.core.event.export;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class RewardRedeemRecordExportEvent {
/**
* 操作用户
*/
private Long userId = 0L;
/**
* 端口
*/
private Integer userType = 2;
/**
* 请求参数
*/
private String requestParams;
/**
* 国际化语言值,默认0中文, 具体取值I18nMessage.getLang()
*/
private Integer lang = 0;
/**
* 文件名称
*/
private String fileName;
/**
* 文件路径
*/
private String path;
/**
* 下载地址
*/
private String url;
/**
* 执行结果
*/
private String result;
@ApiModelProperty(value = "文件ID")
private Long fileId;
}
......@@ -41,7 +41,7 @@
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-system-impl</artifactId>
<version>1.6.1-snapshot</version>
<version>${revision}</version>
<scope>compile</scope>
</dependency>
</dependencies>
......
......@@ -39,12 +39,28 @@
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-system-api</artifactId>
<version>1.6.1-snapshot</version>
<version>${revision}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-ecw-api</artifactId>
<version>${revision}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-config</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-system-impl</artifactId>
<version>1.6.1-snapshot</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-infra-impl</artifactId>
<version>1.6.1-snapshot</version>
<scope>compile</scope>
</dependency>
......
......@@ -69,6 +69,12 @@ public class RedeemRewardController {
return success(rewardRedeemService.verifyBack(redeemIds));
}
@PostMapping("record/export")
@ApiOperation("导出")
public CommonResult<Boolean> export(@Valid @RequestBody RewardRedeemPageReqVO reqVO) {
return success(rewardRedeemService.export(reqVO));
}
@PostMapping("/single")
@ApiOperation("兑换礼品")
......
......@@ -21,4 +21,6 @@ public interface RewardRedeemMapper extends AbstractMapper<RewardRedeemDO> {
int pageCount(@Param("req") RewardRedeemPageReqVO reqVO);
RewardRedeemPageRespVO detail(@Param("id") Long id);
List<RewardRedeemPageRespVO> exportList(@Param("req") RewardRedeemPageReqVO request);
}
package cn.iocoder.yudao.module.reward.listener;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.apollo.core.event.export.RewardRedeemRecordExportEvent;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.util.ExcelUtils;
import cn.iocoder.yudao.module.infra.api.file.FileApi;
import cn.iocoder.yudao.module.infra.api.file.dto.FileRespDto;
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
import cn.iocoder.yudao.module.reward.service.redeem.RewardRedeemService;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemPageReqVO;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemPageRespVO;
import cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemRecordExportVO;
import cn.iocoder.yudao.module.system.framework.ue.UeProperties;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileInputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.excel.constant.ExportConstant.DATA_FORMAT;
@Component
@AllArgsConstructor
@Slf4j
public class RewardRedeemRecordExportListener {
private RewardRedeemService rewardRedeemService;
private UeProperties ueProperties;
private FileApi fileService;
@EventListener(RewardRedeemRecordExportEvent.class)
public void listen(RewardRedeemRecordExportEvent event) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATA_FORMAT);
String nowTime = formatter.format(LocalDateTime.now());
String dir = ueProperties.getTempDir().concat("/rewardRedeemRecord/excel/");
File fileDir = new File(dir);
if (!fileDir.exists()){
// 不存在则创建一个目录
fileDir.mkdirs();
}
String fileName = event.getUserId().toString().concat(StrUtil.DASHED).concat(event.getUserType().toString()).concat(StrUtil.DASHED).concat(nowTime).concat("shipment_preload.xlsx");
RewardRedeemPageReqVO request = JSONObject.parseObject(event.getRequestParams(), RewardRedeemPageReqVO.class);
Integer totalCount = rewardRedeemService.exportCount(request);
int size = 500;
int totalPage = totalCount%size == 0 ? totalCount/size: totalCount/size + 1;
List<RewardRedeemRecordExportVO> result = new ArrayList<>();
for (int i = 1; i <= totalPage ; i++) {
request.setPageNo(i);
request.setPageSize(size);
PageResult<RewardRedeemPageRespVO> rewardRedeemPageRespVOPageResult = rewardRedeemService.pageInfo(request);
result.addAll(convert2ExcelVo(rewardRedeemPageRespVOPageResult.getList()));
}
try {
String path = ExcelUtils.write(dir, fileName, "数据", RewardRedeemRecordExportVO.class, result);
// 获取到临时文件
File file = new File(path);
// 创建FileInputStream对象
FileInputStream fileInputStream = new FileInputStream(file);
// 读取文件内容
byte[] fileBytes = new byte[(int) file.length()];
fileInputStream.read(fileBytes);
// 关闭文件流
fileInputStream.close();
// 将文件上传到资源服务器
FileRespDto fileRespDto = fileService.createFile(dir, fileName, fileBytes);
event.setPath(fileRespDto.getPath());
event.setFileName(fileRespDto.getFileName());
event.setUrl(fileRespDto.getUrl());
event.setFileId(fileRespDto.getId());
} catch (Exception e) {
log.info("reward redeem record export listener exception", e);
event.setResult(e.getMessage());
}
}
private Collection<RewardRedeemRecordExportVO> convert2ExcelVo(List<RewardRedeemPageRespVO> list) {
return list.stream().map(item -> {
RewardRedeemRecordExportVO exportVO = new RewardRedeemRecordExportVO();
exportVO.setId(String.valueOf(item.getId()));
exportVO.setStatus(item.getStatus());
exportVO.setRewardCode(item.getRewardCode());
exportVO.setRewardTitle(item.getRewardTitleZh());
exportVO.setMemberName(item.getMemberName());
exportVO.setRewardCount(item.getRewardCount());
exportVO.setRedeemType(item.getRedeemType());
exportVO.setEntrance(item.getEntrance());
exportVO.setExpenses(item.getExpenses());
exportVO.setCurrencyTitle(item.getCurrencyTitleZh());
exportVO.setRecipientName(item.getRecipientName());
exportVO.setRecipientPhoneNum(item.getRecipientPhoneNum());
exportVO.setRecipientAddress(item.getRecipientAddress());
exportVO.setRedeemer(item.getRedeemer());
exportVO.setRedemptionTime(item.getCreateTime());
exportVO.setCourierCompanyName(item.getCourierCompanyName());
exportVO.setExpressNo(item.getExpressNo());
exportVO.setExpressDate(item.getExpressDate());
exportVO.setExpressSender(item.getExpressSender());
exportVO.setRemark(item.getRemark());
exportVO.setVerifyUser(item.getVerifyUser());
exportVO.setVerifyTime(item.getVerifyTime());
exportVO.setCreatorName(item.getCreatorName());
exportVO.setCreateTime(item.getCreateTime());
exportVO.setUpdaterName(item.getUpdaterName());
exportVO.setUpdateTime(item.getUpdateTime());
return exportVO;
}).collect(Collectors.toList());
}
}
......@@ -25,4 +25,10 @@ public interface RewardRedeemService extends IService<RewardRedeemDO> {
Boolean batchVerify(RewardRedeemBatchVerifyReqVO request);
Boolean verifyBack(List<Long> redeemIds);
Boolean export(RewardRedeemPageReqVO reqVO);
List<RewardRedeemPageRespVO> exportList(RewardRedeemPageReqVO request);
Integer exportCount(RewardRedeemPageReqVO request);
}
package cn.iocoder.yudao.module.reward.service.redeem;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.i18n.core.I18nMessage;
import cn.iocoder.yudao.framework.mybatis.core.service.AbstractService;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.reward.dal.dataobject.redeem.RewardRedeemDO;
......@@ -11,6 +12,9 @@ import cn.iocoder.yudao.module.reward.enums.RewardPickMethedEnum;
import cn.iocoder.yudao.module.reward.enums.RewardRedeemStatusEnum;
import cn.iocoder.yudao.module.reward.service.reward.RewardService;
import cn.iocoder.yudao.module.reward.vo.reward.*;
import cn.iocoder.yudao.module.system.api.file.FileMakeApi;
import cn.iocoder.yudao.module.system.api.file.dto.FileMakeReqDTO;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
......@@ -19,6 +23,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -26,6 +31,7 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.download.DownloadTypeEnum.REWARD_REDEEM_RECORD;
/**
* 礼品兑换 Service
......@@ -39,6 +45,8 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
private RewardRedeemMapper rewardRedeemMapper;
@Resource
private RewardService rewardService;
@Resource
private FileMakeApi fileMakeApi;
@Override
public PageResult<RewardRedeemPageRespVO> pageInfo(RewardRedeemPageReqVO reqVO) {
......@@ -152,6 +160,29 @@ public class RewardRedeemServiceImpl extends AbstractService<RewardRedeemMapper,
return true;
}
@Override
public Boolean export(RewardRedeemPageReqVO reqVO) {
FileMakeReqDTO fileMakeReqDTO = new FileMakeReqDTO();
fileMakeReqDTO.setType(REWARD_REDEEM_RECORD.getType());
fileMakeReqDTO.setName("礼品兑换记录导出excel");
fileMakeReqDTO.setFileSuffix("xlsx");
fileMakeReqDTO.setTemporaryFile(true);
fileMakeReqDTO.setUserType(2);
fileMakeReqDTO.setLang(I18nMessage.getLang());
fileMakeReqDTO.setRequestParams(JSONObject.toJSONString(reqVO));
fileMakeApi.sendFileMake(fileMakeReqDTO);
return true;
}
@Override
public List<RewardRedeemPageRespVO> exportList(RewardRedeemPageReqVO request) {
return rewardRedeemMapper.exportList(request);
}
@Override
public Integer exportCount(RewardRedeemPageReqVO request) {
return rewardRedeemMapper.pageCount(request);
}
private List<Long> checkBatchVerifyParam(RewardRedeemBatchVerifyReqVO request) {
LambdaUpdateWrapper<RewardRedeemDO> wrapper = Wrappers.lambdaUpdate();
wrapper.in(RewardRedeemDO::getId, request.getIds());
......
......@@ -88,7 +88,7 @@ public class RewardRedeemBaseVO {
* 快递日期
*/
@ApiModelProperty(value = "快递日期")
private String expressDate;
private Date expressDate;
/**
* 快递寄出人
*/
......@@ -111,7 +111,7 @@ public class RewardRedeemBaseVO {
@ApiModelProperty(value = "更新人id")
private String updater;
@ApiModelProperty(value = "更新时间")
private String updateTime;
private Date updateTime;
@ApiModelProperty(value = "是否删除")
private Boolean deleted;
/**
......@@ -123,5 +123,5 @@ public class RewardRedeemBaseVO {
* 核销时间
*/
@ApiModelProperty(value = "核销时间")
private String verifyTime;
private Date verifyTime;
}
......@@ -23,12 +23,15 @@ public class RewardRedeemPageRespVO extends RewardRedeemBaseVO {
private String nodeTitleEn;
@ApiModelProperty(value = "兑换积分")
private Integer totalCount;
@ApiModelProperty(value = "创建人时间")
@ApiModelProperty(value = "创建人")
private String creatorName;
@ApiModelProperty(value = "更新人时间")
@ApiModelProperty(value = "更新人")
private String updaterName;
@ApiModelProperty(value = "币种名称中文")
private String currencyTitleZh;
@ApiModelProperty(value = "币种名称英文")
private String currencyTitleEn;
@ApiModelProperty(value = "快递公司名称")
private String courierCompanyName;
}
package cn.iocoder.yudao.module.reward.vo.reward;
import cn.iocoder.yudao.framework.excel.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.convert.DictConvert;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.converters.bigdecimal.BigDecimalStringConverter;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
@Data
public class RewardRedeemRecordExportVO {
@ExcelProperty("兑换记录ID")
private String id;
@ExcelProperty(value = "兑换状态", converter = DictConvert.class)
@DictFormat("reward_redeem_status")
private Integer status;
@ExcelProperty("礼品ID")
private String rewardCode;
@ExcelProperty("礼品名称")
private String rewardTitle;
@ExcelProperty("会员名称")
private String memberName;
@ExcelProperty("兑换数量")
private Integer rewardCount;
@ExcelProperty(value = "兑换方式", converter = DictConvert.class)
@DictFormat("way_of_receiving")
private Integer redeemType;
@ExcelProperty(value = "兑换入口", converter = DictConvert.class)
@DictFormat("platform_type")
private Integer entrance;
@ExcelProperty(value = "费用", converter = BigDecimalStringConverter.class)
private BigDecimal expenses;
@ExcelProperty("币种名称")
private String currencyTitle;
@ExcelProperty(value = "收件人姓名")
private String recipientName;
@ExcelProperty(value = "收件人电话")
private String recipientPhoneNum;
@ExcelProperty(value = "收件人地址")
private String recipientAddress;
@ExcelProperty(value = "兑换人")
private String redeemer;
@ExcelProperty(value = "兑换时间")
private Date redemptionTime;
@ExcelProperty(value = "快递公司名称")
private String courierCompanyName;
@ExcelProperty(value = "快递单号")
private String expressNo;
@ExcelProperty(value = "快递日期")
private Date expressDate;
@ExcelProperty(value = "快递寄出人")
private String expressSender;
@ExcelProperty(value = "备注")
private String remark;
@ExcelProperty(value = "核销人")
private String verifyUser;
@ExcelProperty(value = "核销时间")
private Date verifyTime;
@ExcelProperty(value = "创建人")
private String creatorName;
@ExcelProperty(value = "创建时间")
private Date createTime;
@ExcelProperty(value = "更新人")
private String updaterName;
@ExcelProperty(value = "更新时间")
private Date updateTime;
}
......@@ -19,6 +19,7 @@
left join system_user suc on suc.id = er.creator
left join system_user suu on suu.id = er.updater
left join ecw_currency cc on err.currency = cc.id
left join ecw_express ee on err.courier_company = ee.id
where 1=1
<include refid="pageCondition"/>
order by er.create_time desc
......@@ -32,6 +33,7 @@
left join ecw_node en on er.node_id = en.id
left join system_user suc on suc.id = er.creator
left join system_user suu on suu.id = er.updater
left join ecw_express ee on err.courier_company = ee.id
where 1=1
<include refid="pageCondition"/>
</select>
......@@ -45,8 +47,24 @@
left join system_user suc on suc.id = er.creator
left join system_user suu on suu.id = er.updater
left join ecw_currency cc on err.currency = cc.id
left join ecw_express ee on err.courier_company = ee.id
where err.id = #{id}
</select>
<select id="exportList" resultType="cn.iocoder.yudao.module.reward.vo.reward.RewardRedeemPageRespVO">
select
<include refid="columns"/>
from ecw_reward_redeem err
left join ecw_reward er on err.reward_id = er.id
left join member_user mu on mu.id = err.member_id
left join ecw_node en on er.node_id = en.id
left join system_user suc on suc.id = er.creator
left join system_user suu on suu.id = er.updater
left join ecw_currency cc on err.currency = cc.id
left join ecw_express ee on err.courier_company = ee.id
where 1=1
<include refid="pageCondition"/>
order by er.create_time desc
</select>
<sql id="columns">
err.id ,
......@@ -64,6 +82,7 @@
err.redeemer,
err.redemption_time as redemptionTime,
err.courier_company as courierCompany,
ee.company_name as courierCompanyName,
err.express_no as expressNo,
err.express_date as expressDate,
err.express_sender as expressSender,
......
......@@ -174,6 +174,11 @@ public enum DownloadTypeEnum implements IntArrayValuable {
*/
REPORT_SALES_ANALYSIS(32),
/**
* 礼品兑换记录
*/
REWARD_REDEEM_RECORD(33),
// ....自己补充
;
......
......@@ -362,6 +362,9 @@ public class DownloadLogServiceImpl extends AbstractService<DownloadLogMapper, D
//销售分析报表
REPORT_SALES_ANALYSIS_Event(downloadLog);
break;
case REWARD_REDEEM_RECORD:
rewardRedeemRecordExportPushEvent(downloadLog);
break;
default:
downloadLog.setResult("unknown type");
break;
......@@ -388,6 +391,20 @@ public class DownloadLogServiceImpl extends AbstractService<DownloadLogMapper, D
}
}
private void rewardRedeemRecordExportPushEvent(DownloadLogDO downloadLog) {
RewardRedeemRecordExportEvent event = new RewardRedeemRecordExportEvent();
event.setUserId(downloadLog.getUserId());
event.setUserType(downloadLog.getUserType());
event.setLang(downloadLog.getLang());
event.setRequestParams(downloadLog.getRequestParams());
applicationContext.publishEvent(event);
downloadLog.setFileName(event.getFileName());
downloadLog.setPath(event.getPath());
downloadLog.setDownloadUrl(event.getUrl());
downloadLog.setResult(event.getResult());
downloadLog.setFileId(event.getFileId());
}
private void achievementDetailExcelExportPushEvent(DownloadLogDO downloadLog) {
AchievementDetailExcelExportPushEvent event = new AchievementDetailExcelExportPushEvent();
event.setUserId(downloadLog.getUserId());
......
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