123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- package com.yihu.jw.controller.base;
- import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
- import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
- import com.yihu.jw.commnon.base.base.BaseContants;
- import com.yihu.jw.exception.business.JiWeiException;
- import com.yihu.jw.feign.base.base.FunctionFeign;
- import com.yihu.jw.restmodel.common.Envelop;
- import com.yihu.jw.restmodel.common.EnvelopRestController;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import org.apache.commons.lang.StringUtils;
- import org.json.JSONObject;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.cloud.sleuth.Tracer;
- import org.springframework.http.MediaType;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- /**
- * Created by chenweida on 2017/6/16.
- */
- @RestController
- @RequestMapping("{version}/"+ BaseContants.api_common)
- @Api(value = "功能管理", description = "功能管理")
- public class FunctionController extends EnvelopRestController {
- @Autowired
- private FunctionFeign fegin;
- @Autowired
- private Tracer tracer;
- @HystrixCommand(commandProperties = {
- @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
- @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
- @PostMapping(value = BaseContants.Function.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
- @ApiOperation(value = "创建功能", notes = "创建功能")
- public Envelop createFunction(
- @ApiParam(name = "json_data", value = "", defaultValue = "")
- @RequestBody String jsonData) throws JiWeiException {
- return fegin.create(jsonData);
- }
- @HystrixCommand(commandProperties = {
- @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
- @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
- @PutMapping(value = BaseContants.Function.api_update, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
- @ApiOperation(value = "更新功能", notes = "更新功能")
- public Envelop updateFunction(
- @ApiParam(name = "json_data", value = "", defaultValue = "")
- @RequestBody String jsonData) throws JiWeiException {
- return fegin.update(jsonData);
- }
- @HystrixCommand(commandProperties = {
- @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
- @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
- @DeleteMapping(value = BaseContants.Function.api_delete)
- @ApiOperation(value = "删除功能", notes = "删除功能")
- public Envelop deleteFunction(
- @ApiParam(name = "codes", value = "codes")
- @PathVariable(value = "codes", required = true) String codes,
- @ApiParam(name = "userCode", value = "userCode")
- @RequestParam(value = "userCode", required = true) String userCode,
- @ApiParam(name = "userName", value = "userName")
- @RequestParam(value = "userName", required = true) String userName) throws JiWeiException {
- return fegin.delete(codes,userCode,userName);
- }
- @HystrixCommand(commandProperties = {
- @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
- @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
- @GetMapping(value = BaseContants.Function.api_getByCode)
- @ApiOperation(value = "根据code查找", notes = "根据code查找")
- public Envelop findByCode(
- @ApiParam(name = "code", value = "code")
- @PathVariable(value = "code", required = true) String code
- ) throws JiWeiException {
- return fegin.findByCode(code);
- }
- @HystrixCommand(commandProperties = {
- @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
- @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
- @GetMapping(value = BaseContants.Function.api_getChildren)
- @ApiOperation(value = "根据code查找子节点", notes = "根据code查找子节点")
- public Envelop getChildren(
- @ApiParam(name = "code", value = "code")
- @PathVariable(value = "code", required = true) String code
- ) throws JiWeiException {
- return fegin.getChildren(code);
- }
- @HystrixCommand(commandProperties = {
- @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
- @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
- @RequestMapping(value = BaseContants.Function.api_getList, method = RequestMethod.GET)
- @ApiOperation(value = "获取功能列表(分页)")
- public Envelop getFunctions(
- @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "code,name,saasId,parentCode,remark")
- @RequestParam(value = "fields", required = false) String fields,
- @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
- //code like 1,name大于aa ,code 等于1 , defaultValue = "code?1;name>aa;code=1"
- @RequestParam(value = "filters", required = false) String filters,
- @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
- @RequestParam(value = "sorts", required = false) String sorts,
- @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
- @RequestParam(value = "size", required = false) int size,
- @ApiParam(name = "page", value = "页码", defaultValue = "1")
- @RequestParam(value = "page", required = false) int page,
- HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- String filterStr = "";
- if(StringUtils.isNotBlank(filters)){
- JSONObject jsonResult = new JSONObject(filters);
- if(jsonResult.has("name")){
- filterStr+="name?"+jsonResult.get("name")+";";
- }
- }
- return fegin.getList(fields, filterStr, sorts, size, page);
- }
- @HystrixCommand(commandProperties = {
- @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
- @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
- @GetMapping(value = BaseContants.Function.api_getListNoPage)
- @ApiOperation(value = "获取功能列表,不分页")
- public Envelop getListNoPage(
- @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "code,name,saasId,parentCode,remark")
- @RequestParam(value = "fields", required = false) String fields,
- @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
- @RequestParam(value = "filters", required = false) String filters,
- @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
- @RequestParam(value = "sorts", required = false) String sorts) throws Exception {
- String filterStr = "";
- if(StringUtils.isNotBlank(filters)){
- JSONObject jsonResult = new JSONObject(filters);
- if(jsonResult.has("saasId")){
- filterStr+="saasId="+jsonResult.get("saasId")+";";
- }
- if(jsonResult.has("parentCode")){
- filterStr+="parentCode="+jsonResult.get("parentCode")+";";
- }
- }
- return fegin.getListNoPage(fields, filterStr, sorts);
- }
- }
|