controller.ftl 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package ${code.packageName}.controller;
  2. import com.inkasso.auth.interfaces.Permissions;
  3. import com.inkasso.auth.interfaces.PermissionAndCheck;
  4. import com.inkasso.adapter.page.PageResult;
  5. import ${code.packageName}.model.dto.${code.className}DTO;
  6. import ${code.packageName}.model.request.Add${code.className}Request;
  7. import ${code.packageName}.model.request.Edit${code.className}Request;
  8. import ${code.packageName}.model.request.Query${code.className}Request;
  9. import ${code.packageName}.service.${code.className}Service;
  10. import com.inkasso.adapter.exception.ServiceException;
  11. import com.inkasso.adapter.response.ResponseData;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.validation.annotation.Validated;
  14. import org.springframework.web.bind.annotation.PathVariable;
  15. import org.springframework.web.bind.annotation.RequestBody;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.PostMapping;
  19. import org.springframework.web.bind.annotation.PutMapping;
  20. import org.springframework.web.bind.annotation.DeleteMapping;
  21. import org.springframework.web.bind.annotation.GetMapping;
  22. import com.inkasso.adapter.exception.enums.ExceptionEnum;
  23. import java.util.List;
  24. /**
  25. * @author ${code.author}
  26. * @date ${.now?string('yyyy-MM-dd')}
  27. */
  28. @RestController
  29. @RequestMapping(path = "${code.className?lower_case}")
  30. @Permissions(name="${code.label}",code = "${code.className?lower_case}Manage")
  31. public class ${code.className}Controller {
  32. @Autowired
  33. private ${code.className}Service ${code.className?uncap_first}Service;
  34. @PostMapping(path = "${code.className?lower_case}")
  35. @PermissionAndCheck(name="添加${code.label}",code="${code.className}Controller:add")
  36. public ResponseData add(@Validated @RequestBody Add${code.className}Request add${code.className}Request) {
  37. ${code.className?uncap_first}Service.add${code.className}(add${code.className}Request);
  38. return ResponseData.success();
  39. }
  40. @PutMapping(path = "${code.className?lower_case}")
  41. @PermissionAndCheck(name="更新${code.label}",code="${code.className}Controller:update")
  42. public ResponseData edit(@Validated @RequestBody Edit${code.className}Request edit${code.className}Request) {
  43. ${code.className?uncap_first}Service.edit${code.className}(edit${code.className}Request);
  44. return ResponseData.success();
  45. }
  46. <#if code.parentName = "BaseBean">
  47. @GetMapping(path = "${code.className?lower_case}")
  48. @PermissionAndCheck(name = "分页查询列表", code="${code.className}Controller:pageList")
  49. public ResponseData pageQuery(@RequestBody Query${code.className}Request query${code.className}Request){
  50. ResponseData<PageResult<${code.className}DTO>> result = ${code.className?uncap_first}Service.pageQuery(query${code.className}Request);
  51. return ResponseData.success(result);
  52. }
  53. @GetMapping(path = "${code.className?lower_case}s")
  54. @PermissionAndCheck(name = "查询全部列表", code="${code.className}Controller:allList")
  55. public ResponseData queryList(@RequestBody Query${code.className}Request query${code.className}Request) {
  56. List result = ${code.className?uncap_first}Service.queryList(query${code.className}Request);
  57. return ResponseData.success(result);
  58. }
  59. </#if>
  60. @GetMapping(path = "${code.className?lower_case}/{id}")
  61. @PermissionAndCheck(name = "查询${code.label}详细信息", code="${code.className}Controller:detail")
  62. public ResponseData getById(@PathVariable("id") Long id){
  63. if(id==null){
  64. throw new ServiceException(400, ExceptionEnum.SYSTEM_DATE_ERROR);
  65. }
  66. ${code.className}DTO ${code.className?uncap_first}DTO = ${code.className?uncap_first}Service.get${code.className}DtoById(id);
  67. return ResponseData.success(${code.className?uncap_first}DTO);
  68. }
  69. @DeleteMapping(path = "${code.className?lower_case}/{id}")
  70. @PermissionAndCheck(name = "删除${code.label}", code="${code.className}Controller:delete")
  71. public ResponseData deleteById(@PathVariable("id") Long id){
  72. if(id==null){
  73. throw new ServiceException(400, ExceptionEnum.SYSTEM_DATE_ERROR);
  74. }
  75. ${code.className?uncap_first}Service.delete${code.className}(id);
  76. return ResponseData.success();
  77. }
  78. }