using Model; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Pub_Class; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Web.Http; using WebAPI.Models; using Tea; using AlibabaCloud.SDK.Dingtalkyida_1_0.Models; using AlibabaCloud.SDK.Dingtalkoauth2_1_0.Models; using DingTalk.Api.Request; 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 { //钉钉数据同步 public class DD_DataSynchronizationController : ApiController { //获取系统参数 Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter(); public DBUtility.ClsPub.Enum_BillStatus BillStatus; private json objJsonResult = new json(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); DataSet ds; public static AlibabaCloud.SDK.Dingtalkworkflow_1_0.Client CreateClient1() { AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config(); config.Protocol = "https"; config.RegionId = "central"; return new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Client(config); } public static AlibabaCloud.SDK.Dingtalkoauth2_1_0.Client CreateClient2() { AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config(); config.Protocol = "https"; config.RegionId = "central"; return new AlibabaCloud.SDK.Dingtalkoauth2_1_0.Client(config); } public static AlibabaCloud.SDK.Dingtalkhrm_1_0.Client CreateClient3() { AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config(); config.Protocol = "https"; config.RegionId = "central"; return new AlibabaCloud.SDK.Dingtalkhrm_1_0.Client(config); } public static AlibabaCloud.SDK.Dingtalkyida_1_0.Client CreateClient4() { AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config(); config.Protocol = "https"; config.RegionId = "central"; return new AlibabaCloud.SDK.Dingtalkyida_1_0.Client(config); } public static AlibabaCloud.SDK.Dingtalkyida_1_0.Client CreateClient5() { AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config(); config.Protocol = "https"; config.RegionId = "central"; return new AlibabaCloud.SDK.Dingtalkyida_1_0.Client(config); } #region 变量 private string AppKey = "dingiokapm2dvjrhzl2g"; //已创建的企业内部应用的AppKey。 private string AppSecret = "dPUD7tN3BGVYAC4lDzhpcBH7O4FWFDdjLJWa6cVRBQj5U7GJ4Gwr7Vohnv0oPBOr"; //已创建的企业内部应用的AppSecret。 private long AgentID = 3188176952; //应用的AgentId public string accessToken = ""; //调用该接口的访问凭证。 private string ProcessInstanceId = ""; //审批实例ID。 #endregion #region 模型类 public class YD_GetInstanceIDListResponse { public long? TotalCount; public long? PageNumber; public List Data; } //oa审批返回类 public class OA_GetInstanceIDListResponse { public List list;//获取的id列表 public string nextToken; public bool? success; } #region 分层审核签到表 public class YD_FenCengShenHeQianDaoBiao { //单据信息 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 string HInstanceStatus; //实例状态 public string HApprovedResult; //审批结果 //单据内容 public string HDate; //日期 public string HCheckLevel; //审核等级 public string HArea; //区域 public string HEmployeeID; //成员ID public string HEmplpyee; //成员名称 } #endregion #region 现场变化点评审单 public class YD_XianChangBianHuaDianPingShenDan { //单据信息 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 string HInstanceStatus; //实例状态 public string HApprovedResult; //审批结果 //单据内容 public string HDate; //日期 public string HDept; //车间 public string HChangeType; //变化点类别 public string HRiskLevel; //风险等级 public string HChangeContent; //现场变化点内容 public string HRiskRemark_Safe; //安全风险评估 public string HRiskRemark_Study; //研发部风险评估 public string HRiskRemark_Quality; //品保部风险评估 public string HRiskRemark_Equipment; //设备部风险评估 public string HRiskRemark_Product; //生产部风险评估 public string HRiskRemak_Result; //风险评估评审结果 } #endregion #region 分层审核(LPA)管理 public class YD_FenCengShenHeGuanLi { //单据信息 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 string HInstanceStatus; //实例状态 public string HApprovedResult; //审批结果 //单据内容 public string HEmployeeID; //成员ID public string HEmployee; //成员名称 public string HDate; //日期 public string HCheckLevel; //审核层级 public string HCheckArea; //审核区域 public string HPhoto_NoSatisfyRequire; //不符合证据-照片 public string HDescription_NoSatisfyRequire; //不符合项说明 public string HQuestionType; //问题分类 public string HRequire_ModifyDate; //整改时效要求 public string HEmployeeID_Duty; //整改责任人ID public string HEmployee_Duty; //整改责任人 public string HQuestionIsNoModify; //问题是否无法整改 public string HReason_NoModify; //无法整改原因 public string HReasonAnalysis; //原因分析 public string HMethod_Modify; //整改措施 public string HDate_Achieve; //计划完成时间 public string HFile_Evidence; //证据文件 public string HCloseConfirm; //关闭验证 } #endregion #region QRQC问题提交表 public class YD_QRQCWenTiTiJiaoBiao { //单据信息 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 string HInstanceStatus; //实例状态 public string HApprovedResult; //审批结果 //单据内容 public string HQuestionType; //问题分类 public string HDept_Duty; //责任部门 public List HQuestion_Commit; //问题提交人填写数据 public List HQuestion_Duty; //问题责任人填写数据 } public class YD_QRQCWenTiTiJiaoBiaoSub1 { public string HProjectNo; //项目编号 public string HProjectGroup; //项目组 public string HArea; //发生区域 public string HDate; //发生日期 public string HIsRepeatQuestion; //是否重复性问题 public string HDescription; //问题描述 } public class YD_QRQCWenTiTiJiaoBiaoSub2 { public string HMethod_Cur; //应急措施 public string HDate_Cur; //计划完成时间(应急措施) public string HReasonAnalysis; //原因分析 public string HMethod_Long; //长期措施 public string HDate_Long; //计划完成时间(时间措施) } #endregion #region 花名册 public class DD_HuaMingCe { public string HEmployeeID; public string HEmployeeName; public string HAge; public string HStudyLevel; public string HDept; public string HWorkAge; } #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 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; //区域 public string HEmployeeID; //成员ID public string HEmplpyee; //成员名称 public List DetailColMouldRepair = new List(); public List DetailColMouldMaintain = new List(); } //维修子表 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 HRepairCategory; public string HUrgenLevel; public string HRepairer; public string HIsCapacityImpact; //单据内容 public string HDate; //日期 public string HCheckLevel; //审核等级 public string HArea; //区域 public string HEmployeeID; //成员ID public string HEmplpyee; //成员名称 public List DetailColMouldRepair = new List(); } #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 = new List(); } #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 钉钉 通用操作方法 #region 获取指定日期的时间戳(毫秒) public long getTimeMillions(DateTime dateTime) { DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); TimeSpan timeSpan = dateTime.ToUniversalTime() - epoch; return (long)timeSpan.TotalMilliseconds; } #endregion #region 根据时间戳(以毫秒为单位)转换为指定时区的日期格式(默认转为东八区时间格式) public string convertFromMillisecondsToDateString(double unixTimeStamp,string format,string timeZoneId = "China Standard Time") { //将时间戳转换为默认时区的时间 DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); //dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToUniversalTime(); //时间戳以秒为单位 dtDateTime = dtDateTime.AddMilliseconds(unixTimeStamp).ToUniversalTime(); //时间戳以毫秒为单位 // 获取目标时区信息 TimeZoneInfo targetTimeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId); // 转换为目标时区的时间 DateTimeOffset targetDateTime = TimeZoneInfo.ConvertTimeFromUtc(dtDateTime, targetTimeZone); string DateString = targetDateTime.ToString(format, CultureInfo.InvariantCulture); return DateString; } #endregion #region 获取企业内部应用的accessToken。 public void getAccessToken() { AlibabaCloud.SDK.Dingtalkoauth2_1_0.Client client = CreateClient2(); AlibabaCloud.SDK.Dingtalkoauth2_1_0.Models.GetAccessTokenRequest getAccessTokenRequest = new AlibabaCloud.SDK.Dingtalkoauth2_1_0.Models.GetAccessTokenRequest { AppKey = this.AppKey, //已创建的企业内部应用的AppKey。 AppSecret = this.AppSecret, //已创建的企业内部应用的AppSecret。 }; try { GetAccessTokenResponse accessToken = client.GetAccessToken(getAccessTokenRequest); this.accessToken = accessToken.Body.AccessToken; } catch (TeaException err) { if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message)) { // err 中含有 code 和 message 属性,可帮助开发定位问题 } } catch (Exception _err) { TeaException err = new TeaException(new Dictionary { { "message", _err.Message } }); if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message)) { // err 中含有 code 和 message 属性,可帮助开发定位问题 } } } #endregion #region 获取 钉钉-智能人事 获取在职员工ID列表--指定分页的数据 public bool getEmployeeIDList_Page_DingDing(long offset, long size, ref OapiSmartworkHrmEmployeeQueryonjobResponse response, ref string msg) { try { IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/queryonjob"); OapiSmartworkHrmEmployeeQueryonjobRequest req = new OapiSmartworkHrmEmployeeQueryonjobRequest(); req.StatusList = "2,3,5,-1"; //在职员工状态筛选,可以查询多个状态。不同状态之间使用英文逗号分隔。[2:试用期;3:正式;5:待离职;-1:无状态] req.Offset = offset; //分页游标,从0开始。根据返回结果里的next_cursor是否为空来判断是否还有下一页,且再次调用时offset设置成next_cursor的值。 req.Size = size; //分页大小,最大50。 OapiSmartworkHrmEmployeeQueryonjobResponse rsp = client.Execute(req, this.accessToken); response = rsp; return true; } catch (Exception e) { msg = e.Message; return false; } } #endregion #region 获取 钉钉-智能人事 获取在职员工ID列表 public bool getEmployeeIDList_DingDing(long offset, long size, ref List IDList, ref string msg) { OapiSmartworkHrmEmployeeQueryonjobResponse response = new OapiSmartworkHrmEmployeeQueryonjobResponse(); do { if (getEmployeeIDList_Page_DingDing(offset, size, ref response, ref msg) == false) { return false; } for (int i = 0; i < response.Result.DataList.Count; i++) { IDList.Add(response.Result.DataList[i]); } if (response.Result.NextCursor != 0) { offset = response.Result.NextCursor; } else { break; } } while (true); return true; } #endregion #region 获取 根据职员ID列表批量获取职员详情 --一定数量的 public bool getEmployeeDetailListByEmployeeIDList_DingDing(string IDList, ref OapiSmartworkHrmEmployeeV2ListResponse response, ref string msg) { try { IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/v2/list"); OapiSmartworkHrmEmployeeV2ListRequest req = new OapiSmartworkHrmEmployeeV2ListRequest(); req.UseridList = IDList; req.Agentid = this.AgentID; OapiSmartworkHrmEmployeeV2ListResponse rsp = client.Execute(req, this.accessToken); response = rsp; return true; } catch (Exception e) { msg = e.Message; return false; } } #endregion #endregion #region 宜搭 通用操作方法 #region 获取 宜搭指定单据的实例ID列表--指定分页的数据 public bool getInstanceIDList_Page_YiDa(string appType, string systemToken, string userID, string formUuid, int pageNumber, int pageSize, ref YD_GetInstanceIDListResponse response, ref string msg) { AlibabaCloud.SDK.Dingtalkyida_1_0.Client client = CreateClient4(); AlibabaCloud.SDK.Dingtalkyida_1_0.Models.GetInstanceIdListHeaders getInstanceIdListHeaders = new AlibabaCloud.SDK.Dingtalkyida_1_0.Models.GetInstanceIdListHeaders(); getInstanceIdListHeaders.XAcsDingtalkAccessToken = this.accessToken; AlibabaCloud.SDK.Dingtalkyida_1_0.Models.GetInstanceIdListRequest getInstanceIdListRequest = new AlibabaCloud.SDK.Dingtalkyida_1_0.Models.GetInstanceIdListRequest { //必选属性 AppType = appType, //应用编码。 SystemToken = systemToken, //应用秘钥。 FormUuid = formUuid, //表单ID。 UserId = userID, //用户userid。 ////非必选属性 //ModifiedFromTimeGMT = "23", //修改时间起始值 //ModifiedToTimeGMT = "23", //修改时间终止值。 //Language = "43", //SearchFieldJson = "23", //根据表单内组件值查询。 //InstanceStatus = "32", //实例状态。 //ApprovedResult = "12", //流程审批结果。 //OriginatorId = "12", //根据流程发起人工号查询。 //TaskId = "12", //任务ID。 //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, //分页页码 }; try { GetInstanceIdListResponse getInstanceIdListResponse = client.GetInstanceIdListWithOptions(getInstanceIdListRequest, getInstanceIdListHeaders, new AlibabaCloud.TeaUtil.Models.RuntimeOptions()); //MessageBox.Show(JsonConvert.SerializeObject(getInstanceIdListResponse.Body)); response.Data = getInstanceIdListResponse.Body.Data; response.TotalCount = getInstanceIdListResponse.Body.TotalCount; response.PageNumber = getInstanceIdListResponse.Body.PageNumber; 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 { { "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 获取 宜搭指定单据的实例ID列表 public bool getInstanceIDList_YiDa(string appType, string systemToken, string userID, string formUuid, int pageNumber, int pageSize, ref List IDList, ref string msg) { YD_GetInstanceIDListResponse response = new YD_GetInstanceIDListResponse(); do { if (getInstanceIDList_Page_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref response, ref msg) == false) { return false; } for (int i = 0; i < response.Data.Count; i++) { IDList.Add(response.Data[i]); } pageNumber = (int)response.PageNumber + 1; } while (response.Data.Count != 0); return true; } #endregion #region 获取 宜搭 根据实例ID列表批量获取实例详情 --一定数量的 public bool getInstanceDetailListByInstanceIDList_YiDa(string appType, string systemToken, string formUuid, string userID, List IDList, ref BatchGetFormDataByIdListResponse response, ref string msg) { AlibabaCloud.SDK.Dingtalkyida_1_0.Client client = CreateClient5(); AlibabaCloud.SDK.Dingtalkyida_1_0.Models.BatchGetFormDataByIdListHeaders batchGetFormDataByIdListHeaders = new AlibabaCloud.SDK.Dingtalkyida_1_0.Models.BatchGetFormDataByIdListHeaders(); batchGetFormDataByIdListHeaders.XAcsDingtalkAccessToken = this.accessToken; AlibabaCloud.SDK.Dingtalkyida_1_0.Models.BatchGetFormDataByIdListRequest batchGetFormDataByIdListRequest = new AlibabaCloud.SDK.Dingtalkyida_1_0.Models.BatchGetFormDataByIdListRequest { SystemToken = systemToken, FormUuid = formUuid, FormInstanceIdList = IDList, UserId = userID, AppType = appType, }; try { BatchGetFormDataByIdListResponse batchGetFormDataByIdListResponse = client.BatchGetFormDataByIdListWithOptions(batchGetFormDataByIdListRequest, batchGetFormDataByIdListHeaders, new AlibabaCloud.TeaUtil.Models.RuntimeOptions()); response = batchGetFormDataByIdListResponse; 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 { { "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 获取 宜搭 根据实例ID获取实例详情 public bool getInstanceDetailByInstanceID_FenCengShenHeQianDaoDan__YiDa(string appType, string systemToken, string userID, string instanceID, ref string msg) { AlibabaCloud.SDK.Dingtalkyida_1_0.Client client = CreateClient5(); AlibabaCloud.SDK.Dingtalkyida_1_0.Models.GetFormDataByIDHeaders getFormDataByIDHeaders = new AlibabaCloud.SDK.Dingtalkyida_1_0.Models.GetFormDataByIDHeaders(); getFormDataByIDHeaders.XAcsDingtalkAccessToken = this.accessToken; AlibabaCloud.SDK.Dingtalkyida_1_0.Models.GetFormDataByIDRequest getFormDataByIDRequest = new AlibabaCloud.SDK.Dingtalkyida_1_0.Models.GetFormDataByIDRequest { AppType = appType, //应用编码。 SystemToken = systemToken, //应用秘钥。 UserId = userID, //用户的userid。 }; try { GetFormDataByIDResponse getFormDataByIDResponse = client.GetFormDataByIDWithOptions(instanceID, getFormDataByIDRequest, getFormDataByIDHeaders, 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 { { "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 获取 宜搭 根据流程实例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 { { "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 oa 通用操作方法 #region OA 获取审批实例ID列表(单页) public bool getInstanceIDList_Page_OA(string processCode,DateTime startTime, DateTime endTime,long nextToken, int maxResult, List 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 { { "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 statuses, ref List 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 { { "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 processinstanceIDList, ref List 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列表对应的实例详情 public bool getInstanceDetailList_FenCengShenHeQianDaoDan__YiDa(string appType, string systemToken, string userID, string formUuid, List IDList,ref List 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 IDList_temp = new List(); 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 keys = new List(response.Body.Result[i].FormData.Keys); YD_FenCengShenHeQianDaoBiao oItem = new YD_FenCengShenHeQianDaoBiao(); 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("'", ""); ; 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)response.Body.Result[i].FormData["employeeField_lo6w37hf"])[0].ToString().Replace("'",""); //} //if (keys.Contains("employeeField_lo6w37hf_id")) //{ // oItem.HEmployeeID = ((List)response.Body.Result[i].FormData["employeeField_lo6w37hf_id"])[0].ToString().Replace("'", ""); //} //签到表 if (keys.Contains("dateField_ls9ma7h3")) { double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_ls9ma7h3"].ToString()); oItem.HDate = convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd"); } if (keys.Contains("selectField_ls9ma7h9")) { oItem.HArea = response.Body.Result[i].FormData["selectField_ls9ma7h9"].ToString().Replace("'", ""); } if (keys.Contains("selectField_ls9ma7h7")) { oItem.HCheckLevel = response.Body.Result[i].FormData["selectField_ls9ma7h7"].ToString().Replace("'", ""); } if (keys.Contains("employeeField_ls9ma7h5")) { oItem.HEmplpyee = ((List)response.Body.Result[i].FormData["employeeField_ls9ma7h5"])[0].ToString().Replace("'", ""); } if (keys.Contains("employeeField_ls9ma7h5_id")) { oItem.HEmployeeID = ((List)response.Body.Result[i].FormData["employeeField_ls9ma7h5_id"])[0].ToString().Replace("'", ""); } //获取实例状态 GetInstanceByIdResponse response1 = new GetInstanceByIdResponse(); if (getInstanceStatusByInstanceID__YiDa(appType, systemToken, userID, oItem.HInstanceID, ref response1, ref msg) == false) { return false; } oItem.HInstanceStatus = response1.Body.InstanceStatus; if (oItem.HInstanceStatus == "RUNNING") { oItem.HInstanceStatus = "运行中"; } else if (oItem.HInstanceStatus == "TERMINATED") { oItem.HInstanceStatus = "已终止"; } else if (oItem.HInstanceStatus == "COMPLETED") { oItem.HInstanceStatus = "已完成"; } else if (oItem.HInstanceStatus == "ERROR") { oItem.HInstanceStatus = "异常"; } oItem.HApprovedResult = response1.Body.ApprovedResult; if (oItem.HApprovedResult == "agree") { oItem.HApprovedResult = "同意"; } else if (oItem.HApprovedResult == "disagree") { oItem.HApprovedResult = "拒绝"; } else { oItem.HApprovedResult = ""; } 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_FenCengShenHeQianDaoBiao(ref string msg) { //获取 分层审核表 实例ID列表 string appType = "APP_MMBPP3IFGFBX3VQAIKYX"; string systemToken = "TP866A81107FVI9LBFQRZ9953YWZ2GYR2W6OL1L"; string userID = "1933673646699149"; //string formUuid = "FORM-IQ8666B17ZZE7NQSA01K3DUN78UI3J1Z2W6OLX"; //分层审核签到表 string formUuid = "FORM-A01FFB0B63A34F18B7753F695F49190DJEY7"; //签到表 int pageNumber = 1; int pageSize = 100; //获取分层审核表的实例ID列表 List IDList = new List(); if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false) { return false; } //获取详细信息并附加到列表lsmain中 List lsmain = new List(); if(getInstanceDetailList_FenCengShenHeQianDaoDan__YiDa(appType, systemToken, userID, formUuid, IDList, ref lsmain, ref msg) == false) { return false; } try { oCN.BeginTran(); foreach (YD_FenCengShenHeQianDaoBiao oItem in lsmain) { string sql_searchRepeat = "select * from DD_FenCengShenHeQianDaoBiao where HInstanceID = '" + oItem.HInstanceID + "'"; DataSet ds_searchRepeat = oCN.RunProcReturn(sql_searchRepeat, "DD_FenCengShenHeQianDaoBiao"); if (ds_searchRepeat != null && ds_searchRepeat.Tables[0].Rows.Count > 0) { string sql_deleteRepeat = "delete from DD_FenCengShenHeQianDaoBiao where HInstanceID = '" + oItem.HInstanceID + "'"; oCN.RunProc(sql_deleteRepeat); } string sql_main = "insert into DD_FenCengShenHeQianDaoBiao" + "(HMakerID,HMakeDate,HUpdaterID,HUpdater,HUpdateDate,HInstanceID,HOriginator,HTitle" + ",HDate" + ",HCheckLevel,HArea,HEmployeeID,HEmplpyee" + ",HInstanceStatus,HApprovedResult) " + "values(" + "'" + oItem.HMakerID + "'" + ",'" + oItem.HMakeDate + "'" + ",'" + oItem.HUpdaterID + "'" + ",'" + oItem.HUpdater + "'" + ",'" + oItem.HUpdateDate + "'" + ",'" + oItem.HInstanceID + "'" + ",'" + oItem.HOriginator + "'" + ",'" + oItem.HTitle + "'" + "," + (oItem.HDate==null?"null":"'" + oItem.HDate + "'") + "" + ",'" + (oItem.HCheckLevel==null?"": oItem.HCheckLevel) + "'" + ",'" + (oItem.HArea==null?"": oItem.HArea) + "'" + ",'" + (oItem.HEmployeeID==null?"": oItem.HEmployeeID) + "'" + ",'" + (oItem.HEmplpyee==null?"": oItem.HEmplpyee) + "'" + ",'" + (oItem.HInstanceStatus == null ? "" : oItem.HInstanceStatus) + "'" + ",'" + (oItem.HApprovedResult == null ? "" : oItem.HApprovedResult) + "'" + ")"; oCN.RunProc(sql_main); } oCN.Commit(); return true; }catch(Exception e) { msg = e.Message; oCN.RollBack(); return false; } } #endregion #endregion #region 数据同步-现场变化点评审单 #region 获取 宜搭-现场变化点评审单 实例ID列表对应的实例详情 public bool getInstanceDetailList_XianChangBianHuaDianPingShenDan__YiDa(string appType, string systemToken, string userID, string formUuid, List IDList, ref List 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 IDList_temp = new List(); 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 keys = new List(response.Body.Result[i].FormData.Keys); YD_XianChangBianHuaDianPingShenDan oItem = new YD_XianChangBianHuaDianPingShenDan(); 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("'", ""); ; 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_lxsmpho2")) { double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_lxsmpho2"].ToString()); oItem.HDate = convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd"); } if (keys.Contains("selectField_lxcx8tq0")) { oItem.HDept = response.Body.Result[i].FormData["selectField_lxcx8tq0"].ToString().Replace("'", ""); } if (keys.Contains("selectField_lxbkk45z")) { oItem.HChangeType = response.Body.Result[i].FormData["selectField_lxbkk45z"].ToString().Replace("'", ""); } if (keys.Contains("selectField_lxbkr5c4")) { oItem.HRiskLevel = response.Body.Result[i].FormData["selectField_lxbkr5c4"].ToString().Replace("'", ""); } if (keys.Contains("textareaField_lxbjmu83")) { oItem.HChangeContent = response.Body.Result[i].FormData["textareaField_lxbjmu83"].ToString().Replace("'", ""); } if (keys.Contains("textareaField_lxbl78z2")) { oItem.HRiskRemark_Safe = response.Body.Result[i].FormData["textareaField_lxbl78z2"].ToString().Replace("'", ""); } if (keys.Contains("textareaField_lxbjmu85")) { oItem.HRiskRemark_Study = response.Body.Result[i].FormData["textareaField_lxbjmu85"].ToString().Replace("'", ""); } if (keys.Contains("textareaField_lxbjmu87")) { oItem.HRiskRemark_Quality = response.Body.Result[i].FormData["textareaField_lxbjmu87"].ToString().Replace("'", ""); } if (keys.Contains("textareaField_lxbjmu89")) { oItem.HRiskRemark_Equipment = response.Body.Result[i].FormData["textareaField_lxbjmu89"].ToString().Replace("'", ""); } if (keys.Contains("textareaField_lxbk94n2")) { oItem.HRiskRemark_Product = response.Body.Result[i].FormData["textareaField_lxbk94n2"].ToString().Replace("'", ""); } if (keys.Contains("textareaField_lxblb9xa")) { oItem.HRiskRemak_Result = response.Body.Result[i].FormData["textareaField_lxblb9xa"].ToString().Replace("'", ""); } //获取实例状态 GetInstanceByIdResponse response1 = new GetInstanceByIdResponse(); if (getInstanceStatusByInstanceID__YiDa(appType, systemToken, userID, oItem.HInstanceID, ref response1, ref msg) == false) { return false; } oItem.HInstanceStatus = response1.Body.InstanceStatus; if (oItem.HInstanceStatus == "RUNNING") { oItem.HInstanceStatus = "运行中"; } else if (oItem.HInstanceStatus == "TERMINATED") { oItem.HInstanceStatus = "已终止"; } else if (oItem.HInstanceStatus == "COMPLETED") { oItem.HInstanceStatus = "已完成"; } else if (oItem.HInstanceStatus == "ERROR") { oItem.HInstanceStatus = "异常"; } oItem.HApprovedResult = response1.Body.ApprovedResult; if (oItem.HApprovedResult == "agree") { oItem.HApprovedResult = "同意"; } else if (oItem.HApprovedResult == "disagree") { oItem.HApprovedResult = "拒绝"; } else { oItem.HApprovedResult = ""; } 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_XianChangBianHuaDianPingShenDan(ref string msg) { //现场变化点评审单 参数信息 string appType = "APP_T6CQONMMH5ME9LM8S656"; string systemToken = "QW766881GKWLNUQWEWT9IBSJLB8X279FE9BXLS4"; string userID = "1933673646699149"; string formUuid = "FORM-E3DFC12364514330A836DD3056C15668UGG7"; int pageNumber = 1; int pageSize = 100; //获取实例ID列表 List IDList = new List(); if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false) { return false; } //获取详细信息并附加到列表lsmain中 List lsmain = new List(); if (getInstanceDetailList_XianChangBianHuaDianPingShenDan__YiDa(appType, systemToken, userID, formUuid, IDList, ref lsmain, ref msg) == false) { return false; } try { oCN.BeginTran(); foreach (YD_XianChangBianHuaDianPingShenDan oItem in lsmain) { string sql_searchRepeat = "select * from DD_XianChangBianHuaDianPingShenDan where HInstanceID = '" + oItem.HInstanceID + "'"; DataSet ds_searchRepeat = oCN.RunProcReturn(sql_searchRepeat, "DD_XianChangBianHuaDianPingShenDan"); if (ds_searchRepeat != null && ds_searchRepeat.Tables[0].Rows.Count > 0) { string sql_deleteRepeat = "delete from DD_XianChangBianHuaDianPingShenDan where HInstanceID = '" + oItem.HInstanceID + "'"; oCN.RunProc(sql_deleteRepeat); } string sql_main = "insert into DD_XianChangBianHuaDianPingShenDan" + "(HMakerID,HMakeDate,HUpdaterID,HUpdater,HUpdateDate,HInstanceID,HOriginator,HTitle" + ",HDate" + ",HDept,HChangeType,HRiskLevel,HChangeContent,HRiskRemark_Safe,HRiskRemark_Study,HRiskRemark_Quality,HRiskRemark_Equipment,HRiskRemark_Product,HRiskRemark_Result" + ",HInstanceStatus,HApprovedResult) " + "values(" + "'" + oItem.HMakerID + "'" + ",'" + oItem.HMakeDate + "'" + ",'" + oItem.HUpdaterID + "'" + ",'" + oItem.HUpdater + "'" + ",'" + oItem.HUpdateDate + "'" + ",'" + oItem.HInstanceID + "'" + ",'" + oItem.HOriginator + "'" + ",'" + oItem.HTitle + "'" + "," + (oItem.HDate==null?"null":"'" + oItem.HDate + "'") + "" + ",'" + (oItem.HDept==null?"": oItem.HDept) + "'" + ",'" + (oItem.HChangeType==null?"": oItem.HChangeType) + "'" + ",'" + (oItem.HRiskLevel==null?"": oItem.HRiskLevel )+ "'" + ",'" + (oItem.HChangeContent==null?"": oItem.HChangeContent) + "'" + ",'" + (oItem.HRiskRemark_Safe==null?"": oItem.HRiskRemark_Safe) + "'" + ",'" + (oItem.HRiskRemark_Study==null?"": oItem.HRiskRemark_Study) + "'" + ",'" + (oItem.HRiskRemark_Quality==null?"": oItem.HRiskRemark_Quality) + "'" + ",'" + (oItem.HRiskRemark_Equipment==null?"": oItem.HRiskRemark_Equipment) + "'" + ",'" + (oItem.HRiskRemark_Product==null?"": oItem.HRiskRemark_Product) + "'" + ",'" + (oItem.HRiskRemak_Result==null?"": oItem.HRiskRemak_Result) + "'" + ",'" + (oItem.HInstanceStatus == null ? "" : oItem.HInstanceStatus) + "'" + ",'" + (oItem.HApprovedResult == null ? "" : oItem.HApprovedResult) + "'" + ")"; oCN.RunProc(sql_main); } oCN.Commit(); return true; } catch (Exception e) { msg = e.Message; oCN.RollBack(); return false; } } #endregion #endregion #region 数据同步-分层审核(LPA)管理 #region 获取 宜搭-分层审核(LPA)管理 实例ID列表对应的实例详情 public bool getInstanceDetailList_FenCengShenHeGuanLi__YiDa(string appType, string systemToken, string userID, string formUuid, List IDList, ref List 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 IDList_temp = new List(); 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 keys = new List(response.Body.Result[i].FormData.Keys); YD_FenCengShenHeGuanLi oItem = new YD_FenCengShenHeGuanLi(); 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("'", ""); ; 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("employeeField_loz3zrdt")) { oItem.HEmployee = ((List)response.Body.Result[i].FormData["employeeField_loz3zrdt"])[0].ToString().Replace("'", ""); } if (keys.Contains("employeeField_loz3zrdt_id")) { oItem.HEmployeeID = ((List)response.Body.Result[i].FormData["employeeField_loz3zrdt_id"])[0].ToString().Replace("'", ""); } if (keys.Contains("dateField_loz3zrdu")) { double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_loz3zrdu"].ToString()); oItem.HDate = convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd"); } if (keys.Contains("selectField_ljdtmy2i")) { oItem.HCheckLevel = response.Body.Result[i].FormData["selectField_ljdtmy2i"].ToString().Replace("'", ""); } if (keys.Contains("selectField_ljdn6sgv")) { oItem.HCheckArea = response.Body.Result[i].FormData["selectField_ljdn6sgv"].ToString().Replace("'", ""); } if (keys.Contains("attachmentField_ljdn6sh3")) { oItem.HPhoto_NoSatisfyRequire = response.Body.Result[i].FormData["attachmentField_ljdn6sh3"].ToString().Replace("'", ""); } if (keys.Contains("textareaField_ljdn6sh1")) { oItem.HDescription_NoSatisfyRequire = response.Body.Result[i].FormData["textareaField_ljdn6sh1"].ToString().Replace("'", ""); } if (keys.Contains("selectField_ljdn6sgz")) { oItem.HQuestionType = response.Body.Result[i].FormData["selectField_ljdn6sgz"].ToString().Replace("'", ""); } if (keys.Contains("selectField_ltwahl66")) { oItem.HRequire_ModifyDate = response.Body.Result[i].FormData["selectField_ltwahl66"].ToString().Replace("'", ""); } if (keys.Contains("employeeField_llogutfd_id")) { oItem.HEmployeeID = ((List)response.Body.Result[i].FormData["employeeField_llogutfd_id"])[0].ToString().Replace("'", ""); } if (keys.Contains("employeeField_llogutfd")) { oItem.HEmployee_Duty = ((List)response.Body.Result[i].FormData["employeeField_llogutfd"])[0].ToString().Replace("'", ""); } if (keys.Contains("radioField_lkcbn9ah")) { oItem.HQuestionIsNoModify = response.Body.Result[i].FormData["radioField_lkcbn9ah"].ToString().Replace("'", ""); } if (keys.Contains("textareaField_lkcbn9aj")) { oItem.HReason_NoModify = response.Body.Result[i].FormData["textareaField_lkcbn9aj"].ToString().Replace("'", ""); } if (keys.Contains("textareaField_ljnlv15r")) { oItem.HReasonAnalysis = response.Body.Result[i].FormData["textareaField_ljnlv15r"].ToString().Replace("'", ""); } if (keys.Contains("textareaField_ljdn6sh7")) { oItem.HMethod_Modify = response.Body.Result[i].FormData["textareaField_ljdn6sh7"].ToString().Replace("'", ""); } if (keys.Contains("dateField_ljnmhgqk")) { double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_ljnmhgqk"].ToString()); oItem.HDate_Achieve = convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd"); } if (keys.Contains("attachmentField_ljdn6sh9")) { oItem.HFile_Evidence = response.Body.Result[i].FormData["attachmentField_ljdn6sh9"].ToString().Replace("'", ""); } if (keys.Contains("selectField_ltpe6mdd")) { oItem.HCloseConfirm = response.Body.Result[i].FormData["selectField_ltpe6mdd"].ToString().Replace("'", ""); } //获取实例状态 GetInstanceByIdResponse response1 = new GetInstanceByIdResponse(); if(getInstanceStatusByInstanceID__YiDa(appType, systemToken, userID, oItem.HInstanceID, ref response1, ref msg) == false) { return false; } oItem.HInstanceStatus = response1.Body.InstanceStatus; if(oItem.HInstanceStatus == "RUNNING") { oItem.HInstanceStatus = "运行中"; }else if(oItem.HInstanceStatus== "TERMINATED") { oItem.HInstanceStatus = "已终止"; } else if (oItem.HInstanceStatus == "COMPLETED") { oItem.HInstanceStatus = "已完成"; } else if (oItem.HInstanceStatus == "ERROR") { oItem.HInstanceStatus = "异常"; } oItem.HApprovedResult = response1.Body.ApprovedResult; if (oItem.HApprovedResult== "agree") { oItem.HApprovedResult = "同意"; }else if(oItem.HApprovedResult== "disagree") { oItem.HApprovedResult = "拒绝"; } else { oItem.HApprovedResult = ""; } 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_FenCengShenHeGuanLi(ref string msg) { //分层审核(LPA)管理 参数信息 string appType = "APP_AA6W6DTMJVDC4VU45Y6O"; string systemToken = "WWA66O91ZLZB7LNG76FJQBONY7SV26HQOMDJL71"; string userID = "1933673646699149"; string formUuid = "FORM-K5766HA1CKZB4E1L64Y1KBWCJTQF2HWJ3NDJL4"; int pageNumber = 1; int pageSize = 100; //获取实例ID列表 List IDList = new List(); if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false) { return false; } //获取详细信息并附加到列表lsmain中 List lsmain = new List(); if (getInstanceDetailList_FenCengShenHeGuanLi__YiDa(appType, systemToken, userID, formUuid, IDList, ref lsmain, ref msg) == false) { return false; } try { oCN.BeginTran(); foreach (YD_FenCengShenHeGuanLi oItem in lsmain) { string sql_searchRepeat = "select * from DD_FenCengShenHeGuanLi where HInstanceID = '" + oItem.HInstanceID + "'"; DataSet ds_searchRepeat = oCN.RunProcReturn(sql_searchRepeat, "DD_FenCengShenHeGuanLi"); if (ds_searchRepeat != null && ds_searchRepeat.Tables[0].Rows.Count > 0) { string sql_deleteRepeat = "delete from DD_FenCengShenHeGuanLi where HInstanceID = '" + oItem.HInstanceID + "'"; oCN.RunProc(sql_deleteRepeat); } string sql_main = "insert into DD_FenCengShenHeGuanLi" + "(HMakerID,HMakeDate,HUpdaterID,HUpdater,HUpdateDate,HInstanceID,HOriginator,HTitle,HEmployeeID,HEmployee" + ",HDate" + ",HCheckLevel,HCheckArea,HPhoto_NoSatisfyRequire,HDescription_NoSatisfyRequire,HQuestionType,HRequire_ModifyDate,HEmployeeID_Duty,HEmployee_Duty" + ",HQuestionIsNoModify" + ",HReason_NoModify,HReasonAnalysis,HMethod_Modify" + ",HDate_Achieve,HFile_Evidence,HCloseConfirm,HInstanceStatus,HApprovedResult" + ") " + "values(" + "'" + oItem.HMakerID + "'" + ",'" + oItem.HMakeDate + "'" + ",'" + oItem.HUpdaterID + "'" + ",'" + oItem.HUpdater + "'" + ",'" + oItem.HUpdateDate + "'" + ",'" + oItem.HInstanceID + "'" + ",'" + oItem.HOriginator + "'" + ",'" + oItem.HTitle + "'" + ",'" + (oItem.HEmployeeID==null?"": oItem.HEmployeeID) + "'" + ",'" + (oItem.HEmployee==null?"": oItem.HEmployee) + "'" + "," + (oItem.HDate==null?"null":"'" + oItem.HDate + "'") + "" + ",'" + (oItem.HCheckLevel==null?"": oItem.HCheckLevel) + "'" + ",'" + (oItem.HCheckArea==null?"": oItem.HCheckArea) + "'" + ",'" + (oItem.HPhoto_NoSatisfyRequire==null?"": oItem.HPhoto_NoSatisfyRequire) + "'" + ",'" + (oItem.HDescription_NoSatisfyRequire==null?"": oItem.HDescription_NoSatisfyRequire) + "'" + ",'" + (oItem.HQuestionType==null?"": oItem.HQuestionType) + "'" + ",'" + (oItem.HRequire_ModifyDate==null?"": oItem.HRequire_ModifyDate) + "'" + ",'" + (oItem.HEmployeeID_Duty==null?"": oItem.HEmployeeID_Duty) + "'" + ",'" + (oItem.HEmployee_Duty==null?"": oItem.HEmployee_Duty) + "'" + ",'" + (oItem.HQuestionIsNoModify==null?"": oItem.HQuestionIsNoModify) + "'" + ",'" + (oItem.HReason_NoModify==null?"": oItem.HReason_NoModify) + "'" + ",'" + (oItem.HReasonAnalysis==null?"": oItem.HReasonAnalysis) + "'" + ",'" + (oItem.HMethod_Modify==null?"": oItem.HMethod_Modify) + "'" + "," + (oItem.HDate_Achieve==null?"null":"'"+ oItem.HDate_Achieve+ "'") + "" + ",'" + (oItem.HFile_Evidence==null?"": oItem.HFile_Evidence) + "'" + ",'" + (oItem.HCloseConfirm==null?"": oItem.HCloseConfirm) + "'" + ",'" + (oItem.HInstanceStatus==null?"":oItem.HInstanceStatus) + "'" + ",'" + (oItem.HApprovedResult==null?"":oItem.HApprovedResult) + "'" + ")"; oCN.RunProc(sql_main); } oCN.Commit(); return true; } catch (Exception e) { msg = e.Message; oCN.RollBack(); return false; } } #endregion #endregion #region 数据同步-QRQC问题提交表 #region 获取 宜搭-QRQC问题提交表 实例ID列表对应的实例详情 public bool getInstanceDetailList_QRQCWenTiTiJiaoBiao__YiDa(string appType, string systemToken, string userID, string formUuid, List IDList, ref List 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 IDList_temp = new List(); 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 keys_main = new List(response.Body.Result[i].FormData.Keys); YD_QRQCWenTiTiJiaoBiao oItem = new YD_QRQCWenTiTiJiaoBiao(); 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("'", ""); ; 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_main.Contains("selectField_lx4azanb")) { oItem.HQuestionType = response.Body.Result[i].FormData["selectField_lx4azanb"].ToString().Replace("'", ""); } if (keys_main.Contains("selectField_lxcunmsu")) { oItem.HDept_Duty = response.Body.Result[i].FormData["selectField_lxcunmsu"].ToString().Replace("'", ""); } //获取实例状态 GetInstanceByIdResponse response1 = new GetInstanceByIdResponse(); if (getInstanceStatusByInstanceID__YiDa(appType, systemToken, userID, oItem.HInstanceID, ref response1, ref msg) == false) { return false; } oItem.HInstanceStatus = response1.Body.InstanceStatus; if (oItem.HInstanceStatus == "RUNNING") { oItem.HInstanceStatus = "运行中"; } else if (oItem.HInstanceStatus == "TERMINATED") { oItem.HInstanceStatus = "已终止"; } else if (oItem.HInstanceStatus == "COMPLETED") { oItem.HInstanceStatus = "已完成"; } else if (oItem.HInstanceStatus == "ERROR") { oItem.HInstanceStatus = "异常"; } oItem.HApprovedResult = response1.Body.ApprovedResult; if (oItem.HApprovedResult == "agree") { oItem.HApprovedResult = "同意"; } else if (oItem.HApprovedResult == "disagree") { oItem.HApprovedResult = "拒绝"; } else { oItem.HApprovedResult = ""; } List sub1List = new List(); if (keys_main.Contains("tableField_lx4azand")) { foreach (Dictionary obj in (List)response.Body.Result[i].FormData["tableField_lx4azand"]) { List keys_sub1 = new List(obj.Keys); YD_QRQCWenTiTiJiaoBiaoSub1 sub1 = new YD_QRQCWenTiTiJiaoBiaoSub1(); if (keys_sub1.Contains("textField_lx4azane")) { sub1.HProjectNo = obj["textField_lx4azane"].ToString().Replace("'", ""); } if (keys_sub1.Contains("selectField_lx4azanf")) { sub1.HProjectGroup = obj["selectField_lx4azanf"].ToString().Replace("'", ""); } if (keys_sub1.Contains("selectField_lx4azang")) { sub1.HArea = obj["selectField_lx4azang"].ToString().Replace("'", ""); } if (keys_sub1.Contains("dateField_lx4azanh")) { double HDate_Temp = double.Parse(obj["dateField_lx4azanh"].ToString()); sub1.HDate = convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd"); } if (keys_sub1.Contains("selectField_lx4azank")) { sub1.HIsRepeatQuestion = obj["selectField_lx4azank"].ToString().Replace("'", ""); } if (keys_sub1.Contains("textareaField_lx4azani")) { sub1.HDescription = obj["textareaField_lx4azani"].ToString().Replace("'", ""); } sub1List.Add(sub1); } } oItem.HQuestion_Commit = sub1List; List sub2List = new List(); if (keys_main.Contains("tableField_lx4azanj")) { foreach (Dictionary obj in (List)response.Body.Result[i].FormData["tableField_lx4azanj"]) { List keys_sub2 = new List(obj.Keys); YD_QRQCWenTiTiJiaoBiaoSub2 sub2 = new YD_QRQCWenTiTiJiaoBiaoSub2(); if (keys_sub2.Contains("textareaField_lx4azanm")) { sub2.HMethod_Cur = obj["textareaField_lx4azanm"].ToString().Replace("'", ""); } if (keys_sub2.Contains("dateField_lx4azano")) { double HDate_Temp = double.Parse(obj["dateField_lx4azano"].ToString()); sub2.HDate_Cur = convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd"); } if (keys_sub2.Contains("textareaField_lx4azanl")) { sub2.HReasonAnalysis = obj["textareaField_lx4azanl"].ToString().Replace("'", ""); } if (keys_sub2.Contains("textareaField_lx4azann")) { sub2.HMethod_Long = obj["textareaField_lx4azann"].ToString().Replace("'", ""); } if (keys_sub2.Contains("dateField_lx4azanp")) { double HDate_Temp = double.Parse(obj["dateField_lx4azanp"].ToString()); sub2.HDate_Long = convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd"); } sub2List.Add(sub2); } } oItem.HQuestion_Duty = sub2List; 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_QRQCWenTiTiJiaoBiao(ref string msg) { //QRQC问题提交表 参数信息 string appType = "APP_WC3R2CL3ZOUF4Q63N1CZ"; string systemToken = "LNB66E81MCRLK1DS7N4ODDH2JRJO3C63SA4XL72"; string userID = "1933673646699149"; string formUuid = "FORM-65AD77453E7F44EA847166C3AB5A1F04IPSS"; int pageNumber = 1; int pageSize = 100; //获取实例ID列表 List IDList = new List(); if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false) { return false; } //获取详细信息并附加到列表lsmain中 List lsmain = new List(); if (getInstanceDetailList_QRQCWenTiTiJiaoBiao__YiDa(appType, systemToken, userID, formUuid, IDList, ref lsmain, ref msg) == false) { return false; } try { oCN.BeginTran(); foreach (YD_QRQCWenTiTiJiaoBiao oItem in lsmain) { ////判断单据 实例状态是否为"已完成"且 审批结果为"同意",若是则同步数据,否则不进行同步数据 //if (!(oItem.HInstanceStatus == "已完成" && oItem.HApprovedResult == "同意")) //{ // continue; //} string sql_searchRepeat = "select * from DD_QRQCWenTiTiJiaoBiao where HInstanceID = '" + oItem.HInstanceID + "'"; DataSet ds_searchRepeat = oCN.RunProcReturn(sql_searchRepeat, "DD_QRQCWenTiTiJiaoBiao"); if (ds_searchRepeat != null && ds_searchRepeat.Tables[0].Rows.Count > 0) { string sql_deleteRepeat = "delete from DD_QRQCWenTiTiJiaoBiao where HInstanceID = '" + oItem.HInstanceID + "'"; oCN.RunProc(sql_deleteRepeat); sql_deleteRepeat = "delete from DD_QRQCWenTiTiJiaoBiaoSub1 where HInstanceID = '" + oItem.HInstanceID + "'"; oCN.RunProc(sql_deleteRepeat); sql_deleteRepeat = "delete from DD_QRQCWenTiTiJiaoBiaoSub2 where HInstanceID = '" + oItem.HInstanceID + "'"; oCN.RunProc(sql_deleteRepeat); } string sql_main = "insert into DD_QRQCWenTiTiJiaoBiao" + "(HMakerID,HMakeDate,HUpdaterID,HUpdater,HUpdateDate,HInstanceID,HOriginator,HTitle,HQuestionType,HDept_Duty" + ",HInstanceStatus,HApprovedResult) " + "values(" + "'" + oItem.HMakerID + "'" + ",'" + oItem.HMakeDate + "'" + ",'" + oItem.HUpdaterID + "'" + ",'" + oItem.HUpdater + "'" + ",'" + oItem.HUpdateDate + "'" + ",'" + oItem.HInstanceID + "'" + ",'" + oItem.HOriginator + "'" + ",'" + oItem.HTitle + "'" + ",'" + (oItem.HQuestionType==null?"": oItem.HQuestionType) + "'" + ",'" + (oItem.HDept_Duty==null?"": oItem.HDept_Duty) + "'" + ",'" + (oItem.HInstanceStatus == null ? "" : oItem.HInstanceStatus) + "'" + ",'" + (oItem.HApprovedResult == null ? "" : oItem.HApprovedResult) + "'" + ")"; oCN.RunProc(sql_main); int sub1_Entry = 1; foreach(YD_QRQCWenTiTiJiaoBiaoSub1 sub1 in oItem.HQuestion_Commit) { string sql_sub1 = "insert into DD_QRQCWenTiTiJiaoBiaoSub1" + "(HInstanceID,HEntryID,HProjectNo,HProjectGroup,HArea" + ",HDate" + ",HIsRepeatQuestion,HDescription) " + "values(" + "'" + (oItem.HInstanceID==null?"": oItem.HInstanceID) + "'" + ",'" + (sub1_Entry++) + "'" + ",'" + (sub1.HProjectNo==null?"":sub1.HProjectNo) + "'" + ",'" + (sub1.HProjectGroup==null?"": sub1.HProjectGroup) + "'" + ",'" + (sub1.HArea==null?"": sub1.HArea) + "'" + "," + (sub1.HDate==null?"null":"'" + sub1.HDate + "'") + "" + ",'" + (sub1.HIsRepeatQuestion==null?"": sub1.HIsRepeatQuestion) + "'" + ",'" + (sub1.HDescription==null?"": sub1.HDescription) + "'" + ")"; oCN.RunProc(sql_sub1); } int sub2_Entry = 1; foreach (YD_QRQCWenTiTiJiaoBiaoSub2 sub2 in oItem.HQuestion_Duty) { string sql_sub2 = "insert into DD_QRQCWenTiTiJiaoBiaoSub2" + "(HInstanceID,HEntryID,HMethod_Cur" + ",HDate_Cur" + ",HReasonAnalysis,HMethod_Long" + ",HDate_Long" + ") " + "values(" + "'" + (oItem.HInstanceID == null ? "" : oItem.HInstanceID) + "'" + ",'" + (sub2_Entry++) + "'" + ",'" + (sub2.HMethod_Cur == null ? "" : sub2.HMethod_Cur) + "'" + "," + (sub2.HDate_Cur == null ? "null" : "'" + sub2.HDate_Cur + "'") + "" + ",'" + (sub2.HReasonAnalysis == null ? "" : sub2.HReasonAnalysis) + "'" + ",'" + (sub2.HMethod_Long == null ? "" : sub2.HMethod_Long) + "'" + "," + (sub2.HDate_Long == null ? "null" : "'" + sub2.HDate_Long + "'") + "" + ")"; oCN.RunProc(sql_sub2); } } oCN.Commit(); return true; } catch (Exception e) { msg = e.Message; oCN.RollBack(); return false; } } #endregion #endregion #region 数据同步-钉钉-智能人事-花名册员工信息 #region 获取 根据职员ID列表批量获取职员详情 public bool getEmployeeDetailList_HuaMingCe__DingDing(List IDList, ref List lsmain, ref string msg, int size = 50) { try { int startIndex = 0; int endIndex = startIndex + size; if (endIndex > IDList.Count) { endIndex = IDList.Count; } while (startIndex < endIndex && endIndex <= IDList.Count) { //List IDList_temp = new List(); //for (int i = startIndex; i < endIndex; i++) //{ // IDList_temp.Add(IDList[i]); //} //拼接职员ID string IDList_temp = ""; for (int i = startIndex; i < endIndex; i++) { IDList_temp += IDList[i] + ","; } //去除拼接字符串的最后一个逗号 if (IDList_temp.Length > 0) { IDList_temp = IDList_temp.Substring(0, IDList_temp.Length - 1); } OapiSmartworkHrmEmployeeV2ListResponse response = new OapiSmartworkHrmEmployeeV2ListResponse(); if (getEmployeeDetailListByEmployeeIDList_DingDing(IDList_temp, ref response, ref msg) == false) { return false; } string[] studyLevelList = new string[] {"","高中","中专","大专","本科","","","其他","初中","小学" }; for (int i = 0; i < response.Result.Count; i++) { List fieldNameList = new List(); for (int j = 0; j < response.Result[i].FieldDataList.Count; j++) { fieldNameList.Add(response.Result[i].FieldDataList[j].FieldName); } try { DD_HuaMingCe oItem = new DD_HuaMingCe(); oItem.HEmployeeID = response.Result[i].Userid; if (fieldNameList.IndexOf("姓名") >= 0) { int index = fieldNameList.IndexOf("姓名"); oItem.HEmployeeName = response.Result[i].FieldDataList[index].FieldValueList[0].Value; } if (fieldNameList.IndexOf("年龄(系统计算)") >= 0) { int index = fieldNameList.IndexOf("年龄(系统计算)"); oItem.HAge = response.Result[i].FieldDataList[index].FieldValueList[0].Value; } if (fieldNameList.IndexOf("学历") >= 0) { int index = fieldNameList.IndexOf("学历"); oItem.HStudyLevel = response.Result[i].FieldDataList[index].FieldValueList[0].Value; if (oItem.HStudyLevel != null && oItem.HStudyLevel != "") { long studyLevelIndex = DBUtility.ClsPub.isLong(oItem.HStudyLevel); if (studyLevelIndex >= studyLevelList.Length) { studyLevelIndex = 0; } oItem.HStudyLevel = studyLevelList[studyLevelIndex]; } } if (fieldNameList.IndexOf("部门") >= 0) { int index = fieldNameList.IndexOf("部门"); oItem.HDept = response.Result[i].FieldDataList[index].FieldValueList[0].Value; } if (fieldNameList.IndexOf("司龄(系统计算)") >= 0) { int index = fieldNameList.IndexOf("司龄(系统计算)"); oItem.HWorkAge = response.Result[i].FieldDataList[index].FieldValueList[0].Value; } 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_HuaMingCe(ref string msg) { long offset = 0; long size = 50; //获取花名册职员ID列表 List IDList = new List(); if (getEmployeeIDList_DingDing(offset, size, ref IDList, ref msg) == false) { return false; } //获取详细信息并附加到列表lsmain中 List lsmain = new List(); if (getEmployeeDetailList_HuaMingCe__DingDing(IDList, ref lsmain, ref msg) == false) { return false; } try { oCN.BeginTran(); foreach (DD_HuaMingCe oItem in lsmain) { string sql_searchRepeat = "select * from DD_HuaMingCe where HEmployeeID = '" + oItem.HEmployeeID + "'"; DataSet ds_searchRepeat = oCN.RunProcReturn(sql_searchRepeat, "DD_HuaMingCe"); if (ds_searchRepeat != null && ds_searchRepeat.Tables[0].Rows.Count > 0) { string sql_deleteRepeat = "delete from DD_HuaMingCe where HEmployeeID = '" + oItem.HEmployeeID + "'"; oCN.RunProc(sql_deleteRepeat); } string sql_main = "insert into DD_HuaMingCe" + "(HEmployeeID,HEmployeeName,HAge,HStudyLevel,HDept,HWorkAge) " + "values(" + "'" + (oItem.HEmployeeID == null ? "" : oItem.HEmployeeID) + "'" + ",'" + (oItem.HEmployeeName == null ? "" : oItem.HEmployeeName) + "'" + ",'" + (oItem.HAge == null ? "0" : oItem.HAge) + "'" + ",'" + (oItem.HStudyLevel == null ? "" : oItem.HStudyLevel) + "'" + ",'" + (oItem.HDept == null ? "" : oItem.HDept) + "'" + ",'" + (oItem.HWorkAge == null ? "" : oItem.HWorkAge) + "'" + ")"; oCN.RunProc(sql_main); } oCN.Commit(); return true; } catch (Exception e) { msg = e.Message; oCN.RollBack(); return false; } } #endregion #endregion #region 数据同步-模具维修保养单 #region 获取 宜搭-模具维修保养单 实例ID列表对应的实例详情 public bool getInstanceDetailList___MouldFileWeiXiuBaoYang_YiDa(string appType, string systemToken, string userID, string formUuid, List IDList, ref List 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 IDList_temp = new List(); 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 keys = new List(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_lq0v65sv")) { double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_lq0v65sv"].ToString()); oItem.HDate = convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd HH:mm"); } //模具保养级别 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; } //修模开始时间 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.HBillNo = HDate_Temp; } //要求完成日期 if (keys.Contains("dateField_lq3idkvd")) { 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")); } //维修受理日期 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")); } //最近保养模数 if (keys.Contains("numberField_lq3idkvi")) { string HDate_Temp = response.Body.Result[i].FormData["numberField_lq3idkvi"].ToString(); oItem.HRecentMainModule = double.Parse(HDate_Temp); } //累计模数 if (keys.Contains("numberField_lq3idkvj")) { string HDate_Temp = response.Body.Result[i].FormData["numberField_lq3idkvj"].ToString(); oItem.HCumulativeModule = double.Parse(HDate_Temp); } //本次生产模数 if (keys.Contains("textField_lq4vdvgh")) { string HDate_Temp = response.Body.Result[i].FormData["textField_lq4vdvgh"].ToString(); oItem.HProductionModule = double.Parse(HDate_Temp); } //模具编码 if (keys.Contains("selectField_lq3idkvg")) { string HDate_Temp = response.Body.Result[i].FormData["selectField_lq3idkvg"].ToString(); 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) { HMouldID = ds.Tables[0].Rows[0]["HInterID"].ToString(); } oItem.HMouldID = long.Parse(HMouldID); oItem.HRemark = HDate_Temp; //查询保养计划 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 + " and a.HMaintainLevID = " + oItem.HMaintainLevID, "Sc_MouldMaintainPlanBillMain"); 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]["HInterID"].ToString(); } } //维修部门 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(JsonConvert.SerializeObject(response.Body.Result[i].FormData["employeeField_lq3idkvh"])); 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); } //维修时间 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> dic = JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(response.Body.Result[i].FormData["tableField_lq3ixr9b"])); for (int ij = 0; ij < dic.Count; ij++) { Sc_MouldRepairWorkBillSub oItemSub = new Sc_MouldRepairWorkBillSub(); List keys_Sub = new List(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(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)response.Body.Result[i].FormData["employeeField_lo6w37hf"])[0].ToString().Replace("'", ""); } if (keys.Contains("employeeField_lo6w37hf_id")) { oItem.HEmployeeID = ((List)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) { LogService.Write(e.Message); 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 IDList = new List(); if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false) { return false; } //获取详细信息并附加到列表lsmain中 List lsmain = new List(); if (getInstanceDetailList___MouldFileWeiXiuBaoYang_YiDa(appType, systemToken, userID, formUuid, IDList, ref lsmain, ref msg) == false) { return false; } 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}'"; 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" + ",HMouldID,HBeginDate" + ",HEndDate" + ",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 + "'" + ",'" + oItem.HMouldID + "','" + oItem.HRepairBeginDate + "'" + ",'" + oItem.HRepairEndDate + "'" + ",'" + 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) { 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 + ","+ HMaintainItemID + ",'" + oItem_Detail.HClaim + "'" + ",'','" + oItem_Detail.HClaim + "'" + ",'" + oItem.HEmpID + "'" + ",'','','" + oItem_Detail.HMaintainResult + "'" + ",'0','0','','',0,0,'Y')"; LogService.Write(sql_sub); 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" + ",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 + "','1',0,0" + ",'"+ oItem.HRepairAccepDate + "')"; LogService.Write(sql_main); 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" + ","+ HRepairID + ",'" + oItem_Detail.HRepairExplanation + "','" + oItem.HEmpID + "',0)"; LogService.Write(sql_sub); oCN.RunProc(sql_sub); i += 1; } } } } oCN.Commit(); return true; } catch (Exception e) { LogService.Write(e.Message); 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 IDList, ref List lsmain, ref string msg, int size = 500) { string a = ""; try { int startIndex = 0; int endIndex = startIndex + size; if (endIndex > IDList.Count) { endIndex = IDList.Count; } while (startIndex < endIndex && endIndex <= IDList.Count) { List IDList_temp = new List(); 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 keys = new List(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 (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_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; } else { continue; } } //维修部门 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); } else { continue; } } //维修人 if (keys.Contains("employeeField_lthwkdh2")) { string[] HDate_Temp = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(response.Body.Result[i].FormData["employeeField_lthwkdh2"])); 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); } else { continue; } } //维修内容 if (keys.Contains("textField_l2r9bvwk")) { string HDate_Temp = response.Body.Result[i].FormData["textField_l2r9bvwk"].ToString(); oItem.HRepairContent = HDate_Temp; } //报修类别 if (keys.Contains("multiSelectField_lfg9hgyv")) { string[] HDate_Temp = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(response.Body.Result[i].FormData["multiSelectField_lfg9hgyv"])); oItem.HRepairCategory = HDate_Temp[0]; } //紧急程度 if (keys.Contains("radioField_kzgkw10c")) { string HDate_Temp = response.Body.Result[i].FormData["radioField_kzgkw10c"].ToString(); oItem.HUrgenLevel = HDate_Temp; } //报修人 if (keys.Contains("employeeField_lkasesrk")) { string[] HDate_Temp = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(response.Body.Result[i].FormData["employeeField_lkasesrk"])); oItem.HRepairer = HDate_Temp[0]; } //是否有产能影响 if (keys.Contains("textField_lyjddw0r")) { string HDate_Temp = response.Body.Result[i].FormData["textField_lyjddw0r"].ToString(); oItem.HIsCapacityImpact = HDate_Temp; } //维修时间 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())); } //子表 维修要求 维修备注(问题描述) Sc_MouldRepairWorkBillSub sub = new Sc_MouldRepairWorkBillSub(); //维修要求 if (keys.Contains("textareaField_lthwo99r")) { string HDate_Temp = response.Body.Result[i].FormData["textareaField_lthwo99r"].ToString(); oItem.HExplanation = HDate_Temp; 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)response.Body.Result[i].FormData["employeeField_lo6w37hf"])[0].ToString().Replace("'", ""); } if (keys.Contains("employeeField_lo6w37hf_id")) { oItem.HEmployeeID = ((List)response.Body.Result[i].FormData["employeeField_lo6w37hf_id"])[0].ToString().Replace("'", ""); } lsmain.Add(oItem); } catch (Exception e) { LogService.Write(e.Message); a = ""; 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 IDList = new List(); if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false) { return false; } //获取详细信息并附加到列表lsmain中 List lsmain = new List(); if (getInstanceDetailList___EquipRepairWeiXiu_YiDa(appType, systemToken, userID, formUuid, IDList, ref lsmain, ref msg) == false) { return false; } 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) { //维修记录 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" + ",HRepairCategory,HUrgenLevel,HRepairer,HIsCapacityImpact)" + "values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',getdate()" + ",'" + DateTime.Now.Year + "','" + DateTime.Now.Month + "','"+ oItem.HRemark2 + "','" + oItem.HOriginator + "','" + oItem.HMakeDate + "'" + ",'" + 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) { 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" + "," + HRepairID + ",'" + oItem.HEmpID + "','" + oItem_Detail.HRepairExplanation + "','" + oItem.HEmpID + "')"; LogService.Write(sql_sub); oCN.RunProc(sql_sub); i += 1; } } } } oCN.Commit(); return true; } 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 { 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 { 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 processinstanceIDList, DateTime startTime, DateTime endTime, ref List lsmain,ref string msg) { try { List getProcessInstanceResponses = new List(); //获取钉钉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 rows = Newtonsoft.Json.JsonConvert.DeserializeObject>(tableFieldValue); ExtValue extValue = Newtonsoft.Json.JsonConvert.DeserializeObject(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 statues = new List{"COMPLETED"}; this.AppKey = "ding7miekiaqn4rc2ert"; this.AppSecret = "81qMrC5SvkgjT9t2A3wUyEEENzyl9jJLeXOpjv2SNULc_HSlFZF4NE21YFCXik4K"; getAccessToken();//设置accessToken //获取工时申请的实例ID列表 List IDList = new List(); if (getInstanceIDList_OA(processCode,startTime,endTime,nextToken,maxResult,statues,ref IDList, ref msg) == false) { return false; } //获取详细信息并附加到列表lsmain中 List lsmain = new List(); 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("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 #region 钉钉数据同步 [Route("DD_DataSynchronization/DataSynchronization_DingDing_YiDa")] [HttpGet] public object DataSynchronization_DingDing_YiDa(string sWhere, string user) { string msg = ""; try { getAccessToken(); //if (getData_FenCengShenHeQianDaoBiao(ref msg) == false) //{ // objJsonResult.code = "0"; // objJsonResult.count = 0; // objJsonResult.Message = "Exception!" + msg; // objJsonResult.data = null; // return objJsonResult; //} //if (getData_XianChangBianHuaDianPingShenDan(ref msg) == false) //{ // objJsonResult.code = "0"; // objJsonResult.count = 0; // objJsonResult.Message = "Exception!" + msg; // objJsonResult.data = null; // return objJsonResult; //} //if (getData_FenCengShenHeGuanLi(ref msg) == false) //{ // objJsonResult.code = "0"; // objJsonResult.count = 0; // objJsonResult.Message = "Exception!" + msg; // objJsonResult.data = null; // return objJsonResult; //} //if (getData_QRQCWenTiTiJiaoBiao(ref msg) == false) //{ // objJsonResult.code = "0"; // objJsonResult.count = 0; // objJsonResult.Message = "Exception!" + msg; // objJsonResult.data = null; // return objJsonResult; //} //if (getData_HuaMingCe(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 #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 } }