Explorar el Código

同步员工信息 调整

liuling hace 5 meses
padre
commit
b59ba18cac

+ 193 - 20
src/com/kingdee/eas/custom/beisen/synchronousorg/SynchronousEmpBillControllerBean.java

@@ -15,23 +15,24 @@ import com.kingdee.eas.base.attachment.BoAttchAssoFactory;
 import com.kingdee.eas.base.attachment.BoAttchAssoInfo;
 import com.kingdee.eas.base.codingrule.CodingRuleManagerFactory;
 import com.kingdee.eas.base.codingrule.ICodingRuleManager;
-import com.kingdee.eas.base.common.DCInfo;
 import com.kingdee.eas.base.permission.UserCollection;
 import com.kingdee.eas.base.permission.UserFactory;
 import com.kingdee.eas.base.permission.UserInfo;
 import com.kingdee.eas.basedata.org.*;
 import com.kingdee.eas.basedata.person.PersonInfo;
 import com.kingdee.eas.common.EASBizException;
-import com.kingdee.eas.cp.eip.sso.util.LoginUtil;
 import com.kingdee.eas.custom.beisen.utils.Helper;
 import com.kingdee.eas.custom.beisenconfig.*;
 import com.kingdee.eas.custom.enumerations.ViewTypeEnum;
+import com.kingdee.eas.custom.interfacelog.businessoperationlog.*;
+import com.kingdee.eas.fi.arap.util.DBUtil;
 import com.kingdee.eas.framework.CoreBaseCollection;
 import com.kingdee.eas.framework.CoreBaseInfo;
 import com.kingdee.eas.framework.ICoreBase;
 import com.kingdee.eas.hr.affair.*;
 import com.kingdee.eas.hr.base.ApproveTypeEnum;
 import com.kingdee.eas.hr.base.HRBillStateEnum;
+import com.kingdee.eas.hr.base.HRBizDefineInfo;
 import com.kingdee.eas.hr.emp.PersonPhotoFactory;
 import com.kingdee.eas.hr.emp.PersonPhotoInfo;
 import com.kingdee.shr.attachment.AttachmentState;
@@ -52,12 +53,10 @@ import com.kingdee.shr.base.syssetting.util.SysSettingUIViewUtil;
 import com.kingdee.shr.base.syssetting.web.dynamic.model.FieldInfo;
 import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.IUIViewConverter;
 import com.kingdee.shr.base.syssetting.web.dynamic.view.converter.UIViewConverterFactory;
-import com.kingdee.shr.guilogin.web.wechart.WeChartUtil;
 import com.kingdee.shr.ml.MLServiceFactory;
 import com.kingdee.shr.ml.ResourceType;
 import com.kingdee.util.LocaleUtils;
 import com.kingdee.util.StringUtils;
-import com.kingdee.util.Uuid;
 import org.apache.log4j.Logger;
 
 import java.io.IOException;
@@ -98,25 +97,25 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
                 .getUserCollection("select *,person.* where id = '" + caller.toString() + "'");
         if (userCollection.size() > 0) {
             UserInfo userInfo = userCollection.get(0);
-            if (userInfo.getPerson()==null){
+            if (userInfo.getPerson() == null) {
                 userCollection = UserFactory.getLocalInstance(context)
                         .getUserCollection("select *,person.* where number = '" + userName + "'");
-                if (userCollection.size()>0){
+                if (userCollection.size() > 0) {
                     UserInfo userInfo1 = userCollection.get(0);
                     BOSUuid id = userInfo1.getId();
-                    System.out.println("===userInfo======"+userInfo1.getPerson().getName());
+                    System.out.println("===userInfo======" + userInfo1.getPerson().getName());
                     context.setCaller(new ObjectUuidPK(id));
                     SHRContext shrContext = new SHRContext(null, null, null);
                     context.put("UserInfo", userInfo1);
                     shrContext.setContext(context);
                     SHRContext.setInstance(shrContext);
                 }
-                
-            }else {
+
+            } else {
                 SHRContext instance = SHRContext.getInstance();
-                System.out.println("++++++++"+instance);
-                if (instance==null){
-                    System.out.println("======================"+null);
+                System.out.println("++++++++" + instance);
+                if (instance == null) {
+                    System.out.println("======================" + null);
                     SHRContext shrContext = new SHRContext(null, null, null);
                     context.put("UserInfo", userCollection.get(0));
                     shrContext.setContext(context);
@@ -172,11 +171,13 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
         BSViewConfigEntryInfo bsViewConfigEntryInfo = headBsViewConfigEntryCollection.get(0);
         UIViewInfo view = bsViewConfigEntryInfo.getView();
         String file = bsViewConfigEntryInfo.getFile();
+        IOperateLog localInstance = OperateLogFactory.getLocalInstance(ctx);
         for (int i = 0; i < beiSenData.size(); i++) {
             JSONObject jsonObject1 = beiSenData.getJSONObject(i);
             JSONArray fileArray = jsonObject1.getJSONArray(file);
             boolean isCreateData = bsViewConfigEntryInfo.isIsCreateData();
             String headId = null;
+            OperateLogInfo operateLogInfo = new OperateLogInfo();
             if (isCreateData) {
                 String headDataEntry = bsViewConfigEntryInfo.getHeadDataEntry();
                 if (headDataEntry != null && !headDataEntry.equals("")) {
@@ -190,27 +191,90 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
                     }
                     // 创建对应的实体对象
                     CoreBaseInfo coreBaseInfo = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass, headDataEntry);
+                    EntityObjectInfo entityObjectInfo = MetaDataUtil.getEntityObjectByBosType(coreBaseInfo.getBOSType());
+                    operateLogInfo.setBusinessName(entityObjectInfo.getAlias());
+                    operateLogInfo.setBosType(coreBaseInfo.getBOSType().toString());
+                    OperateLogEntryCollection entrys = operateLogInfo.getEntrys();
                     if (coreBaseInfo instanceof EmpEnrollBizBillInfo) {
                         System.out.println("针对入职单处理");
                         String string = jsonObject1.getJSONObject("staffInfos").getString("id");
+                        JSONArray entryRecord = jsonObject1.getJSONArray("entryRecord");
+                        String entryRecordId = "";
+                        if (entryRecord.size()>1){
+                            JSONArray datas = paixu(entryRecord, "entryDate");
+                            System.out.println("排序后"+datas);
+                            entryRecordId = datas.getJSONObject(0).getString("id");
+                        }else {
+                            entryRecordId = entryRecord.getJSONObject(0).getString("id");
+                        }
+
                         EmpEnrollBizBillCollection collection = EmpEnrollBizBillFactory.getLocalInstance(context)
-                                .getEmpEnrollBizBillCollection("select *,entrys.*,entrys.person.* where beisenid='" + string + "'");
+                                .getEmpEnrollBizBillCollection("select *,entrys.*,entrys.person.* where entryRecordId='" + entryRecordId + "'");
                         if (collection.size() > 0) {
                             System.out.println("=======入职单已存在=============");//0044610
+                            OperateLogEntryInfo operateLogEntryInfo = new OperateLogEntryInfo();
+                            operateLogEntryInfo.setErrorInfo("入职单已存在");
+                            entrys.add(operateLogEntryInfo);
+                            try {
+                                localInstance.save(operateLogInfo);
+                            } catch (EASBizException e) {
+                                e.printStackTrace();
+                                System.out.println(e.getMessage());
+                            }
                             continue;
+                        }else {
+                            EmpEnrollBizBillCollection collection1 = EmpEnrollBizBillFactory.getLocalInstance(context)
+                                    .getEmpEnrollBizBillCollection("select *,entrys.*,entrys.person.* where beisenid='" + string + "'");
+                            if (collection1.size() > 0) {
+                                System.out.println("==========清空beisenid=========");
+                                String sql = "update T_HR_EmpEnrollBizBill set cfbeisenid = null where cfbeisenid = '"+string+"'";
+                                DBUtil.execute(ctx,sql);
+                            }
                         }
 
                     }
                 }
                 try {
                     headId = headProcessing(view, jsonObject1, fileArray, file);
+                    //operateLogInfo = new OperateLogInfo();
+                    operateLogInfo.setBusinessId(headId);
+                    OperateLogEntryCollection entrys = operateLogInfo.getEntrys();
+                    OperateLogEntryInfo operateLogEntryInfo = new OperateLogEntryInfo();
+                    String boy = jsonObject1.toJSONString();
+                    if (boy.length()>500){
+                        boy = boy.substring(0, 500);
+                    }
+                    operateLogEntryInfo.setErrorInfo(boy);
+                    entrys.add(operateLogEntryInfo);
+                    try {
+                        localInstance.save(operateLogInfo);
+                    } catch (EASBizException e) {
+                        e.printStackTrace();
+                        System.out.println(e.getMessage());
+                    }
                 } catch (Exception e) {
+                    operateLogInfo.setBusinessId(headId);
+                    OperateLogEntryCollection entrys = operateLogInfo.getEntrys();
+                    OperateLogEntryInfo operateLogEntryInfo = new OperateLogEntryInfo();
+                    String f = e.getMessage();
+                    if (f!=null&&f.length()>500){
+                        f = f.substring(0, 500);
+                    }
+                    operateLogEntryInfo.setErrorInfo("整理保存头部数据失败!!!!" + f);
+                    entrys.add(operateLogEntryInfo);
+                    System.out.println(e.getMessage());
                     System.out.println("整理保存头部数据失败!!!!");
+                    try {
+                        localInstance.save(operateLogInfo);
+                    } catch (EASBizException ex) {
+                        ex.printStackTrace();
+                    }
                     e.printStackTrace();
                     continue;
                 }
                 id += headId + ",";
             } else {
+                //operateLogInfo = new OperateLogInfo();
                 String headDataEntry = bsViewConfigEntryInfo.getHeadDataEntry();
                 Class objectValueClass = null;
                 try {
@@ -220,6 +284,10 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
                     e.printStackTrace();
                     continue;
                 }
+                operateLogInfo.setBusinessId(headId);
+                OperateLogEntryCollection entrys1 = operateLogInfo.getEntrys();
+                OperateLogEntryInfo operateLogEntryInfo = new OperateLogEntryInfo();
+
                 // 创建对应的实体对象
                 CoreBaseInfo coreBaseInfo = (CoreBaseInfo) MetaDataUtil.newInstance(objectValueClass, headDataEntry);
                 if (coreBaseInfo instanceof EmpEnrollBizBillInfo) {
@@ -237,6 +305,18 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
                                 try {
                                     headProcessing(view, jsonObject1, person, fileArray, file);
                                 } catch (Exception e) {
+                                    String f = e.getMessage();
+                                    if (f!=null&&f.length()>500){
+                                        f = f.substring(0, 500);
+                                    }
+                                    operateLogEntryInfo.setErrorInfo("获取头部信息失败!!!!" + f);
+                                    entrys1.add(operateLogEntryInfo);
+                                    try {
+                                        localInstance.save(operateLogInfo);
+                                    } catch (EASBizException ex) {
+
+                                    }
+
                                     System.out.println("获取头部信息失败");
                                     e.printStackTrace();
                                     continue;
@@ -263,20 +343,55 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
             BSViewConfigEntryCollection boyBsViewConfigEntryCollection = BSViewConfigEntryFactory
                     .getLocalInstance(context).getBSViewConfigEntryCollection(entryBoyEntityViewInfo);
             for (int j = 0; j < boyBsViewConfigEntryCollection.size(); j++) {
+                operateLogInfo = new OperateLogInfo();
+                //operateLogInfo.setBusinessId(headId);
+                OperateLogEntryCollection entrys1 = operateLogInfo.getEntrys();
+                OperateLogEntryInfo operateLogEntryInfo = new OperateLogEntryInfo();
+
                 BSViewConfigEntryInfo boybsViewConfigEntryInfo = boyBsViewConfigEntryCollection.get(j);
                 UIViewInfo view1 = boybsViewConfigEntryInfo.getView();
                 String beiSenData1 = boybsViewConfigEntryInfo.getBeiSenData();
                 UIType type = view1.getType();
+                operateLogInfo.setBusinessName(view1.getName());
                 boolean isCreateData1 = boybsViewConfigEntryInfo.isIsCreateData();
                 try {
                     if (type.getValue().equals("list")) {
                         boyProcessing(view1, headId, jsonObject1.getJSONArray(beiSenData1), null, "fileInfos", beiSenData1);
+                        String boy = jsonObject1.getJSONArray(beiSenData1).toJSONString();
+                        if (boy.length()>500){
+                            boy = boy.substring(0, 500);
+                        }
+
+                        operateLogEntryInfo.setErrorInfo(boy);
                     } else {
                         boyProcessing(view1, isCreateData1, headId, jsonObject1.getJSONObject(beiSenData1), null, "fileInfos", beiSenData1);
+                        String boy =jsonObject1.getJSONObject(beiSenData1).toJSONString();
+                        if (boy.length()>500){
+                            boy = boy.substring(0, 500);
+                        }
+                        operateLogEntryInfo.setErrorInfo(boy);
                     }
+                    entrys1.add(operateLogEntryInfo);
+                    try {
+                        localInstance.save(operateLogInfo);
+                    } catch (EASBizException ex) {
+                        ex.printStackTrace();
+                    }
+
                 } catch (Exception e) {
                     System.out.println("整理报错主题信息失败!!!");
                     e.printStackTrace();
+                    String f = e.getMessage();
+                    if (f!=null&&f.length()>500){
+                        f = f.substring(0, 500);
+                    }
+                    operateLogEntryInfo.setErrorInfo("获取头部信息失败!!!!" + f);
+                    entrys1.add(operateLogEntryInfo);
+                    try {
+                        localInstance.save(operateLogInfo);
+                    } catch (EASBizException ex) {
+
+                    }
                     continue;
                 }
             }
@@ -321,6 +436,7 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
         ICoreBase bosObject = (ICoreBase) (BOSObjectFactory.createBOSObject(context, coreBaseInfo.getBOSType()));
         // 获取关联字段
         String relateField = uiViewInfo1.getRelatedField();
+        System.out.println("==============判断是否需要同步====="+!isCreateData1+"============"+isCreateData1);
         if (!isCreateData1) {
             System.out.println("=============查询不需要同步数据============" + "where " + relateField + " = '" + id + "'");
             CoreBaseCollection collection = bosObject.getCollection("where " + relateField + " = '" + id + "'");
@@ -710,7 +826,17 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
                         value = attributes.get("data-defaultValue");
                     } else {
                         JSONArray jsonArray = jsonObject.getJSONArray(split[0]);
-                        data1 = jsonArray.getJSONObject(0);
+                        if ((split[0].equals("entryRecord")||split[0].equals("employmentRecord"))&&jsonArray.size()>0){
+                            // 定义日期格式
+                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+                            JSONArray sortedJsonArray = paixu(jsonArray, "entryDate");
+                            System.out.println("排序后entryRecord/employmentRecord"+sortedJsonArray);
+                            // (可选)将排序后的List转回JSONArray
+                            data1 = sortedJsonArray.getJSONObject(0);
+                        }else {
+                            data1 = jsonArray.getJSONObject(0);
+                        }
+
                     }
                 } else {
                     data1 = jsonObject.getJSONObject(split[0]);
@@ -746,7 +872,7 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
                     if (s != null && !s.equals("")) {
                         // 解析自定义映射值的 JSON 对象
                         JSONObject jsonObject1 = JSONObject.parseObject(s);
-                        if (jsonObject1 != null) {
+                        if (jsonObject1 != null && value != null) {
                             // 根据值获取映射后的值
                             String string = jsonObject1.getString(value.toString());
                             if (string != null) {
@@ -783,7 +909,7 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
                     if (coreBaseInfo1 instanceof PersonInfo) {
                         where += " or bsUserId = '" + value + "'";
                     } else if (coreBaseInfo1 instanceof AdminOrgUnitInfo) {
-                        where += " or originalId = '" + value + "'";
+                        where += " or reserveFieldFirst = '" + value + "'";
                     } else if (coreBaseInfo1 instanceof PositionInfo) {
                         where += " or OriginalId = '" + value + "'";
                     }
@@ -800,7 +926,7 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
                         if (coreBaseInfo1 instanceof PersonInfo) {
                             where += " or bsUserId = '" + value + "'";
                         } else if (coreBaseInfo1 instanceof AdminOrgUnitInfo) {
-                            where += " or originalId = '" + value + "'";
+                            where += " or reserveFieldFirst = '" + value + "'";
                         } else if (coreBaseInfo1 instanceof PositionInfo) {
                             where += " or OriginalId = '" + value + "'";
                         }
@@ -840,6 +966,21 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
                         //coreBaseInfo.put("passportNO", value);
                         setCoreBaseInfo(coreBaseInfo, "entrys.passportNO", value);
                     }
+                    String where = "where IDCardNo = '"+value+"' or passportNO='"+value+"'";
+                    System.out.println("====判断是否再入职=="+where);
+                    EmpEnrollBizBillEntryCollection empEnrollBizBills = EmpEnrollBizBillEntryFactory
+                            .getLocalInstance(context).getEmpEnrollBizBillEntryCollection(where);
+                    HRBizDefineInfo hrBizDefineInfo = new HRBizDefineInfo();
+                    System.out.println("====empEnrollBizBills=="+empEnrollBizBills.size());
+                    if (empEnrollBizBills.size()>0){
+                        System.out.println("====empEnrollBizBills= DawAAAApC9TmaL7Z= 是");
+                        hrBizDefineInfo.setId(BOSUuid.read("DawAAAApC9TmaL7Z"));
+                        setCoreBaseInfo(coreBaseInfo, "entrys.hrBizDefine", hrBizDefineInfo);
+                    }else {
+                        System.out.println("====empEnrollBizBills= DawAAAApC9DmaL7Z= 否");
+                        hrBizDefineInfo.setId(BOSUuid.read("DawAAAApC9DmaL7Z"));
+                        setCoreBaseInfo(coreBaseInfo, "entrys.hrBizDefine", hrBizDefineInfo);
+                    }
                 } else {
                     setCoreBaseInfo(coreBaseInfo, name, value);
                     // 将值设置到当前实体对象中
@@ -883,10 +1024,14 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
                             throw new RuntimeException(e);
                         }
                     }
-
-
                 }
                 objectValue.put(split[1], value);
+                if (split[1].equals("position")) {
+                    if (value instanceof PositionInfo) {
+                        objectValue.put("job", ((PositionInfo) value).getJob());
+                    }
+
+                }
             }
         } else {
             coreBaseInfo.put(name, value);
@@ -1520,6 +1665,34 @@ public class SynchronousEmpBillControllerBean extends AbstractSynchronousEmpBill
             }
         }
     }
-
+    JSONArray paixu (JSONArray jsonArray,String entryDate){
+        List<JSONObject> list = jsonArray.toJavaList(JSONObject.class);
+        // 定义日期格式
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+        // 排序
+        Collections.sort(list, new Comparator<JSONObject>() {
+            @Override
+            public int compare(JSONObject o1, JSONObject o2) {
+                try {
+                    // 获取entryDate字段
+                    String dateStr1 = o1.getString(entryDate);
+                    String dateStr2 = o2.getString(entryDate);
+
+                    // 解析为Date对象
+                    Date date1 = sdf.parse(dateStr1);
+                    Date date2 = sdf.parse(dateStr2);
+
+                    // 比较日期
+                    return date2.compareTo(date1);
+                } catch (ParseException e) {
+                    // 处理日期解析异常
+                    e.printStackTrace();
+                    return 0;
+                }
+            }
+        });
+        // (可选)将排序后的List转回JSONArray
+        return JSONArray.parseArray(JSONArray.toJSONString(list));
+    }
 
 }

+ 48 - 25
src/com/kingdee/eas/custom/beisen/synchronousorg/synchronousOrgControllerBean.java

@@ -10,16 +10,24 @@ import com.kingdee.eas.basedata.org.*;
 import com.kingdee.eas.basedata.person.PersonInfo;
 import com.kingdee.eas.custom.beisen.utils.BeiSenUtils;
 import com.kingdee.eas.fi.arap.util.DBUtil;
+import com.kingdee.eas.hr.base.EmpPostExperienceHis;
+import com.kingdee.eas.hr.base.EmpPostExperienceHisCollection;
+import com.kingdee.eas.hr.base.EmpPostExperienceHisFactory;
+import com.kingdee.eas.hr.base.EmpPostExperienceHisInfo;
 import com.kingdee.eas.hr.emp.PersonPositionCollection;
 import com.kingdee.eas.hr.emp.PersonPositionFactory;
 import com.kingdee.eas.hr.emp.PersonPositionInfo;
+import com.kingdee.jdbc.rowset.IRowSet;
 import org.apache.log4j.Logger;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
+import java.sql.SQLException;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
 
 import com.kingdee.bos.*;
 
@@ -37,9 +45,9 @@ public class synchronousOrgControllerBean extends AbstractsynchronousOrgControll
     /**
      * 创建或更新组织信息并同步到外部系统的方法。
      *
-     * @param ctx    上下文对象,包含系统运行时的环境信息
-     * @param day    时间范围,用于筛选指定天数内更新的组织信息
-     * @param orgId  组织 ID,如果不为空,则仅处理指定 ID 的组织信息
+     * @param ctx      上下文对象,包含系统运行时的环境信息
+     * @param day      时间范围,用于筛选指定天数内更新的组织信息
+     * @param orgId    组织 ID,如果不为空,则仅处理指定 ID 的组织信息
      * @param isDelete 是否为删除操作
      * @throws BOSException 执行过程中发生业务异常时抛出
      */
@@ -63,26 +71,29 @@ public class synchronousOrgControllerBean extends AbstractsynchronousOrgControll
             for (int i = 0; i < adminOrgUnitCollection.size(); i++) {
                 // 获取当前组织信息
                 AdminOrgUnitInfo adminOrgUnitInfo = adminOrgUnitCollection.get(i);
-                String originalId = adminOrgUnitInfo.getString("originalId");
+                String originalId = adminOrgUnitInfo.getReserveFieldFirst();
+                System.out.println("===========originalId" + originalId);
                 try {
                     JSONObject requestBody = getRequestBody(ctx, adminOrgUnitInfo, null);
 
                     JSONObject orUpdateByOrg = beiSenUtils.createOrUpdateByOrg(requestBody, adminOrgUnitInfo);
 
-                    System.out.println("orUpdateByOrg:"+orUpdateByOrg);
+                    System.out.println("orUpdateByOrg:" + orUpdateByOrg);
                     // 获取响应状态码
                     String code = orUpdateByOrg.getString("code");
                     if ("200".equals(code)) {
-                        if (originalId.isEmpty()) {
+                        if (originalId == null) {
                             // 响应状态码为 200 时,更新组织信息的 originalId 字段
                             String data = orUpdateByOrg.getString("data");
                             //adminOrgUnitInfo.put("originalId", data);
                             // 保存更新后的组织信息
                             String id = adminOrgUnitInfo.getId().toString();
-                            String sql = "update T_ORG_Admin set cforiginalId = '"+data+"' where FID = '"+id+"'";
-                            DBUtil.execute(ctx,sql);
+                            if (data != null && !data.equals("")) {
+                                String sql = "update T_ORG_Admin set FreserveFieldFirst = '" + data + "' where FID = '" + id + "'";
+                                DBUtil.execute(ctx, sql);
+                            }
                         }
-                        ids+=adminOrgUnitInfo.getId().toString();
+                        ids += adminOrgUnitInfo.getId().toString();
                     } else {
                         // 响应状态码不为 200 时,记录错误信息
                         logError(adminOrgUnitInfo.getName(), orUpdateByOrg.getString("message"));
@@ -146,14 +157,16 @@ public class synchronousOrgControllerBean extends AbstractsynchronousOrgControll
             BOSUuid id = responPosition.getId();
             EntityViewInfo entityViewInfo = createPersonPositionViewInfo(id);
             try {
-                PersonPositionCollection personPositionCollection = PersonPositionFactory
-                        .getLocalInstance(context).getPersonPositionCollection(entityViewInfo);
+                EmpPostExperienceHisCollection empPostExperienceHisCollection =
+                        EmpPostExperienceHisFactory.getLocalInstance(context).getEmpPostExperienceHisCollection(entityViewInfo);
+//                PersonPositionCollection personPositionCollection = PersonPositionFactory
+//                        .getLocalInstance(context).getPersonPositionCollection(entityViewInfo);
                 // 遍历人员岗位信息集合
-                for (int i = 0; i < personPositionCollection.size(); i++) {
+                for (int i = 0; i < empPostExperienceHisCollection.size(); i++) {
                     // 获取当前人员岗位信息
-                    PersonPositionInfo personPositionInfo = personPositionCollection.get(i);
+                    EmpPostExperienceHisInfo empPostExperienceHisInfo = empPostExperienceHisCollection.get(i);
                     // 获取人员信息
-                    PersonInfo person = personPositionInfo.getPerson();
+                    PersonInfo person = empPostExperienceHisInfo.getPerson();
                     // 将人员 ID 添加到部门负责人 ID 数组中
                     originalIds.add(person.getId().toString());
                 }
@@ -163,15 +176,20 @@ public class synchronousOrgControllerBean extends AbstractsynchronousOrgControll
             }
             JSONObject customFieldList = new JSONObject();
             //部门负责人岗位编码
-            customFieldList.put("extbumenfuzerengangweibianma_433107_1704083012",responPosition.getNumber());
-            customFieldList.put("extbumenfuzerengangweimingcheng_433107_501692677",responPosition.getName());
-            requestBody.put("customFieldList",customFieldList);
+            customFieldList.put("extbumenfuzerengangweibianma_433107_1704083012", responPosition.getNumber());
+            customFieldList.put("extbumenfuzerengangweimingcheng_433107_501692677", responPosition.getName());
+            requestBody.put("customFieldList", customFieldList);
         }
 
-        if (originalIds.size() > 0) {
-            // 部门负责人 ID 数组不为空时,添加部门负责人 ID 数组到请求体
-            requestBody.put("departmentLeaders", originalIds);
-        }
+
+        // 部门负责人 ID 数组不为空时,添加部门负责人 ID 数组到请求体
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("originalIds", originalIds);
+        jsonObject.put("leaderType", 1);
+        JSONArray jsonArray = new JSONArray();
+        jsonArray.add(jsonObject);
+        requestBody.put("departmentLeaders", jsonArray);
+
 
         // 添加组织修改时间
         requestBody.put("modifiedTime", formatDate(adminOrgUnitInfo.getLastUpdateTime()));
@@ -179,7 +197,6 @@ public class synchronousOrgControllerBean extends AbstractsynchronousOrgControll
         requestBody.put("createTime", formatDate(adminOrgUnitInfo.getCreateTime()));
 
 
-
 //        // 获取组织是否为织状态
 //        boolean isSaleOrgUnit = adminOrgUnitInfo.isIsSealUp();
 //        // 根据销售组织状态设置组织状态
@@ -251,6 +268,7 @@ public class synchronousOrgControllerBean extends AbstractsynchronousOrgControll
         return entityViewInfo;
     }
 
+
     /**
      * 创建人员岗位查询视图信息的方法,用于筛选人员岗位信息。
      *
@@ -262,9 +280,14 @@ public class synchronousOrgControllerBean extends AbstractsynchronousOrgControll
         EntityViewInfo entityViewInfo = new EntityViewInfo();
         FilterInfo filterInfo = new FilterInfo();
         // 添加查询条件,筛选主要岗位等于指定岗位 ID 的人员岗位信息
-        filterInfo.getFilterItems().add(new FilterItemInfo("primaryPosition", positionId.toString(), CompareType.EQUALS));
+        filterInfo.getFilterItems().add(new FilterItemInfo("Position", positionId.toString(), CompareType.EQUALS));
         // 添加查询条件,筛选人员已同步的人员岗位信息
-        filterInfo.getFilterItems().add(new FilterItemInfo("person.isSync", true, CompareType.EQUALS));
+        filterInfo.getFilterItems().add(new FilterItemInfo("person.bsUserId is not null"));
+        filterInfo.getFilterItems().add(new FilterItemInfo("Leffdt", new Date(), CompareType.GREATER_EQUALS));
+        Set<String> stringSet = new HashSet<String>();
+        stringSet.add("1");
+        stringSet.add("4");
+        filterInfo.getFilterItems().add(new FilterItemInfo("person.employeeType.inService", stringSet, CompareType.INCLUDE));
         // 设置查询条件到查询视图信息对象中
         entityViewInfo.setFilter(filterInfo);
 
@@ -273,7 +296,7 @@ public class synchronousOrgControllerBean extends AbstractsynchronousOrgControll
         selectorItemCollection.add("person.*");
         // 设置选择项集合到查询视图信息对象中
         entityViewInfo.setSelector(selectorItemCollection);
-
+        System.out.println("=============entityViewInfo" + entityViewInfo);
         return entityViewInfo;
     }
 

+ 1 - 1
src/com/kingdee/eas/custom/beisen/utils/BeiSenUtils.java

@@ -115,7 +115,7 @@ public class BeiSenUtils {
     }
     public JSONObject createOrUpdateByOrg(JSONObject requestBody, AdminOrgUnitInfo adminOrgUnitInfo) throws FileNotFoundException, IOException
             , URISyntaxException {
-        String originalId = adminOrgUnitInfo.getString("originalId");
+        String originalId = adminOrgUnitInfo.getReserveFieldFirst();
         String orgid = adminOrgUnitInfo.getId().toString();
         // ÓÃÓÚ´æ´¢ÏìÓ¦Êý¾ÝµÄ JSONArray
         JSONArray responseData = new JSONArray();

+ 49 - 0
src/com/kingdee/eas/custom/interfacelog/businessoperationlog/app/OperateLogControllerBean.java

@@ -1,5 +1,7 @@
 package com.kingdee.eas.custom.interfacelog.businessoperationlog.app;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.kingdee.bos.metadata.entity.EntityObjectInfo;
 import com.kingdee.bos.util.BOSUuid;
 import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
@@ -30,6 +32,12 @@ import com.kingdee.bos.dao.IObjectPK;
 import com.kingdee.eas.custom.interfacelog.businessoperationlog.OperateLogCollection;
 
 import java.lang.String;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
 
 import com.kingdee.eas.custom.interfacelog.businessoperationlog.OperateLogInfo;
 import com.kingdee.bos.metadata.entity.EntityViewInfo;
@@ -96,4 +104,45 @@ public class OperateLogControllerBean extends AbstractOperateLogControllerBean {
         // 调用父类的 _addnew 方法完成添加操作
         return super._addnew(ctx, operateLogInfo);
     }
+    public static void main(String[] args) {
+        // 假设这是你的JSONArray
+        String jsonStr = "[{\"organizationName\":\"人力资源管理中心\",\"organizationCode\":\"2\",\"fileInfos\":[],\"id\":\"71c35a64-7c53-4bbd-8700-ac5cf73feb81\",\"entryDate\":\"2025-08-01T00:00:00\",\"jobNumber\":null,\"isCharge\":null,\"place\":null,\"userID\":408241917,\"originalId\":2878593,\"post\":\"fac1edc9-d2d2-4c4e-bd54-029220822844\",\"jobRank\":null,\"jobGrade\":null,\"poIdEmpAdmin\":0,\"poIdEmpReserve\":0,\"job\":null,\"planEntryDate\":null,\"planDate\":\"2025-08-01T00:00:00\",\"probationDate\":6,\"extendInfos\":[{\"text\":null,\"name\":\"Onwer\",\"value\":10000}]},{\"organizationName\":\"人力资源管理中心\",\"organizationCode\":\"2\",\"fileInfos\":[],\"id\":\"33a75888-81bf-4914-877e-d1b5c071f1c1\",\"entryDate\":\"2025-08-07T00:00:00\",\"jobNumber\":null,\"isCharge\":null,\"place\":null,\"userID\":408241917,\"originalId\":2878593,\"post\":\"f1560c71-c04f-4621-9931-9126f6d0b23f\",\"jobRank\":null,\"jobGrade\":null,\"poIdEmpAdmin\":0,\"poIdEmpReserve\":0,\"job\":null,\"planEntryDate\":null,\"planDate\":\"2025-08-08T00:00:00\",\"probationDate\":5,\"extendInfos\":[{\"text\":null,\"name\":\"Onwer\",\"value\":10000}]}]";
+        JSONArray jsonArray = JSONArray.parseArray(jsonStr);
+
+        // 转换为List以便排序
+        List<JSONObject> list = jsonArray.toJavaList(JSONObject.class);
+
+        // 定义日期格式
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+
+        // 排序
+        Collections.sort(list, new Comparator<JSONObject>() {
+            @Override
+            public int compare(JSONObject o1, JSONObject o2) {
+                try {
+                    // 获取entryDate字段
+                    String dateStr1 = o1.getString("entryDate");
+                    String dateStr2 = o2.getString("entryDate");
+
+                    // 解析为Date对象
+                    Date date1 = sdf.parse(dateStr1);
+                    Date date2 = sdf.parse(dateStr2);
+
+                    // 比较日期
+                    return date2.compareTo(date1);
+                } catch (ParseException e) {
+                    // 处理日期解析异常
+                    e.printStackTrace();
+                    return 0;
+                }
+            }
+        });
+
+        // (可选)将排序后的List转回JSONArray
+        JSONArray sortedJsonArray = JSONArray.parseArray(JSONArray.toJSONString(list));
+
+        // 输出排序结果
+        System.out.println("排序后的JSONArray:");
+        System.out.println(sortedJsonArray);
+    }
 }