qingcheng-houduan/src/main/resources/templates/controller.java.vm

123 lines
6.5 KiB
Plaintext
Raw Normal View History

2025-04-01 03:48:31 +00:00
package ${parentPackage}.${controllerPackage};
2025-05-06 08:38:42 +00:00
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;
2025-04-01 03:48:31 +00:00
/**
* ${entityComment} 控制器
*/
@RestController
2025-05-06 11:15:01 +00:00
@RequestMapping("${entityNameLower}")
2025-04-01 03:48:31 +00:00
@Slf4j
2025-05-12 13:05:52 +00:00
@Tag(name = "${entityComment}模块")
2025-04-01 03:48:31 +00:00
public class ${entityName}Controller {
@Resource
2025-05-06 08:38:42 +00:00
private ${entityName}Service ${entityNameLower}Service;
2025-04-01 03:48:31 +00:00
@Resource
private CommonService commonService;
/**
* web端管理员添加${entityComment}
2025-05-06 08:38:42 +00:00
* @param ${entityNameLower}AddRequest ${entityComment}添加请求体
2025-04-01 03:48:31 +00:00
* @return 是否添加成功
*/
@PostMapping("add")
2025-05-06 08:38:42 +00:00
@Operation(summary = "web端管理员添加${entityComment}", description = "参数:${entityComment}添加请求体权限管理员方法名add${entityName}")
2025-05-06 11:15:01 +00:00
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "${entityComment}管理", content = "web端管理员添加${entityComment}")
2025-05-06 08:38:42 +00:00
public BaseResponse<Boolean> add${entityName}(@Valid @RequestBody ${entityName}AddRequest ${entityNameLower}AddRequest) {
${entityName} ${entityNameLower} = commonService.copyProperties(${entityNameLower}AddRequest, ${entityName}.class);
${entityNameLower}Service.save(${entityNameLower});
2025-04-01 03:48:31 +00:00
return ResultUtils.success(true);
}
/**
2025-05-06 08:38:42 +00:00
* web端管理员根据id修改${entityComment}信息
* @param ${entityNameLower}UpdateRequest ${entityComment}更新请求体
2025-04-01 03:48:31 +00:00
* @return 是否更新成功
*/
@PostMapping("update")
2025-05-10 12:39:25 +00:00
@Operation(summary = "web端管理员根据id修改${entityComment}", description = "参数:${entityComment}更新请求体权限管理员方法名update${entityName}")
2025-05-06 08:38:42 +00:00
@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});
2025-04-01 03:48:31 +00:00
return ResultUtils.success(true);
}
/**
2025-05-06 08:38:42 +00:00
* web端管理员根据id删除${entityComment}
2025-04-01 03:48:31 +00:00
* @param commonRequest ${entityComment}删除请求体
* @return 是否删除成功
*/
@PostMapping("delete")
2025-05-06 08:38:42 +00:00
@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) {
2025-04-01 03:48:31 +00:00
Long id = commonRequest.getId();
2025-05-06 08:38:42 +00:00
${entityNameLower}Service.removeById(id);
2025-04-01 03:48:31 +00:00
return ResultUtils.success(true);
}
/**
2025-05-06 08:38:42 +00:00
* web端管理员批量删除${entityComment}
* @param commonBatchRequest ${entityComment}批量删除请求体
* @return 是否删除成功
2025-04-01 03:48:31 +00:00
*/
2025-05-06 08:38:42 +00:00
@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);
2025-04-01 03:48:31 +00:00
}
/**
* web端管理员根据id查询${entityComment}
* @param commonRequest ${entityComment}查询请求体
* @return ${entityComment}信息
*/
@PostMapping("queryById")
2025-05-06 08:38:42 +00:00
@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);
2025-04-01 03:48:31 +00:00
}
/**
2025-05-06 08:38:42 +00:00
* Web端管理员分页查询${entityComment}
* @param ${entityNameLower}QueryRequest ${entityComment}查询请求体
* @return ${entityComment}列表
2025-04-01 03:48:31 +00:00
*/
2025-05-06 08:38:42 +00:00
@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);
2025-04-01 03:48:31 +00:00
}
2025-05-06 08:38:42 +00:00
}