diff --git a/src/main/java/com/cultural/heritage/controller/operategood/GoodController.java b/src/main/java/com/cultural/heritage/controller/operategood/GoodController.java index 2d4acb5..1bc1401 100644 --- a/src/main/java/com/cultural/heritage/controller/operategood/GoodController.java +++ b/src/main/java/com/cultural/heritage/controller/operategood/GoodController.java @@ -1,6 +1,7 @@ package com.cultural.heritage.controller.operategood; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.cultural.heritage.annotation.AuthCheck; import com.cultural.heritage.common.BaseResponse; import com.cultural.heritage.common.ErrorCode; @@ -8,7 +9,10 @@ import com.cultural.heritage.common.ResultUtils; import com.cultural.heritage.constant.UserConstant; import com.cultural.heritage.controller.userinfo.UserController; import com.cultural.heritage.exception.BusinessException; +import com.cultural.heritage.exception.ThrowUtils; +import com.cultural.heritage.model.dto.CommonRequest; import com.cultural.heritage.model.dto.good.GoodAddRequest; +import com.cultural.heritage.model.dto.good.GoodUpdateRequest; import com.cultural.heritage.model.entity.Good; import com.cultural.heritage.service.operategood.GoodService; import io.swagger.v3.oas.annotations.tags.Tag; @@ -50,7 +54,6 @@ public class GoodController { } Good good = new Good(); BeanUtils.copyProperties(goodAddRequest, good); - good.setIsGoodType(1); boolean save = goodService.save(good); if (!save) { throw new BusinessException(ErrorCode.SYSTEM_ERROR); @@ -59,5 +62,46 @@ public class GoodController { } + /** + * 删除商品 + * @param deleteRequest 商品删除请求体 + * @return 是否删除成功 + */ + @PostMapping("/delete") +// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse deleteGood(@RequestBody CommonRequest deleteRequest) { + if (deleteRequest == null || deleteRequest.getId() == null) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + boolean result = goodService.removeById(deleteRequest.getId()); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR); + return ResultUtils.success(true); + } + + + /** + * 更新商品 + * @param goodUpdateRequest 商品更新请求体 + * @return 是否更新成功 + */ + @PostMapping("/update") +// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse updateGoods(@RequestBody GoodUpdateRequest goodUpdateRequest) { + if (goodUpdateRequest == null || goodUpdateRequest.getId() == null) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + Good good = new Good(); + BeanUtils.copyProperties(goodUpdateRequest, good); + boolean result = goodService.updateById(good); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR); + return ResultUtils.success(true); + } + + +// @PostMapping("/list/page") +//// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) +// public BaseResponse> listGoodByPage(@RequestBody ) + + } diff --git a/src/main/java/com/cultural/heritage/controller/userinfo/UserController.java b/src/main/java/com/cultural/heritage/controller/userinfo/UserController.java index cd4d118..00518a7 100644 --- a/src/main/java/com/cultural/heritage/controller/userinfo/UserController.java +++ b/src/main/java/com/cultural/heritage/controller/userinfo/UserController.java @@ -1,15 +1,11 @@ package com.cultural.heritage.controller.userinfo; -import cn.hutool.core.util.IdUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.cultural.heritage.annotation.AuthCheck; import com.cultural.heritage.common.BaseResponse; import com.cultural.heritage.common.ErrorCode; import com.cultural.heritage.common.ResultUtils; -import com.cultural.heritage.constant.CommonConstant; -import com.cultural.heritage.constant.UserConstant; import com.cultural.heritage.exception.BusinessException; import com.cultural.heritage.exception.ThrowUtils; import com.cultural.heritage.model.dto.CommonRequest; @@ -17,27 +13,19 @@ import com.cultural.heritage.model.dto.user.*; import com.cultural.heritage.model.entity.User; import com.cultural.heritage.model.vo.UserVO; import com.cultural.heritage.service.userinfo.UserService; -import com.wf.captcha.SpecCaptcha; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; -import org.apache.catalina.webresources.ExtractingRoot; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; -import org.springframework.context.annotation.Bean; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.util.DigestUtils; import org.springframework.web.bind.annotation.*; -import javax.xml.transform.Result; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; import static com.cultural.heritage.constant.UserConstant.SALT; -import static com.cultural.heritage.constant.UserConstant.USER_LOGIN_STATE; /** * 用户接口 @@ -234,25 +222,55 @@ public class UserController { /** - * 图形验证码 - * @return + * 分页获取用户封装列表 + * + * @param userQueryRequest 查询用户请求体 + * @return 脱敏用户信息列表 */ - @GetMapping("/captcha") - public BaseResponse getCapthca(){ - //设置生成的长宽还有数字位数 - SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 4); - String code = specCaptcha.text().toLowerCase(); - String uuid = IdUtil.simpleUUID(); - redisTemplate.opsForValue().set(uuid,code,120, TimeUnit.SECONDS); - HashMap map = new HashMap<>(3); - map.put("uuid",uuid); - map.put("code",code); - map.put("captcha",specCaptcha.toBase64()); - return ResultUtils.success(map,"成功"); + @PostMapping("/list/page/vo") +// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse> listUserVOByPage(@RequestBody UserQueryRequest userQueryRequest) { + if (userQueryRequest == null) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + long current = userQueryRequest.getCurrent(); + long pageSize = userQueryRequest.getPageSize(); +// ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR); + QueryWrapper queryWrapper = userService.getQueryWrapper(userQueryRequest); + Page userPage = userService.page(new Page<>(current, pageSize), queryWrapper); + + Page userVOPage = new Page<>(current, pageSize, userPage.getTotal()); + List userVO = userService.getUserVO(userPage.getRecords()); + + userVOPage.setRecords(userVO); + return ResultUtils.success(userVOPage); } + +// /** +// * 图形验证码 +// * @return +// */ +// @GetMapping("/captcha") +// public BaseResponse getCapthca(){ +// //设置生成的长宽还有数字位数 +// SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 4); +// String code = specCaptcha.text().toLowerCase(); +// String uuid = IdUtil.simpleUUID(); +// redisTemplate.opsForValue().set(uuid,code,120, TimeUnit.SECONDS); +// HashMap map = new HashMap<>(3); +// map.put("uuid",uuid); +// map.put("code",code); +// map.put("captcha",specCaptcha.toBase64()); +// return ResultUtils.success(map,"成功"); +// } + + + + + } diff --git a/src/main/java/com/cultural/heritage/model/dto/good/GoodQueryRequest.java b/src/main/java/com/cultural/heritage/model/dto/good/GoodQueryRequest.java new file mode 100644 index 0000000..f0ac787 --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/dto/good/GoodQueryRequest.java @@ -0,0 +1,10 @@ +package com.cultural.heritage.model.dto.good; + +import com.cultural.heritage.common.PageRequest; +import lombok.Data; + +@Data +public class GoodQueryRequest extends PageRequest { + + +} diff --git a/src/main/java/com/cultural/heritage/model/dto/good/GoodUpdateRequest.java b/src/main/java/com/cultural/heritage/model/dto/good/GoodUpdateRequest.java new file mode 100644 index 0000000..1e6b46a --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/dto/good/GoodUpdateRequest.java @@ -0,0 +1,63 @@ +package com.cultural.heritage.model.dto.good; + +import com.baomidou.mybatisplus.annotation.TableField; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class GoodUpdateRequest implements Serializable { + + /** + * id + */ + private Long id; + + /** + * 商品名 + */ + private String name; + + /** + * 商品类型 + */ + private String type; + + /** + * 商品图片 + */ + private String goodImg; + + /** + * 商品简介 + */ + private String intro; + + /** + * 商品详情简介 + */ + private String introDetail; + + /** + * 商品详情图片 + */ + private String detailImg; + + /** + * 商品标签 + */ + private String label; + + /** + * 商品库存量 + */ + private Integer inventory; + + /** + * 节日限定序号 + */ + private Integer festivalOrder; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/cultural/heritage/model/dto/user/UserQueryRequest.java b/src/main/java/com/cultural/heritage/model/dto/user/UserQueryRequest.java index 419e818..10112a5 100644 --- a/src/main/java/com/cultural/heritage/model/dto/user/UserQueryRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/user/UserQueryRequest.java @@ -36,5 +36,5 @@ public class UserQueryRequest extends PageRequest implements Serializable { private String userRole; @Serial - private static final long serialVersionUID = -8778649230187591764L; + private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateRequest.java b/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateRequest.java index 25f87a4..e45a9d6 100644 --- a/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateRequest.java @@ -40,6 +40,6 @@ public class UserUpdateRequest implements Serializable { private String userRole; @Serial - private static final long serialVersionUID = -5057503930700700941L; + private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/cultural/heritage/service/userinfo/UserService.java b/src/main/java/com/cultural/heritage/service/userinfo/UserService.java index aada41e..13a04cc 100644 --- a/src/main/java/com/cultural/heritage/service/userinfo/UserService.java +++ b/src/main/java/com/cultural/heritage/service/userinfo/UserService.java @@ -7,6 +7,8 @@ import com.cultural.heritage.model.entity.User; import com.cultural.heritage.model.vo.UserVO; import jakarta.servlet.http.HttpServletRequest; +import java.util.List; + public interface UserService extends IService { /** @@ -37,4 +39,10 @@ public interface UserService extends IService { * 获取查询条件 */ QueryWrapper getQueryWrapper(UserQueryRequest userQueryRequest); + + + /** + * 获取脱敏的用户信息 + */ + List getUserVO(List userList); } diff --git a/src/main/java/com/cultural/heritage/service/userinfo/impl/UserServiceImpl.java b/src/main/java/com/cultural/heritage/service/userinfo/impl/UserServiceImpl.java index 3a98064..5949d28 100644 --- a/src/main/java/com/cultural/heritage/service/userinfo/impl/UserServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/userinfo/impl/UserServiceImpl.java @@ -18,8 +18,13 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import org.springframework.util.DigestUtils; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + import static com.cultural.heritage.constant.UserConstant.SALT; import static com.cultural.heritage.constant.UserConstant.USER_LOGIN_STATE; @@ -130,4 +135,12 @@ public class UserServiceImpl extends ServiceImpl implements Us return queryWrapper; } + @Override + public List getUserVO(List userList) { + if (CollectionUtils.isEmpty(userList)) { + return new ArrayList<>(); + } + return userList.stream().map(this::getUserVO).collect(Collectors.toList()); + } + }