成本中心同步插件遍历修改为倒序

This commit is contained in:
zengweihai 2024-06-29 15:52:06 +08:00
parent cda2891109
commit c9387c0cad
1 changed files with 28 additions and 19 deletions

View File

@ -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<String,String> 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<String, String> 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);
}
}
}