1
duhe
2023-12-13 0a6224c1f057e83ed90b75d0c71286c30d8e01ab
WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs
@@ -41,17 +41,33 @@
                //反序列化
                string msg2 = "[" + sArray[0].ToString() + "]";
                string user = sArray[1].ToString();//用户名
                string OperationType = sArray[2].ToString();//类型
                string HComputerName = SystemInformation.ComputerName; //设备名称
                //判断是否有编辑权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Edit", 1, false, user))
                if (OperationType == "5")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无编辑权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                    //判断是否有编辑权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Edit", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "完工单无编辑权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else {
                    //判断是否有编辑权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Edit", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单无编辑权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                Stopwatch sw = new Stopwatch();
                sw.Start();//开始计时
@@ -125,6 +141,7 @@
                long HPRDOrgID = list[0].HPRDOrgID;//组织ID
                double HmaterOutqty = list[0].HmaterOutqty;//白坯发布
                double HProcPriceRate = list[0].HProcPriceRate;//工价系数
                int HTemporaryAreaID = list[0].HTemporaryAreaID;//暂放区
                LogService.Write($"1.字段赋值,用时" + sw.Elapsed );
@@ -300,10 +317,10 @@
                //    return objJsonResult;
                //}
                LogService.Write($"2.条件判断,用时" + sw.Elapsed);
                //LogService.Write($"2.条件判断,用时" + sw.Elapsed);
                var num = 0;
                LogService.Write($"3.事务开始,用时" + sw.Elapsed);
                //LogService.Write($"3.事务开始,用时" + sw.Elapsed);
                //若MAINDI重复则重新获取
                oCN.BeginTran();
@@ -329,9 +346,9 @@
                    ",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" +
                        ",HmaterOutqty,HProcPriceRate,HTemporaryAreaID" +
                    ") " +
                    " values('" + BillType + "','" + HBillSubType + "'," + HInterID + ",'" + HBillNo + "'," + HBillStatus + ",getdate(),'" + HMaker + "',getdate(),'" + HMouldNum + "'" +
                    " values('" + BillType + "','" + (OperationType == "5" ? "SUB" : HBillSubType)  + "'," + HInterID + ",'" + HBillNo + "'," + HBillStatus + ",getdate(),'" + HMaker + "',getdate(),'" + HMouldNum + "'" +
                    "," + HYear + "," + HPeriod + ",'" + HRemark + "','" + HSourceName + "'," + HPieceQty + "," + HWasterQty + "," + HPlanPieceQty + "," + HBadPNL +
                    "," + HICMOInterID + ",'" + HICMOBillNo + "'," + HProcPlanInterID + "," + HProcPlanEntryID + ",'" + HProcPlanBillNo + "'," + HProcExchInterID + "," + HProcExchEntryID +
                    ",'" + HProcExchBillNo + "'," + HMaterID + "," + HProcID + "," + HICMOQty + "," + HPlanQty + ",getdate()," + HSourceID + "," + HPayProcID +
@@ -339,7 +356,7 @@
                    "," + 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 + ") ");
                  ","+ HmaterOutqty + "," + HProcPriceRate + ","+ HTemporaryAreaID + ") ");
                    LogService.Write($"4.新增结束,用时" + sw.Elapsed);
                    LogService.Write("用户:" + user + ",日期:" + DateTime.Now + ",新增工序出站单据:" + HBillNo);
@@ -371,6 +388,7 @@
                    ",HQty=" + HQty +
                    ",HDSQty=" + HDSQty +
                    ",HChongQty=" + HChongQty +
                    ",HTemporaryAreaID=" + HTemporaryAreaID +
                    ",HMouldNum='" + HMouldNum + "'" +
                    ",HSourceNameList='" + HSourceNameList + "'" +
                    ",HWasterQty=" + HWasterQty +
@@ -391,7 +409,7 @@
                }
                //主表
                LogService.Write($"5.系统控制查询判断,用时" + sw.Elapsed);
                //LogService.Write($"5.系统控制查询判断,用时" + sw.Elapsed);
                ds = oCN.RunProcReturn("exec h_p_MES_StationOutBill_QtyCtrl " + HInterID + "", "h_p_MES_StationOutBill_QtyCtrl");
                if (ds == null)
                {
@@ -402,7 +420,7 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                LogService.Write($"5.1,用时" + sw.Elapsed);
                //LogService.Write($"5.1,用时" + sw.Elapsed);
                if (ds.Tables[0].Rows.Count == 0)
                {
                    oCN.RollBack();
@@ -412,7 +430,7 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                LogService.Write($"5.2,用时" + sw.Elapsed);
                //LogService.Write($"5.2,用时" + sw.Elapsed);
                if (ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) == "2")
                {
                    oCN.RollBack();
@@ -422,13 +440,13 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                LogService.Write($"6.判断结束,用时" + sw.Elapsed);
                //LogService.Write($"6.判断结束,用时" + sw.Elapsed);
                oCN.RunProc("exec h_p_Mes_ProcessExchangeRelationQty_Out " + HInterID + ","+ num + "");
                LogService.Write($"6.1,用时" + sw.Elapsed);
                //LogService.Write($"6.1,用时" + sw.Elapsed);
                oCN.RunProc("exec h_p_Mes_ProcessExchangeChangeStatus  " + HInterID + " ");
                LogService.Write($"6.2,用时" + sw.Elapsed);
                //LogService.Write($"6.2,用时" + sw.Elapsed);
                oCN.RunProc("exec h_p_Mes_StationOutBillBackBarCode  " + HInterID + " ");
                LogService.Write($"7.存储过程结束,用时" + sw.Elapsed);
                //LogService.Write($"7.存储过程结束,用时" + sw.Elapsed);
                //判断是否是 末道工序 
                ds1 = oCN.RunProcReturn(" select HLastProc,HFstProc from Sc_ProcessExchangeBillMain a  " +
                                    " inner join Sc_ProcessExchangeBillSub b on a.HInterID=b.HInterID  " +
@@ -446,10 +464,10 @@
                            //判断末道 生产汇报汇报 是否勾选
                            if (oSystemParameter.omodel.MES_StationOutBill_LastAutoICMOReport == "Y") //系统参数   
                            {
                                LogService.Write($"7.1,用时" + sw.Elapsed);
                                //LogService.Write($"7.1,用时" + sw.Elapsed);
                                //同步生产汇报单
                                objJsonResult = (json)SaveICMOReportBill(HInterID.ToString(), user, HBillNo, HPRDOrgID.ToString());
                                LogService.Write($"7.2,用时" + sw.Elapsed);
                                //LogService.Write($"7.2,用时" + sw.Elapsed);
                                if (objJsonResult.count == 0)
                                {
                                    oCN.RollBack();
@@ -459,15 +477,15 @@
                                    objJsonResult.data = null;
                                    return objJsonResult;
                                }
                                LogService.Write($"8.生产汇报结束,用时" + sw.Elapsed);
                                //LogService.Write($"8.生产汇报结束,用时" + sw.Elapsed);
                            }
                            //判断末道 生产入库 是否勾选
                            else if (oSystemParameter.omodel.MES_StationOutBill_AutoStockIn == "Y") //系统参数   
                            {
                                LogService.Write($"8.1,用时" + sw.Elapsed);
                                //LogService.Write($"8.1,用时" + sw.Elapsed);
                                //同步生产入库单
                                objJsonResult =(json)SaveProcdutInBill(HBillNo);
                                LogService.Write($"8.2,用时" + sw.Elapsed);
                                //LogService.Write($"8.2,用时" + sw.Elapsed);
                                if (objJsonResult.count == 0)
                                {
                                    oCN.RollBack();
@@ -477,7 +495,7 @@
                                    objJsonResult.data = null;
                                    return objJsonResult;
                                }
                                LogService.Write($"9.生产入库结束,用时" + sw.Elapsed);
                                //LogService.Write($"9.生产入库结束,用时" + sw.Elapsed);
                            }
                           
                        }
@@ -485,7 +503,7 @@
                }
                LogService.Write($"10.事务结束,用时" + sw.Elapsed);
                //LogService.Write($"10.事务结束,用时" + sw.Elapsed);
                oCN.Commit();
                string sReturn = "";
                if (oSystemParameter.ShowBill(ref sReturn) == true)
@@ -1406,12 +1424,12 @@
        //递入物料信息 返回未完全汇报的流转卡
        [Route("LEMS/Sc_StationOutBill_Mul_RYQ")]
        [HttpGet]
        public object Sc_StationOutBill_Mul_RYQ(String HMaterName, Int64 HOrgID)
        public object Sc_StationOutBill_Mul_RYQ(String HMaterName,string HProcNumber, Int64 HOrgID)
        {
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                DataSet ds = oCN.RunProcReturn("exec h_p_CJGXPLHB_Query '" + HMaterName + "'," + HOrgID + "", "h_p_CJGXPLHB_Query");
                DataSet ds = oCN.RunProcReturn("exec h_p_CJGXPLHB_Query '" + HMaterName + "'," + HOrgID + ",'"+ HProcNumber + "'", "h_p_CJGXPLHB_Query");
               
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
@@ -1497,20 +1515,35 @@
        #region 返回工序出站汇报单列表
        [Route("Cj_StationOutBill/get_Display")]
        [HttpGet]
        public object get_Display(string sWhere,string user)
        public object get_Display(string sWhere,string user,string HBillSubType)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Query", 1, false, user))
                if (HBillSubType == "SUB")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查询权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                    //判断是否有查询权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Query", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "完工单无查询权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else {
                    //判断是否有查询权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Query", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单无查询权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                //获取系统参数
                string Ret = "";
@@ -1939,20 +1972,35 @@
        #region 根据id删除出站单
        [Route("Cj_StationOutBill/del_StationOutBill")]
        [HttpGet]
        public object del_StationOutBill(long HInterID, string HDeleteMan)
        public object del_StationOutBill(long HInterID, string HDeleteMan,string HBillSubType)
        {
            try
            {
                string HComputerName = SystemInformation.ComputerName; //设备名称
                //编辑权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Drop", 1, false, HDeleteMan))
                if (HBillSubType == "SUB")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                    //编辑权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Drop", 1, false, HDeleteMan))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "完工单无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else {
                    //编辑权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Drop", 1, false, HDeleteMan))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                DAL.ClsSc_StationOutBill oBill = new DAL.ClsSc_StationOutBill();
                if (oBill.ShowBill(HInterID, ref DBUtility.ClsPub.sExeReturnInfo))
                {
@@ -2011,6 +2059,27 @@
                        objJsonResult.Message = "系统参数控制,已有下道工序,不能删除!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //删除前判断有没有生成金蝶单据(生产汇报单,生产入库单)
                    ds = oCn.RunProcReturn($"exec h_p_Cj_StationOutBill_BeforeDelCtrl {HInterID}", "h_p_Cj_StationOutBill_BeforeDelCtrl");
                    if (ds == null || ds.Tables[0].Rows.Count <= 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "删除出站汇报单发生异常,没有任何返回记录!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows[0]["HBackCount"].ToString() == "1")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = ds.Tables[0].Rows[0]["HRemarkBack"].ToString();
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    if (!oBill.DeleteBill(oBill.omodel.HInterID, oBill.omodel.HProcExchInterID, oBill.omodel.HProcExchEntryID, ref DBUtility.ClsPub.sExeReturnInfo))
@@ -2168,20 +2237,35 @@
        #region 审核
        [Route("Cj_StationOutBill/set_CheckBill")]
        [HttpGet]
        public object set_CheckBill(string HInterID, string CurUserName)
        public object set_CheckBill(string HInterID, string CurUserName,string HBillSubType)
        {
            try
            {
                string ModRightNameCheck = "Cj_StationOutBill_Check";
                ////审核权限
                if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, false, CurUserName))
                if (HBillSubType == "SUB")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "审核失败!无权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                    ////审核权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Check", 1, false, CurUserName))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "完工单审核失败!无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {   ////审核权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Check", 1, false, CurUserName))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单审核失败!无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                var HBillNo = HInterID.Split(',');
                DAL.ClsSc_StationOutBill oBill = new DAL.ClsSc_StationOutBill();
@@ -2296,20 +2380,35 @@
        #region 反审核
        [Route("Cj_StationOutBill/set_AbandonCheck")]
        [HttpGet]
        public object set_AbandonCheck(string HInterID, string CurUserName)
        public object set_AbandonCheck(string HInterID, string CurUserName,string HBillSubType)
        {
            try
            {
                string ModRightNameCheck = "Cj_StationOutBill_Check";
                ////审核权限
                if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, false, CurUserName))
                if (HBillSubType == "SUB")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "反审核失败!无权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                    ////审核权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Check", 1, false, CurUserName))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "完工单反审核失败!无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    ////审核权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Check", 1, false, CurUserName))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单反审核失败!无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                var HBillNo = HInterID.Split(',');
                DAL.ClsSc_StationOutBill oBill = new DAL.ClsSc_StationOutBill();
@@ -2448,19 +2547,34 @@
        #region 工序出站关闭/反关闭功能
        [Route("Cj_StationOutBill/CloseCj_StationOutBill")]
        [HttpGet]
        public object CloseCj_StationOutBill(string HInterID, int Type, string user)
        public object CloseCj_StationOutBill(string HInterID, int Type, string user,string HBillSubType)
        {
            try
            {
                //判断是否有删除权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Close", 1, false, user))
                if (HBillSubType == "SUB")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限关闭!";
                    objJsonResult.data = null;
                    return objJsonResult;
                    //判断是否有删除权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Close", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "完工单无权限关闭!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else {
                    //判断是否有删除权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Close", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单无权限关闭!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                if (string.IsNullOrWhiteSpace(HInterID))
                {