AppApiParameterEndPoint.java 5.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package com.yihu.ehr.basic.apps.controller;
  2. import com.yihu.ehr.basic.apps.model.AppApiParameter;
  3. import com.yihu.ehr.basic.apps.service.AppApiParameterService;
  4. import com.yihu.ehr.constants.ApiVersion;
  5. import com.yihu.ehr.constants.ErrorCode;
  6. import com.yihu.ehr.constants.ServiceApi;
  7. import com.yihu.ehr.controller.EnvelopRestEndPoint;
  8. import com.yihu.ehr.exception.ApiException;
  9. import com.yihu.ehr.model.app.MAppApiParameter;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import io.swagger.annotations.ApiParam;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.http.MediaType;
  15. import org.springframework.web.bind.annotation.*;
  16. import javax.servlet.http.HttpServletRequest;
  17. import javax.servlet.http.HttpServletResponse;
  18. import java.util.ArrayList;
  19. import java.util.Collection;
  20. import java.util.List;
  21. /**
  22. * @author linz
  23. * @version 1.0
  24. * @created 2016年7月7日21:04:13
  25. */
  26. @RestController
  27. @RequestMapping(ApiVersion.Version1_0)
  28. @Api(value = "AppApiParameter", description = "API应用请求参数", tags = {"平台应用-API应用请求参数"})
  29. public class AppApiParameterEndPoint extends EnvelopRestEndPoint {
  30. @Autowired
  31. private AppApiParameterService appApiParameterService;
  32. @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameters, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  33. @ApiOperation(value = "创建AppApiParameter")
  34. public MAppApiParameter createAppApiParameter(
  35. @ApiParam(name = "AppApiParameter", value = "对象JSON结构体", allowMultiple = true)
  36. @RequestBody String appApiParameterJson) throws Exception {
  37. AppApiParameter appApiParameter = toEntity(appApiParameterJson, AppApiParameter.class);
  38. appApiParameter = appApiParameterService.createAppApiParameter(appApiParameter);
  39. return convertToModel(appApiParameter, MAppApiParameter.class);
  40. }
  41. @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameters, method = RequestMethod.GET)
  42. @ApiOperation(value = "获取AppApiParameter列表")
  43. public Collection<MAppApiParameter> getAppApiParameters(
  44. @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
  45. @RequestParam(value = "fields", required = false) String fields,
  46. @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
  47. @RequestParam(value = "filters", required = false) String filters,
  48. @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "")
  49. @RequestParam(value = "sorts", required = false) String sorts,
  50. @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
  51. @RequestParam(value = "size", required = false) int size,
  52. @ApiParam(name = "page", value = "页码", defaultValue = "1")
  53. @RequestParam(value = "page", required = false) int page,
  54. HttpServletRequest request,
  55. HttpServletResponse response) throws Exception {
  56. List<AppApiParameter> appApiParameterList = appApiParameterService.search(fields, filters, sorts, page, size);
  57. pagedResponse(request, response, appApiParameterService.getCount(filters), page, size);
  58. return convertToModels(appApiParameterList, new ArrayList<>(appApiParameterList.size()), MAppApiParameter.class, fields);
  59. }
  60. @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameters, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  61. @ApiOperation(value = "更新AppApiParameter")
  62. public MAppApiParameter updateAppApiParameter(
  63. @ApiParam(name = "AppApiParameter", value = "对象JSON结构体", allowMultiple = true)
  64. @RequestBody String appJson) throws Exception {
  65. AppApiParameter appApiParameter = toEntity(appJson, AppApiParameter.class);
  66. if (appApiParameterService.retrieve(appApiParameter.getId()) == null) {
  67. throw new ApiException(ErrorCode.NOT_FOUND, "应用不存在");
  68. }
  69. appApiParameterService.save(appApiParameter);
  70. return convertToModel(appApiParameter, MAppApiParameter.class);
  71. }
  72. @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameter, method = RequestMethod.GET)
  73. @ApiOperation(value = "获取AppApiParameter")
  74. public MAppApiParameter getAppApiParameter(
  75. @ApiParam(name = "id", value = "id")
  76. @PathVariable(value = "id") int id) throws Exception {
  77. AppApiParameter appApiParameter = appApiParameterService.retrieve(id);
  78. return convertToModel(appApiParameter, MAppApiParameter.class);
  79. }
  80. @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameter, method = RequestMethod.DELETE)
  81. @ApiOperation(value = "删除AppApiParameter")
  82. public boolean deleteAppApiParameter(
  83. @ApiParam(name = "id", value = "id")
  84. @PathVariable(value = "id") int id) throws Exception {
  85. appApiParameterService.delete(id);
  86. return true;
  87. }
  88. }