bug修复
This commit is contained in:
parent
5bc5287ee7
commit
2141e30794
|
@ -1,5 +1,7 @@
|
|||
package zcgj.zcdev.zcdev.pr.task;
|
||||
|
||||
import kd.bos.algo.DataSet;
|
||||
import kd.bos.algo.Row;
|
||||
import kd.bos.context.RequestContext;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
|
@ -12,6 +14,7 @@ import kd.bos.orm.query.QCP;
|
|||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.schedule.executor.AbstractTask;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.QueryServiceHelper;
|
||||
import kd.bos.servicehelper.operation.OperationServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import zcgj.zcdev.zcdev.pr.plugin.form.AdjustAmountOftaxBillPlugin;
|
||||
|
@ -29,6 +32,7 @@ import java.util.*;
|
|||
*/
|
||||
public class EquipmentCardTaskPlugin extends AbstractTask {
|
||||
private static final Log log = LogFactory.getLog(EquipmentCardTaskPlugin.class);
|
||||
|
||||
@Override
|
||||
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {//同步资产卡片
|
||||
List<String> strings = new ArrayList<>();
|
||||
|
@ -123,54 +127,55 @@ public class EquipmentCardTaskPlugin extends AbstractTask {
|
|||
String zcgjDebillno = entry.getString("zcgj_debillno");
|
||||
entrys.removeIf(record -> isLastMonth(zcgjDebillno));//若属于上个月那就删除重新塞入
|
||||
}
|
||||
|
||||
}
|
||||
DynamicObject[] depresplitdetails = BusinessDataServiceHelper.load("fa_depresplitdetail", "billno,period,splitdept,assentry.costcentrer,assentry.splitamount", new QFilter[]{qf});
|
||||
Arrays.sort(depresplitdetails, (o1, o2) -> {
|
||||
// 获取期间对象
|
||||
DynamicObject p1 = o1.getDynamicObject("period");
|
||||
DynamicObject p2 = o2.getDynamicObject("period");
|
||||
|
||||
// === 修复1:正确的空值处理 ===
|
||||
// 将空值放在最后(无论升降序)
|
||||
if (p1 == null && p2 == null) return 0;
|
||||
if (p1 == null) return 1; // o1空则排在后面
|
||||
if (p2 == null) return -1; // o2空则排在后面
|
||||
|
||||
String code1 = p1.getString("number");
|
||||
String code2 = p2.getString("number");
|
||||
|
||||
// 处理空字符串
|
||||
if (code1 == null) code1 = "";
|
||||
if (code2 == null) code2 = "";
|
||||
|
||||
// === 修复2:自动检测日期格式 ===
|
||||
DateTimeFormatter formatter = detectFormat(code1, code2);
|
||||
|
||||
try {
|
||||
YearMonth ym1 = parseYearMonth(code1, formatter);
|
||||
YearMonth ym2 = parseYearMonth(code2, formatter);
|
||||
|
||||
// === 修复3:正确的降序比较 ===
|
||||
return ym2.compareTo(ym1); // 注意:这是ym2在前
|
||||
|
||||
} catch (DateTimeParseException e) {
|
||||
// === 修复4:数值化比较作为备选 ===
|
||||
try {
|
||||
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) {
|
||||
DataSet rows = QueryServiceHelper.queryDataSet(this.getClass().getName(), "fa_depresplitdetail", "billno,period,period.number,splitdept,assentry.costcentrer,assentry.splitamount", qFilter.toArray(), "period.number DESC", 1);
|
||||
// Arrays.sort(depresplitdetails, (o1, o2) -> {
|
||||
// // 获取期间对象
|
||||
// DynamicObject p1 = o1.getDynamicObject("period");
|
||||
// DynamicObject p2 = o2.getDynamicObject("period");
|
||||
//
|
||||
// // === 修复1:正确的空值处理 ===
|
||||
// // 将空值放在最后(无论升降序)
|
||||
// if (p1 == null && p2 == null) return 0;
|
||||
// if (p1 == null) return 1; // o1空则排在后面
|
||||
// if (p2 == null) return -1; // o2空则排在后面
|
||||
//
|
||||
// String code1 = p1.getString("number");
|
||||
// String code2 = p2.getString("number");
|
||||
//
|
||||
// // 处理空字符串
|
||||
// if (code1 == null) code1 = "";
|
||||
// if (code2 == null) code2 = "";
|
||||
//
|
||||
// // === 修复2:自动检测日期格式 ===
|
||||
// DateTimeFormatter formatter = detectFormat(code1, code2);
|
||||
//
|
||||
// try {
|
||||
// YearMonth ym1 = parseYearMonth(code1, formatter);
|
||||
// YearMonth ym2 = parseYearMonth(code2, formatter);
|
||||
//
|
||||
// // === 修复3:正确的降序比较 ===
|
||||
// return ym2.compareTo(ym1); // 注意:这是ym2在前
|
||||
//
|
||||
// } catch (DateTimeParseException e) {
|
||||
// // === 修复4:数值化比较作为备选 ===
|
||||
// try {
|
||||
// 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 (Row depresplitdetail : rows) {
|
||||
String billno = depresplitdetail.getString("billno");
|
||||
DynamicObject period = depresplitdetail.getDynamicObject("period");//折旧区间
|
||||
DynamicObject splitdept = depresplitdetail.getDynamicObject("splitdept");//使用部门
|
||||
DynamicObjectCollection assentry = depresplitdetail.getDynamicObjectCollection("assentry");
|
||||
DynamicObject depresplitdetailInfo = BusinessDataServiceHelper.loadSingle("fa_depresplitdetail", new QFilter[]{new QFilter("billno", QCP.equals, billno)});
|
||||
DynamicObject period = depresplitdetailInfo.getDynamicObject("period");//折旧区间
|
||||
DynamicObject splitdept = depresplitdetailInfo.getDynamicObject("splitdept");//使用部门
|
||||
DynamicObjectCollection assentry = depresplitdetailInfo.getDynamicObjectCollection("assentry");
|
||||
DynamicObject costcentrer = assentry.get(0).getDynamicObject("costcentrer");//成本中心
|
||||
BigDecimal splitamount = assentry.get(0).getBigDecimal("splitamount");//分摊金额
|
||||
DynamicObject addNew = entrys.addNew();
|
||||
|
@ -223,7 +228,6 @@ public class EquipmentCardTaskPlugin extends AbstractTask {
|
|||
}
|
||||
|
||||
|
||||
|
||||
// 自动检测日期格式的辅助方法
|
||||
private DateTimeFormatter detectFormat(String code1, String code2) {
|
||||
// 常见格式检测
|
||||
|
@ -239,7 +243,8 @@ public class EquipmentCardTaskPlugin extends AbstractTask {
|
|||
if (!code1.isEmpty()) YearMonth.parse(code1, fmt);
|
||||
if (!code2.isEmpty()) YearMonth.parse(code2, fmt);
|
||||
return fmt; // 找到匹配格式
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// 默认返回标准格式
|
||||
|
|
Loading…
Reference in New Issue