评估、考察优化
This commit is contained in:
		
							parent
							
								
									2e79fce459
								
							
						
					
					
						commit
						0945792f90
					
				| 
						 | 
				
			
			@ -0,0 +1,226 @@
 | 
			
		|||
package shkd.repc.resm.formplugin;
 | 
			
		||||
 | 
			
		||||
import kd.bos.dataentity.OperateOption;
 | 
			
		||||
import kd.bos.dataentity.entity.DynamicObject;
 | 
			
		||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
 | 
			
		||||
import kd.bos.entity.operate.Submit;
 | 
			
		||||
import kd.bos.form.events.AfterDoOperationEventArgs;
 | 
			
		||||
import kd.bos.form.events.BeforeDoOperationEventArgs;
 | 
			
		||||
import kd.bos.form.operate.FormOperate;
 | 
			
		||||
import kd.bos.form.plugin.AbstractFormPlugin;
 | 
			
		||||
import kd.bos.logging.Log;
 | 
			
		||||
import kd.bos.logging.LogFactory;
 | 
			
		||||
import kd.bos.orm.query.QCP;
 | 
			
		||||
import kd.bos.orm.query.QFilter;
 | 
			
		||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.org.OrgUnitServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.org.OrgViewType;
 | 
			
		||||
import kd.sdk.plugin.Plugin;
 | 
			
		||||
import shkd.utils.SetUtils;
 | 
			
		||||
 | 
			
		||||
import java.math.BigDecimal;
 | 
			
		||||
import java.math.RoundingMode;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 动态表单插件
 | 
			
		||||
 * 自动设置评估人
 | 
			
		||||
 */
 | 
			
		||||
public class SetAssessFormPlugin extends AbstractFormPlugin implements Plugin {
 | 
			
		||||
 | 
			
		||||
    private static final Log logger = LogFactory.getLog(SetObjectFormPlugin.class);
 | 
			
		||||
 | 
			
		||||
    private static final Set<Long> userIdSet = new HashSet<>();
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void beforeDoOperation(BeforeDoOperationEventArgs args) {
 | 
			
		||||
        super.beforeDoOperation(args);
 | 
			
		||||
        FormOperate source = (FormOperate) args.getSource();
 | 
			
		||||
        String operateKey = source.getOperateKey();
 | 
			
		||||
        if ("submit".equals(operateKey)) {
 | 
			
		||||
            Submit submit = (Submit) args.getSource();
 | 
			
		||||
            String entityId = submit.getEntityId();
 | 
			
		||||
            if ("resm_evaltask_new".equals(entityId)) {
 | 
			
		||||
                // 获取取值逻辑
 | 
			
		||||
                DynamicObject dataModel = BusinessDataServiceHelper.loadSingle("qeug_datamodel", (new QFilter("qeug_projectsource2", QCP.equals, "评估任务")).toArray());
 | 
			
		||||
                if (dataModel == null) return;
 | 
			
		||||
                Object value = this.getModel().getValue("id");
 | 
			
		||||
                DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(value, entityId);
 | 
			
		||||
                Long orgId;
 | 
			
		||||
                DynamicObjectCollection evalDetail = dynamicObject.getDynamicObjectCollection("evaldetail");
 | 
			
		||||
                if (evalDetail == null || evalDetail.isEmpty()) return;
 | 
			
		||||
                for (DynamicObject evalDetailEntry : evalDetail) {
 | 
			
		||||
                    userIdSet.clear();
 | 
			
		||||
                    //项目
 | 
			
		||||
                    DynamicObject project = evalDetailEntry.getDynamicObject("project");
 | 
			
		||||
                    if (null != project) {
 | 
			
		||||
                        QFilter qFilter1 = new QFilter("id", QCP.equals, project.get("id"));
 | 
			
		||||
                        DynamicObject dynamicObject1 = BusinessDataServiceHelper.loadSingle("repmd_projectbill", qFilter1.toArray());
 | 
			
		||||
                        if (null != dynamicObject1) {
 | 
			
		||||
                            //项目所属组织
 | 
			
		||||
                            DynamicObject org = dynamicObject1.getDynamicObject("org");
 | 
			
		||||
                            if (org == null) return;
 | 
			
		||||
                            orgId = org.getLong("id");
 | 
			
		||||
                            //取值范围
 | 
			
		||||
                            DynamicObjectCollection dataModelEntry = dataModel.getDynamicObjectCollection("entryentity");
 | 
			
		||||
                            //工作流角色
 | 
			
		||||
                            List<DynamicObject> matchingRoles = SetUtils.getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
                            //获取评估详情-标准项设置分录
 | 
			
		||||
                            Object pkValue = evalDetailEntry.getPkValue();
 | 
			
		||||
                            QFilter qFilter = new QFilter("evaldetailid", QCP.equals, pkValue);
 | 
			
		||||
                            DynamicObject dynamicObject2 = BusinessDataServiceHelper.loadSingle("resm_subevaldetail", qFilter.toArray());
 | 
			
		||||
                            if (dynamicObject2 != null) {
 | 
			
		||||
                                DynamicObjectCollection entry = dynamicObject2.getDynamicObjectCollection("entry_evaldetail");
 | 
			
		||||
                                if (entry != null && entry.size() != 0) {
 | 
			
		||||
                                    // 如果有匹配项
 | 
			
		||||
                                    if (!((List<?>) matchingRoles).isEmpty()) {
 | 
			
		||||
                                        creatExamData(matchingRoles, entry, evalDetailEntry,"resm_evaluator_new");
 | 
			
		||||
                                    } else {
 | 
			
		||||
                                        findParentOrgMatch(entry, orgId, dataModelEntry, evalDetailEntry,"resm_evaluator_new");
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    if (userIdSet.size() != 0) {
 | 
			
		||||
                        DynamicObjectCollection evalUsers = evalDetailEntry.getDynamicObjectCollection("evalusers");
 | 
			
		||||
                        evalUsers.clear();
 | 
			
		||||
                        DynamicObjectCollection userObjects = new DynamicObjectCollection();
 | 
			
		||||
                        for (Long userid : userIdSet) {
 | 
			
		||||
                            DynamicObject dynamicObject1 = new DynamicObject(evalUsers.getDynamicObjectType());
 | 
			
		||||
                            dynamicObject1.set("fbasedataid", userid);
 | 
			
		||||
                            userObjects.add(dynamicObject1);
 | 
			
		||||
                        }
 | 
			
		||||
                        evalDetailEntry.set("evalusers", userObjects);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                SaveServiceHelper.save(new DynamicObject[]{dynamicObject});
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void afterDoOperation(AfterDoOperationEventArgs e) {
 | 
			
		||||
        super.afterDoOperation(e);
 | 
			
		||||
        FormOperate source = (FormOperate) e.getSource();
 | 
			
		||||
        String operateKey = source.getOperateKey();
 | 
			
		||||
        if ("submit".equals(operateKey)) {
 | 
			
		||||
            this.getView().invokeOperation("refresh");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 递归查找上级组织
 | 
			
		||||
     *
 | 
			
		||||
     * @param entry          考察任务分录
 | 
			
		||||
     * @param orgId          当前工作流角色组织
 | 
			
		||||
     * @param dataModelEntry 取数模板
 | 
			
		||||
     */
 | 
			
		||||
    private void findParentOrgMatch(DynamicObjectCollection entry, Long orgId, DynamicObjectCollection dataModelEntry,DynamicObject evalDetailEntry, String logotype) {
 | 
			
		||||
        if (orgId == null) return;
 | 
			
		||||
        //取上级组织.
 | 
			
		||||
        List<Long> dptIds = new ArrayList<>();
 | 
			
		||||
        dptIds.add(orgId);
 | 
			
		||||
        Map<Long, Long> orgParentMap = OrgUnitServiceHelper.getDirectSuperiorOrg(OrgViewType.Admin, dptIds);
 | 
			
		||||
        if (orgParentMap != null) {
 | 
			
		||||
            Long parentId = orgParentMap.get(orgId);
 | 
			
		||||
            DynamicObject parentOrg = BusinessDataServiceHelper.loadSingle(parentId, "bos_adminorg");
 | 
			
		||||
            if (parentOrg != null) {
 | 
			
		||||
                orgId = parentOrg.getLong("id");
 | 
			
		||||
                // 使用 Stream API 获取所有匹配的 role 对象
 | 
			
		||||
 | 
			
		||||
                List<DynamicObject> matchingRoles = SetUtils.getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
 | 
			
		||||
                // 如果有匹配项,则返回;否则递归查找上级组织
 | 
			
		||||
                if (!matchingRoles.isEmpty()) {
 | 
			
		||||
                    creatExamData(matchingRoles, entry,evalDetailEntry, logotype);
 | 
			
		||||
                } else {
 | 
			
		||||
                    findParentOrgMatch(entry, orgId, dataModelEntry,evalDetailEntry, logotype); // 没有匹配项,递归调用上级组织
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 生成考察人
 | 
			
		||||
     *
 | 
			
		||||
     * @param matchingRoles 收集符合条件的人员
 | 
			
		||||
     * @param entry         考察任务分录
 | 
			
		||||
     * @param logotype      考察人||评估人权重设置分录
 | 
			
		||||
     */
 | 
			
		||||
    private void creatExamData(List<DynamicObject> matchingRoles, DynamicObjectCollection entry,DynamicObject evalDetailEntry, String logotype) {
 | 
			
		||||
        // 所有考察人(含重复)
 | 
			
		||||
        int totalCount = matchingRoles.size();
 | 
			
		||||
        // 统计每个用户出现的次数
 | 
			
		||||
        Map<Long, Long> userCountMap = new HashMap<>();
 | 
			
		||||
        for (DynamicObject matchingRole : matchingRoles) {
 | 
			
		||||
            Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
            userCountMap.put(userId, userCountMap.getOrDefault(userId, 0L) + 1);
 | 
			
		||||
        }
 | 
			
		||||
        // 去重:使用 Map 按照 userId 去重
 | 
			
		||||
        Map<Long, DynamicObject> uniqueUserMap = new HashMap<>();
 | 
			
		||||
        for (DynamicObject matchingRole : matchingRoles) {
 | 
			
		||||
            Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
            if (!uniqueUserMap.containsKey(userId)) {
 | 
			
		||||
                uniqueUserMap.put(userId, matchingRole);  // 保留第一次遇到的匹配角色
 | 
			
		||||
                userIdSet.add(userId);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        // 获取去重后的列表
 | 
			
		||||
        List<DynamicObject> uniqueMatchingRoles = new ArrayList<>(uniqueUserMap.values());
 | 
			
		||||
 | 
			
		||||
        for (int i = 0; i < entry.size(); i++) {
 | 
			
		||||
            StringBuilder objectText = new StringBuilder();
 | 
			
		||||
            //评估人及权重设置表
 | 
			
		||||
            QFilter qFilter = new QFilter("evalentryid", QCP.equals, entry.get(i).getPkValue());
 | 
			
		||||
            DynamicObject examuatorNew = BusinessDataServiceHelper.loadSingle(logotype, qFilter.toArray());
 | 
			
		||||
            if (examuatorNew == null) {
 | 
			
		||||
                examuatorNew = BusinessDataServiceHelper.newDynamicObject(logotype);
 | 
			
		||||
                long pkValue = entry.get(i).getLong("id");
 | 
			
		||||
                examuatorNew.set("evalentryid", pkValue);
 | 
			
		||||
                examuatorNew.set("evaldetailentryid", evalDetailEntry.getLong("id"));
 | 
			
		||||
                //评估人及权重设置表分录
 | 
			
		||||
                DynamicObjectCollection entryCollection = examuatorNew.getDynamicObjectCollection("entry_evaluator");
 | 
			
		||||
                for (int j = 0; j < uniqueMatchingRoles.size(); j++) {
 | 
			
		||||
                    DynamicObject matchingRole = uniqueMatchingRoles.get(j);
 | 
			
		||||
                    DynamicObject evaluator = entryCollection.addNew();
 | 
			
		||||
                    evaluator.set("user", matchingRole.getLong("user.id"));
 | 
			
		||||
                    evaluator.set("userposition", matchingRole.getLong("userposition.id"));
 | 
			
		||||
                    String name = matchingRole.getString("user.name");
 | 
			
		||||
                    // 根据总人数和该用户的出现次数来计算权重
 | 
			
		||||
                    Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
                    Long userCount = userCountMap.get(userId);
 | 
			
		||||
                    BigDecimal weight = new BigDecimal((1.0 / totalCount) * userCount).setScale(2, RoundingMode.HALF_UP);
 | 
			
		||||
                    String weightPercentage = SetUtils.formatWeight(weight);
 | 
			
		||||
                    objectText.append(name).append("(").append(weightPercentage).append(");");
 | 
			
		||||
                    evaluator.set("weight", weight);
 | 
			
		||||
                    evaluator.set("seq", j + 1);
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                DynamicObjectCollection setBillEntry = examuatorNew.getDynamicObjectCollection("entry_evaluator");
 | 
			
		||||
                setBillEntry.clear();
 | 
			
		||||
                for (int j = 0; j < uniqueMatchingRoles.size(); j++) {
 | 
			
		||||
                    DynamicObject matchingRole = uniqueMatchingRoles.get(j);
 | 
			
		||||
                    DynamicObject evaluator = setBillEntry.addNew();
 | 
			
		||||
                    evaluator.set("user", matchingRole.getDynamicObject("user"));
 | 
			
		||||
                    evaluator.set("userposition", matchingRole.getDynamicObject("userposition"));
 | 
			
		||||
                    String name = matchingRole.getString("user.name");
 | 
			
		||||
                    // 根据总人数和该用户的出现次数来计算权重
 | 
			
		||||
                    Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
                    Long userCount = userCountMap.get(userId);
 | 
			
		||||
                    BigDecimal weight = new BigDecimal((1.0 / totalCount) * userCount).setScale(2, RoundingMode.HALF_UP);
 | 
			
		||||
                    String weightPercentage = SetUtils.formatWeight(weight);
 | 
			
		||||
                    objectText.append(name).append("(").append(weightPercentage).append(");");
 | 
			
		||||
                    evaluator.set("weight", weight);
 | 
			
		||||
                    evaluator.set("seq", j + 1);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            entry.get(i).set("entryevaluatorstr", objectText);
 | 
			
		||||
            SaveServiceHelper.save(new DynamicObject[]{examuatorNew});
 | 
			
		||||
            SaveServiceHelper.update(entry.get(i));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,237 @@
 | 
			
		|||
package shkd.repc.resm.formplugin;
 | 
			
		||||
 | 
			
		||||
import kd.bos.dataentity.OperateOption;
 | 
			
		||||
import kd.bos.dataentity.entity.DynamicObject;
 | 
			
		||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
 | 
			
		||||
import kd.bos.form.control.Toolbar;
 | 
			
		||||
import kd.bos.form.control.events.BeforeItemClickEvent;
 | 
			
		||||
import kd.bos.list.BillList;
 | 
			
		||||
import kd.bos.list.plugin.AbstractListPlugin;
 | 
			
		||||
import kd.bos.logging.Log;
 | 
			
		||||
import kd.bos.logging.LogFactory;
 | 
			
		||||
import kd.bos.mvc.list.ListView;
 | 
			
		||||
import kd.bos.orm.query.QCP;
 | 
			
		||||
import kd.bos.orm.query.QFilter;
 | 
			
		||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.org.OrgUnitServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.org.OrgViewType;
 | 
			
		||||
import kd.sdk.plugin.Plugin;
 | 
			
		||||
import shkd.utils.SetUtils;
 | 
			
		||||
 | 
			
		||||
import java.math.BigDecimal;
 | 
			
		||||
import java.math.RoundingMode;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 标准单据列表插件
 | 
			
		||||
 * 自动设置评估人
 | 
			
		||||
 */
 | 
			
		||||
public class SetAssessListPlugin extends AbstractListPlugin implements Plugin {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private static final Log logger = LogFactory.getLog(SetAssessListPlugin.class);
 | 
			
		||||
 | 
			
		||||
    private static final Set<Long> userIdSet = new HashSet<>();
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void registerListener(EventObject e) {
 | 
			
		||||
        // 监听
 | 
			
		||||
        this.addItemClickListeners("barsubmit");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void beforeItemClick(BeforeItemClickEvent evt) {
 | 
			
		||||
        if ("submit".equals(evt.getOperationKey())) {
 | 
			
		||||
            BillList billList = this.getControl("billlistap");
 | 
			
		||||
            Object[] bill = billList.getSelectedRows().getPrimaryKeyValues();
 | 
			
		||||
            if (bill.length == 0) {
 | 
			
		||||
                this.getView().showTipNotification("最少选择一条数据!");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            Toolbar source = (Toolbar) evt.getSource();
 | 
			
		||||
            ListView view = (ListView) source.getView();
 | 
			
		||||
            String billFormId = view.getBillFormId();
 | 
			
		||||
            //评估任务
 | 
			
		||||
            if ("resm_evaltask_new".equals(billFormId)) {
 | 
			
		||||
                // 获取取值逻辑
 | 
			
		||||
                DynamicObject dataModel = BusinessDataServiceHelper.loadSingle("qeug_datamodel", (new QFilter("qeug_projectsource2", QCP.equals, "评估任务")).toArray());
 | 
			
		||||
                if (dataModel == null) return;
 | 
			
		||||
                for (Object id : bill) {
 | 
			
		||||
                    //评估任务数据
 | 
			
		||||
                    DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(id, billFormId);
 | 
			
		||||
                    if (null != dynamicObject) {
 | 
			
		||||
                        Long orgId;
 | 
			
		||||
                        //评估详情
 | 
			
		||||
                        DynamicObjectCollection evalDetail = dynamicObject.getDynamicObjectCollection("evaldetail");
 | 
			
		||||
                        if (evalDetail == null || evalDetail.isEmpty()) return;
 | 
			
		||||
                        for (DynamicObject evalDetailEntry : evalDetail) {
 | 
			
		||||
                            userIdSet.clear();
 | 
			
		||||
                            //项目
 | 
			
		||||
                            DynamicObject project = evalDetailEntry.getDynamicObject("project");
 | 
			
		||||
                            if (null != project) {
 | 
			
		||||
                                QFilter qFilter1 = new QFilter("id", QCP.equals, project.get("id"));
 | 
			
		||||
                                DynamicObject dynamicObject1 = BusinessDataServiceHelper.loadSingle("repmd_projectbill", qFilter1.toArray());
 | 
			
		||||
                                if (null != dynamicObject1) {
 | 
			
		||||
                                    //项目所属组织
 | 
			
		||||
                                    DynamicObject org = dynamicObject1.getDynamicObject("org");
 | 
			
		||||
                                    if (org == null) return;
 | 
			
		||||
                                    orgId = org.getLong("id");
 | 
			
		||||
                                    //取值范围
 | 
			
		||||
                                    DynamicObjectCollection dataModelEntry = dataModel.getDynamicObjectCollection("entryentity");
 | 
			
		||||
                                    //工作流角色
 | 
			
		||||
                                    List<DynamicObject> matchingRoles = SetUtils.getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
                                    //获取评估详情-标准项设置分录
 | 
			
		||||
                                    Object pkValue = evalDetailEntry.getPkValue();
 | 
			
		||||
                                    QFilter qFilter = new QFilter("evaldetailid", QCP.equals, pkValue);
 | 
			
		||||
                                    DynamicObject dynamicObject2 = BusinessDataServiceHelper.loadSingle("resm_subevaldetail", qFilter.toArray());
 | 
			
		||||
                                    if (dynamicObject2 != null) {
 | 
			
		||||
                                        DynamicObjectCollection entry = dynamicObject2.getDynamicObjectCollection("entry_evaldetail");
 | 
			
		||||
                                        if (entry != null && entry.size() != 0) {
 | 
			
		||||
                                            // 如果有匹配项
 | 
			
		||||
                                            if (!((List<?>) matchingRoles).isEmpty()) {
 | 
			
		||||
                                                creatExamData(matchingRoles, entry,  evalDetailEntry,"resm_evaluator_new");
 | 
			
		||||
                                            } else {
 | 
			
		||||
                                                findParentOrgMatch(entry, orgId, dataModelEntry, evalDetailEntry,"resm_evaluator_new");
 | 
			
		||||
                                            }
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            if (userIdSet.size() != 0) {
 | 
			
		||||
                                DynamicObjectCollection evalUsers = evalDetailEntry.getDynamicObjectCollection("evalusers");
 | 
			
		||||
                                evalUsers.clear();
 | 
			
		||||
                                DynamicObjectCollection userObjects = new DynamicObjectCollection();
 | 
			
		||||
                                for (Long userid : userIdSet) {
 | 
			
		||||
                                    DynamicObject dynamicObject1 = new DynamicObject(evalUsers.getDynamicObjectType());
 | 
			
		||||
                                    dynamicObject1.set("fbasedataid", userid);
 | 
			
		||||
                                    userObjects.add(dynamicObject1);
 | 
			
		||||
                                }
 | 
			
		||||
                                evalDetailEntry.set("evalusers", userObjects);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        SaveServiceHelper.save(new DynamicObject[]{dynamicObject});
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 递归查找上级组织
 | 
			
		||||
     *
 | 
			
		||||
     * @param entry          考察任务分录
 | 
			
		||||
     * @param orgId          当前工作流角色组织
 | 
			
		||||
     * @param dataModelEntry 取数模板
 | 
			
		||||
     */
 | 
			
		||||
    private void findParentOrgMatch(DynamicObjectCollection entry, Long orgId, DynamicObjectCollection dataModelEntry,DynamicObject evalDetailEntry, String logotype) {
 | 
			
		||||
        if (orgId == null) return;
 | 
			
		||||
 | 
			
		||||
        //取上级组织.
 | 
			
		||||
        List<Long> dptIds = new ArrayList<>();
 | 
			
		||||
        dptIds.add(orgId);
 | 
			
		||||
        Map<Long, Long> orgParentMap = OrgUnitServiceHelper.getDirectSuperiorOrg(OrgViewType.Admin, dptIds);
 | 
			
		||||
        if (orgParentMap != null) {
 | 
			
		||||
            Long parentId = orgParentMap.get(orgId);
 | 
			
		||||
            DynamicObject parentOrg = BusinessDataServiceHelper.loadSingle(parentId, "bos_adminorg");
 | 
			
		||||
            if (parentOrg != null) {
 | 
			
		||||
                orgId = parentOrg.getLong("id");
 | 
			
		||||
                // 使用 Stream API 获取所有匹配的 role 对象
 | 
			
		||||
 | 
			
		||||
                List<DynamicObject> matchingRoles = SetUtils.getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
 | 
			
		||||
                // 如果有匹配项,则返回;否则递归查找上级组织
 | 
			
		||||
                if (!matchingRoles.isEmpty()) {
 | 
			
		||||
                    creatExamData(matchingRoles, entry,evalDetailEntry, logotype);
 | 
			
		||||
                } else {
 | 
			
		||||
                    findParentOrgMatch(entry, orgId, dataModelEntry,evalDetailEntry, logotype); // 没有匹配项,递归调用上级组织
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 生成考察人
 | 
			
		||||
     *
 | 
			
		||||
     * @param matchingRoles 收集符合条件的人员
 | 
			
		||||
     * @param entry         考察任务分录
 | 
			
		||||
     * @param logotype      考察人||评估人权重设置分录
 | 
			
		||||
     */
 | 
			
		||||
    private void creatExamData(List<DynamicObject> matchingRoles, DynamicObjectCollection entry,DynamicObject evalDetailEntry, String logotype) {
 | 
			
		||||
        // 所有考察人(含重复)
 | 
			
		||||
        int totalCount = matchingRoles.size();
 | 
			
		||||
        // 统计每个用户出现的次数
 | 
			
		||||
        Map<Long, Long> userCountMap = new HashMap<>();
 | 
			
		||||
        for (DynamicObject matchingRole : matchingRoles) {
 | 
			
		||||
            Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
            userCountMap.put(userId, userCountMap.getOrDefault(userId, 0L) + 1);
 | 
			
		||||
        }
 | 
			
		||||
        // 去重:使用 Map 按照 userId 去重
 | 
			
		||||
        Map<Long, DynamicObject> uniqueUserMap = new HashMap<>();
 | 
			
		||||
        for (DynamicObject matchingRole : matchingRoles) {
 | 
			
		||||
            Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
            if (!uniqueUserMap.containsKey(userId)) {
 | 
			
		||||
                uniqueUserMap.put(userId, matchingRole);  // 保留第一次遇到的匹配角色
 | 
			
		||||
                userIdSet.add(userId);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        // 获取去重后的列表
 | 
			
		||||
        List<DynamicObject> uniqueMatchingRoles = new ArrayList<>(uniqueUserMap.values());
 | 
			
		||||
 | 
			
		||||
        for (DynamicObject dynamicObject : entry) {
 | 
			
		||||
            StringBuilder objectText = new StringBuilder();
 | 
			
		||||
 | 
			
		||||
            //评估人及权重设置表
 | 
			
		||||
            QFilter qFilter = new QFilter("evalentryid", QCP.equals, dynamicObject.getPkValue());
 | 
			
		||||
 | 
			
		||||
            DynamicObject examuator = BusinessDataServiceHelper.loadSingle(logotype, qFilter.toArray());
 | 
			
		||||
            if (examuator == null) {
 | 
			
		||||
                examuator = BusinessDataServiceHelper.newDynamicObject(logotype);
 | 
			
		||||
                long pkValue = dynamicObject.getLong("id");
 | 
			
		||||
                examuator.set("evalentryid", pkValue);
 | 
			
		||||
                examuator.set("evaldetailentryid", evalDetailEntry.getLong("id"));
 | 
			
		||||
                //评估人及权重设置表分录
 | 
			
		||||
                DynamicObjectCollection entryCollection = examuator.getDynamicObjectCollection("entry_evaluator");
 | 
			
		||||
                for (int i = 0; i < uniqueMatchingRoles.size(); i++) {
 | 
			
		||||
                    DynamicObject matchingRole = uniqueMatchingRoles.get(i);
 | 
			
		||||
                    DynamicObject evaluator = entryCollection.addNew();
 | 
			
		||||
                    evaluator.set("user", matchingRole.getLong("user.id"));
 | 
			
		||||
                    evaluator.set("userposition", matchingRole.getLong("userposition.id"));
 | 
			
		||||
                    String name = matchingRole.getString("user.name");
 | 
			
		||||
                    // 根据总人数和该用户的出现次数来计算权重
 | 
			
		||||
                    Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
                    Long userCount = userCountMap.get(userId);
 | 
			
		||||
                    BigDecimal weight = new BigDecimal((1.0 / totalCount) * userCount).setScale(2, RoundingMode.HALF_UP);
 | 
			
		||||
                    String weightPercentage = SetUtils.formatWeight(weight);
 | 
			
		||||
                    objectText.append(name).append("(").append(weightPercentage).append(");");
 | 
			
		||||
                    evaluator.set("weight", weight);
 | 
			
		||||
                    evaluator.set("seq", i + 1);
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                DynamicObjectCollection setBillEntry = examuator.getDynamicObjectCollection("entry_evaluator");
 | 
			
		||||
                setBillEntry.clear();
 | 
			
		||||
                for (int i = 0; i < uniqueMatchingRoles.size(); i++) {
 | 
			
		||||
                    DynamicObject matchingRole = uniqueMatchingRoles.get(i);
 | 
			
		||||
                    DynamicObject evaluator = setBillEntry.addNew();
 | 
			
		||||
                    evaluator.set("user", matchingRole.getDynamicObject("user"));
 | 
			
		||||
                    evaluator.set("userposition", matchingRole.getDynamicObject("userposition"));
 | 
			
		||||
                    String name = matchingRole.getString("user.name");
 | 
			
		||||
                    // 根据总人数和该用户的出现次数来计算权重
 | 
			
		||||
                    Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
                    Long userCount = userCountMap.get(userId);
 | 
			
		||||
                    BigDecimal weight = new BigDecimal((1.0 / totalCount) * userCount).setScale(2, RoundingMode.HALF_UP);
 | 
			
		||||
                    String weightPercentage = SetUtils.formatWeight(weight);
 | 
			
		||||
                    objectText.append(name).append("(").append(weightPercentage).append(");");
 | 
			
		||||
                    evaluator.set("weight", weight);
 | 
			
		||||
                    evaluator.set("seq", i + 1);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            dynamicObject.set("entryevaluatorstr", objectText);
 | 
			
		||||
            SaveServiceHelper.save(new DynamicObject[]{examuator});
 | 
			
		||||
            SaveServiceHelper.update(dynamicObject);
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -17,6 +17,7 @@ import kd.bos.servicehelper.operation.SaveServiceHelper;
 | 
			
		|||
import kd.bos.servicehelper.org.OrgUnitServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.org.OrgViewType;
 | 
			
		||||
import kd.sdk.plugin.Plugin;
 | 
			
		||||
import shkd.utils.SetUtils;
 | 
			
		||||
 | 
			
		||||
import java.math.BigDecimal;
 | 
			
		||||
import java.math.RoundingMode;
 | 
			
		||||
| 
						 | 
				
			
			@ -37,12 +38,12 @@ public class SetObjectFormPlugin extends AbstractFormPlugin implements Plugin {
 | 
			
		|||
        super.beforeDoOperation(args);
 | 
			
		||||
        FormOperate source = (FormOperate) args.getSource();
 | 
			
		||||
        String operateKey = source.getOperateKey();
 | 
			
		||||
        if ("submit".equals(operateKey)){
 | 
			
		||||
            Submit submit=(Submit)args.getSource();
 | 
			
		||||
        if ("submit".equals(operateKey)) {
 | 
			
		||||
            Submit submit = (Submit) args.getSource();
 | 
			
		||||
            String entityId = submit.getEntityId();
 | 
			
		||||
            if ("resm_exam_task".equals(entityId)){
 | 
			
		||||
            if ("resm_exam_task".equals(entityId)) {
 | 
			
		||||
                // 获取取值逻辑
 | 
			
		||||
                DynamicObject dataModel = BusinessDataServiceHelper.loadSingle("qeug_datamodel",(new QFilter("qeug_projectsource2", QCP.equals, "考察任务")).toArray());
 | 
			
		||||
                DynamicObject dataModel = BusinessDataServiceHelper.loadSingle("qeug_datamodel", (new QFilter("qeug_projectsource2", QCP.equals, "考察任务")).toArray());
 | 
			
		||||
                if (dataModel == null) return;
 | 
			
		||||
                Object value = this.getModel().getValue("id");
 | 
			
		||||
                DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(value, entityId);
 | 
			
		||||
| 
						 | 
				
			
			@ -69,7 +70,7 @@ public class SetObjectFormPlugin extends AbstractFormPlugin implements Plugin {
 | 
			
		|||
                    DynamicObjectCollection dataModelEntry = dataModel.getDynamicObjectCollection("entryentity");
 | 
			
		||||
 | 
			
		||||
                    // 使用 Stream API 获取所有匹配的 role 对象
 | 
			
		||||
                    List<DynamicObject> matchingRoles = getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
                    List<DynamicObject> matchingRoles = SetUtils.getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
 | 
			
		||||
                    // 如果有匹配项
 | 
			
		||||
                    if (!((List<?>) matchingRoles).isEmpty()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -80,61 +81,6 @@ public class SetObjectFormPlugin extends AbstractFormPlugin implements Plugin {
 | 
			
		|||
 | 
			
		||||
                }
 | 
			
		||||
                SaveServiceHelper.saveOperate("resm_exam_task", new DynamicObject[]{dynamicObject}, OperateOption.create());
 | 
			
		||||
            }else if ("resm_evaltask_new".equals(entityId)){
 | 
			
		||||
                // 获取取值逻辑
 | 
			
		||||
                DynamicObject dataModel = BusinessDataServiceHelper.loadSingle("qeug_datamodel", (new QFilter("qeug_projectsource2", QCP.equals, "评估任务")).toArray());
 | 
			
		||||
                if (dataModel == null) return;
 | 
			
		||||
                Object value = this.getModel().getValue("id");
 | 
			
		||||
                DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(value, entityId);
 | 
			
		||||
                Long orgId;
 | 
			
		||||
                DynamicObjectCollection evalDetail = dynamicObject.getDynamicObjectCollection("evaldetail");
 | 
			
		||||
                if (evalDetail == null || evalDetail.isEmpty()) return;
 | 
			
		||||
                for (DynamicObject evalDetailEntry : evalDetail) {
 | 
			
		||||
                    userIdSet.clear();
 | 
			
		||||
                    //项目
 | 
			
		||||
                    DynamicObject project = evalDetailEntry.getDynamicObject("project");
 | 
			
		||||
                    if (null != project) {
 | 
			
		||||
                        QFilter qFilter1 = new QFilter("id", QCP.equals, project.get("id"));
 | 
			
		||||
                        DynamicObject dynamicObject1 = BusinessDataServiceHelper.loadSingle("repmd_projectbill", qFilter1.toArray());
 | 
			
		||||
                        if (null != dynamicObject1) {
 | 
			
		||||
                            //项目所属组织
 | 
			
		||||
                            DynamicObject org = dynamicObject1.getDynamicObject("org");
 | 
			
		||||
                            if (org == null) return;
 | 
			
		||||
                            orgId = org.getLong("id");
 | 
			
		||||
                            //取值范围
 | 
			
		||||
                            DynamicObjectCollection dataModelEntry = dataModel.getDynamicObjectCollection("entryentity");
 | 
			
		||||
                            //工作流角色
 | 
			
		||||
                            List<DynamicObject> matchingRoles = getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
                            //获取评估详情-标准项设置分录
 | 
			
		||||
                            Object pkValue = evalDetailEntry.getPkValue();
 | 
			
		||||
                            QFilter qFilter = new QFilter("evaldetailid", QCP.equals, pkValue);
 | 
			
		||||
                            DynamicObject dynamicObject2 = BusinessDataServiceHelper.loadSingle("resm_subevaldetail", qFilter.toArray());
 | 
			
		||||
                            if (dynamicObject2 != null) {
 | 
			
		||||
                                DynamicObjectCollection entry = dynamicObject2.getDynamicObjectCollection("entry_evaldetail");
 | 
			
		||||
                                if (entry != null && entry.size() != 0) {
 | 
			
		||||
                                    // 如果有匹配项
 | 
			
		||||
                                    if (!((List<?>) matchingRoles).isEmpty()) {
 | 
			
		||||
                                        creatExamData(matchingRoles, entry, "resm_evaluator_new");
 | 
			
		||||
                                    } else {
 | 
			
		||||
                                        findParentOrgMatch(entry, orgId, dataModelEntry, "resm_evaluator_new");
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    if (userIdSet.size() != 0) {
 | 
			
		||||
                        DynamicObjectCollection evalUsers = evalDetailEntry.getDynamicObjectCollection("evalusers");
 | 
			
		||||
                        evalUsers.clear();
 | 
			
		||||
                        DynamicObjectCollection userObjects = new DynamicObjectCollection();
 | 
			
		||||
                        for (Long userid : userIdSet) {
 | 
			
		||||
                            DynamicObject dynamicObject1 = new DynamicObject(evalUsers.getDynamicObjectType());
 | 
			
		||||
                            dynamicObject1.set("fbasedataid", userid);
 | 
			
		||||
                            userObjects.add(dynamicObject1);
 | 
			
		||||
                        }
 | 
			
		||||
                        evalDetailEntry.set("evalusers", userObjects);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                SaveServiceHelper.save(new DynamicObject[]{dynamicObject});
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -144,7 +90,7 @@ public class SetObjectFormPlugin extends AbstractFormPlugin implements Plugin {
 | 
			
		|||
        super.afterDoOperation(e);
 | 
			
		||||
        FormOperate source = (FormOperate) e.getSource();
 | 
			
		||||
        String operateKey = source.getOperateKey();
 | 
			
		||||
        if ("submit".equals(operateKey)){
 | 
			
		||||
        if ("submit".equals(operateKey)) {
 | 
			
		||||
            this.getView().invokeOperation("refresh");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -156,7 +102,7 @@ public class SetObjectFormPlugin extends AbstractFormPlugin implements Plugin {
 | 
			
		|||
     * @param orgId          当前工作流角色组织
 | 
			
		||||
     * @param dataModelEntry 取数模板
 | 
			
		||||
     */
 | 
			
		||||
    private  void findParentOrgMatch(DynamicObjectCollection entry, Long orgId, DynamicObjectCollection dataModelEntry, String logotype) {
 | 
			
		||||
    private void findParentOrgMatch(DynamicObjectCollection entry, Long orgId, DynamicObjectCollection dataModelEntry, String logotype) {
 | 
			
		||||
        if (orgId == null) return;
 | 
			
		||||
        //取上级组织.
 | 
			
		||||
        List<Long> dptIds = new ArrayList<>();
 | 
			
		||||
| 
						 | 
				
			
			@ -169,7 +115,7 @@ public class SetObjectFormPlugin extends AbstractFormPlugin implements Plugin {
 | 
			
		|||
                orgId = parentOrg.getLong("id");
 | 
			
		||||
                // 使用 Stream API 获取所有匹配的 role 对象
 | 
			
		||||
 | 
			
		||||
                List<DynamicObject> matchingRoles = getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
                List<DynamicObject> matchingRoles = SetUtils.getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
 | 
			
		||||
                // 如果有匹配项,则返回;否则递归查找上级组织
 | 
			
		||||
                if (!matchingRoles.isEmpty()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -188,7 +134,7 @@ public class SetObjectFormPlugin extends AbstractFormPlugin implements Plugin {
 | 
			
		|||
     * @param entry         考察任务分录
 | 
			
		||||
     * @param logotype      考察人||评估人权重设置分录
 | 
			
		||||
     */
 | 
			
		||||
    private  void creatExamData(List<DynamicObject> matchingRoles, DynamicObjectCollection entry, String logotype) {
 | 
			
		||||
    private void creatExamData(List<DynamicObject> matchingRoles, DynamicObjectCollection entry, String logotype) {
 | 
			
		||||
        // 所有考察人(含重复)
 | 
			
		||||
        int totalCount = matchingRoles.size();
 | 
			
		||||
        // 统计每个用户出现的次数
 | 
			
		||||
| 
						 | 
				
			
			@ -212,137 +158,50 @@ public class SetObjectFormPlugin extends AbstractFormPlugin implements Plugin {
 | 
			
		|||
        for (int i = 0; i < entry.size(); i++) {
 | 
			
		||||
            StringBuilder objectText = new StringBuilder();
 | 
			
		||||
            //评估人及权重设置表
 | 
			
		||||
            QFilter qFilter = null;
 | 
			
		||||
            switch (logotype) {
 | 
			
		||||
                case "resm_evaluator_new":
 | 
			
		||||
                    qFilter = new QFilter("evalentryid", QCP.equals, entry.get(i).getPkValue());
 | 
			
		||||
                    DynamicObject examuatorNew = BusinessDataServiceHelper.loadSingle(logotype, qFilter.toArray());
 | 
			
		||||
                    if (examuatorNew == null) {
 | 
			
		||||
                        examuatorNew = BusinessDataServiceHelper.newDynamicObject(logotype);
 | 
			
		||||
                        String pkValue = entry.get(i).getString("id");
 | 
			
		||||
                        examuatorNew.set("evalentryid", pkValue);
 | 
			
		||||
                        //评估人及权重设置表分录
 | 
			
		||||
                        DynamicObjectCollection entryCollection = examuatorNew.getDynamicObjectCollection("entry_evaluator");
 | 
			
		||||
                        for (int j = 0; j < uniqueMatchingRoles.size(); j++) {
 | 
			
		||||
                            DynamicObject matchingRole = uniqueMatchingRoles.get(j);
 | 
			
		||||
                            DynamicObject evaluator = entryCollection.addNew();
 | 
			
		||||
                            evaluator.set("user", matchingRole.getLong("user.id"));
 | 
			
		||||
                            evaluator.set("userposition", matchingRole.getLong("userposition.id"));
 | 
			
		||||
                            String name = matchingRole.getString("user.name");
 | 
			
		||||
                            // 根据总人数和该用户的出现次数来计算权重
 | 
			
		||||
                            Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
                            Long userCount = userCountMap.get(userId);
 | 
			
		||||
                            BigDecimal weight = new BigDecimal((1.0 / totalCount) * userCount).setScale(2, RoundingMode.HALF_UP);
 | 
			
		||||
                            String weightPercentage = formatWeight(weight);
 | 
			
		||||
                            objectText.append(name).append("(").append(weightPercentage).append(");");
 | 
			
		||||
                            evaluator.set("weight", weight);
 | 
			
		||||
                            evaluator.set("seq", j + 1);
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        DynamicObjectCollection setBillEntry = examuatorNew.getDynamicObjectCollection("entry_evaluator");
 | 
			
		||||
                        setBillEntry.clear();
 | 
			
		||||
                        for (int j = 0; j < uniqueMatchingRoles.size(); j++) {
 | 
			
		||||
                            DynamicObject matchingRole = uniqueMatchingRoles.get(j);
 | 
			
		||||
                            DynamicObject evaluator = setBillEntry.addNew();
 | 
			
		||||
                            evaluator.set("user", matchingRole.getDynamicObject("user"));
 | 
			
		||||
                            evaluator.set("userposition", matchingRole.getDynamicObject("userposition"));
 | 
			
		||||
                            String name = matchingRole.getString("user.name");
 | 
			
		||||
                            // 根据总人数和该用户的出现次数来计算权重
 | 
			
		||||
                            Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
                            Long userCount = userCountMap.get(userId);
 | 
			
		||||
                            BigDecimal weight = new BigDecimal((1.0 / totalCount) * userCount).setScale(2, RoundingMode.HALF_UP);
 | 
			
		||||
                            String weightPercentage = formatWeight(weight);
 | 
			
		||||
                            objectText.append(name).append("(").append(weightPercentage).append(");");
 | 
			
		||||
                            evaluator.set("weight", weight);
 | 
			
		||||
                            evaluator.set("seq", j + 1);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    entry.get(i).set("entryevaluatorstr", objectText);
 | 
			
		||||
                    SaveServiceHelper.save(new DynamicObject[]{examuatorNew});
 | 
			
		||||
                    SaveServiceHelper.update(entry.get(i));
 | 
			
		||||
                    break;
 | 
			
		||||
                case "resm_examuator":
 | 
			
		||||
                    qFilter = new QFilter("evalentryid", QCP.equals, String.valueOf(entry.get(i).getLong("id")));
 | 
			
		||||
                    DynamicObject examuator = BusinessDataServiceHelper.loadSingle(logotype, qFilter.toArray());
 | 
			
		||||
                    if (examuator == null) {
 | 
			
		||||
                        examuator = BusinessDataServiceHelper.newDynamicObject(logotype);
 | 
			
		||||
                        String pkValue = entry.get(i).getString("id");
 | 
			
		||||
                        examuator.set("evalentryid", pkValue);
 | 
			
		||||
                        //评估人及权重设置表分录
 | 
			
		||||
                        DynamicObjectCollection entryCollection = examuator.getDynamicObjectCollection("entry_evaluator");
 | 
			
		||||
                        for (int j = 0; j < uniqueMatchingRoles.size(); j++) {
 | 
			
		||||
                            DynamicObject matchingRole = uniqueMatchingRoles.get(j);
 | 
			
		||||
                            DynamicObject evaluator = entryCollection.addNew();
 | 
			
		||||
                            evaluator.set("user", matchingRole.getLong("user.id"));
 | 
			
		||||
                            evaluator.set("userposition", matchingRole.getLong("userposition.id"));
 | 
			
		||||
                            String name = matchingRole.getString("user.name");
 | 
			
		||||
                            // 根据总人数和该用户的出现次数来计算权重
 | 
			
		||||
                            Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
                            Long userCount = userCountMap.get(userId);
 | 
			
		||||
                            BigDecimal weight = new BigDecimal((1.0 / totalCount) * userCount).setScale(2, RoundingMode.HALF_UP);
 | 
			
		||||
                            String weightPercentage = formatWeight(weight);
 | 
			
		||||
                            objectText.append(name).append("(").append(weightPercentage).append(");");
 | 
			
		||||
                            evaluator.set("weight", weight);
 | 
			
		||||
                            evaluator.set("seq", j + 1);
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        DynamicObjectCollection setBillEntry = examuator.getDynamicObjectCollection("entry_evaluator");
 | 
			
		||||
                        setBillEntry.clear();
 | 
			
		||||
                        for (int j = 0; j < uniqueMatchingRoles.size(); j++) {
 | 
			
		||||
                            DynamicObject matchingRole = uniqueMatchingRoles.get(j);
 | 
			
		||||
                            DynamicObject evaluator = setBillEntry.addNew();
 | 
			
		||||
                            evaluator.set("user", matchingRole.getDynamicObject("user"));
 | 
			
		||||
                            evaluator.set("userposition", matchingRole.getDynamicObject("userposition"));
 | 
			
		||||
                            String name = matchingRole.getString("user.name");
 | 
			
		||||
                            // 根据总人数和该用户的出现次数来计算权重
 | 
			
		||||
                            Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
                            Long userCount = userCountMap.get(userId);
 | 
			
		||||
                            BigDecimal weight = new BigDecimal((1.0 / totalCount) * userCount).setScale(2, RoundingMode.HALF_UP);
 | 
			
		||||
                            String weightPercentage = formatWeight(weight);
 | 
			
		||||
                            objectText.append(name).append("(").append(weightPercentage).append(");");
 | 
			
		||||
                            evaluator.set("weight", weight);
 | 
			
		||||
                            evaluator.set("seq", j + 1);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    SaveServiceHelper.save(new DynamicObject[]{examuator});
 | 
			
		||||
                    this.getModel().setValue("entryevaluatorstr", objectText,i);
 | 
			
		||||
                    break;
 | 
			
		||||
            QFilter qFilter = new QFilter("evalentryid", QCP.equals, String.valueOf(entry.get(i).getLong("id")));
 | 
			
		||||
            DynamicObject examuator = BusinessDataServiceHelper.loadSingle(logotype, qFilter.toArray());
 | 
			
		||||
            if (examuator == null) {
 | 
			
		||||
                examuator = BusinessDataServiceHelper.newDynamicObject(logotype);
 | 
			
		||||
                String pkValue = entry.get(i).getString("id");
 | 
			
		||||
                examuator.set("evalentryid", pkValue);
 | 
			
		||||
                //评估人及权重设置表分录
 | 
			
		||||
                DynamicObjectCollection entryCollection = examuator.getDynamicObjectCollection("entry_evaluator");
 | 
			
		||||
                for (int j = 0; j < uniqueMatchingRoles.size(); j++) {
 | 
			
		||||
                    DynamicObject matchingRole = uniqueMatchingRoles.get(j);
 | 
			
		||||
                    DynamicObject evaluator = entryCollection.addNew();
 | 
			
		||||
                    evaluator.set("user", matchingRole.getLong("user.id"));
 | 
			
		||||
                    evaluator.set("userposition", matchingRole.getLong("userposition.id"));
 | 
			
		||||
                    String name = matchingRole.getString("user.name");
 | 
			
		||||
                    // 根据总人数和该用户的出现次数来计算权重
 | 
			
		||||
                    Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
                    Long userCount = userCountMap.get(userId);
 | 
			
		||||
                    BigDecimal weight = new BigDecimal((1.0 / totalCount) * userCount).setScale(2, RoundingMode.HALF_UP);
 | 
			
		||||
                    String weightPercentage = SetUtils.formatWeight(weight);
 | 
			
		||||
                    objectText.append(name).append("(").append(weightPercentage).append(");");
 | 
			
		||||
                    evaluator.set("weight", weight);
 | 
			
		||||
                    evaluator.set("seq", j + 1);
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                DynamicObjectCollection setBillEntry = examuator.getDynamicObjectCollection("entry_evaluator");
 | 
			
		||||
                setBillEntry.clear();
 | 
			
		||||
                for (int j = 0; j < uniqueMatchingRoles.size(); j++) {
 | 
			
		||||
                    DynamicObject matchingRole = uniqueMatchingRoles.get(j);
 | 
			
		||||
                    DynamicObject evaluator = setBillEntry.addNew();
 | 
			
		||||
                    evaluator.set("user", matchingRole.getDynamicObject("user"));
 | 
			
		||||
                    evaluator.set("userposition", matchingRole.getDynamicObject("userposition"));
 | 
			
		||||
                    String name = matchingRole.getString("user.name");
 | 
			
		||||
                    // 根据总人数和该用户的出现次数来计算权重
 | 
			
		||||
                    Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
                    Long userCount = userCountMap.get(userId);
 | 
			
		||||
                    BigDecimal weight = new BigDecimal((1.0 / totalCount) * userCount).setScale(2, RoundingMode.HALF_UP);
 | 
			
		||||
                    String weightPercentage = SetUtils.formatWeight(weight);
 | 
			
		||||
                    objectText.append(name).append("(").append(weightPercentage).append(");");
 | 
			
		||||
                    evaluator.set("weight", weight);
 | 
			
		||||
                    evaluator.set("seq", j + 1);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            SaveServiceHelper.save(new DynamicObject[]{examuator});
 | 
			
		||||
            this.getModel().setValue("entryevaluatorstr", objectText, i);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 权重转百分比
 | 
			
		||||
     *
 | 
			
		||||
     * @param weight 权重
 | 
			
		||||
     * @return 百分比字符串
 | 
			
		||||
     */
 | 
			
		||||
    private  String formatWeight(BigDecimal weight) {
 | 
			
		||||
        return weight.multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_UP) + "%";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 工作流角色收集
 | 
			
		||||
     *
 | 
			
		||||
     * @param dataModelEntry
 | 
			
		||||
     * @param orgId
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    private  List<DynamicObject> getMatchingRoles(DynamicObjectCollection dataModelEntry, Long orgId) {
 | 
			
		||||
 | 
			
		||||
        return dataModelEntry.stream()
 | 
			
		||||
                .map(modelEntry -> modelEntry.getString("qeug_workrole.number"))
 | 
			
		||||
                .filter(roleNumber -> roleNumber != null)
 | 
			
		||||
                .map(roleNumber -> BusinessDataServiceHelper.loadSingle("wf_role", new QFilter("number", QCP.equals, roleNumber).toArray()))
 | 
			
		||||
                .filter(roleDynamic -> roleDynamic != null)
 | 
			
		||||
                .filter(roleDynamic -> roleDynamic.getDynamicObjectCollection("roleentry") != null && !roleDynamic.getDynamicObjectCollection("roleentry").isEmpty()) // 跳过 roleentry 为空的情况
 | 
			
		||||
                .flatMap(roleDynamic -> roleDynamic.getDynamicObjectCollection("roleentry").stream())
 | 
			
		||||
                .filter(role -> {
 | 
			
		||||
                    Long roleOrgId = role.getLong("org.id");
 | 
			
		||||
                    return roleOrgId != null && roleOrgId.compareTo(orgId) == 0; // 筛选符合条件的 role
 | 
			
		||||
                })
 | 
			
		||||
                .collect(Collectors.toList());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -17,6 +17,7 @@ import kd.bos.servicehelper.operation.SaveServiceHelper;
 | 
			
		|||
import kd.bos.servicehelper.org.OrgUnitServiceHelper;
 | 
			
		||||
import kd.bos.servicehelper.org.OrgViewType;
 | 
			
		||||
import kd.sdk.plugin.Plugin;
 | 
			
		||||
import shkd.utils.SetUtils;
 | 
			
		||||
 | 
			
		||||
import java.math.BigDecimal;
 | 
			
		||||
import java.math.RoundingMode;
 | 
			
		||||
| 
						 | 
				
			
			@ -82,7 +83,7 @@ public class SetObjectListPlugin extends AbstractListPlugin implements Plugin {
 | 
			
		|||
                            DynamicObjectCollection dataModelEntry = dataModel.getDynamicObjectCollection("entryentity");
 | 
			
		||||
 | 
			
		||||
                            // 使用 Stream API 获取所有匹配的 role 对象
 | 
			
		||||
                            List<DynamicObject> matchingRoles = getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
                            List<DynamicObject> matchingRoles = SetUtils.getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
 | 
			
		||||
                            // 如果有匹配项
 | 
			
		||||
                            if (!((List<?>) matchingRoles).isEmpty()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -96,68 +97,6 @@ public class SetObjectListPlugin extends AbstractListPlugin implements Plugin {
 | 
			
		|||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            //评估任务
 | 
			
		||||
            else if ("resm_evaltask_new".equals(billFormId)) {
 | 
			
		||||
                // 获取取值逻辑
 | 
			
		||||
                DynamicObject dataModel = BusinessDataServiceHelper.loadSingle("qeug_datamodel", (new QFilter("qeug_projectsource2", QCP.equals, "评估任务")).toArray());
 | 
			
		||||
                if (dataModel == null) return;
 | 
			
		||||
                for (Object id : bill) {
 | 
			
		||||
                    //评估任务数据
 | 
			
		||||
                    DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(id, billFormId);
 | 
			
		||||
                    if (null != dynamicObject) {
 | 
			
		||||
                        Long orgId;
 | 
			
		||||
                        //评估详情
 | 
			
		||||
                        DynamicObjectCollection evalDetail = dynamicObject.getDynamicObjectCollection("evaldetail");
 | 
			
		||||
                        if (evalDetail == null || evalDetail.isEmpty()) return;
 | 
			
		||||
                        for (DynamicObject evalDetailEntry : evalDetail) {
 | 
			
		||||
                            userIdSet.clear();
 | 
			
		||||
                            //项目
 | 
			
		||||
                            DynamicObject project = evalDetailEntry.getDynamicObject("project");
 | 
			
		||||
                            if (null != project) {
 | 
			
		||||
                                QFilter qFilter1 = new QFilter("id", QCP.equals, project.get("id"));
 | 
			
		||||
                                DynamicObject dynamicObject1 = BusinessDataServiceHelper.loadSingle("repmd_projectbill", qFilter1.toArray());
 | 
			
		||||
                                if (null != dynamicObject1) {
 | 
			
		||||
                                    //项目所属组织
 | 
			
		||||
                                    DynamicObject org = dynamicObject1.getDynamicObject("org");
 | 
			
		||||
                                    if (org == null) return;
 | 
			
		||||
                                    orgId = org.getLong("id");
 | 
			
		||||
                                    //取值范围
 | 
			
		||||
                                    DynamicObjectCollection dataModelEntry = dataModel.getDynamicObjectCollection("entryentity");
 | 
			
		||||
                                    //工作流角色
 | 
			
		||||
                                    List<DynamicObject> matchingRoles = getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
                                    //获取评估详情-标准项设置分录
 | 
			
		||||
                                    Object pkValue = evalDetailEntry.getPkValue();
 | 
			
		||||
                                    QFilter qFilter = new QFilter("evaldetailid", QCP.equals, pkValue);
 | 
			
		||||
                                    DynamicObject dynamicObject2 = BusinessDataServiceHelper.loadSingle("resm_subevaldetail", qFilter.toArray());
 | 
			
		||||
                                    if (dynamicObject2 != null) {
 | 
			
		||||
                                        DynamicObjectCollection entry = dynamicObject2.getDynamicObjectCollection("entry_evaldetail");
 | 
			
		||||
                                        if (entry != null && entry.size() != 0) {
 | 
			
		||||
                                            // 如果有匹配项
 | 
			
		||||
                                            if (!((List<?>) matchingRoles).isEmpty()) {
 | 
			
		||||
                                                creatExamData(matchingRoles, entry, "resm_evaluator_new");
 | 
			
		||||
                                            } else {
 | 
			
		||||
                                                findParentOrgMatch(entry, orgId, dataModelEntry, "resm_evaluator_new");
 | 
			
		||||
                                            }
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            if (userIdSet.size() != 0) {
 | 
			
		||||
                                DynamicObjectCollection evalUsers = evalDetailEntry.getDynamicObjectCollection("evalusers");
 | 
			
		||||
                                evalUsers.clear();
 | 
			
		||||
                                DynamicObjectCollection userObjects = new DynamicObjectCollection();
 | 
			
		||||
                                for (Long userid : userIdSet) {
 | 
			
		||||
                                    DynamicObject dynamicObject1 = new DynamicObject(evalUsers.getDynamicObjectType());
 | 
			
		||||
                                    dynamicObject1.set("fbasedataid", userid);
 | 
			
		||||
                                    userObjects.add(dynamicObject1);
 | 
			
		||||
                                }
 | 
			
		||||
                                evalDetailEntry.set("evalusers", userObjects);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        SaveServiceHelper.save(new DynamicObject[]{dynamicObject});
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -182,7 +121,7 @@ public class SetObjectListPlugin extends AbstractListPlugin implements Plugin {
 | 
			
		|||
                orgId = parentOrg.getLong("id");
 | 
			
		||||
                // 使用 Stream API 获取所有匹配的 role 对象
 | 
			
		||||
 | 
			
		||||
                List<DynamicObject> matchingRoles = getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
                List<DynamicObject> matchingRoles = SetUtils.getMatchingRoles(dataModelEntry, orgId);
 | 
			
		||||
 | 
			
		||||
                // 如果有匹配项,则返回;否则递归查找上级组织
 | 
			
		||||
                if (!matchingRoles.isEmpty()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -226,15 +165,7 @@ public class SetObjectListPlugin extends AbstractListPlugin implements Plugin {
 | 
			
		|||
            StringBuilder objectText = new StringBuilder();
 | 
			
		||||
 | 
			
		||||
            //评估人及权重设置表
 | 
			
		||||
            QFilter qFilter = null;
 | 
			
		||||
            switch (logotype) {
 | 
			
		||||
                case "resm_evaluator_new":
 | 
			
		||||
                    qFilter = new QFilter("evalentryid", QCP.equals, dynamicObject.getPkValue());
 | 
			
		||||
                    break;
 | 
			
		||||
                case "resm_examuator":
 | 
			
		||||
                    qFilter = new QFilter("evalentryid", QCP.equals, String.valueOf(dynamicObject.getLong("id")));
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
            QFilter qFilter = new QFilter("evalentryid", QCP.equals, String.valueOf(dynamicObject.getLong("id")));
 | 
			
		||||
            DynamicObject examuator = BusinessDataServiceHelper.loadSingle(logotype, qFilter.toArray());
 | 
			
		||||
            if (examuator == null) {
 | 
			
		||||
                examuator = BusinessDataServiceHelper.newDynamicObject(logotype);
 | 
			
		||||
| 
						 | 
				
			
			@ -252,7 +183,7 @@ public class SetObjectListPlugin extends AbstractListPlugin implements Plugin {
 | 
			
		|||
                    Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
                    Long userCount = userCountMap.get(userId);
 | 
			
		||||
                    BigDecimal weight = new BigDecimal((1.0 / totalCount) * userCount).setScale(2, RoundingMode.HALF_UP);
 | 
			
		||||
                    String weightPercentage = formatWeight(weight);
 | 
			
		||||
                    String weightPercentage = SetUtils.formatWeight(weight);
 | 
			
		||||
                    objectText.append(name).append("(").append(weightPercentage).append(");");
 | 
			
		||||
                    evaluator.set("weight", weight);
 | 
			
		||||
                    evaluator.set("seq", i + 1);
 | 
			
		||||
| 
						 | 
				
			
			@ -270,7 +201,7 @@ public class SetObjectListPlugin extends AbstractListPlugin implements Plugin {
 | 
			
		|||
                    Long userId = matchingRole.getLong("user.id");
 | 
			
		||||
                    Long userCount = userCountMap.get(userId);
 | 
			
		||||
                    BigDecimal weight = new BigDecimal((1.0 / totalCount) * userCount).setScale(2, RoundingMode.HALF_UP);
 | 
			
		||||
                    String weightPercentage = formatWeight(weight);
 | 
			
		||||
                    String weightPercentage = SetUtils.formatWeight(weight);
 | 
			
		||||
                    objectText.append(name).append("(").append(weightPercentage).append(");");
 | 
			
		||||
                    evaluator.set("weight", weight);
 | 
			
		||||
                    evaluator.set("seq", i + 1);
 | 
			
		||||
| 
						 | 
				
			
			@ -281,58 +212,5 @@ public class SetObjectListPlugin extends AbstractListPlugin implements Plugin {
 | 
			
		|||
            SaveServiceHelper.update(dynamicObject);
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 权重计算
 | 
			
		||||
     *
 | 
			
		||||
     * @param totalRoles   人员列表
 | 
			
		||||
     * @param currentIndex 行数
 | 
			
		||||
     * @return 权重
 | 
			
		||||
     */
 | 
			
		||||
    private BigDecimal calculateWeight(int totalRoles, int currentIndex) {
 | 
			
		||||
        BigDecimal weight = new BigDecimal(1.0 / totalRoles).setScale(2, RoundingMode.HALF_UP);
 | 
			
		||||
        if (totalRoles % 2 == 1 && currentIndex == totalRoles - 1 && totalRoles != 1) {
 | 
			
		||||
            weight = weight.add(new BigDecimal(0.01));
 | 
			
		||||
        }
 | 
			
		||||
        return weight;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 权重转百分比
 | 
			
		||||
     *
 | 
			
		||||
     * @param weight 权重
 | 
			
		||||
     * @return 百分比字符串
 | 
			
		||||
     */
 | 
			
		||||
    private String formatWeight(BigDecimal weight) {
 | 
			
		||||
        return weight.multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_UP) + "%";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 工作流角色收集
 | 
			
		||||
     *
 | 
			
		||||
     * @param dataModelEntry
 | 
			
		||||
     * @param orgId
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    private List<DynamicObject> getMatchingRoles(DynamicObjectCollection dataModelEntry, Long orgId) {
 | 
			
		||||
 | 
			
		||||
        return dataModelEntry.stream()
 | 
			
		||||
                .map(modelEntry -> modelEntry.getString("qeug_workrole.number"))
 | 
			
		||||
                .filter(roleNumber -> roleNumber != null)
 | 
			
		||||
                .map(roleNumber -> BusinessDataServiceHelper.loadSingle("wf_role", new QFilter("number", QCP.equals, roleNumber).toArray()))
 | 
			
		||||
                .filter(roleDynamic -> roleDynamic != null)
 | 
			
		||||
                .filter(roleDynamic -> roleDynamic.getDynamicObjectCollection("roleentry") != null && !roleDynamic.getDynamicObjectCollection("roleentry").isEmpty()) // 跳过 roleentry 为空的情况
 | 
			
		||||
                .flatMap(roleDynamic -> roleDynamic.getDynamicObjectCollection("roleentry").stream())
 | 
			
		||||
                .filter(role -> {
 | 
			
		||||
                    Long roleOrgId = role.getLong("org.id");
 | 
			
		||||
                    return roleOrgId != null && roleOrgId.compareTo(orgId) == 0; // 筛选符合条件的 role
 | 
			
		||||
                })
 | 
			
		||||
                .collect(Collectors.toList());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,50 @@
 | 
			
		|||
package shkd.utils;
 | 
			
		||||
 | 
			
		||||
import kd.bos.dataentity.entity.DynamicObject;
 | 
			
		||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
 | 
			
		||||
import kd.bos.orm.query.QCP;
 | 
			
		||||
import kd.bos.orm.query.QFilter;
 | 
			
		||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
 | 
			
		||||
 | 
			
		||||
import java.math.BigDecimal;
 | 
			
		||||
import java.math.RoundingMode;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
public class SetUtils {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 权重转百分比
 | 
			
		||||
     *
 | 
			
		||||
     * @param weight 权重
 | 
			
		||||
     * @return 百分比字符串
 | 
			
		||||
     */
 | 
			
		||||
    public static String formatWeight(BigDecimal weight) {
 | 
			
		||||
        return weight.multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_UP) + "%";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 工作流角色收集
 | 
			
		||||
     *
 | 
			
		||||
     * @param dataModelEntry
 | 
			
		||||
     * @param orgId
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static List<DynamicObject> getMatchingRoles(DynamicObjectCollection dataModelEntry, Long orgId) {
 | 
			
		||||
 | 
			
		||||
        return dataModelEntry.stream()
 | 
			
		||||
                .map(modelEntry -> modelEntry.getString("qeug_workrole.number"))
 | 
			
		||||
                .filter(roleNumber -> roleNumber != null)
 | 
			
		||||
                .map(roleNumber -> BusinessDataServiceHelper.loadSingle("wf_role", new QFilter("number", QCP.equals, roleNumber).toArray()))
 | 
			
		||||
                .filter(roleDynamic -> roleDynamic != null)
 | 
			
		||||
                .filter(roleDynamic -> roleDynamic.getDynamicObjectCollection("roleentry") != null && !roleDynamic.getDynamicObjectCollection("roleentry").isEmpty()) // 跳过 roleentry 为空的情况
 | 
			
		||||
                .flatMap(roleDynamic -> roleDynamic.getDynamicObjectCollection("roleentry").stream())
 | 
			
		||||
                .filter(role -> {
 | 
			
		||||
                    Long roleOrgId = role.getLong("org.id");
 | 
			
		||||
                    return roleOrgId != null && roleOrgId.compareTo(orgId) == 0; // 筛选符合条件的 role
 | 
			
		||||
                })
 | 
			
		||||
                .collect(Collectors.toList());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue