wtt
2024-12-10 871bc633a7daf1893acc98a84c64c93c9a30aaff
WebAPI/Controllers/Êý¾Ýͬ²½/¶¤¶¤Í¬²½/DD_DataSynchronizationController.cs
@@ -16,6 +16,9 @@
using DingTalk.Api;
using DingTalk.Api.Response;
using System.Globalization;
using System.Linq;
using AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models;
using System.Text.RegularExpressions;
namespace WebAPI.Controllers
{
@@ -74,7 +77,7 @@
        private string AppKey = "dingiokapm2dvjrhzl2g";                                                                             //已创建的企业内部应用的AppKey。
        private string AppSecret = "dPUD7tN3BGVYAC4lDzhpcBH7O4FWFDdjLJWa6cVRBQj5U7GJ4Gwr7Vohnv0oPBOr";                             //已创建的企业内部应用的AppSecret。
        private long AgentID = 3188176952;                                                                                          //应用的AgentId
        private string accessToken = "";                                                                                           //调用该接口的访问凭证。
        public string accessToken = "";                                                                                           //调用该接口的访问凭证。
        private string ProcessInstanceId = "";                                                                                     //审批实例ID。
        #endregion
@@ -84,6 +87,13 @@
            public long? TotalCount;
            public long? PageNumber;
            public List<string> Data;
        }
        //oa审批返回类
        public class OA_GetInstanceIDListResponse
        {
           public List<string> list;//获取的id列表
           public string nextToken;
           public bool? success;
        }
        #region åˆ†å±‚审核签到表
@@ -268,15 +278,26 @@
            public string HExplanation;//   varchar(500)    --维修要求        
            public string HInnerBillNo;//   varchar(50)   --内部单据号
            public Int64 HMouldID;
            public Int64 HMouldMaintainRuleInterID;
            public Int64 HMaintainItemID;
            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 HPlanNo;
            public string HPlanInterID;
            public DateTime HRequestComDate;
            public double HRecentMainModule;
            public double HCumulativeModule;
            public double HProductionModule;
            public DateTime HRepairAccepDate;
            public string HMaintainLevID;
            //单据内容
            public string HBillNo;                                //单据号
            public string HDate;                                //日期
            public string HCheckLevel;                          //审核等级
            public string HArea;                                //区域
@@ -332,6 +353,10 @@
            public Single HPlanTimes;// money         --计划维修工时
            public Single HTimes;// money       --实际维修工时
            public string HRemark2;//备注
            public string HRepairCategory;
            public string HUrgenLevel;
            public string HRepairer;
            public string HIsCapacityImpact;
            //单据内容
            public string HDate;                                //日期
@@ -342,8 +367,83 @@
            public List<Sc_MouldRepairWorkBillSub> DetailColMouldRepair = new List<Sc_MouldRepairWorkBillSub>();
        }
        #endregion
        #region å¼‚常工时申请单
        #region ä¸»è¡¨+子表
        public class Pay_ErrWorkTimesRequestBill
        {
            public int HInterID;
            public string HBillNo;
            public string HDate;
            public string HInnerBillNo;
            public int HDeptID;
            public string HDeptName;
            public int HGroupID;
            public string HGroupName;
            public int HMangerID;
            public string HManagerName;
            public int HICMOInterID;
            public string HICMOBillNo;
            public string HExplanation;
            public double HSumRequestTimes;
            public int HMaterID;
            public string HMaterName;
            public int HUnitID;
            public string HUnitName;
            public double HPlanQty;
            public string HBatchNo;
            public string HRemark;
            public string HMaker;
            public string HMakerDate;
            public string HUpdater;
            public string HUpdaterDate;
            public string HChecker;
            public string HCheckerDate;
            public string HCloseMan;
            public string HCloseManDate;
            public string HDeleteMan;
            public string HDeleteManDate;
            public string HBacker;
            public string HBackerDate;
            public string HBackRemark;
            public List<Pay_ErrWorkTimesRequestBillSub> Pay_ErrWorkTimesRequestBillSub = new List<Pay_ErrWorkTimesRequestBillSub>();
        }
        #endregion
        #region å­è¡¨
        public class Pay_ErrWorkTimesRequestBillSub
        {
            public int HEmpID;
            public string HEmpNumber;
            public string HEmpName;
            public int HWorkTypeID;
            public string HWorkTypeNumber;
            public string HWorkTypeName;
            public double HPayMoney;
            public string HBTimes;
            public string HETimes;
            public double HTimes;
            public double HRelTimes;
            public double HRelPay;
            public string HRemark;
            public int HSourceInterID;
            public int HSourceEntryID;
            public string HSourceBillNo;
            public string HSourceBillType;
            public double HRelationQty;
            public double HRelationMoney;
            public string HCloseMan;
            public string HEntryCloseDate;
        }
        #endregion
        #endregion
        #endregion
        #region é’‰é’‰ é€šç”¨æ“ä½œæ–¹æ³•
@@ -436,25 +536,29 @@
        #region èŽ·å– é’‰é’‰-智能人事 èŽ·å–åœ¨èŒå‘˜å·¥ID列表
        public bool getEmployeeIDList_DingDing(long offset, long size, ref List<string> IDList, ref string msg)
        {
            LogService.Write("查看5-1-1");
            OapiSmartworkHrmEmployeeQueryonjobResponse response = new OapiSmartworkHrmEmployeeQueryonjobResponse();
            do
            {
                if (getEmployeeIDList_Page_DingDing(offset, size, ref response, ref msg) == false)
                {
                    LogService.Write("查看5-1-2");
                    return false;
                }
                LogService.Write("查看5-1-3");
                for (int i = 0; i < response.Result.DataList.Count; i++)
                {
                    IDList.Add(response.Result.DataList[i]);
                }
                LogService.Write("查看5-1-4");
                if (response.Result.NextCursor != 0)
                {
                    LogService.Write("查看5-1-4-1");
                    offset = response.Result.NextCursor;
                }
                else
                {
                    LogService.Write("查看5-1-5");
                    break;
                }
            } while (true);
@@ -510,8 +614,10 @@
                //OriginatorId = "12",                                                                                          //根据流程发起人工号查询。
                //TaskId = "12",                                                                                                //任务ID。
                CreateFromTimeGMT = DateTime.Now.ToString("dd") == "01" ? "2022-01-01" : DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"),                                          //创建时间起始值。
                CreateToTimeGMT = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"),                                               //创建时间终止值。
                //CreateFromTimeGMT = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd"),                                          //创建时间起始值。
                //CreateToTimeGMT = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss"),                                               //创建时间终止值。
                ModifiedFromTimeGMT = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),                                          //修改时间起始值。
                ModifiedToTimeGMT = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),                                               //修改时间终止值。
                PageSize = pageSize,                                                  //分页大小。
                PageNumber = pageNumber,                                                 //分页页码
@@ -706,6 +812,145 @@
        #endregion
        #endregion
        #region oa é€šç”¨æ“ä½œæ–¹æ³•
        #region OA èŽ·å–å®¡æ‰¹å®žä¾‹ID列表(单页)
        public bool getInstanceIDList_Page_OA(string processCode,DateTime startTime, DateTime endTime,long nextToken, int maxResult, List<string> statuses, ref OA_GetInstanceIDListResponse response, ref string msg)
        {
            AlibabaCloud.SDK.Dingtalkworkflow_1_0.Client client = CreateClient1();
            AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.ListProcessInstanceIdsHeaders listProcessInstanceIdsHeaders = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.ListProcessInstanceIdsHeaders();
            listProcessInstanceIdsHeaders.XAcsDingtalkAccessToken = this.accessToken;
            AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.ListProcessInstanceIdsRequest listProcessInstanceIdsRequest = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.ListProcessInstanceIdsRequest
            {
                Statuses = statuses,
                StartTime = getTimeMillions(startTime),
                EndTime  = getTimeMillions(endTime),
                ProcessCode = processCode,
                NextToken = nextToken,
                MaxResults = maxResult,
            };
            try
            {
                ListProcessInstanceIdsResponse listProcessInstanceIdsResponse = client.ListProcessInstanceIdsWithOptions(listProcessInstanceIdsRequest, listProcessInstanceIdsHeaders, new AlibabaCloud.TeaUtil.Models.RuntimeOptions());
                response.success = listProcessInstanceIdsResponse.Body.Success;
                response.list = listProcessInstanceIdsResponse.Body.Result.List;
                response.nextToken = listProcessInstanceIdsResponse.Body.Result.NextToken;
                return true;
            }
            catch (TeaException err)
            {
                if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
                {
                    // err ä¸­å«æœ‰ code å’Œ message å±žæ€§ï¼Œå¯å¸®åŠ©å¼€å‘å®šä½é—®é¢˜
                }
                msg = "错误代码" + err.Code + ":" + 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.Code + ":" + err.Message;
                return false;
            }
        }
        #endregion
        #region èŽ·å– OA指定单据的实例ID列表(全部)
        public bool getInstanceIDList_OA(string processCode, DateTime startTime, DateTime endTime, long nextToken, int maxResult, List<string> statuses, ref List<string> IDList, ref string msg)
        {
            OA_GetInstanceIDListResponse response = new OA_GetInstanceIDListResponse();
            response.nextToken = nextToken.ToString();//赋值初始值
            do
            {
                nextToken = long.Parse(response.nextToken);
                if (getInstanceIDList_Page_OA(processCode, startTime, endTime, nextToken, maxResult, statuses,ref response, ref msg) == false)
                {
                    return false;
                }
                for (int i = 0; i < response.list.Count; i++)
                {
                    IDList.Add(response.list[i]);
                }
            } while (response.nextToken!=null);
            return true;
        }
        #endregion
        #region èŽ·å– OA æ ¹æ®å®žä¾‹ID获取实例详情
        public bool getInstanceDetailByInstanceID_OA(string processinstanceID,ref GetProcessInstanceResponse response, ref string msg)
        {
            AlibabaCloud.SDK.Dingtalkworkflow_1_0.Client client = CreateClient1();
            AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.GetProcessInstanceHeaders getProcessInstanceHeaders = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.GetProcessInstanceHeaders();
            getProcessInstanceHeaders.XAcsDingtalkAccessToken = this.accessToken;
            AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.GetProcessInstanceRequest getProcessInstanceRequest = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.GetProcessInstanceRequest
            {
                ProcessInstanceId = processinstanceID,
            };
            try
            {
                response =  client.GetProcessInstanceWithOptions(getProcessInstanceRequest, getProcessInstanceHeaders, new AlibabaCloud.TeaUtil.Models.RuntimeOptions());
                return true;
            }
            catch (TeaException err)
            {
                if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
                {
                    // err ä¸­å«æœ‰ code å’Œ message å±žæ€§ï¼Œå¯å¸®åŠ©å¼€å‘å®šä½é—®é¢˜
                }
                msg = "错误代码" + err.Code + ":" + 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.Code + ":" + err.Message;
                return false;
            }
        }
        #endregion
        #region èŽ·å– OA æ ¹æ®å®žä¾‹ID列表获取实例详情列表
        public bool getInstanceDetailListByInstanceIDList_OA(List<string> processinstanceIDList, ref List<GetProcessInstanceResponse> responseList, ref string msg)
        {
            GetProcessInstanceResponse getProcessInstanceResponse = new GetProcessInstanceResponse();
            try
            {
                foreach(string processinstanceID in processinstanceIDList)
                {
                    if(!getInstanceDetailByInstanceID_OA(processinstanceID,ref getProcessInstanceResponse,ref msg))
                    {
                        return false;
                    }
                    responseList.Add(getProcessInstanceResponse);
                }
                return true;
            }
            catch (Exception e)
            {
                msg = e.Message;
                return false;
            }
        }
        #endregion
        #endregion
        #region æ•°æ®åŒæ­¥æ–¹æ³•
        #region æ•°æ®åŒæ­¥-分层审核签到表
        #region èŽ·å– å®œæ­-分层审核签到表 å®žä¾‹ID列表对应的实例详情
@@ -857,6 +1102,7 @@
                            lsmain.Add(oItem);
                        }catch(Exception e)
                        {
                            LogService.Write("查看1" + e.Message);
                            continue;
                        }
                    }
@@ -893,7 +1139,7 @@
            string formUuid = "FORM-A01FFB0B63A34F18B7753F695F49190DJEY7";              //签到表
            int pageNumber = 1;
            int pageSize = 100;
            LogService.Write("查看1");
            //获取分层审核表的实例ID列表
            List<string> IDList = new List<string>();
            if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false)
@@ -1100,6 +1346,7 @@
                            lsmain.Add(oItem);
                        }catch(Exception e)
                        {
                            LogService.Write("查看2"+e.Message);
                            continue;
                        }
                    }
@@ -1131,7 +1378,7 @@
            string formUuid = "FORM-E3DFC12364514330A836DD3056C15668UGG7";
            int pageNumber = 1;
            int pageSize = 100;
            LogService.Write("查看2");
            //获取实例ID列表
            List<string> IDList = new List<string>();
            if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false)
@@ -1369,6 +1616,7 @@
                        }
                        catch (Exception e)
                        {
                            LogService.Write("查看3"+e.Message);
                            continue;
                        }
                    }
@@ -1400,7 +1648,7 @@
            string formUuid = "FORM-K5766HA1CKZB4E1L64Y1KBWCJTQF2HWJ3NDJL4";
            int pageNumber = 1;
            int pageSize = 100;
            LogService.Write("查看3");
            //获取实例ID列表
            List<string> IDList = new List<string>();
            if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false)
@@ -1672,6 +1920,7 @@
                        }
                        catch (Exception e)
                        {
                            LogService.Write("查看4"+e.Message);
                            continue;
                        }
                    }
@@ -1703,7 +1952,7 @@
            string formUuid = "FORM-65AD77453E7F44EA847166C3AB5A1F04IPSS";
            int pageNumber = 1;
            int pageSize = 100;
            LogService.Write("查看4");
            //获取实例ID列表
            List<string> IDList = new List<string>();
            if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false)
@@ -1917,6 +2166,7 @@
                        }
                        catch (Exception e)
                        {
                            LogService.Write("查看5"+e.Message);
                            continue;
                        }
                    }
@@ -1948,14 +2198,16 @@
        {
            long offset = 0;
            long size = 50;
            LogService.Write("查看5");
            LogService.Write("查看5.1");
            //获取花名册职员ID列表
            List<string> IDList = new List<string>();
            if (getEmployeeIDList_DingDing(offset, size, ref IDList, ref msg) == false)
            {
                LogService.Write("查看5-1"+ msg);
                return false;
            }
            LogService.Write("查看5-2");
            //获取详细信息并附加到列表lsmain中
            List<DD_HuaMingCe> lsmain = new List<DD_HuaMingCe>();
            if (getEmployeeDetailList_HuaMingCe__DingDing(IDList, ref lsmain, ref msg) == false)
@@ -1964,6 +2216,7 @@
            }
            try
            {
                LogService.Write("查看5-3");
                oCN.BeginTran();
                foreach (DD_HuaMingCe oItem in lsmain)
                {
@@ -1988,12 +2241,14 @@
                    oCN.RunProc(sql_main);
                }
                LogService.Write("查看5-4");
                oCN.Commit();
                return true;
            }
            catch (Exception e)
            {
                msg = e.Message;
                LogService.Write("查看5报错:" + e.Message);
                oCN.RollBack();
                return false;
            }
@@ -2053,11 +2308,121 @@
                            {
                                continue;
                            }
                            string HStaus = "";
                            switch (getInstanceByIdResponse.Body.InstanceStatus)
                            {
                                case "COMPLETED":
                                    HStaus = "维修结束";
                                    break;
                                case "RUNNING":
                                    HStaus = "维修进行中";
                                    break;
                                case "TERMINATED":
                                    HStaus = "维修终止";
                                    break;
                            }
                            LogService.Write("状态:" + HStaus);
                            if (getInstanceByIdResponse.Body.InstanceStatus != "COMPLETED")
                            {
                                //模具编码
                                if (keys.Contains("selectField_lq3idkvg"))
                                {
                                    string HDate_Temp = response.Body.Result[i].FormData["selectField_lq3idkvg"].ToString();
                                    LogService.Write("模具:" + HDate_Temp);
                                    DataSet ds = oCN.RunProcReturn("select * from Gy_MouldFileMain with(nolock)  where HMouldNo='" + HDate_Temp + "'", "Gy_MouldFileMain");
                                    string HMouldID = "0";
                                    if (ds.Tables[0].Rows.Count > 0)
                                    {
                                        LogService.Write("测试1:" + ds.Tables[0].Rows[0]["HCloseDate"].ToString());
                                        string HUpdateDate = ds.Tables[0].Rows[0]["HCloseDate"].ToString() == "" ? "1900-01-01 00:00:00" : ds.Tables[0].Rows[0]["HCloseDate"].ToString();
                                        string HMouldStaus = ds.Tables[0].Rows[0]["HMouldStatus"].ToString();
                                        LogService.Write("模具:" + HDate_Temp + ",状态:" + HMouldStaus + ",时间:" + HUpdateDate);
                                        HMouldID = ds.Tables[0].Rows[0]["HInterID"].ToString();
                                        if (HMouldStaus != HStaus && DateTime.Parse(HUpdateDate) <= DateTime.Parse(oItem.HUpdateDate)) {
                                            //修改模具的状态和时间
                                            oCN.RunProc("update Gy_MouldFileMain set HMouldStatus='" + HStaus + "',HCloseDate='" + oItem.HUpdateDate + "' WHERE HInterID =" + HMouldID);
                                        }
                                    }
                                }
                                continue;
                            }
                            //模具编码
                            if (keys.Contains("selectField_lq3idkvg"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["selectField_lq3idkvg"].ToString();
                                LogService.Write("模具:" + HDate_Temp);
                                DataSet ds = oCN.RunProcReturn("select * from Gy_MouldFileMain with(nolock)  where HMouldNo='" + HDate_Temp + "'", "Gy_MouldFileMain");
                                string HMouldID = "0";
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    LogService.Write("测试2:" + ds.Tables[0].Rows[0]["HCloseDate"].ToString());
                                    HMouldID = ds.Tables[0].Rows[0]["HInterID"].ToString();
                                    string HUpdateDate = ds.Tables[0].Rows[0]["HCloseDate"].ToString() == "" ? "1900-01-01 00:00:00" : ds.Tables[0].Rows[0]["HCloseDate"].ToString();
                                    string HMouldStaus = ds.Tables[0].Rows[0]["HMouldStatus"].ToString();
                                    LogService.Write("模具:" + HDate_Temp+ ",状态:" + HMouldStaus + ",时间:" + HUpdateDate);
                                    if (HMouldStaus != HStaus && DateTime.Parse(HUpdateDate) <= DateTime.Parse(oItem.HUpdateDate))
                                    {
                                        //修改模具的状态和时间
                                        oCN.RunProc("update Gy_MouldFileMain set HMouldStatus='" + HStaus + "',HCloseDate='" + oItem.HUpdateDate + "' WHERE HInterID =" + HMouldID);
                                    }
                                }
                                oItem.HMouldID = long.Parse(HMouldID);
                                oItem.HRemark = HDate_Temp;
                                //LogService.Write("测试3:" + HMouldID);
                                //查询保养计划
                                ds = oCN.RunProcReturn(@"select  a.HInterID,a.HBillNo from  Sc_MouldMaintainPlanBillMain a
                                    inner join Sc_MouldMaintainPlanBillSub b on a.HInterID = b.HInterID
                                    where a.HMouldID =" + oItem.HMouldID+ " order by a.HMakeDate desc", "Sc_MouldMaintainPlanBillMain");
                                //LogService.Write("测试4:");
                                oItem.HPlanInterID = "";
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    oItem.HPlanInterID = ds.Tables[0].Rows[0]["HInterID"].ToString();
                                    oItem.HPlanNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
                                }
                            }
                            LogService.Write("模具编码:" + oItem.HMouldID);
                            //开单日期
                            if (keys.Contains("dateField_lq0v65sv"))
                            {
                                double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_lq0v65sv"].ToString());
                                oItem.HDate = convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd HH:mm");
                            }
                            LogService.Write("开单日期:" + oItem.HDate);
                            //模具保养级别
                            if (keys.Contains("selectField_m1ip9j31"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["selectField_m1ip9j31"].ToString();
                                if (!HDate_Temp.Contains("三级"))
                                {
                                    ds = oCN.RunProcReturn("select  * from h_v_Gy_MaintainLev where ä¿å…»çº§åˆ«ä»£ç ='BY-SE-002'", "h_v_Gy_MaintainLev");
                                    if (ds.Tables[0].Rows.Count > 0)
                                    {
                                        HDate_Temp = ds.Tables[0].Rows[0]["HItemID"].ToString();
                                    }
                                }
                                else if (HDate_Temp.Contains("三级"))
                                {
                                    ds = oCN.RunProcReturn("select  * from h_v_Gy_MaintainLev where ä¿å…»çº§åˆ«ä»£ç ='BY-SE-003'", "h_v_Gy_MaintainLev");
                                    if (ds.Tables[0].Rows.Count > 0)
                                    {
                                        HDate_Temp = ds.Tables[0].Rows[0]["HItemID"].ToString();
                                    }
                                }
                                oItem.HMaintainLevID = HDate_Temp;
                            }
                            LogService.Write("模具保养级别:" + oItem.HMaintainLevID);
                            //修模开始时间
                            if (keys.Contains("dateField_lq4gf2ih"))
@@ -2065,6 +2430,7 @@
                                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"));
                            }
                            LogService.Write("修模开始时间:" + oItem.HRepairBeginDate);
                            //修模结束时间
                            if (keys.Contains("dateField_lq4gf2ii"))
@@ -2072,27 +2438,55 @@
                                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"));
                            }
                            LogService.Write("修模结束时间:" + oItem.HRepairEndDate);
                            //模具批次号
                            //模具单据号
                            if (keys.Contains("serialNumberField_lqaak4ts"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["serialNumberField_lqaak4ts"].ToString();
                                oItem.HRemark = HDate_Temp;
                                oItem.HBillNo = HDate_Temp;
                            }
                            LogService.Write("模具单据号:" + oItem.HBillNo);
                            //模具编码
                            if (keys.Contains("dateField_lq4gf2ii"))
                            //要求完成日期
                            if (keys.Contains("dateField_lq3idkvd"))
                            {
                                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);
                                double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_lq3idkvd"].ToString());
                                oItem.HRequestComDate = DateTime.Parse(convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd HH:mm:ss"));
                            }
                            LogService.Write("要求完成日期:" + oItem.HRequestComDate);
                            //维修受理日期
                            if (keys.Contains("dateField_lq4gf2ih"))
                            {
                                double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_lq4gf2ih"].ToString());
                                oItem.HRepairAccepDate = DateTime.Parse(convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd HH:mm:ss"));
                            }
                            LogService.Write("维修受理日期:" + oItem.HRepairAccepDate);
                            //最近保养模数
                            if (keys.Contains("numberField_lq3idkvi"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["numberField_lq3idkvi"].ToString();
                                oItem.HRecentMainModule = double.Parse(HDate_Temp);
                            }
                            LogService.Write("最近保养模数:" + oItem.HRecentMainModule);
                            //累计模数
                            if (keys.Contains("numberField_lq3idkvj"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["numberField_lq3idkvj"].ToString();
                                oItem.HCumulativeModule = double.Parse(HDate_Temp);
                            }
                            LogService.Write("累计模数:" + oItem.HCumulativeModule);
                            //本次生产模数
                            if (keys.Contains("textField_lq4vdvgh"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textField_lq4vdvgh"].ToString();
                                oItem.HProductionModule = double.Parse(HDate_Temp);
                            }
                            LogService.Write("累计模数:" + oItem.HProductionModule);
                            //维修部门
                            if (keys.Contains("selectField_lq3idkva"))
@@ -2106,6 +2500,7 @@
                                }
                                oItem.HDeptID = long.Parse(HDeptID);
                            }
                            LogService.Write("维修部门:" + oItem.HDeptID);
                            //新设计寿命
                            oItem.HNewDesignLife = 30000;
@@ -2114,7 +2509,7 @@
                            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");
                                DataSet ds = oCN.RunProcReturn("select * from Gy_Employee with(nolock)  where hname='" + HDate_Temp[0] + "'", "Gy_Employee");
                                string HEmpID = "0";
                                if (ds.Tables[0].Rows.Count > 0)
                                {
@@ -2122,6 +2517,7 @@
                                }
                                oItem.HEmpID = long.Parse(HEmpID);
                            }
                            LogService.Write("维修人:" + oItem.HEmpID);
                            //维修时间
                            if (keys.Contains("numberField_lq3ixr9j"))
@@ -2131,6 +2527,7 @@
                                oItem.HTimes = long.Parse(HDate_Temp);
                                oItem.HPlanTimes = long.Parse(HDate_Temp);
                            }
                            LogService.Write("维修时间:" + oItem.HTimes);
                            //子表 ç»´ä¿®è¦æ±‚ ç»´ä¿®å¤‡æ³¨(问题描述)
                            if (keys.Contains("tableField_lq3ixr9b"))
@@ -2147,15 +2544,19 @@
                                    {
                                        oItemSub.HRepairExplanation = dic[ij]["textareaField_lq3ixr9e"].ToString();
                                    }
                                    LogService.Write("维修要求:" + oItemSub.HRepairExplanation);
                                    //备注
                                    if (keys_Sub.Contains("textField_lq3ixr9d"))
                                    {
                                        oItemSub.HRemark = dic[ij]["textField_lq3ixr9d"].ToString();
                                    }
                                    LogService.Write("备注:" + oItemSub.HRemark);
                                    oItem.DetailColMouldRepair.Add(oItemSub);
                                }
                            }
                            string HRemark = "";
                            //子表 ä¿å…»å¤‡æ³¨(问题描述)
@@ -2177,9 +2578,10 @@
                                    oItemSub.HClaim = HDate_Temp[ij];
                                    oItemSub.HMaintainResult = HRemark;
                                    oItem.DetailColMouldMaintain.Add(oItemSub);
                                    LogService.Write("具体要求:" + oItemSub.HClaim);
                                }
                            }
                            int startindex = response.Body.Result[i].Title.IndexOf("zh_CN") + 8;
                            oItem.HTitle = startIndex + response.Body.Result[i].Title.Substring(startindex).Replace("\"}", "").Replace("'", "");
@@ -2214,6 +2616,7 @@
                        }
                        catch (Exception e)
                        {
                            LogService.Write("报错:" + e.Message);
                            continue;
                        }
                    }
@@ -2231,6 +2634,7 @@
            }
            catch (Exception e)
            {
                LogService.Write(e.Message);
                msg = e.Message;
                return false;
            }
@@ -2248,7 +2652,7 @@
            string formUuid = "FORM-30C78F46E77E46A9AA8778214CEFE6B5J0AN";
            int pageNumber = 1;
            int pageSize = 100;
            LogService.Write("查看7");
            //获取模具维修保养表的实例ID列表
            List<string> IDList = new List<string>();
            if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false)
@@ -2266,11 +2670,33 @@
            try
            {
                oCN.BeginTran();
                string HMouldMaintainRuleInterID = "0";
                string HMaintainItemID = "0";
                string HRepairID = "0";
                DataSet dataSet = oCN.RunProcReturn(@"select  a.HInterID,item.HMaintainItemID    from Sc_MouldMaintainRuleBillMain a with(nolock)
inner join Sc_MouldMaintainRuleBillSub_Item item with(nolock) on  a.HInterID = item.HInterID
where a.HRemark like'%钉钉同步%'", "Sc_MouldMaintainRuleBillMain");
                if (dataSet.Tables[0].Rows.Count > 0)
                {
                    HMouldMaintainRuleInterID = dataSet.Tables[0].Rows[0]["HInterID"].ToString();
                    HMaintainItemID = dataSet.Tables[0].Rows[0]["HMaintainItemID"].ToString();
                }
                dataSet = oCN.RunProcReturn(@"select HItemID from Gy_Repair a with(nolock) where a.HRemark like'%钉钉同步%' and HName like'%模具维修%'", "Gy_Repair");
                if (dataSet.Tables[0].Rows.Count > 0)
                {
                    HRepairID = dataSet.Tables[0].Rows[0]["HItemID"].ToString();
                }
                foreach (MouldFileWeiXiuBaoYang oItem in lsmain)
                {
                    //保养记录
                    if (oItem.DetailColMouldMaintain.Count != 0)
                    {
                        string BillType = "3819";
                        string sql = $@"select HInnerBillNo from Sc_MouldMaintainBillMain
                            where HInnerBillNo = '{oItem.HInstanceID}'";
@@ -2279,20 +2705,25 @@
                        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);
                            //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" +
                ",HMouldID,HBeginDate" +
                ",HEndDate" +
                ",HInnerBillNo,HExplanation,HMouldMaintainRuleInterID,HMaintainLevID,HLastResult" +
                ")values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',getdate(),'" + oItem.HOriginator + "','" + oItem.HMakeDate + "'" +
                ",HInnerBillNo,HExplanation,HMouldMaintainRuleInterID,HLastResult" +
                ",HRequestComDate,HRecentMainModule,HCumulativeModule,HProductionModule" +
                ",HPlanInterID,HPlanNo,HMaintainLevID)" +
                "values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + oItem.HBillNo + "','"+ oItem.HDate + "','" + oItem.HOriginator + "','" + oItem.HMakeDate + "'" +
                      ",'" + DateTime.Now.Year + "','" + DateTime.Now.Month + "','"+ oItem.HRemark + "','" + oItem.HUpdateDate + "'" +
                      ",'','0','" + oItem.HMouldID + "','" + oItem.HRepairBeginDate + "'" +
                      ",'" + oItem.HMouldID + "','" + oItem.HRepairBeginDate + "'" +
                      ",'" + oItem.HRepairEndDate + "'" +
                      ",'" + oItem.HInstanceID + "','',0,0,'OK')";
                      ",'" + oItem.HInstanceID + "','',"+ HMouldMaintainRuleInterID + ",'OK'" +
                      ",'"+ oItem.HRequestComDate + "'," + oItem.HRecentMainModule + "," + oItem.HCumulativeModule + "," + oItem.HProductionModule + "" +
                      "," + (oItem.HPlanInterID == "" ? "0" : oItem.HPlanInterID) + ",'" + oItem.HPlanNo + "'," + oItem.HMaintainLevID + ")";
                            LogService.Write(sql_main);
                            oCN.RunProc(sql_main);
                            int i = 1;
                            foreach (Sc_MouldMaintainBillSub oItem_Detail in oItem.DetailColMouldMaintain)
@@ -2303,11 +2734,13 @@
                          ",HManagerID" +
                          ",HCloseMan,HCloseType,HRemark" +
                          ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HMaintainResult" +
                          ") values('" + HInterID + "'," + i + ",0,'" + oItem_Detail.HClaim + "'" +
                          ") " +
                          "values('" + HInterID + "'," + i + ","+ HMaintainItemID + ",'" + oItem_Detail.HClaim + "'" +
                     ",'','" + oItem_Detail.HClaim + "'" +
                     ",'" + oItem.HEmpID + "'" +
                     ",'','','" + oItem_Detail.HMaintainResult + "'" +
                     ",'0','0','','',0,0,'')";
                     ",'0','0','','',0,0,'Y')";
                                LogService.Write(sql_sub);
                                oCN.RunProc(sql_sub);
                                i += 1;
                            }
@@ -2326,7 +2759,7 @@
                        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);
                            //string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
                            //long HInterID = 0;
                            //string HBillNo = "";
                            string sql_main = "Insert Into Sc_MouldRepairWorkBillMain " +
@@ -2336,13 +2769,15 @@
                ",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 + "',''" +
                ",HRepairAccepDate)values" +
                "('" + BillType + "','" + BillType + "'," + HInterID + ",'" + oItem.HBillNo + "','"+ oItem .HDate+ "'" +
                ",'" + DateTime.Now.Year + "','" + DateTime.Now.Month + "','"+ oItem.HRemark + "','" + oItem.HOriginator + "','" + oItem.HMakeDate + "'" +
                      ",'0','"+ HRepairID + "','" + oItem.HRepairBeginDate + "','" + oItem.HRepairEndDate + "',''" +
                      ",'小时','" + oItem.HPlanTimes + "','" + oItem.HTimes + "','" + oItem.HEmpID + "',0" +
                      ",'" + oItem.HDeptID + "','','" + oItem.HInstanceID + "','" + oItem.HMouldID + "'" +
                      ",'0','内部维修','','" + oItem.HNewDesignLife + "','',0,0)";
                      ",'0','内部维修','','" + oItem.HNewDesignLife + "','1',0,0" +
                      ",'"+ oItem.HRepairAccepDate + "')";
                            LogService.Write(sql_main);
                            oCN.RunProc(sql_main);
                            int i = 1;
                            foreach (Sc_MouldRepairWorkBillSub oItem_Detail in oItem.DetailColMouldRepair)
@@ -2353,7 +2788,8 @@
                       ",HRepairID,HRepairExplanation,HManagerID,HMoney) values" +
                       "('" + HInterID + "'," + i + ",'','','','" + oItem_Detail.HRemark + "'" +
                          ",0,0,'','',0,0" +
                          ",0,'" + oItem_Detail.HRepairExplanation + "','" + oItem.HEmpID + "',0)";
                          ","+ HRepairID + ",'" + oItem_Detail.HRepairExplanation + "','" + oItem.HEmpID + "',0)";
                                LogService.Write(sql_sub);
                                oCN.RunProc(sql_sub);
                                i += 1;
                            }
@@ -2368,6 +2804,7 @@
            }
            catch (Exception e)
            {
                LogService.Write(e.Message);
                msg = e.Message;
                oCN.RollBack();
                return false;
@@ -2380,7 +2817,7 @@
        #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)
        {
            string a = "";
            try
            {
                int startIndex = 0;
@@ -2427,25 +2864,79 @@
                                continue;
                            }
                            string HStaus = "";
                            switch (getInstanceByIdResponse.Body.InstanceStatus)
                            {
                                case "COMPLETED":
                                    HStaus = "维修结束";
                                    break;
                                case "RUNNING":
                                    HStaus = "维修进行中";
                                    break;
                                case "TERMINATED":
                                    HStaus = "维修终止";
                                    break;
                            }
                            LogService.Write("状态:" + HStaus);
                            if (getInstanceByIdResponse.Body.InstanceStatus != "COMPLETED")
                            {
                                //设备编码
                                if (keys.Contains("textField_lfg9hgys"))
                                {
                                    string HDate_Temp = response.Body.Result[i].FormData["textField_lfg9hgys"].ToString();
                                    DataSet ds = oCN.RunProcReturn("select * from Gy_EquipFileBillMain with(nolock)  where HEquipFileNo='" + HDate_Temp + "'", "Gy_EquipFileBillMain");
                                    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;
                                        string HUpdateDate = ds.Tables[0].Rows[0]["HCloseDate"].ToString()==""?"1900-01-01 00:00:00": ds.Tables[0].Rows[0]["HCloseDate"].ToString();
                                        string HMouldStaus = ds.Tables[0].Rows[0]["HStatus"].ToString();
                                        LogService.Write("设备:" + HDate_Temp + ",状态:" + HMouldStaus + ",时间:" + HUpdateDate);
                                        if (HMouldStaus != HStaus && DateTime.Parse(HUpdateDate) <= DateTime.Parse(oItem.HUpdateDate))
                                        {
                                            //修改设备的状态和时间
                                            oCN.RunProc("update Gy_EquipFileBillMain set HStatus='" + HStaus + "',HCloseDate='" + oItem.HUpdateDate + "' WHERE HInterID =" + HEquipID);
                                        }
                                    }
                                }
                                continue;
                            }
                            //if (oItem.HInstanceID != "9b6e108c-b7bf-45e4-910d-5629ac30d4aa") {
                            //    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");
                                DataSet ds = oCN.RunProcReturn("select * from Gy_EquipFileBillMain with(nolock)  where HEquipFileNo='" + HDate_Temp + "'", "Gy_EquipFileBillMain");
                                LogService.Write("设备无:" + HDate_Temp);
                                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;
                                    string HUpdateDate = ds.Tables[0].Rows[0]["HCloseDate"].ToString() == "" ? "1900-01-01 00:00:00" : ds.Tables[0].Rows[0]["HCloseDate"].ToString();
                                    string HMouldStaus = ds.Tables[0].Rows[0]["HStatus"].ToString();
                                    LogService.Write("设备:" + HDate_Temp + ",状态:" + HMouldStaus + ",时间:" + HUpdateDate);
                                    if (HMouldStaus != HStaus && DateTime.Parse(HUpdateDate) <= DateTime.Parse(oItem.HUpdateDate))
                                    {
                                        //修改设备的状态和时间
                                        oCN.RunProc("update Gy_EquipFileBillMain set HStatus='" + HStaus + "',HCloseDate='" + oItem.HUpdateDate + "' WHERE HInterID =" + HEquipID);
                                    }
                                }
                                oItem.HEquipID = long.Parse(HEquipID);
                                oItem.HRemark2 = HDate_Temp;
                                else
                                {
                                    continue;
                                }
                            }
                            LogService.Write("设备:" + oItem.HEquipID);
                            //维修部门
                            if (keys.Contains("selectField_kzgkw10a"))
@@ -2456,32 +2947,34 @@
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    HDeptID = ds.Tables[0].Rows[0]["HItemID"].ToString();
                                    oItem.HDeptID = long.Parse(HDeptID);
                                }
                                oItem.HDeptID = long.Parse(HDeptID);
                            }
                                else
                                {
                                    continue;
                                }
                            }
                            LogService.Write("维修部门:" + oItem.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");
                                DataSet ds = oCN.RunProcReturn("select * from Gy_Employee with(nolock)  where HName='" + 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);
                                }
                                oItem.HEmpID = long.Parse(HEmpID);
                            }
                                else
                                {
                                    continue;
                                }
                            //维修时间
                            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);
                            }
                            LogService.Write("维修人:" + oItem.HEmpID);
                            //维修内容
                            if (keys.Contains("textField_l2r9bvwk"))
@@ -2490,6 +2983,59 @@
                                oItem.HRepairContent = HDate_Temp;
                            }
                            LogService.Write("维修内容:" + oItem.HRepairContent);
                            //报修类别
                            if (keys.Contains("multiSelectField_lfg9hgyv"))
                            {
                                string[] HDate_Temp = JsonConvert.DeserializeObject<string[]>(JsonConvert.SerializeObject(response.Body.Result[i].FormData["multiSelectField_lfg9hgyv"]));
                                oItem.HRepairCategory = HDate_Temp[0];
                            }
                            LogService.Write("报修类别:" + oItem.HRepairCategory);
                            //紧急程度
                            if (keys.Contains("radioField_kzgkw10c"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["radioField_kzgkw10c"].ToString();
                                oItem.HUrgenLevel = HDate_Temp;
                            }
                            LogService.Write("紧急程度:" + oItem.HUrgenLevel);
                            //报修人
                            if (keys.Contains("employeeField_lkasesrk"))
                            {
                                string[] HDate_Temp = JsonConvert.DeserializeObject<string[]>(JsonConvert.SerializeObject(response.Body.Result[i].FormData["employeeField_lkasesrk"]));
                                oItem.HRepairer = HDate_Temp[0];
                            }
                            LogService.Write("报修人:" + oItem.HRepairer);
                            //是否有产能影响
                            if (keys.Contains("textField_lyjddw0r"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textField_lyjddw0r"].ToString();
                                oItem.HIsCapacityImpact = HDate_Temp;
                            }
                            LogService.Write("是否有产能影响:" + oItem.HIsCapacityImpact);
                            //维修时间
                            if (keys.Contains("textField_l2r95oo2"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textField_l2r95oo2"].ToString();
                                bool containsNumber = HDate_Temp.Any(c => char.IsDigit(c));
                                if (!containsNumber)
                                {
                                    HDate_Temp = "0";
                                }
                                //LogService.Write("1:------"+HDate_Temp+ ",2:------" + int.Parse(new string(HDate_Temp.Where(char.IsDigit).ToArray())));
                                //a = HDate_Temp;
                                oItem.HTimes = int.Parse(new string(HDate_Temp.Where(char.IsDigit).ToArray()));
                                oItem.HPlanTimes = int.Parse(new string(HDate_Temp.Where(char.IsDigit).ToArray()));
                            }
                            LogService.Write("维修时间:" + oItem.HTimes);
                            //子表 ç»´ä¿®è¦æ±‚ ç»´ä¿®å¤‡æ³¨(问题描述)
@@ -2500,9 +3046,10 @@
                            if (keys.Contains("textareaField_lthwo99r"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textareaField_lthwo99r"].ToString();
                                oItem.HExplanation = HDate_Temp;
                                sub.HRepairExplanation = HDate_Temp;
                            }
                            LogService.Write("维修要求:" + oItem.HExplanation);
                            //备注
                            if (keys.Contains("textField_l2r95oo0"))
@@ -2511,6 +3058,8 @@
                                sub.HRemark = HDate_Temp;
                            }
                            LogService.Write("备注:" + oItem.HRemark);
                            oItem.DetailColMouldRepair.Add(sub);
                            int startindex = response.Body.Result[i].Title.IndexOf("zh_CN") + 8;
@@ -2546,6 +3095,8 @@
                        }
                        catch (Exception e)
                        {
                            LogService.Write("报错:" + e.Message);
                            a = "";
                            continue;
                        }
                    }
@@ -2580,8 +3131,8 @@
            string formUuid = "FORM-OM566O7177LW0ARJ5IMFF63NTFKA34G9RL2YKN1";
            int pageNumber = 1;
            int pageSize = 100;
            //获取模具维修保养表的实例ID列表
            LogService.Write("查看6");
            //获取设备维修保养表的实例ID列表
            List<string> IDList = new List<string>();
            if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false)
            {
@@ -2598,6 +3149,14 @@
            try
            {
                oCN.BeginTran();
               DataSet dataSet = oCN.RunProcReturn(@"select HItemID from Gy_Repair a with(nolock) where a.HRemark like'%钉钉同步%' and HName like'%设备维修%'", "Gy_Repair");
                string HRepairID = "0";
                if (dataSet.Tables[0].Rows.Count > 0)
                {
                    HRepairID = dataSet.Tables[0].Rows[0]["HItemID"].ToString();
                }
                foreach (EquipRepairWeiXiu oItem in lsmain)
                {
                    //维修记录
@@ -2620,12 +3179,14 @@
                ",HEquipID,HRepairID,HPlanTimes,HEmpID,HManagerID,HTimes" +
                ",HDeptID,HExplanation,HInnerBillNo,HRepairBeginDate,HRepairEndDate" +
                ",HRepairContent,HCycleUnit,HMainSourceBillType,HMainSourceInterID,HMainSourceEntryID" +
                ")values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',getdate()" +
                ",HRepairCategory,HUrgenLevel,HRepairer,HIsCapacityImpact)" +
                "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)";
                      ",'" + oItem.HEquipID + "','"+ HRepairID + "','" + oItem.HTimes + "','" + oItem.HEmpID + "','" + oItem.HEmpID + "','" + oItem.HTimes + "'" +
                      ",'" + oItem.HDeptID + "','"+ oItem.HExplanation + "','" + oItem.HInstanceID + "','"+ oItem.HMakeDate + "','" + oItem.HUpdateDate + "'" +
                      ",'" + oItem.HRepairContent + "','小时','手工录入','0',0" +
                      ",'"+ oItem.HRepairCategory + "','" + oItem.HUrgenLevel + "','" + oItem.HRepairer + "','" + oItem.HIsCapacityImpact + "')";
                            LogService.Write(sql_main);
                            oCN.RunProc(sql_main);
                            int i = 1;
                            foreach (Sc_MouldRepairWorkBillSub oItem_Detail in oItem.DetailColMouldRepair)
@@ -2636,7 +3197,8 @@
                       ",HRepairID,HManagerID,HRepairExplanation,HEmpID)" +
                       "values('" + HInterID + "'," + i + ",'','','','" + oItem_Detail.HRemark + "'" +
                          ",0,0,'','',0,0" +
                          ",0,'" + oItem.HEmpID + "','" + oItem_Detail.HRepairExplanation + "','" + oItem.HEmpID + "')";
                          "," + HRepairID + ",'" + oItem.HEmpID + "','" + oItem_Detail.HRepairExplanation + "','" + oItem.HEmpID + "')";
                                LogService.Write(sql_sub);
                                oCN.RunProc(sql_sub);
                                i += 1;
                            }
@@ -2651,12 +3213,295 @@
            }
            catch (Exception e)
            {
                LogService.Write(e.Message);
                msg = e.Message;
                oCN.RollBack();
                return false;
            }
        }
        #endregion
        #endregion
        #region æ•°æ®åŒæ­¥-异常工时单OA里获取
        #region ç±»åž‹è½¬æ¢æå–response中的value对象
        public class StatValue
        {
            public string Id { get; set; }
            public string Label { get; set; }
            public string Upper { get; set; }
            public string Num { get; set; }
        }
        public class ExtValue
        {
            public List<StatValue> StatValue { get; set; }
            public string ComponentName { get; set; }
        }
        public class RowValue
        {
            public string Label { get; set; }
            public object Value { get; set; }
            public string Key { get; set; }
            // æ³¨æ„ï¼šè¿™é‡Œä¸å®šä¹‰extendValue属性,因为我们不需要它
            // public SomeType ExtendValue { get; set; } // å¦‚果需要,可以注释掉或删除这行
        }
        public class Row
        {
            public List<RowValue> RowValue { get; set; }
            public string RowNumber { get; set; }
            // æ³¨æ„ï¼šè¿™é‡Œå‡è®¾ä½ ä¸éœ€è¦componentName,因为JSON示例中没有直接包含它
            // ä½†å¦‚果你的实际JSON或需求中包含,你应该添加这个属性
            // public string ComponentName { get; set; }
        }
        #endregion
        #region OA异常工时申请单 å®žä¾‹ID列表对应的实例详情
        public bool getInstanceDetailList___ErrWorkTimesRequest_OA(List<string> processinstanceIDList, DateTime startTime, DateTime endTime, ref List<Pay_ErrWorkTimesRequestBill> lsmain,ref string msg)
        {
            try
            {
                List<GetProcessInstanceResponse> getProcessInstanceResponses = new List<GetProcessInstanceResponse>();
                //获取钉钉response
                if (getInstanceDetailListByInstanceIDList_OA(processinstanceIDList,ref getProcessInstanceResponses,ref msg)==false)
                {
                    return false;
                }
                foreach(GetProcessInstanceResponse getProcessInstanceResponse in getProcessInstanceResponses)
                {
                    Pay_ErrWorkTimesRequestBill oItem = new Pay_ErrWorkTimesRequestBill();
                    //主表
                    oItem.HDate = getProcessInstanceResponse.Body.Result.FormComponentValues[1].Value;//单据日期计时时间
                    DateTime dateTime1 = DateTime.ParseExact(oItem.HDate + " 00:00:00", "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                    if (!(DateTime.Compare(dateTime1, startTime)>=0&& DateTime.Compare(dateTime1, endTime) <= 0))//控制时间
                    {
                        continue;
                    }
                    string result = getProcessInstanceResponse.Body.Result.Result.ToString();
                    if (result != "agree")
                    {
                        continue;
                    }
                    string[] deptNameAndGroupName = getProcessInstanceResponse.Body.Result.OriginatorDeptName.Split('-');//获取部门拼接字符串数组
                    oItem.HDeptName = deptNameAndGroupName[1];
                    oItem.HGroupName = deptNameAndGroupName[deptNameAndGroupName.Length-1];
                    //主管-负责人
                    string HManagerValue = getProcessInstanceResponse.Body.Result.FormComponentValues[9].Value;//获取的名字含后缀英文
                    string pattern = @"[\u4e00-\u9fff]+"; // ä¸­æ–‡å­—符的Unicode范围
                    MatchCollection matches = Regex.Matches(HManagerValue, pattern);
                    // åˆ›å»ºä¸€ä¸ªStringBuilder来拼接所有匹配的中文字符
                    System.Text.StringBuilder chineseChars = new System.Text.StringBuilder();
                    foreach (Match match in matches)
                    {
                        chineseChars.Append(match.Value);
                    }
                    string HManagerName = chineseChars.ToString();
                    DataSet ds = oCN.RunProcReturn("select * from Gy_Employee with(nolock)  where HName='" + HManagerName + "'", "Gy_Employee");
                    string HMangerID = "0";
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        HMangerID = ds.Tables[0].Rows[0]["HItemID"].ToString();
                    }
                    oItem.HMangerID = int.Parse(HMangerID);
                    //处理部门和班组名称id
                    ds = oCN.RunProcReturn("select * from h_v_GroupList with(nolock)  where ç­ç»„名称='" + oItem.HGroupName + "'", "h_v_GroupList");
                    string HDeptID = "0";
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        HDeptID = ds.Tables[0].Rows[0]["HDeptID"].ToString();
                    }
                    oItem.HDeptID = int.Parse(HDeptID);
                    ds = oCN.RunProcReturn("select * from Gy_Group with(nolock)  where HName='" + oItem.HGroupName + "'", "Gy_Group");
                    string HGroupID = "0";
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        HGroupID = ds.Tables[0].Rows[0]["HItemID"].ToString();
                    }
                    oItem.HGroupID = int.Parse(HGroupID);
                    //反序列化明细内容
                    string tableFieldValue = getProcessInstanceResponse.Body.Result.FormComponentValues[11].Value;
                    List<Row> rows = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Row>>(tableFieldValue);
                    ExtValue extValue = Newtonsoft.Json.JsonConvert.DeserializeObject<ExtValue>(getProcessInstanceResponse.Body.Result.FormComponentValues[11].ExtValue);
                    oItem.HBatchNo = rows[0].RowValue[1].Value.ToString();//批次号-订单号码
                    //任务描述-任务类型+工作内容
                    oItem.HExplanation = getProcessInstanceResponse.Body.Result.FormComponentValues[2].Value + "-" + rows[0].RowValue[0].Value;
                    oItem.HSumRequestTimes = double.Parse(extValue.StatValue[1].Num);//总时长
                    oItem.HPlanQty = 0;//计划数量
                    oItem.HRemark = "钉钉导入" + getProcessInstanceResponse.Body.Result.Title;//备注
                    //循环遍历获取职员名称id,工时
                    for (int i = 0; i < rows.Count; i++)
                    {
                        if (rows[i].RowValue.Count<10)
                        {
                            continue;
                        }
                        string[] nameArray = rows[i].RowValue[4].Value.ToString().Split(',');//获取每个人的人名
                        oItem.HPlanQty += double.Parse(rows[i].RowValue[2].Value.ToString());//计划数量
                        for (int j = 0; j < int.Parse(rows[i].RowValue[5].Value.ToString()); j++)
                        {
                            if (nameArray.Length < j + 1)//防止出现人离职了计时单申请完了导致技术人员与计时人数不一致的问题
                            {
                                continue;
                            }
                            Pay_ErrWorkTimesRequestBillSub pay_ErrWorkTimesRequestBillSub = new Pay_ErrWorkTimesRequestBillSub();
                            ds = oCN.RunProcReturn("select * from Gy_Employee with(nolock)  where HName='" + nameArray[j] + "'", "Gy_Employee");
                            string HEmpID = "0";
                            //设置子表职员id名称
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                HEmpID = ds.Tables[0].Rows[0]["HItemID"].ToString();
                            }
                            pay_ErrWorkTimesRequestBillSub.HEmpName = nameArray[j];
                            pay_ErrWorkTimesRequestBillSub.HEmpID = int.Parse(HEmpID);
                            pay_ErrWorkTimesRequestBillSub.HRelTimes = double.Parse(rows[i].RowValue[6].Value.ToString());
                            pay_ErrWorkTimesRequestBillSub.HTimes = double.Parse(rows[i].RowValue[6].Value.ToString());
                            pay_ErrWorkTimesRequestBillSub.HRelPay = double.Parse(rows[i].RowValue[10].Value.ToString());
                            pay_ErrWorkTimesRequestBillSub.HPayMoney = pay_ErrWorkTimesRequestBillSub.HRelPay / pay_ErrWorkTimesRequestBillSub.HTimes;
                            pay_ErrWorkTimesRequestBillSub.HRemark = "钉钉导入";
                            oItem.Pay_ErrWorkTimesRequestBillSub.Add(pay_ErrWorkTimesRequestBillSub);
                        }
                    }
                    lsmain.Add(oItem);
                }
                return true;
            }catch(Exception e)
            {
                msg = e.Message;
                return false;
            }
        }
        #endregion
        #region æ•°æ®åŒæ­¥
        public bool getData_ErrWorkTimesRequest(DateTime startTime, DateTime endTime,ref string msg)
        {
            string processCode = "PROC-21371550-FEF1-4EDD-A827-639746E22E43";
            long nextToken = 1;
            int maxResult = 20;//最大20
            List<string> statues = new List<string>{"COMPLETED"};
            this.AppKey = "ding7miekiaqn4rc2ert";
            this.AppSecret = "81qMrC5SvkgjT9t2A3wUyEEENzyl9jJLeXOpjv2SNULc_HSlFZF4NE21YFCXik4K";
            getAccessToken();//设置accessToken
            //获取工时申请的实例ID列表
            List<string> IDList = new List<string>();
            if (getInstanceIDList_OA(processCode,startTime,endTime,nextToken,maxResult,statues,ref IDList, ref msg) == false)
            {
                return false;
            }
            //获取详细信息并附加到列表lsmain中
            List<Pay_ErrWorkTimesRequestBill> lsmain = new List<Pay_ErrWorkTimesRequestBill>();
            if (getInstanceDetailList___ErrWorkTimesRequest_OA(IDList,startTime,endTime, ref lsmain, ref msg) == false)
            {
                return false;
            }
            try
            {
                oCN.BeginTran();
                //删除时间范围内的导入单据
                DataSet dataSet = oCN.RunProcReturn(@"select HInterID from Pay_ErrWorkTimesRequestBillMain a with(nolock) where a.HRemark like '%钉钉导入%' and a.HIsImport = 1 and HDate >= '" + startTime + "' and HDate<='" + endTime + "'", "Pay_ErrWorkTimesRequestBillMain");
                if(dataSet != null && dataSet.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow row in dataSet.Tables[0].Rows)
                    {
                        int HInterID = row.Field<int>("HInterID");
                        oCN.RunProc(@"Delete From Pay_ErrWorkTimesRequestBillMain where HInterID = " + HInterID);
                        oCN.RunProc(@"Delete From Pay_ErrWorkTimesRequestBillSub where HInterID = " + HInterID);
                    }
                }
                //插入数据
                foreach(Pay_ErrWorkTimesRequestBill oItem in lsmain)
                {
                    if (oItem.Pay_ErrWorkTimesRequestBillSub.Count != 0)
                    {
                        string HBillType = "2231";
                        long HInterID = DBUtility.ClsPub.CreateBillID(HBillType, ref DBUtility.ClsPub.sExeReturnInfo);
                        string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod(HBillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
                        int HYear = int.Parse(oItem.HDate.Split('-')[0]);
                        int HPeriod = int.Parse(oItem.HDate.Split('-')[1]);
                        //主表
                        string sql = "insert into Pay_ErrWorkTimesRequestBillMain" +
                        "(HYear,HPeriod,HBillType,HBillSubType,HBillStatus,HInterID,HBillNo,HDate,HInnerBillNo,HDeptID,HGroupID,HMangerID,HICMOInterID,HICMOBillNo,HExplanation,HSumRequestTimes,HMaterID,HUnitID,HPlanQty,HBatchNo,HRemark,HMaker,HMakeDate,HChecker,HCheckDate,HIsImport) " +
                        "values(" +
                        "" + HYear +
                        "," + HPeriod +
                        ",'" + HBillType +
                        "','" + " " +
                        "'," + 2 +
                        "," + HInterID +
                        ",'" + HBillNo +
                        "','" + oItem.HDate +
                        "','" + " " +
                        "'," + oItem.HDeptID +
                        "," + oItem.HGroupID +
                        "," + oItem.HMangerID +
                        "," + "0" +
                        ",'" + " " +
                        "','" + oItem.HExplanation +
                        "'," + oItem.HSumRequestTimes +
                        "," + 0 +
                        "," + 0 +
                        "," + oItem.HPlanQty +
                        ",'" + oItem.HBatchNo +
                        "','" + oItem.HRemark +
                        "','" + "System" +
                        "'," + "GETDATE()" +
                        ",'" + "System" +
                        "'," + "GETDATE()" +
                        "," + "1" +
                        ")";
                        //主表
                        LogService.Write(sql);
                        oCN.RunProc(sql);
                        int i = 1;
                        foreach (Pay_ErrWorkTimesRequestBillSub oItem_Detail in oItem.Pay_ErrWorkTimesRequestBillSub)
                        {
                            sql = "insert into Pay_ErrWorkTimesRequestBillSub" +
                            "(HInterID,HEntryID,HEmpID,HWorkTypeID,HPayMoney,HBTimes,HETimes,HTimes,HRelTimes,HRelPay,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo" +
                            ",HSourceBillType,HRelationQty,HRelationMoney) " +
                            "values(" +
                            "" + HInterID +
                            "," + i +
                            "," + oItem_Detail.HEmpID +
                            "," + 0 +
                            "," + oItem_Detail.HPayMoney +
                            ",'" + "" +
                            "','" + "" +
                            "'," + oItem_Detail.HTimes +
                            "," + oItem_Detail.HRelTimes +
                            "," + oItem_Detail.HRelPay +
                            ",'" + oItem_Detail.HRemark +
                            "'," + 0 +
                            "," + 0 +
                            ",'" + " " +
                            "','" + " " +
                            "'," + 0 +
                            "," + 0 +
                            ")";
                            LogService.Write(sql);
                            oCN.RunProc(sql);
                            i += 1;
                        }
                    }
                }
                oCN.Commit();
                return true;
            }
            catch (Exception e)
            {
                LogService.Write(e.Message);
                msg = e.Message;
                oCN.RollBack();
                return false;
            }
        }
        #endregion
        #endregion
        #endregion
@@ -2734,5 +3579,39 @@
        }
        #endregion
        #region é’‰é’‰æ•°æ®åŒæ­¥OA
        [Route("DD_DataSynchronization/DataSynchronization_DingDing_OA")]
        [HttpGet]
        public object DataSynchronization_DingDing_OA(DateTime startTime, DateTime endTime, string user)
        {
            string msg = "";
            try
            {
                //if (getData_ErrWorkTimesRequest(startTime,endTime,ref msg) == false)
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "Exception!" + msg;
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}