From c9387c0cad32d534892b82b8c9d36146098c2c5c Mon Sep 17 00:00:00 2001 From: zengweihai Date: Sat, 29 Jun 2024 15:52:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=90=E6=9C=AC=E4=B8=AD=E5=BF=83=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=8F=92=E4=BB=B6=E9=81=8D=E5=8E=86=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=80=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cosmic/cxkg/task/CostCenterTaskImpl.java | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 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 a8d8b26..f833095 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 @@ -83,14 +83,8 @@ public class CostCenterTaskImpl extends AbstractTask { for (String key : keys) { QFilter userQF = new QFilter("number", QCP.equals, key); DynamicObject bos_user = BusinessDataServiceHelper.loadSingle("bos_user", userQF.toArray());//查找星瀚对应人员 -// if(bos_user.getString("name").equals("周思悦")){ -// System.out.println("11"); -// } if (bos_user != null){//当人员数据不为空时 boolean changeFlag = false; - if(bos_user.getString("name").equals("周思悦")){ - System.out.println("11"); - } HashMap valueMap = orgMap.get(key);//部门及成本中心数据集合 String departmentcode = valueMap.get("departmentcode");//部门编码 String costCenterNumber = valueMap.get("costCenterNumber");//成本中心编码 @@ -102,20 +96,28 @@ public class CostCenterTaskImpl extends AbstractTask { //获取用户的成本中心信息分录 DynamicObjectCollection costEntity = bos_user.getDynamicObjectCollection("shkd_costentity"); int costSize = costEntity.size(); - //首先遍历移除已存在的来源为泛微的数据 - for (int i = costSize-1 ;i >= 0;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); + if (costSize > 0){ + //首先遍历移除已存在的来源为泛微的数据 + for (int i = costSize-1 ;i >= 0;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; + }else { + 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"); - changeFlag = true; } } @@ -145,7 +147,13 @@ public class CostCenterTaskImpl extends AbstractTask { changeFlag = true; } } - OperationResult operationResult = OperationServiceHelper.executeOperate("save", "bos_user", new DynamicObject[]{bos_user}, option); + if(changeFlag){//当数据发生变更时保存数据 + OperationResult operationResult = OperationServiceHelper.executeOperate("save", "bos_user", new DynamicObject[]{bos_user}, option); + boolean success = operationResult.isSuccess(); + if (!success){ + logger.info(bos_user.getString("name")+"保存失败,"+operationResult.getMessage()); + } + } } } @@ -178,6 +186,7 @@ public class CostCenterTaskImpl extends AbstractTask { JSONArray dataList = data.getJSONArray("dataList");//oa人员数据集合 for (int i = 0; i < dataList.size(); i++) {//遍历 JSONObject userData = dataList.getJSONObject(i); + String workcode = userData.getString("workcode"); HashMap valueMap = new HashMap<>(); valueMap.put("departmentcode",userData.getString("departmentcode"));//设置部门信息 valueMap.put("position", userData.getString("jobactivityname"));// 职位 @@ -186,7 +195,7 @@ public class CostCenterTaskImpl extends AbstractTask { if (base_custom_data != null){//设置成本中心数据 valueMap.put("costCenterNumber",base_custom_data.getString("field0")); } - orgMap.put(userData.getString("workcode"), valueMap); + orgMap.put(workcode, valueMap); } } }