| | |
| | | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | 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; |
| | | } |
| | | } |