Browse Source

优化 代码

java110 4 years ago
parent
commit
43d91615f5

+ 18 - 0
java110-utils/src/main/java/com/java110/utils/constant/BusinessTypeConstant.java

@@ -468,6 +468,24 @@ public class BusinessTypeConstant {
      */
     public static final String BUSINESS_TYPE_DELETE_PARKING_AREA_ATTR = "541100050002";
 
+    /**
+     * 增加停车场
+     */
+    public static final String BUSINESS_TYPE_SAVE_PARKING_BOX = "541100030004";
+
+    /**
+     * 修改车位
+     */
+    public static final String BUSINESS_TYPE_UPDATE_PARKING_BOX = "541100040004";
+
+
+    /**
+     * 删除车位
+     */
+    public static final String BUSINESS_TYPE_DELETE_PARKING_BOX = "541100050004";
+
+
+
     /**
      * 增加车位
      */

+ 9 - 0
service-community/src/main/java/com/java110/community/cmd/parkingBoxArea/DeleteParkingBoxAreaCmd.java

@@ -23,6 +23,8 @@ import com.java110.core.event.cmd.AbstractServiceCmdListener;
 import com.java110.core.event.cmd.CmdEvent;
 import com.java110.dto.parkingBoxArea.ParkingBoxAreaDto;
 import com.java110.intf.community.IParkingBoxAreaV1InnerServiceSMO;
+import com.java110.intf.community.IParkingBoxV1InnerServiceSMO;
+import com.java110.po.parkingBox.ParkingBoxPo;
 import com.java110.po.parkingBoxArea.ParkingBoxAreaPo;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
@@ -51,6 +53,9 @@ public class DeleteParkingBoxAreaCmd extends AbstractServiceCmdListener {
     @Autowired
     private IParkingBoxAreaV1InnerServiceSMO parkingBoxAreaV1InnerServiceSMOImpl;
 
+    @Autowired
+    private IParkingBoxV1InnerServiceSMO parkingBoxV1InnerServiceSMOImpl;
+
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
         Assert.hasKeyAndValue(reqJson, "baId", "baId不能为空");
@@ -78,6 +83,10 @@ public class DeleteParkingBoxAreaCmd extends AbstractServiceCmdListener {
             throw new CmdException("删除数据失败");
         }
 
+        ParkingBoxPo parkingBoxPo = new ParkingBoxPo();
+        parkingBoxPo.setBoxId(reqJson.getString("boxId"));
+        parkingBoxV1InnerServiceSMOImpl.updateParkingBox(parkingBoxPo);
+
         cmdDataFlowContext.setResponseEntity(ResultVo.success());
     }
 }

+ 9 - 1
service-community/src/main/java/com/java110/community/cmd/parkingBoxArea/SaveParkingBoxAreaCmd.java

@@ -24,6 +24,8 @@ import com.java110.core.event.cmd.CmdEvent;
 import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.dto.parkingBoxArea.ParkingBoxAreaDto;
 import com.java110.intf.community.IParkingBoxAreaV1InnerServiceSMO;
+import com.java110.intf.community.IParkingBoxV1InnerServiceSMO;
+import com.java110.po.parkingBox.ParkingBoxPo;
 import com.java110.po.parkingBoxArea.ParkingBoxAreaPo;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
@@ -53,6 +55,9 @@ public class SaveParkingBoxAreaCmd extends AbstractServiceCmdListener {
     @Autowired
     private IParkingBoxAreaV1InnerServiceSMO parkingBoxAreaV1InnerServiceSMOImpl;
 
+    @Autowired
+    private IParkingBoxV1InnerServiceSMO parkingBoxV1InnerServiceSMOImpl;
+
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
         Assert.hasKeyAndValue(reqJson, "boxId", "请求报文中未包含boxId");
@@ -67,7 +72,7 @@ public class SaveParkingBoxAreaCmd extends AbstractServiceCmdListener {
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
 
         String defaultArea = reqJson.getString("defaultArea");
-        if(ParkingBoxAreaDto.DEFAULT_AREA_TRUE.equals(defaultArea)){
+        if (ParkingBoxAreaDto.DEFAULT_AREA_TRUE.equals(defaultArea)) {
             ParkingBoxAreaPo tmpParkingBoxAreaPo = new ParkingBoxAreaPo();
             tmpParkingBoxAreaPo.setBoxId(reqJson.getString("boxId"));
             tmpParkingBoxAreaPo.setDefaultArea(ParkingBoxAreaDto.DEFAULT_AREA_FALSE);
@@ -81,6 +86,9 @@ public class SaveParkingBoxAreaCmd extends AbstractServiceCmdListener {
         if (flag < 1) {
             throw new CmdException("保存数据失败");
         }
+        ParkingBoxPo parkingBoxPo = new ParkingBoxPo();
+        parkingBoxPo.setBoxId(reqJson.getString("boxId"));
+        parkingBoxV1InnerServiceSMOImpl.updateParkingBox(parkingBoxPo);
 
         cmdDataFlowContext.setResponseEntity(ResultVo.success());
     }

+ 9 - 0
service-community/src/main/java/com/java110/community/cmd/parkingBoxArea/UpdateParkingBoxAreaCmd.java

@@ -23,6 +23,8 @@ import com.java110.core.event.cmd.AbstractServiceCmdListener;
 import com.java110.core.event.cmd.CmdEvent;
 import com.java110.dto.parkingBoxArea.ParkingBoxAreaDto;
 import com.java110.intf.community.IParkingBoxAreaV1InnerServiceSMO;
+import com.java110.intf.community.IParkingBoxV1InnerServiceSMO;
+import com.java110.po.parkingBox.ParkingBoxPo;
 import com.java110.po.parkingBoxArea.ParkingBoxAreaPo;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
@@ -52,6 +54,9 @@ public class UpdateParkingBoxAreaCmd extends AbstractServiceCmdListener {
     @Autowired
     private IParkingBoxAreaV1InnerServiceSMO parkingBoxAreaV1InnerServiceSMOImpl;
 
+    @Autowired
+    private IParkingBoxV1InnerServiceSMO parkingBoxV1InnerServiceSMOImpl;
+
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
         Assert.hasKeyAndValue(reqJson, "baId", "baId不能为空");
@@ -76,6 +81,10 @@ public class UpdateParkingBoxAreaCmd extends AbstractServiceCmdListener {
             throw new CmdException("更新数据失败");
         }
 
+        ParkingBoxPo parkingBoxPo = new ParkingBoxPo();
+        parkingBoxPo.setBoxId(reqJson.getString("boxId"));
+        parkingBoxV1InnerServiceSMOImpl.updateParkingBox(parkingBoxPo);
+
         cmdDataFlowContext.setResponseEntity(ResultVo.success());
     }
 }

+ 6 - 0
service-job/src/main/java/com/java110/job/adapt/hcIot/IotConstant.java

@@ -62,6 +62,12 @@ public class IotConstant {
     //添加停车场问候语
     public static final String ADD_PARKING_AREA_TEXT_URL = "/extApi/parkingAreaText/addParkingAreaText";
 
+    //添加岗亭
+    public static final String ADD_PARKING_BOX_URL = "/extApi/parkingBox/addParkingBox";
+
+    //删除岗亭
+    public static final String DELETE_PARKING_BOX_URL = "/extApi/parkingBox/deleteParkingBox";
+
     //添加车辆
     public static final String ADD_OWNER_CAR_URL = "/extApi/car/addCar";
     //修改车辆

+ 12 - 0
service-job/src/main/java/com/java110/job/adapt/hcIot/asyn/IIotSendAsyn.java

@@ -164,4 +164,16 @@ public interface IIotSendAsyn {
      * @param postParameters
      */
     void addParkingAreaText(JSONObject postParameters);
+
+    /**
+     * 添加岗亭
+     * @param postParameters
+     */
+    void addParkingBox(JSONObject postParameters);
+
+    /**
+     * 删除岗亭
+     * @param postParameters
+     */
+    void deleteParkingBox(JSONObject postParameters);
 }

+ 92 - 0
service-job/src/main/java/com/java110/job/adapt/hcIot/asyn/impl/IotSendAsynImpl.java

@@ -1256,6 +1256,98 @@ public class IotSendAsynImpl implements IIotSendAsyn {
         }
     }
 
+    @Override
+    public void addParkingBox(JSONObject postParameters) {
+        MachineTranslateDto machineTranslateDto = getMachineTranslateDto(postParameters, MachineTranslateDto.CMD_ADD_PARKING_AREA_TEXT,
+                DEFAULT_MACHINE_CODE,
+                DEFAULT_MACHINE_ID,
+                "extPaId",
+                "textId",
+                MachineTranslateDto.TYPE_PARKING_AREA);
+        ResponseEntity<String> responseEntity = null;
+        String url = IotConstant.getUrl(IotConstant.ADD_PARKING_BOX_URL);
+        try {
+            postParameters.put("taskId", machineTranslateDto.getMachineTranslateId());
+            HttpEntity httpEntity = new HttpEntity(postParameters.toJSONString(), getHeaders());
+            responseEntity = outRestTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
+
+            logger.debug("调用HC IOT信息:" + responseEntity);
+
+            if (responseEntity.getStatusCode() != HttpStatus.OK) {
+                machineTranslateDto.setState(MachineTranslateDto.STATE_ERROR);
+                machineTranslateDto.setRemark(responseEntity.getBody());
+                saveTranslateError(machineTranslateDto, postParameters.toJSONString(), responseEntity != null ? responseEntity.getBody() : "", url);
+                return;
+            }
+            JSONObject tokenObj = JSONObject.parseObject(responseEntity.getBody());
+
+            if (!tokenObj.containsKey("code") || ResultVo.CODE_OK != tokenObj.getInteger("code")) {
+                machineTranslateDto.setState(MachineTranslateDto.STATE_ERROR);
+                machineTranslateDto.setRemark(tokenObj.getString("msg"));
+                //保存 失败报文
+                saveTranslateError(machineTranslateDto, postParameters.toJSONString(), responseEntity != null ? responseEntity.getBody() : "", url);
+
+                return;
+            }
+        } catch (Exception e) {
+            machineTranslateDto.setState(MachineTranslateDto.STATE_ERROR);
+            machineTranslateDto.setRemark(e.getLocalizedMessage());
+            //保存 失败报文
+            saveTranslateError(machineTranslateDto, postParameters.toJSONString(), responseEntity != null ? responseEntity.getBody() : "", url);
+
+            return;
+        } finally {
+            saveTranslateLog(machineTranslateDto);
+            refreshAccessToken(responseEntity);
+        }
+    }
+
+    @Override
+    public void deleteParkingBox(JSONObject postParameters) {
+        MachineTranslateDto machineTranslateDto = getMachineTranslateDto(postParameters, MachineTranslateDto.CMD_ADD_PARKING_AREA_TEXT,
+                DEFAULT_MACHINE_CODE,
+                DEFAULT_MACHINE_ID,
+                "extPaId",
+                "textId",
+                MachineTranslateDto.TYPE_PARKING_AREA);
+        ResponseEntity<String> responseEntity = null;
+        String url = IotConstant.getUrl(IotConstant.DELETE_PARKING_BOX_URL);
+        try {
+            postParameters.put("taskId", machineTranslateDto.getMachineTranslateId());
+            HttpEntity httpEntity = new HttpEntity(postParameters.toJSONString(), getHeaders());
+            responseEntity = outRestTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
+
+            logger.debug("调用HC IOT信息:" + responseEntity);
+
+            if (responseEntity.getStatusCode() != HttpStatus.OK) {
+                machineTranslateDto.setState(MachineTranslateDto.STATE_ERROR);
+                machineTranslateDto.setRemark(responseEntity.getBody());
+                saveTranslateError(machineTranslateDto, postParameters.toJSONString(), responseEntity != null ? responseEntity.getBody() : "", url);
+                return;
+            }
+            JSONObject tokenObj = JSONObject.parseObject(responseEntity.getBody());
+
+            if (!tokenObj.containsKey("code") || ResultVo.CODE_OK != tokenObj.getInteger("code")) {
+                machineTranslateDto.setState(MachineTranslateDto.STATE_ERROR);
+                machineTranslateDto.setRemark(tokenObj.getString("msg"));
+                //保存 失败报文
+                saveTranslateError(machineTranslateDto, postParameters.toJSONString(), responseEntity != null ? responseEntity.getBody() : "", url);
+
+                return;
+            }
+        } catch (Exception e) {
+            machineTranslateDto.setState(MachineTranslateDto.STATE_ERROR);
+            machineTranslateDto.setRemark(e.getLocalizedMessage());
+            //保存 失败报文
+            saveTranslateError(machineTranslateDto, postParameters.toJSONString(), responseEntity != null ? responseEntity.getBody() : "", url);
+
+            return;
+        } finally {
+            saveTranslateLog(machineTranslateDto);
+            refreshAccessToken(responseEntity);
+        }
+    }
+
     @Override
     @Async
     public void updateAttendance(JSONObject postParameters) {

+ 121 - 0
service-job/src/main/java/com/java110/job/adapt/hcIot/parkingBox/AddParkingBoxToIotAdapt.java

@@ -0,0 +1,121 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.job.adapt.hcIot.parkingBox;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.dto.parkingBox.ParkingBoxDto;
+import com.java110.dto.parkingBoxArea.ParkingBoxAreaDto;
+import com.java110.entity.order.Business;
+import com.java110.intf.community.IParkingBoxAreaV1InnerServiceSMO;
+import com.java110.intf.community.IParkingBoxV1InnerServiceSMO;
+import com.java110.intf.user.IOwnerInnerServiceSMO;
+import com.java110.job.adapt.DatabusAdaptImpl;
+import com.java110.job.adapt.hcIot.asyn.IIotSendAsyn;
+import com.java110.po.parkingBox.ParkingBoxPo;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * HC iot 停车场同步适配器
+ * <p>
+ * 接口协议地址: https://gitee.com/java110/MicroCommunityThings/blob/master/back/docs/api.md
+ *
+ * @desc add by 吴学文 18:58
+ */
+@Component(value = "addParkingBoxToIotAdapt")
+public class AddParkingBoxToIotAdapt extends DatabusAdaptImpl {
+
+    @Autowired
+    private IIotSendAsyn hcParkingBoxAsynImpl;
+
+
+    @Autowired
+    private IParkingBoxV1InnerServiceSMO parkingBoxInnerServiceSMOImpl;
+
+    @Autowired
+    private IParkingBoxAreaV1InnerServiceSMO parkingBoxAreaInnerServiceSMOImpl;
+
+
+    @Autowired
+    private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
+
+
+    /**
+     * accessToken={access_token}
+     * &extCommunityUuid=01000
+     * &extCommunityId=1
+     * &devSn=111111111
+     * &name=设备名称
+     * &positionType=0
+     * &positionUuid=1
+     *
+     * @param business   当前处理业务
+     * @param businesses 所有业务信息
+     */
+    @Override
+    public void execute(Business business, List<Business> businesses) {
+        JSONObject data = business.getData();
+        if (data.containsKey(ParkingBoxPo.class.getSimpleName())) {
+            Object bObj = data.get(ParkingBoxPo.class.getSimpleName());
+            JSONArray businessParkingBoxs = null;
+            if (bObj instanceof JSONObject) {
+                businessParkingBoxs = new JSONArray();
+                businessParkingBoxs.add(bObj);
+            } else if (bObj instanceof List) {
+                businessParkingBoxs = JSONArray.parseArray(JSONObject.toJSONString(bObj));
+            } else {
+                businessParkingBoxs = (JSONArray) bObj;
+            }
+            //JSONObject businessParkingBox = data.getJSONObject("businessParkingBox");
+            for (int bParkingBoxIndex = 0; bParkingBoxIndex < businessParkingBoxs.size(); bParkingBoxIndex++) {
+                JSONObject businessParkingBox = businessParkingBoxs.getJSONObject(bParkingBoxIndex);
+                doSendParkingBox(business, businessParkingBox);
+            }
+        }
+    }
+
+    private void doSendParkingBox(Business business, JSONObject businessParkingBox) {
+
+        ParkingBoxPo parkingBoxPo = BeanConvertUtil.covertBean(businessParkingBox, ParkingBoxPo.class);
+
+        ParkingBoxDto parkingBoxDto = new ParkingBoxDto();
+        parkingBoxDto.setBoxId(parkingBoxPo.getBoxId());
+        parkingBoxDto.setCommunityId(parkingBoxPo.getCommunityId());
+        List<ParkingBoxDto> parkingBoxDtos = parkingBoxInnerServiceSMOImpl.queryParkingBoxs(parkingBoxDto);
+
+        Assert.listOnlyOne(parkingBoxDtos, "未找到停车场");
+
+        //查询属性
+        ParkingBoxAreaDto parkingBoxAreaDto = new ParkingBoxAreaDto();
+        parkingBoxAreaDto.setBoxId(parkingBoxDtos.get(0).getBoxId());
+        parkingBoxAreaDto.setCommunityId(parkingBoxDtos.get(0).getCommunityId());
+        List<ParkingBoxAreaDto> parkingBoxAreaDtos = parkingBoxAreaInnerServiceSMOImpl.queryParkingBoxAreas(parkingBoxAreaDto);
+
+        JSONObject postParameters = new JSONObject();
+
+        postParameters.putAll(BeanConvertUtil.beanCovertMap(parkingBoxDtos.get(0)));
+        postParameters.put("extBoxId",parkingBoxPo.getBoxId());
+        postParameters.put("extPaId", parkingBoxDtos.get(0).getPaId());
+        postParameters.put("extCommunityId", parkingBoxDtos.get(0).getCommunityId());
+        postParameters.put("areas", parkingBoxAreaDtos);
+        hcParkingBoxAsynImpl.addParkingBox(postParameters);
+    }
+}

+ 114 - 0
service-job/src/main/java/com/java110/job/adapt/hcIot/parkingBox/DeleteParkingBoxToIotAdapt.java

@@ -0,0 +1,114 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.job.adapt.hcIot.parkingBox;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.dto.parkingBox.ParkingBoxDto;
+import com.java110.dto.parkingBoxArea.ParkingBoxAreaDto;
+import com.java110.entity.order.Business;
+import com.java110.intf.community.IParkingBoxAreaV1InnerServiceSMO;
+import com.java110.intf.community.IParkingBoxV1InnerServiceSMO;
+import com.java110.intf.user.IOwnerInnerServiceSMO;
+import com.java110.job.adapt.DatabusAdaptImpl;
+import com.java110.job.adapt.hcIot.asyn.IIotSendAsyn;
+import com.java110.po.parkingBox.ParkingBoxPo;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * HC iot 停车场同步适配器
+ * <p>
+ * 接口协议地址: https://gitee.com/java110/MicroCommunityThings/blob/master/back/docs/api.md
+ *
+ * @desc add by 吴学文 18:58
+ */
+@Component(value = "deleteParkingBoxToIotAdapt")
+public class DeleteParkingBoxToIotAdapt extends DatabusAdaptImpl {
+
+    @Autowired
+    private IIotSendAsyn hcParkingBoxAsynImpl;
+
+
+    @Autowired
+    private IParkingBoxV1InnerServiceSMO parkingBoxInnerServiceSMOImpl;
+
+    @Autowired
+    private IParkingBoxAreaV1InnerServiceSMO parkingBoxAreaInnerServiceSMOImpl;
+
+
+    @Autowired
+    private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
+
+
+    /**
+     * accessToken={access_token}
+     * &extCommunityUuid=01000
+     * &extCommunityId=1
+     * &devSn=111111111
+     * &name=设备名称
+     * &positionType=0
+     * &positionUuid=1
+     *
+     * @param business   当前处理业务
+     * @param businesses 所有业务信息
+     */
+    @Override
+    public void execute(Business business, List<Business> businesses) {
+        JSONObject data = business.getData();
+        if (data.containsKey(ParkingBoxPo.class.getSimpleName())) {
+            Object bObj = data.get(ParkingBoxPo.class.getSimpleName());
+            JSONArray businessParkingBoxs = null;
+            if (bObj instanceof JSONObject) {
+                businessParkingBoxs = new JSONArray();
+                businessParkingBoxs.add(bObj);
+            } else if (bObj instanceof List) {
+                businessParkingBoxs = JSONArray.parseArray(JSONObject.toJSONString(bObj));
+            } else {
+                businessParkingBoxs = (JSONArray) bObj;
+            }
+            //JSONObject businessParkingBox = data.getJSONObject("businessParkingBox");
+            for (int bParkingBoxIndex = 0; bParkingBoxIndex < businessParkingBoxs.size(); bParkingBoxIndex++) {
+                JSONObject businessParkingBox = businessParkingBoxs.getJSONObject(bParkingBoxIndex);
+                doSendParkingBox(business, businessParkingBox);
+            }
+        }
+    }
+
+    private void doSendParkingBox(Business business, JSONObject businessParkingBox) {
+
+        ParkingBoxPo parkingBoxPo = BeanConvertUtil.covertBean(businessParkingBox, ParkingBoxPo.class);
+
+        ParkingBoxDto parkingBoxDto = new ParkingBoxDto();
+        parkingBoxDto.setBoxId(parkingBoxPo.getBoxId());
+        parkingBoxDto.setCommunityId(parkingBoxPo.getCommunityId());
+        List<ParkingBoxDto> parkingBoxDtos = parkingBoxInnerServiceSMOImpl.queryParkingBoxs(parkingBoxDto);
+
+        Assert.listOnlyOne(parkingBoxDtos, "未找到停车场");
+
+        JSONObject postParameters = new JSONObject();
+
+        postParameters.putAll(BeanConvertUtil.beanCovertMap(parkingBoxDtos.get(0)));
+        postParameters.put("extPaId", parkingBoxDtos.get(0).getPaId());
+        postParameters.put("extBoxId",parkingBoxPo.getBoxId());
+        postParameters.put("extCommunityId", parkingBoxDtos.get(0).getCommunityId());
+        hcParkingBoxAsynImpl.deleteParkingBox(postParameters);
+    }
+}

+ 121 - 0
service-job/src/main/java/com/java110/job/adapt/hcIot/parkingBox/ModifyParkingBoxToIotAdapt.java

@@ -0,0 +1,121 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.job.adapt.hcIot.parkingBox;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.dto.parkingBox.ParkingBoxDto;
+import com.java110.dto.parkingBoxArea.ParkingBoxAreaDto;
+import com.java110.entity.order.Business;
+import com.java110.intf.community.IParkingBoxAreaV1InnerServiceSMO;
+import com.java110.intf.community.IParkingBoxV1InnerServiceSMO;
+import com.java110.intf.user.IOwnerInnerServiceSMO;
+import com.java110.job.adapt.DatabusAdaptImpl;
+import com.java110.job.adapt.hcIot.asyn.IIotSendAsyn;
+import com.java110.po.parkingBox.ParkingBoxPo;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * HC iot 停车场同步适配器
+ * <p>
+ * 接口协议地址: https://gitee.com/java110/MicroCommunityThings/blob/master/back/docs/api.md
+ *
+ * @desc add by 吴学文 18:58
+ */
+@Component(value = "modifyParkingBoxToIotAdapt")
+public class ModifyParkingBoxToIotAdapt extends DatabusAdaptImpl {
+
+    @Autowired
+    private IIotSendAsyn hcParkingBoxAsynImpl;
+
+
+    @Autowired
+    private IParkingBoxV1InnerServiceSMO parkingBoxInnerServiceSMOImpl;
+
+    @Autowired
+    private IParkingBoxAreaV1InnerServiceSMO parkingBoxAreaInnerServiceSMOImpl;
+
+
+    @Autowired
+    private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
+
+
+    /**
+     * accessToken={access_token}
+     * &extCommunityUuid=01000
+     * &extCommunityId=1
+     * &devSn=111111111
+     * &name=设备名称
+     * &positionType=0
+     * &positionUuid=1
+     *
+     * @param business   当前处理业务
+     * @param businesses 所有业务信息
+     */
+    @Override
+    public void execute(Business business, List<Business> businesses) {
+        JSONObject data = business.getData();
+        if (data.containsKey(ParkingBoxPo.class.getSimpleName())) {
+            Object bObj = data.get(ParkingBoxPo.class.getSimpleName());
+            JSONArray businessParkingBoxs = null;
+            if (bObj instanceof JSONObject) {
+                businessParkingBoxs = new JSONArray();
+                businessParkingBoxs.add(bObj);
+            } else if (bObj instanceof List) {
+                businessParkingBoxs = JSONArray.parseArray(JSONObject.toJSONString(bObj));
+            } else {
+                businessParkingBoxs = (JSONArray) bObj;
+            }
+            //JSONObject businessParkingBox = data.getJSONObject("businessParkingBox");
+            for (int bParkingBoxIndex = 0; bParkingBoxIndex < businessParkingBoxs.size(); bParkingBoxIndex++) {
+                JSONObject businessParkingBox = businessParkingBoxs.getJSONObject(bParkingBoxIndex);
+                doSendParkingBox(business, businessParkingBox);
+            }
+        }
+    }
+
+    private void doSendParkingBox(Business business, JSONObject businessParkingBox) {
+
+        ParkingBoxPo parkingBoxPo = BeanConvertUtil.covertBean(businessParkingBox, ParkingBoxPo.class);
+
+        ParkingBoxDto parkingBoxDto = new ParkingBoxDto();
+        parkingBoxDto.setBoxId(parkingBoxPo.getBoxId());
+        parkingBoxDto.setCommunityId(parkingBoxPo.getCommunityId());
+        List<ParkingBoxDto> parkingBoxDtos = parkingBoxInnerServiceSMOImpl.queryParkingBoxs(parkingBoxDto);
+
+        Assert.listOnlyOne(parkingBoxDtos, "未找到停车场");
+
+        //查询属性
+        ParkingBoxAreaDto parkingBoxAreaDto = new ParkingBoxAreaDto();
+        parkingBoxAreaDto.setBoxId(parkingBoxDtos.get(0).getBoxId());
+        parkingBoxAreaDto.setCommunityId(parkingBoxDtos.get(0).getCommunityId());
+        List<ParkingBoxAreaDto> parkingBoxAreaDtos = parkingBoxAreaInnerServiceSMOImpl.queryParkingBoxAreas(parkingBoxAreaDto);
+
+        JSONObject postParameters = new JSONObject();
+
+        postParameters.putAll(BeanConvertUtil.beanCovertMap(parkingBoxDtos.get(0)));
+        postParameters.put("extBoxId",parkingBoxPo.getBoxId());
+        postParameters.put("extPaId", parkingBoxDtos.get(0).getPaId());
+        postParameters.put("extCommunityId", parkingBoxDtos.get(0).getCommunityId());
+        postParameters.put("areas", parkingBoxAreaDtos);
+        hcParkingBoxAsynImpl.addParkingBox(postParameters);
+    }
+}