102 lines
3.3 KiB
C#
102 lines
3.3 KiB
C#
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<SaleExecuteOut> 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);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 参数获取提前天
|
||
/// </summary>
|
||
/// <param name="schedule"></param>
|
||
/// <returns></returns>
|
||
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;
|
||
}
|
||
}
|
||
}
|