AppApiErrorCodeEndPoint.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package com.yihu.ehr.basic.apps.controller;
  2. import com.yihu.ehr.basic.apps.service.AppApiErrorCodeService;
  3. import com.yihu.ehr.constants.ApiVersion;
  4. import com.yihu.ehr.constants.ErrorCode;
  5. import com.yihu.ehr.constants.ServiceApi;
  6. import com.yihu.ehr.controller.EnvelopRestEndPoint;
  7. import com.yihu.ehr.entity.api.AppApiErrorCode;
  8. import com.yihu.ehr.util.rest.Envelop;
  9. import io.swagger.annotations.Api;
  10. import io.swagger.annotations.ApiOperation;
  11. import io.swagger.annotations.ApiParam;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import org.springframework.web.bind.annotation.RequestParam;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import java.util.ArrayList;
  18. import java.util.Arrays;
  19. import java.util.List;
  20. /**
  21. * EndPoint - Api错误码
  22. * Created by progr1mmer on 2018/3/14.
  23. */
  24. @RestController
  25. @RequestMapping(ApiVersion.Version1_0)
  26. @Api(value = "AppApiCategory", description = "接口错误码管理", tags = {"平台应用-接口错误码管理"})
  27. public class AppApiErrorCodeEndPoint extends EnvelopRestEndPoint {
  28. @Autowired
  29. private AppApiErrorCodeService appApiErrorCodeService;
  30. @RequestMapping(value = ServiceApi.AppApiErrorCode.Base, method = RequestMethod.POST)
  31. @ApiOperation("保存记录")
  32. public Envelop save(
  33. @ApiParam(name = "appApiErrorCode", value = "Json串", required = true)
  34. @RequestParam(value = "appApiErrorCode") String appApiErrorCode) throws Exception {
  35. AppApiErrorCode appApiErrorCode1 = toEntity(appApiErrorCode, AppApiErrorCode.class);
  36. AppApiErrorCode appApiErrorCode2 = appApiErrorCodeService.save(appApiErrorCode1);
  37. return success(appApiErrorCode2);
  38. }
  39. @RequestMapping(value = ServiceApi.AppApiErrorCode.Base, method = RequestMethod.DELETE)
  40. @ApiOperation("删除记录")
  41. public Envelop delete(
  42. @ApiParam(name = "ids", value = "id列表xxxx,xxxx,xxxx,...", required = true)
  43. @RequestParam(value = "ids") String ids){
  44. String [] idArr = ids.split(",");
  45. List<String> strIdList = Arrays.asList(idArr);
  46. List<Integer> intIdList = new ArrayList<>(idArr.length);
  47. strIdList.forEach(item -> intIdList.add(new Integer(item)));
  48. appApiErrorCodeService.delete(intIdList);
  49. return success(true);
  50. }
  51. @RequestMapping(value = ServiceApi.AppApiErrorCode.Base, method = RequestMethod.PUT)
  52. @ApiOperation("更新记录")
  53. public Envelop update(
  54. @ApiParam(name = "appApiErrorCode", value = "Json串", required = true)
  55. @RequestParam(value = "appApiErrorCode") String appApiErrorCode) throws Exception {
  56. AppApiErrorCode appApiErrorCode1 = toEntity(appApiErrorCode, AppApiErrorCode.class);
  57. if (appApiErrorCode1.getId() == null || appApiErrorCodeService.findByField("id", appApiErrorCode1.getId()).size() <= 0) {
  58. return failed("操作对象不存在", ErrorCode.OBJECT_NOT_FOUND.value());
  59. }
  60. AppApiErrorCode appApiErrorCode2 = appApiErrorCodeService.save(appApiErrorCode1);
  61. return success(appApiErrorCode2);
  62. }
  63. @RequestMapping(value = ServiceApi.AppApiErrorCode.Base, method = RequestMethod.GET)
  64. @ApiOperation(value = "获取分页")
  65. public Envelop list(
  66. @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
  67. @RequestParam(value = "fields", required = false) String fields,
  68. @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
  69. @RequestParam(value = "filters", required = false) String filters,
  70. @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
  71. @RequestParam(value = "sorts", required = false) String sorts,
  72. @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
  73. @RequestParam(value = "page") int page,
  74. @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
  75. @RequestParam(value = "size") int size) throws Exception {
  76. List<AppApiErrorCode> appApiCategoryList = appApiErrorCodeService.search(fields, filters, sorts, page, size);
  77. int count = (int)appApiErrorCodeService.getCount(filters);
  78. Envelop envelop = getPageResult(appApiCategoryList, count, page, size);
  79. return envelop;
  80. }
  81. @RequestMapping(value = ServiceApi.AppApiErrorCode.CheckCode, method = RequestMethod.GET)
  82. @ApiOperation(value = "更新时检查Code是否重复")
  83. public Boolean check(
  84. @ApiParam(name = "apiId", value = "apiId")
  85. @RequestParam(value = "apiId", required = false) Integer apiId,
  86. @ApiParam(name = "newCode", value = "检查值")
  87. @RequestParam(value = "newCode", required = false) Integer newCode) throws Exception {
  88. List<AppApiErrorCode> appApiErrorCodeList = appApiErrorCodeService.findByField("apiId", apiId);
  89. for (AppApiErrorCode appApiErrorCode : appApiErrorCodeList) {
  90. if (appApiErrorCode.getCode() == newCode) {
  91. return true;
  92. }
  93. }
  94. return false;
  95. }
  96. }