Files
YunTongJackYunTask/Reportapi/MyCode.Project.Services/BaoDianBLL/CommonPlanCalBLL.cs
2025-07-04 09:50:02 +08:00

137 lines
3.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using MyCode.Project.Domain.Model;
using MyCode.Project.Domain.Repositories;
using MyCode.Project.Infrastructure.Common;
using MyCode.Project.Infrastructure.Enumeration;
using MyCode.Project.Infrastructure.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCode.Project.Services.BLL
{
/// <summary>
/// 宝典公共计算
/// </summary>
public class CommonPlanCalBLL
{
#region
/// <summary>
/// 初始化
/// </summary>
public IRepository _repository;
/// <summary>
/// 单据id
/// </summary>
public string SheetId
{
get;
set;
}
/// <summary>
/// 备注字段
/// </summary>
public string Info
{
get;
set;
}
/// <summary>
/// 订单
/// </summary>
public LxmSheet Sheet
{
get;
set;
}
/// <summary>
/// 版本时间
/// </summary>
public DateTime VersionTime
{
get;
set;
}
public CommonPlanCalBLL(IRepository repository)
{
_repository = repository;
}
#endregion
#region Init()
/// <summary>
/// 初始化
/// </summary>
public void Init(string sheetId)
{
this.Sheet = _repository
.Queryable<LxmSheet>()
.Where(p => p.Id == sheetId)
.First();
this.SheetId = sheetId;
this.VersionTime = this.Sheet.CreateTime.Value.GetFirstDayOfMonth();
}
#endregion
#region GetSourceSimpleOrder(退)
/// <summary>
/// 得到退款时的原始订单信息,如果是预售单,则要再取一下得到预售单
/// </summary>
/// <param name="sourceOrderId"></param>
/// <returns></returns>
public LxmSheet GetSourceSimpleOrder(string sourceOrderId)
{
var sourceOrder = _repository.Queryable<LxmSheet>().Where(p => p.Id == Sheet.SourceOrderId).First();
if (sourceOrder.IsPorderToSorder == 1)
{
sourceOrder = _repository.Queryable<LxmSheet>().Where(p => p.Id == sourceOrder.OrderPreorderId).First();
}
return sourceOrder;
}
#endregion
#region CheckPassed()
/// <summary>
/// 数据验证
/// </summary>
/// <param name="isPorderToSorder"></param>
/// <returns></returns>
public bool CheckPassed(PlanType planType)
{
if (this.Sheet.IsPorderToSorder == 1)
{
LogHelper.Info($"{SheetId}是预售单,不参与宝典计划运算");
return false;
}
//只对60天内的数据做运算超过就不运算了
if ((DateTime.Now - this.Sheet.CreateTime.Value).TotalDays > 60)
{
LogHelper.Info($"{SheetId}是60天前的数据就不再宝典计划运算了");
return false;
}
////如果中间表中已经有该数据了,也不运算
var existCal = _repository.IsExist<BdOrderPlan>(p => p.OrderId == SheetId && p.PlanType == (int)planType);
if (existCal)
{
LogHelper.Info($"{SheetId}之前已经运算过,不再运算");
return false;
}
return true;
}
#endregion
}
}