用户模块

This commit is contained in:
2025-05-07 04:14:36 +08:00
parent 6e0576df5b
commit 9fb9d51ed1
10 changed files with 510 additions and 0 deletions

View File

@ -0,0 +1,148 @@
package com.greenorange.promotion.controller.promoCode;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.greenorange.promotion.annotation.RequiresPermission;
import com.greenorange.promotion.annotation.SysLog;
import com.greenorange.promotion.common.BaseResponse;
import com.greenorange.promotion.common.ErrorCode;
import com.greenorange.promotion.common.ResultUtils;
import com.greenorange.promotion.constant.UserConstant;
import com.greenorange.promotion.exception.ThrowUtils;
import com.greenorange.promotion.model.dto.CommonBatchRequest;
import com.greenorange.promotion.model.dto.promoCode.PromoCodeAddRequest;
import com.greenorange.promotion.model.dto.promoCode.PromoCodeQueryRequest;
import com.greenorange.promotion.model.dto.promoCode.PromoCodeUpdateRequest;
import com.greenorange.promotion.model.entity.PromoCode;
import com.greenorange.promotion.model.vo.promoCode.PromoCodeVO;
import com.greenorange.promotion.service.common.CommonService;
import com.greenorange.promotion.service.project.PromoCodeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.greenorange.promotion.model.dto.CommonRequest;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 推广码 控制器
*/
@RestController
@RequestMapping("promoCode")
@Slf4j
@Tag(name = "推广码管理")
public class PromoCodeController {
@Resource
private PromoCodeService promoCodeService;
@Resource
private CommonService commonService;
/**
* web端管理员添加推广码
* @param promoCodeAddRequest 推广码添加请求体
* @return 是否添加成功
*/
@PostMapping("add")
@Operation(summary = "web端管理员添加推广码", description = "参数推广码添加请求体权限管理员方法名addPromoCode")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "推广码管理", content = "web端管理员添加推广码")
public BaseResponse<Boolean> addPromoCode(@Valid @RequestBody PromoCodeAddRequest promoCodeAddRequest) {
PromoCode promoCode = commonService.copyProperties(promoCodeAddRequest, PromoCode.class);
promoCodeService.save(promoCode);
return ResultUtils.success(true);
}
/**
* web端管理员根据id修改推广码信息
* @param promoCodeUpdateRequest 推广码更新请求体
* @return 是否更新成功
*/
@PostMapping("update")
@Operation(summary = "web端管理员更新推广码", description = "参数推广码更新请求体权限管理员方法名updatePromoCode")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "推广码管理", content = "web端管理员根据id修改推广码信息")
public BaseResponse<Boolean> updatePromoCode(@Valid @RequestBody PromoCodeUpdateRequest promoCodeUpdateRequest) {
PromoCode promoCode = commonService.copyProperties(promoCodeUpdateRequest, PromoCode.class);
promoCodeService.updateById(promoCode);
return ResultUtils.success(true);
}
/**
* web端管理员根据id删除推广码
* @param commonRequest 推广码删除请求体
* @return 是否删除成功
*/
@PostMapping("delete")
@Operation(summary = "web端管理员根据id删除推广码", description = "参数推广码删除请求体权限管理员方法名delPromoCode")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "推广码管理", content = "web端管理员根据id删除推广码")
public BaseResponse<Boolean> delPromoCode(@Valid @RequestBody CommonRequest commonRequest) {
Long id = commonRequest.getId();
promoCodeService.removeById(id);
return ResultUtils.success(true);
}
/**
* web端管理员批量删除推广码
* @param commonBatchRequest 推广码批量删除请求体
* @return 是否删除成功
*/
@PostMapping("delBatch")
@Operation(summary = "web端管理员批量删除推广码", description = "参数推广码批量删除请求体权限管理员方法名delBatchPromoCode")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "推广码管理", content = "web端管理员批量删除推广码")
public BaseResponse<Boolean> delBatchPromoCode(@Valid @RequestBody CommonBatchRequest commonBatchRequest) {
List<Long> ids = commonBatchRequest.getIds();
promoCodeService.removeByIds(ids);
return ResultUtils.success(true);
}
/**
* web端管理员根据id查询推广码
* @param commonRequest 推广码查询请求体
* @return 推广码信息
*/
@PostMapping("queryById")
@Operation(summary = "web端管理员根据id查询推广码", description = "参数推广码查询请求体权限管理员方法名queryPromoCodeById")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "推广码管理", content = "web端管理员根据id查询推广码")
public BaseResponse<PromoCodeVO> queryPromoCodeById(@Valid @RequestBody CommonRequest commonRequest) {
Long id = commonRequest.getId();
PromoCode promoCode = promoCodeService.getById(id);
ThrowUtils.throwIf(promoCode == null, ErrorCode.OPERATION_ERROR, "当前推广码不存在");
PromoCodeVO promoCodeVO = commonService.copyProperties(promoCode, PromoCodeVO.class);
return ResultUtils.success(promoCodeVO);
}
// /**
// * Web端管理员分页查询推广码
// * @param promoCodeQueryRequest 推广码查询请求体
// * @return 推广码列表
// */
// @PostMapping("page")
// @Operation(summary = "Web端管理员分页查询推广码", description = "参数推广码查询请求体权限管理员方法名listPromoCodeByPage")
// @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
// @SysLog(title = "推广码管理", content = "Web端管理员分页查询推广码")
// public BaseResponse<Page<PromoCodeVO>> listPromoCodeByPage(@Valid @RequestBody PromoCodeQueryRequest promoCodeQueryRequest) {
// long current = promoCodeQueryRequest.getCurrent();
// long pageSize = promoCodeQueryRequest.getPageSize();
// QueryWrapper<PromoCode> queryWrapper = promoCodeService.getQueryWrapper(promoCodeQueryRequest);
// Page<PromoCode> page = promoCodeService.page(new Page<>(current, pageSize), queryWrapper);
// List<PromoCode> promoCodeList = page.getRecords();
// List<PromoCodeVO> promoCodeVOList = commonService.convertList(promoCodeList, PromoCodeVO.class);
// Page<PromoCodeVO> voPage = new Page<>(current, pageSize);
// voPage.setRecords(promoCodeVOList);
// voPage.setPages(page.getPages());
// voPage.setTotal(page.getTotal());
// return ResultUtils.success(voPage);
// }
}