From d716d27dd53312ad49765f0da285dc700d8bb990 Mon Sep 17 00:00:00 2001 From: zengweihai Date: Thu, 27 Jun 2024 17:59:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=90=E6=9C=AC=E4=B8=AD=E5=BF=83=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E6=B7=BB=E5=8A=A0=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E5=88=86=E5=BD=95=EF=BC=8C=E4=BA=BA=E5=91=98?= =?UTF-8?q?=E9=9D=9E=E6=96=B0=E5=A2=9E=E5=8F=96=E6=B6=88=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=83=A8=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cosmic/cxkg/task/CostCenterTaskImpl.java | 99 ++++++++++++++----- .../shkd/cosmic/cxkg/task/UserTaskImpl.java | 46 +++++---- 2 files changed, 97 insertions(+), 48 deletions(-) diff --git a/shkd-cosmic-debug/src/main/java/shkd/cosmic/cxkg/task/CostCenterTaskImpl.java b/shkd-cosmic-debug/src/main/java/shkd/cosmic/cxkg/task/CostCenterTaskImpl.java index 89f3678..be0e63d 100644 --- a/shkd-cosmic-debug/src/main/java/shkd/cosmic/cxkg/task/CostCenterTaskImpl.java +++ b/shkd-cosmic-debug/src/main/java/shkd/cosmic/cxkg/task/CostCenterTaskImpl.java @@ -24,6 +24,9 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; +/** + * 定时任务:更新成本中心和部门信息 + */ public class CostCenterTaskImpl extends AbstractTask { private static Logger logger = LoggerFactory.getLogger(HrmDepartmentTaskImpl.class); @@ -55,8 +58,8 @@ public class CostCenterTaskImpl extends AbstractTask { queryDTO.setCreated(time.toString()); } - //创建人员对应成本中心集合 - HashMap orgMap = new HashMap<>(); + //创建人员对应成本中心、部门集合 + HashMap> orgMap = new HashMap<>(); JSONObject data = this.getOAUserData(query,oaUrl); this.importOrgMap(orgMap,data);//填充人员数据(人员编码,成本中心编码) @@ -81,26 +84,59 @@ public class CostCenterTaskImpl extends AbstractTask { QFilter userQF = new QFilter("number", QCP.equals, key); DynamicObject bos_user = BusinessDataServiceHelper.loadSingle("bos_user", userQF.toArray());//查找星瀚对应人员 if (bos_user != null){//当人员数据不为空时 - String costNumber = orgMap.get(key);//对应的成本中心编码 - QFilter costQFr = new QFilter("number", QCP.equals, costNumber); - DynamicObject bos_costCenter = BusinessDataServiceHelper.loadSingle("bos_costcenter", costQFr.toArray()); - if (bos_costCenter != null){//当成本中心不为空时 - //获取用户的成本中心信息分录 - DynamicObjectCollection costEntity = bos_user.getDynamicObjectCollection("shkd_costentity"); - //首先遍历移除已存在的来源为泛微的数据 - for (int i = 0;i < costEntity.size();i++){ - DynamicObject dynamicObject = costEntity.get(i); - String shkd_e_source = dynamicObject.getString("shkd_e_source"); - if ("B".equals(shkd_e_source)){ - int index = costEntity.indexOf(dynamicObject); - costEntity.remove(index); + boolean changeFlag = false; + HashMap valueMap = orgMap.get(key);//部门及成本中心数据集合 + String departmentcode = valueMap.get("departmentcode");//部门编码 + String costCenterNumber = valueMap.get("costCenterNumber");//成本中心编码 + if (!"".equals(costCenterNumber)){ + //对应的成本中心编码 + QFilter costQFr = new QFilter("number", QCP.equals, costCenterNumber); + DynamicObject bos_costCenter = BusinessDataServiceHelper.loadSingle("bos_costcenter", costQFr.toArray()); + if (bos_costCenter != null){//当成本中心不为空时 + //获取用户的成本中心信息分录 + DynamicObjectCollection costEntity = bos_user.getDynamicObjectCollection("shkd_costentity"); + //首先遍历移除已存在的来源为泛微的数据 + for (int i = 0;i < costEntity.size();i++){ + DynamicObject dynamicObject = costEntity.get(i); + String shkd_e_source = dynamicObject.getString("shkd_e_source"); + if ("B".equals(shkd_e_source)){ + int index = costEntity.indexOf(dynamicObject); + costEntity.remove(index); + } } + DynamicObject newObject = costEntity.addNew(); + newObject.set("shkd_e_cost",bos_costCenter); + newObject.set("shkd_e_source","B"); + changeFlag = true; } - DynamicObject newObject = costEntity.addNew(); - newObject.set("shkd_e_cost",bos_costCenter); - newObject.set("shkd_e_source","B"); - OperationResult operationResult = OperationServiceHelper.executeOperate("save", "bos_user", new DynamicObject[]{bos_user}, option); } + + if (!"".equals(departmentcode)){ + //对应的部门编码 + QFilter deptQFr = new QFilter("number", QCP.equals, departmentcode); + DynamicObject bos_adminorg = BusinessDataServiceHelper.loadSingle("bos_adminorg", deptQFr.toArray()); + if (bos_adminorg != null){//当行政组织不为空时 + //获取人员的组织分录 + DynamicObjectCollection entryentity = bos_user.getDynamicObjectCollection("entryentity");//组织分录 + //首先遍历移除已存在的来源为泛微的数据 + for (int i = 0;i < entryentity.size();i++){ + DynamicObject dynamicObject = entryentity.get(i); + String shkd_deptsource = dynamicObject.getString("shkd_deptsource"); + if ("2".equals(shkd_deptsource)){ + int index = entryentity.indexOf(dynamicObject); + entryentity.remove(index); + } + } + DynamicObject newObject = entryentity.addNew(); + newObject.set("dpt",bos_adminorg);//部门 + newObject.set("position", valueMap.get("position"));//职位 + newObject.set("isincharge",false); + newObject.set("ispartjob",false); + newObject.set("shkd_deptsource","2"); + changeFlag = true; + } + } + OperationResult operationResult = OperationServiceHelper.executeOperate("save", "bos_user", new DynamicObject[]{bos_user}, option); } } @@ -122,17 +158,26 @@ public class CostCenterTaskImpl extends AbstractTask { return data ; } - private void importOrgMap(HashMap orgMap,JSONObject data){ + + /** + * 根据人员接口返回的数据填充创建人员对应成本中心、部门集合 + * sh + * @param orgMap + * @param data + */ + private void importOrgMap(HashMap> orgMap,JSONObject data){ JSONArray dataList = data.getJSONArray("dataList");//oa人员数据集合 - for (int i = 0; i < dataList.size(); i++) { + for (int i = 0; i < dataList.size(); i++) {//遍历 JSONObject userData = dataList.getJSONObject(i); - JSONObject base_custom_data = userData.getJSONObject("base_custom_data"); - if (base_custom_data != null){ - String field0 = base_custom_data.getString("field0"); - if (!"".equals(field0)){ - orgMap.put(userData.getString("workcode"),field0); - } + HashMap valueMap = new HashMap<>(); + valueMap.put("departmentcode",userData.getString("departmentcode"));//设置部门信息 + valueMap.put("position", userData.getString("jobactivityname"));// 职位 + valueMap.put("superior", userData.getString("managerid"));//直接上级 + JSONObject base_custom_data = userData.getJSONObject("base_custom_data");//获取自定义数据包 + if (base_custom_data != null){//设置成本中心数据 + valueMap.put("costCenterNumber",base_custom_data.getString("field0")); } + orgMap.put(userData.getString("workcode"), valueMap); } } } diff --git a/shkd-cosmic-debug/src/main/java/shkd/cosmic/cxkg/task/UserTaskImpl.java b/shkd-cosmic-debug/src/main/java/shkd/cosmic/cxkg/task/UserTaskImpl.java index 10372ae..ca90ce5 100644 --- a/shkd-cosmic-debug/src/main/java/shkd/cosmic/cxkg/task/UserTaskImpl.java +++ b/shkd-cosmic-debug/src/main/java/shkd/cosmic/cxkg/task/UserTaskImpl.java @@ -190,29 +190,33 @@ public class UserTaskImpl extends AbstractTask { } // 职位分 if(workid == null){//若人不存在则更新部门 - - } - List> posList = new ArrayList<>(); - Map entryentity = new HashMap<>(); - // 通过编码设置部门 - Map dptNumMap = new HashMap<>(); - dptNumMap.put("number", userData.getString("departmentcode")); - entryentity.put("dpt",dptNumMap ); // 部门 - entryentity.put("position", userData.getString("jobactivityname")); // 职位 - entryentity.put("isincharge", false); //负责人 - entryentity.put("ispartjob", false); //兼职 - String managerId_oa = userData.getString("managerid");//获取上级人员id(oa) - Long managerId = userIds.get(managerId_oa);//直接上级id - if (managerId != null){ - entryentity.put("superior", managerId); // 赋值直接上级 - }else { - if (!"".equals(managerId_oa)){//当上级人员id(oa)存在且未在星瀚系统检索成功时,修改参数flag,接口将重新构造人员类更新数据 - flag = true; + List> posList = new ArrayList<>(); + Map entryentity = new HashMap<>(); + // 通过编码设置部门 + Map dptNumMap = new HashMap<>(); + String departmentcode = userData.getString("departmentcode"); + if (departmentcode.isEmpty()){ + logger.info("人员:"+userData.getString("lastname")+",所属部门编码未携带,新增用户时会导致失败"); } + dptNumMap.put("number", departmentcode); + entryentity.put("dpt",dptNumMap ); // 部门 + entryentity.put("position", userData.getString("jobactivityname")); // 职位 + entryentity.put("isincharge", false); //负责人 + entryentity.put("ispartjob", false); //兼职 + entryentity.put("shkd_deptsource","2");//来源设置为泛微 + String managerId_oa = userData.getString("managerid");//获取上级人员id(oa) + Long managerId = userIds.get(managerId_oa);//直接上级id + if (managerId != null){ + entryentity.put("superior", managerId); // 赋值直接上级 + }else { + if (!"".equals(managerId_oa)){//当上级人员id(oa)存在且未在星瀚系统检索成功时,修改参数flag,接口将重新构造人员类更新数据 + flag = true; + } + } + entryentity.put("seq", 1); + posList.add(entryentity); + dataMap.put("entryentity", posList); } - entryentity.put("seq", 1); - posList.add(entryentity); - dataMap.put("entryentity", posList); user.setDataMap(dataMap); paramList.add(user); }