| | |
| | | package com.java110.front.smo.api.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.front.smo.api.IApiSMO; |
| | | import com.java110.core.component.BaseComponentSMO; |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.entity.component.ComponentValidateResult; |
| | | import com.java110.front.smo.api.IApiSMO; |
| | | import com.java110.utils.constant.CommonConstant; |
| | | import com.java110.utils.constant.ServiceConstant; |
| | | import com.java110.utils.util.Assert; |
| | | import com.java110.utils.util.StringUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.web.client.HttpStatusCodeException; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.Map; |
| | | |
| | | @Service("apiSMOImpl") |
| | |
| | | private RestTemplate restTemplate; |
| | | |
| | | @Override |
| | | public ResponseEntity<String> doApi(String body, Map<String, String> headers) { |
| | | protected ComponentValidateResult validateStoreStaffCommunityRelationship(IPageData pd, RestTemplate restTemplate) { |
| | | // 校验 员工和商户是否有关系 |
| | | ResponseEntity responseEntity = getStoreInfo(pd, restTemplate); |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | return new ComponentValidateResult("", "", "", pd.getUserId(), pd.getUserName()); |
| | | } |
| | | |
| | | Assert.jsonObjectHaveKey(responseEntity.getBody().toString(), "storeId", "根据用户ID查询商户ID失败,未包含storeId节点"); |
| | | Assert.jsonObjectHaveKey(responseEntity.getBody().toString(), "storeTypeCd", "根据用户ID查询商户类型失败,未包含storeTypeCd节点"); |
| | | |
| | | String storeId = JSONObject.parseObject(responseEntity.getBody().toString()).getString("storeId"); |
| | | String storeTypeCd = JSONObject.parseObject(responseEntity.getBody().toString()).getString("storeTypeCd"); |
| | | |
| | | JSONObject paramIn = JSONObject.parseObject(pd.getReqData()); |
| | | |
| | | String communityId = ""; |
| | | if (paramIn != null && paramIn.containsKey("communityId") && !StringUtil.isEmpty(paramIn.getString("communityId"))) { |
| | | communityId = paramIn.getString("communityId"); |
| | | checkStoreEnterCommunity(pd, storeId, storeTypeCd, communityId, restTemplate); |
| | | } |
| | | return new ComponentValidateResult(storeId, storeTypeCd, communityId, pd.getUserId(), pd.getUserName()); |
| | | } |
| | | |
| | | @Override |
| | | public ResponseEntity<String> doApi(String body, Map<String, String> headers, HttpServletRequest request) { |
| | | HttpHeaders header = new HttpHeaders(); |
| | | IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA); |
| | | |
| | | ComponentValidateResult result = this.validateStoreStaffCommunityRelationship(pd, restTemplate); |
| | | header.add("user-id", result.getUserId()); |
| | | header.add("user-name", result.getUserName()); |
| | | header.add("store-id", result.getStoreId()); |
| | | logger.debug("api请求头" + headers + ";请求内容:" + body); |
| | | HttpMethod method = null; |
| | | String url = ServiceConstant.SERVICE_API_URL + "/api/" + headers.get(CommonConstant.HTTP_SERVICE); |
| | |
| | | throw new IllegalArgumentException("不支持的请求方式" + headers.get(CommonConstant.HTTP_METHOD)); |
| | | } |
| | | |
| | | HttpHeaders header = new HttpHeaders(); |
| | | |
| | | for (String key : headers.keySet() |
| | | ) { |
| | | header.add(key, headers.get(key)); |