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 256ea94..e45add3 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 @@ -20,7 +20,7 @@ public class MembershipApplyListFilterPlugin extends ListPlugin { /** * 非历史记录 */ - private static final String IS_HISTORY_NO = "0"; + private static final String IS_HISTORY_NO = "1"; @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 2d9dd7c..e0b1fbd 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 @@ -98,6 +98,7 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { // 获取源单据ID String sourceBillId = getSourceBillId(objectValue); String sourceBillNumber = getSourceBillNumber(objectValue); + this.setWidgetAttribute("history",AttributeEnum.VALUE_CHANGE, "0"); // 如果没有源单据ID,说明不是变更操作,正常返回 if (sourceBillId == null || sourceBillId.isEmpty()) { @@ -147,6 +148,10 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { if (sourceBillId == null || sourceBillId.trim().isEmpty()) { sourceBillId = objectValue.getString(PARAM_BILL_ID_ALT); } + Object idObj = objectValue.get("id"); + if (idObj != null && !Integer.valueOf(0).equals(idObj)) { + return false; + } return sourceBillId != null && !sourceBillId.trim().isEmpty(); } @@ -156,6 +161,8 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { throw new RuntimeException("获取数据库连接失败"); } + int version = markOldBillsHistory(ormUtil, objectValue); + ObjectValue newBill = new ObjectValue("membership_apply"); Map values = objectValue.getValues(); for (Object item : values.entrySet()) { @@ -166,6 +173,8 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { } newBill.put(getDbFieldKey(key), entry.getValue()); } + newBill.put("history", "0"); + newBill.put("version_number", version); ObjectCollection detailEntry = copyEntryForManualSave(objectValue.getObjectCollection(CHILD_WIDGET_KEY)); if (detailEntry != null && !detailEntry.isEmpty()) { @@ -175,6 +184,64 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { ormUtil.addNew("membership_apply", newBill); } + private int markOldBillsHistory(OrmGenDataSourceUtil ormUtil, ObjectValue objectValue) throws Exception { + String sourceBillId = getSourceBillId(objectValue); + if (sourceBillId == null || sourceBillId.trim().isEmpty()) { + sourceBillId = objectValue.getString(PARAM_BILL_ID); + } + if (sourceBillId == null || sourceBillId.trim().isEmpty()) { + sourceBillId = objectValue.getString(PARAM_BILL_ID_ALT); + } + if (sourceBillId == null || sourceBillId.trim().isEmpty()) { + return 1; + } + + apelet.common.orm.impl.Filter sourceFilter = new apelet.common.orm.impl.Filter(); + sourceFilter.add(new apelet.common.orm.impl.FilterItem("id", "=", sourceBillId)); + ObjectCollection sourceCollection = ormUtil.query("membership_apply", sourceFilter, null); + if (sourceCollection == null || sourceCollection.isEmpty()) { + return 1; + } + + ObjectValue sourceBill = sourceCollection.getObject(0); + if (sourceBill == null) { + return 1; + } + + String number = sourceBill.getString("number"); + if (number == null || number.trim().isEmpty()) { + return 1; + } + + 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); + if (sameBills == null || sameBills.isEmpty()) { + sourceBill.put("history", "1"); + sourceBill.put("version_number", 1); + ormUtil.update("membership_apply", sourceBill, null); + return 2; + } + + 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)); + int version = 1; + for (ObjectValue bill : bills) { + bill.put("history", "1"); + bill.put("version_number", version); + ormUtil.update("membership_apply", bill, null); + version++; + } + return version; + } + private boolean shouldSkipManualSaveField(String key) { return "id".equals(key) || "eventparams".equals(key) @@ -391,21 +458,13 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { 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); + int billVersion = getVersionNumberSafe(bill); + if (billVersion >= version) { + version = billVersion + 1; } } - - 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);