Просмотр исходного кода

Merge branch 'master' of http://123.60.180.165:4647/ZZYDOP/DOPCore

# Conflicts:
#	MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs
heteng 3 лет назад
Родитель
Сommit
30a0fe0608

+ 63 - 31
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -403,7 +403,7 @@ namespace Business.ResourceExamineManagement
             }
             //获取订单行数据
             List<crm_seorderentry> sentrys = _mysql_crm_seorderentry.GetListAsync(p => p.seorder_id == input.sorderId && p.IsDeleted == false).Result;
-            
+
             string bom_number = "BOM00042070";
             int packages = 1000;
 
@@ -414,7 +414,29 @@ namespace Business.ResourceExamineManagement
             //await SaveChangesCompletedEventData()
 
             //数据库快照-同步mysql库数据到mongoDB中
-            //await SyncData(input.tenantId, input.factoryId, bangid);
+            await SyncData(input.tenantId, input.factoryId, bangid);
+
+            List<BomChildExamineDto> returnlist = new List<BomChildExamineDto>();
+            BomChildExamineDto bomChild = new BomChildExamineDto();
+            bomChild.id = 4331979;
+            bomChild.item_id = 809914;
+            bomChild.item_name = "壳子";
+            bomChild.unit = "只";
+            bomChild.item_code = "2.1.01.01.0007";
+            bomChild.lack_qty = 20;
+            bomChild.erp_cls = 2;
+            returnlist.Add(bomChild);
+            BomChildExamineDto bomChild2 = new BomChildExamineDto();
+            bomChild2.id = 4331981;
+            bomChild2.item_id = 809667;
+            bomChild2.item_name = "壳子";
+            bomChild2.unit = "只";
+            bomChild2.item_code = "2.1.01.01.0053";
+            bomChild2.lack_qty = 20;
+            bomChild2.erp_cls = 2;
+            returnlist.Add(bomChild2);
+            DateTime dateTime = DateTime.Now.AddDays(5);
+            CheckOnOrder(returnlist, 102, 10201, dateTime, bangid);
 
             //产能检查
             await ProductiveExamine(bom_number, packages);
@@ -559,7 +581,7 @@ namespace Business.ResourceExamineManagement
 
             //采购订单
             var srm_po_main = _mysql_srm_po_main.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
-            if (crm_seorderentry.Count > 0)
+            if (srm_po_main.Count > 0)
             {
                 srm_po_main.ForEach(item => { item.bang_id = bangid; });
                 await _srm_po_main.InsertMany(srm_po_main);
@@ -715,13 +737,13 @@ namespace Business.ResourceExamineManagement
         /// <param name="DeliverDate">交付日期</param>
         /// <param name="seorderentry_id">销售订单子表ID</param>
         /// <returns></returns>
-        public async Task GenerateMorder(long seorderentry_id)
+        public async Task GenerateMorder(crm_seorderentry seorderentry)
         {
             //1.库存、在制工单检查完成后 当前BOM需要自制时 产生工单。
 
             //2.每一个销售订单行对应一个工单。
             //查询销售订单子表数据
-            var seorderentry = await _mysql_crm_seorderentry.FindAsync(x => x.Id == seorderentry_id);
+            //var seorderentry = await _mysql_crm_seorderentry.FindAsync(x => x.Id == seorderentry_id);
             //获取销售订单信息
             var seorder = await _mysql_crm_seorder.FindAsync(x => x.Id == seorderentry.seorder_id);
             //物料BOM
@@ -824,7 +846,7 @@ namespace Business.ResourceExamineManagement
         /// <param name="DeliverDate">交付日期</param>
         /// <param name="seorderentry_id">销售订单子表ID</param>
         /// <returns></returns>
-        public async Task<bool> CheckMorder(string bomNumber, decimal? Quantity, DateTime DeliverDate, long seorderentry_id)
+        public async Task<bool> CheckMorder(string bomNumber, decimal? Quantity, DateTime DeliverDate, crm_seorderentry seorderentry)
         {
             if (string.IsNullOrEmpty(bomNumber) || Quantity == null)
             {
@@ -833,14 +855,14 @@ namespace Business.ResourceExamineManagement
             }
             //获取销售订单信息
             //var seorder = await _crm_seorder.FindAsync(x => x.Id == OrderId);
-            var seorderentry = await _mysql_crm_seorderentry.FindAsync(x => x.Id == seorderentry_id);
+            //var seorderentry = await _mysql_crm_seorderentry.FindAsync(x => x.Id == seorderentry_id);
             //根据Bom编码查询出对应工单并且状态不为完成、关闭,非委外工单。
             //TODO:工单类型;
             var morderList = await _mes_morder.GetManyByCondition(x => x.bom_number == bomNumber && (x.morder_state != "完成" || x.morder_state != "关闭"
             && x.morder_icitem_type != "相关委外工单") && x.IsDeleted == false && x.tenant_id == seorderentry.tenant_id);
 
             //获取物料详情
-            var ic_item = _ic_item.GetManyByCondition(x => x.number == bomNumber && x.tenant_id == seorderentry.tenant_id).Result.FirstOrDefault();
+            var ic_item = _ic_item.GetManyByCondition(x => x.number == seorderentry.item_number && x.tenant_id == seorderentry.tenant_id).Result.FirstOrDefault();
 
             //工单已被占用后要与占用表关联查询...减去占用量后 剩下生产数量可供下个销售工单使用。
             var mes_mooccupyList = await _mes_mooccupy.GetManyByCondition(x => x.moo_state == 1 && x.IsDeleted == false && x.tenant_id == seorderentry.tenant_id);
@@ -892,7 +914,7 @@ namespace Business.ResourceExamineManagement
         /// <param name="item">工单表</param>
         /// <param name="mes_mooccupy">占用工单表</param>
         /// <returns></returns>
-        public mes_mooccupy GetMooccupies(crm_seorderentry seorderentry, ic_item mysql_ic_item, mes_morder item, List<mes_mooccupy> mes_mooccupy)
+        public mes_mooccupy GetMooccupies(crm_seorderentry seorderentry, ic_item ic_item, mes_morder item, List<mes_mooccupy> mes_mooccupy)
         {
             decimal? Sumqty = 0;
             if (mes_mooccupy.Count > 0)
@@ -906,9 +928,9 @@ namespace Business.ResourceExamineManagement
             mes_Mooccupy.moo_id_billid = seorderentry.seorder_id;//销售订单ID
             mes_Mooccupy.fbill_no = seorderentry.bill_no;//销售订单号
             mes_Mooccupy.fentry_id = seorderentry.entry_seq.Value;//销售订单行
-            mes_Mooccupy.fitem_name = mysql_ic_item.name;//物料名称
-            mes_Mooccupy.fitem_number = mysql_ic_item.number;
-            mes_Mooccupy.fmodel = mysql_ic_item.model;//规格型号
+            mes_Mooccupy.fitem_name = ic_item.name;//物料名称
+            mes_Mooccupy.fitem_number = ic_item.number;
+            mes_Mooccupy.fmodel = ic_item.model;//规格型号
             mes_Mooccupy.moo_moid = item.Id;
             mes_Mooccupy.moo_mo = item.morder_no;
             //占用量=生产计划数量-入库数量-已被占用数量
@@ -1215,8 +1237,8 @@ namespace Business.ResourceExamineManagement
             }
         }
 
-        
-        public void calcTest(List<BomChildExamineDto> returnlist, long bangid, long orderid,decimal count)
+
+        public void calcTest(List<BomChildExamineDto> returnlist, long bangid, long orderid, decimal count)
         {
             //占用情况
             List<ic_item_stockoccupy> sklist = new List<ic_item_stockoccupy>();
@@ -1258,7 +1280,7 @@ namespace Business.ResourceExamineManagement
             //returnlist[0].kz = childList.Min(s => s.kz);//得到最小可制数量。
             //再加个循环,来根据替代关系里的检查结果,根据规则明确使用和生成占用关系。
 
-            
+
             foreach (var item in childList)
             {
                 if (item.haveicsubs == 1)
@@ -1267,7 +1289,8 @@ namespace Business.ResourceExamineManagement
                     // 如果有群组替代,就移除掉被检查过的记录 item.icitem_ids
                     CalcStrategy(item, returnlist, bangid, sklist);
                 }
-                else { 
+                else
+                {
                     //直接占用库存,缺料就生成采购
                 }
             }
@@ -1297,7 +1320,8 @@ namespace Business.ResourceExamineManagement
             }*/
         }
 
-        public void RecalculationStock(BomChildExamineDto item, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist) {
+        public void RecalculationStock(BomChildExamineDto item, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist)
+        {
             //再计算一边占用情况,这里根据父级产品额缺料量*当前子料的使用数量-子料库存量。得出当前子物料的缺料数量
             var parent = returnlist.Find(s => s.id == item.parent_id);
             decimal stockQty = sklist.Where(s => s.icitem_id == item.item_id).Sum(p => p.quantity);
@@ -1307,7 +1331,7 @@ namespace Business.ResourceExamineManagement
             item.stock_state = item.lack_qty > 0 ? 0 : 1;
         }
 
-        public void CalcStrategy(BomChildExamineDto item, List<BomChildExamineDto> returnlist,long bangid, List<ic_item_stockoccupy> sklist)
+        public void CalcStrategy(BomChildExamineDto item, List<BomChildExamineDto> returnlist, long bangid, List<ic_item_stockoccupy> sklist)
         {
             //提取群组关系
             var sublist = returnlist.Where(s => s.parent_id == item.parent_id && s.num == item.num && s.level == item.level).OrderBy(c => c.substitute_all_num).ToList();
@@ -1330,7 +1354,8 @@ namespace Business.ResourceExamineManagement
                         //走混用
                         MixedUse(sublist, returnlist, sklist, bangid, parent);
                     }
-                    else {
+                    else
+                    {
                         //走整批
                         WholeBatch(sublist, returnlist, sklist, select, bangid, parent);
                     }
@@ -1364,10 +1389,11 @@ namespace Business.ResourceExamineManagement
                     idx = 99;
                 }
             }
-            
+
         }
         //整批占用
-        public void WholeBatch(List<BomChildExamineDto> sublist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist, List<BomChildExamineDto> select, long bangid, BomChildExamineDto parent) {
+        public void WholeBatch(List<BomChildExamineDto> sublist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist, List<BomChildExamineDto> select, long bangid, BomChildExamineDto parent)
+        {
             if (select.Count() == 0)
             {
                 //如果为空,则默认使用优先级为0的集合作为替代关系
@@ -1419,7 +1445,8 @@ namespace Business.ResourceExamineManagement
         }
 
         //混用占用数据
-        public void MixedUse(List<BomChildExamineDto> sublist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist, long bangid, BomChildExamineDto parent) {
+        public void MixedUse(List<BomChildExamineDto> sublist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist, long bangid, BomChildExamineDto parent)
+        {
 
             decimal parent_lack = 0;
             if (parent != null)
@@ -1527,7 +1554,8 @@ namespace Business.ResourceExamineManagement
                     //计算此次群组是否有符合
                     MaterialCalc(sublist, returnlist, sockoccupyList);
                 }
-                else {
+                else
+                {
                     //根据占用情况计算库存
                     Calczykc(item, sockoccupyList);
                     //如果有子集,则丢入循环,判断下库存可制等信息。
@@ -1555,7 +1583,7 @@ namespace Business.ResourceExamineManagement
             for (int i = 0; i <= maxIdx; i++)
             {
                 var group = sublist.Where(s => s.substitute_all_num == i).ToList();
-               // int boolCount = 0;//代表某一颗物料无需采购,可以自制,则集合+1。
+                // int boolCount = 0;//代表某一颗物料无需采购,可以自制,则集合+1。
 
                 //如果替代料库存不够,但是可制够,则也考虑使用优先级最高
                 foreach (var g in group)
@@ -1830,7 +1858,7 @@ namespace Business.ResourceExamineManagement
         /// <param name="factoryid">工厂id</param>
         /// <param name="deliveryDate">销售订单交付日期</param>
         /// <returns></returns>
-        private async Task<List<ICItemDateDto>> CheckOnOrder(List<BomChildExamineDto> returnlist, long tenantId, long factoryid, DateTime deliveryDate)
+        private async Task<List<ICItemDateDto>> CheckOnOrder(List<BomChildExamineDto> returnlist, long tenantId, long factoryid, DateTime deliveryDate, long bangid)
         {
             //ToDo:企业Id,数据状态过滤以及isdeleted
             var po_list = _srm_po_list.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.tenant_id == tenantId && p.factory_id == factoryid && p.rarrdate >= DateTime.Now && p.rarrdate < deliveryDate && !p.IsDeleted).Result;
@@ -1849,15 +1877,15 @@ namespace Business.ResourceExamineManagement
                         //外购生成采购申请单
                         if (item.erp_cls == 3)
                         {
-                            DateTime lastTime = CreateSRMPR(item, tenantId, factoryid, 2, leadTimeList, supplierList, planList, deliveryDate);
+                            DateTime lastTime=CreateSRMPR(item, tenantId, factoryid, bangid,2, leadTimeList, supplierList, planList,deliveryDate);
                             itemlist.Add(new ICItemDateDto { item_id = item.item_id, dateTime = lastTime });
                         }
                         else if (item.erp_cls == 2)
                         {
                             //委外生成委外采购申请单和委外工单
-                            DateTime lastTime = CreateSRMPR(item, tenantId, factoryid, 1, leadTimeList, supplierList, planList, deliveryDate);
-                            CreateMesOOder(item, tenantId, factoryid, leadTimeList, supplierList, deliveryDate);
-                            itemlist.Add(new ICItemDateDto { item_id = item.item_id, dateTime = lastTime });
+                            DateTime lastTime=CreateSRMPR(item, tenantId, factoryid, bangid,1, leadTimeList, supplierList, planList,deliveryDate);
+                            CreateMesOOder(item, tenantId, factoryid, bangid, leadTimeList, supplierList,deliveryDate);
+                            itemlist.Add(new ICItemDateDto { item_id = item.item_id, dateTime = lastTime});
                         }
                     }
                     else
@@ -1884,6 +1912,7 @@ namespace Business.ResourceExamineManagement
                                 po_Occupy.cby = "";//变更人
                                 po_Occupy.creason = "";//变更原因
                                 po_Occupy.ctime = DateTime.Now;//变更时间
+                                po_Occupy.bang_id = bangid;
                                 await _srm_po_occupy.InsertOne(po_Occupy);
                                 break;
                             }
@@ -1906,6 +1935,7 @@ namespace Business.ResourceExamineManagement
                                 po_Occupy.cby = "";//变更人
                                 po_Occupy.creason = "";//变更原因
                                 po_Occupy.ctime = DateTime.Now;//变更时间
+                                po_Occupy.bang_id = bangid;
                                 await _srm_po_occupy.InsertOne(po_Occupy);
                             }
                         }
@@ -1920,7 +1950,7 @@ namespace Business.ResourceExamineManagement
         /// </summary>
         /// <param name="returnlist"></param>
         /// <param name="factoryid"></param>
-        private DateTime CreateMesOOder(BomChildExamineDto returnlist, long tenantId, long factoryid, List<ICItemLeadTimeDto> iCItemLeadTimes, List<ic_item_pur> supplierList, DateTime deliveryDate)
+        private DateTime CreateMesOOder(BomChildExamineDto returnlist, long tenantId, long factoryid, long bangId, List<ICItemLeadTimeDto> iCItemLeadTimes,List<ic_item_pur> supplierList,DateTime deliveryDate)
         {
             mes_oorder oOrder = new mes_oorder();
             oOrder.GenerateNewId();
@@ -1962,6 +1992,7 @@ namespace Business.ResourceExamineManagement
             oOrder.need_icitem_status = 1;//所需物料是否充足  1-充足 0-缺料
             oOrder.tenant_id = tenantId;
             oOrder.factory_id = factoryid;
+            oOrder.bang_id = bangId;
             _mes_oorder.InsertOne(oOrder);
             return DateTime.Now;
         }
@@ -1973,7 +2004,7 @@ namespace Business.ResourceExamineManagement
         /// <param name="returnlist"></param>
         /// <param name="factoryid"></param>
         /// <param name="orderType">1委外采购申请单,2采购申请单</param>
-        private DateTime CreateSRMPR(BomChildExamineDto returnlist, long tenantId, long factoryid, int orderType, List<ICItemLeadTimeDto> iCItemLeadTimes, List<ic_item_pur> supplierList, List<ic_plan> planList, DateTime deliveryDate)
+        private DateTime CreateSRMPR(BomChildExamineDto returnlist, long tenantId, long factoryid,long bangId, int orderType,List<ICItemLeadTimeDto> iCItemLeadTimes, List<ic_item_pur> supplierList, List<ic_plan> planList,DateTime deliveryDate)
         {
             var leadTime = iCItemLeadTimes.Find(x => x.item_id == returnlist.item_id);
             var supplier = supplierList.Find(x => x.icitem_id == returnlist.item_id);//默认取第一个供应商
@@ -2011,6 +2042,7 @@ namespace Business.ResourceExamineManagement
             srm_Pr.secInv_ratio = plan.secinv_ratio;//安全库存触发采购比例
             srm_Pr.tenant_id = tenantId;
             srm_Pr.factory_id = factoryid;
+            srm_Pr.bang_id = bangId;
             _srm_pr_main.InsertOne(srm_Pr);
             decimal? totalLeadTime = leadTime.transportation_leadtime + leadTime.stock_leadtime + leadTime.production_leadtime + leadTime.order_leadtime;
             return deliveryDate.AddDays((double)totalLeadTime * -1);//减去提前期

+ 3 - 3
MicroServices/Business/Business.EntityFrameworkCore/EntityFrameworkCore/BusinessDbContextModelCreatingExtensions.cs

@@ -161,14 +161,14 @@ namespace Business.EntityFrameworkCore
             builder.Entity<srm_po_occupy>(b =>
             {
                 b.ToTable("srm_po_occupy").HasComment("粒劃隆等梩蚚砆ロ");
-
+                b.Ignore(v => v.bang_id);
                 b.ConfigureByConvention();
             });
 
             builder.Entity<srm_pr_main>(b =>
             {
                 b.ToTable("srm_pr_main").HasComment("粒劃扠ワ等");
-
+                b.Ignore(v => v.bang_id);
                 b.ConfigureByConvention();
             });
 
@@ -203,7 +203,7 @@ namespace Business.EntityFrameworkCore
             builder.Entity<mes_oorder>(b =>
             {
                 b.ToTable("mes_oorder").HasComment("巹俋隆等桶");
-
+                b.Ignore(v => v.bang_id);
                 b.ConfigureByConvention();
             });
 

+ 7 - 0
MicroServices/Business/Bussiness.Model/Production/mes_oorder.cs

@@ -5,6 +5,7 @@ using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -233,5 +234,11 @@ namespace Bussiness.Model.Production
         [Description("所需物料是否充足  1-充足 0-缺料")]
         public int? need_icitem_status { get; set; }
 
+        /// <summary>
+        /// 计算ID
+        /// </summary>
+        [Description("计算id")]
+        [NotMapped]
+        public long? bang_id { get; set; }
     }
 }

+ 7 - 0
MicroServices/Business/Bussiness.Model/SRM/srm_pr_main.cs

@@ -3,6 +3,7 @@ using Business.Model;
 using Microsoft.EntityFrameworkCore;
 using System.ComponentModel;
 using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
 
 namespace Bussiness.Model.SRM
 {
@@ -210,5 +211,11 @@ namespace Bussiness.Model.SRM
         [Description("拒绝原因")]
         public string? pr_rreason { get; set; }
 
+        /// <summary>
+        /// 计算ID
+        /// </summary>
+        [Description("计算id")]
+        [NotMapped]
+        public long? bang_id { get; set; }
     }
 }