From 78af839e2e3dbe15283db12a816d54d31acb79c9 Mon Sep 17 00:00:00 2001
From: yusijie <ysj@hz-kingdee.com>
Date: 星期六, 13 九月 2025 22:15:45 +0800
Subject: [PATCH] 更新启用物料信息状态添加供应商过滤;新增送货物料信息物料id加组织过滤;条码档案数据信息处理;

---
 WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs |  151 ++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 109 insertions(+), 42 deletions(-)

diff --git a/WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs b/WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs
index debdad8..e75a97c 100644
--- a/WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs
+++ b/WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs
@@ -94,7 +94,8 @@
             string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
             string msg2 = sArray[0].ToString();//
             string msg3 = sArray[1].ToString();// 
-            string UserName = "";
+            string UserName = sArray[2].ToString();
+            string OrganizationID = sArray[3].ToString();
             ListModels oListModels = new ListModels();
             try
             {
@@ -104,10 +105,11 @@
                 msg2 = msg2.Replace("\n", "");  //\n
                 lsmain = oListModels.getObjectByJson_MaterialHanding(msg2);
                 int get_BarCodecount = 0;
+                
                 foreach (Model.Cls_MaterialHandingModel oItem in lsmain)
                 {
                     get_BarCodecount++;
-                    UserName = oItem.HMaker;
+                    //UserName = oItem.HMaker;
                 }
                 DAL.ClsWeb_BarCodeBill oBill = new DAL.ClsWeb_BarCodeBill();
                 msg3 = msg3.Substring(1, msg3.Length - 2);
@@ -118,6 +120,14 @@
 
                 ls = oListModels.getObjectByJson_BarCodeBill(msg3);//鍒楄〃鏁版嵁model
 
+                if (ls.Count > 1)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "姣忔鍙厑璁搁�夋嫨涓�涓墿鏂欑敓鎴愭潯鐮侊紝璇烽��鍑洪噸鏂伴�夋嫨涓�琛岀墿鏂欙紝涓嶅厑璁搁�夋嫨澶氳鐗╂枡锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
 
                 #region 鏁版嵁鍑嗗
                 long linterid = Pub_Class.ClsPub.CreateBillID_SRMProd("8888", ref DBUtility.ClsPub.sExeReturnInfo);
@@ -137,8 +147,12 @@
                 string HKFDate= ls[0].HKFDQDate==null? DateTime.Now.ToString("yyyy/MM/dd"): ls[0].HKFDQDate;//鐢熶骇鏃ユ湡
                 string HKFDate_1 = string.Join("", HKFDate.Split('/').Select(x => x.PadLeft(2, '0')));
                 double HMinQty= ls[0].HMinQty;//鏍囧噯鍖呰鏁�
+                string HStatusMan = ls[0].HStatusMan;//宸ュ彿
+                //string HBarCodeDate = ls[0].HBarCodeDate;//宸ュ彿
+                string HBarCodeDate = ls[0].HBarCodeDate == null ? DateTime.Now.ToString("yyyy/MM/dd") : ls[0].HBarCodeDate;//鏉$爜鏃ユ湡
+                string HBarCodeDate_1 = string.Join("", HBarCodeDate.Split('-').Select(x => x.PadLeft(2, '0')));
 
-                double HBQty= ls[0].HBQty;//鏈�灏忓寘瑁呮暟
+                double HBQty = ls[0].HBQty;//鏈�灏忓寘瑁呮暟
                 long HISKFPERIOD= ls[0].HISKFPERIOD;//鏄惁鍚敤淇濊川鏈�
                 long HBatchManager= ls[0].HBatchManager;//鏄惁鍚敤鎵瑰彿
 
@@ -151,8 +165,7 @@
                 string HMaterShortNumber = ls[0].HMaterShortNumber;
                 string HMaterName = ls[0].HMaterName;
                 //渚涘簲鍟�
-                long HSupID= ls[0].HSupID;
-                string HSupName= ls[0].HSupName;
+                long HSupID = lsmain[0].HSupID;
                 string HMaker= ls[0].HMaker;
                 DateTime HMakeDate= ls[0].HMakeDate;
                 double HQty= ls[0].HQty; //鏈鐢熸垚鏉$爜鏁伴噺
@@ -161,12 +174,19 @@
         DataSet Ds;
                 SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                 oCn.BeginTran();
-                Ds = oCn.RunProcReturn("exec GetLSH '" + DateTime.Today + "'", "GetLSH");
+                //Ds = oCn.RunProcReturn("exec GetLSH '" + DateTime.Today + "'", "GetLSH");
+                Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HSupID+"_"+ HMaterID+"_" + HBarCodeDate + "'", "GetLSH");
                 LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                 #endregion
 
+                //// 瀛樺偍鐢熸垚鐨勬潯鐮佸垪琛�
+                List<string> generatedBarcodes = new List<string>();
+
+                var biaoqianCount = 0;
                 foreach (Model.ClsGy_MaterialBarCodeBillModel oItemSub in ls)
                 {
+                    biaoqianzhangshu = ls[biaoqianCount].biaoqianzhangshu;
+                    biaoqianCount++;
                     //鏁伴噺涓�0 璺宠繃
                     if (oItemSub.HQty == 0 || oItemSub.HMinQty == 0 )
                         continue;
@@ -187,25 +207,6 @@
                         return objJsonResult;
                     }
                     string sql = "";
-                    //鏍¢獙鎵瑰彿 鍜� 鐢熶骇鏃ユ湡
-                    //string sql = $"select top 1 HKFDate from Gy_BarCodeBill where HSupID = '{oItemSub.HSupID}' and HBatchNo = '{HBatchNo.TrimStart().TrimEnd()}' and HMaterID ={oItemSub.HMaterID} and isnull(HKFDate, '') <> ''";
-                    //LogService.Write($"sql:{sql}");
-                    //DataTable dt = oCn.RunProcReturn(sql, "tables").Tables[0];
-                    //if (dt.Rows.Count > 0)
-                    //{
-                    //    LogService.Write($"HKFDate:{dt.Rows[0][0]}");
-                    //    sql = $"select DATEDIFF(D,{dt.Rows[0][0]},{HKFDate})";
-                    //    DataSet ds = oCn.RunProcReturn(sql, "tables2");
-                    //    LogService.Write($"DATEDIFF:{Convert.ToInt32(ds.Tables[0].Rows[0][0])}");
-                    //    if (ds.Tables[0].Rows.Count > 0 && Convert.ToInt32(ds.Tables[0].Rows[0][0]) != 0)
-                    //    {
-                    //        objJsonResult.code = "0";
-                    //        objJsonResult.count = 0;
-                    //        objJsonResult.Message = $"鐗╂枡缂栫爜{oItemSub.HMaterNumber}锛屾壒鍙穥oItemSub.HBatchNo.TrimStart().TrimEnd()},鐢熶骇鏃ユ湡涓簕dt.Rows[0][0]},璇锋牳瀵�";
-                    //        objJsonResult.data = null;
-                    //        return objJsonResult;
-                    //    }
-                    //}
                     if (ClsPub.isLong(oItemSub.HMaterID) != 0)
                     {
 
@@ -217,9 +218,15 @@
                         // HSumQty = ClsPub.isDoule(oItemSub.HQty);  //浜у搧鏁伴噺
                        for (int i = 0; i < biaoqianzhangshu; i++)
                         {
-                            ///渚涘簲鍟嗗悕绉�+@+鐗╂枡浠g爜+@+鐗╂枡绠�绉�+@+鏁伴噺+@+鏃ユ湡+@+娴佹按鍙�  
+                            double currentQty = (i == biaoqianzhangshu - 1 && (HQty % HMinQty != 0))
+                              ? (HQty % HMinQty)
+                              : HMinQty;
+                            ///渚涘簲鍟嗗悕绉�+@+鐗╂枡浠g爜+@+鐗╂枡绠�绉�+@+鏁伴噺+@鏉$爜鏁�+@+鏃ユ湡+@+娴佹按鍙�  
                             LSH += 1;
-                            TM = $"{oItemSub.HSupName}@{oItemSub.HMaterID}@{oItemSub.HMaterName}@{oItemSub.biaoqianzhangshu}@{HKFDate_1}@{LSH}";
+                            TM = $"{oItemSub.HSupName}@{oItemSub.HMaterNumber}@{oItemSub.HSubjoin}@{currentQty}@{HBarCodeDate_1}@{LSH.ToString("D7")}";
+                            //TM = $"{oItemSub.HSupName}@{oItemSub.HMaterID}@{oItemSub.HMaterName}@{oItemSub.biaoqianzhangshu}@{HKFDate_1}@{LSH}";
+                            // 娣诲姞鍒扮敓鎴愮殑鏉$爜鍒楄〃
+                            generatedBarcodes.Add(TM);
                             Model.ClsGy_BarCodeBill_WMS_Model bar = new Model.ClsGy_BarCodeBill_WMS_Model();
 
                            // var HBarCode_verify = TM.Split('@'); //鏍¢獙鏉$爜淇℃伅
@@ -246,22 +253,28 @@
                             //               + HKFDate + "','" + HKFDQDate + "'," + HISKFPERIOD + ")";
                             sql = "INSERT INTO Gy_BarCodeBill (HInterID, HBarCode, HBarCodeType, HMaterID, HUnitID, HQty, HKFDate, HKFPeriod, HKFDQDate, " +
        "HBatchNo, HBarcodeQtys, HBarcodeNo, HSupID, HGroupID, HMaker, HMakeDate, HPrintQty, HEndQty, HSupflag, " +
-       "HSourceInterID, HSourceEntryID, HSourceBillNo, HSourceBillType, HMTONO, HProduceDate, HExpiryDate, HISKFPERIOD) " +
+       "HSourceInterID, HSourceEntryID, HSourceBillNo, HSourceBillType, HMTONO, HProduceDate, HExpiryDate, HISKFPERIOD,HStatusMan,HBarCodeDate,HinitQty,HSTOCKORGID,HOWNERID) " +
       "VALUES (" +
-       linterid.ToString() + ", '" + TM + "', '" + HBarCodeType + "', " + HMaterID + ", " + "0" + ", " + HQty + ", '" + HKFDate + "', " + HKFPeriod + ", '" + HKFDQDate + "', " +
-       "'" + HBatchNo + "', " + get_BarCodecount + ", '" + virtualCount + "', " + HSupID + ", " + "0" + ", '" + ClsPub.CurUserName + "', '" + DateTime.Today.ToString("yyyy-MM-dd") + "', " + "1" + ", " + "0" + ", 1, " +
-       "1, 1, '1', '" + HSourceBillType + "', '1', '" +
-       HKFDate + "', '" + HKFDQDate + "', " + HISKFPERIOD + ")";
+       linterid.ToString() + ", '" + TM + "', '" + HBarCodeType + "', " + HMaterID + ", " + "0" + ", " + currentQty + ", '" + null + "', " + HKFPeriod + ", '" + null + "', " +
+       "'" + HBatchNo + "', " + get_BarCodecount + ", '" + virtualCount + "', " + HSupID + ", " + "0" + ", '" + UserName + "',getdate()" + "," + "0" + ", " + "0" + ", 1, " +
+       "0, 0, '', '" + HSourceBillType + "', '', '" +
+       null + "', '" + null + "', " + HISKFPERIOD + ",'" + HStatusMan + "','" + HBarCodeDate + "','" + currentQty + "'," + OrganizationID + "," + OrganizationID + "," + null + ")";
                             LogService.Write("鐢熸垚鏉$爜锛� " + sql);
-                            oCn.RunProc(sql);
-                            oCn.RunProc("exec setLSH '" + DateTime.Today + "'");
+                            oCn.RunProc(sql); 
+                            oCn.RunProc("exec h_p_WMS_SetMaxNo '" + HSupID + "_" + HMaterID + "_" + HBarCodeDate + "'");
                             virtualCount++;
                            }
 
                         }
                 }
                 oCn.Commit();
-
+                // 杩斿洖鐢熸垚鐨勬潯鐮佸垪琛�
+                objJsonResult.code = "0";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鐢熸垚鏉$爜鎴愬姛锛�";
+                objJsonResult.data =string.Join("~", generatedBarcodes); // 杩斿洖鐢熸垚鐨勬潯鐮佸垪琛�
+                WebAPIController.Add_Log("鏉$爜涓嬫帹", UserName, "鐢熸垚鏉$爜");
+                return objJsonResult;
             }
             catch (Exception e)
             {
@@ -273,19 +286,14 @@
                 return objJsonResult;
             }
 
-            objJsonResult.code = "0";
-            objJsonResult.count = 1;
-            objJsonResult.Message = "鐢熸垚鏉$爜鎴愬姛锛�";
-            WebAPIController.Add_Log("鏉$爜涓嬫帹", UserName, "鐢熸垚鏉$爜");
-            objJsonResult.data = null;
-            return objJsonResult;
+            
         }
         #endregion
 
         #region 鏉$爜鍒楄〃
         [Route("showHBarCodeBillDetail")]
         [HttpGet]
-        public object showHBarCodeBillDetail(string sMsg,string Organization)
+        public object showHBarCodeBillDetail(string sMsg,string user)
         {
             try
             {
@@ -331,6 +339,65 @@
         }
         #endregion
 
+        #region 鏍规嵁鏉$爜鑾峰彇鏉$爜璇︽儏
+        [Route("GetBarcodeDetails")]
+        [HttpGet]
+        public object GetBarcodeDetails(string barcodes)
+        {
+            try
+            {
+                if (string.IsNullOrEmpty(barcodes))
+                {
+                    objjson.code = "0";
+                    objjson.count = 0;
+                    objjson.Message = "鏉$爜鍙傛暟涓嶈兘涓虹┖";
+                    objjson.data = null;
+                    return objjson;
+                }
+
+                // 灏嗛�楀彿鍒嗛殧鐨勬潯鐮佽浆鎹负SQL IN鏌ヨ鏉′欢
+                var barcodeList = barcodes.Split('~');
+
+                // 鏋勫缓IN瀛愬彞锛屼负姣忎釜鏉$爜娣诲姞鍗曞紩鍙�
+                var inValues = new List<string>();
+                foreach (var barcode in barcodeList)
+                {
+                    inValues.Add("'" + barcode.Replace("'", "''") + "'"); // 澶勭悊鍗曞紩鍙疯浆涔�
+                }
+
+                string inClause = string.Join(",", inValues);
+                string sql = $"SELECT * FROM h_v_Gy_UserMaterRelationPrint WHERE HBarCode IN ({inClause})" + " order by 鐗╂枡浠g爜,cast(娴佹按鍙� as int)";
+
+                // 鐩存帴鎵цSQL鏌ヨ
+                DataSet ds = oCn.RunProcReturn(sql, "h_v_Gy_UserMaterRelationPrint");
+
+                if (ds == null || ds.Tables[0].Rows.Count == 0)
+                {
+                    objjson.code = "0";
+                    objjson.count = 0;
+                    objjson.Message = "鏈壘鍒扮浉鍏虫潯鐮佷俊鎭�";
+                    objjson.data = null;
+                    return objjson;
+                }
+
+                objjson.code = "0";
+                objjson.count = ds.Tables[0].Rows.Count;
+                objjson.Message = "鑾峰彇鎴愬姛";
+                objjson.data = ds.Tables[0];
+                return objjson;
+            }
+            catch (Exception e)
+            {
+                objjson.code = "0";
+                objjson.count = 0;
+                objjson.Message = "鑾峰彇鏉$爜璇︽儏澶辫触:" + e.Message;
+                objjson.data = null;
+                return objjson;
+            }
+        }
+        #endregion
+
+
 
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1