diff --git a/Config/ContextConfig.cs b/Config/ContextConfig.cs new file mode 100644 index 0000000..81fe393 --- /dev/null +++ b/Config/ContextConfig.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GZ_LTHPilot_ORDER.Config +{ + internal class ContextConfig + { + public static string DefaultUserName = "ERP6"; + public static int DefaultUserId = 131409; + } +} diff --git a/GZ_LTHPilot_ORDER.csproj b/GZ_LTHPilot_ORDER.csproj index ad504c0..4b275b8 100644 --- a/GZ_LTHPilot_ORDER.csproj +++ b/GZ_LTHPilot_ORDER.csproj @@ -332,6 +332,7 @@ + @@ -377,6 +378,7 @@ + @@ -442,6 +444,7 @@ - copy $(TargetPath) "D:\kingdee\K3Cloud\WebSite\Bin\$(TargetFileName)" + + \ No newline at end of file diff --git a/ScheduleService/SaleOrderReceiveAmount.cs b/ScheduleService/SaleOrderReceiveAmount.cs index 7ce2be8..8ac88c0 100644 --- a/ScheduleService/SaleOrderReceiveAmount.cs +++ b/ScheduleService/SaleOrderReceiveAmount.cs @@ -3,6 +3,7 @@ using Gatedge.Enpower.BOS.PlugIn.Utils; using GZ_LTHPilot_ORDER.Models.VO; using GZ_LTHPilot_ORDER.Service; using GZ_LTHPilot_ORDER.Services; +using GZ_LTHPilot_ORDER.Utils; using Kingdee.BOS; using Kingdee.BOS.App; using Kingdee.BOS.Contracts; @@ -27,23 +28,17 @@ namespace GZ_LTHPilot_ORDER.ScheduleService /// 查询周期单位:月 /// int Cycle = 12; - public void Run(Context ctx, Schedule schedule) + public void Run(Context oldCtx, Schedule schedule) { - var ctxString = JsonConvert.SerializeObject(ctx); - Context newCtx = DataCenterService.GetDataCenterContextByID(ctx.DBId); - newCtx.UserId = 131409; //服务操作用户暂时记为Administrator - newCtx.UserName = "ERP6"; - newCtx.ServiceType = WebType.WebSite; - newCtx.CurrentOrganizationInfo.ID = 1; - - LogUtil.Log("UserContext", ctxString); - - TempTableService tempTableService = new TempTableService(newCtx); - OrgService orgService = new OrgService(newCtx); - SaleOrderService saleOrderService = new SaleOrderService(newCtx); + var ctxString = JsonConvert.SerializeObject(oldCtx); + ContextUtil contextUtil = new ContextUtil(oldCtx); + var ctx = contextUtil.GetDefaultContext(); + TempTableService tempTableService = new TempTableService(ctx); + OrgService orgService = new OrgService(ctx); + SaleOrderService saleOrderService = new SaleOrderService(ctx); var orgList = orgService.GetOrgList(); var tableName = tempTableService.CreateTempTable(); - CreateTempTable(newCtx, tableName); + CreateTempTable(ctx, tableName); var advanceAays = GetAdvanceAays(schedule); var planStartDate = DateTime.Now; Dictionary orgDict = new Dictionary(); @@ -66,14 +61,14 @@ namespace GZ_LTHPilot_ORDER.ScheduleService var receiveAmountList = saleOrderService.GetSaleOrderReceiveAmountByDate(saleOrgIds, startDate, endDate); if (receiveAmountList.Count > 0) { - InsertDataToTempTable(newCtx, tableName, orgDict, receiveAmountList); + InsertDataToTempTable(ctx, tableName, orgDict, receiveAmountList); } startDate = startDate.AddMonths(Cycle); endDate = startDate.AddMonths(Cycle); } - UpdateSaleOrderReceiveAmount(newCtx, tableName); + UpdateSaleOrderReceiveAmount(ctx, tableName); tempTableService.DropTempTable(tableName); } diff --git a/Utils/ContextUtil.cs b/Utils/ContextUtil.cs new file mode 100644 index 0000000..68dbc0d --- /dev/null +++ b/Utils/ContextUtil.cs @@ -0,0 +1,38 @@ +using GZ_LTHPilot_ORDER.Config; +using Kingdee.BOS; +using Kingdee.BOS.ServiceHelper; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GZ_LTHPilot_ORDER.Utils +{ + public class ContextUtil + { + Context ctx { get; set; } + + public ContextUtil(Context ctx) + { + this.ctx = ctx; + } + + public Context GetDefaultContext() + { + var userName = ContextConfig.DefaultUserName; + var userId = ContextConfig.DefaultUserId; + return GetNewContext(userId, userName); + } + + public Context GetNewContext(long userId, string userName) + { + Context newCtx = DataCenterService.GetDataCenterContextByID(ctx.DBId); + newCtx.UserId = userId; + newCtx.UserName = userName; + newCtx.ServiceType = WebType.WebSite; + newCtx.CurrentOrganizationInfo.ID = 1; + return newCtx; + } + } +}