chenhaozhe
4 天以前 291fdb29daf239a13fcfb3f5e08a2f5bf9167534
WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs
@@ -90,11 +90,12 @@
                double HPeriod = DateTime.Now.Month;
                string HRemark = list[0].HRemark;//备注
                string HSourceName = list[0].HSourceName;//生产资源名称
                double HPieceQty = list[0].HPieceQty;//进站PCS数
                double HPieceQty = list[0].HPieceQty;//进站PCS数  件数
                double HWasterQty = list[0].HWasterQty;//报废数量
                double HPlanPieceQty = list[0].HPlanPieceQty;//进站PNL数
                double HBadPNL = list[0].HBadPNL;//报废PNL数
                long HICMOInterID = list[0].HICMOInterID;//任务单ID
                long HICMOEntryID = list[0].HICMOEntryID;//任务单ID
                string HICMOBillNo = list[0].HICMOBillNo;//任务单
                int HProcPlanInterID = 0;
                int HProcPlanEntryID = 0;
@@ -157,6 +158,7 @@
                int HIsTimeFlag = list[0].HIsTimeFlag;//是否计时
                string HRelBeginTime = list[0].HRelBeginTime;//开工时间
                string HRelEndTime = list[0].HRelEndTime;//完工时间
                double HWeight = list[0].HWeight;//重量
                LogService.Write($"1.字段赋值,用时" + sw.Elapsed );
                //单据完整性判断
@@ -410,25 +412,25 @@
                    oCN.RunProc("Insert Into Sc_StationOutBillMain " +
                    "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate,HMouldNum" +
                    ",HYear,HPeriod,HRemark,HSourceName,HPieceQty,HWasterQty,HPlanPieceQty,HBadPNL" +
                    ",HICMOInterID,HICMOBillNo,HProcPlanInterID,HProcPlanEntryID,HProcPlanBillNo,HProcExchInterID,HProcExchEntryID" +
                    ",HICMOInterID,HICMOEntryID,HICMOBillNo,HProcPlanInterID,HProcPlanEntryID,HProcPlanBillNo,HProcExchInterID,HProcExchEntryID" +
                    ",HProcExchBillNo,HMaterID,HProcID,HICMOQty,HPlanQty,HStationOutTime,HSourceID,HPayProcID" +
                    ",HGroupID,HDeptID,HEmpID,HBarCode,HAddr,HBarCodeMaker,HBarCodeMakeDate,HSourceID2,HSourceID3,HSourceID4,HSourceID5" +
                    ",HSupID,HQty,HPrice,HMoney,HBadCount,HCenterID,HProcNo,HOrderProcNO,HSourceNameList" +
                    ",HMainSourceInterID,HMainSourceBillNo,HMainSourceBillType,HLastSubProc" +
                    ",HEmpID2,HEmpID3,HEmpID4,HEmpID5,HDSQty,HChongQty,HPriceRate,HWorkTimes,HQCCheckID,HMainInterID,HPRDOrgID" +
                    ",HmaterOutqty,HProcPriceRate,HTemporaryAreaID,HWasterQty_Work,HWasterQty_Mater,HBackWorkQty,HShiftsID" +
                    ",HToCheckQty,HLossQty,HBackWorkByMaterQty,HMouldID,HMachineWorkTimes,HIsTimeFlag,HRelBeginTime,HRelEndTime " +
                    ",HToCheckQty,HLossQty,HBackWorkByMaterQty,HMouldID,HMachineWorkTimes,HIsTimeFlag,HRelBeginTime,HRelEndTime,HWeight " +
                    ") " +
                    " values('" + BillType + "','" + (OperationType == "5" ? "SUB" : HBillSubType)  + "'," + HInterID + ",'" + HBillNo + "'," + HBillStatus + ",'"+ HDate + "','" + HMaker + "',getdate(),'" + HMouldNum + "'" +
                    "," + HYear + "," + HPeriod + ",'" + HRemark + "','" + HSourceName + "'," + HPieceQty + "," + HWasterQty + "," + HPlanPieceQty + "," + HBadPNL +
                    "," + HICMOInterID + ",'" + HICMOBillNo + "'," + HProcPlanInterID + "," + HProcPlanEntryID + ",'" + HProcPlanBillNo + "'," + HProcExchInterID + "," + HProcExchEntryID +
                    "," + HICMOInterID + "," + HICMOEntryID + ",'" + HICMOBillNo + "'," + HProcPlanInterID + "," + HProcPlanEntryID + ",'" + HProcPlanBillNo + "'," + HProcExchInterID + "," + HProcExchEntryID +
                    ",'" + HProcExchBillNo + "'," + HMaterID + "," + HProcID + "," + HICMOQty + "," + HPlanQty + ",getdate()," + HSourceID + "," + HPayProcID +
                    "," + HGroupID + "," + HDeptID + "," + HEmpID + ",'" + HBarCode + "','" + HAddr + "','" + HBarCodeMaker + "',getdate()" + "," + HSourceID2 + "," + HSourceID3 + "," + HSourceID4 + "," + HSourceID5 +
                    "," + HSupID + "," + HQty + "," + HPrice + "," + HMoney + "," + HBadCount + "," + HCenterID + "," + HProcNo + ",'" + HOrderProcNO + "'" + ",'" + HSourceNameList + "'" +
                    "," + HMainSourceInterID + ",'" + HMainSourceBillNo + "','" + HMainSourceBillType + "'," + Convert.ToString(HLastSubProc ? 1 : 0) +
                    "," + HEmpID2 + "," + HEmpID3 + "," + HEmpID4 + "," + HEmpID5 + "," + HDSQty + "," + HChongQty + "," + HPriceRate + "," + HWorkTimes + "," + HQCCheckID + "," + HMainInterID + "," + HPRDOrgID +
                    "," + HmaterOutqty + "," + HProcPriceRate + "," + HTemporaryAreaID + "," + HWasterQty_Work + "," + HWasterQty_Mater + "," + HBackWorkQty +
                    "," + HShiftsID + "," + HToCheckQty + "," + HLossQty + ","+ HBackWorkByMaterQty + "," + HMouldID + ",'" + HMachineWorkTimes + "',"+ HIsTimeFlag + ",'" + HRelBeginTime + "','" + HRelEndTime +  "') ");
                    "," + HShiftsID + "," + HToCheckQty + "," + HLossQty + ","+ HBackWorkByMaterQty + "," + HMouldID + ",'" + HMachineWorkTimes + "',"+ HIsTimeFlag + ",'" + HRelBeginTime + "','" + HRelEndTime + "','" + HWeight + "') ");
                    LogService.Write($"4.新增结束,用时" + sw.Elapsed);
                    LogService.Write("用户:" + user + ",日期:" + DateTime.Now + ",新增工序出站单据:" + HBillNo);
@@ -476,9 +478,7 @@
                    ",HBackWorkByMaterQty=" + HBackWorkByMaterQty +
                    ",HMouldID=" + HMouldID +
                    ",HMachineWorkTimes=" + HMachineWorkTimes +
                    //",HIsTimeFlag=" + HIsTimeFlag +
                    //",HRelBeginTime='" + HRelBeginTime + "'" +
                    //",HRelEndTime='" + HRelEndTime + "'" +
                    ",HWeight=" + HWeight +
                    " from Sc_StationOutBillMain a with(nolock)" +
                    " where HInterID=" + HInterID);
@@ -641,29 +641,25 @@
                    {
                        object objResult = set_SaveStationOutBill_CLD_Json(HInterID, HBillNo, user);
                    }
                    //判断客户为华舟包装 生成条码主档
                    else if (oSystemParameter.omodel.WMS_CampanyName == "华舟")
                    {
                        var objResult = Cj_StationOutBarCode_Save(HInterID,1);
                    }
                }
                else if ("Modify".Equals(eventType))
                {
                    //判断客户为华舟包装 生成条码主档
                    if (oSystemParameter.omodel.WMS_CampanyName == "华舟")
                    {
                        var objResult = Cj_StationOutBarCode_Save(HInterID, 2);
                    }
                }
                sw.Stop();//结束计时
                LogService.Write($"11.参数查询结束,新增结束,用时" + sw.Elapsed);
                LogService.Write("END--出站单据保存结束,出站单号:" + HBillNo);
                //测试语句===========================================================================================================
                string msg_str = "";
                string sql_str = "select a.HQty HQty_Main,b.HQty HQty_Sub " +
                            "from Sc_ProcessExchangeBillMain as a with(nolock)" +
                            "inner join Sc_ProcessExchangeBillSub as b with(nolock) on a.HInterID = b.HInterID " +
                            "where a.HInterID = " + HProcExchInterID;
                DataSet ds_str = oCN.RunProcReturn(sql_str, "Sc_ProcessExchangeBillMain");
                if (ds_str.Tables[0].Rows.Count > 0)
                {
                    msg_str = "HQty_Main:" + ds_str.Tables[0].Rows[0]["HQty_Main"].ToString() + ";HQty_Sub:";
                    for (int j = 0; j < ds_str.Tables[0].Rows.Count; j++)
                    {
                        msg_str += ds_str.Tables[0].Rows[j]["HQty_Sub"].ToString() + ",";
                    }
                }
                oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','" + HComputerName + "','" + "修改工序出站单据:" + HBillNo + "[工序流转卡号:" + HProcExchBillNo + "]" + msg_str + "','LMES-工序出站模块','" + DBUtility.ClsPub.IPAddress + "','新增或修改单据'", ref DBUtility.ClsPub.sExeReturnInfo);
                //==============================================================================================================
                objJsonResult.code = "1";
@@ -1366,7 +1362,195 @@
        }
        #endregion
        #region [出站单生成条码主档]
        [Route("Cj_StationOutBill/Cj_StationOutBarCode_Save")]
        [HttpPost]
        public object Cj_StationOutBarCode_Save(long HInterID, int Type)
        {
            try
            {
                ListModels oListModels = new ListModels();
                DAL.ClsGy_BarCodeBill_ChaiMa BillNew = new DAL.ClsGy_BarCodeBill_ChaiMa();
                oCN.BeginTran();
                // 如果Type为2,先删除老的条码记录
                if (Type == 2)
                {
                    string deleteSql = "DELETE FROM Gy_BarCodeBill WHERE HInterID = '" + HInterID + "'";
                    oCN.RunProc(deleteSql);
                }
                // 查询 HQty、HPieceQty 和 重量字段
                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)
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!未查询到条码信息";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                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.data = 1;
                    return objJsonResult;
                }
                if (totalWeight <= 0)
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!重量必须大于0";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                // 固定生成指定件数的条码
                int barcodeCount = (int)HPieceQty;  // HPieceQty 作为条码件数
                // 计算每张条码的基础数量和基础重量
                decimal baseQtyPerPiece = Math.Floor(HQty / HPieceQty);
                decimal remainderQty = HQty % HPieceQty;
                // 计算每张条码的基础重量(净重和毛重相同)
                decimal baseWeightPerPiece = Math.Floor(totalWeight / HPieceQty * 10000) / 10000; // 保留4位小数
                decimal remainderWeight = totalWeight - (baseWeightPerPiece * HPieceQty);
                // 查询原始单据信息
                ds = oCN.RunProcReturn("select * from Sc_StationOutBillMain where HInterID='" + HInterID + "'", "Sc_StationOutBillMain");
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    DataRow row = ds.Tables[0].Rows[0];
                    // 循环生成条码
                    for (int i = 0; i < barcodeCount; i++)
                    {
                        // 计算当前条码的数量
                        decimal currentQty = baseQtyPerPiece;
                        if (i < remainderQty)  // 如果有余数,前N张条码各加1
                        {
                            currentQty += 1;
                        }
                        // 计算当前条码的重量(净重和毛重相同)
                        decimal currentWeight = baseWeightPerPiece;
                        if (i < Math.Ceiling(remainderWeight / baseWeightPerPiece) && remainderWeight > 0)
                        {
                            currentWeight += baseWeightPerPiece; // 重量余数也分摊到前几张条码
                        }
                        // 生成条码号
                        string barcodeNumber = row["HBillNO"].ToString() + (barcodeCount > 1 ? "-" + (i + 1).ToString() : "");
                        // 修改插入语句,添加HMaterialJQty和HMaterialMQty字段
                        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" +
                          ") values (" +
                          "'" + row["HInterID"].ToString() + "', " +
                          "'" + (i + 1).ToString() + "', " +  // HEntryID 改为序号
                          "'" + barcodeNumber + "', " +  // 使用带序号的条码号
                          "'唯一条码', " +
                          "'', " +
                          "'" + row["HMaterID"].ToString() + "', " +
                          "'0', " +
                          "'" + currentQty.ToString() + "', " +  // 使用当前条码的数量
                          "'" + currentWeight.ToString() + "', " +  // 净重
                          "'" + currentWeight.ToString() + "', " +  // 毛重(与净重相同)
                          "'', " +
                          "'', " +
                          "'" + row["HGroupID"].ToString() + "', " +
                          "'" + row["HMaker"].ToString() + "', getdate(), " +
                          "'0', " +
                          "'" + row["HICMOInterID"].ToString() + "', " +
                          "'" + row["HICMOEntryID"].ToString() + "', " +
                          "'" + row["HICMOBillNo"].ToString() + "', " +
                          "'3710', " +
                          "'0', " +
                          "'0', " +
                          "'1', " +
                          "'" + (i + 1).ToString() + "', " +  // HBarcodeNo 改为序号
                          "'" + row["HDeptID"].ToString() + "', " +
                          "'0', " +
                          "'0', " +
                          "'" + row["HRemark"].ToString() + "', " +
                          "'0', " +
                          "'', " +
                          "getdate(), " +
                          "'', " +
                          "'" + row["HDate"].ToString() + "', " +
                          "'" + row["HPRDORGID"].ToString() + "', " +
                          "'" + row["HPRDORGID"].ToString() + "', " +
                          "'', " +
                          "'0', " +
                          "'', " +
                          "'', " +
                          "'', " +
                          "'0', " +
                          "'', " +
                          "'', " +
                          "'', " +
                          "'', " +
                          "'', " +
                          "'0', " +
                          "'', " +
                          "'" + row["HEmpID"].ToString() + "', " +
                          "'', " +
                          "'', " +
                          "'', " +
                          "'', " +
                          "'', " +
                          "''" +
                          ")";
                        // 插入拆分条码
                        oCN.RunProc(sql);
                    }
                    oCN.Commit();
                    objJsonResult.code = "1";
                    objJsonResult.count = barcodeCount;
                    objJsonResult.Message = "保存成功!共生成" + barcodeCount + "张条码";
                    objJsonResult.data = barcodeCount;
                    return objJsonResult;
                }
                else
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!未查询到条码信息";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                oCN.RollBack();
                oCN.RunProc("update Sc_StationOutBillMain set HInterFaceRemark ='" + e.ToString().Replace("'", "''") + "', HInterFaceStatus ='未生成' where HInterID=" + HInterID);
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
@@ -3106,7 +3290,7 @@
                    sReturn = "单据未找到!";
                    return false;
                }
                oCN.RunProc(" Update a set HChecker='" + HChecker + "',HCheckDate='" + HCheckDate + "' from Sc_StationOutBillMain with(nolock) Where HInterID=" + lngBillKey.ToString());
                oCN.RunProc(" Update a set HChecker='" + HChecker + "',HCheckDate='" + HCheckDate + "' from Sc_StationOutBillMain a with(nolock) Where HInterID=" + lngBillKey.ToString());
                oCN.RunProc("exec h_p_Mes_ProcessExchangeRelationQty_Check_In " + lngBillKey.ToString() + ",1");
                //判断是否是 末道工序
                DataSet ds1;
@@ -3867,6 +4051,7 @@
                        objJsonResult.data = ds.Tables[0];
                        return objJsonResult;
                    }
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "";
@@ -3888,6 +4073,8 @@
                        objJsonResult.data = ds.Tables[0];
                        return objJsonResult;
                    }
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
@@ -3933,14 +4120,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));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)