浏览代码

AD域同步

yuanzhi_kuang 21 小时之前
父节点
当前提交
e9439f762c
共有 1 个文件被更改,包括 83 次插入37 次删除
  1. 83 37
      GDYSL/websrc/com/kingdee/shr/customer/gtiit/osf/SynADService.java

+ 83 - 37
GDYSL/websrc/com/kingdee/shr/customer/gtiit/osf/SynADService.java

@@ -6,6 +6,7 @@ import com.kingdee.bos.BOSException;
 import com.kingdee.bos.Context;
 import com.kingdee.bos.bsf.service.app.IHRMsfService;
 import com.kingdee.eas.common.EASBizException;
+import com.kingdee.eas.util.ToolUtils;
 import com.kingdee.eas.util.app.DbUtil;
 import com.kingdee.jdbc.rowset.IRowSet;
 import java.text.SimpleDateFormat;
@@ -24,7 +25,7 @@ public class SynADService implements IHRMsfService {
 
 	public Object process(Context ctx, Map map) throws EASBizException, BOSException {
 		logger.error("进入同步AD域信息接口");
-		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
 		// 开始日期
 		String startDate = (String)map.get("startDate");
 		// 截止日期
@@ -32,11 +33,21 @@ public class SynADService implements IHRMsfService {
 		// 员工工号
 		String personNumber = (String)map.get("personNumber");
 		logger.error("获取员工信息接口参数-开始日期:" + startDate + ",截止日期:" + endDate + ",人员:" + personNumber);
+		// 如果开始日期为空,则默认设置为当天
 
-		if (StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)) {
-			// 如果开始日期或结束日期为空,则默认设置为当天和第二天
+		if (StringUtils.isBlank(startDate) ) {
+			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 			Calendar calendar = Calendar.getInstance();
+			calendar.add(Calendar.DAY_OF_MONTH, -1);  // 减1天设置为前一天
+			calendar.set(Calendar.HOUR_OF_DAY, 0);    // 设置为0点
+			calendar.set(Calendar.MINUTE, 0);        // 0分
+			calendar.set(Calendar.SECOND, 0);        // 0秒
 			startDate = sdf.format(calendar.getTime());
+		}
+		//结束日期为空,则默认设置为第二天
+		if(StringUtils.isBlank(endDate)){
+			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+			Calendar calendar = Calendar.getInstance();
 			calendar.add(Calendar.DAY_OF_MONTH, 1);
 			endDate = sdf.format(calendar.getTime());
 		}
@@ -45,14 +56,16 @@ public class SynADService implements IHRMsfService {
 		Set<String> personIdSet = new HashSet<>();
 
 		try {
+			
 			// 查询调动单审核通过的员工
 			String fluctuaSql = "SELECT b.fpersonid FROM T_HR_FluctuationBizBill a left join T_HR_FluctuationBizBillentry b on a.fid=b.fbillid where FBILLSTATE ='3' and FLASTUPDATETIME >='" +
 					startDate + "' and FLASTUPDATETIME <='" + endDate + "'";
 			IRowSet fluctuaRow = DbUtil.executeQuery(ctx, fluctuaSql);
 			while (fluctuaRow.next())
 				personIdSet.add(fluctuaRow.getString("fpersonid"));
-
+			
 			// 查询前一天离职的员工
+			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 			Calendar resignCalendar = Calendar.getInstance();
 			resignCalendar.add(Calendar.DAY_OF_MONTH, -1);
 			String resignSql = "select b.fpersonid from T_HR_ResignBizBill a left join T_HR_ResignBizBillentry b on a.fid=b.fbillid where a.FBILLSTATE = '3' and b.FBIZDATE = '" +
@@ -60,35 +73,40 @@ public class SynADService implements IHRMsfService {
 			IRowSet resignRow = DbUtil.executeQuery(ctx, resignSql);
 			while (resignRow.next())
 				personIdSet.add(resignRow.getString("fpersonid"));
-
+			
 			// 查询预入职生效的员工
 			String preSql = "select per.fid from T_HR_PreEntry pre left join T_BD_Person per on per.fnumber = pre.CFEMPNUMBER where FBILLSTATE = '3' and FCHECKINSTATE = '3' and CFEMPNUMBER <> '' and FBIZDATE >='" +
 					startDate + "' and FBIZDATE <='" + endDate + "'";
 			IRowSet preRow = DbUtil.executeQuery(ctx, preSql);
 			while (preRow.next())
 				personIdSet.add(preRow.getString("fid"));
-
-
- 			// 查询合同变动的员工  20250829
+			
+			
+			// 查询合同变动的员工  20250829
 			preSql = " SELECT  fpersonid   from CT_MP_Pcontractinfo  where   flastupdatetime >='" + startDate + "' and flastupdatetime <='" + endDate + "'";
 			IRowSet pcoRow = DbUtil.executeQuery(ctx, preSql);
 			while (pcoRow.next())   personIdSet.add(pcoRow.getString("fpersonid"));
-
+			
 			// 查询员工信息变动的员工
 			String lastDateSql = "SELECT fid FROM T_BD_Person where flastupdatetime>='" + startDate +
 					"' and flastupdatetime<='" + endDate + "'";
 			IRowSet lastDateRow = DbUtil.executeQuery(ctx, lastDateSql);
 			while (lastDateRow.next())
 				personIdSet.add(lastDateRow.getString("fid"));
-
+			
+			
 			// 如果指定了员工工号,则只查询该员工
 			if (StringUtils.isNotBlank(personNumber)) {
 				personIdSet = new HashSet<>();
-				String personSql = "SELECT fid FROM T_BD_Person where fnumber = '" + personNumber + "'";
+				//改为多个值
+				String[] split = personNumber.split(",");
+				String  pNums = ToolUtils.aryToStr(split);
+				String personSql = "SELECT fid FROM T_BD_Person where fnumber  in  ( " + pNums + " ) ";
 				IRowSet personRow = DbUtil.executeQuery(ctx, personSql);
 				while (personRow.next())
 					personIdSet.add(personRow.getString("fid"));
-			}
+			} 
+			
 
 			logger.error("员工id集合:" + personIdSet.toString());
 
@@ -102,7 +120,7 @@ public class SynADService implements IHRMsfService {
 				sb.deleteCharAt(sb.length() - 1);
 			}
 			//202508  手机号用于去重
-			HashSet<String> telephoneNumberSet = new HashSet<>();
+			HashSet<String> accountNameSet = new HashSet<>();
 
 			// 构建主查询SQL
 			// 查询非预入职员工信息
@@ -248,6 +266,11 @@ public class SynADService implements IHRMsfService {
 				JSONObject jsonObject = new JSONObject();
 				// 用户名
 				jsonObject.put("sAMAccountName", iRowSet.getString("sAMAccountName"));
+				//去重
+				if(StringUtils.isNotBlank(iRowSet.getString("sAMAccountName") ) && accountNameSet.contains(iRowSet.getString("sAMAccountName"))){
+					continue;
+				}
+				accountNameSet.add(iRowSet.getString("sAMAccountName"));
 				// 名
 				String givenName = iRowSet.getString("givenName");
 				jsonObject.put("givenName", givenName);
@@ -262,9 +285,8 @@ public class SynADService implements IHRMsfService {
 				// 邮箱地址
 				jsonObject.put("mail", iRowSet.getString("mail"));
 				// 办公电话
-				if (StringUtils.isNotBlank(iRowSet.getString("telephoneNumber"))){
-					jsonObject.put("telephoneNumber", iRowSet.getString("telephoneNumber"));
-				}
+				jsonObject.put("telephoneNumber", iRowSet.getString("telephoneNumber"));
+
 				// 职位
 				jsonObject.put("title", iRowSet.getString("title"));
 				// 所属部门
@@ -301,7 +323,7 @@ public class SynADService implements IHRMsfService {
 				jsonObject.put("extensionAttribute10", stringDateFormat(iRowSet.getDate("extensionAttribute10")));
 				// 私人手机
 				jsonObject.put("extensionAttribute11", iRowSet.getString("extensionAttribute11"));
-				telephoneNumberSet.add(iRowSet.getString("extensionAttribute11"));
+			
 				// 失效日期
 				jsonObject.put("AccountExpirationDate", AccountExpirationDate);
 				// 再就业标识
@@ -326,7 +348,7 @@ public class SynADService implements IHRMsfService {
 					.append("pe.CFUserName_l1 AS userPrincipalName, ")
 					.append("pe.cfworkemail AS mail, ")
 					.append("pe.femail AS extensionAttribute9, ")
-					.append("pe.FCellPhone AS telephoneNumber, ")
+					.append("pe.FCellPhone AS extensionAttribute11, ")
 					.append("pe.FPositionID, ")
 					.append("pe.FAdminOrgUnitID, ")
 					.append("pe.CFLmanagerID, ")
@@ -391,6 +413,11 @@ public class SynADService implements IHRMsfService {
 				JSONObject jsonObject = new JSONObject();
 				// 用户名
 				jsonObject.put("sAMAccountName", iRowSet2.getString("sAMAccountName"));
+				//去重
+				if(StringUtils.isNotBlank(iRowSet2.getString("sAMAccountName") ) && accountNameSet.contains(iRowSet2.getString("sAMAccountName"))){
+					continue;
+				}
+				accountNameSet.add(iRowSet2.getString("sAMAccountName"));
 				// 名
 				String givenName = iRowSet2.getString("givenName");
 				jsonObject.put("givenName", givenName);
@@ -405,16 +432,9 @@ public class SynADService implements IHRMsfService {
 				// 邮箱地址
 				jsonObject.put("mail", iRowSet2.getString("mail"));
 				// 手机号码
-				if (StringUtils.isNotBlank(iRowSet2.getString("telephoneNumber"))){
-					jsonObject.put("extensionAttribute11", iRowSet2.getString("telephoneNumber"));
-					jsonObject.put("telephoneNumber", iRowSet2.getString("telephoneNumber"));
-					// 手机号码去重,人去重
-					if(telephoneNumberSet.contains(iRowSet2.getString("telephoneNumber"))){
-						continue;
-					}
-					telephoneNumberSet.add(iRowSet2.getString("telephoneNumber"));
-				}
-
+				jsonObject.put("extensionAttribute11", iRowSet2.getString("extensionAttribute11"));
+			 
+				jsonObject.put("telephoneNumber", "");
 				// 职位
 				jsonObject.put("title", iRowSet2.getString("title"));
 				// 所属部门
@@ -500,6 +520,11 @@ public class SynADService implements IHRMsfService {
 				JSONObject jsonObject = new JSONObject();
 				// 用户名
 				jsonObject.put("sAMAccountName", iRowSet3.getString("sAMAccountName"));
+				//去重
+				if(StringUtils.isNotBlank(iRowSet3.getString("sAMAccountName") ) && accountNameSet.contains(iRowSet3.getString("sAMAccountName"))){
+					continue;
+				}
+				accountNameSet.add(iRowSet3.getString("sAMAccountName"));
 				// 名
 				String givenName = iRowSet3.getString("givenName");
 				jsonObject.put("givenName", givenName);
@@ -514,15 +539,10 @@ public class SynADService implements IHRMsfService {
 				// 邮箱地址
 				jsonObject.put("mail", iRowSet3.getString("mail"));
 				// 手机号码
-				if (StringUtils.isNotBlank(iRowSet3.getString("extensionAttribute11"))){
-					jsonObject.put("extensionAttribute11", iRowSet3.getString("extensionAttribute11"));
-					jsonObject.put("telephoneNumber", iRowSet3.getString("extensionAttribute11"));
-					//去重
-					if(telephoneNumberSet.contains(iRowSet3.getString("extensionAttribute11"))){
-						continue;
-					}
-					telephoneNumberSet.add(iRowSet3.getString("extensionAttribute11"));
-				}
+			  	jsonObject.put("extensionAttribute11", iRowSet3.getString("extensionAttribute11"));
+			
+				  //办公号码
+				jsonObject.put("telephoneNumber", "");
 
 				// 职位
 				jsonObject.put("title", iRowSet3.getString("title"));
@@ -563,6 +583,32 @@ public class SynADService implements IHRMsfService {
 			return jSONObject.toJSONString();
 		}
 
+		//循环jsonArray
+		// 1如果extensionAttribute6的值是"Part Time",
+	   	//2.如果"Division"  "extensionAttribute15"  "extensionAttribute14" 的值是否都为空,是,则将 "title" ,"department" ,"manager" 的值分别赋值到对应顺序的位置;
+		//如果条件1满足,则清空"title" ,"department" ,"manager"
+		// 循环jsonArray
+		for (int i = 0; i < jsonArray.size(); i++) {
+			JSONObject jsonObject = jsonArray.getJSONObject(i);
+			// 1如果extensionAttribute6的值是"Part Time",
+			if ("Part Time".equals(jsonObject.getString("extensionAttribute6"))) {
+				// 2.如果"extensionAttribute15"  "Division"  "extensionAttribute14" 的值是否都为空,是,则将 "title" ,"department" ,"manager" 的值分别赋值到对应顺序的位置;
+				if (StringUtils.isBlank(jsonObject.getString("Division"))
+						&& StringUtils.isBlank(jsonObject.getString("extensionAttribute15"))
+						&& StringUtils.isBlank(jsonObject.getString("extensionAttribute14"))) {
+					jsonObject.put("extensionAttribute15", jsonObject.getString("title"));
+					jsonObject.put("Division", jsonObject.getString("department"));
+					jsonObject.put("extensionAttribute14", jsonObject.getString("manager"));
+				}
+				// 清空"title" ,"department" ,"manager"
+				jsonObject.put("title", "");
+				jsonObject.put("department", "");
+				jsonObject.put("manager", "");
+			}
+		}
+
+
+
 		// 构建返回结果
 		JSONObject resultJson = new JSONObject();
 		resultJson.put("code", "1");