1
yangle
2024-08-22 ab973f62261817e581f48e63074d62d8f0e50c24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
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;
 
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
        private string accessToken = "";                                                                                           //调用该接口的访问凭证。
        private string ProcessInstanceId = "";                                                                                     //审批实例ID。
        #endregion
 
        #region 模型类
        public class YD_GetInstanceIDListResponse
        {
            public long? TotalCount;
            public long? PageNumber;
            public List<string> Data;
        }
 
        #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 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 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 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 HQuestionType;                        //问题分类
            public string HDept_Duty;                           //责任部门
            public List<YD_QRQCWenTiTiJiaoBiaoSub1> HQuestion_Commit;  //问题提交人填写数据
            public List<YD_QRQCWenTiTiJiaoBiaoSub2> 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
        #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<string, object>
                {
                    { "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<string> 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.ToString("dd") == "01"?"2022-01-01":DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"),                                          //创建时间起始值。
                CreateToTimeGMT = 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<string, object>
                {
                    { "message", _err.Message }
                });
                if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
                {
                    // err 中含有 code 和 message 属性,可帮助开发定位问题
                }
                msg = "错误代码" + err.Code + ":" + err.Message;
                return false;
            }
        }
        #endregion
 
        #region 获取 宜搭指定单据的实例ID列表
        public bool getInstanceIDList_YiDa(string appType, string systemToken, string userID, string formUuid, int pageNumber, int pageSize, ref List<string> 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<string> 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<string, object>
                {
                    { "message", _err.Message }
                });
                if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
                {
                    // err 中含有 code 和 message 属性,可帮助开发定位问题
                }
                msg = "错误代码" + err.Code + ":" + err.Message;
                return false;
            }
        }
        #endregion
 
        #region 获取 宜搭 根据实例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<string, object>
                {
                    { "message", _err.Message }
                });
                if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
                {
                    // err 中含有 code 和 message 属性,可帮助开发定位问题
                }
                msg = "错误代码" + err.Code + ":" + err.Message;
                return false;
            }
        }
        #endregion
        #endregion
 
        #region 数据同步方法
        #region 数据同步-分层审核签到表
        #region 获取 宜搭-分层审核签到表 实例ID列表对应的实例详情
        public bool getInstanceDetailList_FenCengShenHeQianDaoDan__YiDa(string appType, string systemToken, string userID, string formUuid, List<string> IDList,ref List<YD_FenCengShenHeQianDaoBiao> lsmain, ref string msg, int size = 500)
        {
 
            try
            {
                int startIndex = 0;
                int endIndex = startIndex + size;
                if (endIndex > IDList.Count)
                {
                    endIndex = IDList.Count;
                }
 
                while (startIndex < endIndex && endIndex <= IDList.Count)
                {
                    List<string> IDList_temp = new List<string>();
                    for (int i = startIndex; i < endIndex; i++)
                    {
                        IDList_temp.Add(IDList[i]);
                    }
 
                    BatchGetFormDataByIdListResponse response = new BatchGetFormDataByIdListResponse();
                    if (getInstanceDetailListByInstanceIDList_YiDa(appType, systemToken, formUuid, userID, IDList_temp, ref response, ref msg) == false)
                    {
                        return false;
                    }
 
 
                    for (int i = 0; i < response.Body.Result.Count; i++)
                    {
                        try
                        {
                            List<string> keys = new List<string>(response.Body.Result[i].FormData.Keys);
 
                            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<object>)response.Body.Result[i].FormData["employeeField_lo6w37hf"])[0].ToString().Replace("'","");
                            }
 
                            if (keys.Contains("employeeField_lo6w37hf_id"))
                            {
                                oItem.HEmployeeID = ((List<object>)response.Body.Result[i].FormData["employeeField_lo6w37hf_id"])[0].ToString().Replace("'", "");
                            }
                            
                            lsmain.Add(oItem);
                        }catch(Exception e)
                        {
                            continue;
                        }
                    }
 
 
 
                    startIndex = endIndex;
                    endIndex += size;
                    if (endIndex > IDList.Count)
                    {
                        endIndex = IDList.Count;
                    }
                }
 
 
                return true;
            }catch(Exception e)
            {
                msg = e.Message;
                return false;
            }
            
        }
        #endregion
 
        #region 数据同步
        public bool getData_FenCengShenHeQianDaoBiao(ref string msg)
        {
            //获取 分层审核表 实例ID列表
            string appType = "APP_MMBPP3IFGFBX3VQAIKYX";
            string systemToken = "TP866A81107FVI9LBFQRZ9953YWZ2GYR2W6OL1L";
            string userID = "1933673646699149";
            string formUuid = "FORM-IQ8666B17ZZE7NQSA01K3DUN78UI3J1Z2W6OLX";
            int pageNumber = 1;
            int pageSize = 100;
 
            //获取分层审核表的实例ID列表
            List<string> IDList = new List<string>();
            if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false)
            {
                return false;
            }
 
            //获取详细信息并附加到列表lsmain中
            List<YD_FenCengShenHeQianDaoBiao> lsmain = new List<YD_FenCengShenHeQianDaoBiao>();
            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) " +
                        "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) + "'" +
                        ")";
 
                    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<string> IDList, ref List<YD_XianChangBianHuaDianPingShenDan> lsmain, ref string msg, int size = 500)
        {
 
            try
            {
                int startIndex = 0;
                int endIndex = startIndex + size;
                if (endIndex > IDList.Count)
                {
                    endIndex = IDList.Count;
                }
 
                while (startIndex < endIndex && endIndex <= IDList.Count)
                {
                    List<string> IDList_temp = new List<string>();
                    for (int i = startIndex; i < endIndex; i++)
                    {
                        IDList_temp.Add(IDList[i]);
                    }
 
                    BatchGetFormDataByIdListResponse response = new BatchGetFormDataByIdListResponse();
                    if (getInstanceDetailListByInstanceIDList_YiDa(appType, systemToken, formUuid, userID, IDList_temp, ref response, ref msg) == false)
                    {
                        return false;
                    }
 
 
                    for (int i = 0; i < response.Body.Result.Count; i++)
                    {
                        try
                        {
                            List<string> keys = new List<string>(response.Body.Result[i].FormData.Keys);
 
                            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("'", "");
                            }
                            
                            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<string> IDList = new List<string>();
            if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false)
            {
                return false;
            }
 
            //获取详细信息并附加到列表lsmain中
            List<YD_XianChangBianHuaDianPingShenDan> lsmain = new List<YD_XianChangBianHuaDianPingShenDan>();
            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) " +
                        "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) + "'" +
                        ")";
 
                    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<string> IDList, ref List<YD_FenCengShenHeGuanLi> lsmain, ref string msg, int size = 500)
        {
 
            try
            {
                int startIndex = 0;
                int endIndex = startIndex + size;
                if (endIndex > IDList.Count)
                {
                    endIndex = IDList.Count;
                }
 
                while (startIndex < endIndex && endIndex <= IDList.Count)
                {
                    List<string> IDList_temp = new List<string>();
                    for (int i = startIndex; i < endIndex; i++)
                    {
                        IDList_temp.Add(IDList[i]);
                    }
 
                    BatchGetFormDataByIdListResponse response = new BatchGetFormDataByIdListResponse();
                    if (getInstanceDetailListByInstanceIDList_YiDa(appType, systemToken, formUuid, userID, IDList_temp, ref response, ref msg) == false)
                    {
                        return false;
                    }
 
                    for (int i = 0; i < response.Body.Result.Count; i++)
                    {
                        try
                        {
                            List<string> keys = new List<string>(response.Body.Result[i].FormData.Keys);
 
                            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<object>)response.Body.Result[i].FormData["employeeField_loz3zrdt"])[0].ToString().Replace("'", "");
                            }
 
                            if (keys.Contains("employeeField_loz3zrdt_id"))
                            {
                                oItem.HEmployeeID = ((List<object>)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<object>)response.Body.Result[i].FormData["employeeField_llogutfd_id"])[0].ToString().Replace("'", "");
                            }
                            if (keys.Contains("employeeField_llogutfd"))
                            {
                                oItem.HEmployee_Duty = ((List<object>)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("'", "");
                            }
 
                            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<string> IDList = new List<string>();
            if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false)
            {
                return false;
            }
 
            //获取详细信息并附加到列表lsmain中
            List<YD_FenCengShenHeGuanLi> lsmain = new List<YD_FenCengShenHeGuanLi>();
            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" +
                        ") " +
                        "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) + "'" +
 
                        ")";
 
                    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<string> IDList, ref List<YD_QRQCWenTiTiJiaoBiao> lsmain, ref string msg, int size = 500)
        {
 
            try
            {
                int startIndex = 0;
                int endIndex = startIndex + size;
                if (endIndex > IDList.Count)
                {
                    endIndex = IDList.Count;
                }
 
                while (startIndex < endIndex && endIndex <= IDList.Count)
                {
                    List<string> IDList_temp = new List<string>();
                    for (int i = startIndex; i < endIndex; i++)
                    {
                        IDList_temp.Add(IDList[i]);
                    }
 
                    BatchGetFormDataByIdListResponse response = new BatchGetFormDataByIdListResponse();
                    if (getInstanceDetailListByInstanceIDList_YiDa(appType, systemToken, formUuid, userID, IDList_temp, ref response, ref msg) == false)
                    {
                        return false;
                    }
 
                    
                    for (int i = 0; i < response.Body.Result.Count; i++)
                    {
                        try
                        {
                            List<string> keys_main = new List<string>(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("'", "");
                            }
 
                            
 
                            List<YD_QRQCWenTiTiJiaoBiaoSub1> sub1List = new List<YD_QRQCWenTiTiJiaoBiaoSub1>();
                            if (keys_main.Contains("tableField_lx4azand"))
                            {
                                foreach (Dictionary<string, object> obj in (List<object>)response.Body.Result[i].FormData["tableField_lx4azand"])
                                {
                                    List<string> keys_sub1 = new List<string>(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<YD_QRQCWenTiTiJiaoBiaoSub2> sub2List = new List<YD_QRQCWenTiTiJiaoBiaoSub2>();
                            if (keys_main.Contains("tableField_lx4azanj"))
                            {
                                foreach (Dictionary<string, object> obj in (List<object>)response.Body.Result[i].FormData["tableField_lx4azanj"])
                                {
                                    List<string> keys_sub2 = new List<string>(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<string> IDList = new List<string>();
            if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false)
            {
                return false;
            }
 
            //获取详细信息并附加到列表lsmain中
            List<YD_QRQCWenTiTiJiaoBiao> lsmain = new List<YD_QRQCWenTiTiJiaoBiao>();
            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)
                {
                    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) " +
                        "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) + "'" +
                        ")";
                    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<string> IDList, ref List<DD_HuaMingCe> 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<string> IDList_temp = new List<string>();
                    //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<string> fieldNameList = new List<string>();
                        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<string> IDList = new List<string>();
            if (getEmployeeIDList_DingDing(offset, size, ref IDList, ref msg) == false)
            {
                return false;
            }
 
            //获取详细信息并附加到列表lsmain中
            List<DD_HuaMingCe> lsmain = new List<DD_HuaMingCe>();
            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
        #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
 
    }
}