diff --git a/GZ_LTHPilot_ORDER.csproj b/GZ_LTHPilot_ORDER.csproj
index fc30c5a..59ccb0c 100644
--- a/GZ_LTHPilot_ORDER.csproj
+++ b/GZ_LTHPilot_ORDER.csproj
@@ -348,9 +348,12 @@
+
+
+
diff --git a/ScheduleService/SaleOrderReceiveAmount.cs b/ScheduleService/SaleOrderReceiveAmount.cs
new file mode 100644
index 0000000..36d1864
--- /dev/null
+++ b/ScheduleService/SaleOrderReceiveAmount.cs
@@ -0,0 +1,101 @@
+using DocumentFormat.OpenXml.Bibliography;
+using GZ_LTHPilot_ORDER.Models.VO;
+using GZ_LTHPilot_ORDER.Service;
+using GZ_LTHPilot_ORDER.Services;
+using Kingdee.BOS;
+using Kingdee.BOS.App;
+using Kingdee.BOS.Contracts;
+using Kingdee.BOS.Core;
+using Kingdee.BOS.ServiceHelper;
+using Kingdee.BOS.Util;
+using Kingdee.BOS.WebApi.FormService;
+using Kingdee.K3.FIN.App.Core.Match.Object;
+using NPOI.SS.Formula.Functions;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+
+namespace GZ_LTHPilot_ORDER.ScheduleService
+{
+ [Description("定时刷新销售订单累计核销金额#"), HotUpdate]
+ public class SaleOrderReceiveAmount : IScheduleService
+ {
+ public void Run(Context ctx, Schedule schedule)
+ {
+ TempTableService tempTableService = new TempTableService(ctx);
+ OrgService orgService = new OrgService(ctx);
+ SaleOrderService saleOrderService = new SaleOrderService(ctx);
+ var orgList = orgService.GetOrgList();
+ var tableName = tempTableService.CreateTempTable();
+ CreateTempTable(ctx, tableName);
+ foreach (var item in orgList)
+ {
+ var advanceAays = GetAdvanceAays(schedule);
+ var orgId = item["FORGID"].ToString();
+ // 提前天的日期
+ var startDate = DateTime.Now.Date.AddDays(-advanceAays - 1);
+ var endDate = DateTime.Now;
+ var receiveAmountList = saleOrderService.GetSaleOrderReceiveAmountByDate(orgId, startDate, endDate);
+ InsertDataToTempTable(ctx, tableName, orgId, receiveAmountList);
+ }
+ }
+
+
+
+ private int InsertDataToTempTable(Context ctx, string tableName, string orgId, List saleExecuteOuts)
+ {
+ var values = saleExecuteOuts.Select(n => $"({orgId},'{n.FSALEORGNAME}','{n.FBILLNO}',{n.FALLMATCHAMOUNT},'{n.FDate}')");
+ var valuesString = string.Join(",", values);
+ var sqlTemp = $@"
+INSERT INTO
+ {tableName} (FORGID, FORGNAME, FBILLNO, FAMOUNT, FDATE)
+VALUES
+ {valuesString}
+";
+ return DBServiceHelper.Execute(ctx, sqlTemp);
+ }
+
+ private void CreateTempTable(Context ctx, string tableName)
+ {
+ var sql = $@"
+CREATE TABLE
+ {tableName} (
+ FORGID int,
+ FORGNAME NVARCHAR (100),
+ FBILLNO NVARCHAR (100),
+ FAMOUNT decimal,
+ FDATE DATETIME,
+ );
+";
+ DBServiceHelper.Execute(ctx, sql);
+ }
+
+
+ ///
+ /// 参数获取提前天
+ ///
+ ///
+ ///
+ private int GetAdvanceAays(Schedule schedule)
+ {
+ // 参数获取提前天
+ var advanceAaysStr = schedule.Parameters;
+ int advanceAays;
+ try
+ {
+ advanceAays = Convert.ToInt32(advanceAaysStr);
+ if (advanceAays < 0)
+ {
+ throw new Exception();
+ }
+ }
+ catch (Exception)
+ {
+
+ throw new Exception("获取参数提前天失败,参数格式为整数,且大于等于0");
+ }
+ return advanceAays;
+ }
+ }
+}
diff --git a/ScheduleService/SaleOrderSumSicsAmountRefresh.cs b/ScheduleService/SaleOrderSumSicsAmountRefresh.cs
index e374cfc..a4bff27 100644
--- a/ScheduleService/SaleOrderSumSicsAmountRefresh.cs
+++ b/ScheduleService/SaleOrderSumSicsAmountRefresh.cs
@@ -10,7 +10,7 @@ using System.ComponentModel;
namespace GZ_LTHPilot_ORDER.ScheduleService
{
- [Description("定时刷新#"), HotUpdate]
+ [Description("定时刷新销售订单累计开票金额#"), HotUpdate]
public class SaleOrderSumSicsAmountRefresh : IScheduleService
{
public void Run(Context ctx, Schedule schedule)
diff --git a/Services/OrgService.cs b/Services/OrgService.cs
new file mode 100644
index 0000000..0eb3361
--- /dev/null
+++ b/Services/OrgService.cs
@@ -0,0 +1,33 @@
+using Kingdee.BOS;
+using Kingdee.BOS.Orm.DataEntity;
+using Kingdee.BOS.ServiceHelper;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace GZ_LTHPilot_ORDER.Services
+{
+ public class OrgService
+ {
+ public Context ctx;
+ public OrgService(Context ctx)
+ {
+ this.ctx = ctx;
+ }
+ public DynamicObjectCollection GetOrgList()
+ {
+ var sql = @"/*dialect*/SELECT
+ t0.FORGID,
+ t0l.FNAME,
+ *
+FROM
+ T_ORG_ORGANIZATIONS t0
+ LEFT JOIN T_ORG_ORGANIZATIONS_L t0L ON t0.FORGID = t0L.FORGID
+ AND FLOCALEID = 2052
+";
+ return DBServiceHelper.ExecuteDynamicObject(this.ctx, sql);
+ }
+ }
+}
diff --git a/Services/SaleOrderService.cs b/Services/SaleOrderService.cs
index 4e3b38a..ac585d5 100644
--- a/Services/SaleOrderService.cs
+++ b/Services/SaleOrderService.cs
@@ -86,11 +86,15 @@ WHERE
var result = JsonConvert.DeserializeObject>(resultString);
var rows = result.Result.Rows;
var dataRow = rows.Where(n => n.FBILLNO == billNo).FirstOrDefault();
- if (dataRow != null)
+ if (dataRow == null)
{
- return Convert.ToDecimal(dataRow.FALLMATCHAMOUNT);
+ return 0m;
}
- return 0m;
+ if (dataRow.FALLMATCHAMOUNT.IsNullOrEmptyOrWhiteSpace())
+ {
+ return 0m;
+ }
+ return Convert.ToDecimal(dataRow.FALLMATCHAMOUNT);
}
@@ -125,7 +129,7 @@ WHERE
{
FSaleOrgList = orgId,
FSoFromDate = startDate,
- FSoToDate = startDate,
+ FSoToDate = endDate,
FFormCloseStatus = "ALL",
FFormStatus = "C",
FPriceFrom = "SALORDERBILL",
diff --git a/Services/SaleSicsService.cs b/Services/SaleSicsService.cs
index b0bbe77..eab3968 100644
--- a/Services/SaleSicsService.cs
+++ b/Services/SaleSicsService.cs
@@ -59,6 +59,7 @@ FROM
AND FCANCELSTATUS = 'A'
AND FSALEORGID = '{0}'
AND F_PaperNumber = '{1}'
+ AND FDATE >= '2025-01-01'
UNION ALL
SELECT
'100302' FSALEORGID, -- 销售组织
diff --git a/Services/TempTableService.cs b/Services/TempTableService.cs
new file mode 100644
index 0000000..3ba9777
--- /dev/null
+++ b/Services/TempTableService.cs
@@ -0,0 +1,47 @@
+using Kingdee.BOS;
+using Kingdee.BOS.App;
+using Kingdee.BOS.Contracts;
+using Kingdee.BOS.Util;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace GZ_LTHPilot_ORDER.Services
+{
+ internal class TempTableService
+ {
+
+ private Context ctx;
+
+ public TempTableService(Context ctx)
+ {
+ this.ctx = ctx;
+ }
+ ///
+ /// 删除临时表
+ ///
+ ///
+ ///
+ public void DropTempTable(string tableName)
+ {
+ if (!tableName.IsNullOrEmptyOrWhiteSpace())
+ {
+ IDBService dbservice = ServiceHelper.GetService();
+ dbservice.DeleteTemporaryTableName(ctx, new string[] { tableName });
+ }
+ }
+ ///
+ /// 创建临时表
+ ///
+ ///
+ ///
+ public string CreateTempTable()
+ {
+ IDBService dbservice = ServiceHelper.GetService();
+ string[] temptables = dbservice.CreateTemporaryTableName(ctx, 1);
+ return temptables[0];
+ }
+ }
+}