From 807bb9a2b4d6db408ebdded1cff41f3094eac11e Mon Sep 17 00:00:00 2001
From: wtt <1985833171@qq.com>
Date: 星期二, 24 三月 2026 15:00:40 +0800
Subject: [PATCH] 1

---
 WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs |  236 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 223 insertions(+), 13 deletions(-)

diff --git a/WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs b/WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs
index ebb3e72..c55dcbc 100644
--- a/WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs
+++ b/WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs
@@ -1381,8 +1381,8 @@
                     oCN.RunProc(deleteSql);
                 }
 
-                // 棣栧厛鏌ヨ HQty 鍜� HPieceQty
-                DataSet dsPiece = oCN.RunProcReturn("select HPieceQty, HQty from Sc_StationOutBillMain where HInterID='" + HInterID + "'", "Sc_StationOutBillMain");
+                // 鏌ヨ HQty銆丠PieceQty 鍜� 閲嶉噺瀛楁
+                DataSet dsPiece = oCN.RunProcReturn("select HPieceQty, HQty, HWeight from Sc_StationOutBillMain where HInterID='" + HInterID + "'", "Sc_StationOutBillMain");
 
                 if (dsPiece == null || dsPiece.Tables[0].Rows.Count == 0)
                 {
@@ -1396,23 +1396,38 @@
 
                 decimal HPieceQty = Convert.ToDecimal(dsPiece.Tables[0].Rows[0]["HPieceQty"]);
                 decimal HQty = Convert.ToDecimal(dsPiece.Tables[0].Rows[0]["HQty"]);
+                decimal totalWeight = Convert.ToDecimal(dsPiece.Tables[0].Rows[0]["HWeight"]);
 
                 if (HPieceQty <= 0)
                 {
                     oCN.RollBack();
                     objJsonResult.code = "0";
                     objJsonResult.count = 0;
-                    objJsonResult.Message = "淇濆瓨澶辫触锛佹潯鐮佸紶鏁板繀椤诲ぇ浜�0";
+                    objJsonResult.Message = "淇濆瓨澶辫触锛佷欢鏁板繀椤诲ぇ浜�0";
                     objJsonResult.data = 1;
                     return objJsonResult;
                 }
 
-                // 鍥哄畾鐢熸垚鎸囧畾寮犳暟鐨勬潯鐮�
-                int barcodeCount = (int)HPieceQty;  // HPieceQty 浣滀负鏉$爜寮犳暟
+                if (totalWeight <= 0)
+                {
+                    oCN.RollBack();
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "淇濆瓨澶辫触锛侀噸閲忓繀椤诲ぇ浜�0";
+                    objJsonResult.data = 1;
+                    return objJsonResult;
+                }
 
-                // 璁$畻姣忓紶鏉$爜鐨勫钩鍧囨暟閲�
-                decimal baseQty = Math.Floor(HQty / HPieceQty);
-                decimal remainder = HQty % HPieceQty;
+                // 鍥哄畾鐢熸垚鎸囧畾浠舵暟鐨勬潯鐮�
+                int barcodeCount = (int)HPieceQty;  // HPieceQty 浣滀负鏉$爜浠舵暟
+
+                // 璁$畻姣忓紶鏉$爜鐨勫熀纭�鏁伴噺鍜屽熀纭�閲嶉噺
+                decimal baseQtyPerPiece = Math.Floor(HQty / HPieceQty);
+                decimal remainderQty = HQty % HPieceQty;
+
+                /// 閲嶉噺鍧囧垎鍩虹鍊间笌浣欐暟
+                decimal baseWeightPerPiece = totalWeight / HPieceQty;
+                decimal remainderWeight = totalWeight % HPieceQty;
 
                 // 鏌ヨ鍘熷鍗曟嵁淇℃伅
                 ds = oCN.RunProcReturn("select * from Sc_StationOutBillMain where HInterID='" + HInterID + "'", "Sc_StationOutBillMain");
@@ -1424,17 +1439,43 @@
                     // 寰幆鐢熸垚鏉$爜
                     for (int i = 0; i < barcodeCount; i++)
                     {
-                        // 璁$畻褰撳墠鏉$爜鐨勬暟閲�
-                        decimal currentQty = baseQty;
-                        if (i < remainder)  // 濡傛灉鏈変綑鏁帮紝鍓峃寮犳潯鐮佸悇鍔�1
+                        // ====================== 淇鏁伴噺璁$畻 ======================
+                        decimal currentQty;
+                        if (barcodeCount == 1)
                         {
-                            currentQty += 1;
+                            // 鍙湁1浠舵椂锛岀洿鎺ヤ娇鐢ㄦ�绘暟閲忥紝涓嶅仛鍙栨暣鎷嗗垎
+                            currentQty = HQty;
+                        }
+                        else
+                        {
+                            currentQty = baseQtyPerPiece;
+                            // 鏈変綑鏁板垯鍓峃鏉″悇鍔�1锛堝彧閽堝鏁存暟浣欐暟鍦烘櫙锛�
+                            if (i < remainderQty)
+                            {
+                                currentQty += 1;
+                            }
+                        }
+
+                        // ====================== 淇閲嶉噺璁$畻 ======================
+                        decimal currentWeight;
+                        if (barcodeCount == 1)
+                        {
+                            currentWeight = totalWeight;
+                        }
+                        else
+                        {
+                            currentWeight = baseWeightPerPiece;
+                            if (i < remainderWeight)
+                            {
+                                currentWeight += baseWeightPerPiece;
+                            }
                         }
 
                         // 鐢熸垚鏉$爜鍙�
                         string barcodeNumber = row["HBillNO"].ToString() + (barcodeCount > 1 ? "-" + (i + 1).ToString() : "");
 
-                        string sql = "insert into Gy_BarCodeBill (HInterID, HEntryID, HBarCode, HBarCodeType, HBarCodeSubType, HMaterID, HUnitID, HQty, HBatchNo, HSupID, HGroupID, HMaker, HMakeDate, " +
+                        // 淇敼鎻掑叆璇彞锛屾坊鍔燞MaterialJQty鍜孒MaterialMQty瀛楁
+                        string sql = "insert into Gy_BarCodeBill (HInterID, HEntryID, HBarCode, HBarCodeType, HBarCodeSubType, HMaterID, HUnitID, HQty, HMaterialJQty, HMaterialMQty, HBatchNo, HSupID, HGroupID, HMaker, HMakeDate, " +
                           "HPrintQty, HSourceInterID, HSourceEntryID, HSourceBillNo, HSourceBillType, HinitQty, HEndQty, HBarcodeQtys, HBarcodeNo, HDeptID, HWhID, HSPID, HRemark, " +
                           "HCusID, HCusType, HEndDate, HWorkLineName, HBarCodeDate, HSTOCKORGID, HOWNERID, HSeOrderBillNo, HGiveAwayFlag, HMaterName, HMaterModel, " +
                           "HPinfan, HAuxPropID, HMTONo, HInnerBillNo, HCoilNO, HFurnaceNO, HFactory, HAuxQty, HheatNO, HEmpID, HCusModel, HCusMaterName, HCheckEmpName, HZZRQ, HSupMaterNumber, HSupBatchNo" +
@@ -1447,6 +1488,8 @@
                           "'" + row["HMaterID"].ToString() + "', " +
                           "'0', " +
                           "'" + currentQty.ToString() + "', " +  // 浣跨敤褰撳墠鏉$爜鐨勬暟閲�
+                          "'" + currentWeight.ToString() + "', " +  // 鍑�閲�
+                          "'" + currentWeight.ToString() + "', " +  // 姣涢噸锛堜笌鍑�閲嶇浉鍚岋級
                           "'', " +
                           "'', " +
                           "'" + row["HGroupID"].ToString() + "', " +
@@ -4026,6 +4069,7 @@
                         objJsonResult.data = ds.Tables[0];
                         return objJsonResult;
                     }
+
                     objJsonResult.code = "1";
                     objJsonResult.count = 1;
                     objJsonResult.Message = "";
@@ -4047,6 +4091,8 @@
                         objJsonResult.data = ds.Tables[0];
                         return objJsonResult;
                     }
+
+                   
 
                     objJsonResult.code = "1";
                     objJsonResult.count = 1;
@@ -4092,14 +4138,27 @@
                     return objJsonResult;
                 }
 
+
+                List<object> columnNameList = new List<object>();
+
                 string sql1 = "select * from h_v_MES_StationOutBillList_SN where 1 = 1 ";
                 string sql = sql1 + sWhere + "  order by 鍒跺崟鏃ユ湡 desc";
                 ds = oCN.RunProcReturn(sql, "h_v_MES_StationOutBillList_SN");
+
+                //娣诲姞鍒楀悕
+                foreach (DataColumn col in ds.Tables[0].Columns)
+                {
+                    LogService.Write(21231321);
+                    Type dataType = col.DataType;
+                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
+                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
+                }
 
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
                 objJsonResult.Message = "Sucess锛�";
                 objJsonResult.data = ds.Tables[0];
+                objJsonResult.list = columnNameList;
                 return objJsonResult;
             }
             catch (Exception e)
@@ -4820,6 +4879,157 @@
 
         #endregion
 
+        //瀹℃牳锛屽甫缂栬緫鍔熻兘
+        [Route("Cj_StationOutBill/setOtherProperty")]
+        [HttpPost]
+        public object setOtherProperty([FromBody] JObject oMain)
+        {
+            try
+            {
+                var _value = oMain["oMain"].ToString();
+                string msg1 = _value.ToString();
+                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
+                string msg2 = "[" + sArray[0].ToString() + "]";
+                string user = sArray[1].ToString();
+                ////鍒ゆ柇鏄惁鏈夌紪杈戞潈闄�
+                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Edit", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犵紪杈戞潈闄�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                //瀹℃牳鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Check", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "瀹℃牳澶辫触锛佹棤鏉冮檺锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                List<StationBill> list1 = Newtonsoft.Json.JsonConvert.DeserializeObject<List<StationBill>>(msg2);
+                long HInterID = list1[0].HInterID;
+                double HQty = list1[0].HQty;
+                double HBadCount = list1[0].HBadCount;
+                double HWasterQty = list1[0].HWasterQty;
+                long HSourceID = list1[0].HSourceID;
+                string HSourceName = list1[0].HSourceName;
+                long HCenterID = list1[0].HCenterID;
+                long HGroupID = list1[0].HGroupID;
+                long HEmpID = list1[0].HEmpID;
 
+                oCN.BeginTran();
+
+                DataSet ds = oCN.RunProcReturn("select * from Sc_StationOutBillMain where HInterID=" + HInterID, "Sc_StationOutBillMain");
+
+                if (ds.Tables.Count > 0 && ds.Tables[0].Rows[0]["HChecker"].ToString() == "")
+                {
+                    string HBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
+                    //瀹℃牳鍓嶆帶鍒�================================================================================
+                    string sql = "exec h_p_Sc_StationOutBill_BeforeCheckCtrl " + HInterID + ",'" + HBillNo + "','" + user + "'";
+                    ds = oCN.RunProcReturn(sql, "h_p_Sc_StationOutBill_BeforeCheckCtrl");
+                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:瀹℃牳鍓嶅垽鏂け璐ワ紝璇蜂笌缃戠粶绠$悊浜哄憳鑱旂郴";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                    if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //================================================================================
+
+                    if (HQty > 0)
+                    {
+
+                        oCN.RunProc($"update Sc_StationOutBillMain set HBillStatus = 2, HQty={HQty},HBadCount='{HBadCount}',HWasterQty='{HWasterQty}',HSourceID='{HSourceID}',HCenterID='{HCenterID}',HGroupID={HGroupID},HEmpID={HEmpID},HChecker='{user}',HCheckDate=getdate() where HInterID={HInterID} ");
+
+                    }
+                    string sReturn = "";
+                    //鑾峰彇绯荤粺鍙傛暟
+                    oSystemParameter.ShowBill(ref sReturn);
+                    //鍒ゆ柇瀹㈡埛涓哄ぉ鎿� 鍚屾閲戣澏宸ュ簭姹囨姤鍗�
+                    if (oSystemParameter.omodel.WMS_CampanyName == "澶╂搸")
+                    {
+                        //鍚屾鍓嶆帶鍒�=========================================
+                        ds = oCN.RunProcReturn("Exec  h_p_Sc_StationOutBill_BeforeSyncCtrl  " + HInterID.ToString() + ", '" + HBillNo + "','" + user + "'", " h_p_Sc_StationOutBill_BeforeSyncCtrl ");
+                        if (ds == null)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "[0000-2-012]淇濆瓨鍓嶅垽鏂け璐ワ紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "[0000-1-051]鍚屾澶辫触锛�" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HRemark"]);
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        //=========================================================
+                        if (oWebs.set_SaveStationOutBill_CLD(HInterID, HBillNo, user, ref DBUtility.ClsPub.sErrInfo))
+                        {
+                            oCN.Commit();
+                            objJsonResult.code = "1";
+                            objJsonResult.count = 1;
+                            objJsonResult.Message = "鎴愬姛";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            oCN.RollBack();
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = DBUtility.ClsPub.sErrInfo;
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+
+                    }
+                    oCN.Commit();
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "瀹℃牳淇敼鎴愬姛锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+
+
+
+                }
+                else
+                {
+                    oCN.Commit();
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鍗曟嵁涓嶅瓨鍦ㄦ垨宸插鏍革紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+            }
+            catch (Exception e)
+            {
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "瀹℃牳澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1