old mode 100644
new mode 100755
| | |
| | | package com.java110.core.base.controller; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.utils.constant.CommonConstant; |
| | | import com.java110.utils.constant.ResponseConstant; |
| | | import com.java110.utils.constant.ServiceConstant; |
| | | import com.java110.utils.exception.NoAuthorityException; |
| | | |
| | | import com.java110.utils.util.StringUtil; |
| | | import com.java110.core.base.AppBase; |
| | | import com.java110.core.context.BusinessServiceDataFlow; |
| | | import com.java110.core.factory.DataFlowFactory; |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.core.context.PageData; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.HttpStatus; |
| | | import com.java110.core.factory.DataFlowFactory; |
| | | import com.java110.dto.basePrivilege.BasePrivilegeDto; |
| | | import com.java110.utils.cache.PrivilegeCache; |
| | | import com.java110.utils.constant.CommonConstant; |
| | | import com.java110.utils.constant.ResponseConstant; |
| | | import com.java110.utils.exception.NoAuthorityException; |
| | | import com.java110.utils.util.StringUtil; |
| | | import com.java110.vo.ResultVo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.ui.Model; |
| | | import org.springframework.web.client.RestTemplate; |
| | |
| | | * Created by wuxw on 2017/2/23. |
| | | */ |
| | | public class BaseController extends AppBase { |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | return returnMap; |
| | | } |
| | | |
| | | // 获取HttpServletRequest里面的参数 |
| | | public static Map<String, String> getRequestParams(HttpServletRequest request) { |
| | | Map<String, String[]> params = request.getParameterMap(); |
| | | Map<String, String> params2 = new HashMap<>(); |
| | | for (String key : params.keySet()) { |
| | | String[] values = params.get(key); |
| | | if (values.length > 0) { |
| | | params2.put(key, request.getParameter(key)); |
| | | } |
| | | } |
| | | return params2; |
| | | } |
| | | |
| | | protected void initHeadParam(HttpServletRequest request, Map headers) { |
| | | |
| | | Enumeration reqHeaderEnum = request.getHeaderNames(); |
| | |
| | | |
| | | headers.put("IP", getIpAddr(request)); |
| | | |
| | | headers.put("hostName", request.getLocalName()); |
| | | //headers.put("hostName", request.getLocalName()); 这里导致部分主机 速度比较慢 |
| | | headers.put("hostName", "localhost"); |
| | | headers.put("port", request.getLocalPort() + ""); |
| | | |
| | | //处理app-id |
| | | if(headers.containsKey("app-id")){ |
| | | headers.put("app_id",headers.get("app-id")); |
| | | if (headers.containsKey("app-id")) { |
| | | headers.put("app_id", headers.get("app-id")); |
| | | } |
| | | |
| | | //处理transaction-id |
| | | if(headers.containsKey("transaction-id")){ |
| | | headers.put("transaction_id",headers.get("transaction-id")); |
| | | if (headers.containsKey("transaction-id")) { |
| | | headers.put("transaction_id", headers.get("transaction-id")); |
| | | } |
| | | |
| | | //处理req-time |
| | | if(headers.containsKey("req-time")){ |
| | | headers.put("req_time",headers.get("req-time")); |
| | | if (headers.containsKey("req-time")) { |
| | | headers.put("req_time", headers.get("req-time")); |
| | | } |
| | | |
| | | //处理req-time |
| | | if(headers.containsKey("user-id")){ |
| | | headers.put("user_id",headers.get("user-id")); |
| | | if (headers.containsKey("user-id") && !"-1".equals(headers.get("user-id"))) { |
| | | headers.put("user_id", headers.get("user-id")); |
| | | } |
| | | |
| | | } |
| | |
| | | return businessServiceDataFlow; |
| | | } |
| | | |
| | | protected void hasPrivilege(RestTemplate restTemplate, IPageData pd, String resource) { |
| | | ResponseEntity<String> responseEntity = null; |
| | | //没有用户的情况下不做权限判断 |
| | | if (StringUtil.isEmpty(pd.getUserId())) { |
| | | return; |
| | | } |
| | | JSONObject paramIn = new JSONObject(); |
| | | paramIn.put("resource", resource); |
| | | paramIn.put("userId", pd.getUserId()); |
| | | responseEntity = this.callCenterService(restTemplate, pd, paramIn.toJSONString(), |
| | | ServiceConstant.SERVICE_API_URL + "/api/basePrivilege.CheckUserHasResourceListener", |
| | | HttpMethod.POST); |
| | | |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | throw new UnsupportedOperationException("用户没有权限操作"); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |