|
@@ -0,0 +1,149 @@
|
|
|
|
|
+using Business.Core.Enum;
|
|
|
|
|
+using Business.Core.MongoDBHelper;
|
|
|
|
|
+using Business.Core.Utilities;
|
|
|
|
|
+using Bussiness.Model.MES.IC;
|
|
|
|
|
+using Bussiness.Model.Sale;
|
|
|
|
|
+using Bussiness.Model.SRM;
|
|
|
|
|
+using Bussiness.MongoModel.MES.IC;
|
|
|
|
|
+using Bussiness.MongoModel.Production;
|
|
|
|
|
+using Bussiness.MongoModel.SRM;
|
|
|
|
|
+using System;
|
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
|
+using System.Linq;
|
|
|
|
|
+using System.Text;
|
|
|
|
|
+using System.Threading.Tasks;
|
|
|
|
|
+using Volo.Abp.Application.Services;
|
|
|
|
|
+using Volo.Abp.Domain.Repositories;
|
|
|
|
|
+using ZstdSharp.Unsafe;
|
|
|
|
|
+
|
|
|
|
|
+namespace Business.ResourceExamineManagement
|
|
|
|
|
+{
|
|
|
|
|
+ public class PurchaseOrderAppService : ApplicationService
|
|
|
|
|
+ {
|
|
|
|
|
+ #region 服务
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 采购订单
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private readonly IMongoDB<mo_srm_po_main> _mo_srm_po_main;
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 采购订单明细详情
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private readonly IMongoDB<mo_srm_po_list> _mo_srm_po_list;
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 采购订单占用详情
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private readonly IMongoDB<mo_srm_po_occupy> _mo_srm_po_occupy;
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 采购申请单
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private readonly IMongoDB<mo_srm_pr_main> _mo_srm_pr_main;
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 雪花算法
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ SnowFlake snowFlake = new SnowFlake();
|
|
|
|
|
+
|
|
|
|
|
+ #endregion
|
|
|
|
|
+ #region 构造函数
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 构造函数
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="icitem"></param>
|
|
|
|
|
+ /// <param name="icbom"></param>
|
|
|
|
|
+ public PurchaseOrderAppService(
|
|
|
|
|
+ IMongoDB<mo_srm_po_main> mo_srm_po_main,
|
|
|
|
|
+ IMongoDB<mo_srm_po_list> mo_srm_po_list,
|
|
|
|
|
+ IMongoDB<mo_srm_po_occupy> mo_srm_po_occupy,
|
|
|
|
|
+ IMongoDB<mo_srm_pr_main> mo_srm_pr_main
|
|
|
|
|
+ )
|
|
|
|
|
+ {
|
|
|
|
|
+ _mo_srm_po_main = mo_srm_po_main;
|
|
|
|
|
+ _mo_srm_po_list = mo_srm_po_list;
|
|
|
|
|
+ _mo_srm_po_occupy = mo_srm_po_occupy;
|
|
|
|
|
+ _mo_srm_pr_main = mo_srm_pr_main;
|
|
|
|
|
+ }
|
|
|
|
|
+ #endregion
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 检查在途订单
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public async void CheckPurchaseOrder(crm_seorderentry seorderentry, long icitem_id, decimal Quantity, DateTime DeliverDate, ic_plan ic_Plan, long bang_id)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (seorderentry == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ //TODO:入参异常
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //查询出对应物料采购订单明细 --数据未被停用 && 评审通过后
|
|
|
|
|
+ var poDetailList = await _mo_srm_po_list.GetManyByCondition(x => x.icitem_id == icitem_id && x.state == 1 && x.rstate == 1);
|
|
|
|
|
+ //采购订单占用数据
|
|
|
|
|
+ var poOccupys = await _mo_srm_po_occupy.GetManyByCondition(x => poDetailList.Select(p => p.id).ToList().Contains(x.polist_id.GetValueOrDefault()));
|
|
|
|
|
+ //先查询出满足日期,并且数量可满足占用的数据
|
|
|
|
|
+ var poDetails = poDetailList.Where(x => x.rarrdate.GetValueOrDefault().AddDays(-(int)ic_Plan.self_inspection_date.GetValueOrDefault()) < DeliverDate && x.qty - x.rqty - x.esqty -
|
|
|
|
|
+ poOccupys.Where(p => p.polist_id.GetValueOrDefault() == x.mysql_id)?.Sum(m => m.qty) > Quantity).OrderByDescending(x => x.rarrdate).ToList();
|
|
|
|
|
+ //未满足则查询出满足日期的订单
|
|
|
|
|
+ if (poDetails.Count == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ poDetails = poDetailList.Where(x => x.rarrdate.GetValueOrDefault().AddDays(-(int)ic_Plan.self_inspection_date.GetValueOrDefault()) < DeliverDate).OrderByDescending(x => x.rarrdate).ToList();
|
|
|
|
|
+ }
|
|
|
|
|
+ var QuantityNumber = 0.00m;
|
|
|
|
|
+ foreach (var item in poDetails)
|
|
|
|
|
+ {
|
|
|
|
|
+ var poOccupy = poOccupys.Where(x => x.polist_id == item.id).ToList();
|
|
|
|
|
+ decimal? Qtys = poOccupy.Count > 0 ? poOccupy.Sum(x => x.qty) : 0.00m;
|
|
|
|
|
+ //剩余可用数量
|
|
|
|
|
+ var PlanQty = item.plan_qty - item.rqty - item.esqty - Qtys;
|
|
|
|
|
+ if (PlanQty > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ //可占用数量-需求数量小于0时 占用全部可占用数量
|
|
|
|
|
+ if (PlanQty - Quantity <= 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ QuantityNumber = PlanQty.GetValueOrDefault();
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ //可占用数量满足 需求数量时直接占用需求数量
|
|
|
|
|
+ QuantityNumber = Quantity;
|
|
|
|
|
+ }
|
|
|
|
|
+ var mes_Mooccupy = GetMooccupies(seorderentry, item, QuantityNumber, bang_id);
|
|
|
|
|
+ //mes_Mooccupies.Add(mes_Mooccupy);
|
|
|
|
|
+ //当剩余需要数量大于0则继续寻找可占用工单,已满足需要数量停止循环查找
|
|
|
|
|
+ if (Quantity - PlanQty <= 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ Quantity = Quantity - PlanQty.GetValueOrDefault();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 拼接工单占用表
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="seorderentry">销售订单子表</param>
|
|
|
|
|
+ /// <param name="mysql_ic_item">物料详情表</param>
|
|
|
|
|
+ /// <param name="item">工单表</param>
|
|
|
|
|
+ /// <param name="mes_mooccupy">占用工单表</param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ public mo_srm_po_occupy GetMooccupies(crm_seorderentry seorderentry, mo_srm_po_list srm_po_list, decimal? number, long bang_id)
|
|
|
|
|
+ {
|
|
|
|
|
+ //生成mo_srm_po_occupy采购占用表数据。
|
|
|
|
|
+ mo_srm_po_occupy srm_Po_Occupy = new mo_srm_po_occupy();
|
|
|
|
|
+ srm_Po_Occupy.mysql_id = snowFlake.NextId();
|
|
|
|
|
+ srm_Po_Occupy.bang_id = bang_id;
|
|
|
|
|
+ srm_Po_Occupy.polist_id = srm_po_list.id;
|
|
|
|
|
+ srm_Po_Occupy.polist_row = srm_po_list.polist_row;
|
|
|
|
|
+ srm_Po_Occupy.eid = seorderentry.entry_seq.Value;
|
|
|
|
|
+ srm_Po_Occupy.bill_no = seorderentry.seorder_id;
|
|
|
|
|
+ srm_Po_Occupy.entry_id = seorderentry.entry_seq.GetValueOrDefault();
|
|
|
|
|
+ srm_Po_Occupy.qty = number;
|
|
|
|
|
+ srm_Po_Occupy.type = "";//TODO:类型未知
|
|
|
|
|
+ srm_Po_Occupy.stime = DateTime.Now.Date;
|
|
|
|
|
+ srm_Po_Occupy.etime = srm_po_list.rarrdate;
|
|
|
|
|
+ srm_Po_Occupy.state = 1;
|
|
|
|
|
+ srm_Po_Occupy.tenant_id = seorderentry.tenant_id;//取销售子表企业ID
|
|
|
|
|
+ srm_Po_Occupy.factory_id = seorderentry.factory_id;
|
|
|
|
|
+ srm_Po_Occupy.org_id = seorderentry.org_id;
|
|
|
|
|
+ return srm_Po_Occupy;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|