first commit
This commit is contained in:
134
src/main/resources/templates/controller.java.vm
Normal file
134
src/main/resources/templates/controller.java.vm
Normal file
@ -0,0 +1,134 @@
|
||||
package ${parentPackage}.${controllerPackage};
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${entityComment} 控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("${entityName}")
|
||||
@Slf4j
|
||||
@Tag(name = "${entityComment}管理")
|
||||
public class ${entityName}Controller {
|
||||
|
||||
@Resource
|
||||
private ${entityName}Service ${entityName}Service;
|
||||
|
||||
@Resource
|
||||
private CommonService commonService;
|
||||
|
||||
/**
|
||||
* web端管理员添加${entityComment}
|
||||
* @param ${entityName}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}添加失败");
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* web端管理员更新${entityComment}
|
||||
* @param ${entityName}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}更新失败");
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* web端管理员删除${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);
|
||||
}
|
||||
Long id = commonRequest.getId();
|
||||
boolean result = ${entityName}Service.removeById(id);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "${entityComment}删除失败");
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Web端管理员分页查看${entityComment}
|
||||
* @param ${entityName}QueryRequest ${entityComment}查询请求体
|
||||
* @return ${entityComment}列表
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
||||
/**
|
||||
* web端管理员根据id查询${entityComment}
|
||||
* @param commonRequest ${entityComment}查询请求体
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* web端管理员批量删除${entityComment}
|
||||
* @param commonRequest ${entityComment}批量删除请求体
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
}
|
29
src/main/resources/templates/dto/Addrequest.java.vm
Normal file
29
src/main/resources/templates/dto/Addrequest.java.vm
Normal file
@ -0,0 +1,29 @@
|
||||
package ${parentPackage}.${dtoPackage};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* ${entityComment}添加请求体
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "${entityComment}添加请求体", requiredProperties = {"name", "categoryId", "price", "image", "period", "isShelves"})
|
||||
public class ${entityName}AddRequest implements Serializable {
|
||||
|
||||
#foreach($field in ${table.fields})
|
||||
#if(!$field.keyFlag && $field.propertyName != "id" && $field.propertyName != "createTime" && $field.propertyName != "updateTime" && $field.propertyName != "isDelete")
|
||||
/**
|
||||
* ${field.comment}
|
||||
*/
|
||||
@Schema(description = "${field.comment}", example = "${field.example}")
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
|
||||
#end
|
||||
#end
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
35
src/main/resources/templates/dto/QueryRequest.java.vm
Normal file
35
src/main/resources/templates/dto/QueryRequest.java.vm
Normal file
@ -0,0 +1,35 @@
|
||||
package ${parentPackage}.${dtoPackage};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import ${parentPackage}.common.PageRequest;
|
||||
|
||||
/**
|
||||
* ${entityComment}查询请求体,继承自分页请求 PageRequest
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "${entityComment}查询请求体", requiredProperties = {"current", "pageSize"})
|
||||
public class ${entityName}QueryRequest extends PageRequest 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}")
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
|
||||
#end
|
||||
#end
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
35
src/main/resources/templates/dto/UpdateRequest.java.vm
Normal file
35
src/main/resources/templates/dto/UpdateRequest.java.vm
Normal file
@ -0,0 +1,35 @@
|
||||
package ${parentPackage}.${dtoPackage};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* ${entityComment}更新请求体
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "${entityComment}更新请求体", requiredProperties = {"id", "name", "categoryId", "price", "image", "period", "isShelves"})
|
||||
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}")
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
|
||||
#end
|
||||
#end
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
35
src/main/resources/templates/vo/VO.java.vm
Normal file
35
src/main/resources/templates/vo/VO.java.vm
Normal file
@ -0,0 +1,35 @@
|
||||
package ${parentPackage}.${voPackage};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* ${entityComment} 视图对象
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "${entityComment} 视图对象")
|
||||
public class ${entityName}VO 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}")
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
|
||||
#end
|
||||
#end
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
Reference in New Issue
Block a user