| | |
| | | */ |
| | | package com.java110.job.adapt.ximoIot.asyn.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.client.RestTemplate; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.dto.machine.MachineDto; |
| | | import com.java110.intf.common.IMachineAttrInnerServiceSMO; |
| | | import com.java110.intf.common.IMachineInnerServiceSMO; |
| | | import com.java110.job.adapt.ximoIot.GetToken; |
| | | import com.java110.job.adapt.ximoIot.XimoIotConstant; |
| | | import com.java110.job.adapt.ximoIot.asyn.IXimoMachineAsyn; |
| | | import com.java110.po.machine.MachineAttrPo; |
| | | import com.java110.vo.ResultVo; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.http.*; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.MultiValueMap; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @desc add by 吴学文 11:55 |
| | |
| | | @Autowired |
| | | private RestTemplate formRestTemplate; |
| | | |
| | | @Autowired |
| | | private IMachineInnerServiceSMO machineInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IMachineAttrInnerServiceSMO machineAttrInnerServiceSMOImpl; |
| | | |
| | | @Override |
| | | @Async |
| | | public void send(MultiValueMap<String, Object> postParameters) { |
| | | public void send(MultiValueMap<String, Object> postParameters, List<MultiValueMap<String, Object>> ownerDtos) { |
| | | postParameters.add("accessToken", GetToken.get(formRestTemplate)); |
| | | HttpHeaders httpHeaders = new HttpHeaders(); |
| | | httpHeaders.add("Content-Type", "application/x-www-form-urlencoded"); |
| | |
| | | ResponseEntity<String> responseEntity = formRestTemplate.exchange(XimoIotConstant.ADD_MACHINE_URL, HttpMethod.POST, httpEntity, String.class); |
| | | |
| | | logger.debug("调用吸墨信息:" + responseEntity); |
| | | |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | return; |
| | | } |
| | | JSONObject tokenObj = JSONObject.parseObject(responseEntity.getBody()); |
| | | |
| | | if (!tokenObj.containsKey("code") || ResultVo.CODE_OK != tokenObj.getInteger("code")) { |
| | | return; |
| | | } |
| | | |
| | | JSONObject data = tokenObj.getJSONObject("data"); |
| | | String devMac = data.getString("devMac"); |
| | | String appEkey = data.getString("appEkey"); |
| | | |
| | | MachineDto machinePo = new MachineDto(); |
| | | machinePo.setMachineId(data.getString("uuid")); |
| | | machinePo.setState("1700"); |
| | | machinePo.setMachineMac(devMac); |
| | | machineInnerServiceSMOImpl.updateMachineState(machinePo); |
| | | |
| | | MachineAttrPo machineAttrPo = new MachineAttrPo(); |
| | | machineAttrPo.setAttrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_attrId)); |
| | | machineAttrPo.setCommunityId(postParameters.get("extCommunityUuid").get(0).toString()); |
| | | machineAttrPo.setSpecCd("7127015495"); |
| | | machineAttrPo.setMachineId(data.getString("uuid")); |
| | | machineAttrPo.setValue(appEkey); |
| | | machineAttrInnerServiceSMOImpl.saveMachineAttrs(machineAttrPo); |
| | | |
| | | for (MultiValueMap<String, Object> owner : ownerDtos) { |
| | | sendOwner(owner); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | logger.debug("调用吸墨信息:" + responseEntity); |
| | | } |
| | | |
| | | @Override |
| | | public void sendOwner(MultiValueMap<String, Object> postParameters) { |
| | | postParameters.add("accessToken", GetToken.get(formRestTemplate)); |
| | | HttpHeaders httpHeaders = new HttpHeaders(); |
| | | httpHeaders.add("Content-Type", "application/x-www-form-urlencoded"); |
| | | |
| | | HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity(postParameters, httpHeaders); |
| | | ResponseEntity<String> responseEntity = formRestTemplate.exchange(XimoIotConstant.ADD_OWNER, HttpMethod.POST, httpEntity, String.class); |
| | | |
| | | logger.debug("调用吸墨信息:" + responseEntity); |
| | | } |
| | | |
| | | @Override |
| | | public void sendUpdateOwner(MultiValueMap<String, Object> postParameters) { |
| | | postParameters.add("accessToken", GetToken.get(formRestTemplate)); |
| | | HttpHeaders httpHeaders = new HttpHeaders(); |
| | | httpHeaders.add("Content-Type", "application/x-www-form-urlencoded"); |
| | | |
| | | HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity(postParameters, httpHeaders); |
| | | ResponseEntity<String> responseEntity = formRestTemplate.exchange(XimoIotConstant.EDIT_OWNER, HttpMethod.POST, httpEntity, String.class); |
| | | |
| | | logger.debug("调用吸墨信息:" + responseEntity); |
| | | } |
| | | |
| | | @Override |
| | | public void sendDeleteOwner(MultiValueMap<String, Object> postParameters) { |
| | | postParameters.add("accessToken", GetToken.get(formRestTemplate)); |
| | | HttpHeaders httpHeaders = new HttpHeaders(); |
| | | httpHeaders.add("Content-Type", "application/x-www-form-urlencoded"); |
| | | |
| | | HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity(postParameters, httpHeaders); |
| | | ResponseEntity<String> responseEntity = formRestTemplate.exchange(XimoIotConstant.DELETE_OWNER, HttpMethod.POST, httpEntity, String.class); |
| | | |
| | | logger.debug("调用吸墨信息:" + responseEntity); |
| | | } |
| | | } |