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/MesItemQtrkManager.cs | 749 ++++++++++++++++++++++++++++-----------------------------
1 files changed, 371 insertions(+), 378 deletions(-)
diff --git a/StandardPda/MES.Service/service/Warehouse/MesItemQtrkManager.cs b/StandardPda/MES.Service/service/Warehouse/MesItemQtrkManager.cs
index 268fe67..da21912 100644
--- a/StandardPda/MES.Service/service/Warehouse/MesItemQtrkManager.cs
+++ b/StandardPda/MES.Service/service/Warehouse/MesItemQtrkManager.cs
@@ -1,424 +1,417 @@
-锘縰sing Masuit.Tools;
-using MES.Service.DB;
+锘縰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 MesItemQtrkManager : Repository<MesItemQtrk>
{
- public class MesItemQtrkManager : Repository<MesItemQtrk>
+ public bool MiscellaneousReceipts(MesItemQtRKDto mesItemQtRKDto)
{
- public bool MiscellaneousReceipts(MesItemQtRKDto mesItemQtRKDto)
+ var itemQtRKFrom = mesItemQtRKDto.from;
+ var itemQtRKLists = mesItemQtRKDto.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 (itemQtRKFrom.Type)
{
- var itemQtRKFrom = mesItemQtRKDto.from;
- var itemQtRKLists = mesItemQtRKDto.items;
+ case "1":
+ {
+ var mesInvItemOuts = Db.Queryable<MesItemQtrk>()
+ .Where(s => s.Qtck == itemQtRKFrom.ApplyNumber
+ )
+ .Count();
- // 鏍规嵁AsnNo鍜孧esNo瀵规槑缁嗚繘琛屽垎缁�
- //var groupedItems = itemOutLists
- // .GroupBy(item => new { item.AsnNo, item.MesNo, item.SqNo })
- // .ToList();
+ if (mesInvItemOuts > 0)
+ throw new NotImplementedException(
+ itemQtRKFrom.ApplyNumber +
+ "鐨勬潅鏀剁敵璇峰崟宸茬粡瀛樺湪");
- bool result = true;
- //foreach (var group in itemQtRKLists)
- //{
- //if (group.Key.AsnNo == null)
- //{
- // throw new NotImplementedException("AsnNo涓嶈兘涓虹┖");
- //}
+ // 涓哄綋鍓嶅垎缁勪繚瀛樻暟鎹�
+ var groupResult = Save(itemQtRKFrom, itemQtRKLists);
+ if (!groupResult) result = false;
- //if (group.Key.MesNo == null)
- //{
- // throw new NotImplementedException("鍏ュ簱鍗曞崟鍙蜂笉鑳戒负绌�");
- //}
+ break;
+ }
+ case "4":
+ var removeResult = Remove(itemQtRKFrom);
+ if (!removeResult) result = false;
- //if (group.Key.SqNo == null)
- //{
- // throw new NotImplementedException("閫�璐х敵璇峰崟琛屽彿涓嶈兘涓虹┖");
- //}
+ break;
+ default:
+ result = false;
+ break;
+ }
+ //}
- // 鍒涘缓涓�涓复鏃剁殑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
- //};
+ return result;
+ }
- // 鏍规嵁Type鎵ц涓嶅悓鐨勯�昏緫
- switch (itemQtRKFrom.Type)
- {
- case "1":
- {
- var mesInvItemOuts = Db.Queryable<MesItemQtrk>()
- .Where(s => s.Qtck == itemQtRKFrom.ApplyNumber
- )
- .Count();
+ private bool Save(MesItemQtRKFrom from, List<MesItemQtRKList> items)
+ {
+ //var mesInvItemIns = Db.Queryable<MesInvItemIns>()
+ // .Where(s => s.BillTypeId == 100
+ // && s.TransctionNo == "101"
+ // && s.BillNo == from.MesNo
+ // ).First();
- if (mesInvItemOuts > 0)
- {
- throw new NotImplementedException(
- itemQtRKFrom.ApplyNumber +
- "鐨勬潅鏀剁敵璇峰崟宸茬粡瀛樺湪");
- }
+ //if (mesInvItemIns == null)
+ //{
+ // throw new NotImplementedException("閲囪喘鍏ュ簱涓嶅瓨鍦�");
+ //}
- // 涓哄綋鍓嶅垎缁勪繚瀛樻暟鎹�
- var groupResult = Save(itemQtRKFrom, itemQtRKLists);
- if (!groupResult)
- {
- result = false;
- }
- break;
- }
- case "4":
- var removeResult = Remove(itemQtRKFrom);
- if (!removeResult)
- {
- result = false;
- }
+ var SuppNo = "";
+ if (from.SupplierCode != "" && from.SupplierCode != null)
+ {
+ var mesLinkU9 = Db.Queryable<MesLinkU9>()
+ .Where(s => s.TableType == "MES_SUPPLIER"
+ && s.U9Id == from.SupplierCode).First();
- break;
- default:
- result = false;
- break;
- }
- //}
+ if (mesLinkU9 == null)
+ throw new NotImplementedException("渚涘簲鍟咺D涓嶅瓨鍦ㄦ垨鏈悓姝ヤ簬U9");
- return result;
+ 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(MesItemQtRKFrom from, List<MesItemQtRKList> 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_QTRK.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 MesItemQtrk
{
- //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.StockInType,
+ 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 mesItemQtrrDetail = new List<MesItemQtrrDetail>();
+
+ 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();
-
- if (mesLinkU9 == null)
- {
- throw new NotImplementedException("渚涘簲鍟咺D涓嶅瓨鍦ㄦ垨鏈悓姝ヤ簬U9");
- }
+ .Where(s => s.TableType == "MES_SUPPLIER"
+ && s.U9Id == ItemQtRKList.SupplierCode).First();
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_QTRK.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 MesItemQtrk
- {
- 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.StockInType,
- 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 mesItemQtrrDetail = new List<MesItemQtrrDetail>();
-
- 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.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;
- }
- string supplierCode = "";
- if (ItemQtRKList.SupplierCode!=null && ItemQtRKList.SupplierCode != "")
- {
- var mesLinkU9 = Db.Queryable<MesLinkU9>()
- .Where(s => s.TableType == "MES_SUPPLIER"
- && s.U9Id == ItemQtRKList.SupplierCode).First();
-
- 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鍊硷紒");
- }
-
- mesItemQtrrDetail.Add(new MesItemQtrrDetail
- {
- 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(mesItemQtrrDetail)
- .PageSize(1).IgnoreColumnsNull().ExecuteCommand();
- if (outItemCommand <= 0)
- {
- throw new Exception("鍒涘缓鏉傛敹鍗曞瓙琛ㄥけ璐�");
- }
- // 鎻掑叆閲囪喘閫�鏂欏崟璁板綍
- var insertResult = Db.Insertable(MesItemQtrk).IgnoreColumns(true)
- .ExecuteCommand();
- if (insertResult <= 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();
- return outItemCommand + insertResult >= 2;
- }
-
- private bool Remove(MesItemQtRKFrom from)
- {
- // 鏌ユ壘瑕佸垹闄ょ殑鏉傛敹鍗�
- var mesItemQtrk = Db.Queryable<MesItemQtrk>()
- .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鍊硷紒");
+
+ mesItemQtrrDetail.Add(new MesItemQtrrDetail
{
- // 鏌ユ壘瑕佸垹闄ょ殑鏉傛敹鍗曟槑缁�
- var mesInvItemOutItems = Db.Queryable<MesItemQtrrDetail>()
- .Where(s => s.Mid == itemRK.Id)
- .ToList();
-
- if (mesInvItemOutItems == null || mesInvItemOutItems.Count == 0)
- {
- throw new NotImplementedException(
- $"鎵句笉鍒版潅鏀跺崟[{from.ApplyNumber}]瀵瑰簲鐨勬槑缁�");
- }
-
- // 鍒犻櫎鏉傛敹鍗曟槑缁�
- var deleteItemsResult = Db.Deleteable<MesItemQtrrDetail>()
- .Where(s => s.Mid == itemRK.Id)
- .ExecuteCommand();
-
- if (deleteItemsResult <= 0)
- {
- throw new Exception($"鎵句笉鍒版潅鏀跺崟[ {from.ApplyNumber}]鏄庣粏锛屽垹闄ゅけ璐�");
- }
-
- // 鍒犻櫎鏉傛敹鍗�
- var deleteResult = Db.Deleteable<MesItemQtrk>()
- .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
+ });
}
+
+ var itemDB = mesItemQtrrDetail
+ .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(mesItemQtrrDetail)
+ .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(MesItemQtRKFrom from)
+ {
+ // 鏌ユ壘瑕佸垹闄ょ殑鏉傛敹鍗�
+ var mesItemQtrk = Db.Queryable<MesItemQtrk>()
+ .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<MesItemQtrrDetail>()
+ .Where(s => s.Mid == itemRK.Id)
+ .ToList();
+
+ if (mesInvItemOutItems == null || mesInvItemOutItems.Count == 0)
+ throw new NotImplementedException(
+ $"鎵句笉鍒版潅鏀跺崟[{from.ApplyNumber}]瀵瑰簲鐨勬槑缁�");
+
+ foreach (var item in mesInvItemOutItems)
+ if (item.Qd008 > 0)
+ throw new NotImplementedException(
+ "璇ユ潅鏀跺崟鍦∕ES宸茬粡鎵爜鍏ュ簱锛屼笉鑳藉弽瀹″垹闄�");
+
+
+ // 鍒犻櫎鏉傛敹鍗曟槑缁�
+ var deleteItemsResult = Db.Deleteable<MesItemQtrrDetail>()
+ .Where(s => s.Mid == itemRK.Id)
+ .ExecuteCommand();
+
+ if (deleteItemsResult <= 0)
+ throw new Exception($"鎵句笉鍒版潅鏀跺崟[ {from.ApplyNumber}]鏄庣粏锛屽垹闄ゅけ璐�");
+
+ // 鍒犻櫎鏉傛敹鍗�
+ var deleteResult = Db.Deleteable<MesItemQtrk>()
+ .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