|
|
@@ -20,99 +20,127 @@ namespace Business.SaleForecastManagement
|
|
|
/// </summary>
|
|
|
public class MonthlyCapacityLoadAppService : ApplicationService, IMonthlyCapacityLoadAppService, ITransientDependency
|
|
|
{
|
|
|
- //#region 服务
|
|
|
- ///// <summary>
|
|
|
- ///// 物料
|
|
|
- ///// </summary>
|
|
|
- //private IRepository<ic_item, long> _ic_item;
|
|
|
+ #region 服务
|
|
|
+ /// <summary>
|
|
|
+ /// 物料
|
|
|
+ /// </summary>
|
|
|
+ private IRepository<ic_item, long> _ic_item;
|
|
|
|
|
|
- ///// <summary>
|
|
|
- ///// 整体需求计划明细
|
|
|
- ///// </summary>
|
|
|
- //private ISqlRepository<OverallDemandPlanDtl> _overallDemandPlanDtl;
|
|
|
+ /// <summary>
|
|
|
+ /// 整体需求计划明细
|
|
|
+ /// </summary>
|
|
|
+ private ISqlRepository<OverallDemandPlanDtl> _overallDemandPlanDtl;
|
|
|
|
|
|
- ///// <summary>
|
|
|
- ///// 生产线明细
|
|
|
- ///// </summary>
|
|
|
- //private ISqlRepository<ProdLineDetail> _prodLineDetail;
|
|
|
+ /// <summary>
|
|
|
+ /// 生产线明细
|
|
|
+ /// </summary>
|
|
|
+ private ISqlRepository<ProdLineDetail> _prodLineDetail;
|
|
|
|
|
|
- ///// <summary>
|
|
|
- ///// 工作日历数据
|
|
|
- ///// </summary>
|
|
|
- //private ISqlRepository<ShopCalendarWorkCtr> _shopCalendarWorkCtr;
|
|
|
+ /// <summary>
|
|
|
+ /// 工作日历数据
|
|
|
+ /// </summary>
|
|
|
+ private ISqlRepository<ShopCalendarWorkCtr> _shopCalendarWorkCtr;
|
|
|
|
|
|
- ///// <summary>
|
|
|
- ///// 产线休息时间记录表
|
|
|
- ///// </summary>
|
|
|
- //private ISqlRepository<QualityLineWorkDetail> _qualityLineWorkDetail;
|
|
|
+ /// <summary>
|
|
|
+ /// 产线休息时间记录表
|
|
|
+ /// </summary>
|
|
|
+ private ISqlRepository<QualityLineWorkDetail> _qualityLineWorkDetail;
|
|
|
|
|
|
- ///// <summary>
|
|
|
- ///// 节假日记录表
|
|
|
- ///// </summary>
|
|
|
- //private ISqlRepository<HolidayMaster> _holidayMaster;
|
|
|
+ /// <summary>
|
|
|
+ /// 节假日记录表
|
|
|
+ /// </summary>
|
|
|
+ private ISqlRepository<HolidayMaster> _holidayMaster;
|
|
|
|
|
|
- ///// <summary>
|
|
|
- ///// 月度产能共识主表
|
|
|
- ///// </summary>
|
|
|
- //private ISqlRepository<MonthlyProdCapacityMain> _monthlyProdCapacityMain;
|
|
|
+ /// <summary>
|
|
|
+ /// 月度产能共识主表
|
|
|
+ /// </summary>
|
|
|
+ private ISqlRepository<MonthlyProdCapacityMain> _monthlyProdCapacityMain;
|
|
|
|
|
|
- ///// <summary>
|
|
|
- ///// 月度产能共识明细表
|
|
|
- ///// </summary>
|
|
|
- //private ISqlRepository<MonthlyProdCapacityDtl> _monthlyProdCapacityDtl;
|
|
|
+ /// <summary>
|
|
|
+ /// 月度产能共识明细表
|
|
|
+ /// </summary>
|
|
|
+ private ISqlRepository<MonthlyProdCapacityDtl> _monthlyProdCapacityDtl;
|
|
|
|
|
|
- ///// <summary>
|
|
|
- ///// 标准物料规格型号设置表
|
|
|
- ///// </summary>
|
|
|
- //private ISqlRepository<StandardItemModelSet> _standardItemModelSet;
|
|
|
+ /// <summary>
|
|
|
+ /// 工作单元
|
|
|
+ /// </summary>
|
|
|
+ private readonly IUnitOfWorkManager _unitOfWorkManager;
|
|
|
|
|
|
- ///// <summary>
|
|
|
- ///// 工作单元
|
|
|
- ///// </summary>
|
|
|
- //private readonly IUnitOfWorkManager _unitOfWorkManager;
|
|
|
+ /// <summary>
|
|
|
+ /// 日志
|
|
|
+ /// </summary>
|
|
|
+ private readonly ICurrentTenant _currentTenant;
|
|
|
|
|
|
- ///// <summary>
|
|
|
- ///// 日志
|
|
|
- ///// </summary>
|
|
|
- //private readonly ICurrentTenant _currentTenant;
|
|
|
+ /// <summary>
|
|
|
+ /// 年度生产需求大纲
|
|
|
+ /// </summary>
|
|
|
+ private IRepository<YearDemandManagement, long> _yearDemandManagement;
|
|
|
|
|
|
- ///// <summary>
|
|
|
- ///// 雪花算法
|
|
|
- ///// </summary>
|
|
|
- //SnowFlake help = new SnowFlake();
|
|
|
- //#endregion
|
|
|
+ /// <summary>
|
|
|
+ /// 国内终端预测
|
|
|
+ /// </summary>
|
|
|
+ private IRepository<DomesticTerminalFcst, long> _domesticTerminalFcst;
|
|
|
|
|
|
- //#region 构造函数
|
|
|
- ///// <summary>
|
|
|
- ///// 构造函数
|
|
|
- ///// </summary>
|
|
|
- //public MonthlyCapacityLoadAppService(
|
|
|
- // IRepository<ic_item, long> ic_item,
|
|
|
- // ISqlRepository<OverallDemandPlanDtl> overallDemandPlanDtl,
|
|
|
- // ISqlRepository<ProdLineDetail> prodLineDetail,
|
|
|
- // ISqlRepository<ShopCalendarWorkCtr> shopCalendarWorkCtr,
|
|
|
- // ISqlRepository<QualityLineWorkDetail> qualityLineWorkDetail,
|
|
|
- // ISqlRepository<HolidayMaster> holidayMaster,
|
|
|
- // ISqlRepository<MonthlyProdCapacityMain> monthlyProdCapacityMain,
|
|
|
- // ISqlRepository<MonthlyProdCapacityDtl> monthlyProdCapacityDtl,
|
|
|
- // IUnitOfWorkManager unitOfWorkManager,
|
|
|
- // ICurrentTenant currentTenant,
|
|
|
- // ISqlRepository<StandardItemModelSet> standardItemModelSet
|
|
|
- // )
|
|
|
- //{
|
|
|
- // _ic_item= ic_item;
|
|
|
- // _overallDemandPlanDtl= overallDemandPlanDtl;
|
|
|
- // _prodLineDetail= prodLineDetail;
|
|
|
- // _shopCalendarWorkCtr= shopCalendarWorkCtr;
|
|
|
- // _qualityLineWorkDetail= qualityLineWorkDetail;
|
|
|
- // _holidayMaster= holidayMaster;
|
|
|
- // _monthlyProdCapacityMain= monthlyProdCapacityMain;
|
|
|
- // _monthlyProdCapacityDtl= monthlyProdCapacityDtl;
|
|
|
- // _unitOfWorkManager= unitOfWorkManager;
|
|
|
- // _currentTenant= currentTenant;
|
|
|
- // _standardItemModelSet= standardItemModelSet;
|
|
|
- //}
|
|
|
- //#endregion
|
|
|
+ /// <summary>
|
|
|
+ /// 海外销售预测
|
|
|
+ /// </summary>
|
|
|
+ private IRepository<OverseasSaleFcst, long> _overseasSaleFcst;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 平台预测收集
|
|
|
+ /// </summary>
|
|
|
+ private IRepository<PlatformFcstCollect, long> _platformFcstCollect;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 标准物料规格型号设置表
|
|
|
+ /// </summary>
|
|
|
+ private IRepository<StandardItemModelSet,long> _standardItemModelSet;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 雪花算法
|
|
|
+ /// </summary>
|
|
|
+ SnowFlake help = new SnowFlake();
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 构造函数
|
|
|
+ /// <summary>
|
|
|
+ /// 构造函数
|
|
|
+ /// </summary>
|
|
|
+ public MonthlyCapacityLoadAppService(
|
|
|
+ IRepository<ic_item, long> ic_item,
|
|
|
+ ISqlRepository<OverallDemandPlanDtl> overallDemandPlanDtl,
|
|
|
+ ISqlRepository<ProdLineDetail> prodLineDetail,
|
|
|
+ ISqlRepository<ShopCalendarWorkCtr> shopCalendarWorkCtr,
|
|
|
+ ISqlRepository<QualityLineWorkDetail> qualityLineWorkDetail,
|
|
|
+ ISqlRepository<HolidayMaster> holidayMaster,
|
|
|
+ ISqlRepository<MonthlyProdCapacityMain> monthlyProdCapacityMain,
|
|
|
+ ISqlRepository<MonthlyProdCapacityDtl> monthlyProdCapacityDtl,
|
|
|
+ IUnitOfWorkManager unitOfWorkManager,
|
|
|
+ ICurrentTenant currentTenant,
|
|
|
+ IRepository<StandardItemModelSet,long> standardItemModelSet,
|
|
|
+ IRepository<YearDemandManagement, long> yearDemandManagement,
|
|
|
+ IRepository<DomesticTerminalFcst, long> domesticTerminalFcst,
|
|
|
+ IRepository<OverseasSaleFcst, long> overseasSaleFcst,
|
|
|
+ IRepository<PlatformFcstCollect, long> platformFcstCollect
|
|
|
+ )
|
|
|
+ {
|
|
|
+ _ic_item = ic_item;
|
|
|
+ _overallDemandPlanDtl = overallDemandPlanDtl;
|
|
|
+ _prodLineDetail = prodLineDetail;
|
|
|
+ _shopCalendarWorkCtr = shopCalendarWorkCtr;
|
|
|
+ _qualityLineWorkDetail = qualityLineWorkDetail;
|
|
|
+ _holidayMaster = holidayMaster;
|
|
|
+ _monthlyProdCapacityMain = monthlyProdCapacityMain;
|
|
|
+ _monthlyProdCapacityDtl = monthlyProdCapacityDtl;
|
|
|
+ _unitOfWorkManager = unitOfWorkManager;
|
|
|
+ _currentTenant = currentTenant;
|
|
|
+ _standardItemModelSet = standardItemModelSet;
|
|
|
+ _yearDemandManagement= yearDemandManagement;
|
|
|
+ _domesticTerminalFcst= domesticTerminalFcst;
|
|
|
+ _overallDemandPlanDtl= overallDemandPlanDtl;
|
|
|
+ _platformFcstCollect= platformFcstCollect;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
|
|
|
///// <summary>
|
|
|
///// 产能分析
|
|
|
@@ -254,5 +282,75 @@ namespace Business.SaleForecastManagement
|
|
|
// }
|
|
|
// return sumDays;
|
|
|
//}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 月度需求预测更新
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="input"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
+ public async Task<string> DemandAnalysis(InputDto input)
|
|
|
+ {
|
|
|
+ //1.0 获取年度生产需求大纲
|
|
|
+ List<YearDemandManagement> yearDemands = _yearDemandManagement.GetListAsync(p => p.Year == input.year && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result;
|
|
|
+ if (yearDemands.Count() == 0)
|
|
|
+ {
|
|
|
+ new NLogHelper("MonthlyCapacityLoadAppService").WriteLog("DemandAnalysis", "请导入" + input.year + "年年度生产需求数据后再操作!", _currentTenant.Id.ToString());
|
|
|
+ return "NO|请导入" + input.year + "年年度生产需求数据后再操作!";
|
|
|
+ }
|
|
|
+ //1.1、获取海外销售预测数据
|
|
|
+ List<OverseasSaleFcst> overseasSales = _overseasSaleFcst.GetListAsync(p => p.Year == input.year && p.Month == input.month && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result;
|
|
|
+ if (overseasSales.Count() == 0)
|
|
|
+ {
|
|
|
+ new NLogHelper("MonthlyCapacityLoadAppService").WriteLog("DemandAnalysis", "请导入"+input.year+"年"+input.month+"月海外预测数据后再操作!", _currentTenant.Id.ToString());
|
|
|
+ return "NO|请导入"+input.year+"年"+input.month+"月海外预测数据后再操作!";
|
|
|
+ }
|
|
|
+ //1.2、获取平台预测收集数据
|
|
|
+ List<PlatformFcstCollect> platformFcsts = _platformFcstCollect.GetListAsync(p => p.Year == input.year && p.Month == input.month && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result;
|
|
|
+ if (platformFcsts.Count() == 0)
|
|
|
+ {
|
|
|
+ new NLogHelper("MonthlyCapacityLoadAppService").WriteLog("DemandAnalysis", "请导入" + input.year + "年" + input.month + "月平台需求预测数据后再操作!", _currentTenant.Id.ToString());
|
|
|
+ return "NO|请导入" + input.year + "年" + input.month + "月平台需求预测数据后再操作!";
|
|
|
+ }
|
|
|
+ //1.3、获取国内终端预测-T1汇总数据
|
|
|
+ List<DomesticTerminalFcst> domesticFcst = _domesticTerminalFcst.GetListAsync(p => p.Year == input.year && p.Month == input.month && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result;
|
|
|
+ if (domesticFcst.Count() == 0)
|
|
|
+ {
|
|
|
+ new NLogHelper("MonthlyCapacityLoadAppService").WriteLog("DemandAnalysis", "请导入" + input.year + "年" + input.month + "月国内终端预测数据后再操作!", _currentTenant.Id.ToString());
|
|
|
+ return "NO|请导入" + input.year + "年" + input.month + "月国内终端预测数据后再操作!";
|
|
|
+ }
|
|
|
+ //1.4、根据年度生产大纲,获取规格型号对应的补货周期
|
|
|
+ List<string> models = yearDemands.Select(p=>p.Model).Distinct().ToList();
|
|
|
+ List<StandardItemModelSet> standards = _standardItemModelSet.GetListAsync(p=>models.Contains(p.Model) && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result;
|
|
|
+ //1.5、获取规格型号对应的标准SKU数据
|
|
|
+ List<string> itemNums = standards.Select(p=>p.ItemNumber).Distinct().ToList();
|
|
|
+ List<ic_item> items = _ic_item.GetListAsync(p=> itemNums.Contains(p.number) && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result;
|
|
|
+
|
|
|
+ //计算海外预测
|
|
|
+
|
|
|
+
|
|
|
+ //保存数据
|
|
|
+ using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ////先删除数据
|
|
|
+ //_monthlyProdCapacityMain.Delete(p => p.tenant_id == input.tenant_id && p.factory_id == input.factory_id && p.Version.Contains(input.version.Substring(0, 7)));
|
|
|
+ //_monthlyProdCapacityDtl.Delete(p => p.tenant_id == input.tenant_id && p.factory_id == input.factory_id && p.Version.Contains(input.version.Substring(0, 7)));
|
|
|
+
|
|
|
+ ////插入数据
|
|
|
+ //_monthlyProdCapacityMain.Insert(capacityMains);
|
|
|
+ //_monthlyProdCapacityDtl.Insert(capacityDtls);
|
|
|
+ //await unitOfWork.CompleteAsync();
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ unitOfWork.Dispose();
|
|
|
+ new NLogHelper("MonthlyCapacityLoadAppService").WriteLog("CapacityAnalysis", "生成【" + input.year + "年" + input.month + "月】月度产能共识失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
+ return "NO|" + e.Message;
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return "OK|发布成功!";
|
|
|
+ }
|
|
|
}
|
|
|
}
|