From a27f32ecbfc7390ceb9e3a8d8651c57ada88bfa0 Mon Sep 17 00:00:00 2001
From: zjh <2207896513@qq.com>
Date: 星期五, 19 十二月 2025 20:51:42 +0800
Subject: [PATCH] Merge branch 'master' of http://43.142.96.171:8080/r/~tjx/XB_MES_API

---
 StandardPda/MES.Service/service/Warehouse/MesItemQtManager.cs |  760 ++++++++++++++++++++++++++++-----------------------------
 1 files changed, 374 insertions(+), 386 deletions(-)

diff --git a/StandardPda/MES.Service/service/Warehouse/MesItemQtManager.cs b/StandardPda/MES.Service/service/Warehouse/MesItemQtManager.cs
index 2fefcf4..e6ed684 100644
--- a/StandardPda/MES.Service/service/Warehouse/MesItemQtManager.cs
+++ b/StandardPda/MES.Service/service/Warehouse/MesItemQtManager.cs
@@ -1,428 +1,416 @@
 锘縰sing MES.Service.DB;
 using MES.Service.Dto.service;
 using MES.Service.Modes;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
-namespace MES.Service.service.Warehouse
+namespace MES.Service.service.Warehouse;
+
+public class MesItemQtManager : Repository<MesItemQt>
 {
-    public class MesItemQtManager:Repository<MesItemQt>
+    public bool MiscellaneousIssues(MesItemQtDto mesItemQtDto)
     {
-        public bool MiscellaneousIssues(MesItemQtDto mesItemQtDto)
+        var itemQtFrom = mesItemQtDto.from;
+        var itemQtLists = mesItemQtDto.items;
+
+        // 鏍规嵁AsnNo鍜孧esNo瀵规槑缁嗚繘琛屽垎缁�
+        //var groupedItems = itemOutLists
+        //    .GroupBy(item => new { item.AsnNo, item.MesNo, item.SqNo })
+        //    .ToList();
+
+        var result = true;
+        //foreach (var group in itemQtRKLists)
+        //{
+        //if (group.Key.AsnNo == null)
+        //{
+        //    throw new NotImplementedException("AsnNo涓嶈兘涓虹┖");
+        //}
+
+        //if (group.Key.MesNo == null)
+        //{
+        //    throw new NotImplementedException("鍏ュ簱鍗曞崟鍙蜂笉鑳戒负绌�");
+        //}
+
+        //if (group.Key.SqNo == null)
+        //{
+        //    throw new NotImplementedException("閫�璐х敵璇峰崟琛屽彿涓嶈兘涓虹┖");
+        //}
+
+        // 鍒涘缓涓�涓复鏃剁殑itemOutFrom瀵硅薄锛屼娇鐢ㄥ垎缁勭殑Key浣滀负涓昏灞炴��
+        //var tempItemOutFrom = new ItemOutFrom
+        //{
+        //    AsnNo = group.Key.AsnNo,
+        //    MesNo = group.Key.MesNo,
+        //    SqNo = group.Key.SqNo,
+        //    // 缁ф壙鍘熷itemOutFrom鐨勫叾浠栧睘鎬�
+        //    RtnNo = itemOutFrom.RtnNo,
+        //    Type = itemOutFrom.Type,
+        //    CreateBy = itemOutFrom.CreateBy,
+        //    FMRMODE = itemOutFrom.FMRMODE,
+        //    DepotId = itemOutFrom.DepotId,
+        //    SupperId = itemOutFrom.SupperId
+        //};
+
+        // 鏍规嵁Type鎵ц涓嶅悓鐨勯�昏緫
+        switch (itemQtFrom.Type)
         {
-            var itemQtFrom = mesItemQtDto.from;
-            var itemQtLists = mesItemQtDto.items;
-
-            // 鏍规嵁AsnNo鍜孧esNo瀵规槑缁嗚繘琛屽垎缁�
-            //var groupedItems = itemOutLists
-            //    .GroupBy(item => new { item.AsnNo, item.MesNo, item.SqNo })
-            //    .ToList();
-
-            bool result = true;
-            //foreach (var group in itemQtRKLists)
-            //{
-            //if (group.Key.AsnNo == null)
-            //{
-            //    throw new NotImplementedException("AsnNo涓嶈兘涓虹┖");
-            //}
-
-            //if (group.Key.MesNo == null)
-            //{
-            //    throw new NotImplementedException("鍏ュ簱鍗曞崟鍙蜂笉鑳戒负绌�");
-            //}
-
-            //if (group.Key.SqNo == null)
-            //{
-            //    throw new NotImplementedException("閫�璐х敵璇峰崟琛屽彿涓嶈兘涓虹┖");
-            //}
-
-            // 鍒涘缓涓�涓复鏃剁殑itemOutFrom瀵硅薄锛屼娇鐢ㄥ垎缁勭殑Key浣滀负涓昏灞炴��
-            //var tempItemOutFrom = new ItemOutFrom
-            //{
-            //    AsnNo = group.Key.AsnNo,
-            //    MesNo = group.Key.MesNo,
-            //    SqNo = group.Key.SqNo,
-            //    // 缁ф壙鍘熷itemOutFrom鐨勫叾浠栧睘鎬�
-            //    RtnNo = itemOutFrom.RtnNo,
-            //    Type = itemOutFrom.Type,
-            //    CreateBy = itemOutFrom.CreateBy,
-            //    FMRMODE = itemOutFrom.FMRMODE,
-            //    DepotId = itemOutFrom.DepotId,
-            //    SupperId = itemOutFrom.SupperId
-            //};
-
-            // 鏍规嵁Type鎵ц涓嶅悓鐨勯�昏緫
-            switch (itemQtFrom.Type)
+            case "1":
             {
-                case "1":
-                    {
-                        var mesInvItemOuts = Db.Queryable<MesItemQt>()
-                            .Where(s => s.Qtck == itemQtFrom.ApplyNumber
+                var mesInvItemOuts = Db.Queryable<MesItemQt>()
+                    .Where(s => s.Qtck == itemQtFrom.ApplyNumber
+                    )
+                    .Count();
 
-                            )
-                            .Count();
+                if (mesInvItemOuts > 0)
+                    throw new NotImplementedException(
+                        itemQtFrom.ApplyNumber +
+                        "鐨勬潅鍙戠敵璇峰崟宸茬粡瀛樺湪");
 
-                        if (mesInvItemOuts > 0)
-                        {
-                            throw new NotImplementedException(
-                                itemQtFrom.ApplyNumber +
-                                "鐨勬潅鍙戠敵璇峰崟宸茬粡瀛樺湪");
-                        }
+                // 涓哄綋鍓嶅垎缁勪繚瀛樻暟鎹�
+                var groupResult = Save(itemQtFrom, itemQtLists);
+                if (!groupResult) result = false;
 
-                        // 涓哄綋鍓嶅垎缁勪繚瀛樻暟鎹�
-                        var groupResult = Save(itemQtFrom, itemQtLists);
-                        if (!groupResult)
-                        {
-                            result = false;
-                        }
-
-                        break;
-                    }
-                case "4":
-                    var removeResult = Remove(itemQtFrom);
-                    if (!removeResult)
-                    {
-                        result = false;
-                    }
-
-                    break;
-                default:
-                    result = false;
-                    break;
+                break;
             }
-            //}
+            case "4":
+                var removeResult = Remove(itemQtFrom);
+                if (!removeResult) result = false;
 
-            return result;
+                break;
+            default:
+                result = false;
+                break;
+        }
+        //}
+
+        return result;
+    }
+
+
+    private bool Save(MesItemQtFrom from, List<MesItemQtList> items)
+    {
+        //var mesInvItemIns = Db.Queryable<MesInvItemIns>()
+        //    .Where(s => s.BillTypeId == 100
+        //                && s.TransctionNo == "101"
+        //                && s.BillNo == from.MesNo
+        //    ).First();
+
+        //if (mesInvItemIns == null)
+        //{
+        //    throw new NotImplementedException("閲囪喘鍏ュ簱涓嶅瓨鍦�");
+        //}
+
+
+        var SuppNo = "";
+        if (from.SupplierCode != "" && from.SupplierCode != null)
+        {
+            var mesLinkU9 = Db.Queryable<MesLinkU9>()
+                .Where(s => s.TableType == "MES_SUPPLIER"
+                            && s.U9Id == from.SupplierCode).First();
+
+            if (mesLinkU9 == null)
+                throw new NotImplementedException("渚涘簲鍟咺D涓嶅瓨鍦ㄦ垨鏈悓姝ヤ簬U9");
+
+            var mesSupplier = Db.Queryable<MesSupplier>()
+                .Where(s => s.Id == decimal.Parse(mesLinkU9.MesId))
+                .First();
+            if (mesSupplier == null)
+                throw new NotImplementedException("[" + from.SupplierCode +
+                                                  "]渚涘簲鍟嗕笉瀛樺湪锛岃鍚屾缁橫ES");
+            SuppNo = mesSupplier.SuppNo;
         }
 
+        var mesDepots = Db.Queryable<MesDepots>()
+            .Where(s => s.DepotId == decimal.Parse(from.FromWarehouse)).First();
 
-        private bool Save(MesItemQtFrom from, List<MesItemQtList> items)
+        if (mesDepots == null)
+            throw new NotImplementedException("[" + from.FromWarehouse +
+                                              "]浠撳簱涓嶅瓨鍦紝璇峰悓姝ョ粰MES");
+
+        var sysDepartment = Db.Queryable<SysDepartment>()
+            .Where(s => s.Departmentid == decimal.Parse(from.ApplyDept))
+            .First();
+
+        if (sysDepartment == null)
+            throw new NotImplementedException("[" + from.ApplyDept +
+                                              "]閮ㄩ棬涓嶅瓨鍦紝璇峰悓姝ョ粰MES");
+
+
+        var nextSequenceValue =
+            Db.Ado.SqlQuery<decimal>("SELECT SEQ_QTCK.NEXTVAL FROM DUAL")
+                .First();
+
+        // var billCode =
+        //     Db.Ado.SqlQuery<string>(
+        //             "SELECT GETBILLCODE1('1000', '1000', 'TLSQ') FROM DUAL")
+        //         .First();
+        //var billCode = from.RtnNo;
+
+        // 鍒涘缓鏉傚彂鐢宠鍗曡褰�
+        var MesItemQtrk = new MesItemQt
         {
-            //var mesInvItemIns = Db.Queryable<MesInvItemIns>()
-            //    .Where(s => s.BillTypeId == 100
-            //                && s.TransctionNo == "101"
-            //                && s.BillNo == from.MesNo
-            //    ).First();
+            Id = nextSequenceValue,
+            Qtck = from.ApplyNumber,
+            Qt001 = from.Equals(null) ? DateTime.Now : from.ApplyDate,
+            Qt002 = from.Equals(null) ? DateTime.Now : from.AuditDate,
+            Qt003 = from.DocumentType,
+            Qt004 = from.StockOutType,
+            Qt005 = from.CreatedBy,
+            Qt006 = from.WorkOrder,
+            Qt009 = sysDepartment.Departmentname,
+            Qt012 = sysDepartment.Departmentcode,
+            Qt010 = from.Reason,
+            Qt011 = mesDepots.DepotCode,
+            Qt008 = mesDepots.DepotName,
 
-            //if (mesInvItemIns == null)
+            Qt015 = 1,
+            Qt016 = from.Auditor,
+            Qt017 = from.TaskNumber,
+            Qt018 = SuppNo,
+            Qt019 = from.Direction,
+            Qt020 = from.OwnerType,
+            CustomerCode = from.CustomerCode,
+            Receiver = from.Receiver,
+            Department = from.Department,
+            StockKeeper = from.StockKeeper,
+            SourceType = from.SourceType,
+            SourceDocument = from.SourceDocument,
+            ProductionRelated = from.ProductionRelated,
+            ProductionLine = from.ProductionLine,
+            ProductionActivity = from.ProductionActivity,
+            FinishedGoods = from.FinishedGoods,
+            ReversePosting = from.ReversePosting,
+            AccountingPeriod = from.AccountingPeriod,
+            Employee = from.Employee,
+            FalseReturn = from.FalseReturn,
+            ProjectCode = from.ProjectCode,
+            TaskCode = from.TaskCode,
+            Status = from.Status,
+            OwnerOrganization = from.OwnerOrganization
+        };
+
+        // 鍒涘缓鏉傚彂鐢宠鍗曡璁板綍
+        var mesItemQtDetail = new List<MesItemQtDatall>();
+
+        foreach (var ItemQtRKList in items)
+        {
+            // 妫�鏌ュ繀瑕佸瓧娈垫槸鍚︿负绌�
+            //if (string.IsNullOrEmpty(itemOutList.SrcDocNo))
             //{
-            //    throw new NotImplementedException("閲囪喘鍏ュ簱涓嶅瓨鍦�");
+            //    throw new NotImplementedException("閲囪喘璁㈠崟鍙蜂笉鑳戒负绌�");
             //}
 
 
-            string SuppNo = "";
-            if (from.SupplierCode != "" && from.SupplierCode != null)
+            //var mesRohInData = Db.Queryable<MesRohInData>()
+            //    .Where(s => s.BillNo == itemOutList.SrcDocNo
+            //                && s.OrderLineId == itemOutList.SrcDocLineNo)
+            //    .First();
+
+            //if (mesRohInData == null)
+            //{
+            //    throw new NotImplementedException("閲囪喘璁㈠崟涓嶅瓨鍦�");
+            //}
+
+            //var deliveryDetail = Db.Queryable<DeliveryDetail>()
+            //    .Where(a => a.Zzasn == from.AsnNo
+            //                && Int32.Parse(a.ZzitemId) ==
+            //                Int32.Parse(itemOutList.AsnLineNo))
+            //    .Count();
+
+            //if (deliveryDetail <= 0)
+            //{
+            //    throw new NotImplementedException("[" + from.AsnNo + "]鐨勬槑缁嗚[" +
+            //                                      itemOutList.AsnLineNo +
+            //                                      "]涓嶅瓨鍦�");
+            //}
+
+            var itemIdLinkU9 = Db.Queryable<MesLinkU9>()
+                .Where(s => s.TableType == "MES_ITEMS"
+                            && s.U9Id == ItemQtRKList.ItemId).First();
+
+            if (itemIdLinkU9 == null)
+                throw new NotImplementedException("鐗╂枡ID涓嶅瓨鍦ㄦ垨鏈悓姝ヤ簬U9");
+
+            var mesItems = Db.Queryable<MesItems>()
+                .Where(s => s.Id == decimal.Parse(itemIdLinkU9.MesId))
+                .First();
+
+            if (mesItems == null)
+                throw new NotImplementedException("[" + ItemQtRKList.ItemId +
+                                                  "]鐗╂枡涓嶅瓨鍦紝璇峰悓姝ョ粰MES");
+            var mesDepot = "";
+            if (ItemQtRKList.StorageLocation != null &&
+                ItemQtRKList.StorageLocation != null)
+            {
+                mesDepots = Db.Queryable<MesDepots>()
+                    .Where(s =>
+                        s.DepotId ==
+                        decimal.Parse(ItemQtRKList.StorageLocation)).First();
+                if (mesDepots == null)
+                    throw new NotImplementedException("[" +
+                        ItemQtRKList.StorageLocation +
+                        "]浠撳簱涓嶅瓨鍦紝璇峰悓姝ョ粰MES");
+                mesDepot = mesDepots.DepotCode;
+            }
+
+            var supplierCode = "";
+            if (ItemQtRKList.SupplierCode != null &&
+                ItemQtRKList.SupplierCode != "")
             {
                 var mesLinkU9 = Db.Queryable<MesLinkU9>()
-              .Where(s => s.TableType == "MES_SUPPLIER"
-                          && s.U9Id == from.SupplierCode).First();
+                    .Where(s => s.TableType == "MES_SUPPLIER"
+                                && s.U9Id == ItemQtRKList.SupplierCode).First();
 
                 if (mesLinkU9 == null)
-                {
-                    throw new NotImplementedException("渚涘簲鍟咺D涓嶅瓨鍦ㄦ垨鏈悓姝ヤ簬U9");
-                }
-
+                    throw new NotImplementedException("[" +
+                        ItemQtRKList.SupplierCode +
+                        "]渚涘簲鍟嗕笉瀛樺湪锛岃鍚屾缁橫ES");
                 var mesSupplier = Db.Queryable<MesSupplier>()
-                    .Where(s => s.Id == Decimal.Parse(mesLinkU9.MesId))
+                    .Where(s => s.Id == decimal.Parse(mesLinkU9.MesId))
                     .First();
                 if (mesSupplier == null)
-                {
-                    throw new NotImplementedException("[" + from.SupplierCode +
-                                                      "]渚涘簲鍟嗕笉瀛樺湪锛岃鍚屾缁橫ES");
-                }
-                SuppNo = mesSupplier.SuppNo;
+                    throw new NotImplementedException("[" +
+                        ItemQtRKList.SupplierCode +
+                        "]渚涘簲鍟嗕笉瀛樺湪锛岃鍚屾缁橫ES");
+                supplierCode = mesSupplier.SuppNo;
             }
-            var mesDepots = Db.Queryable<MesDepots>()
-                .Where(s => s.DepotId == Decimal.Parse(from.FromWarehouse)).First();
 
-            if (mesDepots == null)
+
+            var mesUnit = "";
+            if (mesItems.ItemUnit != null && mesItems.ItemUnit != "")
             {
-                throw new NotImplementedException("[" + from.FromWarehouse +
-                                                  "]浠撳簱涓嶅瓨鍦紝璇峰悓姝ョ粰MES");
-            }
-
-            var sysDepartment = Db.Queryable<SysDepartment>()
-              .Where(s => s.Departmentid == Decimal.Parse(from.ApplyDept)).First();
-
-            if (sysDepartment == null)
-            {
-                throw new NotImplementedException("[" + from.ApplyDept +
-                                                  "]閮ㄩ棬涓嶅瓨鍦紝璇峰悓姝ョ粰MES");
-            }
-
-
-            var nextSequenceValue =
-                Db.Ado.SqlQuery<decimal>("SELECT SEQ_QTCK.NEXTVAL FROM DUAL")
+                var mesUnitDb = Db.Queryable<MesUnit>()
+                    .Where(s => s.Id == decimal.Parse(mesItems.ItemUnit))
                     .First();
-
-            // var billCode =
-            //     Db.Ado.SqlQuery<string>(
-            //             "SELECT GETBILLCODE1('1000', '1000', 'TLSQ') FROM DUAL")
-            //         .First();
-            //var billCode = from.RtnNo;
-
-            // 鍒涘缓鏉傚彂鐢宠鍗曡褰�
-            var MesItemQtrk = new MesItemQt
-            {
-                Id = nextSequenceValue,
-                Qtck = from.ApplyNumber,
-                Qt001 = from.Equals(null) ? DateTime.Now : from.ApplyDate,
-                Qt002 = from.Equals(null) ? DateTime.Now : from.AuditDate,
-                Qt003 = from.DocumentType,
-                Qt004 = from.StockOutType,
-                Qt005 = from.CreatedBy,
-                Qt006 = from.WorkOrder,
-                Qt009 = sysDepartment.Departmentname,
-                Qt012 = sysDepartment.Departmentcode,
-                Qt010 = from.Reason,
-                Qt011 = mesDepots.DepotCode,
-                Qt008 = mesDepots.DepotName,
-
-                Qt015 = 1,
-                Qt016 = from.Auditor,
-                Qt017 = from.TaskNumber,
-                Qt018 = SuppNo,
-                Qt019 = from.Direction,
-                Qt020 = from.OwnerType,
-                CustomerCode = from.CustomerCode,
-                Receiver = from.Receiver,
-                Department = from.Department,
-                StockKeeper = from.StockKeeper,
-                SourceType = from.SourceType,
-                SourceDocument = from.SourceDocument,
-                ProductionRelated = from.ProductionRelated,
-                ProductionLine = from.ProductionLine,
-                ProductionActivity = from.ProductionActivity,
-                FinishedGoods = from.FinishedGoods,
-                ReversePosting = from.ReversePosting,
-                AccountingPeriod = from.AccountingPeriod,
-                Employee = from.Employee,
-                FalseReturn = from.FalseReturn,
-                ProjectCode = from.ProjectCode,
-                TaskCode = from.TaskCode,
-                Status = from.Status,
-                OwnerOrganization = from.OwnerOrganization
-
-
-            };
-
-            // 鍒涘缓鏉傚彂鐢宠鍗曡璁板綍
-            var mesItemQtDetail = new List<MesItemQtDatall>();
-
-            foreach (var ItemQtRKList in items)
-            {
-                // 妫�鏌ュ繀瑕佸瓧娈垫槸鍚︿负绌�
-                //if (string.IsNullOrEmpty(itemOutList.SrcDocNo))
-                //{
-                //    throw new NotImplementedException("閲囪喘璁㈠崟鍙蜂笉鑳戒负绌�");
-                //}
-
-
-
-                //var mesRohInData = Db.Queryable<MesRohInData>()
-                //    .Where(s => s.BillNo == itemOutList.SrcDocNo
-                //                && s.OrderLineId == itemOutList.SrcDocLineNo)
-                //    .First();
-
-                //if (mesRohInData == null)
-                //{
-                //    throw new NotImplementedException("閲囪喘璁㈠崟涓嶅瓨鍦�");
-                //}
-
-                //var deliveryDetail = Db.Queryable<DeliveryDetail>()
-                //    .Where(a => a.Zzasn == from.AsnNo
-                //                && Int32.Parse(a.ZzitemId) ==
-                //                Int32.Parse(itemOutList.AsnLineNo))
-                //    .Count();
-
-                //if (deliveryDetail <= 0)
-                //{
-                //    throw new NotImplementedException("[" + from.AsnNo + "]鐨勬槑缁嗚[" +
-                //                                      itemOutList.AsnLineNo +
-                //                                      "]涓嶅瓨鍦�");
-                //}
-
-                var itemIdLinkU9 = Db.Queryable<MesLinkU9>()
-                    .Where(s => s.TableType == "MES_ITEMS"
-                                && s.U9Id == ItemQtRKList.Itemld).First();
-
-                if (itemIdLinkU9 == null)
-                {
-                    throw new NotImplementedException("鐗╂枡ID涓嶅瓨鍦ㄦ垨鏈悓姝ヤ簬U9");
-                }
-
-                var mesItems = Db.Queryable<MesItems>()
-                    .Where(s => s.Id == Decimal.Parse(itemIdLinkU9.MesId))
-                    .First();
-
-                if (mesItems == null)
-                {
-                    throw new NotImplementedException("[" + ItemQtRKList.Itemld +
-                                                      "]鐗╂枡涓嶅瓨鍦紝璇峰悓姝ョ粰MES");
-                }
-                var mesDepot = "";
-                if (ItemQtRKList.StorageLocation != null && ItemQtRKList.StorageLocation != null)
-                {
-                    mesDepots = Db.Queryable<MesDepots>()
-                   .Where(s => s.DepotId == Decimal.Parse(ItemQtRKList.StorageLocation)).First();
-                    if (mesDepots == null)
-                    {
-                        throw new NotImplementedException("[" + ItemQtRKList.StorageLocation +
-                                                          "]浠撳簱涓嶅瓨鍦紝璇峰悓姝ョ粰MES");
-                    }
-                    mesDepot = mesDepots.DepotCode;
-                }
-                string supplierCode = "";
-                if (ItemQtRKList.SupplierCode != null && ItemQtRKList.SupplierCode != "")
-                {
-                    var mesLinkU9 = Db.Queryable<MesLinkU9>()
-   .Where(s => s.TableType == "MES_SUPPLIER"
-               && s.U9Id == ItemQtRKList.SupplierCode).First();
-
-                    if (mesLinkU9 == null)
-                    {
-                        throw new NotImplementedException("[" + ItemQtRKList.SupplierCode +
-                                                          "]渚涘簲鍟嗕笉瀛樺湪锛岃鍚屾缁橫ES");
-                    }
-                    var mesSupplier = Db.Queryable<MesSupplier>()
-        .Where(s => s.Id == Decimal.Parse(mesLinkU9.MesId))
-        .First();
-                    if (mesSupplier == null)
-                    {
-                        throw new NotImplementedException("[" + ItemQtRKList.SupplierCode +
-                                                          "]渚涘簲鍟嗕笉瀛樺湪锛岃鍚屾缁橫ES");
-                    }
-                    supplierCode = mesSupplier.SuppNo;
-                }
-
-
-                //var mesInvItemInCItems = Db.Queryable<MesInvItemInCItems>()
-                //    .Where(s => s.ItemInId == mesInvItemIns.Id
-                //                && s.ItemNo == mesItems.ItemNo
-                //                && s.Ebeln == itemOutList.SrcDocNo
-                //                && s.EbelnLineNo ==
-                //                Decimal.Parse(itemOutList.SrcDocLineNo)
-                //                && s.SuppNo == mesSupplier.SuppNo
-                //                && Convert.ToInt32(s.ZzitemId) ==
-                //                Convert.ToInt32(itemOutList.AsnLineNo)).First();
-
-                //if (mesInvItemInCItems == null)
-                //{
-                //    throw new NotImplementedException("娌℃湁瀵瑰簲鐨勫叆搴撴槑缁�");
-                //}
-
-
-                // 纭繚CbillNo涓嶄负绌�
-                if (ItemQtRKList.AppliedQuantity <= 0 || ItemQtRKList.AppliedQuantity == null)
-                {
-                    throw new NotImplementedException("鐢宠鏁伴噺涓嶈兘涓�0鎴朜ULL鍊硷紒");
-                }
-
-                mesItemQtDetail.Add(new MesItemQtDatall
-                {
-                    Mid = nextSequenceValue,
-                    Qd002 = mesItems.ItemNo,
-                    Qd003 = mesItems.ItemName,
-                    Qd004 = mesItems.ItemModel,
-                    Qd005 = mesItems.ColorName,
-                    Qd006 = ItemQtRKList.PlannedQuantity,
-                    Qd007 = ItemQtRKList.AppliedQuantity,
-                    Qd008 = 0, // 宸插叆鏁伴噺榛樿涓�0
-                    Qd009 = mesItems.ItemUnit,
-                    Qd010 = ItemQtRKList.Remark,
-                    Qd012 = mesItems.Id, // 鐗╂枡鍐呯爜
-                    LineNumber = ItemQtRKList.LineNumber,
-                    ProductionRelated = ItemQtRKList.ProductionRelated,
-                    StorageType = ItemQtRKList.StorageType,
-                    OwnerOrganization = ItemQtRKList.OwnerOrganization,
-                    StorageLocation = mesDepot,
-                    SupplierCode = supplierCode,
-                    CustomerCode = ItemQtRKList.CustomerCode,
-                    ProjectCode = ItemQtRKList.ProjectCode,
-                    TaskCode = ItemQtRKList.TaskCode,
-                    ProductionOrder = ItemQtRKList.ProductionOrder,
-                    DailyPlan = ItemQtRKList.DailyPlan,
-                    ProductionActivity = ItemQtRKList.ProductionActivity,
-                    FinishedProduct = ItemQtRKList.FinishedProduct
-
-                });
+                if (mesUnitDb == null)
+                    throw new NotImplementedException("[" +
+                        ItemQtRKList.SupplierCode +
+                        "]鍗曚綅涓嶅瓨鍦紝璇峰悓姝ョ粰MES");
+                mesUnit = mesUnitDb.Fnumber;
             }
 
-            var outItemCommand = Db.Insertable(mesItemQtDetail)
-                .PageSize(1).IgnoreColumnsNull().ExecuteCommand();
-            if (outItemCommand <= 0)
-            {
-                throw new Exception("鍒涘缓鏉傚彂鍗曞瓙琛ㄥけ璐�");
-            }
+            //var mesInvItemInCItems = Db.Queryable<MesInvItemInCItems>()
+            //    .Where(s => s.ItemInId == mesInvItemIns.Id
+            //                && s.ItemNo == mesItems.ItemNo
+            //                && s.Ebeln == itemOutList.SrcDocNo
+            //                && s.EbelnLineNo ==
+            //                Decimal.Parse(itemOutList.SrcDocLineNo)
+            //                && s.SuppNo == mesSupplier.SuppNo
+            //                && Convert.ToInt32(s.ZzitemId) ==
+            //                Convert.ToInt32(itemOutList.AsnLineNo)).First();
 
-            // 鎻掑叆閲囪喘閫�鏂欏崟璁板綍
-            var insertResult = Db.Insertable(MesItemQtrk).IgnoreColumns(true)
-                .ExecuteCommand();
-            if (insertResult <= 0)
-            {
-                throw new Exception("鍒涘缓鏉傚彂鍗曞け璐�");
-            }
-
-            return outItemCommand + insertResult >= 2;
-        }
-
-        private bool Remove(MesItemQtFrom from)
-        {
-            // 鏌ユ壘瑕佸垹闄ょ殑鏉傚彂鍗�
-            var mesItemQtrk = Db.Queryable<MesItemQt>()
-                .Where(s => s.Qtck == from.ApplyNumber
-                           ).ToList();
-
-            if (mesItemQtrk == null || mesItemQtrk.Count == 0)
-            {
-                throw new NotImplementedException("鎵句笉鍒板搴旂殑鏉傚彂鍗�: " + from.ApplyNumber);
-            }
-
-            // 妫�鏌ユ槸鍚︽湁宸插鏍哥殑鍗曟嵁锛屽鏋滃瓨鍦ㄥ凡瀹℃牳(Status=1)鍒欎笉鍏佽鍒犻櫎
-            //if (mesInvItemOuts.Any(item => item.Status == 1))
+            //if (mesInvItemInCItems == null)
             //{
-            //    throw new NotImplementedException("瀛樺湪宸插鏍哥殑閲囪喘閫�鏂欏崟锛屼笉鍏佽鍒犻櫎");
+            //    throw new NotImplementedException("娌℃湁瀵瑰簲鐨勫叆搴撴槑缁�");
             //}
 
-            // 鍒犻櫎鎵�鏈夌浉鍏冲崟鎹�
-            foreach (var itemRK in mesItemQtrk)
+
+            // 纭繚CbillNo涓嶄负绌�
+            if (ItemQtRKList.AppliedQuantity <= 0 ||
+                ItemQtRKList.AppliedQuantity == null)
+                throw new NotImplementedException("鐢宠鏁伴噺涓嶈兘涓�0鎴朜ULL鍊硷紒");
+
+            mesItemQtDetail.Add(new MesItemQtDatall
             {
-                // 鏌ユ壘瑕佸垹闄ょ殑鏉傚彂鍗曟槑缁�
-                var mesInvItemOutItems = Db.Queryable<MesItemQtDatall>()
-                    .Where(s => s.Mid == itemRK.Id)
-                    .ToList();
-
-                if (mesInvItemOutItems == null || mesInvItemOutItems.Count == 0)
-                {
-                    throw new NotImplementedException(
-                        $"鎵句笉鍒版潅鍙戝崟[{from.ApplyNumber}]瀵瑰簲鐨勬槑缁�");
-                }
-
-                // 鍒犻櫎鏉傚彂鍗曟槑缁�
-                var deleteItemsResult = Db.Deleteable<MesItemQtDatall>()
-                    .Where(s => s.Mid == itemRK.Id)
-                    .ExecuteCommand();
-
-                if (deleteItemsResult <= 0)
-                {
-                    throw new Exception($"鎵句笉鍒版潅鍙戝崟[ {from.ApplyNumber}]鏄庣粏锛屽垹闄ゅけ璐�");
-                }
-
-                // 鍒犻櫎鏉傚彂鍗�
-                var deleteResult = Db.Deleteable<MesItemQt>()
-                    .Where(s => s.Id == itemRK.Id)
-                    .ExecuteCommand();
-
-                if (deleteResult <= 0)
-                {
-                    throw new Exception($"鍒犻櫎鏉傚彂鍗昜{from.ApplyNumber}]澶辫触");
-                }
-            }
-
-            return true;
+                Mid = nextSequenceValue,
+                Qd002 = mesItems.ItemNo,
+                Qd003 = mesItems.ItemName,
+                Qd004 = mesItems.ItemModel,
+                Qd005 = mesItems.ColorName,
+                Qd006 = ItemQtRKList.PlannedQuantity,
+                Qd007 = ItemQtRKList.AppliedQuantity,
+                Qd008 = 0, // 宸插叆鏁伴噺榛樿涓�0
+                Qd009 = mesUnit,
+                Qd010 = ItemQtRKList.Remark,
+                Qd012 = mesItems.Id, // 鐗╂枡鍐呯爜
+                LineNumber = ItemQtRKList.LineNumber,
+                ProductionRelated = ItemQtRKList.ProductionRelated,
+                StorageType = ItemQtRKList.StorageType,
+                OwnerOrganization = ItemQtRKList.OwnerOrganization,
+                StorageLocation = mesDepot,
+                SupplierCode = supplierCode,
+                CustomerCode = ItemQtRKList.CustomerCode,
+                ProjectCode = ItemQtRKList.ProjectCode,
+                TaskCode = ItemQtRKList.TaskCode,
+                ProductionOrder = ItemQtRKList.ProductionOrder,
+                DailyPlan = ItemQtRKList.DailyPlan,
+                ProductionActivity = ItemQtRKList.ProductionActivity,
+                FinishedProduct = ItemQtRKList.FinishedProduct,
+                PickingUsage = ItemQtRKList.PickingUsage
+            });
         }
+
+        var itemDB = mesItemQtDetail
+            .Where(x => x.Qd002 != null) // 杩囨护鎺� null 鍊�
+            .GroupBy(x => x.Qd002) // 鎸� Qd002 鍒嗙粍
+            .Select(g => new
+            {
+                no = g.Key,
+                count = g.Count()
+            })
+            .ToList();
+
+        // 杈撳嚭缁熻缁撴灉
+        foreach (var item in itemDB)
+            if (item.count > 1)
+                throw new Exception($"鏄庣粏琛岀墿鏂�:{item.no}閲嶅锛岃妫�鏌ュ悗閲嶈瘯锛�");
+
+        //Console.WriteLine($"鐗╂枡缂栧彿: {item.鐗╂枡缂栧彿}, 鍑虹幇娆℃暟: {item.鍑虹幇娆℃暟}");
+        var outItemCommand = Db.Insertable(mesItemQtDetail)
+            .PageSize(1).IgnoreColumnsNull().ExecuteCommand();
+        if (outItemCommand <= 0) throw new Exception("鍒涘缓鏉傚彂鍗曞瓙琛ㄥけ璐�");
+
+        // 鎻掑叆閲囪喘閫�鏂欏崟璁板綍
+        var insertResult = Db.Insertable(MesItemQtrk).IgnoreColumns(true)
+            .ExecuteCommand();
+        if (insertResult <= 0) throw new Exception("鍒涘缓鏉傚彂鍗曞け璐�");
+
+        return outItemCommand + insertResult >= 2;
     }
-}
+
+    private bool Remove(MesItemQtFrom from)
+    {
+        // 鏌ユ壘瑕佸垹闄ょ殑鏉傚彂鍗�
+        var mesItemQtrk = Db.Queryable<MesItemQt>()
+            .Where(s => s.Qtck == from.ApplyNumber
+            ).ToList();
+
+        if (mesItemQtrk == null || mesItemQtrk.Count == 0)
+            throw new NotImplementedException("鎵句笉鍒板搴旂殑鏉傚彂鍗�: " + from.ApplyNumber);
+
+        // 妫�鏌ユ槸鍚︽湁宸插鏍哥殑鍗曟嵁锛屽鏋滃瓨鍦ㄥ凡瀹℃牳(Status=1)鍒欎笉鍏佽鍒犻櫎
+        //if (mesInvItemOuts.Any(item => item.Status == 1))
+        //{
+        //    throw new NotImplementedException("瀛樺湪宸插鏍哥殑閲囪喘閫�鏂欏崟锛屼笉鍏佽鍒犻櫎");
+        //}
+
+        // 鍒犻櫎鎵�鏈夌浉鍏冲崟鎹�
+        foreach (var itemRK in mesItemQtrk)
+        {
+            // 鏌ユ壘瑕佸垹闄ょ殑鏉傚彂鍗曟槑缁�
+            var mesInvItemOutItems = Db.Queryable<MesItemQtDatall>()
+                .Where(s => s.Mid == itemRK.Id)
+                .ToList();
+
+            if (mesInvItemOutItems == null || mesInvItemOutItems.Count == 0)
+                throw new NotImplementedException(
+                    $"鎵句笉鍒版潅鍙戝崟[{from.ApplyNumber}]瀵瑰簲鐨勬槑缁�");
+
+            // 鍒犻櫎鏉傚彂鍗曟槑缁�
+            var deleteItemsResult = Db.Deleteable<MesItemQtDatall>()
+                .Where(s => s.Mid == itemRK.Id)
+                .ExecuteCommand();
+
+            if (deleteItemsResult <= 0)
+                throw new Exception($"鎵句笉鍒版潅鍙戝崟[ {from.ApplyNumber}]鏄庣粏锛屽垹闄ゅけ璐�");
+
+            // 鍒犻櫎鏉傚彂鍗�
+            var deleteResult = Db.Deleteable<MesItemQt>()
+                .Where(s => s.Id == itemRK.Id)
+                .ExecuteCommand();
+
+            if (deleteResult <= 0)
+                throw new Exception($"鍒犻櫎鏉傚彂鍗昜{from.ApplyNumber}]澶辫触");
+        }
+
+        return true;
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3