From 2849ca841f76b42dfc9dfa9ca568cc439342b89b Mon Sep 17 00:00:00 2001 From: yuxueliang0813 <407010292@qq.com> Date: Wed, 4 Dec 2024 17:07:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=8E=A5=E5=8F=A3=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8F=98=E6=9B=B4=E5=B1=82=E7=BA=A7=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=A4=9A=E4=B8=AA=E8=A7=86=E5=9B=BE=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shkd/bamp/base/task/DobeDWorgTask.java | 76 +++++++++++++++---- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/main/java/shkd/bamp/base/task/DobeDWorgTask.java b/main/java/shkd/bamp/base/task/DobeDWorgTask.java index 03a5039..e5b2ec5 100644 --- a/main/java/shkd/bamp/base/task/DobeDWorgTask.java +++ b/main/java/shkd/bamp/base/task/DobeDWorgTask.java @@ -10,6 +10,7 @@ import kd.bos.db.DBRoute; import kd.bos.exception.KDException; import kd.bos.logging.Log; import kd.bos.logging.LogFactory; +import kd.bos.org.model.OrgDutyView; import kd.bos.org.model.OrgParam; import kd.bos.orm.query.QFilter; import kd.bos.schedule.executor.AbstractTask; @@ -27,6 +28,7 @@ import java.util.*; /** * 后台任务插件 yxl 20240830 + * 组织和人员的相关操作参考 https://dev.kingdee.com/open/detail/sdk/2077750769712378880 */ 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 idlist = new ArrayList<>(); + idlist.add(currentOrg.getLong("id")); + //获取直接上级组织 返回值说明 <组织ID - 上级组织ID> + Map 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) { JSONArray detailsJson = json_body.getJSONArray("data"); // List paramList = new ArrayList<>(); @@ -98,6 +114,8 @@ public class DobeDWorgTask extends AbstractTask implements Plugin { String person_charge = null;//部门下的负责人的工号 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=?);"; + TreeMap multiViewMap = new TreeMap<>(); + OrgDutyView dutyView = null; for (int i = 0; i < detailsJson.size(); i++) { json_body = detailsJson.getJSONObject(i); 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())); 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查找系统现有数据是否存在,这种写法会抛异常,需要关注原因 currentOrg = QueryServiceHelper.queryOne(entityName,"id,number,name",new QFilter[]{new QFilter("fyzjorgid","=",orgID)}); 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}); } //已存在,做更新 - if(orgNumber.equals(currentOrg.getString("number")) && orgName.equals(currentOrg.getString("name"))){ - //编号和名称都没有变化,无需更新 + if(!isNeedUpdate(currentOrg,orgNumber,orgName,parentOrg.getLong("id"))){ + //编号和名称、上级单位都没有变化,无需更新;现在判断不出来上级单位,直接更新 continue; } param = new OrgParam(); param.setId(currentOrg.getLong("id")); param.setName(orgName); 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); if (!param.isSuccess()) { log.info(String.format("组织修改异常:%s", param.getMsg())); } }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.setParentId(parentOrg.getLong("id"));//上级组织的金蝶ID +// param.setParentId(parentOrg.getLong("id"));//上级组织的金蝶ID param.setName(orgName); param.setYzjOrgId(orgID);//云之家组织内码字段,用于保存组织的外部ID param.setNumber(orgNumber); @@ -157,12 +195,22 @@ public class DobeDWorgTask extends AbstractTask implements Plugin { // 设置多视图参数 // TreeMap multiViewMap = new TreeMap<>(); -// OrgDutyView dutyView = new OrgDutyView(); -// dutyView.setParentId(0L);//上级组织的金蝶ID -// multiViewMap.put(OrgViewType.ControlUnit, dutyView); -// param.setMultiViewMap(multiViewMap);//多职能参数 支持一次更新多种业务视图方案;键为视图方案编码(参照本页参数说明的OrgViewType),值为OrgDutyView对象 -// paramList.add(param); + multiViewMap.clear(); + dutyView = new OrgDutyView(); + dutyView.setParentId(parentOrg.getLong("id"));//上级组织的金蝶ID + multiViewMap.put(OrgViewType.Admin, dutyView);//行政组织 + 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); // orgService.add(paramList);