提交自动带出考察人
This commit is contained in:
parent
dced18f74d
commit
8fe433e092
|
@ -0,0 +1,39 @@
|
|||
package shkd.repc.resm.formplugin;
|
||||
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
||||
import kd.bos.form.plugin.AbstractFormPlugin;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* 动态表单插件
|
||||
*/
|
||||
public class GetDataTemplatePlugin extends AbstractFormPlugin implements Plugin {
|
||||
|
||||
private static final String BIZ_OBJECT= "qeug_projectsource2";
|
||||
|
||||
private static final String PRO_SOURCE="qeug_projectsourceid2";
|
||||
|
||||
private static final String INVESTIGATION="resm_investigationplan";
|
||||
|
||||
private static final String PRO_BILL="repmd_projectbill";
|
||||
|
||||
@Override
|
||||
public void propertyChanged(PropertyChangedArgs e) {
|
||||
super.propertyChanged(e);
|
||||
String fieldKey = e.getProperty().getName();
|
||||
if (StringUtils.equals(BIZ_OBJECT,fieldKey)){
|
||||
String value = (String)this.getModel().getValue(BIZ_OBJECT);
|
||||
if (null!=value&&!"".equals(value)){
|
||||
switch (value){
|
||||
case "考察任务":
|
||||
this.getModel().setValue(PRO_SOURCE,INVESTIGATION);
|
||||
break;
|
||||
case "评估任务":
|
||||
this.getModel().setValue(PRO_SOURCE,PRO_BILL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,337 @@
|
|||
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.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 java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 自动设置评估任务考察对象-列表
|
||||
*/
|
||||
public class SetObjectFormPlugin 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_exam_task".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);
|
||||
DynamicObjectCollection entry = dynamicObject.getDynamicObjectCollection("entry_evaldetail");
|
||||
if (entry == null || entry.isEmpty()) return;
|
||||
String entryEvalUat = entry.get(0).getString("entryevaluatorstr");
|
||||
if ("".equals(entryEvalUat)) {
|
||||
Long orgId;
|
||||
// 获取考察详情
|
||||
QFilter qFilter = new QFilter("plandetails.evaltask", QCP.equals, dynamicObject.getPkValue());
|
||||
DynamicObject plane = BusinessDataServiceHelper.loadSingle("resm_investigationplan", qFilter.toArray());
|
||||
if (plane == null) return;
|
||||
DynamicObject project = plane.getDynamicObject("qeug_project");
|
||||
if (project == null) return;
|
||||
// 获取项目-所属组织
|
||||
QFilter qFilter1 = new QFilter("id", QCP.equals, project.get("id"));
|
||||
DynamicObject dynamicObject1 = BusinessDataServiceHelper.loadSingle("repmd_projectbill", qFilter1.toArray());
|
||||
if (dynamicObject1 == null) return;
|
||||
|
||||
DynamicObject org = dynamicObject1.getDynamicObject("org");
|
||||
if (org == null) return;
|
||||
|
||||
orgId = org.getLong("id");
|
||||
DynamicObjectCollection dataModelEntry = dataModel.getDynamicObjectCollection("entryentity");
|
||||
|
||||
// 使用 Stream API 获取所有匹配的 role 对象
|
||||
List<DynamicObject> matchingRoles = getMatchingRoles(dataModelEntry, orgId);
|
||||
|
||||
// 如果有匹配项
|
||||
if (!((List<?>) matchingRoles).isEmpty()) {
|
||||
creatExamData(matchingRoles, entry, "resm_examuator");
|
||||
} else {
|
||||
findParentOrgMatch(entry, orgId, dataModelEntry, "resm_examuator");
|
||||
}
|
||||
|
||||
}
|
||||
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});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查找上级组织
|
||||
*
|
||||
* @param entry 考察任务分录
|
||||
* @param orgId 当前工作流角色组织
|
||||
* @param dataModelEntry 取数模板
|
||||
*/
|
||||
private void findParentOrgMatch(DynamicObjectCollection entry, Long orgId, DynamicObjectCollection dataModelEntry, 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 = getMatchingRoles(dataModelEntry, orgId);
|
||||
|
||||
// 如果有匹配项,则返回;否则递归查找上级组织
|
||||
if (!matchingRoles.isEmpty()) {
|
||||
creatExamData(matchingRoles, entry, logotype);
|
||||
} else {
|
||||
findParentOrgMatch(entry, orgId, dataModelEntry, logotype); // 没有匹配项,递归调用上级组织
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成考察人
|
||||
*
|
||||
* @param matchingRoles 收集符合条件的人员
|
||||
* @param entry 考察任务分录
|
||||
* @param logotype 考察人||评估人权重设置分录
|
||||
*/
|
||||
private void creatExamData(List<DynamicObject> matchingRoles, DynamicObjectCollection entry, 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 = 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 权重转百分比
|
||||
*
|
||||
* @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,338 @@
|
|||
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 java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 自动设置考察任务考察对象-列表
|
||||
*/
|
||||
public class SetObjectListPlugin extends AbstractListPlugin implements Plugin {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(SetObjectListPlugin.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_exam_task".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) {
|
||||
//考察任务分录
|
||||
DynamicObjectCollection entry = dynamicObject.getDynamicObjectCollection("entry_evaldetail");
|
||||
if (entry == null || entry.isEmpty()) return;
|
||||
String entryEvalUat = entry.get(0).getString("entryevaluatorstr");
|
||||
if ("".equals(entryEvalUat)) {
|
||||
Long orgId;
|
||||
// 获取考察详情
|
||||
QFilter qFilter = new QFilter("plandetails.evaltask", QCP.equals, dynamicObject.getPkValue());
|
||||
DynamicObject plane = BusinessDataServiceHelper.loadSingle("resm_investigationplan", qFilter.toArray());
|
||||
if (plane == null) return;
|
||||
DynamicObject project = plane.getDynamicObject("qeug_project");
|
||||
if (project == null) return;
|
||||
// 获取项目-所属组织
|
||||
QFilter qFilter1 = new QFilter("id", QCP.equals, project.get("id"));
|
||||
DynamicObject dynamicObject1 = BusinessDataServiceHelper.loadSingle("repmd_projectbill", qFilter1.toArray());
|
||||
if (dynamicObject1 == null) return;
|
||||
|
||||
DynamicObject org = dynamicObject1.getDynamicObject("org");
|
||||
if (org == null) return;
|
||||
|
||||
orgId = org.getLong("id");
|
||||
DynamicObjectCollection dataModelEntry = dataModel.getDynamicObjectCollection("entryentity");
|
||||
|
||||
// 使用 Stream API 获取所有匹配的 role 对象
|
||||
List<DynamicObject> matchingRoles = getMatchingRoles(dataModelEntry, orgId);
|
||||
|
||||
// 如果有匹配项
|
||||
if (!((List<?>) matchingRoles).isEmpty()) {
|
||||
creatExamData(matchingRoles, entry, "resm_examuator");
|
||||
} else {
|
||||
findParentOrgMatch(entry, orgId, dataModelEntry, "resm_examuator");
|
||||
}
|
||||
|
||||
}
|
||||
SaveServiceHelper.saveOperate("resm_exam_task", new DynamicObject[]{dynamicObject}, OperateOption.create());
|
||||
}
|
||||
}
|
||||
}
|
||||
//评估任务
|
||||
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});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查找上级组织
|
||||
*
|
||||
* @param entry 考察任务分录
|
||||
* @param orgId 当前工作流角色组织
|
||||
* @param dataModelEntry 取数模板
|
||||
*/
|
||||
private void findParentOrgMatch(DynamicObjectCollection entry, Long orgId, DynamicObjectCollection dataModelEntry, 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 = getMatchingRoles(dataModelEntry, orgId);
|
||||
|
||||
// 如果有匹配项,则返回;否则递归查找上级组织
|
||||
if (!matchingRoles.isEmpty()) {
|
||||
creatExamData(matchingRoles, entry, logotype);
|
||||
} else {
|
||||
findParentOrgMatch(entry, orgId, dataModelEntry, logotype); // 没有匹配项,递归调用上级组织
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成考察人
|
||||
*
|
||||
* @param matchingRoles 收集符合条件的人员
|
||||
* @param entry 考察任务分录
|
||||
* @param logotype 考察人||评估人权重设置分录
|
||||
*/
|
||||
private void creatExamData(List<DynamicObject> matchingRoles, DynamicObjectCollection entry, 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 = 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;
|
||||
}
|
||||
DynamicObject examuator = BusinessDataServiceHelper.loadSingle(logotype, qFilter.toArray());
|
||||
if (examuator == null) {
|
||||
examuator = BusinessDataServiceHelper.newDynamicObject(logotype);
|
||||
String pkValue = dynamicObject.getString("id");
|
||||
examuator.set("evalentryid", pkValue);
|
||||
//评估人及权重设置表分录
|
||||
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 = 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 = 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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 权重计算
|
||||
*
|
||||
* @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());
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue