| | |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.google.gson.JsonArray; |
| | | import com.google.gson.JsonObject; |
| | | import com.java110.api.properties.WechatAuthProperties; |
| | | import com.java110.core.component.AbstractComponentSMO; |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.core.factory.AuthenticationFactory; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.dto.basePrivilege.BasePrivilegeDto; |
| | | import com.java110.dto.app.AppDto; |
| | | import com.java110.dto.privilege.BasePrivilegeDto; |
| | | import com.java110.dto.store.StoreDto; |
| | | import com.java110.dto.user.UserDto; |
| | | import com.java110.entity.component.ComponentValidateResult; |
| | | import com.java110.dto.system.ComponentValidateResult; |
| | | import com.java110.intf.user.IUserInnerServiceSMO; |
| | | import com.java110.utils.cache.PrivilegeCache; |
| | | import com.java110.utils.constant.CommonConstant; |
| | |
| | | import com.java110.utils.util.*; |
| | | import com.java110.vo.ResultVo; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.java110.core.log.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.*; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.client.HttpStatusCodeException; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | |
| | | |
| | | headers.put(CommonConstant.USER_ID, StringUtil.isEmpty(pd.getUserId()) ? "-1" : pd.getUserId()); |
| | | |
| | | if (!headers.containsKey(CommonConstant.HTTP_USER_ID)) { |
| | | headers.put(CommonConstant.HTTP_USER_ID, StringUtil.isEmpty(pd.getUserId()) ? "-1" : pd.getUserId()); |
| | | } |
| | | if (!headers.containsKey(CommonConstant.HTTP_APP_ID)) { |
| | | headers.put(CommonConstant.HTTP_APP_ID, pd.getAppId()); |
| | | headers.put(CommonConstant.HTTP_APP_ID, AppDto.WEB_APP_ID); |
| | | } |
| | | if (!headers.containsKey(CommonConstant.APP_ID)) { |
| | | headers.put(CommonConstant.APP_ID, AppDto.WEB_APP_ID); |
| | | } |
| | | |
| | | if (!headers.containsKey(CommonConstant.HTTP_TRANSACTION_ID)) { |
| | | headers.put(CommonConstant.HTTP_TRANSACTION_ID, GenerateCodeFactory.getUUID()); |
| | | } |
| | | if (!headers.containsKey(CommonConstant.HTTP_REQ_TIME)) { |
| | | headers.put(CommonConstant.HTTP_REQ_TIME, DateUtil.getNowDefault()); |
| | | } |
| | | if (!headers.containsKey(CommonConstant.HTTP_SIGN)) { |
| | | headers.put(CommonConstant.HTTP_SIGN, ""); |
| | | } |
| | | |
| | | if (url.indexOf("?") > -1) { |
| | |
| | | } |
| | | headers.put(CommonConstant.HTTP_SERVICE, url); |
| | | headers.put(CommonConstant.HTTP_METHOD, CommonConstant.getHttpMethodStr(httpMethod)); |
| | | |
| | | if (HttpMethod.GET == httpMethod) { |
| | | initUrlParam(JSONObject.parseObject(param), headers); |
| | | } |
| | | if (HttpMethod.GET == httpMethod) { |
| | | headers.put("REQUEST_URL", "http://127.0.0.1:8008/" + url + mapToUrlParam(JSONObject.parseObject(param))); |
| | | } |
| | | AuthenticationFactory.createSign(headers,httpMethod,headers.get("REQUEST_URL"),param); |
| | | |
| | | try { |
| | | responseEntity = apiServiceSMOImpl.service(param, headers); |
| | | } catch (HttpStatusCodeException e) { //这里spring 框架 在4XX 或 5XX 时抛出 HttpServerErrorException 异常,需要重新封装一下 |
| | |
| | | headers.put(CommonConstant.HTTP_USER_ID, "-1"); |
| | | } |
| | | |
| | | headers.put(CommonConstant.USER_ID, "-1"); |
| | | |
| | | if (!headers.containsKey(CommonConstant.HTTP_USER_ID)) { |
| | | headers.put(CommonConstant.HTTP_USER_ID, "-1"); |
| | | if (!headers.containsKey(CommonConstant.USER_ID)) { |
| | | headers.put(CommonConstant.USER_ID, headers.get(CommonConstant.HTTP_USER_ID)); |
| | | } |
| | | if (!headers.containsKey(CommonConstant.HTTP_TRANSACTION_ID)) { |
| | | headers.put(CommonConstant.HTTP_TRANSACTION_ID, GenerateCodeFactory.getUUID()); |
| | | } |
| | | if (!headers.containsKey(CommonConstant.HTTP_REQ_TIME)) { |
| | | headers.put(CommonConstant.HTTP_REQ_TIME, DateUtil.getNowDefault()); |
| | | } |
| | | if (!headers.containsKey(CommonConstant.HTTP_SIGN)) { |
| | | headers.put(CommonConstant.HTTP_SIGN, ""); |
| | | } |
| | | |
| | | if (url.indexOf("?") > -1) { |
| | |
| | | if (HttpMethod.GET == httpMethod) { |
| | | headers.put("REQUEST_URL", "http://127.0.0.1:8008/" + url + mapToUrlParam(JSONObject.parseObject(param))); |
| | | } |
| | | AuthenticationFactory.createSign(headers,httpMethod,headers.get("REQUEST_URL"),param); |
| | | |
| | | try { |
| | | responseEntity = apiServiceSMOImpl.service(param, headers); |
| | | } catch (HttpStatusCodeException e) { //这里spring 框架 在4XX 或 5XX 时抛出 HttpServerErrorException 异常,需要重新封装一下 |
| | |
| | | } |
| | | |
| | | ResultVo resultVo = getCommunityStoreInfoSMOImpl.checkUserHasResourceListener(restTemplate, pd, paramIn, pd.getUserId()); |
| | | if (resultVo == null || resultVo.getCode() != ResultVo.CODE_OK) { |
| | | if (resultVo == null || |
| | | resultVo.getCode() != ResultVo.CODE_OK) { |
| | | throw new UnsupportedOperationException("用户没有权限操作"); |
| | | } |
| | | JSONArray privileges = JSONArray.parseArray(resultVo.getMsg()); |
| | |
| | | return new ResponseEntity<String>(resultVo.getMsg(), resultVo.getCode() == ResultVo.CODE_OK ? HttpStatus.OK : HttpStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | private ResponseEntity<String> getStoreEnterCommunitys(IPageData pd, String storeId, String storeTypeCd, RestTemplate restTemplate) { |
| | | ResultVo resultVo = getCommunityStoreInfoSMOImpl.getStoreEnterCommunitys(pd, storeId, storeTypeCd, restTemplate); |
| | | return new ResponseEntity<String>(resultVo.getMsg(), resultVo.getCode() == ResultVo.CODE_OK ? HttpStatus.OK : HttpStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | /** |
| | | * 查询商户信息 |
| | |
| | | */ |
| | | protected void checkStoreEnterCommunity(IPageData pd, String storeId, String storeTypeCd, String communityId, RestTemplate restTemplate) { |
| | | Assert.hasLength(pd.getUserId(), "用户未登录请先登录"); |
| | | ResponseEntity<String> responseEntity = null; |
| | | responseEntity = getStoreEnterCommunitys(pd, storeId, storeTypeCd, restTemplate); |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | ResultVo resultVo = getCommunityStoreInfoSMOImpl.getStoreEnterCommunitys(pd, storeId, storeTypeCd, restTemplate); |
| | | if (resultVo.getCode() != ResultVo.CODE_OK) { |
| | | throw new SMOException(ResponseConstant.RESULT_CODE_ERROR, "还未入驻小区,请先入驻小区"); |
| | | } |
| | | |
| | | Assert.jsonObjectHaveKey(responseEntity.getBody().toString(), "data", "还未入驻小区,请先入驻小区"); |
| | | |
| | | JSONObject community = JSONObject.parseObject(responseEntity.getBody().toString()); |
| | | |
| | | JSONArray communitys = community.getJSONArray("data"); |
| | | JSONArray communitys = JSONArray.parseArray(resultVo.getData().toString()); |
| | | |
| | | if (communitys == null || communitys.size() == 0) { |
| | | throw new SMOException(ResponseConstant.RESULT_CODE_ERROR, "还未入驻小区,请先入驻小区"); |
| | |
| | | JSONObject paramIn = JSONObject.parseObject(pd.getReqData()); |
| | | |
| | | String communityId = ""; |
| | | if (paramIn.containsKey("communityId") && !StringUtil.isEmpty(paramIn.getString("communityId"))) { |
| | | if (paramIn.containsKey("communityId") |
| | | && !StringUtil.isEmpty(paramIn.getString("communityId")) |
| | | && !"-1".equals(paramIn.getString("communityId")) |
| | | && !StoreDto.STORE_TYPE_ADMIN.equals(storeTypeCd) |
| | | && !StoreDto.STORE_TYPE_DEV.equals(storeTypeCd) |
| | | ) { |
| | | communityId = paramIn.getString("communityId"); |
| | | checkStoreEnterCommunity(pd, storeId, storeTypeCd, communityId, restTemplate); |
| | | } |
| | |
| | | |
| | | ResponseEntity<String> responseEntity = callCenterService(restTemplate, pd, JSONObject.toJSONString(param), url, HttpMethod.POST); |
| | | |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | throw new SMOException("调用" + serviceCode + "失败," + responseEntity.getBody()); |
| | | } |
| | | |
| | | JSONObject resultVo = JSONObject.parseObject(responseEntity.getBody()); |
| | | |
| | | if (ResultVo.CODE_MACHINE_OK != resultVo.getInteger("code")) { |
| | | throw new SMOException(resultVo.getString("msg")); |
| | | } |
| | | |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | throw new SMOException(resultVo.getString("msg")); |
| | | } |
| | | |
| | | Object bObj = resultVo.get("data"); |
| | | JSONArray datas = null; |
| | | if (bObj instanceof JSONObject) { |