@Override
@Transactional
public com.chitai.saasplatform.base.framework.result.Result<String> exportApply2(Long id) {
CouponApply couponApply = couponApplyDao.selectByPrimaryKey(id);
// 记录导出信息
saveRecord2(id, OperationTypeEnum.EXPPORT.getCode(), RecordTypeEnum.EXPPORT.getCode(), "");
// 导出券码
MutipleCondition where = new MutipleCondition();
where.add(new SingleCondition().setField(CouponInfoDao.applyId).setOperator(CompareOperator.EQUAL).setLongs(id));
List<CouponInfo> couponInfoList = couponInfoDao.selectByCondition(where, CommonConstant.ORDER_CREATED);
List<CouponApplyRule> couponApplyRuleList = couponApplyRuleDao.selectByCondition(where,CommonConstant.ORDER_CREATED);
// 获取CouponInfo的规则id,转为List集合
// couponInfoList:一个实体类的集合,类型为List<CouponInfo>
// CouponInfo:实体类,map是为了映射每个元素到对应结果
// getRuleId:实体类中的get方法,为获取规则id
List<Long> ruleIds = couponInfoList.stream().map(CouponInfo::getRuleId).collect(Collectors.toList());
List<CouponRule> couponRuleList = couponRuleDao.selectByPrimaryKeys(ruleIds);
List<CouponExportVO> couponExportVOList = new ArrayList<>();
for (CouponRule couponRule : couponRuleList) {
CouponExportVO couponExportVO = new CouponExportVO();
BeanUtil.copyProperties(couponRule, couponExportVO);
couponExportVO.setCouponTypeStr(EnumCouponType.parseId(couponRule.getStatus()).getTitle());
couponExportVO.setCouponCode(
couponInfoList.stream().filter(couponInfo -> couponInfo.getRuleId().equals(couponRule.getId()))
.collect(Collectors.toList()).get(0).getCouponCode());
Long unitPrice = couponApplyRuleList.stream()
.filter(couponApplyRule -> couponApplyRule.getRuleId().equals(couponRule.getId()))
.collect(Collectors.toList()).get(0).getUnitPrice();
couponExportVO.setUnitPrice(null != unitPrice ? PriceHelper.fen2YuanStr(unitPrice) : null);
couponExportVOList.add(couponExportVO);
}
String[] titles = { "券规则名称", "券类型", "券码", "生效时间", "失效时间", "截止兑回时间", "单价" };
String[] cols = { "name", "couponTypeStr", "couponCode", "effectiveDate", "expirationDate", "cutoffInspectTime",
"unitPrice" };
Map<String, Object> map = new HashMap<>(6);
map.put("list", couponExportVOList);
map.put("titles", titles);
map.put("cols", cols);
map.put("fileName", couponApply.getCode() + ".xlsx");
map.put("title", "");
return commonFeignService.upload(map);
}
将List集合导出为Excel
最新推荐文章于 2023-11-09 15:47:35 发布