qingwu 5 місяців тому
батько
коміт
a65e0efc07

+ 21 - 4
src/com/kingdee/eas/custom/synctask/SyncTranForIOTFacadeControllerBean.java

@@ -7,9 +7,6 @@ import com.kingdee.bos.Context;
 import com.kingdee.bos.metadata.entity.*;
 import com.kingdee.bos.metadata.query.util.CompareType;
 import com.kingdee.eas.basedata.org.*;
-import com.kingdee.eas.basedata.person.IPerson;
-import com.kingdee.eas.basedata.person.PersonCollection;
-import com.kingdee.eas.basedata.person.PersonFactory;
 import com.kingdee.eas.basedata.person.PersonInfo;
 import com.kingdee.eas.common.EASBizException;
 import com.kingdee.eas.custom.log.ISyncLog;
@@ -19,6 +16,7 @@ import com.kingdee.eas.custom.log.app.DataDirectionEnum;
 import com.kingdee.eas.custom.log.app.DockingSystemEnum;
 import com.kingdee.eas.custom.log.app.SyncEntityNameEnum;
 import com.kingdee.eas.custom.log.app.SyncStatusEnum;
+import com.kingdee.eas.custom.synctask.utils.GeneralUtils;
 import com.kingdee.eas.hr.ats.AtsUtil;
 import com.kingdee.eas.hr.base.EmployeeTypeInfo;
 import com.kingdee.eas.hr.emp.IPersonPosition;
@@ -26,6 +24,7 @@ import com.kingdee.eas.hr.emp.PersonPositionCollection;
 import com.kingdee.eas.hr.emp.PersonPositionFactory;
 import com.kingdee.eas.hr.emp.PersonPositionInfo;
 import com.kingdee.eas.utils.ExpiringMapCache;
+import com.kingdee.util.DateTimeUtils;
 import okhttp3.*;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.log4j.Logger;
@@ -236,6 +235,13 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
                 EmployeeTypeInfo employeeType = person.getEmployeeType();
                 String number = employeeType.getNumber();
                 String personStatus = personStatusMap.get(number);
+                //调用新增接口---禁用系统用户账号 状态等于3属于离职人员
+                if ("3".equals(personStatus)) {
+                    logger.error("personStatus=3" + person.getName());
+                    //调用禁用用户接口
+                    GeneralUtils generalUtils = new GeneralUtils();
+                    generalUtils.disableUserAccount(ctx, person);
+                }
                 personMap.put("status", personStatus);//状态
                 AdminOrgUnitInfo personDep = personPositionInfo.getPersonDep();
                 List orgIds = new ArrayList();
@@ -245,6 +251,11 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
                 //员工编码
                 Map paramsMap = new HashMap();
                 paramsMap.put("employeeNo", person.getNumber());
+                Date hireDate = person.getHireDate();
+                if (hireDate != null) {
+                    String entryDate = DateTimeUtils.format(hireDate, "yyyy-MM-dd");
+                    paramsMap.put("entryDate", entryDate);
+                }
                 personMap.put("params", paramsMap);
                 personMap.put("areaCode", "+86");
             }
@@ -252,7 +263,9 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
             syncLogInfo.setRequestParams(jsonObject.toString());
             //执行同步人员到Iot
             syncLogInfo.setSyncCount(personIds.size());
+            //部署需要替换 syncPerson(ctx, jsonObject.toString(), syncLogInfo);
             return syncPerson(ctx, jsonObject.toString(), syncLogInfo);
+            //return new HashMap();
         } catch (Exception e) {
             e.printStackTrace();
             syncLogInfo.setSyncStatus(SyncStatusEnum.ERROR);
@@ -387,6 +400,8 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
                     .build();
             response = client.newCall(request).execute();
             String string = response.body().string();
+            logger.error("string--" + string);
+            syncLogInfo.setSyncResult(string);
             ObjectMapper objectMapper = new ObjectMapper();
             result = objectMapper.readValue(string, Map.class);
         } catch (IOException e) {
@@ -412,7 +427,7 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
             //syncLogInfo.setSyncCount(total);
             syncLogInfo.setSuccessNum(success);
             syncLogInfo.setFailNum(fail);
-            syncLogInfo.setSyncResult(result.toString());
+
             SyncLogFactory.getLocalInstance(ctx).save(syncLogInfo);
         } else {
             syncLogInfo.setSyncStatus(SyncStatusEnum.ERROR);
@@ -496,4 +511,6 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
         }
         return paramStr.toString();
     }
+
+
 }

+ 0 - 1
src/com/kingdee/eas/custom/synctask/SyncTranForOAFacadeControllerBean.java

@@ -553,7 +553,6 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
                         setPersonIds.add(personPositionInfo.getPerson().getId());
                     }
                 }
-
             }
             ObjectMapper mapper = new ObjectMapper();
             logger.error("_syncpersonToOA------------------dataList----- " + mapper.writeValueAsString(dataList));

+ 128 - 0
src/com/kingdee/eas/custom/synctask/utils/GeneralUtils.java

@@ -0,0 +1,128 @@
+package com.kingdee.eas.custom.synctask.utils;
+
+import com.alibaba.fastjson.JSONObject;
+import com.kingdee.bos.BOSException;
+import com.kingdee.bos.Context;
+import com.kingdee.eas.basedata.person.PersonInfo;
+import com.kingdee.eas.common.EASBizException;
+import com.kingdee.eas.custom.log.ISyncLog;
+import com.kingdee.eas.custom.log.SyncLogFactory;
+import com.kingdee.eas.custom.log.SyncLogInfo;
+import com.kingdee.eas.custom.log.app.DataDirectionEnum;
+import com.kingdee.eas.custom.log.app.SyncEntityNameEnum;
+import com.kingdee.eas.custom.log.app.SyncStatusEnum;
+import com.kingdee.eas.hr.affair.IResignBizBillEntry;
+import com.kingdee.eas.hr.affair.ResignBizBillEntryCollection;
+import com.kingdee.eas.hr.affair.ResignBizBillEntryFactory;
+import com.kingdee.eas.hr.affair.ResignBizBillEntryInfo;
+import okhttp3.*;
+import org.apache.log4j.Logger;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author qingwu
+ * @date 2025/2/26
+ * @apiNote
+ */
+public class GeneralUtils {
+    private Properties propt = new Properties();
+    Logger logger = Logger.getLogger("com.kingdee.eas.custom.synctask.utils.GeneralUtils");
+    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+    public GeneralUtils() throws BOSException {
+        String syncOAConfigPath = System.getProperty("EAS_HOME") + "/server/properties/scy/syncIOTConfig.properties";
+        try {
+            propt.load(new FileInputStream(syncOAConfigPath));
+        } catch (IOException e) {
+            e.printStackTrace();
+            String errorMsg = "获取配置文件报错,请检查配置:" + syncOAConfigPath + "   " + e.getMessage();
+            throw new BOSException(errorMsg);
+        }
+    }
+
+    public void disableUserAccount(Context ctx, PersonInfo personInfo) throws IOException, BOSException, EASBizException {
+        logger.error("disableUserAccount----new");
+        //日志
+        ISyncLog iSyncLog = SyncLogFactory.getLocalInstance(ctx);
+        SyncLogInfo syncLogInfo = new SyncLogInfo();
+        syncLogInfo.setEntityName(SyncEntityNameEnum.person);
+        syncLogInfo.setDataDirection(DataDirectionEnum.outflow);
+        JSONObject param = new JSONObject();//请求参数
+        //员工ID
+        String personId = personInfo.getId().toString();
+        //通过员工id获取离职当分录  预计离职日期  最后工作日  禁用用户日期 用户账号
+        IResignBizBillEntry iResignBizBillEntry = ResignBizBillEntryFactory.getLocalInstance(ctx);
+        ResignBizBillEntryCollection resignBizBillEntryCollection = iResignBizBillEntry.getResignBizBillEntryCollection("where person = '" + personId + "'");
+        //判断该人员是否存在离职单
+        if (resignBizBillEntryCollection.size() > 0) {
+            ResignBizBillEntryInfo resignBizBillEntryInfo = resignBizBillEntryCollection.get(0);
+            Date expectedDate = (Date) resignBizBillEntryInfo.get("expectedDate");//预计离职日期
+            Date leftCompanyDate = resignBizBillEntryInfo.getLeftCompanyDate();//最后工作日
+            Date forbidUserDate = resignBizBillEntryInfo.getForbidUserDate();//禁用用户日期
+            if (expectedDate != null) {
+                String estimatedLeaveDate = sdf.format(expectedDate);
+                logger.error("estimatedLeaveDate--" + estimatedLeaveDate);
+                param.put("estimatedLeaveDate", estimatedLeaveDate);
+            }
+            if (leftCompanyDate != null) {
+                String lastWorkingDay = sdf.format(leftCompanyDate);
+                logger.error("lastWorkingDay--" + lastWorkingDay);
+                param.put("lastWorkingDay", lastWorkingDay);
+            }
+            if (forbidUserDate != null) {
+                String disableUserDate = sdf.format(forbidUserDate);
+                logger.error("disableUserDate--" + disableUserDate);
+                param.put("disableUserDate", disableUserDate);
+            }
+            param.put("userAccount", personInfo.getNumber());
+            logger.error("param" + param);
+            syncLogInfo.setRequestParams(param.toString());//请求参数
+            //请求接口  禁用用户
+            OkHttpClient client = new OkHttpClient.Builder()
+                    .connectTimeout(30, TimeUnit.SECONDS)
+                    .writeTimeout(30, TimeUnit.SECONDS)
+                    .readTimeout(30, TimeUnit.SECONDS)
+                    .build();
+            MediaType mediaType = MediaType.parse("application/json");
+            RequestBody body = RequestBody.create(mediaType, param.toString());
+            Request request = new Request.Builder()
+                    .url(propt.getProperty("disableUserAccountUrl"))
+                    .post(body)
+                    .addHeader("Accept", "*/*")
+                    .addHeader("Accept-Encoding", "gzip, deflate, br")
+                    .addHeader("User-Agent", "PostmanRuntime-ApipostRuntime/1.1.0")
+                    .addHeader("Connection", "keep-alive")
+                    .addHeader("Content-Type", "application/json")
+                    .build();
+            Response response = client.newCall(request).execute();
+            String result = response.body().string();
+            if (response.isSuccessful()) {
+                JSONObject jsonObject = JSONObject.parseObject(result);
+                logger.error("jsonObject" + jsonObject);
+                if (jsonObject.get("code").equals("200")) {
+                    syncLogInfo.setSyncStatus(SyncStatusEnum.SUCCESS);
+                    syncLogInfo.setSuccessNum(1);
+                    syncLogInfo.setSyncResult(result);
+                    iSyncLog.save(syncLogInfo);
+                } else {
+                    syncLogInfo.setSyncStatus(SyncStatusEnum.ERROR);
+                    syncLogInfo.setFailNum(1);
+                    syncLogInfo.setSyncResult(result);
+                    iSyncLog.save(syncLogInfo);
+                }
+            } else {
+                syncLogInfo.setSyncStatus(SyncStatusEnum.ERROR);
+                syncLogInfo.setFailNum(1);
+                syncLogInfo.setSyncResult(result);
+                iSyncLog.save(syncLogInfo);
+            }
+        }
+
+    }
+}