cm-cloud/cloud-common-plugin-dynamic/target/classes/templates/codetemplate/default/controller/resources/ResourceController.ftl

120 lines
6.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ${basePackage}.controller.app.apis.${lowerTableName};
import com.cm.common.annotation.CheckRequestBodyAnnotation;
import com.cm.common.base.AbstractController;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.exception.RemoveException;
import com.cm.common.exception.SearchException;
import com.cm.common.pojo.ListPage;
import com.cm.common.result.ErrorResult;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultData;
import com.cm.common.result.SuccessResultList;
import ${basePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO;
import ${basePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}VO;
import ${basePackage}.service.${lowerTableName}.I${firstUpperTableName}Service;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @ClassName: ${firstUpperTableName}ResourceController
* @Description: ${tableExplain}
* @Author: ${author}
* @Date: ${date}
* @Version: ${version}
**/
@Api(tags = ISystemConstant.API_TAGS_RESOURCE_PREFIX + "${tableExplain}接口")
@RestController
@RequestMapping(ISystemConstant.RESOURCE_PREFIX + "/${lowerTableName}")
public class ${firstUpperTableName}ResourceController extends AbstractController {
@Autowired
private I${firstUpperTableName}Service ${firstLowerTableName}Service;
@ApiOperation(value = "新增${tableExplain}", notes = "新增${tableExplain}接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("save${lowerTableName}")
@CheckRequestBodyAnnotation
public SuccessResult save${firstUpperTableName}(@RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception {
return ${firstLowerTableName}Service.save${firstUpperTableName}(${firstLowerTableName}VO);
}
@ApiOperation(value = "删除${tableExplain}(id列表)", notes = "删除${tableExplain}(id列表)接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query"),
@ApiImplicitParam(name = "ids", value = "ID列表用下划线分隔", paramType = "path", example = "1_2_3")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@DeleteMapping("remove${lowerTableName}/{ids}")
public SuccessResult remove${firstUpperTableName}(@PathVariable("ids") String ids) throws RemoveException {
return ${firstLowerTableName}Service.remove${firstUpperTableName}(ids);
}
@ApiOperation(value = "修改${tableExplain}", notes = "修改${tableExplain}接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query"),
@ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PutMapping("update${lowerTableName}/{${firstLowerTableName}Id}")
@CheckRequestBodyAnnotation
public SuccessResult update${firstUpperTableName}(@PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id, @RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception {
return ${firstLowerTableName}Service.update${firstUpperTableName}(${firstLowerTableName}Id, ${firstLowerTableName}VO);
}
@ApiOperation(value = "${tableExplain}详情(通过ID)", notes = "${tableExplain}详情(通过ID)接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query"),
@ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("get${lowerTableName}byid/{${firstLowerTableName}Id}")
public ${firstUpperTableName}DTO get${firstUpperTableName}ById(@PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id) throws SearchException {
return ${firstLowerTableName}Service.get${firstUpperTableName}ById(${firstLowerTableName}Id);
}
@ApiOperation(value = "${tableExplain}列表", notes = "${tableExplain}列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("list${lowerTableName}")
public List<${firstUpperTableName}DTO> list${firstUpperTableName}() throws SearchException {
Map<String, Object> params = requestParams();
return ${firstLowerTableName}Service.list${firstUpperTableName}(params);
}
@ApiOperation(value = "${tableExplain}分页列表", notes = "${tableExplain}分页列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query"),
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listpage${lowerTableName}")
public SuccessResultList<List<${firstUpperTableName}DTO>> listPage${firstUpperTableName}(ListPage page) throws SearchException {
Map<String, Object> params = requestParams();
page.setParams(params);
return ${firstLowerTableName}Service.listPage${firstUpperTableName}(page);
}
@ApiOperation(value = "${tableExplain}统计", notes = "${tableExplain}统计接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("count${lowerTableName}")
SuccessResultData<Integer> count${firstUpperTableName}() throws SearchException {
Map<String, Object> params = requestParams();
return ${firstLowerTableName}Service.count${firstUpperTableName}(params);
}
}