From adb18caa714692ccabf111ae3ab3481bf04844d4 Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期二, 28 二月 2023 18:03:01 +0800 Subject: [PATCH] 订单管理,优惠券管理 --- management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TAppUserController.java | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 46 insertions(+), 4 deletions(-) diff --git a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TAppUserController.java b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TAppUserController.java index 216eed1..f707d54 100644 --- a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TAppUserController.java +++ b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TAppUserController.java @@ -3,13 +3,19 @@ import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.stylefeng.guns.core.base.controller.BaseController; import com.stylefeng.guns.core.log.LogObjectHolder; +import com.stylefeng.guns.modular.system.controller.resp.TAppUserResp; import com.stylefeng.guns.modular.system.controller.util.ExcelUtil; import com.stylefeng.guns.modular.system.enums.CouponStatusEnum; +import com.stylefeng.guns.modular.system.enums.OrderStateEnum; import com.stylefeng.guns.modular.system.exports.TAppUserExceptionExport; import com.stylefeng.guns.modular.system.model.TAppUser; import com.stylefeng.guns.modular.system.model.TCoupon; +import com.stylefeng.guns.modular.system.model.TOrder; +import com.stylefeng.guns.modular.system.model.TUserToCoupon; import com.stylefeng.guns.modular.system.service.ITAppUserService; import com.stylefeng.guns.modular.system.service.ITCouponService; +import com.stylefeng.guns.modular.system.service.ITOrderService; +import com.stylefeng.guns.modular.system.service.ITUserToCouponService; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; @@ -18,10 +24,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.OutputStream; +import java.math.BigDecimal; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -46,6 +54,10 @@ private ITAppUserService tAppUserService; @Autowired private ITCouponService tCouponService; + @Autowired + private ITOrderService tOrderService; + @Autowired + private ITUserToCouponService tUserToCouponService; /** * 跳转到首页 @@ -139,7 +151,6 @@ @RequestMapping("/userDetail") public String userDetail(Integer tAppUserId, Model model) { tAppUserService.detail(tAppUserId,model); - return PREFIX + "tAppUserDetail.html"; } @@ -164,7 +175,37 @@ EntityWrapper<TAppUser> wrapper = tAppUserService.getUserListWrapper(createTime,nickname,phone,id,status); // 是否异常 wrapper.eq("is_exception",2); - return tAppUserService.selectList(wrapper); + List<TAppUser> tAppUsers = tAppUserService.selectList(wrapper); + List<TAppUserResp> tAppUserRespList = new ArrayList<>(tAppUsers.size()); + for (TAppUser tAppUser : tAppUsers) { + TAppUserResp tAppUserResp = new TAppUserResp(); + BeanUtils.copyProperties(tAppUser,tAppUserResp); + + // 查询当前用户优惠券数量 + List<TUserToCoupon> tUserToCoupons = tUserToCouponService.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 = tOrderService.selectList(new EntityWrapper<TOrder>().eq("userId", tAppUser.getId()).orderBy(true,"createTime",false)); + if(!CollectionUtils.isEmpty(orders)){ + 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; } @@ -180,6 +221,7 @@ Integer id, Integer status) { EntityWrapper<TAppUser> wrapper = tAppUserService.getUserListWrapper(createTime,nickname,phone,id,status); + wrapper.ne("is_exception",2); return tAppUserService.selectList(wrapper); } @@ -213,7 +255,7 @@ } /** - * 修改 + * 修改用户状态 */ @RequestMapping(value = "/update-status") @ResponseBody @@ -270,8 +312,8 @@ String[] title = new String[] {"用户ID","用户昵称","手机号","性别","头像","微信openid", "微信unionid","紧急联系人","紧急联系电话","账户余额","用户标签id","状态","添加时间"}; EntityWrapper<TAppUser> wrapper = tAppUserService.getUserListWrapper(createTime,nickname,phone,id,status); + wrapper.ne("is_exception",2); // 是否异常 - wrapper.eq("is_exception",2); List<TAppUser> list = tAppUserService.selectList(wrapper); String[][] values = new String[list.size()][]; -- Gitblit v1.7.1