ソースを参照

优化添加删除员工时判断是否有 考勤 如果有考勤信息同步iot 进行考勤

java110 5 年 前
コミット
bfc8358adf

+ 3 - 3
java110-core/src/main/java/com/java110/core/client/OssUploadTemplate.java

@@ -92,7 +92,7 @@ public class OssUploadTemplate {
             ossClient = OSSUtil.getOSSClient();
             fileName = UUID.randomUUID().toString() + "." + uploadFile.getOriginalFilename().substring(uploadFile.getOriginalFilename().lastIndexOf(".") + 1);
             is = uploadFile.getInputStream();
-            OSSUtil.uploadByInputStream(ossClient, is, "java110", ftpPath);
+            OSSUtil.uploadByInputStream(ossClient, is, ftpPath);
         } catch (Exception e) {
             // logger.error("上传文件失败", e);
             throw new IllegalArgumentException("上传文件失败");
@@ -119,7 +119,7 @@ public class OssUploadTemplate {
         ByteArrayInputStream fis = null;
         try {
             ossClient = OSSUtil.getOSSClient();
-            OSSUtil.getInputStreamByOSS(ossClient, "java110", remotePath + fileName);
+            OSSUtil.getInputStreamByOSS(ossClient, remotePath + fileName);
             byteOut = new ByteArrayOutputStream();
             byte[] buf = new byte[2048];
             int bufsize = 0;
@@ -185,7 +185,7 @@ public class OssUploadTemplate {
         ByteArrayInputStream fis = null;
         try {
             ossClient = OSSUtil.getOSSClient();
-            is = OSSUtil.getInputStreamByOSS(ossClient, "java110", remotePath + fileName);
+            is = OSSUtil.getInputStreamByOSS(ossClient,  remotePath + fileName);
             if (null == is) {
                 throw new FileNotFoundException(remotePath);
             }

+ 32 - 0
java110-utils/src/main/java/com/java110/utils/util/OSSUtil.java

@@ -21,6 +21,7 @@ public class OSSUtil {
     public static final String ENDPOINT = "endpoint";
     public static final String ACCESS_KEY_ID = "accessKeyId";
     public static final String ACCESS_KEY_SECRET = "accessKeySecret";
+    public static final String BUCKET_NAME = "bucketName";
 
     /**
      * @return OSSClient oss客户端
@@ -61,6 +62,22 @@ public class OSSUtil {
         }
     }
 
+    /**
+     * @param ossClient   oss客户端
+     * @param inputStream 输入流
+     * @param objectName  上传文件目录和(包括文件名) 例如“test/a.jpg”
+     * @return void        返回类型
+     * @throws
+     * @Title: uploadByInputStream
+     * @Description: 通过输入流上传文件
+     */
+    public static void uploadByInputStream(OSSClient ossClient, InputStream inputStream,
+                                           String objectName) {
+
+        String bucketName = MappingCache.getValue(DOMAIN, BUCKET_NAME);
+        uploadByInputStream(ossClient, inputStream, bucketName, objectName);
+    }
+
     /**
      * @param ossClient   oss客户端
      * @param inputStream 输入流
@@ -120,6 +137,21 @@ public class OSSUtil {
         ossClient.deleteObject(bucketName, key);
     }
 
+    /**
+     * @param ossClient oss客户端
+     * @param key       文件路径和名称
+     * @return InputStream    文件输入流
+     * @throws
+     * @Title: getInputStreamByOSS
+     * @Description:根据key获取服务器上的文件的输入流
+     */
+    public static InputStream getInputStreamByOSS(OSSClient ossClient, String key) {
+        String bucketName = MappingCache.getValue(DOMAIN, BUCKET_NAME);
+        return getInputStreamByOSS(ossClient,bucketName,key);
+
+    }
+
+
     /**
      * @param ossClient  oss客户端
      * @param bucketName bucket名称

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

@@ -87,6 +87,10 @@ public class IotConstant {
     //添加考勤班次
     public static final String ADD_ATTENDANCE_CLASSES_STAFFS = "/extApi/attendance/addAttendanceClassStaffs";
 
+
+    //删除考勤班次
+    public static final String DELETE_ATTENDANCE_CLASSES_STAFFS = "/extApi/attendance/deleteAttendanceClassStaff";
+
     //添加考勤班次
     public static final String ADD_ATTENDANCE_CLASSES = "/extApi/attendance/addAttendanceClass";
     //修改考勤班次

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

@@ -138,6 +138,13 @@ public interface IIotSendAsyn {
      */
     void addAttendance(JSONObject postParameters, List<JSONObject> staffs);
 
+    /**
+     * 考勤员工同步
+     * @param postParameters
+     * @param staffs
+     */
+    void addAttendanceStaff(JSONObject postParameters, List<JSONObject> staffs);
+
     /**
      * 编辑考勤 同步
      * @param postParameters
@@ -149,4 +156,6 @@ public interface IIotSendAsyn {
      * @param postParameters
      */
     void deleteAttendance(JSONObject postParameters);
+
+    void deleteAttendanceStaff(JSONObject postParameters);
 }

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

@@ -1108,6 +1108,105 @@ public class IotSendAsynImpl implements IIotSendAsyn {
         }
     }
 
+    @Override
+    public void addAttendanceStaff(JSONObject postParameters, List<JSONObject> staffs) {
+        MachineTranslateDto machineTranslateDto = getMachineTranslateDto(postParameters,
+                MachineTranslateDto.CMD_ADD_ATTENDANCE_CLASSES,
+                DEFAULT_MACHINE_CODE,
+                DEFAULT_MACHINE_ID,
+                "extClassesId",
+                "classesName",
+                MachineTranslateDto.TYPE_ATTENDANCE);
+        ResponseEntity<String> responseEntity = null;
+        String url = IotConstant.getUrl(IotConstant.ADD_ATTENDANCE_CLASSES_STAFFS);
+        try {
+            for (JSONObject staff : staffs) {
+                staff.put("taskId", machineTranslateDto.getMachineTranslateId());
+            }
+            HttpEntity httpEntity = new HttpEntity(JSONArray.toJSONString(staffs), 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 deleteAttendanceStaff(JSONObject postParameters) {
+        MachineTranslateDto machineTranslateDto = getMachineTranslateDto(postParameters,
+                MachineTranslateDto.CMD_DELETE_ATTENDANCE_CLASSES,
+                DEFAULT_MACHINE_CODE,
+                DEFAULT_MACHINE_ID,
+                "extClassesId",
+                "classesName",
+                MachineTranslateDto.TYPE_ATTENDANCE);
+        ResponseEntity<String> responseEntity = null;
+        String url = IotConstant.getUrl(IotConstant.DELETE_ATTENDANCE_CLASSES_STAFFS);
+        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 updateAttendance(JSONObject postParameters) {
         MachineTranslateDto machineTranslateDto = getMachineTranslateDto(postParameters,

+ 1 - 0
service-job/src/main/java/com/java110/job/adapt/hcIot/machine/AddMachineToIotAdapt.java

@@ -238,6 +238,7 @@ public class AddMachineToIotAdapt extends DatabusAdaptImpl {
             postParameters.put("machineCode", machinePo.getMachineCode());
             postParameters.put("extMachineId", machinePo.getMachineId());
             postParameters.put("extCommunityId", machinePo.getCommunityId());
+            postParameters.put("attrs",tOwnerDto.getOwnerAttrDtos());
             ownerDtos.add(postParameters);
         }
 

+ 14 - 0
service-job/src/main/java/com/java110/job/adapt/hcIot/owner/AddOwnerToIotAdapt.java

@@ -21,11 +21,13 @@ import com.java110.dto.RoomDto;
 import com.java110.dto.file.FileDto;
 import com.java110.dto.file.FileRelDto;
 import com.java110.dto.machine.MachineDto;
+import com.java110.dto.owner.OwnerDto;
 import com.java110.entity.order.Business;
 import com.java110.intf.common.IFileInnerServiceSMO;
 import com.java110.intf.common.IFileRelInnerServiceSMO;
 import com.java110.intf.common.IMachineInnerServiceSMO;
 import com.java110.intf.community.IRoomInnerServiceSMO;
+import com.java110.intf.user.IOwnerInnerServiceSMO;
 import com.java110.job.adapt.DatabusAdaptImpl;
 import com.java110.job.adapt.hcIot.asyn.IIotSendAsyn;
 import com.java110.po.owner.OwnerPo;
@@ -56,12 +58,17 @@ public class AddOwnerToIotAdapt extends DatabusAdaptImpl {
     @Autowired
     private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
 
+    @Autowired
+    private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
+
     @Autowired
     private IFileRelInnerServiceSMO fileRelInnerServiceSMOImpl;
 
     @Autowired
     private IFileInnerServiceSMO fileInnerServiceSMOImpl;
 
+
+
     /**
      * accessToken={access_token}
      * &extCommunityUuid=01000
@@ -114,6 +121,12 @@ public class AddOwnerToIotAdapt extends DatabusAdaptImpl {
         if (fileDtos == null || fileDtos.size() != 1) {
             return;
         }
+        OwnerDto ownerDto = new OwnerDto();
+        ownerDto.setMemberId(ownerPo.getMemberId());
+        ownerDto.setCommunityId(ownerPo.getCommunityId());
+        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwnerMembers(ownerDto);
+
+        Assert.listOnlyOne(ownerDtos,"业主不存在");
 
         RoomDto roomDto = new RoomDto();
         roomDto.setOwnerId(ownerPo.getOwnerId());
@@ -151,6 +164,7 @@ public class AddOwnerToIotAdapt extends DatabusAdaptImpl {
             postParameters.put("machineCode", tmpMachineDto.getMachineCode());
             postParameters.put("extMachineId", tmpMachineDto.getMachineId());
             postParameters.put("extCommunityId", tmpMachineDto.getCommunityId());
+            postParameters.put("attrs",ownerDtos.get(0).getOwnerAttrDtos());
             hcMachineAsynImpl.addOwner(postParameters);
         }
 

+ 12 - 0
service-job/src/main/java/com/java110/job/adapt/hcIot/owner/EditOwnerToIotAdapt.java

@@ -21,11 +21,13 @@ import com.java110.dto.RoomDto;
 import com.java110.dto.file.FileDto;
 import com.java110.dto.file.FileRelDto;
 import com.java110.dto.machine.MachineDto;
+import com.java110.dto.owner.OwnerDto;
 import com.java110.entity.order.Business;
 import com.java110.intf.common.IFileInnerServiceSMO;
 import com.java110.intf.common.IFileRelInnerServiceSMO;
 import com.java110.intf.common.IMachineInnerServiceSMO;
 import com.java110.intf.community.IRoomInnerServiceSMO;
+import com.java110.intf.user.IOwnerInnerServiceSMO;
 import com.java110.job.adapt.DatabusAdaptImpl;
 import com.java110.job.adapt.hcIot.asyn.IIotSendAsyn;
 import com.java110.po.owner.OwnerPo;
@@ -64,6 +66,9 @@ public class EditOwnerToIotAdapt extends DatabusAdaptImpl {
     @Autowired
     private IFileInnerServiceSMO fileInnerServiceSMOImpl;
 
+    @Autowired
+    private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
+
     /**
      * accessToken={access_token}
      * &extCommunityUuid=01000
@@ -122,6 +127,12 @@ public class EditOwnerToIotAdapt extends DatabusAdaptImpl {
         //这种情况说明 业主已经删掉了 需要查询状态为 1 的数据
         List<RoomDto> rooms = roomInnerServiceSMOImpl.queryRoomsByOwner(roomDto);
 
+        OwnerDto ownerDto = new OwnerDto();
+        ownerDto.setMemberId(ownerPo.getMemberId());
+        ownerDto.setCommunityId(ownerPo.getCommunityId());
+        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwnerMembers(ownerDto);
+        Assert.listOnlyOne(ownerDtos,"业主不存在");
+
         //拿到小区ID
         String communityId = ownerPo.getCommunityId();
         //根据小区ID查询现有设备
@@ -152,6 +163,7 @@ public class EditOwnerToIotAdapt extends DatabusAdaptImpl {
             postParameters.put("machineCode", tmpMachineDto.getMachineCode());
             postParameters.put("extMachineId", tmpMachineDto.getMachineId());
             postParameters.put("extCommunityId", tmpMachineDto.getCommunityId());
+            postParameters.put("attrs",ownerDtos.get(0).getOwnerAttrDtos());
             hcMachineAsynImpl.sendUpdateOwner(postParameters);
         }
 

+ 130 - 0
service-job/src/main/java/com/java110/job/adapt/hcIot/staff/AddStaffToIotAdapt.java

@@ -0,0 +1,130 @@
+/*
+ * 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.staff;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.dto.attendanceClasses.AttendanceClassesDto;
+import com.java110.dto.org.OrgStaffRelDto;
+import com.java110.dto.store.StoreUserDto;
+import com.java110.entity.order.Business;
+import com.java110.intf.common.IAttendanceClassesInnerServiceSMO;
+import com.java110.intf.user.IOrgStaffRelInnerServiceSMO;
+import com.java110.job.adapt.DatabusAdaptImpl;
+import com.java110.job.adapt.hcIot.asyn.IIotSendAsyn;
+import com.java110.po.store.StoreUserPo;
+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.ArrayList;
+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 = "addStaffToIotAdapt")
+public class AddStaffToIotAdapt extends DatabusAdaptImpl {
+
+    @Autowired
+    private IIotSendAsyn hcStoreUserAsynImpl;
+
+    @Autowired
+    private IOrgStaffRelInnerServiceSMO orgStaffRelInnerServiceSMOImpl;
+
+    @Autowired
+    private IAttendanceClassesInnerServiceSMO attendanceClassesInnerServiceSMOImpl;
+
+
+    /**
+     * 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(StoreUserPo.class.getSimpleName())) {
+            Object bObj = data.get(StoreUserPo.class.getSimpleName());
+            JSONArray businessStoreUsers = null;
+            if (bObj instanceof JSONObject) {
+                businessStoreUsers = new JSONArray();
+                businessStoreUsers.add(bObj);
+            } else if (bObj instanceof List) {
+                businessStoreUsers = JSONArray.parseArray(JSONObject.toJSONString(bObj));
+            } else {
+                businessStoreUsers = (JSONArray) bObj;
+            }
+            //JSONObject businessStoreUser = data.getJSONObject("businessStoreUser");
+            for (int bStoreUserIndex = 0; bStoreUserIndex < businessStoreUsers.size(); bStoreUserIndex++) {
+                JSONObject businessStoreUser = businessStoreUsers.getJSONObject(bStoreUserIndex);
+                doSendStoreUser(business, businessStoreUser);
+            }
+        }
+    }
+
+    private void doSendStoreUser(Business business, JSONObject businessStoreUser) {
+
+        StoreUserPo storeUserPo = BeanConvertUtil.covertBean(businessStoreUser, StoreUserPo.class);
+
+        //查询员工部门
+        OrgStaffRelDto orgStaffRelDto = new OrgStaffRelDto();
+        orgStaffRelDto.setStaffId(storeUserPo.getUserId());
+        orgStaffRelDto.setStoreId(storeUserPo.getStoreId());
+        List<OrgStaffRelDto> orgStaffRelDtos = orgStaffRelInnerServiceSMOImpl.queryOrgStaffRels(orgStaffRelDto);
+
+        Assert.listOnlyOne(orgStaffRelDtos, "未包含员工信息");
+
+        //查询员工部门是否参与考勤
+        AttendanceClassesDto attendanceClassesDto = new AttendanceClassesDto();
+        attendanceClassesDto.setClassesObjType(AttendanceClassesDto.CLASSES_OBJ_TYPE_PARTMENT);
+        attendanceClassesDto.setClassesObjId(orgStaffRelDtos.get(0).getDepartmentId());
+        List<AttendanceClassesDto> attendanceClassesDtos = attendanceClassesInnerServiceSMOImpl.queryAttendanceClassess(attendanceClassesDto);
+
+        //员工部门没有考勤,不用处理
+        if (attendanceClassesDtos == null || attendanceClassesDtos.size() < 1) {
+            return;
+        }
+        JSONObject storeUserObj = null;
+        List<JSONObject> storeUserObjs = new ArrayList<>();
+        for(AttendanceClassesDto tmpAttendanceClassesDto : attendanceClassesDtos ){
+            storeUserObj = new JSONObject();
+            storeUserObj.put("extClassesId", tmpAttendanceClassesDto.getClassesId());
+            storeUserObj.put("extStaffId", orgStaffRelDtos.get(0).getStaffId());
+            storeUserObj.put("StaffName", orgStaffRelDtos.get(0).getStaffName());
+            storeUserObj.put("departmentId", orgStaffRelDtos.get(0).getDepartmentId());
+            storeUserObj.put("departmentName", orgStaffRelDtos.get(0).getDepartmentName());
+            storeUserObjs.add(storeUserObj);
+        }
+        JSONObject postParameters = new JSONObject();
+        postParameters.put("classesName", attendanceClassesDtos.get(0).getClassesName());
+        postParameters.put("extClassesId", attendanceClassesDtos.get(0).getClassesId());
+        postParameters.put("extCommunityId", "-1");
+        hcStoreUserAsynImpl.addAttendanceStaff(postParameters, storeUserObjs);
+    }
+}

+ 126 - 0
service-job/src/main/java/com/java110/job/adapt/hcIot/staff/DeleteStaffToIotAdapt.java

@@ -0,0 +1,126 @@
+/*
+ * 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.staff;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.dto.attendanceClasses.AttendanceClassesDto;
+import com.java110.dto.org.OrgStaffRelDto;
+import com.java110.entity.order.Business;
+import com.java110.intf.common.IAttendanceClassesInnerServiceSMO;
+import com.java110.intf.user.IOrgStaffRelInnerServiceSMO;
+import com.java110.job.adapt.DatabusAdaptImpl;
+import com.java110.job.adapt.hcIot.asyn.IIotSendAsyn;
+import com.java110.po.attendanceClasses.AttendanceClassesPo;
+import com.java110.po.store.StoreUserPo;
+import com.java110.utils.constant.StatusConstant;
+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.ArrayList;
+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 = "deleteStaffToIotAdapt")
+public class DeleteStaffToIotAdapt extends DatabusAdaptImpl {
+
+    @Autowired
+    private IIotSendAsyn hcStoreUserAsynImpl;
+
+
+    @Autowired
+    private IAttendanceClassesInnerServiceSMO attendanceClassesInnerServiceSMOImpl;
+
+    @Autowired
+    private IOrgStaffRelInnerServiceSMO orgStaffRelInnerServiceSMOImpl;
+
+
+    /**
+     * 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(StoreUserPo.class.getSimpleName())) {
+            Object bObj = data.get(StoreUserPo.class.getSimpleName());
+            JSONArray businessOwnerAttendances = null;
+            if (bObj instanceof JSONObject) {
+                businessOwnerAttendances = new JSONArray();
+                businessOwnerAttendances.add(bObj);
+            } else if (bObj instanceof List) {
+                businessOwnerAttendances = JSONArray.parseArray(JSONObject.toJSONString(bObj));
+            } else {
+                businessOwnerAttendances = (JSONArray) bObj;
+            }
+            //JSONObject businessOwnerAttendance = data.getJSONObject("businessOwnerAttendance");
+            for (int bOwnerAttendanceIndex = 0; bOwnerAttendanceIndex < businessOwnerAttendances.size(); bOwnerAttendanceIndex++) {
+                JSONObject businessOwnerAttendance = businessOwnerAttendances.getJSONObject(bOwnerAttendanceIndex);
+                doSendOwnerAttendance(business, businessOwnerAttendance);
+            }
+        }
+    }
+
+    private void doSendOwnerAttendance(Business business, JSONObject businessStoreUser) {
+
+        StoreUserPo storeUserPo = BeanConvertUtil.covertBean(businessStoreUser, StoreUserPo.class);
+
+        //查询员工部门
+        OrgStaffRelDto orgStaffRelDto = new OrgStaffRelDto();
+        orgStaffRelDto.setStaffId(storeUserPo.getUserId());
+        orgStaffRelDto.setStoreId(storeUserPo.getStoreId());
+        List<OrgStaffRelDto> orgStaffRelDtos = orgStaffRelInnerServiceSMOImpl.queryOrgStaffRels(orgStaffRelDto);
+
+        Assert.listOnlyOne(orgStaffRelDtos, "未包含员工信息");
+
+        //查询员工部门是否参与考勤
+        AttendanceClassesDto attendanceClassesDto = new AttendanceClassesDto();
+        attendanceClassesDto.setClassesObjType(AttendanceClassesDto.CLASSES_OBJ_TYPE_PARTMENT);
+        attendanceClassesDto.setClassesObjId(orgStaffRelDtos.get(0).getDepartmentId());
+        List<AttendanceClassesDto> attendanceClassesDtos = attendanceClassesInnerServiceSMOImpl.queryAttendanceClassess(attendanceClassesDto);
+
+        //员工部门没有考勤,不用处理
+        if (attendanceClassesDtos == null || attendanceClassesDtos.size() < 1) {
+            return;
+        }
+
+        for(AttendanceClassesDto tmpAttendanceClassesDto : attendanceClassesDtos ){
+            JSONObject postParameters = new JSONObject();
+            postParameters.put("classesName", tmpAttendanceClassesDto.getClassesName());
+            postParameters.put("extClassesId", tmpAttendanceClassesDto.getClassesId());
+            postParameters.put("extStaffId", orgStaffRelDtos.get(0).getStaffId());
+            postParameters.put("extCommunityId", "-1");
+            hcStoreUserAsynImpl.deleteAttendanceStaff(postParameters);
+        }
+
+    }
+}

+ 113 - 0
service-job/src/main/java/com/java110/job/adapt/hcIot/staff/UpdateStaffToIotAdapt.java

@@ -0,0 +1,113 @@
+/*
+ * 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.staff;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.dto.attendanceClasses.AttendanceClassesDto;
+import com.java110.entity.order.Business;
+import com.java110.intf.common.IAttendanceClassesInnerServiceSMO;
+import com.java110.intf.user.IOrgStaffRelInnerServiceSMO;
+import com.java110.job.adapt.DatabusAdaptImpl;
+import com.java110.job.adapt.hcIot.asyn.IIotSendAsyn;
+import com.java110.po.attendanceClasses.AttendanceClassesPo;
+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 = "updateStaffToIotAdapt")
+public class UpdateStaffToIotAdapt extends DatabusAdaptImpl {
+
+    @Autowired
+    private IIotSendAsyn hcOwnerAttendanceAsynImpl;
+
+
+    @Autowired
+    private IAttendanceClassesInnerServiceSMO attendanceClassesInnerServiceSMOImpl;
+
+    @Autowired
+    private IOrgStaffRelInnerServiceSMO orgStaffRelInnerServiceSMOImpl;
+
+
+    /**
+     * 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(AttendanceClassesPo.class.getSimpleName())) {
+            Object bObj = data.get(AttendanceClassesPo.class.getSimpleName());
+            JSONArray businessOwnerAttendances = null;
+            if (bObj instanceof JSONObject) {
+                businessOwnerAttendances = new JSONArray();
+                businessOwnerAttendances.add(bObj);
+            } else if (bObj instanceof List) {
+                businessOwnerAttendances = JSONArray.parseArray(JSONObject.toJSONString(bObj));
+            } else {
+                businessOwnerAttendances = (JSONArray) bObj;
+            }
+            //JSONObject businessOwnerAttendance = data.getJSONObject("businessOwnerAttendance");
+            for (int bOwnerAttendanceIndex = 0; bOwnerAttendanceIndex < businessOwnerAttendances.size(); bOwnerAttendanceIndex++) {
+                JSONObject businessOwnerAttendance = businessOwnerAttendances.getJSONObject(bOwnerAttendanceIndex);
+                doSendOwnerAttendance(business, businessOwnerAttendance);
+            }
+        }
+    }
+
+    private void doSendOwnerAttendance(Business business, JSONObject businessOwnerAttendance) {
+
+        AttendanceClassesPo ownerAttendancePo = BeanConvertUtil.covertBean(businessOwnerAttendance, AttendanceClassesPo.class);
+
+        AttendanceClassesDto ownerAttendanceDto = new AttendanceClassesDto();
+        ownerAttendanceDto.setClassesId(ownerAttendancePo.getClassesId());
+        ownerAttendanceDto.setStoreId(ownerAttendancePo.getStoreId());
+        List<AttendanceClassesDto> attendanceDtos = attendanceClassesInnerServiceSMOImpl.queryAttendanceClassess(ownerAttendanceDto);
+
+        Assert.listOnlyOne(attendanceDtos, "未找到考勤班组");
+
+        JSONObject postParameters = new JSONObject();
+        postParameters.put("classesName", attendanceDtos.get(0).getClassesName());
+        postParameters.put("timeOffset", attendanceDtos.get(0).getTimeOffset());
+        postParameters.put("clockCount", attendanceDtos.get(0).getClockCount());
+        postParameters.put("clockType", attendanceDtos.get(0).getClockType());
+        postParameters.put("clockTypeValue", attendanceDtos.get(0).getClockTypeValue());
+        postParameters.put("lateOffset", attendanceDtos.get(0).getLateOffset());
+        postParameters.put("leaveOffset", attendanceDtos.get(0).getLeaveOffset());
+        postParameters.put("extClassesId", attendanceDtos.get(0).getClassesId());
+        postParameters.put("extCommunityId", "-1");
+        postParameters.put("attrs", JSONArray.parseArray(JSONArray.toJSONString(attendanceDtos.get(0).getAttrs())));
+        hcOwnerAttendanceAsynImpl.updateAttendance(postParameters);
+    }
+}