From 87630e05daa721f9f742787db0d7b9749d8c2649 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期四, 19 十二月 2024 16:20:46 +0800 Subject: [PATCH] 代码 --- manage/src/main/java/com/jilongda/manage/controller/TAppUserController.java | 78 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 76 insertions(+), 2 deletions(-) diff --git a/manage/src/main/java/com/jilongda/manage/controller/TAppUserController.java b/manage/src/main/java/com/jilongda/manage/controller/TAppUserController.java index 366dd41..23f26e3 100644 --- a/manage/src/main/java/com/jilongda/manage/controller/TAppUserController.java +++ b/manage/src/main/java/com/jilongda/manage/controller/TAppUserController.java @@ -1,9 +1,27 @@ package com.jilongda.manage.controller; -import org.springframework.web.bind.annotation.RequestMapping; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.jilongda.common.basic.ApiResult; +import com.jilongda.common.basic.PageInfo; +import com.jilongda.manage.model.TAppUser; +import com.jilongda.manage.model.TOptometry; +import com.jilongda.manage.model.TOrder; +import com.jilongda.manage.query.TAppUserQuery; +import com.jilongda.manage.query.TOptometristQuery; +import com.jilongda.manage.service.TAppUserService; +import com.jilongda.manage.service.TOptometryService; +import com.jilongda.manage.service.TOrderService; +import com.jilongda.manage.vo.TAppUserVO; +import com.jilongda.manage.vo.TOptometristVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.BeanUtils; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; -import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; +import java.math.BigDecimal; /** * <p> @@ -14,8 +32,64 @@ * @since 2024-12-09 */ @RestController +@Api(tags = "用户管理") @RequestMapping("/t-app-user") public class TAppUserController { + @Resource + private TAppUserService appUserService; + @Resource + private TOrderService orderService; + @Resource + private TOptometryService tOptometryService; + @ApiOperation(value = "用户列表") + @PostMapping(value = "/pageList") + public ApiResult<PageInfo<TAppUserVO>> pageList(@RequestBody TAppUserQuery query) { + if (StringUtils.hasLength(query.getStartTime())){ + query.setStartTime(query.getStartTime()+" 00:00:00"); + query.setEndTime(query.getEndTime()+" 23:59:59"); + } + PageInfo<TAppUserVO> appUserVOPageInfo = appUserService.pageList(query); + return ApiResult.success(appUserVOPageInfo); + } + @ApiOperation(value = "启用/禁用") + @GetMapping(value = "/updateState") + public ApiResult updateState(Integer id) { + TAppUser byId = appUserService.getById(id); + if (byId.getStatus()==1){ + byId.setStatus(2); + }else{ + byId.setStatus(1); + } + appUserService.updateById(byId); + return ApiResult.success(); + } + @ApiOperation(value = "用户详情") + @GetMapping(value = "/getDetailById") + public ApiResult<TAppUserVO> getDetailById(Integer id) { + TAppUser byId = appUserService.getById(id); + TAppUserVO tAppUserVO = new TAppUserVO(); + BeanUtils.copyProperties(byId, tAppUserVO); + // 查询消费次数 + long l = orderService.count(new LambdaQueryWrapper<TOrder>() + .eq(TOrder::getUserId, tAppUserVO.getId())); + tAppUserVO.setSalesCount((int) l); + // 查询验光次数 + int size = tOptometryService.lambdaQuery().eq(TOptometry::getUserId, tAppUserVO.getId()) + .eq(TOptometry::getStatus, 3).list().size(); + tAppUserVO.setOptometryCount(size); + // 查询最后消费时间 + tAppUserVO.setSalesTime(orderService.lambdaQuery().eq(TOrder::getUserId, tAppUserVO.getId()) + .orderByDesc(TOrder::getCreateTime).last("limit 1").one().getCreateTime()); + // 查询最后验光时间 + tAppUserVO.setOptometryTime(tOptometryService.lambdaQuery().eq(TOptometry::getUserId, tAppUserVO.getId()) + .eq(TOptometry::getStatus, 3).orderByDesc(TOptometry::getCreateTime).last("limit 1").one().getCreateTime()); + // 查询订单总额 + BigDecimal reduce = orderService.lambdaQuery().eq(TOrder::getUserId, byId.getId()).list().stream().map(TOrder::getPayMoney) + .reduce(BigDecimal.ZERO, BigDecimal::add); + tAppUserVO.setSalesAmount(reduce); + + return ApiResult.success(tAppUserVO); + } } -- Gitblit v1.7.1