项目模块初步完成

This commit is contained in:
2025-05-06 16:38:42 +08:00
parent 5038cebbfa
commit 2eb5ee1207
21 changed files with 1026 additions and 132 deletions

View File

@ -1,100 +1,82 @@
package ${parentPackage}.${controllerPackage};
import java.util.List;
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;
/**
* ${entityComment} 控制器
*/
@RestController
@RequestMapping("${entityName}")
@RequestMapping("${tableName}")
@Slf4j
@Tag(name = "${entityComment}管理")
public class ${entityName}Controller {
@Resource
private ${entityName}Service ${entityName}Service;
private ${entityName}Service ${entityNameLower}Service;
@Resource
private CommonService commonService;
/**
* web端管理员添加${entityComment}
* @param ${entityName}AddRequest ${entityComment}添加请求体
* @param ${entityNameLower}AddRequest ${entityComment}添加请求体
* @return 是否添加成功
*/
@PostMapping("add")
@Operation(summary = "web端管理员添加${entityComment}", description = "参数:${entityComment}添加请求体,权限:管理员boss, admin)方法名add${entityName}")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> add${entityName}(@RequestBody ${entityName}AddRequest ${entityName}AddRequest) {
if (${entityName}AddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
${entityName} ${entityName} = new ${entityName}();
BeanUtils.copyProperties(${entityName}AddRequest, ${entityName});
boolean result = ${entityName}Service.save(${entityName});
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "${entityComment}添加失败");
@Operation(summary = "web端管理员添加${entityComment}", description = "参数:${entityComment}添加请求体权限管理员方法名add${entityName}")
public BaseResponse<Boolean> add${entityName}(@Valid @RequestBody ${entityName}AddRequest ${entityNameLower}AddRequest) {
${entityName} ${entityNameLower} = commonService.copyProperties(${entityNameLower}AddRequest, ${entityName}.class);
${entityNameLower}Service.save(${entityNameLower});
return ResultUtils.success(true);
}
/**
* web端管理员更新${entityComment}
* @param ${entityName}UpdateRequest ${entityComment}更新请求体
* web端管理员根据id修改${entityComment}信息
* @param ${entityNameLower}UpdateRequest ${entityComment}更新请求体
* @return 是否更新成功
*/
@PostMapping("update")
@Operation(summary = "web端管理员更新${entityComment}", description = "参数:${entityComment}更新请求体,权限:管理员boss, admin)方法名update${entityName}")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> update${entityName}(@RequestBody ${entityName}UpdateRequest ${entityName}UpdateRequest) {
if (${entityName}UpdateRequest == null || ${entityName}UpdateRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
${entityName} ${entityName} = new ${entityName}();
BeanUtils.copyProperties(${entityName}UpdateRequest, ${entityName});
boolean result = ${entityName}Service.updateById(${entityName});
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "${entityComment}更新失败");
@Operation(summary = "web端管理员更新${entityComment}", description = "参数:${entityComment}更新请求体权限管理员方法名update${entityName}")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "${entityComment}管理", content = "web端管理员根据id修改${entityComment}信息")
public BaseResponse<Boolean> update${entityName}(@Valid @RequestBody ${entityName}UpdateRequest ${entityNameLower}UpdateRequest) {
${entityName} ${entityNameLower} = commonService.copyProperties(${entityNameLower}UpdateRequest, ${entityName}.class);
${entityNameLower}Service.updateById(${entityNameLower});
return ResultUtils.success(true);
}
/**
* web端管理员删除${entityComment}
* web端管理员根据id删除${entityComment}
* @param commonRequest ${entityComment}删除请求体
* @return 是否删除成功
*/
@PostMapping("delete")
@Operation(summary = "web端管理员删除${entityComment}", description = "参数:${entityComment}删除请求体,权限:管理员boss, admin)方法名del${entityName}")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> del${entityName}(@RequestBody CommonRequest commonRequest) {
if (commonRequest == null || commonRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
@Operation(summary = "web端管理员根据id删除${entityComment}", description = "参数:${entityComment}删除请求体权限管理员方法名del${entityName}")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "${entityComment}管理", content = "web端管理员根据id删除${entityComment}")
public BaseResponse<Boolean> del${entityName}(@Valid @RequestBody CommonRequest commonRequest) {
Long id = commonRequest.getId();
boolean result = ${entityName}Service.removeById(id);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "${entityComment}删除失败");
${entityNameLower}Service.removeById(id);
return ResultUtils.success(true);
}
/**
* Web端管理员分页查看${entityComment}
* @param ${entityName}QueryRequest ${entityComment}查询请求体
* @return ${entityComment}列表
* web端管理员批量删除${entityComment}
* @param commonBatchRequest ${entityComment}批量删除请求体
* @return 是否删除成功
*/
@PostMapping("page")
@Operation(summary = "Web端管理员分页查看${entityComment}", description = "参数:${entityComment}查询请求体,权限:管理员boss, admin),方法名:list${entityName}ByPage")
public BaseResponse<Page<${entityName}VO>> list${entityName}ByPage(@RequestBody ${entityName}QueryRequest ${entityName}QueryRequest) {
if (${entityName}QueryRequest == null) throw new BusinessException(ErrorCode.PARAMS_ERROR);
long current = ${entityName}QueryRequest.getCurrent();
long pageSize = ${entityName}QueryRequest.getPageSize();
QueryWrapper<${entityName}> queryWrapper = ${entityName}Service.getQueryWrapper(${entityName}QueryRequest);
Page<${entityName}> page = ${entityName}Service.page(new Page<>(current, pageSize), queryWrapper);
List<${entityName}> ${entityName}List = page.getRecords();
List<${entityName}VO> ${entityName}VOList = commonService.convertList(${entityName}List, ${entityName}VO.class);
Page<${entityName}VO> voPage = new Page<>();
voPage.setRecords(${entityName}VOList);
voPage.setPages(page.getPages());
voPage.setCurrent(page.getCurrent());
voPage.setTotal(page.getTotal());
voPage.setSize(page.getSize());
return ResultUtils.success(voPage);
@PostMapping("delBatch")
@Operation(summary = "web端管理员批量删除${entityComment}", description = "参数:${entityComment}批量删除请求体,权限:管理员方法名delBatch${entityName}")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "${entityComment}管理", content = "web端管理员批量删除${entityComment}")
public BaseResponse<Boolean> delBatch${entityName}(@Valid @RequestBody CommonBatchRequest commonBatchRequest) {
List<Long> ids = commonBatchRequest.getIds();
${entityNameLower}Service.removeByIds(ids);
return ResultUtils.success(true);
}
/**
@ -103,32 +85,37 @@ public class ${entityName}Controller {
* @return ${entityComment}信息
*/
@PostMapping("queryById")
@Operation(summary = "web端管理员根据id查询${entityComment}", description = "参数:${entityComment}查询请求体,权限:管理员boss, admin),方法名:query${entityName}ById")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<${entityName}VO> query${entityName}ById(@RequestBody CommonRequest commonRequest) {
if (commonRequest == null || commonRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
${entityName} ${entityName} = ${entityName}Service.getById(commonRequest.getId());
ThrowUtils.throwIf(${entityName} == null, ErrorCode.NOT_FOUND, "${entityComment}未找到");
${entityName}VO ${entityName}VO = commonService.convert(${entityName}, ${entityName}VO.class);
return ResultUtils.success(${entityName}VO);
@Operation(summary = "web端管理员根据id查询${entityComment}", description = "参数:${entityComment}查询请求体,权限:管理员,方法名query${entityName}ById")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "${entityComment}管理", content = "web端管理员根据id查询${entityComment}")
public BaseResponse<${entityName}VO> query${entityName}ById(@Valid @RequestBody CommonRequest commonRequest) {
Long id = commonRequest.getId();
${entityName} ${entityNameLower} = ${entityNameLower}Service.getById(id);
ThrowUtils.throwIf(${entityNameLower} == null, ErrorCode.OPERATION_ERROR, "当前${entityComment}不存在");
${entityName}VO ${entityNameLower}VO = commonService.copyProperties(${entityNameLower}, ${entityName}VO.class);
return ResultUtils.success(${entityNameLower}VO);
}
/**
* web端管理员批量删除${entityComment}
* @param commonRequest ${entityComment}批量删除请求体
* @return 是否删除成功
* Web端管理员分页查询${entityComment}
* @param ${entityNameLower}QueryRequest ${entityComment}查询请求体
* @return ${entityComment}列表
*/
@PostMapping("delBatch")
@Operation(summary = "web端管理员批量删除${entityComment}", description = "参数:${entityComment}批量删除请求体,权限:管理员boss, admin),方法名:delBatch${entityName}")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> delBatch${entityName}(@RequestBody CommonRequest commonRequest) {
if (commonRequest == null || commonRequest.getIds() == null || commonRequest.getIds().isEmpty()) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
boolean result = ${entityName}Service.removeByIds(commonRequest.getIds());
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "${entityComment}批量删除失败");
return ResultUtils.success(true);
@PostMapping("page")
@Operation(summary = "Web端管理员分页查询${entityComment}", description = "参数:${entityComment}查询请求体,权限:管理员方法名list${entityName}ByPage")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "${entityComment}管理", content = "Web端管理员分页查询${entityComment}")
public BaseResponse<Page<${entityName}VO>> list${entityName}ByPage(@Valid @RequestBody ${entityName}QueryRequest ${entityNameLower}QueryRequest) {
long current = ${entityNameLower}QueryRequest.getCurrent();
long pageSize = ${entityNameLower}QueryRequest.getPageSize();
QueryWrapper<${entityName}> queryWrapper = ${entityNameLower}Service.getQueryWrapper(${entityNameLower}QueryRequest);
Page<${entityName}> page = ${entityNameLower}Service.page(new Page<>(current, pageSize), queryWrapper);
List<${entityName}> ${entityNameLower}List = page.getRecords();
List<${entityName}VO> ${entityNameLower}VOList = commonService.convertList(${entityNameLower}List, ${entityName}VO.class);
Page<${entityName}VO> voPage = new Page<>(current, pageSize);
voPage.setRecords(${entityNameLower}VOList);
voPage.setPages(page.getPages());
voPage.setTotal(page.getTotal());
return ResultUtils.success(voPage);
}
}
}

View File

@ -1,6 +1,8 @@
package ${parentPackage}.${dtoPackage};
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Min;
import lombok.Data;
import java.io.Serial;
@ -10,7 +12,13 @@ import java.io.Serializable;
* ${entityComment}添加请求体
*/
@Data
@Schema(description = "${entityComment}添加请求体", requiredProperties = {"name", "categoryId", "price", "image", "period", "isShelves"})
@Schema(description = "${entityComment}添加请求体", requiredProperties = {
#foreach($field in ${table.fields})
#if(!$field.keyFlag && $field.propertyName != "id" && $field.propertyName != "createTime" && $field.propertyName != "updateTime" && $field.propertyName != "isDelete")
"${field.propertyName}",
#end
#end
})
public class ${entityName}AddRequest implements Serializable {
#foreach($field in ${table.fields})
@ -18,7 +26,13 @@ public class ${entityName}AddRequest implements Serializable {
/**
* ${field.comment}
*/
@Schema(description = "${field.comment}", example = "${field.example}")
#if($field.propertyType == "String")
@NotBlank(message = "${field.comment}不能为空")
#end
#if($field.propertyType == "Long")
@Min(value = 1L, message = "${field.comment} ID不能小于1")
#end
@Schema(description = "${field.comment}", example = "")
private ${field.propertyType} ${field.propertyName};
#end
@ -27,3 +41,4 @@ public class ${entityName}AddRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -1,10 +1,13 @@
package ${parentPackage}.${dtoPackage};
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Min;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import ${parentPackage}.common.PageRequest;
import com.greenorange.promotion.common.PageRequest;
/**
* ${entityComment}查询请求体,继承自分页请求 PageRequest
@ -17,6 +20,7 @@ public class ${entityName}QueryRequest extends PageRequest implements Serializab
* ${entityComment} ID
*/
@Schema(description = "${entityComment} ID", example = "1")
@Min(value = 1L, message = "${entityComment} ID不能小于1")
private Long id;
#foreach($field in ${table.fields})
@ -24,7 +28,10 @@ public class ${entityName}QueryRequest extends PageRequest implements Serializab
/**
* ${field.comment}
*/
@Schema(description = "${field.comment}", example = "${field.example}")
#if($field.propertyType == "String")
@NotBlank(message = "${field.comment}不能为空")
#end
@Schema(description = "${field.comment}", example = "")
private ${field.propertyType} ${field.propertyName};
#end
@ -33,3 +40,4 @@ public class ${entityName}QueryRequest extends PageRequest implements Serializab
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -1,6 +1,8 @@
package ${parentPackage}.${dtoPackage};
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Min;
import lombok.Data;
import java.io.Serial;
@ -10,21 +12,27 @@ import java.io.Serializable;
* ${entityComment}更新请求体
*/
@Data
@Schema(description = "${entityComment}更新请求体", requiredProperties = {"id", "name", "categoryId", "price", "image", "period", "isShelves"})
@Schema(description = "${entityComment}更新请求体", requiredProperties = {
#foreach($field in ${table.fields})
#if(!$field.keyFlag && $field.propertyName != "createTime" && $field.propertyName != "updateTime" && $field.propertyName != "isDelete")
"${field.propertyName}",
#end
#end
})
public class ${entityName}UpdateRequest implements Serializable {
/**
* ${entityComment} ID
*/
@Schema(description = "${entityComment} ID", example = "1")
private Long id;
#foreach($field in ${table.fields})
#if(!$field.keyFlag && $field.propertyName != "createTime" && $field.propertyName != "updateTime" && $field.propertyName != "isDelete")
/**
* ${field.comment}
*/
@Schema(description = "${field.comment}", example = "${field.example}")
#if($field.propertyType == "String")
@NotBlank(message = "${field.comment}不能为空")
#end
#if($field.propertyType == "Long")
@Min(value = 1L, message = "${field.comment} ID不能小于1")
#end
@Schema(description = "${field.comment}", example = "")
private ${field.propertyType} ${field.propertyName};
#end
@ -32,4 +40,4 @@ public class ${entityName}UpdateRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
}
}

View File

@ -5,6 +5,7 @@ import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* ${entityComment} 视图对象