From 32ab919eef88603640d2538308d932e1289de53c Mon Sep 17 00:00:00 2001 From: huangdehua <2329023417@qq.com> Date: Thu, 2 Jul 2026 09:16:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E5=91=98=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MembershipApplyHistoryListFilterPlugin.java | 35 +++ .../member/MembershipApplyListFilterPlugin.java | 4 +- .../member/UnitNameChangeFormInitPlugin.java | 164 +++++++++++- .../member/UnitNameChangeOperationPlugin.java | 283 +-------------------- .../member/ViewHistoryBillOperationPlugin.java | 107 ++------ 5 files changed, 218 insertions(+), 375 deletions(-) create mode 100644 common/common-association/src/main/java/apelet/association/plugin/member/MembershipApplyHistoryListFilterPlugin.java diff --git a/common/common-association/src/main/java/apelet/association/plugin/member/MembershipApplyHistoryListFilterPlugin.java b/common/common-association/src/main/java/apelet/association/plugin/member/MembershipApplyHistoryListFilterPlugin.java new file mode 100644 index 0000000..0ff923d --- /dev/null +++ b/common/common-association/src/main/java/apelet/association/plugin/member/MembershipApplyHistoryListFilterPlugin.java @@ -0,0 +1,35 @@ +package apelet.association.plugin.member; + +import apelet.common.online.abstractplugin.ListPlugin; +import apelet.common.online.dto.OnlineEventPluginExecuteDto; +import apelet.common.orm.impl.Filter; +import apelet.common.orm.impl.FilterItem; + +import java.util.Map; + +/** + * 入会申请历史列表过滤插件。 + */ +public class MembershipApplyHistoryListFilterPlugin extends ListPlugin { + + private static final String PARAM_BILL_NUMBER = "billNumber"; + + private static final String FIELD_NUMBER = "number"; + + @Override + protected Filter getFilter() { + Filter filter = new Filter(); + OnlineEventPluginExecuteDto dto = getDto(); + if (dto == null || dto.getEventParams() == null) { + return filter; + } + + Map parentParams = dto.getEventParams(); + Object billNumber = parentParams.get(PARAM_BILL_NUMBER); + if (billNumber != null && !billNumber.toString().isEmpty()) { + filter.add(new FilterItem(FIELD_NUMBER, "=", billNumber.toString())); + filter.add(new FilterItem("history", "=", "1")); + } + return filter; + } +} diff --git a/common/common-association/src/main/java/apelet/association/plugin/member/MembershipApplyListFilterPlugin.java b/common/common-association/src/main/java/apelet/association/plugin/member/MembershipApplyListFilterPlugin.java index e83f43a..cdfb3a5 100644 --- a/common/common-association/src/main/java/apelet/association/plugin/member/MembershipApplyListFilterPlugin.java +++ b/common/common-association/src/main/java/apelet/association/plugin/member/MembershipApplyListFilterPlugin.java @@ -21,12 +21,12 @@ public class MembershipApplyListFilterPlugin extends ListPlugin { /** * 是否历史字段 */ - private static final String FIELD_IS_HISTORY = "is_history"; + private static final String FIELD_IS_HISTORY = "history"; /** * 非历史记录 */ - private static final Integer IS_HISTORY_NO = 0; + private static final String IS_HISTORY_NO = "0"; @Override protected Filter getFilter() { diff --git a/common/common-association/src/main/java/apelet/association/plugin/member/UnitNameChangeFormInitPlugin.java b/common/common-association/src/main/java/apelet/association/plugin/member/UnitNameChangeFormInitPlugin.java index 7f2ad3d..11d07b7 100644 --- a/common/common-association/src/main/java/apelet/association/plugin/member/UnitNameChangeFormInitPlugin.java +++ b/common/common-association/src/main/java/apelet/association/plugin/member/UnitNameChangeFormInitPlugin.java @@ -7,6 +7,8 @@ import apelet.common.online.abstractplugin.ExecutePluginParent; import apelet.common.online.model.constant.AttributeEnum; import com.alibaba.fastjson.JSONObject; +import java.util.HashMap; +import java.util.List; import java.util.Map; @@ -23,12 +25,19 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { * 来源参数key - 单据ID */ private static final String PARAM_BILL_ID = "sourceBillId"; + private static final String PARAM_BILL_ID_ALT = "srcbillid"; /** * 来源参数key - 单据编号 */ private static final String PARAM_BILL_NUMBER = "sourceBillNumber"; + private static final String CHILD_TABLE_NAME = "membership_apply_entry"; + + private static final String CHILD_PARENT_FIELD = "parent_id"; + + private static final String CHILD_WIDGET_KEY = "table1777360622546"; + /** * 需要设置为只读的字段列表(除单位名称外) */ @@ -37,7 +46,6 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { "number", // 单据编号 "billstatus", // 单据状态 "membershipMangerId",// 会员负责人 - "unitName", // 单位名称 "natureUnit", // 单位性质 "menbershipAttributes",// 会员属性 "scopeBusiness", // 业务经营范围 @@ -45,7 +53,6 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { "businessRegistNumber",// 工商注册号 "registCapital", // 注册资金 "registTime", // 注册时间 - "bankReceiptV", // 银行收款凭证号 "companyAddress", // 企业地址 "history", // 是否历史 "versionNumber", // 版本号 @@ -61,6 +68,29 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { "unitname" }; + private static final Map FIELD_WIDGET_MAPPING = new HashMap<>(); + + static { + FIELD_WIDGET_MAPPING.put("create_user_id", "createUserId"); + FIELD_WIDGET_MAPPING.put("create_time", "createTime"); + FIELD_WIDGET_MAPPING.put("update_user_id", "updateUserId"); + FIELD_WIDGET_MAPPING.put("update_time", "updateTime"); + FIELD_WIDGET_MAPPING.put("deleted_flag", "deletedFlag"); + FIELD_WIDGET_MAPPING.put("is_history", "history"); + FIELD_WIDGET_MAPPING.put("nature_unit", "natureUnit"); + FIELD_WIDGET_MAPPING.put("unit_name", "unitName"); + FIELD_WIDGET_MAPPING.put("membership_manger_id", "membershipMangerId"); + FIELD_WIDGET_MAPPING.put("membership_type", "membershipType"); + FIELD_WIDGET_MAPPING.put("menbership_attributes", "menbershipAttributes"); + FIELD_WIDGET_MAPPING.put("scope_business", "scopeBusiness"); + FIELD_WIDGET_MAPPING.put("business_regist_number", "businessRegistNumber"); + FIELD_WIDGET_MAPPING.put("regist_capital", "registCapital"); + FIELD_WIDGET_MAPPING.put("regist_time", "registTime"); + FIELD_WIDGET_MAPPING.put("company_address", "companyAddress"); + FIELD_WIDGET_MAPPING.put("version_number", "versionNumber"); + FIELD_WIDGET_MAPPING.put(CHILD_TABLE_NAME, CHILD_WIDGET_KEY); + } + @Override public void formCreated(String widgetVariableName, ObjectValue objectValue) { super.formCreated(widgetVariableName, objectValue); @@ -80,6 +110,11 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { // 2. 设置其他字段为只读,只有单位名称可编辑 setFieldsReadonly(); + + //3.隐藏按钮 + this.setWidgetAttribute("submit", AttributeEnum.SHOW, false); + this.setWidgetAttribute("审核", AttributeEnum.SHOW, true); + this.setWidgetAttribute("table-btn primary", AttributeEnum.SHOW, false); } /** @@ -89,7 +124,20 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { private String getSourceBillId(ObjectValue objectValue) { Object eventparams = objectValue.get("eventparams"); if (eventparams instanceof JSONObject){ - return ((JSONObject) eventparams).getString(PARAM_BILL_ID); + JSONObject params = (JSONObject) eventparams; + String sourceBillId = params.getString(PARAM_BILL_ID); + if (sourceBillId == null || sourceBillId.isEmpty()) { + sourceBillId = params.getString(PARAM_BILL_ID_ALT); + } + return sourceBillId; + } + if (eventparams instanceof Map) { + Map params = (Map) eventparams; + Object sourceBillId = params.get(PARAM_BILL_ID); + if (sourceBillId == null || sourceBillId.toString().isEmpty()) { + sourceBillId = params.get(PARAM_BILL_ID_ALT); + } + return sourceBillId == null ? null : sourceBillId.toString(); } return null; } @@ -103,6 +151,10 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { if (eventparams instanceof JSONObject){ return ((JSONObject) eventparams).getString(PARAM_BILL_NUMBER); } + if (eventparams instanceof Map) { + Object sourceBillNumber = ((Map) eventparams).get(PARAM_BILL_NUMBER); + return sourceBillNumber == null ? null : sourceBillNumber.toString(); + } return null; } @@ -189,23 +241,121 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { } // 设置字段值到ObjectValue - if (value != null) { - objectValue.put(key, value); - } + String widgetKey = getWidgetKey(key); + objectValue.put(widgetKey, value); // 设置字段值到表单控件 try { - this.setWidgetAttribute(key, AttributeEnum.VALUE_CHANGE, value); + this.setWidgetAttribute(widgetKey, AttributeEnum.VALUE_CHANGE, value); } catch (Exception e) { // 字段可能不存在,忽略异常 } } + syncHistoryAndVersionForChangeBill(objectValue, ormUtil, sourceBill); + // 保存源单据ID作为标识(用于后续业务逻辑) + fillSourceBillEntryData(objectValue, ormUtil, sourceBillId); objectValue.put(PARAM_BILL_ID, sourceBillId); } catch (Exception e) { e.printStackTrace(); } } + + private String getWidgetKey(String fieldKey) { + String widgetKey = FIELD_WIDGET_MAPPING.get(fieldKey); + return widgetKey == null ? fieldKey : widgetKey; + } + + private void syncHistoryAndVersionForChangeBill(ObjectValue objectValue, + OrmGenDataSourceUtil ormUtil, + ObjectValue sourceBill) throws Exception { + if (sourceBill == null) { + return; + } + + String number = sourceBill.getString("number"); + if (number == null || number.trim().isEmpty()) { + return; + } + + apelet.common.orm.impl.Filter sameNumberFilter = new apelet.common.orm.impl.Filter(); + sameNumberFilter.add(new apelet.common.orm.impl.FilterItem("number", "=", number)); + ObjectCollection sameBills = ormUtil.query("membership_apply", sameNumberFilter, null); + + int version = 1; + if (sameBills != null && !sameBills.isEmpty()) { + List bills = new java.util.ArrayList<>(); + for (int i = 0; i < sameBills.size(); i++) { + ObjectValue bill = sameBills.getObject(i); + if (bill != null) { + bills.add(bill); + } + } + + bills.sort(java.util.Comparator.comparingInt(this::getVersionNumberSafe)); + for (ObjectValue bill : bills) { + bill.put("is_history", 1); + bill.put("version_number", version); + ormUtil.update("membership_apply", bill, null); + version++; + } + } + + objectValue.put("is_history", 0); + objectValue.put("history", 0); + objectValue.put("version_number", version); + objectValue.put("versionNumber", version); + + try { + this.setWidgetAttribute("history", AttributeEnum.VALUE_CHANGE, "0"); + this.setWidgetAttribute("versionNumber", AttributeEnum.VALUE_CHANGE, version); + } catch (Exception e) { + // 字段可能不存在,忽略异常 + } + } + + private int getVersionNumberSafe(ObjectValue bill) { + if (bill == null) { + return 0; + } + Object value = bill.getValues().get("version_number"); + if (value == null) { + value = bill.getValues().get("versionNumber"); + } + if (value == null) { + return 0; + } + try { + return Integer.parseInt(value.toString()); + } catch (Exception e) { + return 0; + } + } + + private void fillSourceBillEntryData(ObjectValue objectValue, OrmGenDataSourceUtil ormUtil, String sourceBillId) throws Exception { + if (sourceBillId == null || sourceBillId.isEmpty()) { + return; + } + + apelet.common.orm.impl.Filter entryFilter = new apelet.common.orm.impl.Filter(); + entryFilter.add(new apelet.common.orm.impl.FilterItem(CHILD_PARENT_FIELD, "=", sourceBillId)); + ObjectCollection entryCollection = ormUtil.query(CHILD_TABLE_NAME, entryFilter, null); + if (entryCollection == null) { + return; + } + ObjectCollection detailEntry = objectValue.getObjectCollection(CHILD_WIDGET_KEY); + if (detailEntry == null) { + detailEntry = new ObjectCollection(); + } + detailEntry.addObjectCollection(entryCollection); + + objectValue.put(CHILD_WIDGET_KEY, detailEntry); + try { + this.setWidgetAttribute(CHILD_WIDGET_KEY, AttributeEnum.VALUE_CHANGE, detailEntry); + } catch (Exception e) { + // 字段可能不存在,忽略异常 + } + } } diff --git a/common/common-association/src/main/java/apelet/association/plugin/member/UnitNameChangeOperationPlugin.java b/common/common-association/src/main/java/apelet/association/plugin/member/UnitNameChangeOperationPlugin.java index c40b335..1468018 100644 --- a/common/common-association/src/main/java/apelet/association/plugin/member/UnitNameChangeOperationPlugin.java +++ b/common/common-association/src/main/java/apelet/association/plugin/member/UnitNameChangeOperationPlugin.java @@ -1,295 +1,30 @@ package apelet.association.plugin.member; -import apelet.common.core.object.ObjectCollection; import apelet.common.core.object.ObjectValue; -import apelet.common.generator.utils.OrmGenDataSourceUtil; import apelet.common.online.plugin.BeginOperationTransactionArgs; import apelet.common.online.plugin.OperationResult; import apelet.common.online.plugin.OperationServicePlugIn; -import apelet.common.orm.impl.Filter; -import apelet.common.orm.impl.FilterItem; - -import java.util.Iterator; -import java.util.Map; /** - * @ClassName: UnitNameChangeOperationPlugin - * @Author: huangdehua - * @Date: 2026/4/30 11:02 - * @Description: 入会申请与审核 变更单位名称 + * 单位名称变更单操作插件。 */ public class UnitNameChangeOperationPlugin extends OperationServicePlugIn { - // 主表与子表数据源变量名,需与在线表单配置保持一致。 - private static final String TABLE_NAME = "membership_apply"; - private static final String CHILD_TABLE_NAME = "membership_apply_entry"; - private static final String FIELD_ID = "id"; private static final String FIELD_NUMBER = "number"; - private static final String FIELD_UNIT_NAME = "unit_name"; - private static final String FIELD_BILL_STATUS = "billstatus"; - private static final String FIELD_IS_HISTORY = "is_history"; - private static final String FIELD_VERSION_NUMBER = "version_number"; - private static final String STATUS_ACTIVE = "A"; - private static final String STATUS_CHANGED = "C"; - private static final Integer IS_HISTORY_YES = 1; - private static final Integer IS_HISTORY_NO = 0; @Override public void beginOperationTransaction(BeginOperationTransactionArgs args) { - try { - ObjectValue model = args.getModel(); - if (model == null) { - setFailResult("获取表单数据失败"); - return; - } - - String pkId = model.getString(FIELD_ID); - if (pkId == null || pkId.isEmpty()) { - setFailResult("新增单据不允许执行变更操作"); - return; - } - - String newUnitName = model.getString(FIELD_UNIT_NAME); - if (newUnitName == null || newUnitName.isEmpty()) { - setFailResult("单位名称不能为空"); - return; - } - - OrmGenDataSourceUtil ormUtil = ormGenDataSourceUtil(); - if (ormUtil == null) { - setFailResult("获取数据库连接失败"); - return; - } - - Filter pkFilter = new Filter(); - pkFilter.add(new FilterItem(FIELD_ID, "=", pkId)); - ObjectCollection oldCollection = ormUtil.query(TABLE_NAME, pkFilter, null); - if (oldCollection == null || oldCollection.isEmpty()) { - setFailResult("未找到当前单据数据"); - return; - } - - ObjectValue oldBill = oldCollection.getObject(0); - String oldUnitName = oldBill.getString(FIELD_UNIT_NAME); - if (oldUnitName == null || oldUnitName.equals(newUnitName)) { - setFailResult("单位名称未发生变化,无需变更"); - return; - } - - String billNumber = oldBill.getString(FIELD_NUMBER); - if (billNumber == null || billNumber.isEmpty()) { - setFailResult("单据编号不能为空"); - return; - } - - // 通过单据编号 + 排除当前ID,查找同一业务单据之前变更产生的记录 - ObjectValue previousChangedBill = findBillByNumberAndStatus(ormUtil, billNumber, pkId, STATUS_CHANGED); - ObjectValue previousActiveBill = findBillByNumberAndStatus(ormUtil, billNumber, pkId, STATUS_ACTIVE); - - if (previousActiveBill != null) { - // 二次变更:同一单据编号下已存在 A 记录(上次变更产生的),直接更新其 unit_name,无需新增 - // 获取当前历史单据的最大版本号 - int currentMaxVersion = getMaxVersionNumber(ormUtil, billNumber, pkId); - if (previousChangedBill != null) { - // 已有历史 C 记录,用当前旧单据数据覆盖它,并更新版本号 - overwriteBill(ormUtil, previousChangedBill, oldBill, currentMaxVersion + 1); - } else { - // 无历史 C 记录,将当前旧单据标记为 C,并设置版本号 - oldBill.put(FIELD_BILL_STATUS, STATUS_CHANGED); - oldBill.put(FIELD_IS_HISTORY, IS_HISTORY_YES); - oldBill.put(FIELD_VERSION_NUMBER, currentMaxVersion + 1); - ormUtil.update(TABLE_NAME, oldBill, null); - } - // 直接更新 A 记录的 unit_name - previousActiveBill.put(FIELD_UNIT_NAME, newUnitName); - ormUtil.update(TABLE_NAME, previousActiveBill, null); - } else { - // 首次变更:同一单据编号下没有 A 记录,走新增逻辑 - oldBill.put(FIELD_BILL_STATUS, STATUS_CHANGED); - oldBill.put(FIELD_IS_HISTORY, IS_HISTORY_YES); - oldBill.put(FIELD_VERSION_NUMBER, 1); - ormUtil.update(TABLE_NAME, oldBill, null); - - ObjectValue newBill = new ObjectValue(TABLE_NAME); - copyValuesWithoutId(oldBill, newBill, FIELD_BILL_STATUS, FIELD_IS_HISTORY, FIELD_VERSION_NUMBER); - newBill.put(FIELD_UNIT_NAME, newUnitName); - newBill.put(FIELD_IS_HISTORY, IS_HISTORY_NO); - newBill.put(FIELD_VERSION_NUMBER, 1); - - ObjectCollection copiedChildren = copyChildCollection(model.getValues().get(CHILD_TABLE_NAME)); - if (copiedChildren != null && !copiedChildren.isEmpty()) { - newBill.put(CHILD_TABLE_NAME, copiedChildren); - } - - ormUtil.addNew(TABLE_NAME, newBill); - updateNewBillStatus(ormUtil, pkId, newUnitName); - } - setSuccessResult(); - } catch (Exception e) { - e.printStackTrace(); - setFailResult("单位名称变更处理失败:" + e.getMessage()); - } - } - - private void copyValuesWithoutId(ObjectValue source, ObjectValue target, String... excludedFields) { - Map values = source.getValues(); - Iterator it = values.keySet().iterator(); - while (it.hasNext()) { - String key = it.next(); - if (FIELD_ID.equals(key) || isExcludedField(key, excludedFields)) { - continue; - } - // 排除 history 和 versionNumber 字段,由业务逻辑单独设置 - if (FIELD_IS_HISTORY.equals(key) || FIELD_VERSION_NUMBER.equals(key)) { - continue; - } - target.put(key, values.get(key)); - } - } - - private boolean isExcludedField(String fieldName, String... excludedFields) { - if (excludedFields == null) { - return false; - } - for (String excludedField : excludedFields) { - if (fieldName.equals(excludedField)) { - return true; - } - } - return false; - } - - private ObjectCollection copyChildCollection(Object childValue) { - if (!(childValue instanceof ObjectCollection)) { - return null; - } - - // 子表行只去掉主键,其他字段原样复制,避免丢失联系人等历史明细。 - ObjectCollection oldChildren = (ObjectCollection) childValue; - if (oldChildren.isEmpty()) { - return null; - } - - ObjectCollection newChildren = new ObjectCollection(); - for (int i = 0; i < oldChildren.size(); i++) { - ObjectValue oldChild = oldChildren.getObject(i); - if (oldChild == null) { - continue; - } - - ObjectValue newChild = new ObjectValue(null); - copyValuesWithoutId(oldChild, newChild); - newChildren.addObject(newChild); - } - return newChildren; - } - - /** - * 通过单据编号查找同一业务单据的变更记录。 - * 查询条件:number = billNumber AND id != excludePkId AND billstatus = status - * - * @param ormUtil ORM 工具 - * @param billNumber 单据编号(关联同一业务单据) - * @param excludePkId 排除的单据主键(当前操作的记录) - * @param status 单据状态 - * @return 匹配的单据,无则返回 null - */ - private ObjectValue findBillByNumberAndStatus(OrmGenDataSourceUtil ormUtil, String billNumber, String excludePkId, String status) throws Exception { - Filter filter = new Filter(); - filter.add(new FilterItem(FIELD_NUMBER, "=", billNumber)); - filter.add(new FilterItem(FIELD_ID, "<>", excludePkId)); - //filter.add(new FilterItem(FIELD_BILL_STATUS, "=", status)); - ObjectCollection collection = ormUtil.query(TABLE_NAME, filter, null); - if (collection == null || collection.isEmpty()) { - return null; - } - return collection.getObject(0); - } - - /** - * 用源单据数据覆盖目标单据(保留目标单据的 ID,其他字段用源数据替换)。 - * - * @param ormUtil ORM 工具 - * @param targetBill 被覆盖的历史单据(保留其 ID) - * @param sourceBill 用于覆盖的数据源 - * @param versionNumber 版本号 - */ - private void overwriteBill(OrmGenDataSourceUtil ormUtil, ObjectValue targetBill, ObjectValue sourceBill, int versionNumber) throws Exception { - ObjectValue overwrittenBill = new ObjectValue(TABLE_NAME); - overwrittenBill.put(FIELD_ID, targetBill.getString(FIELD_ID)); - copyValuesWithoutId(sourceBill, overwrittenBill, FIELD_BILL_STATUS, FIELD_IS_HISTORY, FIELD_VERSION_NUMBER); - overwrittenBill.put(FIELD_BILL_STATUS, STATUS_CHANGED); - overwrittenBill.put(FIELD_IS_HISTORY, IS_HISTORY_YES); - overwrittenBill.put(FIELD_VERSION_NUMBER, versionNumber); - ormUtil.update(TABLE_NAME, overwrittenBill, null); + ObjectValue model = args.getModel(); + keepExistingBillNumber(model); } - private void updateNewBillStatus(OrmGenDataSourceUtil ormUtil, String oldPkId, String newUnitName) throws Exception { - Filter filter = new Filter(); - filter.add(new FilterItem(FIELD_ID, "<>", oldPkId)); - filter.add(new FilterItem(FIELD_UNIT_NAME, "=", newUnitName)); - ObjectCollection collection = ormUtil.query(TABLE_NAME, filter, null); - if (collection == null || collection.isEmpty()) { + private void keepExistingBillNumber(ObjectValue model) { + if (model == null) { return; } - - ObjectValue newBill = collection.getObject(0); - if (newBill == null) { - return; - } - - newBill.put(FIELD_BILL_STATUS, STATUS_ACTIVE); - newBill.put(FIELD_IS_HISTORY, IS_HISTORY_NO); - newBill.put(FIELD_VERSION_NUMBER, 1); - ormUtil.update(TABLE_NAME, newBill, null); - } - - private void setSuccessResult() { - OperationResult result = new OperationResult(); - result.setSuccess(true); - setOperationResult(result); - } - - private void setFailResult(String message) { - OperationResult result = new OperationResult(); - result.setSuccess(false); - result.setMessage(message); - result.setShowMessage(true); - setOperationResult(result); - } - - /** - * 获取同一单据编号下的最大版本号(排除当前操作的记录)。 - * - * @param ormUtil ORM 工具 - * @param billNumber 单据编号 - * @param excludePkId 排除的单据主键 - * @return 最大版本号,未找到则返回 0 - */ - private int getMaxVersionNumber(OrmGenDataSourceUtil ormUtil, String billNumber, String excludePkId) throws Exception { - Filter filter = new Filter(); - filter.add(new FilterItem(FIELD_NUMBER, "=", billNumber)); - filter.add(new FilterItem(FIELD_ID, "<>", excludePkId)); - ObjectCollection collection = ormUtil.query(TABLE_NAME, filter, null); - if (collection == null || collection.isEmpty()) { - return 0; - } - int maxVersion = 0; - for (int i = 0; i < collection.size(); i++) { - ObjectValue bill = collection.getObject(i); - Object versionObj = bill.getValues().get(FIELD_VERSION_NUMBER); - if (versionObj != null) { - int version; - if (versionObj instanceof Integer) { - version = (Integer) versionObj; - } else { - version = Integer.parseInt(versionObj.toString()); - } - if (version > maxVersion) { - maxVersion = version; - } - } + String number = model.getString(FIELD_NUMBER); + if (number != null && !number.trim().isEmpty()) { + model.put(FIELD_NUMBER, number); } - return maxVersion; } -} +} \ No newline at end of file diff --git a/common/common-association/src/main/java/apelet/association/plugin/member/ViewHistoryBillOperationPlugin.java b/common/common-association/src/main/java/apelet/association/plugin/member/ViewHistoryBillOperationPlugin.java index b6e78d9..5fb3fc2 100644 --- a/common/common-association/src/main/java/apelet/association/plugin/member/ViewHistoryBillOperationPlugin.java +++ b/common/common-association/src/main/java/apelet/association/plugin/member/ViewHistoryBillOperationPlugin.java @@ -3,6 +3,7 @@ package apelet.association.plugin.member; import apelet.common.core.object.ObjectCollection; import apelet.common.core.object.ObjectValue; import apelet.common.generator.utils.OrmGenDataSourceUtil; +import apelet.common.online.dto.OnlineEventPluginExecuteDto; import apelet.common.orm.impl.Filter; import apelet.common.orm.impl.FilterItem; import apelet.common.online.abstractplugin.ExecutePluginParent; @@ -11,6 +12,7 @@ import apelet.common.online.model.constant.ShowTypeEnum; import apelet.common.online.model.constant.ViewStatus; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -27,16 +29,12 @@ public class ViewHistoryBillOperationPlugin extends ExecutePluginParent { */ private static final String BUTTON_KEY = "查看历史"; - /** - * 列表页面中表格控件的变量名/key - */ - private static final String TABLE_WIDGET_KEY = "membership_apply_list"; /** * 历史单据列表表单ID * 需要在平台配置中创建历史单据列表表单并配置此ID */ - private static final String HISTORY_LIST_FORM_ID = "membership_apply_history_list"; + private static final String HISTORY_LIST_FORM_ID = "2071862530363363328"; /** * 传递到历史列表的参数key - 单据编号 @@ -53,30 +51,6 @@ public class ViewHistoryBillOperationPlugin extends ExecutePluginParent { */ private static final String FIELD_NUMBER = "number"; - /** - * 字段:是否历史 - */ - private static final String FIELD_IS_HISTORY = "is_history"; - - /** - * 字段:单据状态 - */ - private static final String FIELD_BILL_STATUS = "billstatus"; - - /** - * 字段:版本号 - */ - private static final String FIELD_VERSION_NUMBER = "version_number"; - - /** - * 字段:单位名称 - */ - private static final String FIELD_UNIT_NAME = "unit_name"; - - /** - * 字段:变更时间 - */ - private static final String FIELD_UPDATE_TIME = "update_time"; /** * 按钮点击事件(列表按钮) @@ -93,15 +67,18 @@ public class ViewHistoryBillOperationPlugin extends ExecutePluginParent { return; } - // 【列表场景】通过 getSelectData 获取选中/点击行的数据 - Map selectedRow = getSelectData(objectValue, TABLE_WIDGET_KEY); - if (selectedRow == null) { + + OnlineEventPluginExecuteDto dto = getDto(); + List rowDatas = dto.getModel().getRowDatas(); + if (rowDatas == null || rowDatas.size() != 1) { showWarningMessage("请先在列表中选中一条单据"); + this.cancelOperate(); return; } + Map data = rowDatas.get(0); // 从选中行中获取单据编号 - Object numberObj = selectedRow.get(FIELD_NUMBER); + Object numberObj = data.get(FIELD_NUMBER); String billNumber = (numberObj != null) ? numberObj.toString() : ""; if (billNumber.isEmpty()) { showWarningMessage("选中的单据缺少编号信息,请重新选择"); @@ -110,13 +87,13 @@ public class ViewHistoryBillOperationPlugin extends ExecutePluginParent { // 查询该单据的所有历史记录 ObjectCollection historyList = queryHistoryBills(billNumber); - if (historyList == null || historyList.isEmpty()) { - showWarnMessage("该单据暂无历史变更记录"); + if (historyList == null || historyList.size() <= 1) { + showWarningMessage("该单据暂无历史变更记录"); return; } // 打开历史单据列表弹窗 - openHistoryListPopup(billNumber, historyList); + openHistoryListPopup(billNumber); } /** @@ -135,8 +112,7 @@ public class ViewHistoryBillOperationPlugin extends ExecutePluginParent { // 查询条件:相同单据编号的所有记录(按版本号降序) Filter filter = new Filter(); filter.add(new FilterItem(FIELD_NUMBER, "=", billNumber)); - // 排序:版本号降序,最新在前 - String orderBy = FIELD_VERSION_NUMBER + " desc"; + ObjectCollection result = ormUtil.query(TABLE_NAME, filter, null); return result; @@ -151,9 +127,8 @@ public class ViewHistoryBillOperationPlugin extends ExecutePluginParent { * 打开历史单据列表弹窗 * * @param billNumber 单据编号 - * @param historyList 历史单据列表 */ - private void openHistoryListPopup(String billNumber, ObjectCollection historyList) { + private void openHistoryListPopup(String billNumber) { ShowParameter showParameter = new ShowParameter(); showParameter.setFormId(HISTORY_LIST_FORM_ID); showParameter.setHowType(ShowTypeEnum.OPEN_ONLINE_MODAL); @@ -162,61 +137,9 @@ public class ViewHistoryBillOperationPlugin extends ExecutePluginParent { // 设置自定义参数 Map customParam = new HashMap<>(); customParam.put(PARAM_BILL_NUMBER, billNumber); - // 将历史数据也传递过去 - customParam.put("historyList", historyList); showParameter.setCustomParam(customParam); super.showForm(showParameter); } - /** - * 显示警告消息 - * - * @param message 警告消息内容 - */ - private void showWarnMessage(String message) { - try { - // 尝试通过OperationResult显示消息 - apelet.common.online.plugin.OperationResult result = - new apelet.common.online.plugin.OperationResult(); - result.setSuccess(true); - result.setShowMessage(true); - result.setMessage(message); - //setOperationResult(result); - } catch (Exception e) { - // 如果框架不支持OperationResult,则打印到控制台 - System.out.println("[ViewHistoryBillOperationPlugin] " + message); - } - } - - /** - * 辅助方法:格式化历史单据信息用于显示 - * - * @param historyBill 历史单据对象 - * @return 格式化的字符串 - */ - public String formatHistoryBillInfo(ObjectValue historyBill) { - if (historyBill == null) { - return ""; - } - - StringBuilder sb = new StringBuilder(); - sb.append("版本号:").append(historyBill.get(FIELD_VERSION_NUMBER)); - sb.append(",单位名称:").append(historyBill.get(FIELD_UNIT_NAME)); - sb.append(",状态:").append(historyBill.get(FIELD_BILL_STATUS)); - sb.append(",变更时间:").append(historyBill.get(FIELD_UPDATE_TIME)); - - return sb.toString(); - } - - /** - * 获取当前单据的历史记录数量 - * - * @param billNumber 单据编号 - * @return 历史记录数量 - */ - public int getHistoryCount(String billNumber) { - ObjectCollection historyList = queryHistoryBills(billNumber); - return historyList != null ? historyList.size() : 0; - } }