From 02b26bfaca24386f7b4f4a5e9f336812370ed49b Mon Sep 17 00:00:00 2001
From: cdk <2441919651@qq.com>
Date: 星期一, 22 十二月 2025 09:45:46 +0800
Subject: [PATCH] 获取BOM参数调整
---
service/Wom/WwGdManager.cs | 1741 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 1,676 insertions(+), 65 deletions(-)
diff --git a/service/Wom/WwGdManager.cs b/service/Wom/WwGdManager.cs
index 5803cf3..0b038e0 100644
--- a/service/Wom/WwGdManager.cs
+++ b/service/Wom/WwGdManager.cs
@@ -1,10 +1,13 @@
-锘縰sing System.Data;
-using System.Data.SqlClient;
-using Masuit.Tools;
+锘縰sing Masuit.Tools;
using NewPdaSqlServer.DB;
using NewPdaSqlServer.Dto.service;
using NewPdaSqlServer.entity;
+using NewPdaSqlServer.entity.Base;
+using NewPdaSqlServer.util;
using SqlSugar;
+using System.Data;
+using System.Data.SqlClient;
+using System.Threading.Tasks.Dataflow;
namespace NewPdaSqlServer.service.Wom;
@@ -57,7 +60,9 @@
daa001 = query.daa001,
barcodeNum = barcodeNum,
splitNum = splitNum,
- barcode = query.barcode
+ barcode = query.barcode,
+ strMsg = _strMsg,
+ result = _intSum
};
return dto;
@@ -134,85 +139,1691 @@
}
}
- public ProductionPickDto GetItemsByDaa001(WarehouseQuery query)
+
+ /// <summary>
+ /// 鑾峰彇搴撲綅淇℃伅
+ /// </summary>
+ /// <param name="unity"></param>
+ /// <returns></returns>
+ /// <exception cref="Exception"></exception>
+ public dynamic GetBarKwByItem(dynamic unity)
{
- return getDaa001(query);
+ if (unity == null)
+ throw new ArgumentNullException(nameof(unity), "鍙傛暟瀵硅薄涓嶈兘涓簄ull");
+
+ if (string.IsNullOrEmpty(unity.itemId?.ToString()))
+ throw new ArgumentException("鐗╂枡ID涓嶈兘涓虹┖", nameof(unity.itemId));
+
+ try
+ {
+ var parameters = new List<SugarParameter>
+ {
+ new SugarParameter("@itemId",unity.itemId)
+ };
+
+ return Db.Ado.SqlQuery<dynamic>("EXEC prc_pda_scll_selBarMx @itemId", parameters);
+ }
+ catch (Exception ex)
+ {
+ throw new Exception($"鑾峰彇鏉$爜淇℃伅澶辫触锛歿ex.Message}");
+ }
+
}
- private ProductionPickDto getDaa001(WarehouseQuery query)
+ /// <summary>
+ /// 閫夊彇鍒楄〃
+ /// </summary>
+ /// <param name="unity"></param>
+ /// <param name="RequestInfo"></param>
+ /// <returns></returns>
+ public dynamic GetXcslDaa(dynamic unity, dynamic RequestInfo)
{
- if (string.IsNullOrEmpty(query.daa001)) throw new Exception("宸ュ崟鍙蜂负绌�");
+ var orgId = RequestInfo.OrgId;
+ var parameters = new List<SugarParameter>
+ {
+ new SugarParameter("@selectKey", unity.selectKey),
+ new SugarParameter("@inP1", orgId), // 鍙�夊弬鏁�
+ new SugarParameter("@inP2", unity.selDaaType), // 鍙�夊弬鏁�
+ new SugarParameter("@inP3", null), // 鍙�夊弬鏁�
+ new SugarParameter("@inP4", null), // 鍙�夊弬鏁�
+ // ...鍏朵粬鍙�夊弬鏁�
+ };
+ var result = Db.Ado.SqlQuery<dynamic>("EXEC prc_pda_wwll_list @selectKey, @inP1, @inP2, @inP3, @inP4", parameters);
+ return result;
+ }
- var womdaa = Db.Queryable<WwGd, MesItems>((a, i) =>
- new JoinQueryInfos(JoinType.Left,
- a.Daa003 == i.ItemId))
- .Where((a, i) => a.Daa001 == query.daa001)
- .Select((a, i) => new
+
+
+ /// <summary>
+ /// 閫夊彇鍒楄〃
+ /// </summary>
+ /// <param name="unity"></param>
+ /// <param name="RequestInfo"></param>
+ /// <returns></returns>
+ public dynamic GetWWCKsq(dynamic unity, dynamic RequestInfo)
+ {
+ var orgId = RequestInfo.OrgId;
+ var parameters = new List<SugarParameter>
+ {
+ new SugarParameter("@pi_selectKey", unity.selectKey),
+ new SugarParameter("@pi_type", unity.type), // 鍙�夊弬鏁�
+ new SugarParameter("@pi_orgId", orgId), // 鍙�夊弬鏁�
+ new SugarParameter("@inP1", null), // 鍙�夊弬鏁�
+ new SugarParameter("@inP2", null), // 鍙�夊弬鏁�
+ new SugarParameter("@inP3", null), // 鍙�夊弬鏁�
+ new SugarParameter("@inP4", null), // 鍙�夊弬鏁�
+ // ...鍏朵粬鍙�夊弬鏁�
+ };
+ var result = Db.Ado.SqlQuery<dynamic>("EXEC prc_pda_wwcksq_list @pi_selectKey, @pi_type, @pi_orgId , @inP1, @inP2, @inP3, @inP4", parameters);
+ return result;
+ }
+
+
+ /// <summary>
+ /// 鍒楄〃鏄庣粏
+ /// </summary>
+ /// <param name="query"></param>
+ /// <param name="RequestInfo"></param>
+ /// <returns></returns>
+ public dynamic GetItemsByDaa001(WarehouseQuery query, dynamic RequestInfo)
+ {
+ return getDaa001(query, RequestInfo);
+ }
+
+ private dynamic getDaa001(WarehouseQuery query, dynamic RequestInfo)
+ {
+ if (string.IsNullOrEmpty(query.daa001)) throw new Exception("璇烽�夊伐鍗曞彿锛�");
+ if (query == null)
+ throw new ArgumentNullException(nameof(query), "鍙傛暟瀵硅薄涓嶈兘涓簄ull");
+ if (string.IsNullOrEmpty(query.daa001?.ToString()))
+ throw new ArgumentException("宸ュ崟鍙蜂笉瀛樺湪", nameof(query.daa001));
+
+ var orgId = RequestInfo.OrgId;
+ if (orgId == null)
+ throw new Exception("缁勭粐涓嶅瓨鍦紒");
+
+ var parameters = new[]
+ {
+ new SugarParameter("@daa001", query.daa001),
+ new SugarParameter("@pi_orgId", orgId),
+ new SugarParameter("@inP1", null),
+ new SugarParameter("@inP2", null),
+ new SugarParameter("@inP3", null),
+ new SugarParameter("@inP4", null)
+ };
+ try
+ {
+ List<dynamic>? blDetails = Db.Ado.SqlQuery<dynamic>(
+ "EXEC prc_pda_wwll_detailList @daa001,@pi_orgId,@inP1,@inP2,@inP3,@inP4", parameters);
+ var items = blDetails.Where(x => x.DSQty > 0).ToList(); // 寰呮壂鐗╂枡
+ var ysitems = blDetails.Where(x => x.SQty > 0).ToList(); // 宸叉壂鐗╂枡
+ var planNo = blDetails.FirstOrDefault()?.ErpProductionOrderNo?.ToString();// 鑾峰彇宸ュ崟璁″垝鍙�
+ return new
{
- a.Daa001, a.RwdGuid
- }).First();
+ daa001 = query.daa001,
+ PlanNo = planNo,
+ items = items,
+ ysitems = ysitems
+ };
+ }
+ catch (Exception ex)
+ {
+ throw new Exception($"{ex.Message}");
+ }
+ }
- if (womdaa?.Daa001 == null) throw new Exception("宸ュ崟鍙蜂笉瀛樺湪");
+ /// <summary>
+ /// 濮斿鍑哄簱鐢宠鍗曞彿鑾峰彇鏄庣粏
+ /// </summary>
+ /// <param name="query"></param>
+ /// <param name="RequestInfo"></param>
+ /// <returns></returns>
+ /// <exception cref="Exception"></exception>
+ /// <exception cref="ArgumentNullException"></exception>
+ /// <exception cref="ArgumentException"></exception>
+ public dynamic GetItemsByWwckNo(WarehouseQuery query, dynamic RequestInfo)
+ {
+ if (string.IsNullOrEmpty(query.daa001)) throw new Exception("璇烽�夊伐鍗曞彿锛�");
+ if (query == null)
+ throw new ArgumentNullException(nameof(query), "鍙傛暟瀵硅薄涓嶈兘涓簄ull");
+ if (string.IsNullOrEmpty(query.daa001?.ToString()))
+ throw new ArgumentException("宸ュ崟鍙蜂笉瀛樺湪", nameof(query.daa001));
- var womdabs = Db.Queryable<WwGd, WwGdDetail, MesItems, ProductionOrderSub>(
- (a, b, c, d) =>
- new JoinQueryInfos(
- JoinType.Left,
- a.Id == b.Pid,
- JoinType.Inner,
- c.Id ==
- b.Dab003,
- JoinType.Inner, b.Erpid.ToString() == d.ErpId
- ))
- .Where((a, b, c, d) =>
- a.Daa001 == query.daa001 && d.IssuingMethod == "1")
- .Select((a, b, c, d) => new WwGdDetail
+ var orgId = RequestInfo.OrgId;
+ if (orgId == null)
+ throw new Exception("缁勭粐涓嶅瓨鍦紒");
+
+ var parameters = new[]
+ {
+ new SugarParameter("@daa001", query.daa001),
+ new SugarParameter("@pi_orgId", orgId),
+ new SugarParameter("@inP1", null),
+ new SugarParameter("@inP2", null),
+ new SugarParameter("@inP3", null),
+ new SugarParameter("@inP4", null)
+ };
+ try
+ {
+ List<dynamic>? blDetails = Db.Ado.SqlQuery<dynamic>(
+ "EXEC prc_pda_wwcksq_detailList @daa001,@pi_orgId,@inP1,@inP2,@inP3,@inP4", parameters);
+ var items = blDetails.Where(x => x.DSQty > 0).ToList(); // 寰呮壂鐗╂枡
+ var ysitems = blDetails.Where(x => x.SQty > 0).ToList(); // 宸叉壂鐗╂枡
+ var planNo = blDetails.FirstOrDefault()?.ErpProductionOrderNo?.ToString();// 鑾峰彇宸ュ崟璁″垝鍙�
+ return new
{
- Pid = b.Pid,
- Dab003 = b.Dab003,
- Dab006 = b.Dab006,
- Dab007 = b.Dab007,
- wNum = b.Dab006 - b.Dab007, // 璁$畻瀛楁 W_NUM
- ItemName = c.ItemName, // 鍔ㄦ�佸瓧娈� ITEM_NAME
- ItemNo = c.ItemNo // 鍔ㄦ�佸瓧娈� ITEM_NO
- })
- .ToList();
+ daa001 = query.daa001,
+ PlanNo = planNo,
+ items = items,
+ ysitems = ysitems,
+ allList = blDetails
+ };
+ }
+ catch (Exception ex)
+ {
+ throw new Exception($"{ex.Message}");
+ }
+ }
- var list = womdabs.Where(s => s.wNum > 0).ToList();
+ /// <summary>
+ /// w濮斿鍑哄簱
+ /// </summary>
+ /// <param name="query"></param>
+ /// <returns></returns>
+ /// <exception cref="Exception"></exception>
+ public ProductionPickDto WwckScanCode(WarehouseQuery query)
+ {
+ var _strMsg = "";
+ var _intSum = "";
+ using (var conn = new SqlConnection(DbHelperSQL.strConn))
+ {
+ if (query.userName.IsNullOrEmpty()) throw new Exception("鐢ㄦ埛鍚嶄笉鍏佽涓虹┖");
+ if (query.daa001.IsNullOrEmpty()) throw new Exception("棰嗘枡鍗曞彿涓嶅厑璁镐负绌�");
+ if (query.barcode.IsNullOrEmpty()) throw new Exception("鏉$爜涓嶅厑璁镐负绌�");
- var mesInvItemOutCDetailsList = Db
- .Queryable<MesInvItemOutCDetails, MesItems, MesDepots>
- ((a, b, c) =>
- new JoinQueryInfos(
- JoinType.Inner, a.ItemId == b.Id,
- JoinType.Inner, c.DepotId == a.DepotId
- ))
- .Where((a, b, c) => a.WorkNo == query.daa001)
- .Select((a, b, c) => new MesInvItemOutCDetails
+ using (var cmd = new SqlCommand("[PRC_PDA_WWCK_SCAN]", conn))
{
- ItemName = b.ItemName,
- ItemNo = b.ItemNo,
- ItemId = a.ItemId,
- DepotId = a.DepotId,
- WorkNo = a.WorkNo,
- DepotName = c.DepotName,
- Quantity = a.Quantity
- })
- .ToList();
+ try
+ {
+ conn.Open();
+ cmd.CommandType = CommandType.StoredProcedure;
+ //SqlParameter[] parameters =
+ //{
+ // new("@outMsg", SqlDbType.NVarChar, 300),
+ // new("@outSum", SqlDbType.NVarChar, 300),
+ // new("@barcode_num", SqlDbType.NVarChar, 300),
+ // new("@split_num", SqlDbType.NVarChar, 300),
+ // new("@c_User", query.userName),
+ // new("@p_biLL_no", query.daa001),
+ // new("@p_item_barcode", query.barcode)
+ //};
- var womcaa = Db.Queryable<ProductionOrder>()
- .Where(s => s.Guid == womdaa.RwdGuid)
- .First();
+ var parameters = new SqlParameter[]
+ {
+ new SqlParameter("@C_USER", SqlDbType.NVarChar, 100) { Value = query.userName ?? string.Empty },
+ new SqlParameter("@P_BILL_NO", SqlDbType.NVarChar, 50) { Value = query.billNo ?? string.Empty },
+ new SqlParameter("@P_ITEM_BARCODE", SqlDbType.NVarChar, 100) { Value = query.barcode ?? string.Empty },
+ new SqlParameter("@P_BL_NO", SqlDbType.NVarChar, 100) { Value = query.blNo ?? string.Empty },
+ new SqlParameter("@P_TYPE", SqlDbType.NVarChar, 20) { Value = query.Type ?? string.Empty },
+ new SqlParameter("@OUT_MSG", SqlDbType.NVarChar, 2000) { Direction = ParameterDirection.Output },
+ new SqlParameter("@OUT_SUM", SqlDbType.Int) { Direction = ParameterDirection.Output },
+ new SqlParameter("@BARCODE_NUM", SqlDbType.Decimal) {
+ Direction = ParameterDirection.Output,
+ Precision = 18,
+ Scale = 10
+ },
+ new SqlParameter("@SPLIT_NUM", SqlDbType.Decimal) {
+ Direction = ParameterDirection.Output,
+ Precision = 18,
+ Scale = 10
+ }
+ };
+
+ parameters[5].Direction = ParameterDirection.Output;
+ parameters[6].Direction = ParameterDirection.Output;
+ parameters[7].Direction = ParameterDirection.Output;
+ parameters[8].Direction = ParameterDirection.Output;
+ foreach (var parameter in parameters)
+ cmd.Parameters.Add(parameter);
+ cmd.ExecuteNonQuery();
+ _strMsg = parameters[5].Value.ToString();
+ _intSum = parameters[6].Value.ToString();
+
+ var barcodeNum = parameters[7].Value.ToString();
+ var splitNum = parameters[8].Value.ToString();
+
+ var result = Convert.ToInt32(_intSum);
+ if (result <= 0) throw new Exception(_strMsg);
+
+ var dto = new ProductionPickDto
+ {
+ daa001 = query.daa001,
+ barcodeNum = barcodeNum,
+ splitNum = splitNum,
+ barcode = query.barcode,
+ strMsg = _strMsg,
+ result = _intSum
+ };
+
+ return dto;
+ }
+ catch (Exception ex)
+ {
+ throw new Exception(ex.Message);
+ }
+ finally
+ {
+ conn.Close();
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// 濮斿鎷嗗垎鍑哄簱鎷嗗垎
+ /// </summary>
+ /// <param name="query"></param>
+ /// <returns></returns>
+ /// <exception cref="Exception"></exception>
+ public ProductionPickDto WwckScanCodeCF(WarehouseQuery query)
+ {
+ // Validate input parameters
+ if (string.IsNullOrEmpty(query.userName))
+ throw new Exception("鐢ㄦ埛鍚嶄笉鑳戒负绌猴紒");
+
+ if (string.IsNullOrEmpty(query.barcode))
+ throw new Exception("璇锋壂鎻忔潯鐮侊紒");
+
+ if ((query.Num ?? 0) <= 0)
+ throw new Exception("璇疯緭鍏ユ纭殑鍙戞枡鏁伴噺锛�");
+
+ if (string.IsNullOrEmpty(query.blNo))
+ throw new Exception("琛ユ枡鍗曞彿涓嶈兘涓虹┖锛�");
+
+ // Prepare parameters for the stored procedure
+ var parameters = new List<SugarParameter>
+ {
+ new SugarParameter("@C_USER", query.userName),
+ new SugarParameter("@P_BILL_NO", query.billNo),
+ new SugarParameter("@P_ITEM_BARCODE", query.barcode),
+ new SugarParameter("@P_BL_NO", query.blNo),
+ new SugarParameter("@P_TYPE", query.Type),
+ new SugarParameter("@NUM", query.Num),
+ new SugarParameter("@OUT_MSG", "", System.Data.DbType.String, ParameterDirection.Output),
+ new SugarParameter("@OUT_SUM", 0, System.Data.DbType.Int32, ParameterDirection.Output),
+ new SugarParameter("@OUT_CF_BAR", "", System.Data.DbType.String, ParameterDirection.Output)
+ };
+
+ // Execute the stored procedure
+ Db.Ado.UseStoredProcedure().ExecuteCommand("PRC_PDA_WWCK_SCAN_CF", parameters);
+
+ // Get output parameters
+ var outMsg = parameters.FirstOrDefault(p => p.ParameterName == "@OUT_MSG")?.Value?.ToString();
+ var outSum = Convert.ToInt32(parameters.FirstOrDefault(p => p.ParameterName == "@OUT_SUM")?.Value ?? -1);
+ var outCfBar = parameters.FirstOrDefault(p => p.ParameterName == "@OUT_CF_BAR")?.Value?.ToString();
+
+ // Handle the result
+ if (outSum == -1)
+ {
+ throw new Exception(outMsg ?? "鎿嶄綔澶辫触");
+ }
+
var dto = new ProductionPickDto
{
- daa001 = womdaa.Daa001,
- PlanNo = womcaa.ErpProductionOrderNo,
- totals1 = womdabs,
- daisao1 = list,
- yisao = mesInvItemOutCDetailsList
+ daa001 = query.billNo,
+ barcode = query.barcode,//鍘熸潯鐮�
+ cfBarcode = outCfBar//鎷嗗垎鍚庢潯鐮�
};
return dto;
}
+
+ #region 濮斿閫�鏂�
+
+ /// <summary>
+ /// 濮斿閫�鏂欐壂鎻忔潯鐮�(鐢熶骇閫�鏂欑殑閫昏緫锛屽彧鏄皟鏁翠簡鍑犱釜瀛楁)
+ /// </summary>
+ /// <param name="query">浠撳簱鏌ヨ鍙傛暟</param>
+ /// <returns>澶勭悊缁撴灉</returns>
+ public WarehouseQuery WwtlScanBarcode(WarehouseQuery query)
+ {
+ var p_item_barcode = query.barcode; // 鐗╂枡鏉$爜
+ var p_bill_no = query.billNo; // 鍗曟嵁鍙�
+ var p_section_code = query.DepotCode; // 搴撲綅缂栫爜
+ var c_user = query.userName; // 鐢ㄦ埛鍚�
+
+ var p_bill_type_id = 100; // 鍗曟嵁绫诲瀷ID
+ var p_transction_no = 104; // 浜ゆ槗缂栧彿
+
+ // 楠岃瘉搴撲綅鏉$爜
+ if (p_section_code.IsNullOrEmpty()) throw new Exception("璇锋壂搴撲綅鏉$爜锛�");
+
+ // 鑾峰彇搴撲綅淇℃伅
+ var c_depot_code = Db.Queryable<MesDepotSections, MesDepots>((a, b) =>
+ new JoinQueryInfos(JoinType.Inner, a.DepotGuid == b.Guid))
+ .Where((a, b) => a.DepotSectionCode == p_section_code)
+ .Select((a, b) => b.DepotId).First();
+
+ if (!c_depot_code.HasValue)
+ throw new Exception("搴撲綅缂栫爜" + p_section_code + " 涓嶅瓨鍦紝璇风‘璁わ紒");
+
+ // 鑾峰彇搴撲綅鍒嗗尯淇℃伅
+ var mesDepotSections = Db.Queryable<MesDepotSections>()
+ .Where(a => a.DepotSectionCode == p_section_code).First();
+
+ if (mesDepotSections == null)
+ throw new Exception("搴撲綅缂栫爜" + p_section_code + " 涓嶅瓨鍦紝璇风‘璁わ紒");
+
+ // 鑾峰彇搴撲綅鍩虹淇℃伅
+ var c_mes_depots = Db.Queryable<MesDepots>()
+ .Where(b => b.Guid == mesDepotSections.DepotGuid).First();
+
+ if (c_mes_depots == null)
+ throw new Exception("搴撲綅缂栫爜" + p_section_code + " 涓嶅瓨鍦紝璇风‘璁わ紒");
+
+ // 妫�鏌ユ潯鐮佹槸鍚﹀凡鍏ュ簱
+ var c_num = Db.Queryable<MesInvItemIns, MesInvItemInCDetails>((a, b) =>
+ new JoinQueryInfos(JoinType.Inner, a.Guid == b.ItemInId))
+ .Where((a, b) => b.ItemBarcode == p_item_barcode
+ && a.BillTypeId == p_bill_type_id &&
+ a.TransctionNo == p_transction_no.ToString())
+ .Count();
+
+ if (c_num > 0) throw new Exception("姝ゆ潯鐮佸凡鎵叆搴擄紝鍕块噸澶嶆壂鎻忥紒");
+
+ c_num = Db.Queryable<MesInvItemStocks>()
+ .Where(t => t.ItemBarcode == p_item_barcode).Count();
+
+ if (c_num > 0) throw new Exception("姝ゆ潯鐮佸凡鎵叆搴擄紝鍕块噸澶嶆壂鎻忥紒");
+
+ // 鑾峰彇鏉$爜淇℃伅
+ var c_mes_inv_item_barcodes = Db.Queryable<MesInvItemBarcodes>()
+ .Where(t => t.ItemBarcode == p_item_barcode).First();
+
+ if (c_mes_inv_item_barcodes == null)
+ throw new Exception("姝ゆ潯鐮佷笉灞炰簬璇ラ��鏂欏崟锛岃鏍稿锛�");
+
+
+
+ // if (c_mes_inv_item_barcodes.Memo != "鐢熶骇閫�鏂�")
+ // throw new Exception("姝ゆ潯鐮佷笉鏄敓浜ч��鏂欐潯鐮侊紝涓嶅彲浣跨敤鐢熶骇閫�鏂欐ā鍧楋紒");
+
+ // 鑾峰彇閫�鏂欏崟淇℃伅
+ var C_MES_ITEM_TBL = Db.Queryable<MesItemTbl>()
+ .Where(a => a.BillNo == c_mes_inv_item_barcodes.BillNo
+ && (a.Tbl013 ?? 0) == 1).First();
+
+ if (C_MES_ITEM_TBL == null) throw new Exception("鐢宠鍗曞凡鎾ゅ洖,鏃犳硶鎵爜!");
+
+ if (C_MES_ITEM_TBL.Tbl020 == 1) throw new Exception("鎵爜瀹屾垚,鐢宠鍗曞凡瀹岀粨!");
+
+ // 妫�鏌ュ伐鍗曚俊鎭�
+ var wwgd = Db.Queryable<WwGd>()
+ .Where(a => a.Id.ToString() == C_MES_ITEM_TBL.Tbl002)
+ .First();
+
+ if (wwgd == null) throw new Exception("鐢宠鍗曞搴旂殑宸ュ崟涓嶅瓨鍦ㄦ垨宸插垹闄�,鏃犳硶鎵爜!");
+
+ // 妫�鏌ュ伐鍗曚俊鎭�
+ var WWRWD = Db.Queryable<ProductionOrder>()
+ .Where(a => a.OrderNo == wwgd.Daa014)
+ .First();
+
+ // 鑾峰彇閫�鏂欏崟鏄庣粏
+ var C_MES_ITEM_TBL_DETAIL = Db.Queryable<MesItemTblDetail>()
+ .Where(a => a.Tlid == c_mes_inv_item_barcodes.AboutGuid)
+ .First();
+
+ if (C_MES_ITEM_TBL_DETAIL == null)
+ throw new Exception("鏉$爜涓嶅睘浜庤鐢宠鍗曟槑缁�,鏃犳硶鎵爜!");
+
+ //鍒ゆ柇璐т富淇℃伅
+ var CABerpid = Db.Queryable<WwGdDetail>().Where(womdab => womdab.Id.ToString() == C_MES_ITEM_TBL_DETAIL.Tld013).Select(womdab => womdab.Erpid).First();
+
+ var WWCAB = Db.Queryable<ProductionOrderSub>().Where(womcab => womcab.ErpId == CABerpid.Value.ToString()).First();
+
+
+ if ( String.IsNullOrEmpty(WWCAB.Owner)) throw new Exception("鐢ㄦ枡娓呭崟璐т富淇℃伅涓嶅瓨鍦�,鏃犳硶鎵爜锛岃鑱旂郴绠$悊鍛�!");
+
+ //var owner_type = "";
+ //if (Db.Queryable<SysOrganization>().Any(x => x.Fid == ownerId))
+ //{
+ // owner_type = "BD_OwnerOrg";
+ //}
+ //else
+ //{
+ // // 绗簩灞傚垽鏂細妫�鏌� MES_CUSTOMER
+ // if (Db.Queryable<MesCustomer>().Any(x => x.Id == Convert.ToInt32(ownerId)))
+ // {
+ // owner_type = "BD_Customer";
+ // }
+ // else
+ // {
+ // // 绗笁灞傚垽鏂細妫�鏌� MES_SUPPLIER
+ // if (Db.Queryable<MesSupplier>().Any(x => x.Id == Convert.ToInt32(ownerId)))
+ // {
+ // owner_type = "BD_Supplier";
+ // }
+ // else
+ // {
+ // throw new Exception("鍏ュ簱澶辫触,鐢ㄦ枡娓呭崟璐т富淇℃伅瀛樺湪闂锛岃鑱旂郴绠$悊鍛樿В鍐筹紒");
+ // }
+ // }
+ //}
+
+ var c_quantity = c_mes_inv_item_barcodes.Quantity;
+
+ var c_bill_no = "";
+ var c_id = Guid.Empty;
+
+ // 浣跨敤浜嬪姟澶勭悊鏁版嵁鏇存柊
+ UseTransaction(db =>
+ {
+ // 鏌ヨ鍏ュ簱鍗�
+ var mesInvItemIns = db.Queryable<MesInvItemIns>()
+ .Where(d =>
+ d.Status == 0 && d.TransctionNo ==
+ p_transction_no.ToString()
+ && d.TaskNo == c_mes_inv_item_barcodes.BillNo
+ && d.DepotsId == c_depot_code
+ && d.InsDate.Value.ToString("yyyyMMdd") ==
+ DateTime.Now.ToString("yyyyMMdd")).First();
+
+ var totalResult = 0;
+
+ // 濡傛灉鍏ュ簱鍗曚笉瀛樺湪鍒欏垱寤烘柊鐨勫叆搴撳崟
+ if (mesInvItemIns == null)
+ {
+ c_bill_no = BillNo.GetBillNo("WWTL(濮斿閫�鏂�)");
+
+ c_id = Guid.NewGuid();
+
+ totalResult += db.Insertable(new MesInvItemIns
+ {
+ Guid = c_id,
+ BillNo = c_bill_no,
+ BillTypeId = p_bill_type_id,
+ InsDate = DateTime.Now,
+ DepotsId = c_depot_code,
+ UserNoBack = c_user,
+ Reason = C_MES_ITEM_TBL.Tbl005,
+ Remark = C_MES_ITEM_TBL.Tbl006,
+ //InsDate = DateTime.Now,
+ DepotsCode = c_mes_depots.DepotCode,
+ TaskNo = c_mes_inv_item_barcodes.BillNo,
+ //DepotsId = c_depot_code,
+ TransctionNo = p_transction_no.ToString(),
+ CreateBy = c_user,
+ CreateDate = DateTime.Now,
+ LastupdateBy = c_user,
+ LastupdateDate = DateTime.Now,
+ CbillNo = wwgd.Daa001,
+ InType = "濮斿閫�鏂�",
+ ReceiveOrgId = c_mes_depots.FSubsidiary,
+ Fstatus = 0,
+ Status = 0,
+ WorkNo = WWRWD.ErpProductionOrderNo
+ }).IgnoreColumns(true).ExecuteCommand();
+ }
+ else
+ {
+ c_id = mesInvItemIns.Guid;
+ c_bill_no = mesInvItemIns.BillNo;
+ }
+
+ // 妫�鏌ユ槸鍚︿负鍚堝苟鎵撳嵃鏉$爜
+ var hbdy = c_mes_inv_item_barcodes.Hbdy ?? 0;
+ if (hbdy == 1) throw new Exception("涓嶆敮鎸佸悎骞舵墦鍗扮殑鏉$爜:" + p_item_barcode);
+
+
+ // 妫�鏌ユ槸鍚﹀瓨鍦ㄤ簬 MES_INV_ITEM_IN_C_ITEMS 琛�
+ var existingCount = db.Queryable<MesInvItemInCItems>()
+ .Where(it =>
+ it.ItemInId == c_id &&
+ it.ItemId == C_MES_ITEM_TBL_DETAIL.Tld009 &&
+ it.DepotId == c_depot_code.ToString())
+ .Count();
+
+ if (existingCount == 0)
+ // 涓嶅瓨鍦ㄦ椂鎻掑叆鏂拌褰�
+ db.Insertable(new MesInvItemInCItems
+ {
+ ItemInId = c_id,
+ Quantity = c_mes_inv_item_barcodes.Quantity,
+ CreateBy = c_user,
+ CreateDate = DateTime.Now,
+ ItemNo = c_mes_inv_item_barcodes.ItemNo,
+ //DepotCode = mesDepost.DepotCode,
+ ItemSname = c_mes_inv_item_barcodes.ItemSname,
+ Unit = c_mes_inv_item_barcodes.Unit,
+ Ebeln = c_mes_inv_item_barcodes.WorkNo,
+ BillNo = c_bill_no,
+ WorkNo = c_mes_inv_item_barcodes.WorkNo,
+ EbelnLineNo = c_mes_inv_item_barcodes.WorkLine,
+ CbillNo = c_mes_inv_item_barcodes.BillNo,
+ WorkLine = c_mes_inv_item_barcodes.WorkLine,
+ SuppId = c_mes_inv_item_barcodes.SuppId,
+ SuppNo = c_mes_inv_item_barcodes.SuppNo,
+ Remark = c_mes_inv_item_barcodes.Memo,
+ EbelnK3id = c_mes_inv_item_barcodes.EbelnK3id,
+ LineK3id = c_mes_inv_item_barcodes.LineK3id,
+ ItemId = c_mes_inv_item_barcodes.ItemId,
+ DepotCode = c_mes_depots.DepotCode,
+ DepotId = c_depot_code.ToString(),
+ itemDabid = c_mes_inv_item_barcodes.AboutGuid.ToString()
+ }).IgnoreColumns(true).ExecuteCommand();
+ else
+ // 瀛樺湪鏃舵洿鏂版暟閲�
+ db.Updateable<MesInvItemInCItems>()
+ .SetColumns(it => new MesInvItemInCItems
+ {
+ Quantity = SqlFunc.IsNull(it.Quantity, 0) + c_mes_inv_item_barcodes.Quantity // 纭繚 Quantity 涓嶄负 null
+ })
+ .Where(it =>
+ it.ItemInId == c_id &&
+ it.ItemId == C_MES_ITEM_TBL_DETAIL.Tld009 &&
+ it.DepotId == c_depot_code.ToString())
+ //.IgnoreColumns(true) // 淇濈暀 IgnoreColumns
+ .ExecuteCommand();
+
+ // 鎻掑叆鍏ュ簱鍗曟槑缁�
+ totalResult += db.Insertable(new MesInvItemInCDetails
+ {
+ Guid = Guid.NewGuid(),
+ ItemInId = c_id,
+ BillNo = c_bill_no,
+ ItemBarcode = p_item_barcode,
+ Quantity = c_quantity,
+ BarcodeFlag = true,
+ EpFlag = true,
+ WorkType = 1,
+ ItemId = c_mes_inv_item_barcodes.ItemId,
+ ItemNo = c_mes_inv_item_barcodes.ItemNo,
+ LotNo = c_mes_inv_item_barcodes.LotNo,
+ SuppId = c_mes_inv_item_barcodes.SuppId,
+ SuppNo = c_mes_inv_item_barcodes.SuppNo,
+ DepotId = c_mes_depots.DepotId,
+ DepotCode = c_mes_depots.DepotCode,
+ DepotSectionCode = p_section_code,
+ ItemSname = c_mes_inv_item_barcodes.ItemSname,
+ Unit = c_mes_inv_item_barcodes.Unit,
+ CreateBy = c_user,
+ CreateDate = DateTime.Now,
+ LastupdateBy = c_user,
+ LastupdateDate = DateTime.Now,
+ Remark = c_mes_inv_item_barcodes.Memo,
+ Ebeln = c_mes_inv_item_barcodes.Mblnr,
+ EbelnLineNo = c_mes_inv_item_barcodes.Zeile,
+ WorkNo = c_mes_inv_item_barcodes.WorkNo,
+ WorkLine = c_mes_inv_item_barcodes.WorkLine,
+ CbillNo = c_mes_inv_item_barcodes.BillNo,
+ UrgentFlag = c_mes_inv_item_barcodes.UrgentFlag,
+ BoardStyle = c_mes_inv_item_barcodes.BoardStyle,
+ TaskNo = c_mes_inv_item_barcodes.TaskNo,
+ RbillNo = C_MES_ITEM_TBL.Tbl002,
+ ReceiveOrgId = c_mes_depots.FSubsidiary,
+ EbelnK3id = c_mes_inv_item_barcodes.EbelnK3id,
+ LineK3id = c_mes_inv_item_barcodes.LineK3id,
+ Ischeck = true,
+ }).IgnoreColumns(true).ExecuteCommand();
+
+ // 鎻掑叆涓氬姟璁板綍
+ totalResult += db.Insertable(new MesInvBusiness2
+ {
+ Guid = Guid.NewGuid(),
+ Status = 1,
+ BillTypeId = p_bill_type_id,
+ TransactionCode = p_transction_no.ToString(),
+ BusinessType = 1,
+ ItemBarcode = p_item_barcode,
+ ItemNo = c_mes_inv_item_barcodes.ItemNo,
+ LotNo = c_mes_inv_item_barcodes.LotNo,
+ EpFlag = true,
+ Quantity = c_mes_inv_item_barcodes.Quantity,
+ ToInvDepotsCode = c_mes_depots.DepotCode,
+ InvDepotId = c_depot_code,
+ ToInvDepotSectionsCode = p_section_code,
+ Description = "濮斿閫�鏂�",
+ CreateBy = c_user,
+ CreateDate = DateTime.Now,
+ LastupdateBy = c_user,
+ LastupdateDate = DateTime.Now,
+ TaskNo = c_mes_inv_item_barcodes.TaskNo,
+ BillNo = c_bill_no,
+ WorkNo = c_mes_inv_item_barcodes.WorkNo,
+ WorkLine = c_mes_inv_item_barcodes.WorkLine,
+ SuppId = c_mes_inv_item_barcodes.SuppId,
+ SuppNo = c_mes_inv_item_barcodes.SuppNo,
+ ItemId = c_mes_inv_item_barcodes.ItemId
+ }).IgnoreColumns(true).ExecuteCommand();
+
+ // 鎻掑叆搴撳瓨璁板綍
+ totalResult += db.Insertable(new MesInvItemStocks
+ {
+ Guid = Guid.NewGuid(),
+ TaskNo = c_mes_inv_item_barcodes.TaskNo,
+ ItemBarcode = p_item_barcode,
+ ItemNo = c_mes_inv_item_barcodes.ItemNo,
+ LotNo = c_mes_inv_item_barcodes.LotNo,
+ Quantity = c_mes_inv_item_barcodes.Quantity,
+ //EpFlag = c_mes_inv_item_barcodes.EpFlag.Value
+ // ? (byte)1
+ // : (byte)0,
+ DepotId = c_mes_depots.DepotId,
+ DepotsCode = c_mes_depots.DepotCode,
+ DepotSectionsCode = p_section_code,
+ CheckDate = c_mes_inv_item_barcodes.CreateDate,
+ IndepDate = DateTime.Now,
+ BoardStyle = c_mes_inv_item_barcodes.BoardStyle,
+ WorkNo = c_mes_inv_item_barcodes.WorkNo,
+ WorkLine = c_mes_inv_item_barcodes.WorkLine,
+ SuppNo = c_mes_inv_item_barcodes.SuppNo,
+ ItemId = c_mes_inv_item_barcodes.ItemId,
+ BillNo = c_mes_inv_item_barcodes.BillNo,
+ //DepotId = Convert.ToInt32(c_depot_code),
+ OwnerId = WWCAB.Owner,
+ OwnerType = WWCAB.OwnerType,
+ StockOrgId = c_mes_depots.FSubsidiary,
+ IndepUserCode = c_user
+ }).IgnoreColumns(true).ExecuteCommand();
+
+ // 鏍规嵁閫�鏂欑被鍨�(鑹搧閫�鏂欍�佹潵鏂欎笉鑹��鏂欍�佷綔涓氫笉鑹��鏂�)鏇存柊鐩稿叧鏁版嵁
+ if (C_MES_ITEM_TBL.Tbl005 is "鑹搧閫�鏂�" or "鏉ユ枡涓嶈壇閫�鏂�")
+ {
+ // 鑹搧閫�鏂� - 鏇存柊宸ュ崟琛�(WOMDAB)鐩稿叧鏁伴噺
+ if (C_MES_ITEM_TBL.Tbl005 == "鑹搧閫�鏂�")
+ totalResult += Db.Updateable<Womdab>()
+ .SetColumns(it => new Womdab
+ {
+ Dab007 = it.Dab007 -
+ c_mes_inv_item_barcodes.Quantity, // 鍑忓皯宸ュ崟鏁伴噺
+ Dab022 = (it.Dab022 ?? 0) +
+ c_mes_inv_item_barcodes.Quantity, // 澧炲姞閫�鏂欐暟閲�
+ LpTl = (it.LpTl ?? 0) +
+ (int)c_mes_inv_item_barcodes
+ .Quantity, // 澧炲姞鑹搧閫�鏂欐暟閲�
+ Dab020 = (it.Dab020 ?? 0) -
+ c_mes_inv_item_barcodes.Quantity // 鍑忓皯宸插彂鏂欐暟閲�
+ })
+ .Where(it => it.Dab001 == c_mes_inv_item_barcodes.WorkNo
+ && it.Dab002 == c_mes_inv_item_barcodes
+ .WorkLine
+ && it.Dab003 == c_mes_inv_item_barcodes
+ .ItemId.ToString())
+ .ExecuteCommand();
+ // 鏉ユ枡涓嶈壇閫�鏂� - 鏇存柊宸ュ崟琛�(WOMDAB)鐩稿叧鏁伴噺
+ else if (C_MES_ITEM_TBL.Tbl005 == "鏉ユ枡涓嶈壇閫�鏂�")
+ totalResult += Db.Updateable<Womdab>()
+ .SetColumns(it => new Womdab
+ {
+ Dab007 = it.Dab007 -
+ c_mes_inv_item_barcodes.Quantity, // 鍑忓皯宸ュ崟鏁伴噺
+ Dab022 = (it.Dab022 ?? 0) +
+ c_mes_inv_item_barcodes.Quantity, // 澧炲姞閫�鏂欐暟閲�
+ LlBl = (it.LlBl ?? 0) +
+ (int)c_mes_inv_item_barcodes
+ .Quantity, // 澧炲姞鏉ユ枡涓嶈壇鏁伴噺
+ Dab020 = (it.Dab020 ?? 0) -
+ c_mes_inv_item_barcodes.Quantity // 鍑忓皯宸插彂鏂欐暟閲�
+ })
+ .Where(it => it.Dab001 == c_mes_inv_item_barcodes.WorkNo
+ && it.Dab002 == c_mes_inv_item_barcodes
+ .WorkLine
+ && it.Dab003 == c_mes_inv_item_barcodes
+ .ItemId.ToString())
+ .ExecuteCommand();
+
+ // 鏇存柊閫�鏂欏崟鏄庣粏琛ㄥ凡閫�鏁伴噺
+ totalResult += Db.Updateable<MesItemTblDetail>()
+ .SetColumns(it => new MesItemTblDetail
+ {
+ Tld006 = (it.Tld006 ?? 0) +
+ (int)c_mes_inv_item_barcodes.Quantity // 澧炲姞宸查��鏁伴噺
+ })
+ .Where(it => it.Tlmid == C_MES_ITEM_TBL.Id
+ && it.Tld009 == c_mes_inv_item_barcodes.ItemId)
+ //&& it.Tld010 ==
+ //c_mes_inv_item_barcodes.WorkLine)
+ .ExecuteCommand();
+ }
+ // 浣滀笟涓嶈壇閫�鏂� - 鏇存柊宸ュ崟琛ㄥ拰閫�鏂欏崟鏄庣粏琛�
+ else if (C_MES_ITEM_TBL.Tbl005 == "浣滀笟涓嶈壇閫�鏂�")
+ {
+ totalResult += Db.Updateable<Womdab>()
+ .SetColumns(it => new Womdab
+ {
+ Dab022 = (it.Dab022 ?? 0) +
+ c_mes_inv_item_barcodes.Quantity, // 澧炲姞閫�鏂欐暟閲�
+ ZyBl = (it.ZyBl ?? 0) +
+ (int)c_mes_inv_item_barcodes
+ .Quantity, // 澧炲姞浣滀笟涓嶈壇鏁伴噺
+ Dab020 = (it.Dab020 ?? 0) -
+ c_mes_inv_item_barcodes.Quantity // 鍑忓皯宸插彂鏂欐暟閲�
+ })
+ .Where(it => it.Dab001 == c_mes_inv_item_barcodes.WorkNo
+ && it.Dab002 ==
+ c_mes_inv_item_barcodes.WorkLine
+ && it.Dab003 == c_mes_inv_item_barcodes.ItemId
+ .ToString())
+ .ExecuteCommand();
+
+ // 鏇存柊閫�鏂欏崟鏄庣粏琛ㄥ凡閫�鏁伴噺
+ totalResult += Db.Updateable<MesItemTblDetail>()
+ .SetColumns(it => new MesItemTblDetail
+ {
+ Tld006 = (it.Tld006 ?? 0) +
+ (int)c_mes_inv_item_barcodes.Quantity // 澧炲姞宸查��鏁伴噺
+ })
+ .Where(it => it.Tlmid == C_MES_ITEM_TBL.Id
+ && it.Tld009 == c_mes_inv_item_barcodes.ItemId)
+ //&& it.Tld010 ==
+ //c_mes_inv_item_barcodes.WorkLine)
+ .ExecuteCommand();
+ }
+
+ // 濡傛灉寰呴��鏁伴噺绛変簬鏈閫�鏂欐暟閲忥紝鍒欐洿鏂版槑缁嗗畬鎴愮姸鎬�
+ if ((C_MES_ITEM_TBL_DETAIL.Tld005 ?? 0) -
+ (C_MES_ITEM_TBL_DETAIL.Tld006 ?? 0) ==
+ c_mes_inv_item_barcodes.Quantity)
+ totalResult += Db.Updateable<MesItemTblDetail>()
+ .SetColumns(it => new MesItemTblDetail
+ { Tld008 = 1 }) // 璁剧疆瀹屾垚鏍囧織
+ .Where(it => it.Tlid == C_MES_ITEM_TBL_DETAIL.Tlid)
+ .ExecuteCommand();
+
+ // 妫�鏌ラ��鏂欏崟鏄惁鎵�鏈夋槑缁嗛兘宸插畬鎴�
+ var remainingCount = Db.Queryable<MesItemTbl, MesItemTblDetail>(
+ (a, b) =>
+ new JoinQueryInfos(JoinType.Left, a.Id == b.Tlmid))
+ .Where((a, b) =>
+ a.BillNo == p_bill_no &&
+ (b.Tld005 ?? 0) - (b.Tld006 ?? 0) > 0)
+ .Count();
+
+ // 濡傛灉鎵�鏈夋槑缁嗛兘宸插畬鎴愶紝鍒欐洿鏂伴��鏂欏崟鐘舵�佷负宸插畬鎴�
+ if (remainingCount < 1)
+ totalResult += Db.Updateable<MesItemTbl>()
+ .SetColumns(it => it.Tbl020 == 1) // 璁剧疆瀹屾垚鏍囧織
+ .Where(it => it.BillNo == p_bill_no)
+ .ExecuteCommand();
+
+ // 妫�鏌ュ繀瑕佺殑鎻掑叆鎿嶄綔鏄惁閮芥垚鍔熸墽琛�
+ var minimumExpectedOperations = 3; // 鑷冲皯闇�瑕佹墽琛岀殑鎻掑叆鎿嶄綔鏁�
+ if (totalResult < minimumExpectedOperations)
+ throw new Exception(
+ $"鍏抽敭鏁版嵁鎻掑叆澶辫触锛岄鏈熻嚦灏憑minimumExpectedOperations}涓搷浣滐紝瀹為檯鎵ц{totalResult}涓搷浣�");
+
+ // 鍒涘缓 鎻掑叆鏃ュ織
+ var logService = new LogService();
+ var LogMsg = "[PDA]濮斿閫�鏂欍�傛潯鐮併��" + query.barcode + "銆� 閫�鏂欏崟鍙枫��" + c_bill_no + "銆�";
+ logService.CreateLog(db, query.userName, wwgd.Id.ToString(), "WW_GD", LogMsg, wwgd.Daa001);
+
+ return totalResult;
+ });
+
+ query.itemNo = c_mes_inv_item_barcodes.ItemNo;
+ query.Num = c_quantity.Value;
+ return query;
+ }
+
+ #endregion
+
+ #region 濮斿琛ユ枡
+
+ /// <summary>
+ /// 濮斿宸ュ崟琛ユ枡鎵爜
+ /// 鎵弿鏉$爜 prc_rf_pda_scan_zout_barcode3
+ /// </summary>
+ /// <param name="query">鏌ヨ鍙傛暟</param>
+ /// <returns>鎵弿缁撴灉</returns>
+ /// <remarks>
+ /// 鍙傛暟璇存槑:
+ /// - billNo: 鍗曟嵁鍙�(蹇呭~)
+ /// - barcode: 鏉$爜(蹇呭~)
+ /// - userName: 鐢ㄦ埛鍚�
+ /// - blNo: 琛ユ枡鍗曞彿(蹇呭~)
+ /// </remarks>
+ public (WarehouseQuery item, List<MesItemBlDetail> pendingList)
+ WwblScanBarcode(WarehouseQuery query)
+ {
+ if (string.IsNullOrEmpty(query.billNo))
+ throw new Exception("璇烽�夊彇鍗曟嵁鍙凤紒");
+
+ if (string.IsNullOrEmpty(query.barcode))
+ throw new Exception("璇锋壂鎻忔潯鐮侊紒");
+
+ if (string.IsNullOrEmpty(query.userName))
+ throw new Exception("鐢ㄦ埛鍚嶄笉鑳戒负绌猴紒");
+
+ if (string.IsNullOrEmpty(query.blNo))
+ throw new Exception("琛ユ枡鍗曞彿涓嶈兘涓虹┖锛�");
+
+
+ // 妫�楠屾槸鍚﹂噸澶嶆壂鎻�
+ var exists = Db.Queryable<MesInvItemOutCDetails>()
+ .Where(b => b.ItemBarcode == query.barcode)
+ .Any();
+
+ if (exists)
+ throw new Exception("姝ゆ潯鐮佸凡鎵弿,鍕块噸澶嶆壂鐮侊紒");
+
+ // 鏌ヨ鏉$爜搴撳瓨淇℃伅
+ var stockBarcode = Db.Queryable<MesInvItemStocks>()
+ .Where(t => t.ItemBarcode == query.barcode && t.Quantity > 0)
+ .First();
+
+ if (stockBarcode == null)
+ throw new Exception($"搴撳瓨涓棤姝ゆ潯鐮�,璇锋牳瀵癸紒{query.barcode}");
+
+ // 妫�鏌ヨˉ鏂欏崟鐘舵��
+ var mesItemBl = Db.Queryable<MesItemBl>()
+ .Where(a => a.BlNo == query.blNo)
+ .First();
+
+ if (mesItemBl == null)
+ throw new Exception($"鐢宠鍗� {query.blNo} 宸叉挙鍥烇紒");
+
+ if (mesItemBl.Bl018 != true)
+ throw new Exception($"鐢宠鍗� {query.blNo} 鏈鏍革紒");
+
+ if (mesItemBl.Bl019 == true)
+ throw new Exception($"鐢宠鍗� {query.blNo} 宸插畬缁擄紒");
+
+ // 鑾峰彇琛ユ枡鍗曟槑缁嗗苟鏍¢獙
+ var blDetail = Db.Queryable<MesItemBlDetail>()
+ .Where(b =>
+ b.Mid == mesItemBl.Id && b.Bld012 == stockBarcode.ItemId && b.Bld007 > b.Bld008)
+ .First();
+
+ if (blDetail == null)
+ throw new Exception($"鐢宠鍗曚笉瀛樺湪姝ょ墿鏂� {stockBarcode.ItemNo} 璇风‘璁わ紒");
+
+ // 妫�鏌ュ緟琛ユ暟閲�
+ var quantity = (blDetail.Bld007 ?? 0) - (blDetail.Bld008 ?? 0);
+ if (quantity == 0)
+ throw new Exception("鐗╂枡宸叉壂鐮佸畬鎴愶紝璇锋牳瀵癸紒");
+
+ // 妫�鏌ュ伐鍗曚俊鎭�
+ var wwgd = Db.Queryable<WwGd>()
+ .Where(a => a.Daa001 == query.billNo)
+ .First();
+
+ // 妫�鏌ュ伐鍗曚俊鎭�
+ var WWRWD = Db.Queryable<ProductionOrder>()
+ .Where(a => a.OrderNo == wwgd.Daa014)
+ .First();
+
+ if (wwgd == null)
+ throw new Exception($"宸ュ崟 {query.billNo} 涓嶅瓨鍦紝璇风‘璁わ紒");
+
+ // 妫�鏌ュ鏂欐槑缁�
+ var womdab = Db.Queryable<WwGdDetail>()
+ .Where(b => b.Dab001 == query.billNo && b.Erpid == blDetail.Bld014)
+ .First();
+
+ if (womdab == null)
+ throw new Exception($"澶囨枡鏄庣粏涓嶅瓨鍦ㄦ鐗╂枡 {stockBarcode.ItemNo} 璇风‘璁わ紒");
+
+
+ var depots = Db.Queryable<MesDepots>()
+ .Where(t => t.DepotId == stockBarcode.DepotId)
+ .First();
+
+ if (stockBarcode.Quantity > quantity)
+ {
+ // 鑾峰彇寰呭彂鏂欐槑缁嗗垪琛�
+ var pendingList = Db.Queryable<MesItemBl, MesItemBlDetail>((a, b) =>
+ new JoinQueryInfos(JoinType.Left, a.Id == b.Mid))
+ .Where((a, b) => a.BlNo == query.blNo
+ && (b.Bld007 ?? 0) - (b.Bld008 ?? 0) > 0)
+ .Select((a, b) => new MesItemBlDetail
+ {
+ Bld012 = b.Bld012,
+ Bld002 = b.Bld002,
+ Bld003 = b.Bld003,
+ Bld004 = b.Bld004,
+ Bld007 = b.Bld007,
+ Bld008 = b.Bld008
+ })
+ .ToList();
+
+
+ query.Num = stockBarcode.Quantity;
+ query.Fum = quantity;
+
+ return (query, pendingList);
+ }
+
+ // 寮�鍚簨鍔″鐞�
+ var success = UseTransaction(db =>
+ {
+ //query.Type = "濮斿琛ユ枡";
+ var outNoType = "WWBL(濮斿琛ユ枡)";
+ if (query.Type == "濮斿琛ユ枡")
+ {
+ outNoType = "WWBL(濮斿琛ユ枡)";
+ }
+ else
+ {
+ outNoType = "WWCL(濮斿瓒呴)";
+ }
+ //outNoType = "WWBL(濮斿琛ユ枡)";
+ // 鑾峰彇鎴栧垱寤哄嚭搴撳崟
+ var outId = Guid.NewGuid();
+ var outNo = BillNo.GetBillNo(outNoType);
+
+ var existingOut = db.Queryable<MesInvItemOuts>()
+ .Where(a => a.TaskNo == query.blNo
+ && a.DepotId == stockBarcode.DepotId
+ && a.OutDate.Value.Date.ToString("yyyy-MM-dd") ==
+ DateTime.Now.Date.ToString("yyyy-MM-dd")
+ && a.BillTypeId == 200
+ && a.TransactionNo == 209
+ && a.Status == 0)
+ .First();
+
+ if (existingOut != null)
+ {
+ outId = existingOut.Guid;
+ outNo = existingOut.ItemOutNo;
+ }
+ else
+ {
+ // 鎻掑叆鍑哄簱鍗曚富琛�
+ db.Insertable(new MesInvItemOuts
+ {
+ Guid = outId,
+ ItemOutNo = outNo,
+ TaskNo = query.blNo,
+ CreateBy = query.userName,
+ CreateDate = DateTime.Now,
+ LastupdateBy = query.userName,
+ LastupdateDate = DateTime.Now,
+ BillTypeId = 200,
+ TransactionNo = 209,
+ Remark = mesItemBl.Bl007,
+ DepotCode = depots.DepotCode,
+ OutPart = wwgd.DepartId.ToString(),
+ OutType = query.Type,
+ FType = 0,
+ Factory = stockBarcode.Factory,
+ Company = stockBarcode.Company,
+ WorkNo = WWRWD.ErpProductionOrderNo,
+ BoardItem = wwgd.Daa003.ToString(),
+ PbillNo = wwgd.Daa001,
+ OutDate = DateTime.Now,
+ Status = 0,
+ DepotId = stockBarcode.DepotId,
+ THORGID = stockBarcode.StockOrgId,
+ //BbillNo = query.billNo
+ }).IgnoreColumns(true).ExecuteCommand();
+ }
+
+ // 妫�鏌ュ苟鏇存柊鍑哄簱鍗曠墿鏂欐槑缁�
+ var itemCount = db.Queryable<MesInvItemOutItems>()
+ .Where(i =>
+ i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId && i.ItemOutId == outId && i.DepotId == stockBarcode.DepotsId.ToString())
+ .Count();
+
+ if (itemCount > 0)
+ // 鏇存柊宸插瓨鍦ㄧ殑鐗╂枡鏄庣粏鏁伴噺
+ db.Updateable<MesInvItemOutItems>()
+ .SetColumns(i =>
+ i.TlQty == i.TlQty + stockBarcode.Quantity)
+ .Where(i =>
+ i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId && i.ItemOutId == outId && i.DepotId == stockBarcode.DepotsId.ToString())
+ .ExecuteCommand();
+ else
+ // 鎻掑叆鏂扮殑鐗╂枡鏄庣粏璁板綍
+ db.Insertable(new MesInvItemOutItems
+ {
+ Guid = Guid.NewGuid(),
+ ItemOutId = outId,
+ ItemNo = blDetail.Bld002,
+ Quantity = stockBarcode.Quantity,
+ TlQty = stockBarcode.Quantity,
+ CreateBy = query.userName,
+ CreateDate = DateTime.Now,
+ LastupdateBy = query.userName,
+ LastupdateDate = DateTime.Now,
+ Factory = stockBarcode.Factory,
+ Company = stockBarcode.Company,
+ DepotCode = depots.DepotCode,
+ TaskNo = query.blNo,
+ WorkNo = WWRWD.ErpProductionOrderNo,
+ WorkLine = blDetail.Bld013,
+ ErpItemNo = womdab.Dab003.ToString(),
+ ErpId = womdab.Eid,
+ ErpAutoid = womdab.Erpid,
+ PbillNo = query.billNo,
+ ItemId = blDetail.Bld012,
+ DepotId = stockBarcode.DepotId.ToString(),
+ ItemDabid = blDetail.Id,
+ //AboutGuid = womdab.Id
+ // Unit = blDetail.Bld009,
+ // DepotId = (int)stockBarcode.DepotsId
+ }).IgnoreColumns(true).ExecuteCommand();
+
+ // 鎻掑叆鍑哄簱鍗曟潯鐮佹槑缁�
+ db.Insertable(new MesInvItemOutCDetails
+ {
+ Guid = Guid.NewGuid(),
+ ItemOutId = outId,
+ ItemBarcode = stockBarcode.ItemBarcode,
+ ItemNo = stockBarcode.ItemNo,
+ LotNo = stockBarcode.LotNo,
+ Quantity = stockBarcode.Quantity,
+ ForceOutFlag = 0,
+ CreateBy = query.userName,
+ CreateDate = DateTime.Now,
+ LastupdateBy = query.userName,
+ LastupdateDate = DateTime.Now,
+ DepotCode = depots.DepotCode,
+ DepotSectionCode = stockBarcode.DepotSectionsCode,
+ Remark = blDetail.Bld010,
+ Factory = stockBarcode.Factory,
+ Company = stockBarcode.Company,
+ TaskNoy = mesItemBl.Bl013,
+ BoardStyle = mesItemBl.Bl002,
+ TaskNo = query.blNo,
+ WorkNo = blDetail.Bld001,
+ WorkLine = blDetail.Bld013,
+ SuppNo = stockBarcode.SuppNo,
+ PbillNo = query.billNo,
+ ItemId = blDetail.Bld012,
+ Unit = blDetail.Bld009,
+ DepotId = (int)stockBarcode.DepotId,
+ EbelnK3id = womdab.Eid,
+ LineK3id = womdab.Erpid
+ }).IgnoreColumns(true).ExecuteCommand();
+
+ // 鎻掑叆涓氬姟浜ゆ槗璁板綍
+ db.Insertable(new MesInvBusiness2
+ {
+ Guid = Guid.NewGuid(),
+ Status = 1,
+ BillTypeId = 200, // p_bill_type_id
+ TransactionCode = "209", // p_transaction_no
+ BusinessType = -1,
+ ItemBarcode = stockBarcode.ItemBarcode,
+ ItemNo = stockBarcode.ItemNo,
+ LotNo = stockBarcode.LotNo,
+ EpFlag = true,
+ Quantity = stockBarcode.Quantity,
+ FromInvDepotsCode = stockBarcode.DepotsCode,
+ FromInvDepotSectionsCode = stockBarcode.DepotSectionsCode,
+ CreateBy = query.userName,
+ CreateDate = DateTime.Now,
+ LastupdateBy = query.userName,
+ LastupdateDate = DateTime.Now,
+ Factory = stockBarcode.Factory,
+ Company = stockBarcode.Company,
+ TaskNo = mesItemBl.Bl012, // Matches C_QTCK.Bl012
+ BillNo = query.blNo,
+ WorkNo = blDetail.Bld001, // Matches C_QTCK_D.Bld001
+ WorkLine = blDetail.Bld013, // Matches C_QTCK_D.Bld013
+ SuppNo = stockBarcode.SuppNo,
+ ItemId = stockBarcode.ItemId
+ // CkDepot = stockBarcode.DepotsId
+ }).IgnoreColumns(true).ExecuteCommand();
+
+
+ // 鏇存柊宸ュ崟琛ㄦ暟閲�
+ db.Updateable<WwGdDetail>()
+ .SetColumns(it => new WwGdDetail
+ {
+ Dab007 = (it.Dab007 ?? 0) + (int)stockBarcode.Quantity,
+ Dab020 = (it.Dab020 ?? 0) + (int)stockBarcode.Quantity,
+ Dab021 = (it.Dab021 ?? 0) + (int)stockBarcode.Quantity
+ })
+ .Where(it => it.Id == womdab.Id && it.Dab003 == womdab.Dab003)
+ .ExecuteCommand();
+
+
+ // 鏇存柊琛ユ枡鍗曟槑缁嗗凡琛ユ暟閲�
+ db.Updateable<MesItemBlDetail>()
+ .SetColumns(it => new MesItemBlDetail
+ {
+ Bld008 = (it.Bld008 ?? 0) + (int)stockBarcode.Quantity
+ })
+ .Where(it => it.Id == blDetail.Id)
+ .ExecuteCommand();
+
+ // 妫�鏌ヨˉ鏂欏崟鏄庣粏鏄惁瀹屾垚
+ var blDetail1 = db.Queryable<MesItemBlDetail>()
+ .Where(it => it.Id == blDetail.Id)
+ .First();
+
+ if ((blDetail1.Bld007 ?? 0) <= (blDetail1.Bld008 ?? 0))
+ // 鏇存柊鏄庣粏瀹屾垚鐘舵��
+ db.Updateable<MesItemBlDetail>()
+ .SetColumns(it => it.Bld011 == 1)
+ .Where(it => it.Id == blDetail1.Id)
+ .ExecuteCommand();
+
+ // 鏇存柊搴撳瓨鏁伴噺涓�0
+ db.Updateable<MesInvItemStocks>()
+ .SetColumns(it => it.Quantity == 0)
+ .Where(it => it.Guid == stockBarcode.Guid)
+ .ExecuteCommand();
+
+
+ // 妫�鏌ユ槸鍚︽墍鏈夋槑缁嗛兘宸插畬鎴�
+ var unfinishedDetail = db.Queryable<MesItemBlDetail>()
+ .LeftJoin<MesItemBl>((b, a) => a.Id == b.Mid)
+ .Where((b, a) => a.BlNo == query.blNo && (b.Bld011 ?? 0) == 0)
+ .Select((b, a) => b)
+ .First();
+
+ if (unfinishedDetail == null)
+ // 濡傛灉娌℃湁鏈畬鎴愮殑鏄庣粏锛屾洿鏂拌ˉ鏂欏崟鐘舵�佷负宸插畬鎴�
+ db.Updateable<MesItemBl>()
+ .SetColumns(it => new MesItemBl
+ {
+ Bl019 = true,
+ WcUser = query.userName,
+ WcTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ })
+ .Where(it => it.Id == mesItemBl.Id)
+ .ExecuteCommand();
+
+ // 鍒涘缓 鎻掑叆鏃ュ織
+ var logService = new LogService();
+ var LogMsg = "[PDA]"+query.Type + "銆傛潯鐮併��" +query.barcode+"銆� 鏁伴噺銆�"+ stockBarcode.Quantity.ToString() + "銆� 鍑哄簱鍗曞彿銆�"+ outNo +"銆�";
+ logService.CreateLog(db,query.userName,wwgd.Id.ToString(), "WW_GD", LogMsg,wwgd.Daa001);
+
+ return 1;
+ });
+
+ // 鑾峰彇鏈�缁堢殑寰呭彂鏂欐槑缁嗗垪琛�
+ var finalPendingList = Db.Queryable<MesItemBl, MesItemBlDetail>(
+ (a, b) =>
+ new JoinQueryInfos(JoinType.Left, a.Id == b.Mid))
+ .Where((a, b) => a.BlNo == query.blNo
+ && (b.Bld007 ?? 0) - (b.Bld008 ?? 0) > 0)
+ .Select((a, b) => new MesItemBlDetail
+ {
+ Bld012 = b.Bld012,
+ Bld002 = b.Bld002,
+ Bld003 = b.Bld003,
+ Bld004 = b.Bld004,
+ Bld007 = b.Bld007,
+ Bld008 = b.Bld008
+ })
+ .ToList();
+
+ return (query, finalPendingList);
+ }
+
+ /// <summary>
+ /// 鐢熶骇琛ユ枡鍗曟潯鐮佹媶鍒� prc_rf_pda_prnt_zout_barcode2
+ /// </summary>
+ /// <param name="query">鏌ヨ鍙傛暟</param>
+ /// <returns>(鎴愬姛鏍囧織, 寰呭鐞嗗垪琛�)</returns>
+ /// <remarks>
+ /// 鍓嶅彴闇�瑕佷紶鍏ョ殑鍙傛暟:
+ /// - userName: 鐢ㄦ埛鍚�(蹇呭~)
+ /// - billNo: 宸ュ崟鍙�(蹇呭~)
+ /// - barcode: 鐗╂枡鏉$爜(蹇呭~)
+ /// - Num: 鍙戞枡鏁伴噺(蹇呭~,蹇呴』澶т簬0)
+ /// - blNo: 琛ユ枡鍗曞彿(蹇呭~)
+ /// </remarks>
+ public (bool success, List<MesItemBlDetail> pendingList) SplitBarcode(
+ WarehouseQuery query)
+ {
+ if (string.IsNullOrEmpty(query.userName))
+ throw new Exception("鐢ㄦ埛鍚嶄笉鑳戒负绌猴紒");
+
+ if (string.IsNullOrEmpty(query.billNo))
+ throw new Exception("璇烽�夊彇鍗曟嵁鍙凤紒");
+
+ if (string.IsNullOrEmpty(query.barcode))
+ throw new Exception("璇锋壂鎻忔潯鐮侊紒");
+
+ if (query.Num <= 0)
+ throw new Exception("璇疯緭鍏ユ纭殑鍙戞枡鏁伴噺锛�");
+
+ if (string.IsNullOrEmpty(query.blNo))
+ throw new Exception("琛ユ枡鍗曞彿涓嶈兘涓虹┖锛�");
+
+
+ // 妫�楠屾槸鍚﹂噸澶嶆壂鎻�
+ var exists = Db.Queryable<MesInvItemOutCDetails>()
+ .Where(b => b.ItemBarcode == query.barcode)
+ .Any();
+
+ if (exists)
+ throw new Exception("姝ゆ潯鐮佸凡鎵弿,鍕块噸澶嶆壂鐮侊紒");
+
+ // 鏌ヨ鏉$爜搴撳瓨淇℃伅
+ var stockBarcode = Db.Queryable<MesInvItemStocks>()
+ .Where(t => t.ItemBarcode == query.barcode && t.Quantity > 0)
+ .First();
+
+ if (stockBarcode == null)
+ throw new Exception($"搴撳瓨涓棤姝ゆ潯鐮�,璇锋牳瀵癸紒{query.barcode}");
+
+ var totalQty = stockBarcode.Quantity;
+ string newBarcode = null;
+
+ // 寮�鍚簨鍔″鐞�
+ var success = UseTransaction(db =>
+ {
+ var executeCommand = 0;
+
+ // 鎷嗗垎鏉$爜
+ if (totalQty > query.Num)
+ {
+ var mesItems = db.Queryable<MesItems>()
+ .Where(s => s.Id == stockBarcode.ItemId).First();
+
+ // 鐢熸垚鏂版潯鐮佸彿
+ newBarcode = BillNo.GetBillNo("TM(鏉$爜)", mesItems.ItemNo);
+
+ // 鍐欏叆鏂版潯鐮�
+ executeCommand += db.Insertable(new MesInvItemBarcodes
+ {
+ Guid = Guid.NewGuid(),
+ ItemBarcode = newBarcode,
+ CustNo = stockBarcode.CustomerNo,
+ // ProductCode = stockBarcode.ProductCode,
+ // ItemBarcode2 = stockBarcode.ItemBarcode2,
+ // ItemCode = stockBarcode.ItemCode,
+ ItemNo = stockBarcode.ItemNo,
+ LotNo = stockBarcode.LotNo,
+ Quantity = query.Num,
+ EpFlag = true,
+ TaskNo = stockBarcode.TaskNo,
+ CreateBy = query.userName,
+ CreateDate = DateTime.Now,
+ LastupdateBy = query.userName,
+ LastupdateDate = DateTime.Now,
+ OldItemBarcode = query.barcode,
+ // Mblnr = stockBarcode.Mblnr,
+ // Zeile = stockBarcode.Zeile,
+ // RohInId = stockBarcode.RohInId,
+ Barcodestatus = false,
+ Oldqty = query.Num as long?,
+ // Unit = stockBarcode.Unit,
+ // WeightUnit = stockBarcode.WeightUnit,
+ Factory = stockBarcode.Factory,
+ Company = stockBarcode.Company,
+ BillNo = stockBarcode.BillNo,
+ BoardStyle = stockBarcode.BoardStyle,
+ // ColorName = stockBarcode.ColorName,
+ WorkNo = stockBarcode.WorkNo,
+ WorkLine = stockBarcode.WorkLine,
+ // MemoBad = stockBarcode.MemoBad,
+ ComeFlg = 5,
+ // Memo = stockBarcode.Memo,
+ SuppId = stockBarcode.SuppId,
+ SuppNo = stockBarcode.SuppNo,
+ InsDate = stockBarcode.IndepDate, // Added InsDate
+ ItemId = stockBarcode.ItemId
+ // ItemUnit = stockBarcode.ItemUnit // Added ItemUnit
+ }).IgnoreColumns(true).ExecuteCommand();
+
+ // 鏇存柊鍘熸潯鐮佹暟閲�
+ executeCommand += db.Updateable<MesInvItemBarcodes>()
+ .SetColumns(it => it.Quantity == totalQty - query.Num)
+ .Where(it => it.ItemBarcode == query.barcode)
+ .ExecuteCommand();
+
+ // 鍒犻櫎鍘熸潯鐮佸簱瀛樿褰�
+ executeCommand += db.Deleteable<MesInvItemStocks>()
+ .Where(it => it.ItemBarcode == query.barcode)
+ .ExecuteCommand();
+
+ // 鎻掑叆鍓╀綑鏉$爜鏁伴噺鐨勬柊搴撳瓨璁板綍
+ executeCommand += db.Insertable(new MesInvItemStocks
+ {
+ Guid = Guid.NewGuid(),
+ TaskNo = stockBarcode.TaskNo,
+ ItemBarcode = stockBarcode.ItemBarcode,
+ ItemNo = stockBarcode.ItemNo,
+ LotNo = stockBarcode.LotNo,
+ Quantity = totalQty - query.Num,
+ EpFlag = stockBarcode.EpFlag,
+ CustomerNo = stockBarcode.CustomerNo,
+ ItemWt = stockBarcode.ItemWt,
+ DepotsCode = stockBarcode.DepotsCode,
+ DepotsId = stockBarcode.DepotsId,
+ DepotSectionsCode = stockBarcode.DepotSectionsCode,
+ CheckDate = stockBarcode.CheckDate,
+ ItemType = stockBarcode.ItemType,
+ IndepDate = stockBarcode.IndepDate,
+ Factory = stockBarcode.Factory,
+ Company = stockBarcode.Company,
+ IqcStatus = stockBarcode.IqcStatus,
+ BoardStyle = stockBarcode.BoardStyle,
+ WorkNo = stockBarcode.WorkNo,
+ WorkLine = stockBarcode.WorkLine,
+ SuppNo = stockBarcode.SuppNo,
+ ItemId = stockBarcode.ItemId
+ // UnitId = stockBarcode.ItemUnit
+ }).IgnoreColumns(true).ExecuteCommand();
+
+ // 鍐欏叆鏂版潯鐮佺殑浜ゆ槗璁板綍
+ executeCommand += db.Insertable(new MesInvBusiness2
+ {
+ Guid = Guid.NewGuid(),
+ Status = 1,
+ BillTypeId = 200, // p_bill_type_id
+ TransactionCode = "220", // p_transaction_no
+ BusinessType = -1,
+ ItemBarcode = newBarcode,
+ ItemNo = stockBarcode.ItemNo,
+ LotNo = stockBarcode.LotNo,
+ EpFlag = true,
+ Quantity = query.Num,
+ FromInvDepotsCode = null,
+ FromInvDepotSectionsCode = null,
+ ToInvDepotsCode = stockBarcode.DepotsCode,
+ ToInvDepotSectionsCode = stockBarcode.DepotSectionsCode,
+ Description = null,
+ CreateBy = query.userName,
+ CreateDate = DateTime.Now,
+ LastupdateBy = query.userName,
+ LastupdateDate = DateTime.Now,
+ Factory = stockBarcode.Factory,
+ Company = stockBarcode.Company,
+ TaskNo = stockBarcode.TaskNo,
+ BillNo = stockBarcode.BillNo,
+ WorkNo = stockBarcode.WorkNo,
+ WorkLine = stockBarcode.WorkLine,
+ SuppNo = stockBarcode.SuppNo,
+ SuppId = stockBarcode.SuppId,
+ ItemId = stockBarcode.ItemId
+ // CkDepot = stockBarcode.DepotsId
+ }).IgnoreColumns(true).ExecuteCommand();
+ }
+ else if (totalQty < query.Num)
+ {
+ throw new Exception("鍙戞枡鏁伴噺澶т簬鏉$爜鏁�,璇锋牳瀵癸紒");
+ }
+
+ if (string.IsNullOrEmpty(newBarcode)) newBarcode = query.barcode;
+
+ // 妫�鏌ヨˉ鏂欏崟鐘舵��
+ var mesItemBl = Db.Queryable<MesItemBl>()
+ .Where(a => a.BlNo == query.blNo && (a.Bl018 ?? false) == false)
+ .First();
+
+ if (mesItemBl == null)
+ throw new Exception($"鐢宠鍗� {query.blNo} 宸叉挙鍥烇紒");
+
+ if (mesItemBl.Bl018 != true)
+ throw new Exception($"鐢宠鍗� {query.blNo} 鏈鏍革紒");
+
+ if (mesItemBl.Bl019 == true)
+ throw new Exception($"鐢宠鍗� {query.blNo} 宸插畬缁擄紒");
+
+ // 鑾峰彇琛ユ枡鍗曟槑缁嗗苟鏍¢獙
+ var blDetail = Db.Queryable<MesItemBlDetail>()
+ .Where(b =>
+ b.Mid == mesItemBl.Id && b.Bld012 == stockBarcode.ItemId)
+ .First();
+
+ if (blDetail == null)
+ throw new Exception($"鐢宠鍗曚笉瀛樺湪姝ょ墿鏂� {stockBarcode.ItemNo} 璇风‘璁わ紒");
+
+ var remainingQty = (blDetail.Bld007 ?? 0) - (blDetail.Bld008 ?? 0);
+ if (remainingQty == 0)
+ throw new Exception("鐗╂枡宸叉壂鐮佸畬鎴愶紝璇锋牳瀵癸紒");
+
+ if (query.Num > remainingQty)
+ throw new Exception(
+ $"鎷嗗垎鏁伴噺锛歿query.Num} 澶т簬寰呭彂鏂欐暟閲忥細{remainingQty}锛岃鏍稿锛�");
+
+ // 妫�鏌ュ伐鍗曚俊鎭�
+ var womdaa = Db.Queryable<WwGd>()
+ .Where(a => a.Daa001 == query.billNo)
+ .First();
+
+ if (womdaa == null)
+ throw new Exception($"宸ュ崟 {query.billNo} 涓嶅瓨鍦紝璇风‘璁わ紒");
+
+ var womdab = Db.Queryable<WwGdDetail>()
+ .Where(b =>
+ b.Dab001 == query.billNo && b.Erpid == blDetail.Bld014)
+ .First();
+
+ if (womdab == null)
+ throw new Exception($"澶囨枡鏄庣粏涓嶅瓨鍦ㄦ鐗╂枡 {stockBarcode.ItemNo} 璇风‘璁わ紒");
+
+ // 妫�鏌ュ凡鍙戞枡鏁伴噺鏄惁瓒呰繃寰呭彂鏂欐暟閲�
+ var sumQty = db.Queryable<MesInvItemOutCDetails>()
+ .Where(it =>
+ it.TaskNo == query.blNo && it.ItemId == stockBarcode.ItemId)
+ .Sum(it => it.Quantity);
+
+ if (sumQty > remainingQty)
+ throw new Exception(
+ $"鎷嗗垎鏁伴噺锛歿sumQty} 澶т簬寰呭彂鏂欐暟閲忥細{remainingQty}锛岃鏍稿锛�");
+
+ // 鑾峰彇鎴栧垱寤哄嚭搴撳崟
+ var itemOut = db.Queryable<MesInvItemOuts>()
+ .Where(a => a.BbillNo == query.blNo
+ && a.DepotCode == womdab.Dab017
+ && a.OutDate.Value.Date.ToString("yyyy-MM-dd") ==
+ DateTime.Now.Date.ToString("yyyy-MM-dd")
+ && a.BillTypeId == 200
+ && a.TransactionNo == 220
+ && a.Status == 0)
+ .First();
+
+ if (itemOut == null)
+ {
+ // 鍒涘缓鏂扮殑鍑哄簱鍗�
+ var outId = Guid.NewGuid();
+ var outNo = BillNo.GetBillNo("BL(宸ュ崟琛ユ枡)");
+
+ // 鎻掑叆鍑哄簱鍗曚富琛�
+ executeCommand += db.Insertable(new MesInvItemOuts
+ {
+ Guid = outId,
+ ItemOutNo = outNo,
+ TaskNo = query.blNo,
+ CreateBy = query.userName,
+ CreateDate = DateTime.Now,
+ LastupdateBy = query.userName,
+ LastupdateDate = DateTime.Now,
+ BillTypeId = 200,
+ TransactionNo = 220,
+ Remark = mesItemBl.Bl007,
+ DepotCode = womdab.Dab017,
+ OutPart = womdaa.Daa013.ToString(),
+ FType = 0,
+ Factory = stockBarcode.Factory,
+ Company = stockBarcode.Company,
+ // WorkNo = womdaa.Daa021,
+ // BoardItem = womdaa.Daa002,
+ PbillNo = womdaa.Daa001,
+ OutDate = DateTime.Now,
+ Status = 0,
+ BbillNo = query.blNo
+ }).IgnoreColumns(true).ExecuteCommand();
+ }
+
+ // 妫�鏌ユ槸鍚﹀凡瀛樺湪鍑哄簱鍗曟槑缁�
+ var itemOutItemCount = db.Queryable<MesInvItemOutItems>()
+ .Where(it =>
+ it.ItemOutId == itemOut.Guid &&
+ it.ItemId == stockBarcode.ItemId)
+ .Count();
+
+ if (itemOutItemCount == 0)
+ // 鎻掑叆鏂扮殑鍑哄簱鍗曟槑缁�
+ executeCommand += db.Insertable(new MesInvItemOutItems
+ {
+ Guid = Guid.NewGuid(),
+ ItemOutId = itemOut.Guid,
+ ItemNo = blDetail.Bld002,
+ Quantity = query.Num,
+ CreateBy = query.userName,
+ CreateDate = DateTime.Now,
+ LastupdateBy = query.userName,
+ LastupdateDate = DateTime.Now,
+ Factory = stockBarcode.Factory,
+ Company = stockBarcode.Company,
+ DepotCode = womdab.Dab017,
+ TaskNo = query.blNo,
+ // WorkNo = womdaa.Daa021,
+ WorkLine = blDetail.Bld013,
+ ErpItemNo = womdab.Dab003.ToString(),
+ ErpId = womdab.Eid,
+ ErpAutoid = womdab.Erpid,
+ PbillNo = query.billNo,
+ ItemId = blDetail.Bld012
+ // Unit = blDetail.Bld009,
+ // DepotId = (int)stockBarcode.DepotsId
+ }).IgnoreColumns(true).ExecuteCommand();
+ else
+ // 鏇存柊宸叉湁鍑哄簱鍗曟槑缁嗘暟閲�
+ executeCommand += db.Updateable<MesInvItemOutItems>()
+ .SetColumns(it => it.Quantity == it.Quantity + query.Num)
+ .Where(it =>
+ it.ItemOutId == itemOut.Guid &&
+ it.ItemId == stockBarcode.ItemId)
+ .ExecuteCommand();
+
+ // 鎻掑叆鍑哄簱鏉$爜鏄庣粏
+ executeCommand += db.Insertable(new MesInvItemOutCDetails
+ {
+ Guid = Guid.NewGuid(),
+ ItemOutId = itemOut.Guid,
+ ItemBarcode = newBarcode ?? query.barcode,
+ ItemNo = stockBarcode.ItemNo,
+ LotNo = stockBarcode.LotNo,
+ Quantity = query.Num,
+ ForceOutFlag = 0,
+ CreateBy = query.userName,
+ CreateDate = DateTime.Now,
+ LastupdateBy = query.userName,
+ LastupdateDate = DateTime.Now,
+ DepotCode = stockBarcode.DepotsCode,
+ DepotSectionCode = stockBarcode.DepotSectionsCode,
+ Remark = blDetail.Bld010,
+ Factory = stockBarcode.Factory,
+ Company = stockBarcode.Company,
+ TaskNoy = mesItemBl.Bl013,
+ BoardStyle = mesItemBl.Bl002,
+ TaskNo = query.blNo,
+ WorkNo = blDetail.Bld001,
+ WorkLine = blDetail.Bld013,
+ SuppNo = stockBarcode.SuppNo,
+ PbillNo = query.billNo,
+ ItemId = blDetail.Bld012,
+ Unit = blDetail.Bld009,
+ DepotId = (int)stockBarcode.DepotsId
+ }).IgnoreColumns(true).ExecuteCommand();
+
+ // 鎻掑叆涓氬姟娴佹按
+ executeCommand += db.Insertable(new MesInvBusiness2
+ {
+ Guid = Guid.NewGuid(),
+ Status = 1,
+ BillTypeId = 200, // p_bill_type_id
+ TransactionCode = "210", // p_transaction_no
+ BusinessType = 1,
+ ItemBarcode = newBarcode ?? query.barcode,
+ ItemNo = stockBarcode.ItemNo,
+ LotNo = stockBarcode.LotNo,
+ EpFlag = true,
+ Quantity = query.Num,
+ FromInvDepotsCode = stockBarcode.DepotsCode,
+ FromInvDepotSectionsCode = stockBarcode.DepotSectionsCode,
+ Description = null,
+ CreateBy = query.userName,
+ CreateDate = DateTime.Now,
+ LastupdateBy = query.userName,
+ LastupdateDate = DateTime.Now,
+ Factory = stockBarcode.Factory,
+ Company = stockBarcode.Company,
+ TaskNo = mesItemBl.Bl012,
+ BillNo = query.blNo,
+ WorkNo = blDetail.Bld001,
+ WorkLine = blDetail.Bld013,
+ SuppNo = stockBarcode.SuppNo,
+ ItemId = stockBarcode.ItemId
+ // CkDepot = stockBarcode.DepotsId
+ }).IgnoreColumns(true).ExecuteCommand();
+
+ // 鏇存柊宸ュ崟琛ㄦ暟閲�
+ executeCommand += db.Updateable<WwGdDetail>()
+ .SetColumns(it => new WwGdDetail
+ {
+ Dab007 = (it.Dab007 ?? 0) + (int)query.Num, // 宸ュ崟鏁伴噺
+ Dab020 = (it.Dab020 ?? 0) + (int)query.Num, // 宸插彂鏂欐暟閲�
+ Dab021 = (it.Dab021 ?? 0) + (int)query.Num // 宸插彂鏂欐暟閲�
+ })
+ .Where(it => it.Id == womdab.Id && it.Dab003 == womdab.Dab003)
+ .IgnoreColumns(true)
+ .ExecuteCommand();
+
+ // 鏇存柊琛ユ枡鍗曟槑缁嗗凡琛ユ暟閲�
+ executeCommand += db.Updateable<MesItemBlDetail>()
+ .SetColumns(it => new MesItemBlDetail
+ {
+ Bld008 = (it.Bld008 ?? 0) + (int)query.Num
+ })
+ .Where(it => it.Id == blDetail.Id)
+ .ExecuteCommand();
+
+ // 鑾峰彇鏇存柊鍚庣殑琛ユ枡鍗曟槑缁嗘暟閲�
+ var updatedDetail = db.Queryable<MesItemBlDetail>()
+ .Where(it => it.Id == blDetail.Id)
+ .Select(it => new { it.Bld007, it.Bld008 })
+ .First();
+
+ if ((updatedDetail.Bld007 ?? 0) <= (updatedDetail.Bld008 ?? 0))
+ // 鏇存柊鏄庣粏瀹屾垚鐘舵��
+ executeCommand += db.Updateable<MesItemBlDetail>()
+ .SetColumns(it => new MesItemBlDetail { Bld011 = 1 })
+ .Where(it => it.Id == blDetail.Id)
+ .ExecuteCommand();
+
+ // 妫�鏌ユ槸鍚﹁繕鏈夋湭瀹屾垚鐨勬槑缁�
+
+ var unfinishedDetail = db.Queryable<MesItemBlDetail>()
+ .Where(it => it.Mid == mesItemBl.Id && (it.Bld011 ?? 0) == 0)
+ .First();
+
+ if (unfinishedDetail == null)
+ // 濡傛灉娌℃湁鎵惧埌鏈畬鎴愭槑缁嗭紝鍒欐洿鏂拌ˉ鏂欏崟鐘舵�佷负宸插畬鎴�
+ executeCommand += db.Updateable<MesItemBl>()
+ .SetColumns(it => new MesItemBl
+ {
+ Bl019 = true,
+ WcUser = query.userName,
+ WcTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ })
+ .Where(it => it.Id == mesItemBl.Id)
+ .ExecuteCommand();
+
+ if (executeCommand <= 1) throw new Exception("鏇存柊澶辫触");
+
+ return executeCommand;
+ }) > 0;
+
+ // 鑾峰彇鏈�缁堢殑寰呭彂鏂欐槑缁嗗垪琛�
+ var pendingList = Db.Queryable<MesItemBl, MesItemBlDetail>((a, b) =>
+ new JoinQueryInfos(JoinType.Left, a.Id == b.Mid))
+ .Where((a, b) => a.BlNo == query.blNo
+ && (b.Bld007 ?? 0) - (b.Bld008 ?? 0) > 0)
+ .Select((a, b) => new MesItemBlDetail
+ {
+ Bld012 = b.Bld012,
+ Bld002 = b.Bld002,
+ Bld003 = b.Bld003,
+ Bld004 = b.Bld004,
+ Bld007 = b.Bld007,
+ Bld008 = b.Bld008
+ })
+ .ToList();
+
+ return (success, pendingList);
+ }
+
+ #endregion
}
\ No newline at end of file
--
Gitblit v1.9.3