文件名排序问题处理
This commit is contained in:
parent
5179c7da33
commit
d9925d41d2
@ -1372,34 +1372,10 @@ public class OutputWordUtil {
|
|||||||
List<UpfileModel> search2 = upFileDao.searchByRepositoryId(repositoryModel.getId(), "f");
|
List<UpfileModel> search2 = upFileDao.searchByRepositoryId(repositoryModel.getId(), "f");
|
||||||
|
|
||||||
DCContext dcContextModel = null;
|
DCContext dcContextModel = null;
|
||||||
|
|
||||||
|
|
||||||
// 排序
|
|
||||||
try {
|
|
||||||
Collections.sort(search2, new Comparator<UpfileModel>() {
|
|
||||||
@Override
|
|
||||||
public int compare(UpfileModel o1, UpfileModel o2) {
|
|
||||||
String p1 = o1.getFileName();
|
|
||||||
String p2 = o2.getFileName();
|
|
||||||
|
|
||||||
if (p1.substring(0, 2).equals("附件") && p2.substring(0, 2).equals("附件") && p1.contains(":") && p2.contains(":") && StringUtils.isNumeric(p1.substring(2, p1.indexOf(":"))) && StringUtils.isNumeric(p2.substring(2, p2.indexOf(":")))) {
|
|
||||||
return Integer.parseInt(p1.substring(2, p1.indexOf(":"))) - Integer.parseInt(p2.substring(2, p2.indexOf(":")));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
//读取模型附件插入手册中文档对象
|
//读取模型附件插入手册中文档对象
|
||||||
if (search2 != null && search2.size() > 0) {
|
if (search2 != null && search2.size() > 0) {
|
||||||
|
//插入前,附件名先排序先排序
|
||||||
|
sortFilesByNumber(search2);
|
||||||
//附件如果为空,不插入附件标题
|
//附件如果为空,不插入附件标题
|
||||||
CharacterFormat format4 = new CharacterFormat();
|
CharacterFormat format4 = new CharacterFormat();
|
||||||
//创建字体格式
|
//创建字体格式
|
||||||
@ -2831,14 +2807,21 @@ public class OutputWordUtil {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// 精准提取附件后的第一个连续数字
|
// 提取附件后的第一个连续数字(支持小数)
|
||||||
private static Integer extractLeadingNumber(UpfileModel file) {
|
private static Double extractLeadingNumber(UpfileModel file) {
|
||||||
// 增强版正则表达式(核心改进点)
|
|
||||||
Pattern FILE_NUMBER_PATTERN =
|
Pattern FILE_NUMBER_PATTERN =
|
||||||
Pattern.compile("^附件\\s*(\\d+)\\s*[::、,_\\-]"); // ^开头匹配防止中途匹配
|
Pattern.compile("^附件[^\\d]*(\\d+(?:\\.\\d+)?|\\.\\d+)"); // 增强正则
|
||||||
try {
|
try {
|
||||||
Matcher matcher = FILE_NUMBER_PATTERN.matcher(file.getFileName());
|
Matcher matcher = FILE_NUMBER_PATTERN.matcher(file.getFileName());
|
||||||
return matcher.find() ? Integer.parseInt(matcher.group(1)) : null;
|
if (matcher.find()) {
|
||||||
|
String numberStr = matcher.group(1);
|
||||||
|
// 处理结尾单独的小数点(如"123."的情况)
|
||||||
|
if (numberStr.endsWith(".")) {
|
||||||
|
numberStr = numberStr.substring(0, numberStr.length() - 1);
|
||||||
|
}
|
||||||
|
return Double.parseDouble(numberStr);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user