将List集合导出为Excel

@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);
	}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值