业务单元分配部门插件更新

This commit is contained in:
zengweihai 2024-06-28 14:05:49 +08:00
parent c961907162
commit fbac3eb04e
1 changed files with 40 additions and 28 deletions

View File

@ -14,6 +14,7 @@ import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.operation.OperationServiceHelper; import kd.bos.servicehelper.operation.OperationServiceHelper;
import kd.bos.servicehelper.org.OrgUnitServiceHelper; import kd.bos.servicehelper.org.OrgUnitServiceHelper;
import kd.sdk.plugin.Plugin; import kd.sdk.plugin.Plugin;
import kd.tmc.tm.business.validate.business.BusinessUnauditOpValidator;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -32,36 +33,47 @@ public class DefaultAdminOrgRelationTaskImpl extends AbstractTask implements Plu
@Override @Override
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException { public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
List<Long> orgIds_query = new ArrayList<>(); List<Long> orgIds_query = new ArrayList<>();
orgIds_query.add(1947801724118892544L);//1947801724118892544L QFilter numberQF = new QFilter("number", QCP.equals, "Q-003-001");
//查询上海晨曦私募基金管理有限公司分配的行政组织集合 DynamicObject org = BusinessDataServiceHelper.loadSingle("bos_org", "id", numberQF.toArray());
List<Long> adminOrgRelation = OrgUnitServiceHelper.getAdminOrgRelation(orgIds_query,true); if (org != null){
//查询oa同步的行政组织 long orgID = org.getLong("id");
QFilter qf = new QFilter("number",QCP.not_equals,"16005873"); orgIds_query.add(orgID);
qf.and("shkd_oaid",QCP.not_equals,""); //查询上海晨曦私募基金管理有限公司分配的行政组织集合
DynamicObjectCollection queryOrges = QueryServiceHelper.query("bos_adminorg", "id,number,name", qf.toArray()); List<Long> adminOrgRelation = OrgUnitServiceHelper.getAdminOrgRelation(orgIds_query,true);
int i = 0; //查询oa同步的行政组织
OperateOption option = OperateOption.create(); QFilter qf = new QFilter("number",QCP.not_equals,"16005873");
qf.and("shkd_oaid",QCP.not_equals,"");
logger.info("开始查询oa同步过来的行政组织");
DynamicObjectCollection queryOrges = QueryServiceHelper.query("bos_adminorg", "id,number,name", qf.toArray());
logger.info("查询的oa行政组织为"+queryOrges.toString());
QFilter org_typerelation_qFilter = new QFilter("number", QCP.equals, "orgunit2admin");//设置为业务单元委托行政组织
DynamicObject typerelation_dynamicObject = BusinessDataServiceHelper.loadSingle("bos_org_typerelation", "id", org_typerelation_qFilter.toArray());
int i = 0;
OperateOption option = OperateOption.create();
// List<DynamicObject> dys = new ArrayList<>();//设置对象集合 // List<DynamicObject> dys = new ArrayList<>();//设置对象集合
for (DynamicObject queryOrg : queryOrges) { for (DynamicObject queryOrg : queryOrges) {
long id = queryOrg.getLong("id"); long id = queryOrg.getLong("id");
if (!adminOrgRelation.contains(id)){//当查询出的行政组织还没分配给该业务单元时创建分配关系 if (!adminOrgRelation.contains(id)){//当查询出的行政组织还没分配给该业务单元时创建分配关系
i++; i++;
logger.info(""+i+""+"组织:"+queryOrg.get("name")+",还未分配部门,准备分配中......"); logger.info(""+i+""+"组织:"+queryOrg.get("name")+",还未分配部门,准备分配中......");
DynamicObject newDynamicObject = BusinessDataServiceHelper.newDynamicObject("bos_org_orgrelation_dept");//创建实体对象 DynamicObject newDynamicObject = BusinessDataServiceHelper.newDynamicObject("bos_org_orgrelation_dept");//创建实体对象
DynamicObject newOrg = BusinessDataServiceHelper.newDynamicObject("bos_org");//业务单元 DynamicObject newOrg = BusinessDataServiceHelper.newDynamicObject("bos_org");//业务单元固定为上海晨曦私募基金管理有限公司分或编码为Q-003-001
newOrg.set("id",1947801724118892544L); newOrg.set("id",orgID);
DynamicObject newAdminOrg = BusinessDataServiceHelper.newDynamicObject("bos_adminorg");//行政组织 logger.info(""+i+"次分配操作,业务单元元素为:"+newOrg.toString());
newAdminOrg.set("id",id); DynamicObject newAdminOrg = BusinessDataServiceHelper.newDynamicObject("bos_adminorg");//行政组织
DynamicObject newOrgDuty = BusinessDataServiceHelper.newDynamicObject("bos_org_duty");//部门属性 newAdminOrg.set("id",id);
newOrgDuty.set("id",1L); logger.info(""+i+"次分配操作,行政组织元素为:"+newAdminOrg.toString());
DynamicObject newOrgTypeRelation = BusinessDataServiceHelper.newDynamicObject("bos_org_typerelation");//协作关系类型 DynamicObject newOrgDuty = BusinessDataServiceHelper.newDynamicObject("bos_org_duty");//部门属性
newOrgTypeRelation.set("id",585511977942548480L); newOrgDuty.set("id",1L);
newDynamicObject.set("fromorg",newOrg); logger.info(""+i+"次分配操作,部门属性元素为:"+newOrgDuty.toString());
newDynamicObject.set("toorg",newAdminOrg); newDynamicObject.set("fromorg",newOrg);
newDynamicObject.set("orgduty",newOrgDuty); newDynamicObject.set("toorg",newAdminOrg);
newDynamicObject.set("typerelation",newOrgTypeRelation); newDynamicObject.set("orgduty",newOrgDuty);
OperationServiceHelper.executeOperate("save", "bos_adminorg", new DynamicObject[]{newDynamicObject}, option); newDynamicObject.set("typerelation",typerelation_dynamicObject);//统一设置为业务单元委托行政组织
OperationServiceHelper.executeOperate("save", "bos_org_orgrelation_dept", new DynamicObject[]{newDynamicObject}, option);
}
} }
} }
} }
} }