FunctionController.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package com.yihu.jw.controller.base;
  2. import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
  3. import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
  4. import com.yihu.jw.commnon.base.base.BaseContants;
  5. import com.yihu.jw.exception.business.JiWeiException;
  6. import com.yihu.jw.feign.base.base.FunctionFeign;
  7. import com.yihu.jw.restmodel.common.Envelop;
  8. import com.yihu.jw.restmodel.common.EnvelopRestController;
  9. import io.swagger.annotations.Api;
  10. import io.swagger.annotations.ApiOperation;
  11. import io.swagger.annotations.ApiParam;
  12. import org.apache.commons.lang.StringUtils;
  13. import org.json.JSONObject;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.cloud.sleuth.Tracer;
  16. import org.springframework.http.MediaType;
  17. import org.springframework.web.bind.annotation.*;
  18. import javax.servlet.http.HttpServletRequest;
  19. import javax.servlet.http.HttpServletResponse;
  20. /**
  21. * Created by chenweida on 2017/6/16.
  22. */
  23. @RestController
  24. @RequestMapping("{version}/"+ BaseContants.api_common)
  25. @Api(value = "功能管理", description = "功能管理")
  26. public class FunctionController extends EnvelopRestController {
  27. @Autowired
  28. private FunctionFeign fegin;
  29. @Autowired
  30. private Tracer tracer;
  31. @HystrixCommand(commandProperties = {
  32. @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
  33. @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
  34. @PostMapping(value = BaseContants.Function.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  35. @ApiOperation(value = "创建功能", notes = "创建功能")
  36. public Envelop createFunction(
  37. @ApiParam(name = "json_data", value = "", defaultValue = "")
  38. @RequestBody String jsonData) throws JiWeiException {
  39. return fegin.create(jsonData);
  40. }
  41. @HystrixCommand(commandProperties = {
  42. @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
  43. @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
  44. @PutMapping(value = BaseContants.Function.api_update, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  45. @ApiOperation(value = "更新功能", notes = "更新功能")
  46. public Envelop updateFunction(
  47. @ApiParam(name = "json_data", value = "", defaultValue = "")
  48. @RequestBody String jsonData) throws JiWeiException {
  49. return fegin.update(jsonData);
  50. }
  51. @HystrixCommand(commandProperties = {
  52. @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
  53. @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
  54. @DeleteMapping(value = BaseContants.Function.api_delete)
  55. @ApiOperation(value = "删除功能", notes = "删除功能")
  56. public Envelop deleteFunction(
  57. @ApiParam(name = "codes", value = "codes")
  58. @PathVariable(value = "codes", required = true) String codes,
  59. @ApiParam(name = "userCode", value = "userCode")
  60. @RequestParam(value = "userCode", required = true) String userCode,
  61. @ApiParam(name = "userName", value = "userName")
  62. @RequestParam(value = "userName", required = true) String userName) throws JiWeiException {
  63. return fegin.delete(codes,userCode,userName);
  64. }
  65. @HystrixCommand(commandProperties = {
  66. @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
  67. @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
  68. @GetMapping(value = BaseContants.Function.api_getByCode)
  69. @ApiOperation(value = "根据code查找", notes = "根据code查找")
  70. public Envelop findByCode(
  71. @ApiParam(name = "code", value = "code")
  72. @PathVariable(value = "code", required = true) String code
  73. ) throws JiWeiException {
  74. return fegin.findByCode(code);
  75. }
  76. @HystrixCommand(commandProperties = {
  77. @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
  78. @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
  79. @GetMapping(value = BaseContants.Function.api_getChildren)
  80. @ApiOperation(value = "根据code查找子节点", notes = "根据code查找子节点")
  81. public Envelop getChildren(
  82. @ApiParam(name = "code", value = "code")
  83. @PathVariable(value = "code", required = true) String code
  84. ) throws JiWeiException {
  85. return fegin.getChildren(code);
  86. }
  87. @HystrixCommand(commandProperties = {
  88. @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
  89. @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
  90. @RequestMapping(value = BaseContants.Function.api_getList, method = RequestMethod.GET)
  91. @ApiOperation(value = "获取功能列表(分页)")
  92. public Envelop getFunctions(
  93. @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "code,name,saasId,parentCode,remark")
  94. @RequestParam(value = "fields", required = false) String fields,
  95. @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
  96. //code like 1,name大于aa ,code 等于1 , defaultValue = "code?1;name>aa;code=1"
  97. @RequestParam(value = "filters", required = false) String filters,
  98. @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
  99. @RequestParam(value = "sorts", required = false) String sorts,
  100. @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
  101. @RequestParam(value = "size", required = false) int size,
  102. @ApiParam(name = "page", value = "页码", defaultValue = "1")
  103. @RequestParam(value = "page", required = false) int page,
  104. HttpServletRequest request,
  105. HttpServletResponse response) throws Exception {
  106. String filterStr = "";
  107. if(StringUtils.isNotBlank(filters)){
  108. JSONObject jsonResult = new JSONObject(filters);
  109. if(jsonResult.has("name")){
  110. filterStr+="name?"+jsonResult.get("name")+";";
  111. }
  112. }
  113. return fegin.getList(fields, filterStr, sorts, size, page);
  114. }
  115. @HystrixCommand(commandProperties = {
  116. @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
  117. @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
  118. @GetMapping(value = BaseContants.Function.api_getListNoPage)
  119. @ApiOperation(value = "获取功能列表,不分页")
  120. public Envelop getListNoPage(
  121. @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "code,name,saasId,parentCode,remark")
  122. @RequestParam(value = "fields", required = false) String fields,
  123. @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
  124. @RequestParam(value = "filters", required = false) String filters,
  125. @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
  126. @RequestParam(value = "sorts", required = false) String sorts) throws Exception {
  127. String filterStr = "";
  128. if(StringUtils.isNotBlank(filters)){
  129. JSONObject jsonResult = new JSONObject(filters);
  130. if(jsonResult.has("saasId")){
  131. filterStr+="saasId="+jsonResult.get("saasId")+";";
  132. }
  133. if(jsonResult.has("parentCode")){
  134. filterStr+="parentCode="+jsonResult.get("parentCode")+";";
  135. }
  136. }
  137. return fegin.getListNoPage(fields, filterStr, sorts);
  138. }
  139. }