yangle
2024-09-19 3b9d0ef535563fff2102a76a59581301037a2b84
设备维修记录单 模具维修记录单 保养记录单
1个文件已修改
811 ■■■■■ 已修改文件
WebAPI/Controllers/数据同步/钉钉同步/DD_DataSynchronizationController.cs 811 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebAPI/Controllers/Êý¾Ýͬ²½/¶¤¶¤Í¬²½/DD_DataSynchronizationController.cs
@@ -231,6 +231,111 @@
        }
        #endregion
        #region æ¨¡å…·ä¿å…»ç»´ä¿®è¡¨
        public class MouldFileWeiXiuBaoYang
        {
            //ClsSb_MouldRepairWorkBillSub
            //单据信息
            public string HMakerID;                             //创建人ID
            public string HMaker;                               //创建人名称
            public string HMakeDate;                            //创建日期
            public string HUpdaterID;                           //修改人ID
            public string HUpdater;                             //修改人名称
            public string HUpdateDate;                          //修改日期
            public string HInstanceID;                          //单据实例ID
            public string HOriginator;                          //发起人
            public string HTitle;                               //单据标题
            public Int64 HEquipID;//              --设备ID(Gy_EquipMent)
            public Int64 HRepairID;//    --维修项目(Gy_Repair)
            public DateTime HRepairBeginDate;//  --维修开始日期
            public DateTime HRepairEndDate;//  --维修结束日期
            public string HRepairContent;//   --维修内容
            public string HCycleUnit;//   varchar(10)    --时间单位(小时,天)
            public double HPlanTimes;//  money         --计划维修工时
            public double HTimes;//      money       --实际维修工时
            public Int64 HEmpID;//    int    --维修人(Gy_Employee)
            public Int64 HManagerID;//   int       --负责人(Gy_Employee)
            public Int64 HDeptID;//    int    --维修部门(Gy_Department)
            public string HExplanation;//   varchar(500)    --维修要求
            public string HInnerBillNo;//   varchar(50)   --内部单据号
            public Int64 HMouldID;
            public Int64 HSupID;//        int    --供应商(Gy_Supplier)                    addnew
            public string HRepairType;//    varchar(10)        --维修类型(内部维修,委外维修)       addnew
            public string HNewModel;//    varchar(100)        --维修后新规格                addnew
            public Single HNewDesignLife;//    money            --新设计寿命
            public string HRemark;
            //单据内容
            public string HDate;                                //日期
            public string HCheckLevel;                          //审核等级
            public string HArea;                                //区域
            public string HEmployeeID;                          //成员ID
            public string HEmplpyee;                            //成员名称
            public List<Sc_MouldRepairWorkBillSub> DetailColMouldRepair = new List<Sc_MouldRepairWorkBillSub>();
            public List<Sc_MouldMaintainBillSub> DetailColMouldMaintain = new List<Sc_MouldMaintainBillSub>();
        }
        //维修子表
        public class Sc_MouldRepairWorkBillSub
        {
            public string HRepairExplanation;
            public string HRemark;
        }
        //保养子表
        public class Sc_MouldMaintainBillSub
        {
            public string HClaim;
            public string HMaintainResult;
        }
        #endregion
        #region è®¾å¤‡ç»´ä¿®è®°å½•表
        public class EquipRepairWeiXiu
        {
            //单据信息
            public string HMakerID;                             //创建人ID
            public string HMaker;                               //创建人名称
            public string HMakeDate;                            //创建日期
            public string HUpdaterID;                           //修改人ID
            public string HUpdater;                             //修改人名称
            public string HUpdateDate;                          //修改日期
            public string HInstanceID;                          //单据实例ID
            public string HOriginator;                          //发起人
            public string HTitle;                               //单据标题
            public Int64 HEmpID;//    int                --维修人
            public Int64 HManagerID;//   int            --负责人
            public Int64 HSecManagerID;//  int           --验收
            public Int64 HDeptID;//     int             --维修部门
            public string HExplanation;//   varchar(200)        --维修要求
            public string HInnerBillNo;//  varchar(50)         --内部单据号
            public string HRemark; //加工要求
            public Int64 HEquipID;//     int       --设备ID(Gy_EquipMent)
            public Int64 HRepairID;//int  --维修项目(Gy_Repair)
            public DateTime HRepairBeginDate;// datetime --维修开始日期
            public DateTime HRepairEndDate;//datetime --维修结束日期
            public string HRepairContent;//varchar(500) --维修内容
            public string HCycleUnit;//varchar(10)    --时间单位(小时,天)
            public Single HPlanTimes;// money         --计划维修工时
            public Single HTimes;// money       --实际维修工时
            public string HRemark2;//备注
            //单据内容
            public string HDate;                                //日期
            public string HCheckLevel;                          //审核等级
            public string HArea;                                //区域
            public string HEmployeeID;                          //成员ID
            public string HEmplpyee;                            //成员名称
            public List<Sc_MouldRepairWorkBillSub> DetailColMouldRepair = new List<Sc_MouldRepairWorkBillSub>();
        }
        #endregion
        #endregion
        #region é’‰é’‰ é€šç”¨æ“ä½œæ–¹æ³•
@@ -397,7 +502,7 @@
                //OriginatorId = "12",                                                                                          //根据流程发起人工号查询。
                //TaskId = "12",                                                                                                //任务ID。
                CreateFromTimeGMT = DateTime.Now.ToString("dd") == "01"?"2022-01-01":DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"),                                          //创建时间起始值。
                CreateFromTimeGMT = DateTime.Now.ToString("dd") == "01"?"2022-01-01":DateTime.Now.AddDays(-14).ToString("yyyy-MM-dd"),                                          //创建时间起始值。
                CreateToTimeGMT = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"),                                               //创建时间终止值。
                PageSize = pageSize,                                                  //分页大小。
@@ -547,6 +652,51 @@
            }
        }
        #endregion
        #region èŽ·å– å®œæ­ æ ¹æ®æµç¨‹å®žä¾‹ID获取流程实例
        public bool getInstanceStatusByInstanceID__YiDa(string appType, string systemToken, string userID, string instanceID, ref GetInstanceByIdResponse response, ref string msg)
        {
            AlibabaCloud.SDK.Dingtalkyida_1_0.Client client = CreateClient5();
            AlibabaCloud.SDK.Dingtalkyida_1_0.Models.GetInstanceByIdHeaders getInstanceByIdHeaders = new AlibabaCloud.SDK.Dingtalkyida_1_0.Models.GetInstanceByIdHeaders();
            getInstanceByIdHeaders.XAcsDingtalkAccessToken = this.accessToken;
            AlibabaCloud.SDK.Dingtalkyida_1_0.Models.GetInstanceByIdRequest getInstanceByIdRequest = new AlibabaCloud.SDK.Dingtalkyida_1_0.Models.GetInstanceByIdRequest
            {
                SystemToken = systemToken,
                Language = "12",
                UserId = userID,
                AppType = appType,
            };
            try
            {
                GetInstanceByIdResponse getInstanceByIdResponse = client.GetInstanceByIdWithOptions(instanceID, getInstanceByIdRequest, getInstanceByIdHeaders, new AlibabaCloud.TeaUtil.Models.RuntimeOptions());
                response = getInstanceByIdResponse;
                return true;
            }
            catch (TeaException err)
            {
                if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
                {
                    // err ä¸­å«æœ‰ code å’Œ message å±žæ€§ï¼Œå¯å¸®åŠ©å¼€å‘å®šä½é—®é¢˜
                }
                msg = err.Message;
                return false;
            }
            catch (Exception _err)
            {
                TeaException err = new TeaException(new Dictionary<string, object>
                {
                    { "message", _err.Message }
                });
                if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
                {
                    // err ä¸­å«æœ‰ code å’Œ message å±žæ€§ï¼Œå¯å¸®åŠ©å¼€å‘å®šä½é—®é¢˜
                }
                msg = _err.Message;
                return false;
            }
        }
        #endregion
        #endregion
        #region æ•°æ®åŒæ­¥æ–¹æ³•
@@ -1635,6 +1785,665 @@
        }
        #endregion
        #endregion
        #region æ•°æ®åŒæ­¥-模具维修保养单
        #region èŽ·å– å®œæ­-模具维修保养单 å®žä¾‹ID列表对应的实例详情
        public bool getInstanceDetailList___MouldFileWeiXiuBaoYang_YiDa(string appType, string systemToken, string userID, string formUuid, List<string> IDList, ref List<MouldFileWeiXiuBaoYang> lsmain, ref string msg, int size = 500)
        {
            try
            {
                int startIndex = 0;
                int endIndex = startIndex + size;
                if (endIndex > IDList.Count)
                {
                    endIndex = IDList.Count;
                }
                while (startIndex < endIndex && endIndex <= IDList.Count)
                {
                    List<string> IDList_temp = new List<string>();
                    for (int i = startIndex; i < endIndex; i++)
                    {
                        IDList_temp.Add(IDList[i]);
                    }
                    BatchGetFormDataByIdListResponse response = new BatchGetFormDataByIdListResponse();
                    if (getInstanceDetailListByInstanceIDList_YiDa(appType, systemToken, formUuid, userID, IDList_temp, ref response, ref msg) == false)
                    {
                        return false;
                    }
                    for (int i = 0; i < response.Body.Result.Count; i++)
                    {
                        try
                        {
                            List<string> keys = new List<string>(response.Body.Result[i].FormData.Keys);
                            MouldFileWeiXiuBaoYang oItem = new MouldFileWeiXiuBaoYang();
                            oItem.HMakerID = response.Body.Result[i].CreatorUserId.Replace("'", "");
                            oItem.HMaker = response.Body.Result[i].CreatorUserId.Replace("'", "");
                            oItem.HMakeDate = response.Body.Result[i].CreateTimeGMT.Replace("T", " ").Replace("Z", "").Replace("'", "");
                            oItem.HUpdaterID = response.Body.Result[i].ModifyUser.UserId.Replace("'", "");
                            oItem.HUpdater = response.Body.Result[i].ModifyUser.Name.NameInChinese.Replace("'", "");
                            oItem.HUpdateDate = response.Body.Result[i].ModifiedTimeGMT.Replace("T", " ").Replace("Z", "").Replace("'", "");
                            oItem.HInstanceID = response.Body.Result[i].FormInstanceId.Replace("'", "");
                            oItem.HOriginator = response.Body.Result[i].Originator.Name.NameInChinese.Replace("'", "");
                            GetInstanceByIdResponse getInstanceByIdResponse = new GetInstanceByIdResponse(); ;
                            if (!getInstanceStatusByInstanceID__YiDa(appType, systemToken, userID, oItem.HInstanceID, ref getInstanceByIdResponse, ref msg))
                            {
                                continue;
                            }
                            if (getInstanceByIdResponse.Body.InstanceStatus != "COMPLETED")
                            {
                                continue;
                            }
                            //修模开始时间
                            if (keys.Contains("dateField_lq4gf2ih"))
                            {
                                double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_lq4gf2ih"].ToString());
                                oItem.HRepairBeginDate = DateTime.Parse(convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd HH:mm"));
                            }
                            //修模结束时间
                            if (keys.Contains("dateField_lq4gf2ii"))
                            {
                                double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_lq4gf2ii"].ToString());
                                oItem.HRepairEndDate = DateTime.Parse(convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd HH:mm"));
                            }
                            //模具批次号
                            if (keys.Contains("serialNumberField_lqaak4ts"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["serialNumberField_lqaak4ts"].ToString();
                                oItem.HRemark = HDate_Temp;
                            }
                            //模具编码
                            if (keys.Contains("dateField_lq4gf2ii"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["dateField_lq4gf2ii"].ToString();
                                DataSet ds = oCN.RunProcReturn("select * from Gy_MouldFileMain with(nolock)  where HNumber='" + HDate_Temp + "'", "Gy_MouldFileMain");
                                string HMouldID = "0";
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    HMouldID = ds.Tables[0].Rows[0]["HInterID"].ToString();
                                }
                                oItem.HMouldID = long.Parse(HMouldID);
                            }
                            //维修部门
                            if (keys.Contains("selectField_lq3idkva"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["selectField_lq3idkva"].ToString();
                                DataSet ds = oCN.RunProcReturn("select * from Gy_Department with(nolock)  where HName='" + HDate_Temp + "'", "Gy_Department");
                                string HDeptID = "0";
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    HDeptID = ds.Tables[0].Rows[0]["HItemID"].ToString();
                                }
                                oItem.HDeptID = long.Parse(HDeptID);
                            }
                            //新设计寿命
                            oItem.HNewDesignLife = 30000;
                            //维修人
                            if (keys.Contains("employeeField_lq3idkvh"))
                            {
                                string[] HDate_Temp = JsonConvert.DeserializeObject<string[]>(JsonConvert.SerializeObject(response.Body.Result[i].FormData["employeeField_lq3idkvh"]));
                                DataSet ds = oCN.RunProcReturn("select * from Gy_Employee with(nolock)  where HNumber='" + HDate_Temp[0] + "'", "Gy_Employee");
                                string HEmpID = "0";
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    HEmpID = ds.Tables[0].Rows[0]["HItemID"].ToString();
                                }
                                oItem.HEmpID = long.Parse(HEmpID);
                            }
                            //维修时间
                            if (keys.Contains("numberField_lq3ixr9j"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["numberField_lq3ixr9j"].ToString();
                                oItem.HTimes = long.Parse(HDate_Temp);
                                oItem.HPlanTimes = long.Parse(HDate_Temp);
                            }
                            //子表 ç»´ä¿®è¦æ±‚ ç»´ä¿®å¤‡æ³¨(问题描述)
                            if (keys.Contains("tableField_lq3ixr9b"))
                            {
                                List<Dictionary<string, object>> dic = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(JsonConvert.SerializeObject(response.Body.Result[i].FormData["tableField_lq3ixr9b"]));
                                for (int ij = 0; ij < dic.Count; ij++)
                                {
                                    Sc_MouldRepairWorkBillSub oItemSub = new Sc_MouldRepairWorkBillSub();
                                    List<string> keys_Sub = new List<string>(dic[ij].Keys);
                                    //维修要求
                                    if (keys_Sub.Contains("textareaField_lq3ixr9e"))
                                    {
                                        oItemSub.HRepairExplanation = dic[ij]["textareaField_lq3ixr9e"].ToString();
                                    }
                                    //备注
                                    if (keys_Sub.Contains("textField_lq3ixr9d"))
                                    {
                                        oItemSub.HRemark = dic[ij]["textField_lq3ixr9d"].ToString();
                                    }
                                    oItem.DetailColMouldRepair.Add(oItemSub);
                                }
                            }
                            string HRemark = "";
                            //子表 ä¿å…»å¤‡æ³¨(问题描述)
                            if (keys.Contains("textareaField_ltpf2wiw"))
                            {
                                HRemark = response.Body.Result[i].FormData["textareaField_ltpf2wiw"].ToString();
                            }
                            //子表 å…·ä½“要求 ä¿å…»é¡¹ç›®
                            if (keys.Contains("checkboxField_ltpf2wif"))
                            {
                                string[] HDate_Temp = JsonConvert.DeserializeObject<string[]>(JsonConvert.SerializeObject(response.Body.Result[i].FormData["checkboxField_ltpf2wif"]));
                                for (int ij = 0; ij < HDate_Temp.Length; ij++)
                                {
                                    Sc_MouldMaintainBillSub oItemSub = new Sc_MouldMaintainBillSub();
                                    oItemSub.HClaim = HDate_Temp[ij];
                                    oItemSub.HMaintainResult = HRemark;
                                    oItem.DetailColMouldMaintain.Add(oItemSub);
                                }
                            }
                            int startindex = response.Body.Result[i].Title.IndexOf("zh_CN") + 8;
                            oItem.HTitle = startIndex + response.Body.Result[i].Title.Substring(startindex).Replace("\"}", "").Replace("'", "");
                            if (keys.Contains("dateField_lo6w37hk"))
                            {
                                double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_lo6w37hk"].ToString());
                                oItem.HDate = convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd");
                            }
                            if (keys.Contains("selectField_lockncvh_id"))
                            {
                                oItem.HArea = response.Body.Result[i].FormData["selectField_lockncvh_id"].ToString().Replace("'", "");
                            }
                            if (keys.Contains("selectField_lockncvg_id"))
                            {
                                oItem.HCheckLevel = response.Body.Result[i].FormData["selectField_lockncvg_id"].ToString().Replace("'", "");
                            }
                            if (keys.Contains("employeeField_lo6w37hf"))
                            {
                                oItem.HEmplpyee = ((List<object>)response.Body.Result[i].FormData["employeeField_lo6w37hf"])[0].ToString().Replace("'", "");
                            }
                            if (keys.Contains("employeeField_lo6w37hf_id"))
                            {
                                oItem.HEmployeeID = ((List<object>)response.Body.Result[i].FormData["employeeField_lo6w37hf_id"])[0].ToString().Replace("'", "");
                            }
                            lsmain.Add(oItem);
                        }
                        catch (Exception e)
                        {
                            continue;
                        }
                    }
                    startIndex = endIndex;
                    endIndex += size;
                    if (endIndex > IDList.Count)
                    {
                        endIndex = IDList.Count;
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                msg = e.Message;
                return false;
            }
        }
        #endregion
        #region æ•°æ®åŒæ­¥
        public bool getData_MouldFileWeiXiuBaoYang(ref string msg)
        {
            //获取 åˆ†å±‚审核表 å®žä¾‹ID列表
            string appType = "APP_CSD7RLFJ3CTU330N3SCV";
            string systemToken = "9T566BD1NWMGH17C93CKA9M4AS0D233TNU0QL82";
            string userID = "011113050243860353";
            string formUuid = "FORM-30C78F46E77E46A9AA8778214CEFE6B5J0AN";
            int pageNumber = 1;
            int pageSize = 100;
            //获取模具维修保养表的实例ID列表
            List<string> IDList = new List<string>();
            if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false)
            {
                return false;
            }
            //获取详细信息并附加到列表lsmain中
            List<MouldFileWeiXiuBaoYang> lsmain = new List<MouldFileWeiXiuBaoYang>();
            if (getInstanceDetailList___MouldFileWeiXiuBaoYang_YiDa(appType, systemToken, userID, formUuid, IDList, ref lsmain, ref msg) == false)
            {
                return false;
            }
            try
            {
                oCN.BeginTran();
                foreach (MouldFileWeiXiuBaoYang oItem in lsmain)
                {
                    //保养记录
                    if (oItem.DetailColMouldMaintain.Count != 0)
                    {
                        string BillType = "3819";
                        string sql = $@"select HInnerBillNo from Sc_MouldMaintainBillMain
                            where HInnerBillNo = '{oItem.HInstanceID}'";
                        DataSet ds = oCN.RunProcReturn(sql, "Sc_MouldMaintainBillMain");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            long HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo);
                            string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
                            //long HInterID = 0;
                            //string HBillNo = "";
                            string sql_main = "Insert Into Sc_MouldMaintainBillMain " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HDate,HMaker,HMakeDate" +
                ",HYear,HPeriod,HRemark,HUpDateDate" +
                ",HPlanNo,HPlanInterID,HMouldID,HBeginDate" +
                ",HEndDate" +
                ",HInnerBillNo,HExplanation,HMouldMaintainRuleInterID,HMaintainLevID,HLastResult" +
                ")values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',getdate(),'" + oItem.HOriginator + "','" + oItem.HMakeDate + "'" +
                      ",'" + DateTime.Now.Year + "','" + DateTime.Now.Month + "','"+ oItem.HRemark + "','" + oItem.HUpdateDate + "'" +
                      ",'','0','" + oItem.HMouldID + "','" + oItem.HRepairBeginDate + "'" +
                      ",'" + oItem.HRepairEndDate + "'" +
                      ",'" + oItem.HInstanceID + "','',0,0,'OK')";
                            oCN.RunProc(sql_main);
                            int i = 1;
                            foreach (Sc_MouldMaintainBillSub oItem_Detail in oItem.DetailColMouldMaintain)
                            {
                                string sql_sub = "Insert into Sc_MouldMaintainBillSub_Item" +
                          " (HInterID,HEntryID,HMaintainItemID,HMaintainItem" +
                          ",HMaintainPart,HClaim" +
                          ",HManagerID" +
                          ",HCloseMan,HCloseType,HRemark" +
                          ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HMaintainResult" +
                          ") values('" + HInterID + "'," + i + ",0,'" + oItem_Detail.HClaim + "'" +
                     ",'','" + oItem_Detail.HClaim + "'" +
                     ",'" + oItem.HEmpID + "'" +
                     ",'','','" + oItem_Detail.HMaintainResult + "'" +
                     ",'0','0','','',0,0,'')";
                                oCN.RunProc(sql_sub);
                                i += 1;
                            }
                        }
                    }
                    //维修记录
                    if (oItem.DetailColMouldRepair.Count != 0)
                    {
                        string BillType = "3807";
                        string sql = $@"select HInnerBillNo from Sc_MouldRepairWorkBillMain
                            where HInnerBillNo = '{oItem.HInstanceID}'";
                        DataSet ds = oCN.RunProcReturn(sql, "Sc_MouldRepairWorkBillMain");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            long HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo);
                            string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
                            //long HInterID = 0;
                            //string HBillNo = "";
                            string sql_main = "Insert Into Sc_MouldRepairWorkBillMain " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HDate" +
                ",HYear,HPeriod,HRemark,HMaker,HMakeDate" +
                ",HEquipID,HRepairID,HRepairBeginDate,HRepairEndDate,HRepairContent" +
                ",HCycleUnit,HPlanTimes,HTimes,HEmpID,HManagerID" +
                ",HDeptID,HExplanation,HInnerBillNo,HMouldID" +
                ",HSupID,HRepairType,HNewModel,HNewDesignLife,HMainSourceBillType,HMainSourceInterID,HMainSourceEntryID" +
                ")values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',getdate()" +
                ",'" + DateTime.Now.Year + "','" + DateTime.Now.Month + "','','" + oItem.HOriginator + "','" + oItem.HMakeDate + "'" +
                      ",'0','0','" + oItem.HRepairBeginDate + "','" + oItem.HUpdateDate + "',''" +
                      ",'小时','" + oItem.HPlanTimes + "','" + oItem.HTimes + "','" + oItem.HEmpID + "',0" +
                      ",'" + oItem.HDeptID + "','','" + oItem.HInstanceID + "','" + oItem.HMouldID + "'" +
                      ",'0','内部维修','','" + oItem.HNewDesignLife + "','',0,0)";
                            oCN.RunProc(sql_main);
                            int i = 1;
                            foreach (Sc_MouldRepairWorkBillSub oItem_Detail in oItem.DetailColMouldRepair)
                            {
                                string sql_sub = "Insert into Sc_MouldRepairWorkBillSub " +
                       " (HInterID,HEntryID,HCloseMan,HEntryCloseDate,HCloseType,HRemark" +
                       ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" +
                       ",HRepairID,HRepairExplanation,HManagerID,HMoney) values" +
                       "('" + HInterID + "'," + i + ",'','','','" + oItem_Detail.HRemark + "'" +
                          ",0,0,'','',0,0" +
                          ",0,'" + oItem_Detail.HRepairExplanation + "','" + oItem.HEmpID + "',0)";
                                oCN.RunProc(sql_sub);
                                i += 1;
                            }
                        }
                    }
                }
                oCN.Commit();
                return true;
            }
            catch (Exception e)
            {
                msg = e.Message;
                oCN.RollBack();
                return false;
            }
        }
        #endregion
        #endregion
        #region æ•°æ®åŒæ­¥-设备维修记录单
        #region èŽ·å– å®œæ­-设备维修记录单 å®žä¾‹ID列表对应的实例详情
        public bool getInstanceDetailList___EquipRepairWeiXiu_YiDa(string appType, string systemToken, string userID, string formUuid, List<string> IDList, ref List<EquipRepairWeiXiu> lsmain, ref string msg, int size = 500)
        {
            try
            {
                int startIndex = 0;
                int endIndex = startIndex + size;
                if (endIndex > IDList.Count)
                {
                    endIndex = IDList.Count;
                }
                while (startIndex < endIndex && endIndex <= IDList.Count)
                {
                    List<string> IDList_temp = new List<string>();
                    for (int i = startIndex; i < endIndex; i++)
                    {
                        IDList_temp.Add(IDList[i]);
                    }
                    BatchGetFormDataByIdListResponse response = new BatchGetFormDataByIdListResponse();
                    if (getInstanceDetailListByInstanceIDList_YiDa(appType, systemToken, formUuid, userID, IDList_temp, ref response, ref msg) == false)
                    {
                        return false;
                    }
                    for (int i = 0; i < response.Body.Result.Count; i++)
                    {
                        try
                        {
                            List<string> keys = new List<string>(response.Body.Result[i].FormData.Keys);
                            EquipRepairWeiXiu oItem = new EquipRepairWeiXiu();
                            oItem.HMakerID = response.Body.Result[i].CreatorUserId.Replace("'", "");
                            oItem.HMaker = response.Body.Result[i].CreatorUserId.Replace("'", "");
                            oItem.HMakeDate = response.Body.Result[i].CreateTimeGMT.Replace("T", " ").Replace("Z", "").Replace("'", "");
                            oItem.HUpdaterID = response.Body.Result[i].ModifyUser.UserId.Replace("'", "");
                            oItem.HUpdater = response.Body.Result[i].ModifyUser.Name.NameInChinese.Replace("'", "");
                            oItem.HUpdateDate = response.Body.Result[i].ModifiedTimeGMT.Replace("T", " ").Replace("Z", "").Replace("'", "");
                            oItem.HInstanceID = response.Body.Result[i].FormInstanceId.Replace("'", "");
                            oItem.HOriginator = response.Body.Result[i].Originator.Name.NameInChinese.Replace("'", "");
                            GetInstanceByIdResponse getInstanceByIdResponse = new GetInstanceByIdResponse(); ;
                            if (!getInstanceStatusByInstanceID__YiDa(appType, systemToken, userID, oItem.HInstanceID, ref getInstanceByIdResponse, ref msg))
                            {
                                continue;
                            }
                            if (getInstanceByIdResponse.Body.InstanceStatus != "COMPLETED")
                            {
                                continue;
                            }
                            //设备编码
                            if (keys.Contains("textField_lfg9hgys"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textField_lfg9hgys"].ToString();
                                DataSet ds = oCN.RunProcReturn("select * from Gy_MouldFileMain with(nolock)  where HNumber='" + HDate_Temp + "'", "Gy_MouldFileMain");
                                string HEquipID = "0";
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    HEquipID = ds.Tables[0].Rows[0]["HInterID"].ToString();
                                }
                                oItem.HEquipID = long.Parse(HEquipID);
                                oItem.HRemark2 = HDate_Temp;
                            }
                            //维修部门
                            if (keys.Contains("selectField_kzgkw10a"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["selectField_kzgkw10a"].ToString();
                                DataSet ds = oCN.RunProcReturn("select * from Gy_Department with(nolock)  where HName='" + HDate_Temp + "'", "Gy_Department");
                                string HDeptID = "0";
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    HDeptID = ds.Tables[0].Rows[0]["HItemID"].ToString();
                                }
                                oItem.HDeptID = long.Parse(HDeptID);
                            }
                            //维修人
                            if (keys.Contains("employeeField_lthwkdh2"))
                            {
                                string[] HDate_Temp = JsonConvert.DeserializeObject<string[]>(JsonConvert.SerializeObject(response.Body.Result[i].FormData["employeeField_lthwkdh2"]));
                                DataSet ds = oCN.RunProcReturn("select * from Gy_Employee with(nolock)  where HNumber='" + HDate_Temp[0] + "'", "Gy_Employee");
                                string HEmpID = "0";
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    HEmpID = ds.Tables[0].Rows[0]["HItemID"].ToString();
                                }
                                oItem.HEmpID = long.Parse(HEmpID);
                            }
                            //维修时间
                            if (keys.Contains("textField_l2r95oo2"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textField_l2r95oo2"].ToString();
                                oItem.HTimes = long.Parse(HDate_Temp);
                                oItem.HPlanTimes = long.Parse(HDate_Temp);
                            }
                            //维修内容
                            if (keys.Contains("textField_l2r9bvwk"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textField_l2r9bvwk"].ToString();
                                oItem.HRepairContent = HDate_Temp;
                            }
                            //子表 ç»´ä¿®è¦æ±‚ ç»´ä¿®å¤‡æ³¨(问题描述)
                            Sc_MouldRepairWorkBillSub sub = new Sc_MouldRepairWorkBillSub();
                            //维修要求
                            if (keys.Contains("textareaField_lthwo99r"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textareaField_lthwo99r"].ToString();
                                sub.HRepairExplanation = HDate_Temp;
                            }
                            //备注
                            if (keys.Contains("textField_l2r95oo0"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textField_l2r95oo0"].ToString();
                                sub.HRemark = HDate_Temp;
                            }
                            oItem.DetailColMouldRepair.Add(sub);
                            int startindex = response.Body.Result[i].Title.IndexOf("zh_CN") + 8;
                            oItem.HTitle = startIndex + response.Body.Result[i].Title.Substring(startindex).Replace("\"}", "").Replace("'", "");
                            if (keys.Contains("dateField_lo6w37hk"))
                            {
                                double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_lo6w37hk"].ToString());
                                oItem.HDate = convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd");
                            }
                            if (keys.Contains("selectField_lockncvh_id"))
                            {
                                oItem.HArea = response.Body.Result[i].FormData["selectField_lockncvh_id"].ToString().Replace("'", "");
                            }
                            if (keys.Contains("selectField_lockncvg_id"))
                            {
                                oItem.HCheckLevel = response.Body.Result[i].FormData["selectField_lockncvg_id"].ToString().Replace("'", "");
                            }
                            if (keys.Contains("employeeField_lo6w37hf"))
                            {
                                oItem.HEmplpyee = ((List<object>)response.Body.Result[i].FormData["employeeField_lo6w37hf"])[0].ToString().Replace("'", "");
                            }
                            if (keys.Contains("employeeField_lo6w37hf_id"))
                            {
                                oItem.HEmployeeID = ((List<object>)response.Body.Result[i].FormData["employeeField_lo6w37hf_id"])[0].ToString().Replace("'", "");
                            }
                            lsmain.Add(oItem);
                        }
                        catch (Exception e)
                        {
                            continue;
                        }
                    }
                    startIndex = endIndex;
                    endIndex += size;
                    if (endIndex > IDList.Count)
                    {
                        endIndex = IDList.Count;
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                msg = e.Message;
                return false;
            }
        }
        #endregion
        #region æ•°æ®åŒæ­¥
        public bool getData_EquipRepairWeiXiu(ref string msg)
        {
            //获取 åˆ†å±‚审核表 å®žä¾‹ID列表
            string appType = "APP_E2A54CQBDX3TZN51JGBI";
            string systemToken = "YKB660C1ZPNW58JDZKAP318W5VQE2RRMQL2YKZK";
            string userID = "011113050243860353";
            string formUuid = "FORM-OM566O7177LW0ARJ5IMFF63NTFKA34G9RL2YKN1";
            int pageNumber = 1;
            int pageSize = 100;
            //获取模具维修保养表的实例ID列表
            List<string> IDList = new List<string>();
            if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false)
            {
                return false;
            }
            //获取详细信息并附加到列表lsmain中
            List<EquipRepairWeiXiu> lsmain = new List<EquipRepairWeiXiu>();
            if (getInstanceDetailList___EquipRepairWeiXiu_YiDa(appType, systemToken, userID, formUuid, IDList, ref lsmain, ref msg) == false)
            {
                return false;
            }
            try
            {
                oCN.BeginTran();
                foreach (EquipRepairWeiXiu oItem in lsmain)
                {
                    //维修记录
                    if (oItem.DetailColMouldRepair.Count != 0)
                    {
                        string BillType = "3910";
                        string sql = $@"select HInnerBillNo from Sb_EquipRepairWorkBillMain
                            where HInnerBillNo = '{oItem.HInstanceID}'";
                        DataSet ds = oCN.RunProcReturn(sql, "Sb_EquipRepairWorkBillMain");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            long HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo);
                            string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
                            //long HInterID = 0;
                            //string HBillNo = "";
                            string sql_main = "Insert Into Sb_EquipRepairWorkBillMain " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HDate" +
                ",HYear,HPeriod,HRemark,HMaker,HMakeDate" +
                ",HEquipID,HRepairID,HPlanTimes,HEmpID,HManagerID,HTimes" +
                ",HDeptID,HExplanation,HInnerBillNo,HRepairBeginDate,HRepairEndDate" +
                ",HRepairContent,HCycleUnit,HMainSourceBillType,HMainSourceInterID,HMainSourceEntryID" +
                ")values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',getdate()" +
                ",'" + DateTime.Now.Year + "','" + DateTime.Now.Month + "','"+ oItem.HRemark2 + "','" + oItem.HOriginator + "','" + oItem.HMakeDate + "'" +
                      ",'" + oItem.HEquipID + "','0','" + oItem.HTimes + "','" + oItem.HEmpID + "','" + oItem.HEmpID + "','" + oItem.HTimes + "'" +
                      ",'" + oItem.HDeptID + "','" + oItem.HExplanation + "','" + oItem.HInstanceID + "','',''" +
                      ",'" + oItem.HRepairContent + "','小时','','0',0)";
                            oCN.RunProc(sql_main);
                            int i = 1;
                            foreach (Sc_MouldRepairWorkBillSub oItem_Detail in oItem.DetailColMouldRepair)
                            {
                                string sql_sub = "Insert into Sb_EquipRepairWorkBillSub " +
                       " (HInterID,HEntryID,HCloseMan,HEntryCloseDate,HCloseType,HRemark" +
                       ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" +
                       ",HRepairID,HManagerID,HRepairExplanation,HEmpID)" +
                       "values('" + HInterID + "'," + i + ",'','','','" + oItem_Detail.HRemark + "'" +
                          ",0,0,'','',0,0" +
                          ",0,'" + oItem.HEmpID + "','" + oItem_Detail.HRepairExplanation + "','" + oItem.HEmpID + "')";
                                oCN.RunProc(sql_sub);
                                i += 1;
                            }
                        }
                    }
                }
                oCN.Commit();
                return true;
            }
            catch (Exception e)
            {
                msg = e.Message;
                oCN.RollBack();
                return false;
            }
        }
        #endregion
        #endregion
        #endregion