feat:获取下个图册编号方法,适应不同类型编号

This commit is contained in:
zzs 2025-01-08 16:09:01 +08:00
parent 1b81eca93a
commit b022c6d349
3 changed files with 112 additions and 14 deletions

View File

@ -242,8 +242,8 @@ public class AssAtlasdetFromEdit extends AbstractBillPlugIn implements UploadLis
if ("test_getatlasno".equals(key)) { if ("test_getatlasno".equals(key)) {
IDataModel model = this.getModel(); IDataModel model = this.getModel();
String number = (String)model.getValue("number"); String number = (String)model.getValue("number");
int atlasno = Getatlasno(number); String atlasno = Getatlasno(number);
getView().showMessage(String.valueOf(atlasno)); getView().showMessage(atlasno);
} }
} }

View File

@ -327,8 +327,7 @@ public class AtlasUtils {
subentryentity.set("yem_completetime", entryentity.getDate("yem_completetime")); subentryentity.set("yem_completetime", entryentity.getDate("yem_completetime"));
subentryentity.set("yem_replace", entryentity.getString("yem_replace")); subentryentity.set("yem_replace", entryentity.getString("yem_replace"));
subentryentity.set("yem_creationtime", new Date()); subentryentity.set("yem_creationtime", new Date());
int yem_enableparno = SubRelationUtils.Getatlasno(entryentity.getString("yem_enableparno")); subentryentity.set("yem_atlasno", SubRelationUtils.Getatlasno(entryentity.getString("yem_enableparno")));
subentryentity.set("yem_atlasno", yem_enableparno + 1);
//zzs add https://docs.qq.com/sheet/DQkFUcGxLTnRTaWl4?tab=BB08J2 问题974 //zzs add https://docs.qq.com/sheet/DQkFUcGxLTnRTaWl4?tab=BB08J2 问题974
if (entryentity.containsProperty("yem_remark") && subentryentity.containsProperty("yem_partremark")) { if (entryentity.containsProperty("yem_remark") && subentryentity.containsProperty("yem_partremark")) {
subentryentity.set("yem_partremark", entryentity.getString("yem_remark")); subentryentity.set("yem_partremark", entryentity.getString("yem_remark"));
@ -468,8 +467,7 @@ public class AtlasUtils {
subentryentity.set("yem_completetime", entryentity.getDate("yem_completetime")); subentryentity.set("yem_completetime", entryentity.getDate("yem_completetime"));
subentryentity.set("yem_replace", entryentity.getString("yem_replace")); subentryentity.set("yem_replace", entryentity.getString("yem_replace"));
subentryentity.set("yem_creationtime", new Date()); subentryentity.set("yem_creationtime", new Date());
int yem_enableparno = SubRelationUtils.Getatlasno(entryentity.getString("yem_repno")); subentryentity.set("yem_atlasno", SubRelationUtils.Getatlasno(entryentity.getString("yem_repno")));
subentryentity.set("yem_atlasno", yem_enableparno + 1);
//zzs add https://docs.qq.com/sheet/DQkFUcGxLTnRTaWl4?tab=BB08J2 问题974 //zzs add https://docs.qq.com/sheet/DQkFUcGxLTnRTaWl4?tab=BB08J2 问题974
if (entryentity.containsProperty("yem_remark") && subentryentity.containsProperty("yem_partremark")) { if (entryentity.containsProperty("yem_remark") && subentryentity.containsProperty("yem_partremark")) {
subentryentity.set("yem_partremark", entryentity.getString("yem_remark")); subentryentity.set("yem_partremark", entryentity.getString("yem_remark"));

View File

@ -6,14 +6,20 @@ import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.datamodel.IDataModel; import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.operate.result.OperationResult; import kd.bos.entity.operate.result.OperationResult;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP; import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter; import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper; import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.operation.OperationServiceHelper; import kd.bos.servicehelper.operation.OperationServiceHelper;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
@ -24,6 +30,8 @@ import java.util.stream.Stream;
*/ */
public class SubRelationUtils { public class SubRelationUtils {
public final static Log log = LogFactory.getLog(SubRelationUtils.class);
/** /**
* 查询替换关系 * 查询替换关系
* *
@ -629,20 +637,112 @@ public class SubRelationUtils {
/** /**
* 根据替换编码获取最大图册号 * 根据替换编码获取最大图册号
* * 查找下一个图册编号
* 同一个图册中编号层级一致不一致不处理
* 例如层级为0编号为12456
* 层级为1编号为1.11.21.3
* 层级为2编号为1.1.11.1.21.1.3
* 对图册中编号按照层级进行排序之后取最大的编号给最后一位数加一返回加一后的时
* 如果按照以上规则无法获取到正确的编号返回空字符串后续手动维护编号
* @param repno * @param repno
* @return * @return
*/ */
public static int Getatlasno(String repno) { public static String Getatlasno(String repno) {
int result = 0;
QFilter qFilter = new QFilter("number", QCP.in, repno); QFilter qFilter = new QFilter("number", QCP.in, repno);
DynamicObjectCollection data = QueryServiceHelper.query("yem_em_assatlasdet", DynamicObjectCollection data = QueryServiceHelper.query("yem_em_assatlasdet",
"id,number,name,yem_entryentity.yem_atlasno", new QFilter[]{qFilter}, "id,number,name,yem_entryentity.yem_atlasno atlasno", new QFilter[]{qFilter});
"length(yem_entryentity.yem_atlasno) DESC,yem_entryentity.yem_atlasno DESC"); Set<Integer> bits = new HashSet<>();
if (data.size() > 0) { Set<String> existNo = new LinkedHashSet<>();
result = data.get(0).getInt("yem_entryentity.yem_atlasno"); for (DynamicObject datum : data) {
String atlasno = datum.getString("atlasno");
if (!isValid(atlasno)) {
log.error("无法验证的图册编号:" + atlasno);
return "";
} }
return result; int matches = StringUtils.countMatches(atlasno, ".");
bits.add(matches);
existNo.add(atlasno);
}
if (bits.size() == 1) {
Integer bit = bits.iterator().next();
return findNextMax(existNo, bit);
} else {
log.error("存在不同层级,无法处理:" + bits);
log.error(existNo.toString());
}
return "";
}
/**
* 对图册中编号按照层级进行排序之后取最大的编号给最后一位数加一返回加一后的时
* @param hierarchicalStrings 已有编号
* @param levels 层级
* @return 下一个编号
*/
public static String findNextMax(Set<String> hierarchicalStrings, int levels) {
String maxString = null;
for (String str : hierarchicalStrings) {
if (str.split("\\.").length == levels + 1) {
if (maxString == null || compareHierarchicalStrings(str, maxString) > 0) {
maxString = str;
}
}
}
if (maxString != null) {
return getNextValue(maxString);
}
return null;
}
/**
* 比较两个编号大小
*/
private static int compareHierarchicalStrings(String str1, String str2) {
String[] parts1 = str1.split("\\.");
String[] parts2 = str2.split("\\.");
int length = Math.min(parts1.length, parts2.length);
for (int i = 0; i < length; i++) {
int num1 = Integer.parseInt(parts1[i]);
int num2 = Integer.parseInt(parts2[i]);
if (num1 != num2) {
return Integer.compare(num1, num2);
}
}
return Integer.compare(parts1.length, parts2.length);
}
/**
* 最后一位编号加一
* @param maxString 当前最大编号
*/
private static String getNextValue(String maxString) {
String[] parts = maxString.split("\\.");
int lastIndex = parts.length - 1;
parts[lastIndex] = String.valueOf(Integer.parseInt(parts[lastIndex]) + 1);
return String.join(".", parts);
}
/**
* 判断编号是否是一个可识别的编号
* 编号为正整数
* 为多个小数点分割的数字前后不能时数字两个点之间不能为空
* 例如
* {true} 451.1.31.4
* {false} .1232..323.--
*/
public static boolean isValid(String str) {
if (str.matches("\\d+")) {
return true;
}
Pattern pattern = Pattern.compile("^\\d+(\\.\\d+)+$");
Matcher matcher = pattern.matcher(str);
return matcher.matches();
} }