diff --git a/main/java/shkd/repc/iwork/IWorkParticipantPlugin.java b/main/java/shkd/repc/iwork/IWorkParticipantPlugin.java index f845d94..6faecf0 100644 --- a/main/java/shkd/repc/iwork/IWorkParticipantPlugin.java +++ b/main/java/shkd/repc/iwork/IWorkParticipantPlugin.java @@ -2,6 +2,8 @@ package shkd.repc.iwork; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; +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; @@ -11,8 +13,20 @@ import kd.bos.workflow.engine.extitf.IWorkflowPlugin; import java.util.List; +/** + * 设置流程参与人插件 + */ public class IWorkParticipantPlugin implements IWorkflowPlugin { + private static final Log logger = LogFactory.getLog(IWorkParticipantPlugin.class); + + /** + * recon_contractbill(合同)-印章管理员 + * recon_payreqbill(付款申请)-资金出纳和园区会计 + * recon_designchgbill(涉及变更) 供应商:designunit(设计单位) + * recon_chgauditorderbill(工程指令) 供应商:construnit(施工单位) + * recon_rewarddeductbill(奖励扣款) 供应商存在分录:rewarddeductentry(奖惩单分录) 供应商:entry_supplier(供应商) + */ @Override public List calcUserIds(AgentExecution execution) { List currentApprover = execution.getCurrentApprover(); // 获取当前节点的审批人 @@ -21,11 +35,6 @@ public class IWorkParticipantPlugin implements IWorkflowPlugin { String entityNumber = execution.getEntityNumber(); // 单据实体编码 DynamicObject entity = BusinessDataServiceHelper.loadSingle(businessKey, entityNumber); - - //recon_designchgbill(涉及变更) 供应商:designunit(设计单位) - //recon_chgauditorderbill(工程指令) 供应商:construnit(施工单位) - //recon_rewarddeductbill(奖励扣款) 供应商存在分录:rewarddeductentry(奖惩单分录) 供应商:entry_supplier(供应商) - if (entity != null) { switch (entityNumber) { case "recon_designchgbill": @@ -37,6 +46,12 @@ public class IWorkParticipantPlugin implements IWorkflowPlugin { case "recon_rewarddeductbill": getApprovers(entity, currentApprover, "rewarddeductentry", "entry_supplier"); break; + case "recon_contractbill": + handleContractBill(entity, currentApprover); + break; + case "recon_payreqbill": + handlePayReqBill(entity, currentApprover); + break; default: // 处理未定义的实体编码的情况(可选) break; @@ -115,4 +130,39 @@ public class IWorkParticipantPlugin implements IWorkflowPlugin { } } + private void handleContractBill(DynamicObject entity, List currentApprover) { + String partyatype = entity.getString("partyatype"); // 甲方类别 + if ("qeug_recon_developer".equals(partyatype)) { + DynamicObject dynamicObject = entity.getDynamicObject("multitypepartya"); // 甲方 + addApprover(currentApprover, dynamicObject, "qeug_userfield2", "印章管理员"); + } + } + + private void handlePayReqBill(DynamicObject entity, List currentApprover) { + DynamicObject contractbill = entity.getDynamicObject("contractbill"); // 付款申请_获取选择的合同 + if (contractbill != null) { + contractbill = BusinessDataServiceHelper.loadSingle(contractbill.getPkValue(), "recon_contractbill"); + String partyatype1 = contractbill.getString("partyatype"); // 甲方类别 + if ("qeug_recon_developer".equals(partyatype1)) { + DynamicObject dynamicObject = contractbill.getDynamicObject("multitypepartya"); // 甲方 + addApprover(currentApprover, dynamicObject, "qeug_userfield", "园区会计"); + addApprover(currentApprover, dynamicObject, "qeug_userfield1", "资金出纳"); + + } + } + } + + private void addApprover(List currentApprover, DynamicObject dynamicObject, String field, String role) { + if (dynamicObject != null) { + dynamicObject = BusinessDataServiceHelper.loadSingle(dynamicObject.getPkValue(), "qeug_recon_developer"); + DynamicObject approver = dynamicObject.getDynamicObject(field); + if (approver != null) { + Long id = approver.getLong("id"); + currentApprover.add(id); + logger.info("添加参与人(" + role + "):" + id + " " + approver.getString("name")); + } + } + } + + } diff --git a/main/java/shkd/repc/rebm/formplugin/PurPlanFormPlugin.java b/main/java/shkd/repc/rebm/formplugin/PurPlanFormPlugin.java new file mode 100644 index 0000000..bef3b5b --- /dev/null +++ b/main/java/shkd/repc/rebm/formplugin/PurPlanFormPlugin.java @@ -0,0 +1,57 @@ +package shkd.repc.rebm.formplugin; + +import kd.bos.bill.AbstractBillPlugIn; +import kd.bos.bill.BillShowParameter; +import kd.bos.bill.OperationStatus; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.form.ShowType; +import kd.bos.form.control.EntryGrid; +import kd.bos.form.events.HyperLinkClickEvent; +import kd.bos.form.events.HyperLinkClickListener; +import kd.bos.orm.query.QCP; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; + +import java.util.EventObject; + +public class PurPlanFormPlugin extends AbstractBillPlugIn implements HyperLinkClickListener { + + @Override + public void registerListener(EventObject e) { + super.registerListener(e); + + //集中--明细中---采购计划编号 点击事件监听单据体 + EntryGrid billentry = this.getView().getControl("qeug_cgxuentryss"); + billentry.addHyperClickListener(this); + } + + @Override + public void hyperLinkClick(HyperLinkClickEvent hyperLinkClickEvent) { + String clickEventFieldName = hyperLinkClickEvent.getFieldName(); + if ("qeug_qxbillno".equals(clickEventFieldName)) { + int rowIndex = hyperLinkClickEvent.getRowIndex(); + DynamicObjectCollection billentry = this.getModel().getDataEntity(Boolean.TRUE).getDynamicObjectCollection("qeug_cgxuentryss"); + if (billentry.size() > 0) { + String qeug_qxbillno = billentry.get(rowIndex).getString("qeug_qxbillno"); + showPurplan("recon_settleplanbill", qeug_qxbillno); + } + } + + } + + private void showPurplan(String formId, String shkd_purplanno) { + if (shkd_purplanno != null) { + DynamicObject object = BusinessDataServiceHelper.loadSingle(formId, new QFilter[]{new QFilter("qeug_billno", QCP.equals, shkd_purplanno)}); + if (null != object) { + BillShowParameter params = new BillShowParameter(); + params.setFormId(formId); + params.setPkId(object.getPkValue()); + params.getOpenStyle().setShowType(ShowType.MainNewTabPage); + params.setHasRight(true); + params.setStatus(OperationStatus.VIEW); + this.getView().showForm(params); + } + } + } +} diff --git a/main/java/shkd/repc/rebm/opplugin/PurapplyAuditOPPlugin.java b/main/java/shkd/repc/rebm/opplugin/PurapplyAuditOPPlugin.java new file mode 100644 index 0000000..a84811d --- /dev/null +++ b/main/java/shkd/repc/rebm/opplugin/PurapplyAuditOPPlugin.java @@ -0,0 +1,30 @@ +package shkd.repc.rebm.opplugin; + +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.entity.plugin.AbstractOperationServicePlugIn; +import kd.bos.entity.plugin.args.AfterOperationArgs; + +/** + * 采购需求单 + * qeug_purchaseapplybill + */ +public class PurapplyAuditOPPlugin extends AbstractOperationServicePlugIn { + + @Override + public void afterExecuteOperationTransaction(AfterOperationArgs e) { + super.afterExecuteOperationTransaction(e); + String operationKey = e.getOperationKey(); + if ("audit".equals(operationKey)) { + DynamicObject[] dataEntities = e.getDataEntities(); + DynamicObject dataEntity = dataEntities[0]; + DynamicObjectCollection collection = dataEntity.getDynamicObjectCollection("qeug_entryentity"); + if (collection.isEmpty()) { + DynamicObject add = collection.addNew(); +// add.set("",); + } + + } + + } +} diff --git a/main/java/shkd/repc/recon/listplugin/ContractSummaryListPlugin.java b/main/java/shkd/repc/recon/listplugin/ContractSummaryListPlugin.java index 151fb26..314149a 100644 --- a/main/java/shkd/repc/recon/listplugin/ContractSummaryListPlugin.java +++ b/main/java/shkd/repc/recon/listplugin/ContractSummaryListPlugin.java @@ -6,6 +6,7 @@ import kd.bos.dataentity.entity.DynamicObject; import kd.bos.entity.datamodel.ListSelectedRow; import kd.bos.entity.datamodel.ListSelectedRowCollection; import kd.bos.entity.filter.FilterParameter; +import kd.bos.form.IFormView; import kd.bos.form.events.*; import kd.bos.form.operate.FormOperate; import kd.bos.list.BillList; @@ -109,6 +110,10 @@ public class ContractSummaryListPlugin extends AbstractListPlugin implements ILi public void setFilter(SetFilterEvent e) { super.setFilter(e); +// IFormView parentView = this.getView().getParentView(); +// parentView.getFormShowParameter().getFormId(); +// parentView.getModel().getValue() +// e.getQFilters().add() Map customParams = this.getView().getFormShowParameter().getCustomParams(); if (customParams.isEmpty()) { return; diff --git a/main/java/shkd/repc/resm/formplugin/AutomaticallySetObjectPlugin.java b/main/java/shkd/repc/resm/formplugin/AutomaticallySetObjectPlugin.java new file mode 100644 index 0000000..580a51c --- /dev/null +++ b/main/java/shkd/repc/resm/formplugin/AutomaticallySetObjectPlugin.java @@ -0,0 +1,219 @@ +package shkd.repc.resm.formplugin; + +import kd.bos.bill.AbstractBillPlugIn; +import kd.bos.dataentity.OperateOption; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.utils.StringUtils; +import kd.bos.form.control.Control; +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.botp.BFTrackerServiceHelper; +import kd.bos.servicehelper.operation.SaveServiceHelper; +import kd.bos.servicehelper.org.OrgUnitServiceHelper; +import kd.bos.servicehelper.org.OrgViewType; +import kd.scm.bid.common.constant.entity.BidTemplateMangeEntity; +import kd.sdk.plugin.Plugin; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.EventObject; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 自动设置考察任务考察对象 + */ +public class AutomaticallySetObjectPlugin extends AbstractBillPlugIn implements Plugin { + + private static final Log logger = LogFactory.getLog(AutomaticallySetObjectPlugin.class); + + @Override + public void afterBindData(EventObject e) { + super.afterBindData(e); + + DynamicObject dataEntity = this.getModel().getDataEntity(); + DynamicObjectCollection entry = dataEntity.getDynamicObjectCollection("entry_evaldetail"); + + if (entry == null || entry.isEmpty()) return; + + String object = entry.get(0).getString("entryevaluatorstr"); + + // 状态暂存且分录考察人为空 + if ("A".equals(this.getModel().getValue("billstatus")) && "".equals(object)) { + + // 获取取值逻辑 + DynamicObject dataModel = BusinessDataServiceHelper.loadSingle("qeug_datamodel", + (new QFilter("qeug_projectsource", QCP.equals, "考察计划")).toArray()); + + if (dataModel == null) return; + + String projectSource = dataModel.getString("qeug_projectsource"); + Long orgId; + if ("考察计划".equals(projectSource)) { + + // 获取考察详情 + QFilter qFilter = new QFilter("plandetails.evaltask", QCP.equals, dataEntity.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 matchingRoles = dataModelEntry.stream() + .map(modelEntry -> modelEntry.getString("qeug_rolenumber")) + .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()); + // 如果有匹配项 + if (!((List) matchingRoles).isEmpty()) { + creatExamData(matchingRoles, entry); + } else { + findParentOrgMatch(entry, orgId, dataModelEntry); + } + SaveServiceHelper.saveOperate("resm_exam_task", new DynamicObject[]{dataEntity}, OperateOption.create()); + } + } + this.getView().updateView("entry_evaldetail"); + } + + + /** + * 递归查找上级组织 + * + * @param entry 考察任务分录 + * @param orgId 当前工作流角色组织 + * @param dataModelEntry 取数模板 + */ + private void findParentOrgMatch(DynamicObjectCollection entry, Long orgId, DynamicObjectCollection dataModelEntry) { + if (orgId == null) return; + //取上级组织. + List dptIds = new ArrayList<>(); + dptIds.add(orgId); + Map 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 对象 + Long finalOrgId = orgId; + List matchingRoles = dataModelEntry.stream() + .map(modelEntry -> modelEntry.getString("qeug_rolenumber")) + .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(finalOrgId) == 0; // 筛选符合条件的 role + }) + .collect(Collectors.toList()); + // 如果有匹配项,则返回;否则递归查找上级组织 + if (!matchingRoles.isEmpty()) { + creatExamData(matchingRoles, entry); + } else { + findParentOrgMatch(entry, orgId, dataModelEntry); // 没有匹配项,递归调用上级组织 + } + } + } + } + + /** + * 生成考察人 + * @param matchingRoles 收集符合条件的人员 + * @param entry 考察任务分录 + */ + private void creatExamData(List matchingRoles, DynamicObjectCollection entry) { + for (DynamicObject dynamicObject : entry) { + StringBuilder objectText = new StringBuilder(); + DynamicObject examuator = BusinessDataServiceHelper.newDynamicObject("resm_examuator"); + String pkValue = dynamicObject.getString("id"); + examuator.set("evalentryid", pkValue); + + DynamicObjectCollection entryCollection = examuator.getDynamicObjectCollection("entry_evaluator"); + + boolean isSingleRole = matchingRoles.size() == 1; + + for (int i = 0; i < matchingRoles.size(); i++) { + DynamicObject matchingRole = matchingRoles.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"); + BigDecimal weight = calculateWeight(matchingRoles.size(), i); + String weightPercentage = formatWeight(weight); + + if (isSingleRole) { + objectText.append(name).append("(").append(weightPercentage).append(")"); + } else { + if (i > 0) objectText.append(";"); + objectText.append(name).append("(").append(weightPercentage).append(")"); + } + + evaluator.set("weight", weight); + evaluator.set("seq", i + 1); + } + dynamicObject.set("entryevaluatorstr", objectText); + try { + SaveServiceHelper.saveOperate("resm_examuator", new DynamicObject[]{examuator}, OperateOption.create()); + } catch (Exception ex) { + logger.error("保存考察人数据失败", ex); + } + } + } + + + /** + * 权重计算 + * @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) + "%"; + } + + + +} \ No newline at end of file