feat:获取下个图册编号方法,适应不同类型编号
This commit is contained in:
parent
1b81eca93a
commit
b022c6d349
@ -242,8 +242,8 @@ public class AssAtlasdetFromEdit extends AbstractBillPlugIn implements UploadLis
|
||||
if ("test_getatlasno".equals(key)) {
|
||||
IDataModel model = this.getModel();
|
||||
String number = (String)model.getValue("number");
|
||||
int atlasno = Getatlasno(number);
|
||||
getView().showMessage(String.valueOf(atlasno));
|
||||
String atlasno = Getatlasno(number);
|
||||
getView().showMessage(atlasno);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -327,8 +327,7 @@ public class AtlasUtils {
|
||||
subentryentity.set("yem_completetime", entryentity.getDate("yem_completetime"));
|
||||
subentryentity.set("yem_replace", entryentity.getString("yem_replace"));
|
||||
subentryentity.set("yem_creationtime", new Date());
|
||||
int yem_enableparno = SubRelationUtils.Getatlasno(entryentity.getString("yem_enableparno"));
|
||||
subentryentity.set("yem_atlasno", yem_enableparno + 1);
|
||||
subentryentity.set("yem_atlasno", SubRelationUtils.Getatlasno(entryentity.getString("yem_enableparno")));
|
||||
//zzs add https://docs.qq.com/sheet/DQkFUcGxLTnRTaWl4?tab=BB08J2 问题974
|
||||
if (entryentity.containsProperty("yem_remark") && subentryentity.containsProperty("yem_partremark")) {
|
||||
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_replace", entryentity.getString("yem_replace"));
|
||||
subentryentity.set("yem_creationtime", new Date());
|
||||
int yem_enableparno = SubRelationUtils.Getatlasno(entryentity.getString("yem_repno"));
|
||||
subentryentity.set("yem_atlasno", yem_enableparno + 1);
|
||||
subentryentity.set("yem_atlasno", SubRelationUtils.Getatlasno(entryentity.getString("yem_repno")));
|
||||
//zzs add https://docs.qq.com/sheet/DQkFUcGxLTnRTaWl4?tab=BB08J2 问题974
|
||||
if (entryentity.containsProperty("yem_remark") && subentryentity.containsProperty("yem_partremark")) {
|
||||
subentryentity.set("yem_partremark", entryentity.getString("yem_remark"));
|
||||
|
@ -6,14 +6,20 @@ import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.entity.datamodel.IDataModel;
|
||||
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.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.QueryServiceHelper;
|
||||
import kd.bos.servicehelper.operation.OperationServiceHelper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@ -24,6 +30,8 @@ import java.util.stream.Stream;
|
||||
*/
|
||||
public class SubRelationUtils {
|
||||
|
||||
public final static Log log = LogFactory.getLog(SubRelationUtils.class);
|
||||
|
||||
/**
|
||||
* 查询替换关系
|
||||
*
|
||||
@ -629,20 +637,112 @@ public class SubRelationUtils {
|
||||
|
||||
/**
|
||||
* 根据替换编码获取最大图册号
|
||||
*
|
||||
* 查找下一个图册编号
|
||||
* 同一个图册中,编号层级一致,不一致不处理
|
||||
* 例如层级为0:编号为1,2,4,5,6
|
||||
* 层级为1:编号为1.1,1.2,1.3
|
||||
* 层级为2:编号为1.1.1,1.1.2,1.1.3
|
||||
* 对图册中编号按照层级进行排序,之后取最大的编号,给最后一位数加一,返回加一后的时
|
||||
* 如果按照以上规则无法获取到正确的编号,返回空字符串,后续手动维护编号
|
||||
* @param repno
|
||||
* @return
|
||||
*/
|
||||
public static int Getatlasno(String repno) {
|
||||
int result = 0;
|
||||
public static String Getatlasno(String repno) {
|
||||
QFilter qFilter = new QFilter("number", QCP.in, repno);
|
||||
DynamicObjectCollection data = QueryServiceHelper.query("yem_em_assatlasdet",
|
||||
"id,number,name,yem_entryentity.yem_atlasno", new QFilter[]{qFilter},
|
||||
"length(yem_entryentity.yem_atlasno) DESC,yem_entryentity.yem_atlasno DESC");
|
||||
if (data.size() > 0) {
|
||||
result = data.get(0).getInt("yem_entryentity.yem_atlasno");
|
||||
"id,number,name,yem_entryentity.yem_atlasno atlasno", new QFilter[]{qFilter});
|
||||
Set<Integer> bits = new HashSet<>();
|
||||
Set<String> existNo = new LinkedHashSet<>();
|
||||
for (DynamicObject datum : data) {
|
||||
String atlasno = datum.getString("atlasno");
|
||||
if (!isValid(atlasno)) {
|
||||
log.error("无法验证的图册编号:" + atlasno);
|
||||
return "";
|
||||
}
|
||||
int matches = StringUtils.countMatches(atlasno, ".");
|
||||
bits.add(matches);
|
||||
existNo.add(atlasno);
|
||||
}
|
||||
return result;
|
||||
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} 45,1.1.3,1.4
|
||||
* {false} .123,2..3,23.,--
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user