组织接口增加变更层级,增加多个视图设置功能

This commit is contained in:
yuxueliang0813 2024-12-04 17:07:41 +08:00
parent b36597ab05
commit 2849ca841f
1 changed files with 62 additions and 14 deletions

View File

@ -10,6 +10,7 @@ import kd.bos.db.DBRoute;
import kd.bos.exception.KDException; import kd.bos.exception.KDException;
import kd.bos.logging.Log; import kd.bos.logging.Log;
import kd.bos.logging.LogFactory; import kd.bos.logging.LogFactory;
import kd.bos.org.model.OrgDutyView;
import kd.bos.org.model.OrgParam; import kd.bos.org.model.OrgParam;
import kd.bos.orm.query.QFilter; import kd.bos.orm.query.QFilter;
import kd.bos.schedule.executor.AbstractTask; import kd.bos.schedule.executor.AbstractTask;
@ -27,6 +28,7 @@ import java.util.*;
/** /**
* 后台任务插件 yxl 20240830 * 后台任务插件 yxl 20240830
* 组织和人员的相关操作参考 https://dev.kingdee.com/open/detail/sdk/2077750769712378880
*/ */
public class DobeDWorgTask extends AbstractTask implements Plugin { public class DobeDWorgTask extends AbstractTask implements Plugin {
@ -85,6 +87,20 @@ public class DobeDWorgTask extends AbstractTask implements Plugin {
} }
} }
private boolean isNeedUpdate(DynamicObject currentOrg,String orgNumber,String orgName,Long parentId){
if(!orgNumber.equals(currentOrg.getString("number")) || !orgName.equals(currentOrg.getString("name"))){
return true;
}
List<Long> idlist = new ArrayList<>();
idlist.add(currentOrg.getLong("id"));
//获取直接上级组织 返回值说明 <组织ID - 上级组织ID>
Map<Long,Long> maprs = OrgUnitServiceHelper.getDirectSuperiorOrg(OrgViewType.Admin,idlist);
if(maprs != null && !parentId.equals(maprs.get(idlist.get(0)))){
return true;
}
return false;
}
private void handleOrg(JSONObject json_body) { private void handleOrg(JSONObject json_body) {
JSONArray detailsJson = json_body.getJSONArray("data"); JSONArray detailsJson = json_body.getJSONArray("data");
// List<OrgParam> paramList = new ArrayList<>(); // List<OrgParam> paramList = new ArrayList<>();
@ -98,6 +114,8 @@ public class DobeDWorgTask extends AbstractTask implements Plugin {
String person_charge = null;//部门下的负责人的工号 String person_charge = null;//部门下的负责人的工号
String updateNocgeSql = "UPDATE t_SEC_UserPosition SET fisincharge=? WHERE fdptid in (select fid from t_org_org where fyzjorgid=?);"; String updateNocgeSql = "UPDATE t_SEC_UserPosition SET fisincharge=? WHERE fdptid in (select fid from t_org_org where fyzjorgid=?);";
String updatecgeSql = "UPDATE t_SEC_UserPosition SET fisincharge=? WHERE fdptid in (select fid from t_org_org where fyzjorgid=?) and fid in (select fid from t_sec_user where fnumber=?);"; String updatecgeSql = "UPDATE t_SEC_UserPosition SET fisincharge=? WHERE fdptid in (select fid from t_org_org where fyzjorgid=?) and fid in (select fid from t_sec_user where fnumber=?);";
TreeMap<String, OrgDutyView> multiViewMap = new TreeMap<>();
OrgDutyView dutyView = null;
for (int i = 0; i < detailsJson.size(); i++) { for (int i = 0; i < detailsJson.size(); i++) {
json_body = detailsJson.getJSONObject(i); json_body = detailsJson.getJSONObject(i);
orgNumber = json_body.getString("org_code"); orgNumber = json_body.getString("org_code");
@ -112,6 +130,12 @@ public class DobeDWorgTask extends AbstractTask implements Plugin {
log.info(String.format("组织入参为空异常:%s", json_body.toJSONString())); log.info(String.format("组织入参为空异常:%s", json_body.toJSONString()));
continue; continue;
} }
//根据父级ID获取父级组织对象,组织的主数据id存在于星瀚组织的fyzjorgid字段中
parentOrg = QueryServiceHelper.queryOne(entityName,"id,number,name",new QFilter[]{new QFilter("fyzjorgid","=",parentId)});
if(parentOrg == null){
log.info(String.format("根据数仓组织父级ID未在金蝶中找到对应组织%s", parentId));
continue;
}
//根据组织ID查找系统现有数据是否存在这种写法会抛异常需要关注原因 //根据组织ID查找系统现有数据是否存在这种写法会抛异常需要关注原因
currentOrg = QueryServiceHelper.queryOne(entityName,"id,number,name",new QFilter[]{new QFilter("fyzjorgid","=",orgID)}); currentOrg = QueryServiceHelper.queryOne(entityName,"id,number,name",new QFilter[]{new QFilter("fyzjorgid","=",orgID)});
if(currentOrg != null){ if(currentOrg != null){
@ -121,28 +145,42 @@ public class DobeDWorgTask extends AbstractTask implements Plugin {
DB.update(DBRoute.of("sys"), updatecgeSql, new Object[]{1,orgID,person_charge}); DB.update(DBRoute.of("sys"), updatecgeSql, new Object[]{1,orgID,person_charge});
} }
//已存在做更新 //已存在做更新
if(orgNumber.equals(currentOrg.getString("number")) && orgName.equals(currentOrg.getString("name"))){ if(!isNeedUpdate(currentOrg,orgNumber,orgName,parentOrg.getLong("id"))){
//编号和名称都没有变化无需更新 //编号和名称上级单位都没有变化无需更新现在判断不出来上级单位直接更新
continue; continue;
} }
param = new OrgParam(); param = new OrgParam();
param.setId(currentOrg.getLong("id")); param.setId(currentOrg.getLong("id"));
param.setName(orgName); param.setName(orgName);
param.setNumber(orgNumber); param.setNumber(orgNumber);
// param.setParentId(parentOrg.getLong("id"));//上级组织的金蝶ID
//设置多视图参数
multiViewMap.clear();
dutyView = new OrgDutyView();
//组织移动时设置新的上级ID
dutyView.setParentId(parentOrg.getLong("id"));
//行政组织
multiViewMap.put(OrgViewType.Admin, dutyView);
//每种视图方案的参数对象不能用同一个需要单独实例化
dutyView = new OrgDutyView();
dutyView.setParentId(parentOrg.getLong("id"));
//业务单元
multiViewMap.put(OrgViewType.OrgUnit, dutyView);
//采购组织
// dutyView = new OrgDutyView();
// dutyView.setParentId(parentOrg.getLong("id"));
// multiViewMap.put(OrgViewType.Asset, dutyView);
param.setMultiViewMap(multiViewMap);
OrgUnitServiceHelper.update(param); OrgUnitServiceHelper.update(param);
if (!param.isSuccess()) { if (!param.isSuccess()) {
log.info(String.format("组织修改异常:%s", param.getMsg())); log.info(String.format("组织修改异常:%s", param.getMsg()));
} }
}else{ }else{
//根据父级ID获取父级组织对象,组织的主数据id存在于星瀚组织的fyzjorgid字段中
parentOrg = QueryServiceHelper.queryOne(entityName,"id,number,name",new QFilter[]{new QFilter("fyzjorgid","=",parentId)});
if(parentOrg == null){
log.info(String.format("根据数仓组织父级ID未在金蝶中找到对应组织%s", parentId));
continue;
}
/* 新增单个视图方案的组织 */ /* 新增单个视图方案的组织 */
param = new OrgParam(); param = new OrgParam();
param.setParentId(parentOrg.getLong("id"));//上级组织的金蝶ID // param.setParentId(parentOrg.getLong("id"));//上级组织的金蝶ID
param.setName(orgName); param.setName(orgName);
param.setYzjOrgId(orgID);//云之家组织内码字段用于保存组织的外部ID param.setYzjOrgId(orgID);//云之家组织内码字段用于保存组织的外部ID
param.setNumber(orgNumber); param.setNumber(orgNumber);
@ -157,12 +195,22 @@ public class DobeDWorgTask extends AbstractTask implements Plugin {
// 设置多视图参数 // 设置多视图参数
// TreeMap<String, OrgDutyView> multiViewMap = new TreeMap<>(); // TreeMap<String, OrgDutyView> multiViewMap = new TreeMap<>();
// OrgDutyView dutyView = new OrgDutyView(); multiViewMap.clear();
// dutyView.setParentId(0L);//上级组织的金蝶ID dutyView = new OrgDutyView();
// multiViewMap.put(OrgViewType.ControlUnit, dutyView); dutyView.setParentId(parentOrg.getLong("id"));//上级组织的金蝶ID
// param.setMultiViewMap(multiViewMap);//多职能参数 支持一次更新多种业务视图方案键为视图方案编码参照本页参数说明的OrgViewType值为OrgDutyView对象 multiViewMap.put(OrgViewType.Admin, dutyView);//行政组织
// paramList.add(param); dutyView = new OrgDutyView();
dutyView.setParentId(parentOrg.getLong("id"));//上级组织的金蝶ID
multiViewMap.put(OrgViewType.OrgUnit, dutyView);//业务单元
dutyView = new OrgDutyView();
dutyView.setParentId(parentOrg.getLong("id"));//上级组织的金蝶ID
multiViewMap.put(OrgViewType.Accounting, dutyView);//核算组织
dutyView = new OrgDutyView();
dutyView.setParentId(parentOrg.getLong("id"));//上级组织的金蝶ID
multiViewMap.put(OrgViewType.Purchase, dutyView);//采购组织
param.setMultiViewMap(multiViewMap);//多职能参数 支持一次更新多种业务视图方案键为视图方案编码参照本页参数说明的OrgViewType值为OrgDutyView对象
// paramList.add(param);
// 执行并判断结果如下是微服务模式调用会提示服务找不到 // 执行并判断结果如下是微服务模式调用会提示服务找不到
// IOrgService orgService = ServiceFactory.getService(OrgService.class); // IOrgService orgService = ServiceFactory.getService(OrgService.class);
// orgService.add(paramList); // orgService.add(paramList);