|
@@ -6,6 +6,7 @@ import com.actionsoft.bpms.commons.database.RowMap;
|
|
|
import com.actionsoft.bpms.server.UserContext;
|
|
import com.actionsoft.bpms.server.UserContext;
|
|
|
import com.actionsoft.bpms.util.DBSql;
|
|
import com.actionsoft.bpms.util.DBSql;
|
|
|
import com.actionsoft.sdk.local.SDK;
|
|
import com.actionsoft.sdk.local.SDK;
|
|
|
|
|
+import com.actionsoft.sdk.local.api.Logger;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
@@ -16,9 +17,11 @@ import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 发票服务(单例模式,方法体≤5个)
|
|
|
|
|
|
|
+ * 发票服务
|
|
|
*/
|
|
*/
|
|
|
public class InvoiceService {
|
|
public class InvoiceService {
|
|
|
|
|
+
|
|
|
|
|
+ private static final Logger logger = SDK.getLogAPI().getLogger(InvoiceService.class);
|
|
|
// 单例模式:双重校验锁保证线程安全
|
|
// 单例模式:双重校验锁保证线程安全
|
|
|
private static volatile InvoiceService instance;
|
|
private static volatile InvoiceService instance;
|
|
|
|
|
|
|
@@ -39,8 +42,9 @@ public class InvoiceService {
|
|
|
// ====================== 1. 核心入口方法:处理发票生成 ======================
|
|
// ====================== 1. 核心入口方法:处理发票生成 ======================
|
|
|
public List<String> processInvoice(UserContext uc, String accDeduIds, InvoiceDealDto param, boolean isDeal) {
|
|
public List<String> processInvoice(UserContext uc, String accDeduIds, InvoiceDealDto param, boolean isDeal) {
|
|
|
|
|
|
|
|
- System.out.println("处理发票生成");
|
|
|
|
|
- System.out.println("accDeduIds:" + accDeduIds);
|
|
|
|
|
|
|
+ logger.info("处理发票生成");
|
|
|
|
|
+ logger.info("accDeduIds:" + accDeduIds);
|
|
|
|
|
+ logger.info("日期范围:" + param.getDateRangeFrom() + "--" + param.getDateRangeTo());
|
|
|
|
|
|
|
|
// 1. 基础校验:空值过滤
|
|
// 1. 基础校验:空值过滤
|
|
|
if (StringUtils.isBlank(accDeduIds)) return new ArrayList<>();
|
|
if (StringUtils.isBlank(accDeduIds)) return new ArrayList<>();
|
|
@@ -57,6 +61,9 @@ public class InvoiceService {
|
|
|
"SELECT * FROM VIEW_EU_DNV_POSTED_ALL d WHERE d.ID IN " + sqlWhere + " AND (d.invoice_id is null OR d.invoice_id='' OR NOT EXISTS(SELECT 1 FROM bo_eu_dnctt_invoice i WHERE i.id=d.invoice_id AND IS_VOIDED=0)) AND d.bill_account_id is NOT NULL AND d.ORGID='" + uc.getCompanyModel().getId() + "' ORDER BY ACCOUNT_ID,BILL_ACCOUNT_ID",
|
|
"SELECT * FROM VIEW_EU_DNV_POSTED_ALL d WHERE d.ID IN " + sqlWhere + " AND (d.invoice_id is null OR d.invoice_id='' OR NOT EXISTS(SELECT 1 FROM bo_eu_dnctt_invoice i WHERE i.id=d.invoice_id AND IS_VOIDED=0)) AND d.bill_account_id is NOT NULL AND d.ORGID='" + uc.getCompanyModel().getId() + "' ORDER BY ACCOUNT_ID,BILL_ACCOUNT_ID",
|
|
|
dedIdArr
|
|
dedIdArr
|
|
|
);
|
|
);
|
|
|
|
|
+
|
|
|
|
|
+ logger.info("账单个数:" + postedDataList.size());
|
|
|
|
|
+
|
|
|
// 统一Key为大写,避免字段名大小写不一致导致的NPE
|
|
// 统一Key为大写,避免字段名大小写不一致导致的NPE
|
|
|
postedDataList.forEach(row -> row.forEach((key, value) -> {
|
|
postedDataList.forEach(row -> row.forEach((key, value) -> {
|
|
|
if (key.toUpperCase().equals("BILL_ACCOUNT_ID")) {
|
|
if (key.toUpperCase().equals("BILL_ACCOUNT_ID")) {
|
|
@@ -133,7 +140,7 @@ public class InvoiceService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ logger.info("发票ID:" + invoiceIds.toString());
|
|
|
return invoiceIds;
|
|
return invoiceIds;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -302,7 +309,7 @@ public class InvoiceService {
|
|
|
public boolean invoiceUpdate(UserContext uc, String invoiceIds, String dealStatus) {
|
|
public boolean invoiceUpdate(UserContext uc, String invoiceIds, String dealStatus) {
|
|
|
for (String invoiceId : invoiceIds.split(",")) {
|
|
for (String invoiceId : invoiceIds.split(",")) {
|
|
|
BO invoice = SDK.getBOAPI().get("BO_EU_DNCTT_INVOICE", invoiceId);
|
|
BO invoice = SDK.getBOAPI().get("BO_EU_DNCTT_INVOICE", invoiceId);
|
|
|
- List<BO> invoiceDetails = SDK.getBOAPI().query("BO_EU_DNCTT_INVOICE_DETAIL").bindId(invoice.getBindId()).addQuery("INVOICE_ID=", invoiceId).orderBy("ACCOUNT_ID").orderBy("BILL_ACCOUNT_ID").list();
|
|
|
|
|
|
|
+ List<BO> invoiceDetails = SDK.getBOAPI().query("BO_EU_DNCTT_INVOICE_DETAIL").bindId(invoice.getBindId()).addQuery("INVOICE_ID =", invoiceId).orderBy("ACCOUNT_ID").orderBy("BILL_ACCOUNT_ID").list();
|
|
|
|
|
|
|
|
boolean isDelete = true;
|
|
boolean isDelete = true;
|
|
|
int lineNo = 1;
|
|
int lineNo = 1;
|
|
@@ -360,14 +367,16 @@ public class InvoiceService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- if (dealStatus.equals("作废发票")) {
|
|
|
|
|
- List<BO> deductions = SDK.getBOAPI().query("BO_EU_DNCRM_ACCOUNT_DEDUCTION").addQuery("INVOICE_ID=", invoiceId).list();
|
|
|
|
|
|
|
+ if (isDelete || dealStatus.equals("作废发票")) {
|
|
|
|
|
+ List<BO> deductions = SDK.getBOAPI().query("BO_EU_DNCRM_ACCOUNT_DEDUCTION").addQuery("INVOICE_ID =", invoiceId).list();
|
|
|
for (BO deduction : deductions) {
|
|
for (BO deduction : deductions) {
|
|
|
deduction.set("INVOICE_ID", null);
|
|
deduction.set("INVOICE_ID", null);
|
|
|
deduction.set("INVOICE_LINE_ITEM_NO", 0);
|
|
deduction.set("INVOICE_LINE_ITEM_NO", 0);
|
|
|
dn.recordFormChanges.record(uc, deduction, "作废发票");
|
|
dn.recordFormChanges.record(uc, deduction, "作废发票");
|
|
|
SDK.getBOAPI().update("BO_EU_DNCRM_ACCOUNT_DEDUCTION", deduction);
|
|
SDK.getBOAPI().update("BO_EU_DNCRM_ACCOUNT_DEDUCTION", deduction);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ DBSql.update("UPDATE BO_EU_DNCRM_ACCOUNT_DEDUCTION SET INVOICE_ID=null,INVOICE_LINE_ITEM_NO=0 WHERE INVOICE_ID=?", new Object[]{invoiceId});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|