From 8a66f76e0b0af13ccdba14f1d38eed91139ca124 Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期四, 23 三月 2023 11:41:43 +0800 Subject: [PATCH] 处理TODO,导出部分修改 --- management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TAppUserServiceImpl.java | 43 +++++++++++++++++++++++++++++++++++++++---- 1 files changed, 39 insertions(+), 4 deletions(-) diff --git a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TAppUserServiceImpl.java b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TAppUserServiceImpl.java index e4091f2..632cd90 100644 --- a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TAppUserServiceImpl.java +++ b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TAppUserServiceImpl.java @@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.stylefeng.guns.core.util.DateUtil; +import com.stylefeng.guns.modular.system.controller.resp.TAppUserResp; import com.stylefeng.guns.modular.system.dao.TCouponMapper; import com.stylefeng.guns.modular.system.dao.TOrderMapper; import com.stylefeng.guns.modular.system.dao.TUserToCouponMapper; @@ -15,6 +16,7 @@ import com.stylefeng.guns.modular.system.model.TUserToCoupon; import com.stylefeng.guns.modular.system.service.ITAppUserService; import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.ui.Model; @@ -22,10 +24,7 @@ import org.springframework.util.StringUtils; import java.math.BigDecimal; -import java.util.Date; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; /** @@ -155,4 +154,40 @@ wrapper.ne("status", StatusEnum.DELETE.getCode()); return wrapper; } + + @Override + public List<TAppUserResp> getTAppUserResp(List<TAppUser> tAppUsers) { + List<TAppUserResp> tAppUserRespList = new ArrayList<>(tAppUsers.size()); + for (TAppUser tAppUser : tAppUsers) { + TAppUserResp tAppUserResp = new TAppUserResp(); + BeanUtils.copyProperties(tAppUser,tAppUserResp); + + // 查询当前用户优惠券数量 + List<TUserToCoupon> tUserToCoupons = tUserToCouponMapper.selectList(new EntityWrapper<TUserToCoupon>().eq("userId", tAppUser.getId())); + + int couponTotal = tUserToCoupons.stream().mapToInt(TUserToCoupon::getCouponTotal).sum(); + int validCount = tUserToCoupons.stream().mapToInt(TUserToCoupon::getValidCount).sum(); + +// List<TCoupon> tCoupons = tCouponService.selectList(new EntityWrapper<TCoupon>().eq("user_id", tAppUser.getId())); +// List<TCoupon> notUsedList = tCoupons.stream().filter(coupon -> coupon.getCouponStatus().equals(CouponStatusEnum.NOT_USED.getCode())).collect(Collectors.toList()); + tAppUserResp.setCouponSum(couponTotal); + tAppUserResp.setNotUsedCount(validCount); + List<TOrder> orders = tOrderMapper.selectList(new EntityWrapper<TOrder>().eq("userId", tAppUser.getId()).orderBy(true,"createTime",false)); + if(!CollectionUtils.isEmpty(orders)){ + // 最后一次消费时间 + tAppUserResp.setLastConsumptionTime(orders.get(0).getCreateTime()); + List<TOrder> collect1 = orders.stream().filter(order->Objects.nonNull(order.getState())) + .filter(order -> OrderStateEnum.WAIT_EVALUATED.getCode() == order.getState() || + OrderStateEnum.FINISH.getCode() == order.getState()).collect(Collectors.toList()); + if(!CollectionUtils.isEmpty(collect1)) { + tAppUserResp.setConsumeSum(collect1.size()); + // 总消费金额 + collect1.stream().map(TOrder::getPayMoney).reduce(BigDecimal::add) + .ifPresent(tAppUserResp::setConsumePrice); + } + } + tAppUserRespList.add(tAppUserResp); + } + return tAppUserRespList; + } } -- Gitblit v1.7.1