| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.client.RestTemplate; |
| | | import com.java110.core.factory.AuthenticationFactory; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.dto.machine.MachineTranslateErrorDto; |
| | | import com.java110.dto.system.AppRoute; |
| | | import com.java110.intf.common.IMachineTranslateErrorInnerServiceSMO; |
| | | import com.java110.job.adapt.hcIot.GetToken; |
| | | import com.java110.job.adapt.hcIot.IotConstant; |
| | | import com.java110.po.machine.MachineTranslateErrorPo; |
| | | import com.java110.utils.cache.AppRouteCache; |
| | | import com.java110.utils.cache.CommonCache; |
| | | import com.java110.utils.cache.MappingCache; |
| | |
| | | @Autowired |
| | | private RestTemplate outRestTemplate; |
| | | |
| | | @Autowired |
| | | private IMachineTranslateErrorInnerServiceSMO machineTranslateErrorInnerServiceSMOImpl; |
| | | |
| | | |
| | | @Override |
| | | public ResultVo get(String url) { |
| | | HttpHeaders header = getHeaders(url, "", HttpMethod.POST); |
| | |
| | | |
| | | String body = tokenRes.getBody(); |
| | | JSONObject paramOut = JSONObject.parseObject(body); |
| | | |
| | | |
| | | return new ResultVo(paramOut.getIntValue("code"), paramOut.getString("msg"), paramOut.getJSONObject("data")); |
| | | } |
| | |
| | | String body = tokenRes.getBody(); |
| | | JSONObject paramOut = JSONObject.parseObject(body); |
| | | |
| | | if(paramOut.getIntValue("code") != ResultVo.CODE_OK){ |
| | | saveTranslateError(paramIn.getString("communityId"),paramIn.toJSONString(),body,url); |
| | | } |
| | | |
| | | |
| | | return new ResultVo(paramOut.getIntValue("code"), paramOut.getString("msg"), paramOut.getJSONObject("data")); |
| | | } |
| | | |
| | | |
| | | |
| | | public void saveTranslateError(String communityId,String reqJson, String resJson, String url) { |
| | | MachineTranslateErrorPo machineTranslateErrorPo = new MachineTranslateErrorPo(); |
| | | machineTranslateErrorPo.setLogId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_logId)); |
| | | machineTranslateErrorPo.setCommunityId(communityId); |
| | | machineTranslateErrorPo.setMachineTranslateId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_machineTranslateId)); |
| | | machineTranslateErrorPo.setReqBody(reqJson); |
| | | machineTranslateErrorPo.setReqHeader(""); |
| | | machineTranslateErrorPo.setResBody(resJson); |
| | | machineTranslateErrorPo.setReqPath(url); |
| | | machineTranslateErrorPo.setCommunityId("-1"); |
| | | machineTranslateErrorPo.setReqType(MachineTranslateErrorDto.REQ_TYPE_URL); |
| | | machineTranslateErrorInnerServiceSMOImpl.saveMachineTranslateError(machineTranslateErrorPo); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | private HttpHeaders getHeaders(String url, String param, HttpMethod method) { |
| | | HttpHeaders header = new HttpHeaders(); |
| | | header.add(CommonConstant.APP_ID.toLowerCase(), CommonConstant.HC_HARDWARE_APP_ID); |
| | | header.add(CommonConstant.APP_ID.toLowerCase(), MappingCache.getValue(IOT_DOMAIN, "APP_ID")); |
| | | header.add(CommonConstant.USER_ID.toLowerCase(), CommonConstant.ORDER_DEFAULT_USER_ID); |
| | | header.add(CommonConstant.TRANSACTION_ID.toLowerCase(), UUID.randomUUID().toString()); |
| | | header.add(CommonConstant.REQUEST_TIME.toLowerCase(), DateUtil.getDefaultFormateTimeString(new Date())); |
| | |
| | | String password = MappingCache.getValue(IOT_DOMAIN, "IOT_PASSWORD"); |
| | | JSONObject param = new JSONObject(); |
| | | param.put("username", userName); |
| | | param.put("password", password); |
| | | param.put("passwd", password); |
| | | |
| | | HttpHeaders header = new HttpHeaders(); |
| | | header.add(CommonConstant.APP_ID.toLowerCase(), MappingCache.getValue(IOT_DOMAIN, "APP_ID")); |
| | |
| | | |
| | | ResponseEntity<String> tokenRes = outRestTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class); |
| | | |
| | | if (tokenRes.getStatusCode() != HttpStatus.OK) { |
| | | |
| | | JSONObject tokenObj = JSONObject.parseObject(tokenRes.getBody()); |
| | | if (tokenObj.getIntValue("code") != 0) { |
| | | throw new IllegalArgumentException("获取token失败" + tokenRes.getBody()); |
| | | } |
| | | JSONObject tokenObj = JSONObject.parseObject(tokenRes.getBody()); |
| | | |
| | | if (!tokenObj.containsKey("token")) { |
| | | throw new IllegalArgumentException("获取token失败" + tokenRes.getBody()); |
| | | } |