完成了后台用户管理

This commit is contained in:
chen-xin-zhi 2024-10-28 19:32:47 +08:00
parent 439da50095
commit 7e1b0b0b04
8 changed files with 185 additions and 29 deletions

View File

@ -1,6 +1,7 @@
package com.cultural.heritage.controller.operategood; package com.cultural.heritage.controller.operategood;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cultural.heritage.annotation.AuthCheck; import com.cultural.heritage.annotation.AuthCheck;
import com.cultural.heritage.common.BaseResponse; import com.cultural.heritage.common.BaseResponse;
import com.cultural.heritage.common.ErrorCode; 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.constant.UserConstant;
import com.cultural.heritage.controller.userinfo.UserController; import com.cultural.heritage.controller.userinfo.UserController;
import com.cultural.heritage.exception.BusinessException; 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.GoodAddRequest;
import com.cultural.heritage.model.dto.good.GoodUpdateRequest;
import com.cultural.heritage.model.entity.Good; import com.cultural.heritage.model.entity.Good;
import com.cultural.heritage.service.operategood.GoodService; import com.cultural.heritage.service.operategood.GoodService;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@ -50,7 +54,6 @@ public class GoodController {
} }
Good good = new Good(); Good good = new Good();
BeanUtils.copyProperties(goodAddRequest, good); BeanUtils.copyProperties(goodAddRequest, good);
good.setIsGoodType(1);
boolean save = goodService.save(good); boolean save = goodService.save(good);
if (!save) { if (!save) {
throw new BusinessException(ErrorCode.SYSTEM_ERROR); 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<Boolean> 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<Boolean> 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<Page<Good>> listGoodByPage(@RequestBody )
} }

View File

@ -1,15 +1,11 @@
package com.cultural.heritage.controller.userinfo; package com.cultural.heritage.controller.userinfo;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.BaseResponse;
import com.cultural.heritage.common.ErrorCode; import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.common.ResultUtils; 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.BusinessException;
import com.cultural.heritage.exception.ThrowUtils; import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.model.dto.CommonRequest; 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.entity.User;
import com.cultural.heritage.model.vo.UserVO; import com.cultural.heritage.model.vo.UserVO;
import com.cultural.heritage.service.userinfo.UserService; import com.cultural.heritage.service.userinfo.UserService;
import com.wf.captcha.SpecCaptcha;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.webresources.ExtractingRoot;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.xml.transform.Result;
import java.util.HashMap;
import java.util.List; 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.SALT;
import static com.cultural.heritage.constant.UserConstant.USER_LOGIN_STATE;
/** /**
* 用户接口 * 用户接口
@ -234,25 +222,55 @@ public class UserController {
/** /**
* 图形验证码 * 分页获取用户封装列表
* @return *
* @param userQueryRequest 查询用户请求体
* @return 脱敏用户信息列表
*/ */
@GetMapping("/captcha") @PostMapping("/list/page/vo")
public BaseResponse<Map> getCapthca(){ // @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
//设置生成的长宽还有数字位数 public BaseResponse<Page<UserVO>> listUserVOByPage(@RequestBody UserQueryRequest userQueryRequest) {
SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 4); if (userQueryRequest == null) {
String code = specCaptcha.text().toLowerCase(); throw new BusinessException(ErrorCode.PARAMS_ERROR);
String uuid = IdUtil.simpleUUID(); }
redisTemplate.opsForValue().set(uuid,code,120, TimeUnit.SECONDS); long current = userQueryRequest.getCurrent();
HashMap<String, String> map = new HashMap<>(3); long pageSize = userQueryRequest.getPageSize();
map.put("uuid",uuid); // ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
map.put("code",code); QueryWrapper<User> queryWrapper = userService.getQueryWrapper(userQueryRequest);
map.put("captcha",specCaptcha.toBase64()); Page<User> userPage = userService.page(new Page<>(current, pageSize), queryWrapper);
return ResultUtils.success(map,"成功");
Page<UserVO> userVOPage = new Page<>(current, pageSize, userPage.getTotal());
List<UserVO> userVO = userService.getUserVO(userPage.getRecords());
userVOPage.setRecords(userVO);
return ResultUtils.success(userVOPage);
} }
// /**
// * 图形验证码
// * @return
// */
// @GetMapping("/captcha")
// public BaseResponse<Map> 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<String, String> map = new HashMap<>(3);
// map.put("uuid",uuid);
// map.put("code",code);
// map.put("captcha",specCaptcha.toBase64());
// return ResultUtils.success(map,"成功");
// }
} }

View File

@ -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 {
}

View File

@ -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;
}

View File

@ -36,5 +36,5 @@ public class UserQueryRequest extends PageRequest implements Serializable {
private String userRole; private String userRole;
@Serial @Serial
private static final long serialVersionUID = -8778649230187591764L; private static final long serialVersionUID = 1L;
} }

View File

@ -40,6 +40,6 @@ public class UserUpdateRequest implements Serializable {
private String userRole; private String userRole;
@Serial @Serial
private static final long serialVersionUID = -5057503930700700941L; private static final long serialVersionUID = 1L;
} }

View File

@ -7,6 +7,8 @@ import com.cultural.heritage.model.entity.User;
import com.cultural.heritage.model.vo.UserVO; import com.cultural.heritage.model.vo.UserVO;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import java.util.List;
public interface UserService extends IService<User> { public interface UserService extends IService<User> {
/** /**
@ -37,4 +39,10 @@ public interface UserService extends IService<User> {
* 获取查询条件 * 获取查询条件
*/ */
QueryWrapper<User> getQueryWrapper(UserQueryRequest userQueryRequest); QueryWrapper<User> getQueryWrapper(UserQueryRequest userQueryRequest);
/**
* 获取脱敏的用户信息
*/
List<UserVO> getUserVO(List<User> userList);
} }

View File

@ -18,8 +18,13 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.DigestUtils; 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.SALT;
import static com.cultural.heritage.constant.UserConstant.USER_LOGIN_STATE; import static com.cultural.heritage.constant.UserConstant.USER_LOGIN_STATE;
@ -130,4 +135,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
return queryWrapper; return queryWrapper;
} }
@Override
public List<UserVO> getUserVO(List<User> userList) {
if (CollectionUtils.isEmpty(userList)) {
return new ArrayList<>();
}
return userList.stream().map(this::getUserVO).collect(Collectors.toList());
}
} }