优化
This commit is contained in:
@@ -20,6 +20,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||
@@ -108,4 +109,29 @@ public class RedeemCodeController {
|
||||
BeanUtils.toBean(list, RedeemCodeRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-plain")
|
||||
@Operation(summary = "导出兑换码纯文本(按批次号,用于自动发货软件)")
|
||||
@Parameter(name = "batchNo", description = "批次号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('muye:redeem-code:export')")
|
||||
public void exportRedeemCodePlain(@RequestParam("batchNo") String batchNo,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<RedeemCodeDO> list = redeemCodeService.getRedeemCodeListByBatchNo(batchNo);
|
||||
|
||||
// 只导出未使用的码
|
||||
List<String> codes = list.stream()
|
||||
.filter(c -> c.getStatus() == RedeemCodeDO.STATUS_ENABLED)
|
||||
.map(RedeemCodeDO::getCode)
|
||||
.toList();
|
||||
|
||||
response.setContentType("text/plain; charset=UTF-8");
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment; filename=codes_" + batchNo + ".txt");
|
||||
|
||||
PrintWriter writer = response.getWriter();
|
||||
for (String code : codes) {
|
||||
writer.println(code);
|
||||
}
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -99,5 +99,11 @@ public class RedeemCodeDO extends BaseDO {
|
||||
public static final String SOURCE_PAY = "pay";
|
||||
/** 来源:礼包赠送 */
|
||||
public static final String SOURCE_GIFT = "gift";
|
||||
/** 来源:淘宝 */
|
||||
public static final String SOURCE_TAOBAO = "taobao";
|
||||
/** 来源:闲鱼 */
|
||||
public static final String SOURCE_XIANYU = "xianyu";
|
||||
/** 来源:活动发放 */
|
||||
public static final String SOURCE_ACTIVITY = "activity";
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 兑换码 Mapper
|
||||
*
|
||||
@@ -47,4 +49,13 @@ public interface RedeemCodeMapper extends BaseMapperX<RedeemCodeDO> {
|
||||
.orderByDesc(RedeemCodeDO::getId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据批次号查询列表
|
||||
*/
|
||||
default List<RedeemCodeDO> selectListByBatchNo(String batchNo) {
|
||||
return selectList(new LambdaQueryWrapperX<RedeemCodeDO>()
|
||||
.eq(RedeemCodeDO::getBatchNo, batchNo)
|
||||
.orderByAsc(RedeemCodeDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -94,4 +94,12 @@ public interface RedeemCodeService {
|
||||
*/
|
||||
String issueCodeAfterPayment(Long userId, Integer points, String sourceId);
|
||||
|
||||
/**
|
||||
* 根据批次号获取兑换码列表
|
||||
*
|
||||
* @param batchNo 批次号
|
||||
* @return 兑换码列表
|
||||
*/
|
||||
List<RedeemCodeDO> getRedeemCodeListByBatchNo(String batchNo);
|
||||
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class RedeemCodeServiceImpl implements RedeemCodeService {
|
||||
.maxUseCount(generateReqVO.getMaxUseCount() != null ? generateReqVO.getMaxUseCount() : 1)
|
||||
.usedCount(0)
|
||||
.batchNo(batchNo)
|
||||
.source(RedeemCodeDO.SOURCE_ADMIN)
|
||||
.source(generateReqVO.getSource() != null ? generateReqVO.getSource() : RedeemCodeDO.SOURCE_ADMIN)
|
||||
.expireTime(generateReqVO.getExpireTime())
|
||||
.status(RedeemCodeDO.STATUS_ENABLED)
|
||||
.remark(generateReqVO.getRemark())
|
||||
@@ -250,6 +250,11 @@ public class RedeemCodeServiceImpl implements RedeemCodeService {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RedeemCodeDO> getRedeemCodeListByBatchNo(String batchNo) {
|
||||
return redeemCodeMapper.selectListByBatchNo(batchNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成唯一兑换码
|
||||
*/
|
||||
|
||||
@@ -38,4 +38,7 @@ public class RedeemCodeGenerateReqVO {
|
||||
@Schema(description = "操作人账号", example = "admin")
|
||||
private String operatorName;
|
||||
|
||||
@Schema(description = "来源", example = "taobao")
|
||||
private String source;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user