51 lines
1.8 KiB
Java
51 lines
1.8 KiB
Java
|
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());
|
||
|
}
|
||
|
|
||
|
}
|