Murphy 2 лет назад
Родитель
Сommit
de0d8c9f43

+ 9 - 6
MicroServices/Business/Business.Application/Business.Application.csproj

@@ -9,6 +9,15 @@
     <RepositoryType>git</RepositoryType>
   </PropertyGroup>
 
+  <ItemGroup>
+    <Compile Remove="MES\**" />
+    <Compile Remove="QMS\**" />
+    <EmbeddedResource Remove="MES\**" />
+    <EmbeddedResource Remove="QMS\**" />
+    <None Remove="MES\**" />
+    <None Remove="QMS\**" />
+  </ItemGroup>
+
   <ItemGroup>
     <PackageReference Include="Magicodes.IE.Pdf" Version="2.7.1" />
     <PackageReference Include="NLog" Version="5.1.2" />
@@ -26,13 +35,7 @@
     <ProjectReference Include="..\Business.Domain\Business.Domain.csproj" />
     <ProjectReference Include="..\Business.EntityFrameworkCore\Business.EntityFrameworkCore.csproj" />
     <ProjectReference Include="..\Bussiness.Model\Business.Model.csproj" />
-    <ProjectReference Include="..\Bussiness.Model\Bussiness.Model.csproj" />
     <ProjectReference Include="..\Bussiness.MongoModel\Business.MongoModel.csproj" />
   </ItemGroup>
 
-  <ItemGroup>
-    <Folder Include="MES\" />
-    <Folder Include="QMS\" />
-  </ItemGroup>
-
 </Project>

+ 268 - 2
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -28,6 +28,9 @@ using Volo.Abp.DependencyInjection;
 using Volo.Abp.Domain.Repositories;
 using Volo.Abp.MultiTenancy;
 using Z.EntityFramework.Plus;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.ComponentModel.DataAnnotations;
+using Spire.Pdf.General.Render.Decode.Jpeg2000.j2k.wavelet.synthesis;
 
 namespace Business.ResourceExamineManagement
 {
@@ -131,6 +134,12 @@ namespace Business.ResourceExamineManagement
         private readonly IMongoDB<mo_srm_po_occupy> _srm_po_occupy;
         private IRepository<srm_po_occupy, long> _mysql_srm_po_occupy;
 
+        /// <summary>
+        /// 供应商
+        /// </summary>
+        private readonly IMongoDB<mo_srm_supplier> _srm_supplier;
+        private IRepository<srm_supplier, long> _mysql_srm_supplier;
+
         /// <summary>
         /// 委外工单
         /// </summary>
@@ -266,6 +275,7 @@ namespace Business.ResourceExamineManagement
             IMongoDB<mo_mes_moentry> mes_moentry,
             IMongoDB<mo_mes_mooccupy> mes_mooccupy,
             IMongoDB<mo_ic_item_stockoccupy> ic_item_stockoccupy,
+            IMongoDB<mo_srm_supplier> srm_supplier,
             IRepository<ic_item, long> mysql_ic_item,
             IRepository<ic_bom, long> mysql_ic_bom,
             IRepository<ic_bom_child, long> mysql_ic_bom_child,
@@ -294,6 +304,7 @@ namespace Business.ResourceExamineManagement
             IRepository<b_purchase, long> mysql_purchase,
             IRepository<b_purchase_occupy, long> mysql_purchase_occupy,
             IRepository<b_bom_pretreatment, long> mysql_b_bom_pretreatment,
+            IRepository<srm_supplier, long> mysql_srm_supplier,
             ISqlRepository<TagMaster> tagMasterRepository,
             PretreatmentAppService pretreatmentAppService,
             CalcBomViewAppService calcbomviewAppService,
@@ -328,6 +339,7 @@ namespace Business.ResourceExamineManagement
             _mes_moentry = mes_moentry;
             _mes_mooccupy = mes_mooccupy;
             _ic_item_stockoccupy = ic_item_stockoccupy;
+            _srm_supplier= srm_supplier;
             _mysql_ic_item = mysql_ic_item;
             _mysql_ic_bom = mysql_ic_bom;
             _mysql_ic_bom_child = mysql_ic_bom_child;
@@ -353,6 +365,7 @@ namespace Business.ResourceExamineManagement
             _mysql_purchase = mysql_purchase;
             _mysql_purchase_occupy = mysql_purchase_occupy;
             _mysql_b_bom_pretreatment = mysql_b_bom_pretreatment;
+            _mysql_srm_supplier= mysql_srm_supplier;
             _tagMasterRepository = tagMasterRepository;
             _pretreatmentAppService = pretreatmentAppService;
             _CalcBomViewAppService = calcbomviewAppService;
@@ -558,7 +571,7 @@ namespace Business.ResourceExamineManagement
             }
             if (_CalcBomViewAppService.SRMPRDtoList.Any())
             {
-                var prlist = _CalcBomViewAppService.SRMPRDtoList.Where(f => f.srm_Pr_Main != null).Select(s => s.srm_Pr_Main).ToList();
+                List<List<mo_srm_pr_main>> prlist = _CalcBomViewAppService.SRMPRDtoList.Where(f => f.srm_Pr_Main != null).Select(s => s.srm_Pr_Main).ToList();
                 List<mo_srm_pr_main> list = new List<mo_srm_pr_main>();
                 foreach (var pr in prlist)
                 {
@@ -1216,7 +1229,7 @@ namespace Business.ResourceExamineManagement
             }
 
             srm_Pr.GenerateNewId();
-            srm_Pr.pr_billno = getOrderNum("PR");//pr单号
+            srm_Pr.pr_billno = returnlist.erp_cls==2?getOrderNum("WWPR"): getOrderNum("PR");//pr单号
             srm_Pr.pr_mono = "";//关联工单号
             srm_Pr.entity_id = 1;//工单行号
             srm_Pr.pr_purchaseid = supplier.supplier_id;//供应商id  
@@ -1267,6 +1280,259 @@ namespace Business.ResourceExamineManagement
             return new_orderNum;
         }
 
+        /// <summary>
+        /// 同一周以周五为合并采购申请单截点判断是否为同一周
+        /// </summary>
+        /// <param name="orderTime1">基准订单时间</param>
+        /// <param name="orderTime2">目标订单时间</param>
+        /// <returns></returns>
+        private bool IsSameWeek(DateTime orderTime1,DateTime orderTime2)
+        {
+            int week = (int)orderTime1.DayOfWeek;
+            bool isSameWeek = false;
+            DateTime? dateTime = orderTime1;
+            switch (week)
+            {
+                case 0:
+                    //星期天
+                    dateTime = new DateTime(orderTime1.AddDays(0).Year, orderTime1.AddDays(0).Month, orderTime1.AddDays(0).Day, 23, 59, 59);
+                    isSameWeek = orderTime2 <dateTime;
+                    break;
+                case 1:
+                    //星期一
+                    dateTime = new DateTime(orderTime1.AddDays(4).Year, orderTime1.AddDays(0).Month, orderTime1.AddDays(0).Day, 23, 59, 59);
+                    isSameWeek = orderTime2 < dateTime;
+                    break;
+                case 2:
+                    //星期二
+                    dateTime = new DateTime(orderTime1.AddDays(3).Year, orderTime1.AddDays(0).Month, orderTime1.AddDays(0).Day, 23, 59, 59);
+                    isSameWeek = orderTime2 < dateTime;
+                    break;
+                case 3:
+                    //星期三
+                    dateTime = new DateTime(orderTime1.AddDays(2).Year, orderTime1.AddDays(0).Month, orderTime1.AddDays(0).Day, 23, 59, 59);
+                    isSameWeek = orderTime2 < dateTime;
+                    break;
+                case 4:
+                    //星期四
+                    dateTime = new DateTime(orderTime1.AddDays(1).Year, orderTime1.AddDays(0).Month, orderTime1.AddDays(0).Day, 23, 59, 59);
+                    isSameWeek = orderTime2 < dateTime;
+                    break;
+                case 5:
+                    //星期五
+                    dateTime = new DateTime(orderTime1.AddDays(0).Year, orderTime1.AddDays(0).Month, orderTime1.AddDays(0).Day, 23, 59, 59);
+                    isSameWeek = orderTime2 < dateTime;
+                    break;
+                case 6:
+                    //星期六
+                    dateTime = new DateTime(orderTime1.AddDays(0).Year, orderTime1.AddDays(0).Month, orderTime1.AddDays(0).Day, 23, 59, 59);
+                    isSameWeek = orderTime2 < dateTime;
+                    break;
+            }
+            return isSameWeek;
+        }
+
+        private void AutoCreatePOFromPR(List<mo_srm_pr_main> list,long bangid, ResourceCheckInputDto input)
+        {
+            List<mo_srm_po_main> polist = new List<mo_srm_po_main>();
+            List<mo_srm_po_list> podetaillist = new List<mo_srm_po_list>();
+            //将PR按供应商和物料和日期(一周内)进行合并,生成PO
+            //1.按照供应商、需求日期排序
+            //2.判断是不是同一个供应商,不是的话就新建一个PO;是的话判断是不是同一周,不是的话就新建一个PO,是的话判断有没有相同物料,有的话合并物料数量价格,没有的话新建一条明细
+            list = list.OrderBy(a => a.pr_purchaseid).ThenBy(b => b.pr_rarrive_date).ToList();
+            long? supplierId = -1;
+            DateTime supplierDate = DateTime.Now;
+            foreach (var item in list)
+            {
+                if (item.pr_purchaseid != supplierId)
+                {
+                    var itemsupplier = _srm_supplier.Find(a => a.mysql_id == item.pr_purchaseid && a.tenant_id == input.tenantId && a.factory_id == input.factoryId).Result;
+                    //新建一个PO
+                    mo_srm_po_main po_Main = new mo_srm_po_main();
+                    po_Main.GenerateNewId();
+                    po_Main.po_billno = getOrderNum("PO");
+                    po_Main.po_purchaser = item.pr_purchaser;
+                    po_Main.po_purchaser_no = item.pr_purchaser_num;
+                    po_Main.po_ssend_date = DateTime.Now;
+                    po_Main.po_total = item.pr_orderprice;
+                    po_Main.po_tax_rate = item.pr_rate;
+                    po_Main.po_express = 1;
+                    po_Main.state = 0;
+                    po_Main.po_note = "PR自动转PO";
+                    po_Main.po_order_type = 1;
+                    po_Main.currency = item.currencytype;
+                    po_Main.bill_type = 1;
+                    po_Main.supplier_id = item.pr_purchaseid;
+                    po_Main.supplier_name = item.pr_purchasename;
+                    po_Main.supplier_no = item.pr_purchasenumber;
+                    po_Main.contact = itemsupplier?.FirstOrDefault().contact;
+                    po_Main.suppliertelephone = itemsupplier?.FirstOrDefault().telephone;
+                    po_Main.deliveryaddress = "";
+                    po_Main.supplierdddress = itemsupplier?.FirstOrDefault().supplier_address;
+                    po_Main.confirmstate = 1;
+                    po_Main.logisticsstate = 0;
+                    po_Main.financialstate = 0;
+                    po_Main.create_time = DateTime.Now;
+                    po_Main.factory_id = input.factoryId;
+                    po_Main.tenant_id = input.tenantId;
+                    po_Main.bang_id = bangid;
+                    polist.Add(po_Main);
+
+                    mo_srm_po_list podetail = new mo_srm_po_list();
+                    podetail.GenerateNewId();
+                    podetail.po_id = po_Main.mysql_id;
+                    podetail.po_billno = po_Main.po_billno;
+                    podetail.polist_row = podetaillist.Count + 1;
+                    podetail.pr_id = item.mysql_id;
+                    podetail.pr_billno = item.pr_billno;
+                    podetail.pr_purchase_id = po_Main.supplier_id;
+                    podetail.pr_purchase_name = po_Main.supplier_name;
+                    podetail.icitem_id = item.icitem_id;
+                    podetail.icitem_name = item.icitem_name;
+                    podetail.qty = item.pr_aqty;
+                    podetail.netprice = item.pr_price;
+                    podetail.rate = item.pr_rate;
+                    podetail.price = item.pr_orderprice / item.pr_aqty;
+                    podetail.total_price = item.pr_orderprice;
+                    podetail.plan_qty = item.pr_aqty;
+                    podetail.unit = item.pr_unit;
+                    podetail.state = item.state;
+                    podetail.rarrdate = item.pr_rarrive_date;
+                    podetail.currencytype = item.currencytype;
+                    podetail.create_time = DateTime.Now;
+                    podetail.factory_id = input.factoryId;
+                    podetail.tenant_id = input.tenantId;
+                    podetail.bang_id = bangid;
+                    podetaillist.Add(podetail);
+
+                    supplierId = item.pr_purchaseid;
+                    supplierDate = item.pr_rarrive_date.Value;
+                }
+                else
+                {
+                    //同一个供应商先判断需求日期是否在同一周
+                    if (IsSameWeek(supplierDate, item.pr_rarrive_date.Value))
+                    {
+                        var pomain = polist.FindAll(x => x.supplier_id == item.pr_purchaseid).OrderByDescending(b => b.create_time).First();
+                        List<mo_srm_po_list> detail = podetaillist.FindAll(a => a.po_billno == pomain.po_billno && a.icitem_id == item.icitem_id);
+                        if (detail.Count > 0)
+                        {
+                            //TODO:只能记录一条PR,可能需要先合PR
+                            //存在同一种物料,存在就计算数量和价格,
+                            detail[0].qty = detail[0].qty + item.pr_aqty;
+                            detail[0].netprice = detail[0].netprice + item.pr_price;
+                            detail[0].price = detail[0].qty + item.pr_aqty;
+                            detail[0].total_price = detail[0].total_price + item.pr_orderprice;
+                            detail[0].plan_qty = detail[0].plan_qty + item.pr_aqty;
+                            detail[0].rarrdate = item.pr_rarrive_date;
+                        }
+                        else
+                        {
+                            //不存在同一种物料新增一条明细
+                            mo_srm_po_list podetail = new mo_srm_po_list();
+                            podetail.GenerateNewId();
+                            podetail.po_id = pomain.mysql_id;
+                            podetail.po_billno = pomain.po_billno;
+                            podetail.polist_row = podetaillist.Count + 1;
+                            podetail.pr_id = item.mysql_id;
+                            podetail.pr_billno = item.pr_billno;
+                            podetail.pr_purchase_id = pomain.supplier_id;
+                            podetail.pr_purchase_name = pomain.supplier_name;
+                            podetail.icitem_id = item.icitem_id;
+                            podetail.icitem_name = item.icitem_name;
+                            podetail.qty = item.pr_aqty;
+                            podetail.netprice = item.pr_price;
+                            podetail.rate = item.pr_rate;
+                            podetail.price = item.pr_orderprice / item.pr_aqty;
+                            podetail.total_price = item.pr_orderprice;
+                            podetail.plan_qty = item.pr_aqty;
+                            podetail.unit = item.pr_unit;
+                            podetail.state = item.state;
+                            podetail.rarrdate = item.pr_rarrive_date;
+                            podetail.currencytype = item.currencytype;
+                            podetail.create_time = DateTime.Now;
+                            podetail.factory_id = input.factoryId;
+                            podetail.tenant_id = input.tenantId;
+                            podetail.bang_id = bangid;
+                            podetaillist.Add(podetail);
+                        }
+
+                    }
+                    else
+                    {
+                        //不在同一周需要新建一张PO
+                        var itemsupplier = _srm_supplier.Find(a => a.mysql_id == item.pr_purchaseid && a.tenant_id == input.tenantId && a.factory_id == input.factoryId).Result;
+                        //新建一个PO单
+                        mo_srm_po_main po_Main = new mo_srm_po_main();
+                        po_Main.GenerateNewId();
+                        po_Main.po_billno = getOrderNum("PO");
+                        po_Main.po_purchaser = item.pr_purchaser;
+                        po_Main.po_purchaser_no = item.pr_purchaser_num;
+                        po_Main.po_ssend_date = DateTime.Now;
+                        po_Main.po_total = item.pr_orderprice;
+                        po_Main.po_tax_rate = item.pr_rate;
+                        po_Main.po_express = 1;
+                        po_Main.state = 0;
+                        po_Main.po_note = "PR自动转PO";
+                        po_Main.po_order_type = 1;
+                        po_Main.currency = item.currencytype;
+                        po_Main.bill_type = 1;
+                        po_Main.supplier_id = item.pr_purchaseid;
+                        po_Main.supplier_name = item.pr_purchasename;
+                        po_Main.supplier_no = item.pr_purchasenumber;
+                        po_Main.contact = itemsupplier?.FirstOrDefault().contact;
+                        po_Main.suppliertelephone = itemsupplier?.FirstOrDefault().telephone;
+                        po_Main.deliveryaddress = "";
+                        po_Main.supplierdddress = itemsupplier?.FirstOrDefault().supplier_address;
+                        po_Main.confirmstate = 1;
+                        po_Main.logisticsstate = 0;
+                        po_Main.financialstate = 0;
+                        po_Main.create_time = DateTime.Now;
+                        po_Main.factory_id = input.factoryId;
+                        po_Main.tenant_id = input.tenantId;
+                        po_Main.bang_id = bangid;
+                        polist.Add(po_Main);
+
+                        mo_srm_po_list podetail = new mo_srm_po_list();
+                        podetail.GenerateNewId();
+                        podetail.po_id = po_Main.mysql_id;
+                        podetail.po_billno = po_Main.po_billno;
+                        podetail.polist_row = podetaillist.Count + 1;
+                        podetail.pr_id = item.mysql_id;
+                        podetail.pr_billno = item.pr_billno;
+                        podetail.pr_purchase_id = po_Main.supplier_id;
+                        podetail.pr_purchase_name = po_Main.supplier_name;
+                        podetail.icitem_id = item.icitem_id;
+                        podetail.icitem_name = item.icitem_name;
+                        podetail.qty = item.pr_aqty;
+                        podetail.netprice = item.pr_price;
+                        podetail.rate = item.pr_rate;
+                        podetail.price = item.pr_orderprice / item.pr_aqty;
+                        podetail.total_price = item.pr_orderprice;
+                        podetail.plan_qty = item.pr_aqty;
+                        podetail.unit = item.pr_unit;
+                        podetail.state = item.state;
+                        podetail.rarrdate = item.pr_rarrive_date;
+                        podetail.currencytype = item.currencytype;
+                        podetail.create_time = DateTime.Now;
+                        podetail.factory_id = input.factoryId;
+                        podetail.tenant_id = input.tenantId;
+                        podetail.bang_id = bangid;
+                        podetaillist.Add(podetail);
+
+                        supplierId = item.pr_purchaseid;
+                        supplierDate = item.pr_rarrive_date.Value;
+                    }
+                }
+            }
+             _srm_po_main.InsertMany(polist);
+             _srm_po_list.InsertMany(podetaillist);
+            var po_mainlist = ObjectMapper.Map<List<mo_srm_po_main>, List<srm_po_main>>(polist);
+             _businessDbContext.srm_po_main.BulkInsertAsync(po_mainlist, options => options.InsertKeepIdentity = true);
+            var po_listlist = ObjectMapper.Map<List<mo_srm_po_list>, List<srm_po_list>>(podetaillist);
+             _businessDbContext.srm_po_list.BulkInsertAsync(po_listlist, options => options.InsertKeepIdentity = true);
+        }
+
         /// <summary>
         /// 工单齐套检查
         /// </summary>

+ 0 - 51
MicroServices/Business/Business.Application/Test/TestAppService.cs

@@ -1,51 +0,0 @@
-using BaseService.Systems.UserMenusManagement;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Volo.Abp.Application.Services;
-using Volo.Abp.Identity;
-
-namespace Business.Test
-{
-    /// <summary>
-    /// 内部网关接口示例
-    /// </summary>
-    public class TestAppService : ApplicationService, ITestAppService
-    {
-        private readonly IIdentityUserLookupAppService _identityUserLookupAppService;
-        private readonly IRoleMenusAppService _roleMenusAppService;
-
-        public TestAppService(
-            IIdentityUserLookupAppService identityUserLookupAppService,
-            IRoleMenusAppService roleMenusAppService
-            )
-        {
-            _identityUserLookupAppService = identityUserLookupAppService;
-            _roleMenusAppService = roleMenusAppService;
-        }
-
-        public async Task<string> TestApi(string name)
-        {
-            var arr = name.Split('.');
-
-            return "010101";
-        }
-
-        /// <summary>
-        /// 内部网关-用户数量
-        /// </summary>
-        /// <returns></returns>
-        public async Task<long> GetUserCount()
-        {
-            return await _identityUserLookupAppService.GetCountAsync(new UserLookupCountInputDto { Filter = null });
-        }
-
-        ///// <summary>
-        ///// 内部网关-菜单树形
-        ///// </summary>
-        ///// <returns></returns>
-        //public async Task<dynamic> GetMenuTree()
-        //{
-        //    return await _roleMenusAppService.GetMenusList();
-        //}
-    }
-}

+ 0 - 12
MicroServices/Business/Bussiness.Model/SRM/srm_po_main.cs

@@ -31,18 +31,6 @@ namespace Business.Model.SRM
         [Comment("采购员工号")]
         public string? po_purchaser_no { get; set; }
         /// <summary>
-        /// 供应商id
-        /// </summary>
-        [Required]
-        [Comment("供应商id")]
-        public long? po_purchase_id { get; set; }
-        /// <summary>
-        /// 供应商名称
-        /// </summary>
-        [StringLength(80)]
-        [Comment("供应商名称")]
-        public string? po_purchase_name { get; set; }
-        /// <summary>
         /// 下单日期
         /// </summary>
         [Comment("下单日期")]

+ 1 - 12
MicroServices/Business/Bussiness.MongoModel/SRM/mo_srm_po_main.cs

@@ -32,18 +32,7 @@ namespace Business.MongoModel.SRM
         [StringLength(80)]
         [Comment("采购员工号")]
         public string? po_purchaser_no { get; set; }
-        /// <summary>
-        /// 供应商id
-        /// </summary>
-        [Required]
-        [Comment("供应商id")]
-        public long? po_purchase_id { get; set; }
-        /// <summary>
-        /// 供应商名称
-        /// </summary>
-        [StringLength(80)]
-        [Comment("供应商名称")]
-        public string? po_purchase_name { get; set; }
+
         /// <summary>
         /// 下单日期
         /// </summary>