chenhaozhe
23 小时以前 862257fe2991fa96e0f20e31bcf00e4f9b1f86a2
WebAPI/Controllers/Sc_ProcessMangementController.cs
@@ -12,6 +12,7 @@
using WebAPI.Models;
using WebAPI.Service;
using Kingdee.BOS.WebApi.Client;
using SyntacticSugar.constant;
namespace WebAPI.Controllers
{
@@ -34,12 +35,21 @@
        {
            try
            {
                List<object> a = new List<object>();
                foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用
                {
                    Type dataType = col.DataType; //获取当前数据类型传入 自定义变量datadataType
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接         // 将列名和数据类型信息拼接成一个JSON格式的字符串
                    a.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                //if (ds.Tables[0].Rows.Count != 0 || ds != null)
                //{
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = a;
                return objJsonResult;
                //}
                //else
@@ -482,6 +492,8 @@
        {
            try
            {
                LogService.Write("生产汇报单进入同步方法,汇报单号:" + BillNo);
                string sErr = "";
                oSystemParameter.ShowBill(ref sErr);
@@ -495,6 +507,7 @@
                DataSet ds = oCN.RunProcReturn("select * from h_v_MES_StationOutBillList_LastProc where HInterID=" + InterID, "h_v_MES_StationOutBillList_LastProc");
                if (ds.Tables[0].Rows.Count <= 0)
                {
                    LogService.Write("生产汇报单回滚,汇报单号:" + BillNo + "   原因:生成生产汇报单过程中没有查询到出站单");
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "生成生产汇报单过程中没有查询到出站单";
@@ -505,9 +518,10 @@
                //保存
                oCN.BeginTran();
                DataSet DsTable = oCN.RunProcReturn($"select * from Sc_ICMOReportBillMain where HBillNo='{HBillNo}'", "Sc_ICMOReportBillMain");
                DataSet DsTable = oCN.RunProcReturn($"select * from Sc_ICMOReportBillMain with(nolock) where HBillNo='{HBillNo}'", "Sc_ICMOReportBillMain");
                if (DsTable.Tables[0].Rows.Count > 0)
                {
                    LogService.Write("生产汇报单回滚,汇报单号:" + BillNo + "   原因:已入库,请不要重复入库");
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "已入库,请不要重复入库";
@@ -550,6 +564,7 @@
                var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
                if (isSuccess == 0)
                {
                    LogService.Write("生产汇报单回滚,汇报单号:" + BillNo + "   原因:操作失败,金蝶账号登录异常");
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "操作失败,金蝶账号登录异常。" + loginRet;
@@ -643,6 +658,7 @@
                if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                {
                    LogService.Write("工序汇报单入库错误jsonRoot:" + jsonRoot);
                    LogService.Write("生产汇报单保存失败,汇报单号:" + BillNo + "   原因:" + result);
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
@@ -663,10 +679,11 @@
                result2 = InvokeHelper.Audit("PRD_MORPT", JsonConvert.SerializeObject(json));//提交
                if (JObject.Parse(result1)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                {
                    LogService.Write("生产汇报单提交失败,汇报单号:" + BillNo + "   原因:" + result1);
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = $"生产汇报单单号:{fBillNo},提交失败" + result;
                    objJsonResult.Message = $"生产汇报单单号:{fBillNo},提交失败" + result1;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
@@ -674,6 +691,9 @@
                oCN.RunProc("update Sc_StationOutBillMain set HRelationQty=1 where  HBillNo='" + BillNo + "'");
                oCN.Commit();
                LogService.Write("生产汇报单保存成功,汇报单号:" + BillNo );
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "保存成功!";
@@ -682,6 +702,7 @@
            }
            catch (Exception e)
            {
                LogService.Write("生产汇报单同步发生异常,汇报单号:" + BillNo + "    " + e.ToString());
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
@@ -768,6 +789,7 @@
        {
            try
            {
                LogService.Write("生产入库单进入同步方法:" + "  入库单号:" + BillNo);
                //获取生产汇报单最大InterID和单据号
                Int64 HInterID = DBUtility.ClsPub.CreateBillID("1202", ref DBUtility.ClsPub.sExeReturnInfo);
                string HBillNo = DBUtility.ClsPub.CreateBillCode("1202", ref DBUtility.ClsPub.sExeReturnInfo, true);
@@ -778,10 +800,11 @@
                //DataRow dr = ds.Tables[0].Rows[0];
                //判断入库的合格数量是否为0
                var DTable = oCN.RunProcReturn("select * from  Sc_StationOutBillMain where HBillNo='" + BillNo + "' ", "Sc_StationOutBillMain").Tables[0];
                var DTable = oCN.RunProcReturn("select * from Sc_StationOutBillMain with(nolock) where HBillNo='" + BillNo + "' ", "Sc_StationOutBillMain").Tables[0];
                if (double.Parse(DTable.Rows[0]["HQty"].ToString()) == 0)
                {
                    LogService.Write("同步金蝶生产生产入库单回滚--出站单号:" + BillNo + "  回滚原因:合格数量为0,不需要入库!");
                    objJsonResult.code = "1";
                    objJsonResult.count = 2;
                    objJsonResult.Message = "合格数量为0,不需要入库!";
@@ -827,6 +850,7 @@
                var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
                if (isSuccess == 0)
                {
                    LogService.Write("同步金蝶生产入库单回滚--出站单号:" + BillNo + "  回滚原因:操作失败,金蝶账号登录异常");
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "操作失败,金蝶账号登录异常。" + loginRet;
@@ -839,6 +863,7 @@
                if (ds1 == null || ds1.Tables[0].Rows.Count == 0)
                {
                    LogService.Write("同步金蝶生产入库单回滚--出站单号:" + BillNo + "  回滚原因:未找到对应的本地或金蝶云生产汇报单记录;1.未查询到对应的生产汇报单;2.请确保当前工序是末道工序3.汇报单对应的入库数量已满 请在金蝶云查看入库记录!");
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "未找到对应的本地或金蝶云生产汇报单记录;1.未查询到对应的生产汇报单;2.请确保当前工序是末道工序3.汇报单对应的入库数量已满 请在金蝶云查看入库记录!";
@@ -849,6 +874,7 @@
                DataRow dr1 = ds1.Tables[0].Rows[0];
                if (double.Parse(dr1[0].ToString()) <= 0)
                {
                    LogService.Write("同步金蝶生产入库单回滚--出站单号:" + BillNo + "  回滚原因:未找到对应的生产汇报单记录;1.未查询到对应的生产汇报单;2.请确保当前工序是末道工序3.汇报单对应的入库数量已满 请在金蝶云查看入库记录!");
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "未找到对应的生产汇报单记录;1.未查询到对应的生产汇报单;2.请确保当前工序是末道工序3.汇报单对应的入库数量已满 请在金蝶云查看入库记录!";
@@ -868,6 +894,7 @@
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            LogService.Write("同步金蝶生产入库单回滚--出站单号:" + BillNo + "  回滚原因:当前出站单号已入库,请不要重新入库!");
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "当前出站单号已入库,请不要重新入库!";
@@ -876,7 +903,7 @@
                        }
                        //判断金蝶云生产汇报单 数量 是否 大于 末道出站数量
                        ds = oCN.RunProcReturn($@"select sum(FFinishQty)-sum(FSTOCKINQUASELQTY)-(select HQty from Sc_StationOutBillMain where HBillNo='{BillNo}')
                        ds = oCN.RunProcReturn($@"select sum(FFinishQty)-sum(FSTOCKINQUASELQTY)-(select HQty from Sc_StationOutBillMain with(nolock) where HBillNo='{BillNo}')
                        from  AIS20220308151944..T_PRD_MORPT rpt3 
                        left join AIS20220308151944..T_PRD_MORPTENTRY  rpt2 on rpt3.FID = rpt2.FID
                        left join AIS20220308151944..T_PRD_MORPTENTRY_A  rpt1 on rpt2.FID = rpt1.FID
@@ -884,6 +911,7 @@
                        if (double.Parse(ds.Tables[0].Rows[0][0].ToString()) < 0)
                        {
                            LogService.Write("同步金蝶生产入库单回滚--出站单号:" + BillNo + "  回滚原因:金蝶云汇报数量小于本地出站数量!");
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "金蝶云汇报数量小于本地出站数量!";
@@ -896,6 +924,7 @@
                        {
                            if (item["HWYID"].ToString() == null || item["HWYID"].ToString() == "" || item["HWYID"].ToString() == "undefined")
                            {
                                LogService.Write("同步金蝶生产入库单回滚--出站单号:" + BillNo + "  回滚原因:唯一ID为空,请重新手动入库或联系管理员!");
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "唯一ID为空,请重新手动入库或联系管理员!";
@@ -1045,8 +1074,8 @@
                string result = InvokeHelper.Save("PRD_INSTOCK", JsonConvert.SerializeObject(jsonRoot));//保存
                //判断保存是否成功
                if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                {
                    LogService.Write("生产入库错误jsonRoot:" + jsonRoot);
                {
                    LogService.Write("生产入库保存错误jsonRoot:" + jsonRoot + "  入库单号:" + BillNo);
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
@@ -1067,6 +1096,7 @@
                //result2 = InvokeHelper.Audit("PRD_INSTOCK", JsonConvert.SerializeObject(json));//提交
                if (JObject.Parse(result1)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                {
                    LogService.Write("生产入库提交错误jsonRoot:" + jsonRoot + "  入库单号:" + BillNo);
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
@@ -1076,7 +1106,7 @@
                }
                oCN.RunProc("update Sc_StationOutBillMain set HRelationQty=1 where  HBillNo='" + BillNo + "'");
                LogService.Write("生产入库同步成功:" + "  入库单号:" + BillNo);
                oCN.Commit();
                objJsonResult.code = "0";
                objJsonResult.count = 1;
@@ -1086,6 +1116,7 @@
            }
            catch (Exception e)
            {
                LogService.Write("生产入库同步发生异常:" + "  入库单号:" + BillNo + "    " + e.ToString());
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
@@ -1371,7 +1402,7 @@
            }
        }
        #region
        /// <summary>
        /// 生成金蝶云来料检验单
        /// </summary>
@@ -1617,9 +1648,306 @@
                return objJsonResult;
            }
        }
        #endregion
        #region 生成金蝶云来料检验单 2025/11/26
        [Route("QCStockInCheckBill/set_SaveQCStockInCheckBill_Json2")]
        [HttpGet]
        public object set_SaveQCStockInCheckBill_Json2(string HZJOrgNumber, string HMaterNumber, string HUnitNumber,
            double HCheckQty, double HRightQty, double HBadQty,
            string HCheckResult, string HSupNumber,
            string HUseResult, Int64 HSeQ, Int64 HSourceInterID,
            Int64 HSourceEntryID, string HSourceBillNo, string user,
            Int64 HWHID, Int64 HSPID, Int64 HSupID, Int64 HKeeperID,
            Int64 HMaterID, string HSourceBillType, Int64 HSLInterID,
            Int64 HSLEntryID, string HSLBillNo, Int64 HSLSeQ, string HBillNo, Int64 HInterID, string HBatchNo)
        {
            try
            {
                //获取生产汇报单最大InterID和单据号
                //Int64 HInterID = DBUtility.ClsPub.CreateBillID("7503", ref DBUtility.ClsPub.sExeReturnInfo);
                //string HBillNo = DBUtility.ClsPub.CreateBillCode("7503", ref DBUtility.ClsPub.sExeReturnInfo, true);
                HBatchNo = HBatchNo ?? "";
                //保存
                oCN.BeginTran();
                //生产汇报单主表
                oCN.RunProc("Insert Into QC_POStockInCheckBillMain   " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HDate,HMaker,HMakeDate,HBillStatus,HChecker,HCheckDate" +
                ",HYear,HPeriod,HRemark,HSupID,HMaterID" +
                ",HInstockQty,HCheckQty,HRightQty,HBadQty,HFirstCheckEmp" +
                ",HCheckerResult,HSteelStoveNo,HSteelCompReport,HAspect,HSize" +
                ") " +
                " values('7503','7503'," + HInterID.ToString() + ",'" + HBillNo + "',getdate(),'" + user + "',getdate(),2,'" + user + "',getdate()" +
                ",DATENAME(YEAR,GETDATE()),0,''," + HSupID.ToString() + "," + HMaterID.ToString() +
                ",'" + HCheckQty.ToString() + "','" + HCheckQty.ToString() + "','" + HRightQty.ToString() + "','" + HBadQty.ToString() + "','" + HKeeperID.ToString() + "'" +
                ",'" + HCheckResult.ToString() + "','', '','',''" +
                ") ");
                //生产汇报单子表
                oCN.RunProc("Insert into QC_POStockInCheckBillSub " +
                      " (HInterID,HEntryID,HCloseMan,HCloseType" +
                      ",HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType" +
                      ",HRelationQty,HRelationMoney,HQCCheckClassID,HQCCheckItemID,HQCStd," +
                      "HResult,HQCRelValue,HProcCheckEmp,HProcCheckTime" +
                      ") values("
                      + HInterID.ToString() + ",1,'',''" +
                      ",''," + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo.ToString() + "','" + HSourceBillType.ToString() + "'" +
                      ",0,0,0,0,''" +
                      ",'" + HCheckResult.ToString() + "','" + HCheckResult.ToString() + "','" + HKeeperID.ToString() + "',getdate()" +
                      ") ");
                //同步金蝶
                //访问金蝶
                var loginRet = InvokeHelper.Login();
                var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
                if (isSuccess == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "操作失败,金蝶账号登录异常。" + loginRet;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                // string sql = @"select a.FID,a.FNUMBER Employee,d.FNUMBER Dept from Gy_Employee e
                //             join AIS20210811135644..T_HR_EMPINFO a on e.HNumber = a.FNUMBER
                //             join AIS20210811135644..T_BD_STAFFTEMP c on c.FID = a.FID
                //             join AIS20210811135644..T_BD_DEPARTMENT d on c.FDEPTID = d.FDEPTID
                //             where e.HItemID ='" + HKeeperID + "' ";
                // //查询质检员对应质检部门
                // ds = oCN.RunProcReturn(sql, "T_HR_EMPINFO");
                // LogService.Write("sql" + sql);
                // if (ds.Tables[0].Rows.Count == 0)
                // {
                //     objJsonResult.code = "0";
                //     objJsonResult.count = 0;
                //     objJsonResult.Message = "操作失败,质检员对应质检部门无数据。" + sql;
                //     objJsonResult.data = null;
                //     return objJsonResult;
                // }
                JObject model = new JObject();
                model.Add("FBillTypeID", new JObject() { ["Fnumber"] = "JYD001_SYS" }); //单据类型 来料检验单JYD001_SYS
                model.Add("FBusinessType", "1"); //业务类型
                model.Add("FDate", DateTime.Now.ToString("yyyy-MM-dd")); //单据日期
                model.Add("FInspectOrgId", new JObject() { ["Fnumber"] = HZJOrgNumber.ToString() }); //质检组织
                model.Add("FSourceOrgId", new JObject() { ["Fnumber"] = HZJOrgNumber.ToString() }); //来源组织
                //model.Add("FInspectDepId", new JObject() { ["Fnumber"] = ds.Tables[0].Rows[0]["Dept"].ToString() }); //质检部门
                //model.Add("FInspectorId", new JObject() { ["Fnumber"] = ds.Tables[0].Rows[0]["Employee"].ToString() }); //质检员
                model.Add("FISSYNCED", "false");//  是否已同步
                model.Add("F_PGKJ_Date", DateTime.Now.ToString("yyyy-MM-dd"));//  报检日期
                model.Add("FBillNo", HBillNo);
               // LogService.Write("质检部门" + ds.Tables[0].Rows[0]["Dept"].ToString());
               // LogService.Write("质检员" + ds.Tables[0].Rows[0]["Employee"].ToString());
                JArray Fentity = new JArray();
                JObject FentityModel = new JObject();
                FentityModel.Add("FMaterialId", new JObject() { ["Fnumber"] = HMaterNumber.ToString() });//  物料内码
                FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = HUnitNumber.ToString() });//计量单位内码
                FentityModel.Add("FInspectQty", HCheckQty.ToString());//  检验数量
                FentityModel.Add("FQualifiedQty", HRightQty.ToString());//  合格数量
                FentityModel.Add("FUnqualifiedQty", HBadQty.ToString());//  不合格数量
                FentityModel.Add("FInspectResult", HCheckResult.ToString());//  检验结果
                FentityModel.Add("FQCStatus", "1");//  质检状态
                FentityModel.Add("FIsRelated", false);//  不良品关联标志
                FentityModel.Add("FSrcBillType0", "PUR_ReceiveBill");//  源单类型
                FentityModel.Add("FBaseUnitId", new JObject() { ["Fnumber"] = HUnitNumber.ToString() });//基本单位
                FentityModel.Add("FBaseInspectQty", HCheckQty.ToString());//基本单位检验数量
                FentityModel.Add("FSupplierId", new JObject() { ["Fnumber"] = HSupNumber.ToString() }); //  供应商
                                                                                                        //FentityModel.Add("FStockId", new JObject() { ["Fnumber"] = HWHNumber.ToString() }); // 仓库
                FentityModel.Add("FInspectTimes", "1"); // 检验次数
                FentityModel.Add("FTimeUnit", "24");//时间单位
                FentityModel.Add("FSAMPLEDAMAGEBEARER", "2");//样本破坏承担方
                FentityModel.Add("FISFIRSTINSPECT", false);//首检
                FentityModel.Add("FBaseQualifiedQty", HRightQty.ToString());//基本单位合格数
                FentityModel.Add("FBaseAcceptQty", HRightQty.ToString());//基本单位接收数
                FentityModel.Add("FCurrency", new JObject() { ["Fnumber"] = "PRE001" });//币别
                FentityModel.Add("FIsSplitRow ", false);// 是否拆分行
                FentityModel.Add("FLot", new JObject() { ["Fnumber"] = HBatchNo.ToString() });//批号
                JArray Fentity2 = new JArray();
                JObject FentityModel2 = new JObject();
                FentityModel2.Add("FPolicyMaterialId", new JObject() { ["Fnumber"] = HMaterNumber.ToString() });//  物料内码
                FentityModel2.Add("FPolicyStatus", "1");  //状态
                FentityModel2.Add("FPolicyQty", HRightQty.ToString() == "0" ? HBadQty.ToString() : HRightQty.ToString());    //数量
                FentityModel2.Add("FBasePolicyQty", HRightQty.ToString() == "0" ? HBadQty.ToString() : HRightQty.ToString()); //基本单位数量
                FentityModel2.Add("FUsePolicy", HUseResult.ToString());   //使用决策
                FentityModel2.Add("FIsCheck", false);   //是否抽检
                FentityModel2.Add("FIsDefectProcess", false);  //不良处理
                FentityModel2.Add("FCanSale", false);   //可销售
                FentityModel2.Add("FIsMRBReview", false);   //MRP评审
                FentityModel2.Add("FIsReturn", true);   //判退
                FentityModel2.Add("FIsRelatedDefect", false);   //不良品关联标志
                Fentity2.Add(FentityModel2);
                FentityModel.Add("FPolicyDetail", Fentity2);
                JArray Fentity3 = new JArray();
                JObject FentityModel3 = new JObject();
                FentityModel3.Add("FDetailID", "0");//
                FentityModel3.Add("FSrcBillType", "PUR_ReceiveBill");   //源单类型
                FentityModel3.Add("FSrcBillNo", HSLBillNo.ToString());    //收料通知单单号
                FentityModel3.Add("FSrcInterId", HSLInterID.ToString());      //收料通知单主ID
                FentityModel3.Add("FSrcEntryId", HSLEntryID.ToString());    //收料通知单子ID
                FentityModel3.Add("FSrcEntrySeq", HSLSeQ.ToString());    //源单行号
                FentityModel3.Add("FOrderType", new JObject() { ["FID"] = "PUR_PurchaseOrder" });  //  订单类型
                FentityModel3.Add("FOrderBillNo", HSourceBillNo.ToString());   //订单单号
                FentityModel3.Add("FOrderId", HSourceInterID.ToString());      //订单主ID
                FentityModel3.Add("FOrderEntryId", HSourceEntryID.ToString());  //订单子ID
                FentityModel3.Add("FOrderEntrySeq", HSeQ.ToString());  //订单行号
                Fentity3.Add(FentityModel3);
                FentityModel.Add("FReferDetail", Fentity3);
                JArray Fentity4 = new JArray();
                JObject FentityModel4 = new JObject();
                FentityModel4.Add("FEntity_Link_FRuleId", "QM_PURReceive2Inspect");   //单据转换规则
                FentityModel4.Add("FEntity_Link_FSTableName", "T_PUR_RECEIVEENTRY");    //收料通知单子表
                FentityModel4.Add("FEntity_Link_FSBillId", HSLInterID.ToString());      //收料通知单主内码
                FentityModel4.Add("FEntity_Link_FSId", HSLEntryID.ToString());    //收料通知单子内码
                FentityModel4.Add("FEntity_Link_FBaseAcceptQty", HRightQty.ToString());    //
                FentityModel4.Add("FEntity_Link_FBaseAcceptQtyOld", HRightQty.ToString());    //
                FentityModel4.Add("FEntity_Link_FBaseInspectQtyOld", HRightQty.ToString());    //
                FentityModel4.Add("FEntity_Link_FInspectQtyOld", HRightQty.ToString());    //
                Fentity4.Add(FentityModel4);
                FentityModel.Add("FEntity_Link", Fentity4);
                Fentity.Add(FentityModel);
                model.Add("FEntity", Fentity); //明细信息
                JObject jsonRoot = new JObject()
                {
                    ["Creator"] = "",
                    ["NeedUpDateFields"] = new JArray(),
                    ["NeedReturnFields"] = new JArray(),
                    ["IsDeleteEntry"] = "false",
                    ["SubSystemId"] = "",
                    ["IsVerifyBaseDataField"] = "false",
                    //["IsAutoSubmitAndAudit"] = true,//自动调用提交和审核功能
                    ["Model"] = model
                };
                LogService.Write("检验单json:" + jsonRoot);
                string result = InvokeHelper.Save("QM_InspectBill", JsonConvert.SerializeObject(jsonRoot));//保存
                //判断保存是否成功
                if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                {
                    LogService.Write("来料检验单保存错误jsonRoot:" + jsonRoot);
                    LogService.Write("报错:" + result);
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = $"来料检验单同步金蝶云失败!单号:{HBillNo.ToString()}" + jsonRoot;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //提交审核
                string result1 = string.Empty;
                string result2 = string.Empty;
                var fID = JObject.Parse(result)["Result"]["Id"].ToString();
                var fBillNo = JObject.Parse(result)["Result"]["Number"].ToString();
                var json = new
                {
                    Ids = fID,
                };
                K3CloudApiClient client = new K3CloudApiClient("http://47.96.97.237/k3cloud");
                //        K3CloudApiClient client = new K3CloudApiClient("http://192.168.80.90/k3cloud/");
                result1 = InvokeHelper.Submit("QM_InspectBill", JsonConvert.SerializeObject(json));//提交
                //result2 = InvokeHelper.Audit("QM_InspectBill", JsonConvert.SerializeObject(json));//审核
                if (JObject.Parse(result1)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = $"来料检验单号:{fBillNo},提交失败" + result;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    DataSet ds1 = oCN.RunProcReturn("select * from MES_AccessoriesList  where  HSourceBillNo = '" + HBillNo + "'", "MES_AccessoriesList");
                    for (var i = 0; i < ds1.Tables[0].Rows.Count; i++)
                    {
                        string HFileName = DBUtility.ClsPub.isStrNull(ds1.Tables[0].Rows[i]["HFileName"]);
                        string HFilePath = DBUtility.ClsPub.isStrNull(ds1.Tables[0].Rows[i]["HFilePath"]);
                        string path = HFilePath;
                        FileInfo fi = new FileInfo(path);
                        long len = fi.Length;
                        byte[] buffer = new byte[len];
                        FileStream fs = new FileStream(path, FileMode.Open);
                        fs.Read(buffer, 0, (int)len);
                        //文件IO流
                        string a = Convert.ToBase64String(buffer);
                        ds = oCN.RunProcReturn("select * from  AIS20210811135644..T_QM_INSPECTBILL where FBILLNO='" + HBillNo + "'", "T_QM_INSPECTBILL");
                        HInterID = long.Parse(ds.Tables[0].Rows[0]["FID"].ToString());
                        string jsonStr = "{" +
                           " \"FileName\":\"" + HFileName + "\"," +
                               " \"FormId\":\"QM_InspectBill\"," +
                               " \"IsLast\":\"true\"," +
                               " \"InterId\":\"" + HInterID + "\"," +
                               " \"BillNo\":\"" + HBillNo + "\"," +
                               " \"AliasFileName\":\"test\"," +
                               " \"SendByte\":\"" + a + "\"" +
                           "}";
                        string _vlog = InvokeHelper.UpLoad("QM_InspectBill", jsonStr);
                        LogService.Write("json:" + jsonStr);
                        LogService.Write("_vlog:" + _vlog);
                        if (JObject.Parse(_vlog)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                        {
                            oCN.RollBack();
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = $"来料检验单号:{fBillNo},照片同步失败" + _vlog;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    //string jsonStr = "{" +
                    //   " \"FileName\":\"" + HFileName + "\"," +
                    //       " \"FormId\":\"QM_InspectBill\"," +
                    //       " \"IsLast\":\"true\"," +
                    //       " \"InterId\":\"" + HInterID + "\"," +
                    //       " \"BillNO\":\"" + HBillNo + "\"," +
                    //       " \"AliasFileName\":\"test\"," +
                    //       " \"SendByte\":\"" + a + "\"," +
                    //   "}";
                    //var ret = client.AttachmentUpload(jsonStr);
                }
                oCN.Commit();
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "保存成功!";
                objJsonResult.data = 1;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
@@ -2054,6 +2382,7 @@
            DataSet ds;
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Sc_ProcessPlan_Query", 1, false, user))
                {
                    objJsonResult.code = "0";
@@ -2074,6 +2403,7 @@
                    string sql = sql1 + sWhere + " order by hmainid desc ";
                    ds = oCN.RunProcReturn(sql, "h_v_Sc_ProcessPlanList");
                }
            }
            catch (Exception e)
            {
@@ -6089,6 +6419,61 @@
        }
        #endregion
        #region 不良品评审处理单 分页列表
        [Route("Sc_ProcessMangement/getGet_QC_NoPassProdDisposeBillListPage")]
        [HttpGet]
        public json Get_QC_NoPassProdDisposeBillListPage(string sWhere, string user, int page, int size)
        {
            DataSet ds;
            json res = new json();
            try
            {
                List<object> columnNameList = new List<object>();
                //判断权限
                if (!DBUtility.ClsPub.Security_Log("QC_NoPassProdDisposeBillMain_Query", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限查询!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                sWhere = sWhere.Replace("'", "''");
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("exec h_p_QC_NoPassProdDisposeBillList " + page + "," + size + ",''", "h_p_QC_NoPassProdDisposeBillList");
                }
                else
                {
                    ds = oCN.RunProcReturn("exec h_p_QC_NoPassProdDisposeBillList " + page + "," + size + ",'" + sWhere + "'", "h_p_QC_NoPassProdDisposeBillList");
                }
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                res.code = CodeConstant.SUCCEED;
                res.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
                res.Message = "Sucess!";
                res.list = columnNameList;
                res.data = ds.Tables[0];
                return res;
            }
            catch (Exception e)
            {
                res.code = CodeConstant.FAIL;
                res.count = CountConstant.FAIL;
                res.Message = "Exception!" + e.ToString();
                res.data = null;
                return res;
            }
        }
        #endregion
        #region 不良品评审处理单 删除
        [Route("Sc_ProcessMangement/DeleteQC_NoPassProdDisposeBill")]
@@ -6507,8 +6892,30 @@
                //进行需要进行的关闭/反关闭操作
                if (IsAudit == 0) //关闭提交
                {
                    //关闭前控制=========================================
                    string sql1 = "exec h_p_Sc_WorkBeginDotCheckBill_BeforeCloseCtrl " + oBill.omodel.HInterID + ",'" + oBill.omodel.HBillNo + "','" + CurUserName + "'";
                    ds = oCN.RunProcReturn(sql1, "h_p_Sc_WorkBeginDotCheckBill_BeforeCloseCtrl");
                    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 (oBill.CloseBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                    if (oBill.CloseBill(lngBillKey, oBill.omodel.HBillNo, "h_p_Sc_WorkBeginDotCheckBill_AfterCloseCtrl", CurUserName, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                    {
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
@@ -6527,8 +6934,31 @@
                }
                if (IsAudit == 1) //反关闭提交
                {
                    //反关闭前控制=========================================
                    string sql1 = "exec h_p_Sc_WorkBeginDotCheckBill_BeforeUnCloseCtrl " + oBill.omodel.HInterID + ",'" + oBill.omodel.HBillNo + "','" + CurUserName + "'";
                    ds = oCN.RunProcReturn(sql1, "h_p_Sc_WorkBeginDotCheckBill_BeforeUnCloseCtrl    ");
                    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 (oBill.CancelClose(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                    if (oBill.CancelClose(lngBillKey, oBill.omodel.HBillNo, "h_p_Sc_WorkBeginDotCheckBill_AfterUnCloseCtrl", CurUserName, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                    {
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
@@ -6695,6 +7125,45 @@
        }
        #endregion
        #region 不良品评审处理单 出站单下推查询
        [Route("Sc_ProcessMangement/Get_Sc_StationOutBill")]
        [HttpGet]
        public object Get_Sc_StationOutBill(string HID)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                string sql = "select * from h_v_MES_StationOutBillList where hmainid='" + HID + "'";
                ds = oCN.RunProcReturn(sql, "h_v_MES_StationOutBillList");
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    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 ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "查询数据异常,请与管理员联系!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
        #region 不良品评审处理验收单