bug修复
This commit is contained in:
parent
2786d65392
commit
5bc5287ee7
|
@ -115,7 +115,7 @@ public class EquipmentCardTaskPlugin extends AbstractTask {
|
||||||
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM"); //设置格式
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM"); //设置格式
|
||||||
String ym =sd.format(date);
|
String ym =sd.format(date);
|
||||||
DynamicObjectCollection entrys = eceq_equipment.getDynamicObjectCollection("zcgj_entryentity");
|
DynamicObjectCollection entrys = eceq_equipment.getDynamicObjectCollection("zcgj_entryentity");
|
||||||
QFilter qf = new QFilter("realcard.number", QCP.in, number);
|
QFilter qf = new QFilter("realcard.number", QCP.equals, number);
|
||||||
if (entrys.size()>0){//若分录行数大于0 则取上月的
|
if (entrys.size()>0){//若分录行数大于0 则取上月的
|
||||||
qf.and(new QFilter("billno", QCP.in, ym));
|
qf.and(new QFilter("billno", QCP.in, ym));
|
||||||
for (int i = 0; i < entrys.size(); i++) {
|
for (int i = 0; i < entrys.size(); i++) {
|
||||||
|
@ -126,32 +126,44 @@ public class EquipmentCardTaskPlugin extends AbstractTask {
|
||||||
|
|
||||||
}
|
}
|
||||||
DynamicObject[] depresplitdetails = BusinessDataServiceHelper.load("fa_depresplitdetail", "billno,period,splitdept,assentry.costcentrer,assentry.splitamount", new QFilter[]{qf});
|
DynamicObject[] depresplitdetails = BusinessDataServiceHelper.load("fa_depresplitdetail", "billno,period,splitdept,assentry.costcentrer,assentry.splitamount", new QFilter[]{qf});
|
||||||
// === 新增:按期间编码(年月格式)排序 ===
|
|
||||||
Arrays.sort(depresplitdetails, (o1, o2) -> {
|
Arrays.sort(depresplitdetails, (o1, o2) -> {
|
||||||
|
// 获取期间对象
|
||||||
DynamicObject p1 = o1.getDynamicObject("period");
|
DynamicObject p1 = o1.getDynamicObject("period");
|
||||||
DynamicObject p2 = o2.getDynamicObject("period");
|
DynamicObject p2 = o2.getDynamicObject("period");
|
||||||
|
|
||||||
|
// === 修复1:正确的空值处理 ===
|
||||||
|
// 将空值放在最后(无论升降序)
|
||||||
if (p1 == null && p2 == null) return 0;
|
if (p1 == null && p2 == null) return 0;
|
||||||
if (p1 == null) return 1;
|
if (p1 == null) return 1; // o1空则排在后面
|
||||||
if (p2 == null) return -1;
|
if (p2 == null) return -1; // o2空则排在后面
|
||||||
|
|
||||||
String c1 = p1.getString("number");
|
String code1 = p1.getString("number");
|
||||||
String c2 = p2.getString("number");
|
String code2 = p2.getString("number");
|
||||||
|
|
||||||
if (c1 == null) c1 = "";
|
// 处理空字符串
|
||||||
if (c2 == null) c2 = "";
|
if (code1 == null) code1 = "";
|
||||||
|
if (code2 == null) code2 = "";
|
||||||
|
|
||||||
// 创建年月格式化器
|
// === 修复2:自动检测日期格式 ===
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
|
DateTimeFormatter formatter = detectFormat(code1, code2);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
YearMonth ym1 = YearMonth.parse(c1, formatter);
|
YearMonth ym1 = parseYearMonth(code1, formatter);
|
||||||
YearMonth ym2 = YearMonth.parse(c2, formatter);
|
YearMonth ym2 = parseYearMonth(code2, formatter);
|
||||||
return ym2.compareTo(ym1); // 升序
|
|
||||||
|
// === 修复3:正确的降序比较 ===
|
||||||
|
return ym2.compareTo(ym1); // 注意:这是ym2在前
|
||||||
|
|
||||||
} catch (DateTimeParseException e) {
|
} catch (DateTimeParseException e) {
|
||||||
// 记录解析失败的编码
|
// === 修复4:数值化比较作为备选 ===
|
||||||
log.error("期间编码解析失败: " + c1 + " 或 " + c2, e);
|
try {
|
||||||
return c1.compareTo(c2);
|
int num1 = Integer.parseInt(code1.replaceAll("\\D", ""));
|
||||||
|
int num2 = Integer.parseInt(code2.replaceAll("\\D", ""));
|
||||||
|
return Integer.compare(num2, num1); // 降序数值比较
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
// 最终回退到字符串降序
|
||||||
|
return code2.compareTo(code1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (DynamicObject depresplitdetail : depresplitdetails) {
|
for (DynamicObject depresplitdetail : depresplitdetails) {
|
||||||
|
@ -201,4 +213,36 @@ public class EquipmentCardTaskPlugin extends AbstractTask {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 安全解析年月
|
||||||
|
private YearMonth parseYearMonth(String code, DateTimeFormatter fmt) {
|
||||||
|
if (code == null || code.isEmpty()) {
|
||||||
|
return YearMonth.of(1900, 1); // 返回最小值
|
||||||
|
}
|
||||||
|
return YearMonth.parse(code, fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 自动检测日期格式的辅助方法
|
||||||
|
private DateTimeFormatter detectFormat(String code1, String code2) {
|
||||||
|
// 常见格式检测
|
||||||
|
String[] patterns = {
|
||||||
|
"yyyyMM", "yyyy-MM", "yyyy/MM",
|
||||||
|
"yyyy年MM月", "MM-yyyy", "MM/yyyy"
|
||||||
|
};
|
||||||
|
|
||||||
|
for (String pattern : patterns) {
|
||||||
|
try {
|
||||||
|
DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern);
|
||||||
|
// 用两个值测试格式
|
||||||
|
if (!code1.isEmpty()) YearMonth.parse(code1, fmt);
|
||||||
|
if (!code2.isEmpty()) YearMonth.parse(code2, fmt);
|
||||||
|
return fmt; // 找到匹配格式
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 默认返回标准格式
|
||||||
|
return DateTimeFormatter.ofPattern("yyyyMM");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue