fs-danaus
2022-08-03 1937886b35d7610cf142e89b11fda29ccc49fa8b
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
package com.yc.open.deli.service.v2;
 
import com.yc.action.grid.GridUtils;
import com.yc.entity.DataSourceEntity;
import com.yc.exception.ApplicationException;
import com.yc.factory.FactoryBean;
import com.yc.open.deli.entity.*;
import com.yc.open.deli.service.PostDataBaseService;
import com.yc.open.init.Task;
import com.yc.service.BaseService;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
 
/**
 * 德立接口
 */
@Service
public class DeLiImplV2 extends BaseService implements DeLiIfc {
 
 
    @Override
    public List<T110203Entity> getCustomerList(String cltcode) {
        List<T110203Entity> results=null;
 
        return  results;
    }
 
    @Override
    public List<T170139Entity> getT170139List(String docCode,Task task) {
        List<T170139Entity> results=null;
        String sql=" set nocount on \n"
                + " declare @DefaultVndCode varchar(50), @mydocStatus int="+task.getCurrentDocStatus()+",@myDocCode varchar(50)="+GridUtils.prossSqlParm(docCode)+" \n"
                + " select top 1 @DefaultVndCode = DefaultVndCode from t110561 \n"
                + " if isnull(@DefaultVndCode,'') = '' \n"
                + " begin \n"
                + "    raiserror('请在 110561 功能号中维护【缺省供应商编号】',16,1) \n"
                + "    return \n"
                + " end \n" +
                " select  " +
                " b.docCode,--单号\n" +
                " b.docDate,--单据日期\n" +
                " b.refCode,--引用单号\n" +
                " b.cltCode,--客户编号\n" +
                " b.cltName,--客户名称\n" +
                " b.tel,--电话\n" +
                " b.propertyAddress,--送货地址\n" +
                " b.opportunity,--客户意向\n" +
                " b.description,--跟进情况\n" +
                " b.lostType,--跟踪状态\n" +
                " b.lostMemo,--流失原因\n" +
                " b.attachment, --附件 \n" +
                " a.cshopCode,a.cshopName ,a.cVenCode,a.cVenName," +
                " case when (select controltype from gField where formid=170139 and HeadFlag = 0 and fieldid='attachment')=9  then 1 else 3 end as attachmentType," +
                " b.hrname,b.docStatus, b.docStatusName,b.EnterName,b.PostDate "+
                " from t170139H b join t110606 a on a.ccCode=b.ccCode " +
                " where isnull(b.cccode,'') <> '' " +
                " and   b.DocStatus=@mydocStatus \n" +
                " and   b.DocCode=@myDocCode \n" +
                " and exists(select 1 from t120201h h join t120201d d  on h.doccode = d.doccode \n" +
                "            join t110560 t on t.ObjCode = @DefaultVndCode and d.matcode = t.matcode \n" +
                "            where b.cltcode = h.cltcode )\n" +
                " order by b.DocCode";
        try {
            List<Map<String,Object>> list= this.jdbcTemplate.queryForList(sql);
            if(list!=null&&list.size()>0) {
                results=new ArrayList<>();
                for (Map<String, Object> map : list) {
                    //处理附件
                    String attachment=GridUtils.prossRowSetDataType_String(map,"attachment");
                    if(attachment!=null&&!"".equals(attachment)){
                        attachment="uuid="+attachment+"&type="+GridUtils.prossRowSetDataType_String(map,"attachmentType");
                    }
 
                    results.add(new T170139Entity(
                            GridUtils.prossRowSetDataType_String(map,"docCode"),
                            GridUtils.prossRowSetDataType_Date(map,"docDate"),
                            GridUtils.prossRowSetDataType_String(map,"refCode"),
                            GridUtils.prossRowSetDataType_String(map,"cltCode"),
                            GridUtils.prossRowSetDataType_String(map,"cltName"),
                            GridUtils.prossRowSetDataType_String(map,"tel"),
                            GridUtils.prossRowSetDataType_String(map,"propertyAddress"),
                            GridUtils.prossRowSetDataType_String(map,"opportunity"),
                            GridUtils.prossRowSetDataType_String(map,"description"),
                            GridUtils.prossRowSetDataType_String(map,"lostType"),
                            GridUtils.prossRowSetDataType_String(map,"lostMemo"),
                            attachment,
                            GridUtils.prossRowSetDataType_Int(map,"docStatus"),
                            GridUtils.prossRowSetDataType_String(map,"docStatusName"),
                            GridUtils.prossRowSetDataType_String(map,"hrname"),
                            GridUtils.prossRowSetDataType_String(map,"cVenCode"),
                            GridUtils.prossRowSetDataType_String(map,"cVenName"),
                            GridUtils.prossRowSetDataType_String(map,"cshopCode"),
                            GridUtils.prossRowSetDataType_String(map,"cshopName"),
                            GridUtils.prossRowSetDataType_String(map,"EnterName"),
                            GridUtils.prossRowSetDataType_Date(map,"PostDate")
                    ));
                }
            }
        }catch(Exception e ) {
            if (e instanceof EmptyResultDataAccessException){
                return null ;
            }else {
                e.printStackTrace();
                this.doErrorLog(170139,e);
            }
        }
        return results;
    }
 
    /**
     *把推送时查询sql出错信息写到日志表110562
     * @param sql
     */
    private  void doErrorLog(int formid,Exception ex){
        PostDataBaseService postDataBaseService= (PostDataBaseService) FactoryBean.getBean("postDataBaseService");
        List<T110562Entity> list=new ArrayList<>();
        //一个功能号只生成一条运行时出错日志
         list.add(new T110562Entity(formid,"",0, RandomStringUtils.randomAlphanumeric(6),"","","","",0,0,0,"","","sql出错",0,0,ex.getMessage().replaceAll("'","''")));
        try {
            postDataBaseService.doLogBy110562(list);
 
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
    @Override
    public List<T640109Entity> getT640109(String docCode,Task task) {
        List<T640109Entity> results=null;
        String sql=" set nocount on \n"
                + "  declare @docCode varchar(20),@docDate datetime,@preSendDate datetime,@factdate datetime,@docType varchar(50),@mydocStatus int="+task.getCurrentDocStatus()+",@myDocCode varchar(50)="+GridUtils.prossSqlParm(docCode)+" \n" +
                "    ,@cltCode varchar(20),@cltName varchar(80),@meterName varchar(200),@tel varchar(50),@propertyAddress varchar(200),@sellerName varchar(50),\n" +
                "    @shopGuideName varchar(50),@shejiCode varchar(50),@shejiName varchar(50),@hDMemo varchar(400),@attachmentDate datetime,   \n" +
                "    @approvalMemo varchar(200),@approvalMemo2 varchar(200),@approvalMemo3 varchar(200),    \n" +
                "    @approvalMemo4 varchar(200),@docStatus int, @docStatusName varchar(50),@refCode varchar(20),@EnterName varchar(50),@cccode varchar(20), \n" +
                "    @cshopCode varchar(50),@cshopName varchar(50) ,@cVenCode varchar(50),@cVenName varchar(50) , \n" +
 
                "    @rowid varchar(20),@DocItem int, \n" +
                "    @ObjMatCode varchar(50),@ObjMatName varchar(80),@ObjSpecial varchar(80), \n" +
                "    @uom varchar(20),@digit money,@locationName varchar(200),@ItemMemo varchar(400),@refcodeitem varchar(50),@refrowid varchar(20),@PushStatus int  \n" +
                " declare @table table(docCode varchar(20),docDate datetime,preSendDate datetime,factdate datetime,docType varchar(50),          \n" +
                "    cltCode varchar(20),cltName varchar(80),meterName varchar(200),tel varchar(50),propertyAddress varchar(200),sellerName varchar(50),\n" +
                "    shopGuideName varchar(50),shejiCode varchar(50),shejiName varchar(50),hDMemo varchar(400),attachmentDate datetime,   \n" +
                "    approvalMemo varchar(200),approvalMemo2 varchar(200),approvalMemo3 varchar(200),    \n" +
                "    approvalMemo4 varchar(200),docStatus int, docStatusName varchar(50),refCode varchar(20),EnterName varchar(50),cccode varchar(20), \n" +
                "    cshopCode varchar(50),cshopName varchar(50) ,cVenCode varchar(50),cVenName varchar(50) , \n" +
 
                "    rowid varchar(20),DocItem int, \n" +
                "    matcode varchar(50),matname varchar(80),special varchar(80), \n" +
                "    uom varchar(20),digit money,locationName varchar(200),ItemMemo varchar(400),refcodeitem varchar(50),refrowid varchar(20),PushStatus int )\n" +
 
                " declare @ccname varchar(80),@errMsg varchar(500)\n" +
                " declare @myrowcount int,@myerror int\n" +
                " declare @DefaultVndCode varchar(50), @DefaultVndName varchar(80) ,@postdocstatus int,@formid int = 640109 \n" +
                " declare @MatCode varchar(50),@MatName varchar(120) ,@Special varchar(120) \n" +
 
                " select top 1 @DefaultVndCode = a.DefaultVndCode ,@DefaultVndName = b.vndName \n" +
                " from t110561 a left join t110302 b on a.DefaultVndCode = b.vndCode \n" +
                " if isnull(@DefaultVndCode,'') = '' \n" +
                " begin \n" +
                "   raiserror('请在 110561 功能号中维护【缺省供应商编号】',16,1) \n" +
                "    return \n" +
                " end \n" +
 
                " declare mycurDeli cursor for\n" +
                " select  b.docCode,b.docDate,b.preSendDate,b.factdate,b.docType,          \n" +
                "    b.cltCode,b.cltName,b.meterName,b.tel,b.propertyAddress,b.sellerName,\n" +
                "    b.shopGuideName,b.shejiCode,b.shejiName,b.hDMemo,b.attachmentDate,   \n" +
                "    b.approvalMemo,b.approvalMemo2,b.approvalMemo3,    \n" +
                "    b.approvalMemo4,b.docStatus, b.docStatusName,b.refCode,b.EnterName,b.cccode, \n" +
 
                "    c.rowid,c.DocItem,c.matcode,c.matname, \n" +
                "    c.uom,c.digit,c.locationName,c.ItemMemo,c.refcodeitem,c.refrowid,0 \n" +
 
                " from t640109H b --join t110606 a on a.ccCode=b.ccCode  \n" +
                " join t640109D c on b.doccode = c.doccode  \n" +
                " --join t110560 d on d.ObjCode = @DefaultVndCode and c.matcode = d.matcode  \n" +
                " --join t110203 e on b.cltcode = e.cltcode  \n" +
                "   join t110503 e on c.matcode = e.matcode \n" +
                " where  isnull(b.cccode,'') <> ''  \n" +
                " and b.docStatus=@mydocStatus \n"+
                " and b.docCode=@myDocCode \n"+
                " and isnull(e.vndcode,'') = @DefaultVndCode \n" +
                " order by b.DocCode\n" +
 
                " open mycurDeli \n" +
                " fetch next from mycurDeli into @docCode,@docDate,@preSendDate,@factdate,@docType,          \n" +
                "    @cltCode,@cltName,@meterName,@tel,@propertyAddress,@sellerName,\n" +
                "    @shopGuideName,@shejiCode,@shejiName,@hDMemo,@attachmentDate,   \n" +
                "    @approvalMemo,@approvalMemo2,@approvalMemo3,    \n" +
                "    @approvalMemo4,@docStatus, @docStatusName,@refCode,@EnterName,@cccode, \n" +
                "    @rowid,@DocItem,@matcode,@matname, \n" +
                "    @uom,@digit,@locationName,@ItemMemo,@refcodeitem,@refrowid,@PushStatus \n" +
                " while @@FETCH_STATUS = 0\n" +
                " begin\n" +
                "      --检查该客户是否存在\n" +
                "     if not exists(select 1 from t110203 where cltcode = @cltcode) \n" +
                "      begin  \n" +
                "         set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据【'+ isnull(@doccode,'') + '】客户编号【'+ isnull(@cltcode,'') + '】不存在,请在 110203 中新增该客户编号' \n" +
                "      end \n" +
 
                "      --检查与德立对照表是否存在或有重复设置照表\n" +
                "      select  @cvenCode = cvenCode,@cvenName = cvenName,@cshopCode=cshopCode,@cshopName=cshopName from t110606 where cccode = @CcCode and isnull(cccode,'') <> '' \n" +
                "      select @myrowcount = @@ROWCOUNT,@myerror = @@ERROR\n" +
                "      if @myrowcount = 0 or isnull(@cvenCode,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应代理商编号中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount = 0 or isnull(@cshopCode,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应门店编号中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount = 0 or isnull(@cvenName,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应代理商名称中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount = 0 or isnull(@cshopName,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应门店名称中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount <> 1  set @errMsg =case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end + '在 110606 功能号找到多条部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】对照关系,请去掉重复的,保留一条即可'\n" +
                "      --检查物料主数据 是否有对照表关系 \n" +
                "      select @ObjMatCode = ObjMatCode,@ObjMatName = ObjMatName ,@ObjSpecial = ObjSpecial\n" +
                "      from t110560 a where a.ObjCode =  @DefaultVndCode and a.matcode = @matcode \n" +
                "      select @myrowcount = @@ROWCOUNT,@myerror = @@ERROR\n" +
                "      if @myrowcount = 0 or isnull(@ObjMatCode,'') = '' \n" +
                "      begin\n" +
                "       set @errMsg =case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'物料编号【'+ isnull(@matcode,'') + '】【'+isnull(@matname,'') + '】在 110560 中没找到业务伙伴属于【'+isnull(@DefaultVndCode,'') + '】【'+isnull(@DefaultVndName,'')+'】对照关系,请在 110560 中预先维护好'  \n" +
                "      end \n" +
                "      if isnull(@errMsg,'') <> '' \n" +
                "      begin\n" +
                "         if exists(select 1 from t110562 where doccode = @docCode and rowid = @rowid )\n" +
                "         begin\n" +
                "             update a set PushStatus = 0,PushDate = getdate(),PushTimes = isnull(PushTimes,0) + 1,PushMsg = @errMsg\n" +
                "             from t110562 a \n" +
                "             where a.doccode = @docCode and a.rowid = @rowid \n" +
                "         end else \n" +
                "         begin\n" +
                "             insert into t110562(FormId,DocCode,DocItem,RowId,MatCode,MatName,Special,Uom,\n" +
                "             Digit,Price,TotalMoney,StCode,StName,ItemMemo,PushStatus,PushDate,PushTimes,PushMsg)\n" +
                "             values (@FormId,@DocCode,@DocItem,@RowId,@MatCode,@MatName,@Special,@Uom,\n" +
                "             @Digit,0,0,'','',@ItemMemo,0,getdate(),1,@errMsg)\n" +
                "         end \n" +
                "      end else \n" +
                "      begin\n" +
                "        insert into @table (docCode,docDate,preSendDate,factdate,docType,          \n" +
                "            cltCode,cltName,meterName,tel,propertyAddress,sellerName,\n" +
                "            shopGuideName,shejiCode,shejiName,hDMemo,attachmentDate,   \n" +
                "            approvalMemo,approvalMemo2,approvalMemo3,    \n" +
                "            approvalMemo4,docStatus, docStatusName,refCode,EnterName,cccode, \n" +
                "            cshopCode ,cshopName  ,cVenCode ,cVenName,\n" +
                "            rowid,DocItem,matcode ,matname ,special,\n" +
                "            uom,digit,locationName,ItemMemo,refcodeitem,refrowid,PushStatus  )\n" +
                "        values(@docCode,@docDate,@preSendDate,@factdate,@docType,          \n" +
                "            @cltCode,@cltName,@meterName,@tel,@propertyAddress,@sellerName,\n" +
                "            @shopGuideName,@shejiCode,@shejiName,@hDMemo,@attachmentDate,   \n" +
                "            @approvalMemo,@approvalMemo2,@approvalMemo3,    \n" +
                "            @approvalMemo4,@docStatus, @docStatusName,@refCode,@EnterName,@cccode, \n" +
                "            @cshopCode ,@cshopName  ,@cVenCode ,@cVenName,\n" +
 
                "            @rowid,@DocItem,@ObjMatCode ,@ObjMatName ,@ObjSpecial ,\n" +
                "            @uom,@digit,@locationName,@ItemMemo,@refcodeitem,@refrowid,@PushStatus )\n" +
 
                "      end \n" +
                "     fetch next from mycurDeli into @docCode,@docDate,@preSendDate,@factdate,@docType,          \n" +
                "        @cltCode,@cltName,@meterName,@tel,@propertyAddress,@sellerName,\n" +
                "        @shopGuideName,@shejiCode,@shejiName,@hDMemo,@attachmentDate,   \n" +
                "        @approvalMemo,@approvalMemo2,@approvalMemo3,    \n" +
                "        @approvalMemo4,@docStatus, @docStatusName,@refCode,@EnterName,@cccode, \n" +
                "        @rowid,@DocItem,@matcode,@matname, \n" +
                "        @uom,@digit,@locationName,@ItemMemo,@refcodeitem,@refrowid,@PushStatus \n" +
                " end \n" +
                " close mycurDeli\n" +
                " deallocate mycurDeli \n" +
                " select docCode,docDate,preSendDate,factdate,docType,          \n" +
                "            cltCode,cltName,meterName,tel,propertyAddress,sellerName,\n" +
                "            shopGuideName,shejiCode,shejiName,hDMemo,attachmentDate,   \n" +
                "            approvalMemo,approvalMemo2,approvalMemo3,    \n" +
                "            approvalMemo4,docStatus, docStatusName,refCode,EnterName,cccode, \n" +
                "            cshopCode ,cshopName  ,cVenCode ,cVenName,\n" +
                "            rowid,DocItem,matcode ,matname ,special,\n" +
                "            uom,digit,locationName,ItemMemo,refcodeitem,refrowid,PushStatus\n" +
                " from @table ";
 
 
        try {
            List<Map<String,Object>> list= this.jdbcTemplate.queryForList(sql);
            if(list!=null&&list.size()>0) {
                Set<Object> distinctDoccdeList = list.stream().map(x -> x.get("docCode")).collect(Collectors.toSet());//取出集合中不重复单号
                for (Object dist : distinctDoccdeList) {
                    List<T640109DetailEntity> detailEntities=new ArrayList<>();
                    T640109Entity t640109Entity = new T640109Entity();
                    boolean flag = false;//
                    List<Map<String,Object>> t640109List = list.stream().filter(x -> dist.equals(x.get("docCode"))).collect(Collectors.toList());
                    if(results==null){ results = new ArrayList<>();}
                    for(Map<String,Object> map : t640109List) {
                        if (!flag) {//表示第一次,则要取主表
                            t640109Entity.setCustomer(new T640109HeadEntity(
                                    GridUtils.prossRowSetDataType_String(map, "docCode"),
                                    GridUtils.prossRowSetDataType_Date(map, "docdate"),
                                    GridUtils.prossRowSetDataType_Date(map, "preSendDate"),
                                    GridUtils.prossRowSetDataType_Date(map, "factdate"),
                                    GridUtils.prossRowSetDataType_String(map, "docType"),
                                    GridUtils.prossRowSetDataType_String(map, "cltCode"),
                                    GridUtils.prossRowSetDataType_String(map, "cltName"),
                                    GridUtils.prossRowSetDataType_String(map, "meterName"),
                                    GridUtils.prossRowSetDataType_String(map, "tel"),
                                    GridUtils.prossRowSetDataType_String(map, "propertyAddress"),
                                    GridUtils.prossRowSetDataType_String(map, "sellerName"),
                                    GridUtils.prossRowSetDataType_String(map, "shopGuideName"),
                                    GridUtils.prossRowSetDataType_String(map, "shejiCode"),
                                    GridUtils.prossRowSetDataType_String(map, "shejiName"),
                                    GridUtils.prossRowSetDataType_String(map, "hDMemo"),
                                    GridUtils.prossRowSetDataType_Date(map, "attachmentDate"),
                                    GridUtils.prossRowSetDataType_String(map, "approvalMemo"),
                                    GridUtils.prossRowSetDataType_String(map, "approvalMemo2"),
                                    GridUtils.prossRowSetDataType_String(map, "approvalMemo3"),
                                    GridUtils.prossRowSetDataType_String(map, "approvalMemo4"),
                                    GridUtils.prossRowSetDataType_Int(map, "docStatus"),
                                    GridUtils.prossRowSetDataType_String(map, "docStatusName"),
                                    GridUtils.prossRowSetDataType_String(map, "refCode"),
                                    GridUtils.prossRowSetDataType_String(map,"cVenCode"),
                                    GridUtils.prossRowSetDataType_String(map,"cVenName"),
                                    GridUtils.prossRowSetDataType_String(map,"cshopCode"),
                                    GridUtils.prossRowSetDataType_String(map,"cshopName"),
                                    GridUtils.prossRowSetDataType_String(map,"cccode"),
                                    GridUtils.prossRowSetDataType_String(map,"EnterName")
 
                            ));
                        }
                        detailEntities.add(new T640109DetailEntity(
                                GridUtils.prossRowSetDataType_String(map, "matCode"),
                                GridUtils.prossRowSetDataType_String(map, "matName"),
                                GridUtils.prossRowSetDataType_String(map, "uom"),
                                GridUtils.prossRowSetDataType_Double(map, "digit"),
                                GridUtils.prossRowSetDataType_String(map, "ItemMemo"),
                                GridUtils.prossRowSetDataType_Int(map, "DocItem"),
                                GridUtils.prossRowSetDataType_String(map, "rowid"),
                                GridUtils.prossRowSetDataType_String(map, "DocCode"),
                                GridUtils.prossRowSetDataType_String(map, "locationName"),
                                GridUtils.prossRowSetDataType_String(map, "special"),
                                GridUtils.prossRowSetDataType_String(map, "refcodeitem"),
                                GridUtils.prossRowSetDataType_Int(map, "PushStatus"),
                                GridUtils.prossRowSetDataType_String(map, "refrowid")
 
                        ));
                        flag=true;
                    }
                    t640109Entity.setDetails(detailEntities);
                    results.add(t640109Entity);
 
                }
            }
        }catch(Exception e ) {
            if (e instanceof EmptyResultDataAccessException){
                return null ;
            }else {
                e.printStackTrace();
                this.doErrorLog(640109,e);
            }
        }
        return  results;
    }
 
    @Override
    public Agent get110606(String ccCode) {
        String sql="select cVenCode,cVenName,cshopCode,cshopName from t110606 where ccCode=?";
        Agent agent=null;
        try {
            Map<String,Object> map= this.jdbcTemplate.queryForMap(sql,ccCode);
            if(map!=null){
                agent=new Agent(
                        GridUtils.prossRowSetDataType_String(map,"cVenCode"),
                        GridUtils.prossRowSetDataType_String(map,"cVenName"),
                        GridUtils.prossRowSetDataType_String(map,"cshopCode"),
                        GridUtils.prossRowSetDataType_String(map,"cshopName")
                );
            }
        }catch(Exception e ) {
            if (e instanceof EmptyResultDataAccessException){
                return null ;
            }else {
                e.printStackTrace();
                this.doErrorLog(110606,e);
            }
        }
        return agent;
    }
 
    @Override
    public int updatePrimaryKey(String doccodes,String tableName) {
        Integer result = this.jdbcTemplate.queryForObject("update "+tableName+" set isPosted=1 where DocCode in ('"+doccodes+"') ; select @@rowcount",Integer.class);
        return result==null?0:result;
    }
 
    @Override
    public List<T110601Entity> getT110601List() {
        List<T110601Entity> results=null;
        String sql=" select Tel,Address ,fax, longitude, latitude, tel2, hrcode, hrname, generalHrcode, generalHrname, b.cshopCode,b.cshopName ,b.cVenCode,b.cVenName from t110601 a ,t110606 b where a.ccCode=b.ccCode and    ISNULL(a.isIndependentAccountAbility,0) = 1";
        try {
            List<Map<String,Object>> list= this.jdbcTemplate.queryForList(sql);
            if(list!=null&&list.size()>0){
                results=new ArrayList<>();
 
                for(Map<String,Object> map : list) {
 
                    results.add(new T110601Entity(
                                    GridUtils.prossRowSetDataType_String(map,"cshopCode"),
                                    GridUtils.prossRowSetDataType_String(map,"cshopName"),
                                    GridUtils.prossRowSetDataType_String(map,"Tel"),
                                    GridUtils.prossRowSetDataType_String(map,"Address"),
                                    GridUtils.prossRowSetDataType_String(map,"fax"),
                                    GridUtils.prossRowSetDataType_String(map,"longitude"),
                                    GridUtils.prossRowSetDataType_String(map,"latitude"),
                                    GridUtils.prossRowSetDataType_String(map,"tel2"),
                                    GridUtils.prossRowSetDataType_String(map,"hrcode"),
                                    GridUtils.prossRowSetDataType_String(map,"hrname"),
                                    GridUtils.prossRowSetDataType_String(map,"generalHrcode"),
                                    GridUtils.prossRowSetDataType_String(map,"generalHrname"),
                                    GridUtils.prossRowSetDataType_String(map,"cVenCode"),
                                    GridUtils.prossRowSetDataType_String(map,"cVenName")
                            )
                    );
                }
            }
        }catch(Exception e ) {
            if (e instanceof EmptyResultDataAccessException){
                return null ;
            }else {
                e.printStackTrace();
                this.doErrorLog(110601,e);
            }
        }
        return  results;
    }
 
    @Override
    public List<T120201Entity> getT120201List(String docCode,Task task) {
        List<T120201Entity> results=null;
        String sql=" set nocount on \n"+
                " declare @shouKuanAmount money,@docCode varchar(20),@preSendDate datetime,@docType varchar(50),\n" +
                "    @cltCode varchar(20),@cltName varchar(80),@linkMan varchar(50),@ccCode varchar(20),@ccName varchar(50),@hDMemo varchar(400), @tel varchar(50), \n" +
                "    @tel2 varchar(50),@propertyAddress varchar(200), @sellerName varchar(50), @shopGuideName varchar(50),@serviceName varchar(50), \n" +
                "    @dengjiname varchar(80), @referralsName varchar(80),@docStatus int, @docStatusName varchar(50),@docDate datetime,@mydocStatus int="+task.getCurrentDocStatus()+",@myDocCode varchar(50)="+GridUtils.prossSqlParm(docCode)+" \n" +
                "    ,@actname varchar(50),@refCode varchar(20),@cshopCode varchar(50),@cshopName varchar(50) ,@cVenCode varchar(50),@cVenName varchar(50),@EnterName varchar(50),  \n" +
                "    @rowid varchar(20),@DocItem int,@ObjMatCode varchar(50),@ObjMatName varchar(120) ,@ObjSpecial varchar(120) ,\n" +
                "    @uom varchar(20),@digit money,@price money,@totalmoney money,@stcode varchar(20),@stname varchar(50),@ItemMemo varchar(400), \n" +
                "    @overallcoding varchar(50),@locationName varchar(200), @brand varchar(50),@trademarkPrice money, \n" +
                "    @discount money, @cv2 varchar(80), @unsubscribeDoccode varchar(200), @subDocdate datetime , \n" +
                "    @cltdocdate datetime,@cltType varchar(50),@sourceInfo varchar(50),@clttel varchar(50),@clttel2 varchar(50),@cltpropertyAddress varchar(200), \n" +
                "    @cltenterName  varchar(50),@cltsellerName varchar(50),@cltHDNote  varchar(200),  \n" +
                "    @cltreferralsName varchar(50),@cltbrithday varchar(50) ,@cltdocStatus int, @cltdocStatusName varchar(50)\n" +
                " declare @errMsg varchar(500),  @myrowcount int,@myerror int,@formid int\n" +
                " declare @table table (shouKuanAmount money,docCode varchar(20),preSendDate datetime,docType varchar(50),\n" +
                "    cltCode varchar(20),cltName varchar(80),linkMan varchar(50),ccCode varchar(20),ccName varchar(50),hDMemo varchar(400), tel varchar(50), \n" +
                "    tel2 varchar(50),propertyAddress varchar(200), sellerName varchar(50), shopGuideName varchar(50),serviceName varchar(50), \n" +
                "    dengjiname varchar(80), referralsName varchar(80),docStatus int, docStatusName varchar(50),docDate datetime, \n" +
                "    actname varchar(50),refCode varchar(20),cshopCode varchar(50),cshopName varchar(50) ,cVenCode varchar(50),cVenName varchar(50),EnterName varchar(50),  \n" +
                "    rowid varchar(20),DocItem int,ObjMatCode varchar(50),ObjMatName varchar(120) ,ObjSpecial varchar(120) ,\n" +
                "    uom varchar(20),digit money,price money,totalmoney money,stcode varchar(20),stname varchar(50),ItemMemo varchar(400), \n" +
                "    overallcoding varchar(50),locationName varchar(200), brand varchar(50),trademarkPrice money, \n" +
                "    discount money, cv2 varchar(80), unsubscribeDoccode varchar(200), subDocdate datetime , \n" +
                "    cltdocdate datetime,cltType varchar(50),sourceInfo varchar(50),clttel varchar(50),clttel2 varchar(50),cltpropertyAddress varchar(200), \n" +
                "    cltenterName  varchar(50),cltsellerName varchar(50),cltHDNote  varchar(200),  \n" +
                "    cltreferralsName varchar(50),cltbrithday varchar(50) ,cltdocStatus int, cltdocStatusName varchar(50) )\n" +
                " declare @DefaultVndCode varchar(50), @DefaultVndName varchar(80) ,@postdocstatus int\n" +
                " declare @MatCode varchar(50),@MatName varchar(120) ,@Special varchar(120) \n" +
 
                " select top 1 @DefaultVndCode = a.DefaultVndCode ,@DefaultVndName = b.vndName \n" +
                " from t110561 a left join t110302 b on a.DefaultVndCode = b.vndCode \n" +
                " if isnull(@DefaultVndCode,'') = '' \n" +
                " begin \n" +
                "   raiserror('请在 110561 功能号中维护【缺省供应商编号】',16,1) \n" +
                "    return \n" +
                " end \n" +
 
                " declare mycurDeli cursor for\n" +
                " select b.formid,b.shouKuanAmount,b.docCode,b.preSendDate,b.docType,\n" +
                "    b.cltCode,b.linkMan,b.ccCode,b.ccName,b.hDMemo, b.tel, \n" +
                "    b.tel2, b.propertyAddress, b.sellerName, b.shopGuideName, b.serviceName, \n" +
                "    b.dengjiname, b.referralsName,b.docStatus, b.docStatusName,b.docDate, \n" +
                "    b.actname,b.refCode, a.cshopCode,a.cshopName ,a.cVenCode,a.cVenName,b.EnterName,  \n" +
 
                "    c.rowid,c.DocItem,c.MatCode , c.MatName,c.special,\n" +
                "    c.uom,c.digit,c.price,c.totalmoney,c.stcode,c.stname,c.ItemMemo, \n" +
                "    c.overallcoding,c.locationName, c.brand, c.trademarkPrice, \n" +
                "    c.discount, c.cv2, c.unsubscribeDoccode, c.subDocdate, \n" +
 
                "   e.cltname,\n" +
                "   e.docdate as cltdocdate,--登记日期          \n" +
                "     e.cltType,--客户类型         \n" +
                "     e.sourceInfo,--客户来源     \n" +
                "     e.tel as clttel,--客户电话             \n" +
                "     e.tel2 as clttel2,--联系人电话          \n" +
                "     e.propertyAddress as cltpropertyAddress,--送货地址   \n" +
                "     e.enterName as cltenterName,--登记人        \n" +
                "     e.sellerName as cltsellerName,--业务员          \n" +
                "     e.hDnote as cltHDNote,--备注              \n" +
                "     e.referralsName as cltreferralsName,--介绍人         \n" +
                "     e.cltbrithday as cltbrithday,\n" +
                "     e.docStatus as cltdocStatus, e.docStatusName as cltdocStatusName \n" +
                " from t120201H b join t110606 a on a.ccCode=b.ccCode \n" +
                " join t120201D c on b.doccode = c.doccode \n" +
                " join t110503 d on c.matcode = d.matcode \n" +
                " join t110203 e on b.cltcode = e.cltcode \n" +
                " where isnull(b.cccode,'') <> '' \n" +
                " and b.docStatus=@mydocStatus \n"+
                " and b.docCode=@myDocCode \n"+
                " and isnull(d.vndcode,'') = @DefaultVndCode  \n" +
                " order by b.DocCode\n" +
                " open mycurDeli \n" + 
                " fetch next from mycurDeli into @formid,@shouKuanAmount,@docCode,@preSendDate,@docType,\n" +
                "    @cltCode,@linkMan,@ccCode,@ccName,@hDMemo, @tel, \n" +
                "    @tel2, @propertyAddress,@sellerName, @shopGuideName,@serviceName, \n" +
                "    @dengjiname, @referralsName,@docStatus, @docStatusName,@docDate, \n" +
                "    @actname,@refCode,@cshopCode ,@cshopName,@cVenCode,@cVenName, @EnterName,@rowid,@DocItem,@MatCode , @MatName,@special,\n" +
                "    @uom,@digit,@price,@totalmoney,@stcode,@stname,@ItemMemo, \n" +
                "    @overallcoding,@locationName, @brand, @trademarkPrice, \n" +
                "    @discount, @cv2, @unsubscribeDoccode, @subDocdate, \n" +
 
                "   @cltname,@cltdocdate,@cltType,@sourceInfo,@clttel,@clttel2,\n" +
                "   @cltpropertyAddress,@cltenterName,@cltsellerName,@cltHDNote,\n" +
                "   @cltreferralsName,@cltbrithday,@cltdocStatus,@cltdocStatusName \n" +
                " while @@FETCH_STATUS = 0\n" +
                " begin\n" +
                "    --检查该客户是否存在\n" +
                "    select @cltname = a.cltname ,@cltdocdate = a.docdate  ,@cltType = a.cltType,@sourceInfo = a.sourceInfo,\n" +
                "        @clttel = a.tel ,@clttel2 = a.tel2 ,@cltpropertyAddress = a.propertyAddress , \n" +
                "        @cltenterName = a.enterName,@cltsellerName = a.sellerName ,@cltHDNote = a.hDnote ,  \n" +
                "        @cltreferralsName = a.referralsName ,@cltbrithday = a.cltbrithday ,\n" +
                "        @cltdocStatus = a.docStatus  , @cltdocStatusName = a.docStatusName \n" +
                "    from t110203 a  where cltcode = @cltcode\n" +
                "    select @myrowcount = @@ROWCOUNT,@myerror = @@ERROR\n" +
                "    if @myrowcount = 0 \n" +
                "    begin  \n" +
                "        set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据【'+ isnull(@doccode,'') + '】客户编号【'+ isnull(@cltcode,'') + '】不存在,请在 110203 中新增该客户编号' \n" +
                "    end  \n" +
                "    if isnull(@cltName,'')='' " +
                " begin \n" +
                "   set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'请在 110203 功能号中维护【客户名称】' \n" +
 
                " end \n" +
                "    if isnull(@clttel,'')='' and isnull(@clttel2,'')='' " +
                " begin \n" +
                "   set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'请在 110203 功能号中维护【客户手机号】'\n" +
                " end \n" +
                "    if isnull(@cltpropertyAddress,'')=''  " +
                " begin \n" +
                "   set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'请在 110203 功能号中维护【客户地址】' \n" +
                " end \n" +
 
                "      --检查与德立对照表是否存在或有重复设置照表\n" +
                "      select  @cvenCode = cvenCode,@cvenName = cvenName,@cshopCode=cshopCode,@cshopName=cshopName from t110606 where cccode = @CcCode and isnull(cccode,'') <> '' \n" +
                "      select @myrowcount = @@ROWCOUNT,@myerror = @@ERROR\n" +
                "      if @myrowcount = 0 or isnull(@cvenCode,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应代理商编号中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount = 0 or isnull(@cshopCode,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应门店编号中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount = 0 or isnull(@cvenName,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应代理商名称中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount = 0 or isnull(@cshopName,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应门店名称中不存在,请在 110606 功能号维护对照关系' \n" +
 
                "      if @myrowcount <> 1  set @errMsg =case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end + '在 110606 功能号找到多条部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】对照关系,请去掉重复的,保留一条即可'\n" +
                "      --检查物料主数据 是否有对照表关系 \n" +
                "      select @ObjMatCode = ObjMatCode,@ObjMatName = ObjMatName ,@ObjSpecial = ObjSpecial\n" +
                "      from t110560 a where a.ObjCode =  @DefaultVndCode and a.matcode = @matcode \n" +
                "      select @myrowcount = @@ROWCOUNT,@myerror = @@ERROR\n" +
                "      if @myrowcount = 0 or isnull(@ObjMatCode,'') = '' \n" +
                "      begin\n" +
                "       set @errMsg =case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'物料编号【'+ isnull(@matcode,'') + '】【'+isnull(@matname,'') + '】在 110560 中没找到业务伙伴属于【'+isnull(@DefaultVndCode,'') + '】【'+isnull(@DefaultVndName,'')+'】对照关系,请在 110560 中预先维护好'  \n" +
                "      end \n" +
                "      if isnull(@errMsg,'') <> '' \n" +
                "      begin\n" +
                "         if exists(select 1 from t110562 where doccode = @docCode and rowid = @rowid )\n" +
                "         begin\n" +
                "             update a set PushStatus = 0,PushDate = getdate(),PushTimes = isnull(PushTimes,0) + 1,PushMsg = @errMsg\n" +
                "             from t110562 a \n" +
                "             where a.doccode = @docCode and a.rowid = @rowid \n" +
                "         end else \n" +
                "         begin\n" +
                "             insert into t110562(FormId,DocCode,DocItem,RowId,MatCode,MatName,Special,Uom,\n" +
                "             Digit,Price,TotalMoney,StCode,StName,ItemMemo,PushStatus,PushDate,PushTimes,PushMsg)\n" +
                "             values (@FormId,@DocCode,@DocItem,@RowId,@MatCode,@MatName,@Special,@Uom,\n" +
                "             @Digit,@Price,@TotalMoney,@StCode,@StName,@ItemMemo,0,getdate(),1,@errMsg)\n" +
                "         end \n" +
                "      end else \n" +
                "      begin\n" +
                "        insert into @table (shouKuanAmount,docCode,preSendDate,docType,\n" +
                "            cltCode,linkMan,ccCode,ccName,hDMemo, tel, \n" +
                "            tel2, propertyAddress,sellerName, shopGuideName,serviceName, \n" +
                "            dengjiname, referralsName,docStatus, docStatusName,docDate, \n" +
                "            actname,refCode,cshopCode ,cshopName,cVenCode,cVenName, EnterName,\n" +
                "            rowid,DocItem,ObjMatCode,ObjMatName,ObjSpecial ,\n" +
                "            uom,digit,price,totalmoney,stcode,stname,ItemMemo, \n" +
                "            overallcoding,locationName, brand, trademarkPrice, \n" +
                "            discount, cv2, unsubscribeDoccode, subDocdate, " +
                "            cltname,cltdocdate,cltType,sourceInfo,clttel,clttel2,\n" +
                "             cltpropertyAddress,cltenterName,cltsellerName,cltHDNote,\n" +
                "            cltreferralsName,cltbrithday,cltdocStatus,cltdocStatusName \n" +
                ")\n" +
                "        values (@shouKuanAmount,@docCode,@preSendDate,@docType,\n" +
                "            @cltCode,@linkMan,@ccCode,@ccName,@hDMemo, @tel, \n" +
                "            @tel2, @propertyAddress,@sellerName, @shopGuideName,@serviceName, \n" +
                "            @dengjiname, @referralsName,@docStatus, @docStatusName,@docDate, \n" +
                "            @actname,@refCode, @cshopCode ,@cshopName,@cVenCode,@cVenName,@EnterName,\n" +
                "            @rowid,@DocItem,@ObjMatCode,@ObjMatName,@ObjSpecial ,\n" +
                "            @uom,@digit,@price,@totalmoney,@stcode,@stname,@ItemMemo, \n" +
                "            @overallcoding,@locationName, @brand, @trademarkPrice, \n" +
                "            @discount, @cv2, @unsubscribeDoccode, @subDocdate," +
                "            @cltname,@cltdocdate,@cltType,@sourceInfo,@clttel,@clttel2,\n" +
                "            @cltpropertyAddress,@cltenterName,@cltsellerName,@cltHDNote,\n" +
                "            @cltreferralsName,@cltbrithday,@cltdocStatus,@cltdocStatusName \n" +
                ")\n" +
                "      end \n" +
                "      fetch next from mycurDeli into @formid,@shouKuanAmount,@docCode,@preSendDate,@docType,\n" +
                "        @cltCode,@linkMan,@ccCode,@ccName,@hDMemo, @tel, \n" +
                "        @tel2, @propertyAddress,@sellerName, @shopGuideName,@serviceName, \n" +
                "        @dengjiname, @referralsName,@docStatus, @docStatusName,@docDate, \n" +
                "        @actname,@refCode,@cshopCode ,@cshopName,@cVenCode,@cVenName, @EnterName,@rowid,@DocItem,@MatCode , @MatName,@special,\n" +
                "        @uom,@digit,@price,@totalmoney,@stcode,@stname,@ItemMemo, \n" +
                "        @overallcoding,@locationName, @brand, @trademarkPrice, \n" +
                "        @discount, @cv2, @unsubscribeDoccode, @subDocdate,\n" +
                "        @cltname,@cltdocdate,@cltType,@sourceInfo,@clttel,@clttel2,\n" +
                "        @cltpropertyAddress,@cltenterName,@cltsellerName,@cltHDNote,\n" +
                "        @cltreferralsName,@cltbrithday,@cltdocStatus,@cltdocStatusName \n" +
                " end \n" +
                " close mycurDeli\n" +
                " deallocate mycurDeli \n" +
                " select shouKuanAmount,docCode,preSendDate,docType,\n" +
                "    cltCode,linkMan,ccCode,ccName,hDMemo, tel, \n" +
                "    tel2, propertyAddress,sellerName, shopGuideName,serviceName, \n" +
                "    dengjiname, referralsName,docStatus, docStatusName,docDate, \n" +
                "    actname,refCode,cshopCode ,cshopName,cVenCode,cVenName, EnterName,\n" +
                "    rowid,DocItem,ObjMatCode as matcode,ObjMatName as matname,ObjSpecial as special ,\n" +
                "    uom,digit,price,totalmoney,stcode,stname,ItemMemo, \n" +
                "    overallcoding,locationName, brand, trademarkPrice, \n" +
                "    discount, cv2, unsubscribeDoccode, subDocdate,\n" +
                "    cltname,cltdocdate,cltType,sourceInfo,clttel,clttel2,\n" +
                "    cltpropertyAddress,cltenterName,cltsellerName,cltHDNote,\n" +
                "    cltreferralsName,cltbrithday,cltdocStatus,cltdocStatusName \n" +
                " from @table " ;
 
 
 
        try {
            List<Map<String,Object>> list= this.jdbcTemplate.queryForList(sql);
            if(list!=null&&list.size()>0) {
                results=new ArrayList<>();
                Set<Object> distinctDoccdeList = list.stream().map(x -> x.get("docCode")).collect(Collectors.toSet());//取出集合中不重复单号
                for (Object dist : distinctDoccdeList) {
                    List<Map<String,Object>> t120201List = list.stream().filter(x -> dist.equals(x.get("docCode"))).collect(Collectors.toList());
                    boolean flag=false ;//
                    T120201Entity t120201Entity = new T120201Entity();
                    List<T120201DetailEntity> detailEntityList = new ArrayList<>();
                    for (Map<String,Object> map : t120201List) {
                        if (!flag) {//表示第一次,则要取主表和客户信息
                            t120201Entity.setHead(new T120201HeadEntity(
                                    GridUtils.prossRowSetDataType_String(map, "docCode"),
                                    GridUtils.prossRowSetDataType_Date(map, "preSendDate"),
                                    GridUtils.prossRowSetDataType_String(map, "docType"),
                                    GridUtils.prossRowSetDataType_String(map, "cltCode"),
                                    GridUtils.prossRowSetDataType_String(map, "cltName"),
                                    GridUtils.prossRowSetDataType_String(map, "linkMan"),
                                    GridUtils.prossRowSetDataType_String(map, "cshopCode"),
                                    GridUtils.prossRowSetDataType_String(map, "cshopName"),
                                    GridUtils.prossRowSetDataType_String(map, "hDMemo"),
                                    GridUtils.prossRowSetDataType_Double(map, "shouKuanAmount"),
                                    GridUtils.prossRowSetDataType_String(map, "tel"),
                                    GridUtils.prossRowSetDataType_String(map, "tel2"),
                                    GridUtils.prossRowSetDataType_String(map, "propertyAddress"),
                                    GridUtils.prossRowSetDataType_String(map, "sellerName"),
                                    GridUtils.prossRowSetDataType_String(map, "shopGuideName"),
                                    GridUtils.prossRowSetDataType_String(map, "serviceName"),
                                    GridUtils.prossRowSetDataType_String(map, "dengjiname"),
                                    GridUtils.prossRowSetDataType_String(map, "referralsName"),
                                    GridUtils.prossRowSetDataType_Int(map, "docStatus"),
                                    GridUtils.prossRowSetDataType_String(map, "docStatusName"),
                                    GridUtils.prossRowSetDataType_Date(map, "docDate"),
                                    GridUtils.prossRowSetDataType_String(map, "actname"),
                                    GridUtils.prossRowSetDataType_String(map, "refCode"),
                                    GridUtils.prossRowSetDataType_String(map, "cVenCode"),
                                    GridUtils.prossRowSetDataType_String(map, "cVenName"),
                                    GridUtils.prossRowSetDataType_String(map, "enterName")
                            ));
                            //客户信息
                            t120201Entity.setCustomer(new T110203Entity(
                                    GridUtils.prossRowSetDataType_String(map, "cltCode"),
                                    GridUtils.prossRowSetDataType_String(map, "cltName"),
                                    GridUtils.prossRowSetDataType_Date(map, "cltdocdate"),
                                    GridUtils.prossRowSetDataType_String(map, "cltType"),
                                    GridUtils.prossRowSetDataType_String(map, "sourceInfo"),
                                    GridUtils.prossRowSetDataType_String(map, "clttel"),
                                    GridUtils.prossRowSetDataType_String(map, "clttel2"),
                                    GridUtils.prossRowSetDataType_String(map, "cshopCode"),
                                    GridUtils.prossRowSetDataType_String(map, "cshopName"),
                                    GridUtils.prossRowSetDataType_String(map, "cltpropertyAddress"),
                                    GridUtils.prossRowSetDataType_String(map, "cltenterName"),
                                    GridUtils.prossRowSetDataType_String(map, "cltsellerName"),
                                    GridUtils.prossRowSetDataType_String(map, "cltHDNote"),
                                    GridUtils.prossRowSetDataType_String(map, "cltreferralsName"),
                                    GridUtils.prossRowSetDataType_String(map, "cltbrithday"),
                                    GridUtils.prossRowSetDataType_Int(map, "cltdocStatus"),
                                    GridUtils.prossRowSetDataType_String(map, "cltdocStatusName"),
                                    GridUtils.prossRowSetDataType_String(map, "cVenCode"),
                                    GridUtils.prossRowSetDataType_String(map, "cVenName"),null
                            ));
                        }
                        //取明细表
                        detailEntityList.add(new T120201DetailEntity(
                                GridUtils.prossRowSetDataType_String(map, "matCode"),
                                GridUtils.prossRowSetDataType_String(map, "matName"),
                                GridUtils.prossRowSetDataType_String(map, "uom"),
                                GridUtils.prossRowSetDataType_Double(map, "digit"),
                                GridUtils.prossRowSetDataType_Double(map, "price"),
                                GridUtils.prossRowSetDataType_Double(map, "totalmoney"),
                                GridUtils.prossRowSetDataType_String(map, "stcode"),
                                GridUtils.prossRowSetDataType_String(map, "stname"),
                                GridUtils.prossRowSetDataType_String(map, "ItemMemo"),
                                GridUtils.prossRowSetDataType_Int(map, "DocItem"),
                                GridUtils.prossRowSetDataType_String(map, "rowid"),
                                GridUtils.prossRowSetDataType_String(map, "docCode"),
                                GridUtils.prossRowSetDataType_String(map, "overallcoding"),
                                GridUtils.prossRowSetDataType_String(map, "locationName"),
                                GridUtils.prossRowSetDataType_String(map, "brand"),
                                GridUtils.prossRowSetDataType_Double(map, "trademarkPrice"),
                                GridUtils.prossRowSetDataType_Double(map, "discount"),
                                GridUtils.prossRowSetDataType_String(map, "cv2"),
                                GridUtils.prossRowSetDataType_String(map, "unsubscribeDoccode"),
                                GridUtils.prossRowSetDataType_Date(map, "subDocdate"),
                                GridUtils.prossRowSetDataType_String(map, "special")
                        ));
                        flag=true;
                    }
                    t120201Entity.setOrders(detailEntityList);
                    results.add(t120201Entity);
                }
            }
        }catch(Exception e) {
            if (e instanceof EmptyResultDataAccessException){
                return null ;
            }else {
                e.printStackTrace();
                this.doErrorLog(120201,e);
            }
        }
        return  results;
    }
    @Override
    public CanelEntity getCanelEntityByTableName(String hdtable,String dttable,String doccode,int formid) {
 
        String hsql="";
        if(formid==170139) {
            hsql = "  set nocount on " +
                    "    select distinct b.docCode,b.docType,a.cvenCode, a.cshopCode,b.refcode " +
                    " from " + hdtable + " b join t110606 a on a.ccCode=b.ccCode " +
                    " where isnull(b.cccode,'') <> '' and b.pushStatus=1 and b.DocCode=?";
        }else{
            hsql = "  set nocount on " +
                    "    select  distinct b.docCode,b.docType,a.cvenCode, a.cshopCode,b.refcode " +
                    " from " + hdtable + " b join t110606 a on a.ccCode=b.ccCode " +
                    " join "+dttable+" c on b.doccode = c.doccode " +
                    " where isnull(b.cccode,'') <> '' and c.pushStatus=1 and b.DocCode=?";
        }
        try {
            Map<String,Object> map= this.jdbcTemplate.queryForMap(hsql,doccode);
            CanelEntity canelEntity=new CanelEntity(
                                                    GridUtils.prossRowSetDataType_String(map,"docCode"),
                                                    GridUtils.prossRowSetDataType_String(map,"docType"),
                                                    GridUtils.prossRowSetDataType_String(map,"cvenCode"),
                                                    GridUtils.prossRowSetDataType_String(map,"cshopCode"),
                                                    GridUtils.prossRowSetDataType_String(map,"refcode")
                                                    );
 
            return  canelEntity;
        }catch(DataAccessException e ) {
            if (e instanceof EmptyResultDataAccessException){
                return null ;
            }else {
                e.printStackTrace();
                throw e;
            }
        }
    }
    @Override
    public List<T130301Entity> getT130301List(String docCode,Task task) {
        List<T130301Entity> results=null;
        String hsql="  set nocount on " +
                "  declare @DefaultVndCode varchar(50),@DefaultVndName varchar(80) ,@postdocstatus int \n" +
                "  declare @table table(docCode varchar(20),docDate datetime,docType varchar(50) , \n" +
                "  cvenCode varchar(50),cvenName varchar(80),factoryNumber varchar(50),cltCode varchar(20),\n" +
                "  cltName varchar(200),plateNO varchar(50), \n" +
                "  plateTel varchar(50),cccode varchar(50),ccname varchar(50),buyerCode varchar(20),buyerName varchar(50), \n" +
                "  hDMemo varchar(400),sumtotalmoney2 money,transCosts money,reduceMoney money,receivMoney money, \n" +
                "  docStatus int,docStatusName varchar(50),refCode varchar(20),EnterName varchar(50),rowid varchar(20), \n" +
                "  DocItem int,matCode varchar(50),matName varchar(80),special varchar(80),uom varchar(20),digit float, \n" +
                "  stcode varchar(20),stname varchar(30),ItemMemo varchar(400),soDocCode varchar(20),canceldigit money, \n" +
                "  propertyAddress varchar(200),brand varchar(20),cv2 varchar(80),trademarkPrice money, \n" +
                "  price float,totalmoney money,packingQuantity varchar(100),weight money,totalWeight money, \n" +
                "  discount money,unsubscribeDoccode varchar(20),sORowid varchar(20),errMsg varchar(500) )  \n" +
                "  declare @docCode varchar(20),@docDate datetime,@docType varchar(50) , @mydocStatus int="+task.getCurrentDocStatus()+",@myDocCode varchar(50)="+GridUtils.prossSqlParm(docCode)+" \n" +
                "  ,@cvenCode varchar(50),@cvenName varchar(80),@factoryNumber varchar(50),@cltCode varchar(20),\n" +
                "  @cltName varchar(200),@plateNO varchar(50), \n" +
                "  @plateTel varchar(50),@cccode varchar(50),@ccname varchar(50),@buyerCode varchar(20),@buyerName varchar(50), \n" +
                "  @hDMemo varchar(400),@sumtotalmoney2 money,@transCosts money,@reduceMoney money,@receivMoney money, \n" +
                "  @docStatus int,@docStatusName varchar(50),@refCode varchar(20),@EnterName varchar(50),@rowid varchar(20), \n" +
                "  @DocItem int,@matCode varchar(50),@matName varchar(80),@special varchar(80),@uom varchar(20),@digit float, \n" +
                "  @stcode varchar(20),@stname varchar(30),@ItemMemo varchar(400),@soDocCode varchar(20),@canceldigit money, \n" +
                "  @propertyAddress varchar(200),@brand varchar(20),@cv2 varchar(80),@trademarkPrice money, \n" +
                "  @price float,@totalmoney money,@packingQuantity varchar(100),@weight money,@totalWeight money, \n" +
                "  @discount money,@unsubscribeDoccode varchar(20),@soRowid varchar(20) ,@soCcCode varchar(20),@soCcName varchar(50)    \n" +
                " declare @ObjMatCode varchar(50),@ObjMatName varchar(120) ,@ObjSpecial varchar(120) ,@FormId int = 130301,@cshopCode varchar(80),@cshopName varchar(80) \n" +
                " select top 1 @DefaultVndCode = a.DefaultVndCode ,@DefaultVndName = b.vndName \n" +
                " from t110561 a left join t110302 b on a.DefaultVndCode = b.vndCode \n" +
                " if isnull(@DefaultVndCode,'') = '' \n" +
                " begin \n" +
                "    raiserror('请在 110561 功能号中维护【缺省供应商编号】',16,1) \n" +
                "    return \n" +
                "  end \n" +
                " select @postdocstatus = postdocstatus from gform where formid = @FormId \n" +
                " declare @errMsg varchar(2000) = '',@myrowcount int,@myerror int\n" +
                " declare mycurDeli cursor for\n" +
                " select a.docCode,a.docDate,a.docType,a.factoryNumber,\n" +
                "  a.plateNO, a.plateTel, a.cccode, d.ccname, a.buyerCode, \n" +
                "  a.buyerName, a.hDMemo, a.sumtotalmoney2, a.transCosts, a.reduceMoney, a.receivMoney,\n" +
                "  a.docStatus, a.docStatusName,a.refCode,a.EnterName,b.MatCode,b.MatName,b.rowid ,b.SODoccode,b.SOrowid\n" +
                " from t130301H a join t130301D b on a.DocCode  = b.DocCode\n" +
                " left join t110601 d on a.cccode = d.cccode\n" +
                " join t110503 e on b.matcode = e.matcode " +
                " where a.vndCode = @DefaultVndCode   \n" +
                " and   a.DocStatus=@mydocStatus \n" +
                " and   a.DocCode=@myDocCode \n" +
                " and isnull(e.vndcode,'') = @DefaultVndCode \n" +
                " order by a.doccode asc,b.DocItem asc \n" +
                " open mycurDeli \n" +
                " fetch next from mycurDeli into @docCode,@docDate,@docType,@factoryNumber,\n" +
                "  @plateNO, @plateTel, @cccode, @ccname, @buyerCode, \n" +
                "  @buyerName, @hDMemo, @sumtotalmoney2, @transCosts, @reduceMoney, @receivMoney,\n" +
                "  @docStatus, @docStatusName,@refCode,@EnterName,@MatCode,@MatName,@RowId,@soDocCode,@soRowId\n" +
                " while @@FETCH_STATUS = 0 \n" +
                " begin\n" +
                "  select @errMsg = '',@cvenCode = '',@cvenName='',@ObjMatCode='',@ObjMatName = '' ,@ObjSpecial=''\n" +
                "  if isnull(@soDocCode,'') = '' set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'【soDocCode】字段值为空,自动推送的采购订单必须引用销售订单行记录'\n" +
                "  --检查销售订单是否存在 \n" +
                "  select @soCcCode = a.cccode,@soCcName = b.ccname ,@cltCode = a.cltcode ,@cltName = a.CltName \n" +
                "  from t120201h a  left join t110601 b on a.ccCode = b.ccCode\n" +
                "  where a.doccode = @soDocCode \n" +
                "  select @myrowcount = @@ROWCOUNT,@myerror = @@ERROR\n" +
                "  if @myrowcount = 0 set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end + '引用的销售订单【单号:'+isnull(@soDocCode,'') + '】不存在,【rowid: + ' + isnull(@soRowid,'') + '】'\n" +
                "  if isnull(@soCcCode,'') = '' set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end + '当前单据【'+ isnull(@doccode,'')+ '】引用的销售订单【'+ isnull(@soDocCode,'') + '】部门编号不能为空'\n" +
                "  if isnull(@soCcName,'') = ''  set @errMsg =case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end + '当前单据【'+ isnull(@doccode,'') + '】引用的销售订单【'+ isnull(@soDocCode,'') + '】部门参数【'+ isnull(@soCcCode,'') + '】不存在(可能名称为空值),请在 110601 中维护该部门编号及其名称'\n" +
                "  --检查该客户是否存在\n" +
                "  if not exists(select 1 from t110203 where cltcode = @cltcode) \n" +
                "  begin  \n" +
                " set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据【'+ isnull(@doccode,'') + '】客户编号【'+ isnull(@cltcode,'') + '】不存在,请在 110203 中新增该客户编号' \n" +
                "  end  \n" +
 
                "      --检查与德立对照表是否存在或有重复设置照表\n" +
                "      select  @cvenCode = cvenCode,@cvenName = cvenName,@cshopCode=cshopCode,@cshopName=cshopName from t110606 where cccode = @CcCode and isnull(cccode,'') <> '' \n" +
                "      select @myrowcount = @@ROWCOUNT,@myerror = @@ERROR\n" +
                "      if @myrowcount = 0 or isnull(@cvenCode,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应代理商编号中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount = 0 or isnull(@cshopCode,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应门店编号中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount = 0 or isnull(@cvenName,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应代理商名称中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount = 0 or isnull(@cshopName,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应门店名称中不存在,请在 110606 功能号维护对照关系' \n" +
 
                "  if @myrowcount <> 1  set @errMsg =case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end + '在 110606 功能号找到多条部门【'+isnull(@soCcCode,'') + '】【'+ isnull(@soCcName,'') + '】对照关系,请去掉重复的,保留一条即可'\n" +
                "  --检查物料主数据 是否有对照表关系 \n" +
                "  select @ObjMatCode = ObjMatCode,@ObjMatName = ObjMatName ,@ObjSpecial = ObjSpecial\n" +
                "  from t110560 a where a.ObjCode =  @DefaultVndCode and a.matcode = @matcode \n" +
                "  select @myrowcount = @@ROWCOUNT,@myerror = @@ERROR\n" +
                "  if @myrowcount = 0 or isnull(@ObjMatCode,'') = '' \n" +
                "  begin\n" +
                "    set @errMsg =case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'物料编号【'+ isnull(@matcode,'') + '】【'+isnull(@matname,'') + '】在 110560 中没找到业务伙伴属于【'+isnull(@DefaultVndCode,'') + '】【'+isnull(@DefaultVndName,'')+'】对照关系,请在 110560 中预先维护好'  \n" +
                "  end \n" +
                "  if isnull(@errMsg,'') <> '' \n" +
                "  begin\n" +
                "     if exists(select 1 from t110562 where doccode = @docCode and rowid = @rowid )\n" +
                "     begin\n" +
                "         update a set PushStatus = 0,PushDate = getdate(),PushTimes = isnull(PushTimes,0) + 1,PushMsg = @errMsg\n" +
                "         from t110562 a \n" +
                "         where a.doccode = @docCode and a.rowid = @rowid \n" +
                "     end else \n" +
                "     begin\n" +
                "     insert into t110562(FormId,DocCode,DocItem,RowId,MatCode,MatName,Special,Uom,\n" +
                "         Digit,Price,TotalMoney,StCode,StName,ItemMemo,PushStatus,PushDate,PushTimes,PushMsg)\n" +
                "         values (@FormId,@DocCode,@DocItem,@RowId,@MatCode,@MatName,@Special,@Uom,\n" +
                "         @Digit,@Price,@TotalMoney,@StCode,@StName,@ItemMemo,0,getdate(),1,@errMsg)\n" +
                "     end \n"+
                "  end else \n" +
                "  begin \n" +
                "  insert into @table(docCode ,docDate ,docType  , \n" +
                " cvenCode ,cvenName ,factoryNumber,cltCode ,cltName,plateNO , \n" +
                " plateTel ,cccode ,ccname,buyerCode ,buyerName , \n" +
                " hDMemo,sumtotalmoney2 ,transCosts ,reduceMoney ,receivMoney , \n" +
                " docStatus ,docStatusName,refCode ,EnterName,rowid, \n" +
                " DocItem ,matCode ,matName,special ,uom ,digit , \n" +
                " stcode,stname ,ItemMemo ,soDocCode,canceldigit, \n" +
                " propertyAddress,brand,cv2,trademarkPrice , \n" +
                " price ,totalmoney ,packingQuantity,[weight] ,totalWeight , \n" +
                " discount ,unsubscribeDoccode,sORowid ,errMsg) \n" +
                "  values(@docCode ,@docDate ,@docType  , \n" +
                " @cvenCode ,@cvenName ,@factoryNumber,@cltCode ,@cltName,@plateNO , \n" +
                " @plateTel ,@cccode ,@ccname,@buyerCode ,@buyerName , \n" +
                " @hDMemo,@sumtotalmoney2 ,@transCosts ,@reduceMoney ,@receivMoney , \n" +
                " @docStatus ,@docStatusName,@refCode ,@EnterName,@rowid, \n" +
                " @DocItem ,@ObjMatCode ,@ObjMatName,@ObjSpecial ,@uom ,@digit , \n" +
                " @stcode,@stname ,@ItemMemo ,@soDocCode,@canceldigit, \n" +
                " @propertyAddress,@brand,@cv2,@trademarkPrice , \n" +
                " @price ,@totalmoney ,@packingQuantity,@weight ,@totalWeight , \n" +
                " @discount ,@unsubscribeDoccode,@sORowid ,@errMsg )\n" +
                "  end \n" +
                "  fetch next from mycurDeli into @docCode,@docDate,@docType,@factoryNumber,\n" +
                "    @plateNO, @plateTel, @cccode, @ccname, @buyerCode, \n" +
                "    @buyerName, @hDMemo, @sumtotalmoney2, @transCosts, @reduceMoney, @receivMoney,\n" +
                "    @docStatus, @docStatusName,@refCode,@EnterName,@MatCode,@MatName,@RowId,@soDocCode,@soRowId\n" +
                " end \n" +
                " close mycurDeli\n" +
                " deallocate mycurDeli \n" +
                " select docCode ,docDate ,docType  , \n" +
                "     cvenCode ,cvenName ,factoryNumber,cltCode ,\n" +
                "     cltName,plateNO , \n" +
                "     plateTel ,cccode ,ccname,buyerCode ,buyerName , \n" +
                "     hDMemo,sumtotalmoney2 ,transCosts ,reduceMoney ,receivMoney , \n" +
                "     docStatus ,docStatusName,refCode ,EnterName,rowid, \n" +
                "     DocItem ,matCode ,matName,special ,uom ,digit , \n" +
                "     stcode,stname ,ItemMemo ,soDocCode,canceldigit, \n" +
                "     propertyAddress,brand,cv2,trademarkPrice , \n" +
                "     price ,totalmoney ,packingQuantity,[weight] as weight ,totalWeight , \n" +
                "     discount ,unsubscribeDoccode,sORowid ,errMsg\n" +
                " from @table ";
 
 
        try {
 
            List<Map<String,Object>> list= this.jdbcTemplate.queryForList(hsql);
            if(list!=null&&list.size()>0) {
                results=new ArrayList<>();
                Set<Object> distinctDoccdeList = list.stream().map(x -> x.get("docCode")).collect(Collectors.toSet());//取出集合中不重复单号
 
                for (Object dist : distinctDoccdeList) {
                    List<Map<String,Object>> t130301List = list.stream().filter(x -> dist.equals(x.get("docCode"))).collect(Collectors.toList());
                    boolean flag = false;//
                    T130301Entity t130301Entity =new T130301Entity();
                    List<T130301DetailEntity> detailEntityList=new ArrayList<>();
                    for (Map<String,Object> map : t130301List) {
                        if (!flag) {//表示第一次,则要取主表和客户信息
                            t130301Entity.setSupplier(new T130301HeadEntity(
                                    GridUtils.prossRowSetDataType_String(map,"docCode"),
                                    GridUtils.prossRowSetDataType_Date(map,"docDate"),
                                    GridUtils.prossRowSetDataType_String(map,"docType"),
                                    GridUtils.prossRowSetDataType_String(map,"vndCode")    ,
                                    GridUtils.prossRowSetDataType_String(map,"vndName")    ,
                                    GridUtils.prossRowSetDataType_String(map,"factoryNumber"),
                                    GridUtils.prossRowSetDataType_String(map,"cltCode"),
                                    GridUtils.prossRowSetDataType_String(map,"cltName"),
                                    GridUtils.prossRowSetDataType_String(map,"plateNO"),
                                    GridUtils.prossRowSetDataType_String(map,"plateTel"),
 
                                    GridUtils.prossRowSetDataType_String(map,"buyerCode"),
                                    GridUtils.prossRowSetDataType_String(map,"buyerName"),
                                    GridUtils.prossRowSetDataType_String(map,"hDMemo"),
                                    GridUtils.prossRowSetDataType_Double(map,"sumtotalmoney2"),
                                    GridUtils.prossRowSetDataType_Double(map,"transCosts"),
                                    GridUtils.prossRowSetDataType_Double(map,"reduceMoney"),
                                    GridUtils.prossRowSetDataType_Double(map,"receivMoney"),
                                    GridUtils.prossRowSetDataType_Int(map,"docStatus"),
                                    GridUtils.prossRowSetDataType_String(map,"docStatusName"),
                                    GridUtils.prossRowSetDataType_String(map,"refCode"),
                                    GridUtils.prossRowSetDataType_String(map,"enterName")
                            ));
 
                        }
                        detailEntityList.add(new T130301DetailEntity(
                                GridUtils.prossRowSetDataType_String(map,"matCode"),
                                GridUtils.prossRowSetDataType_String(map,"matName"),
                                GridUtils.prossRowSetDataType_String(map,"special"),
                                GridUtils.prossRowSetDataType_String(map,"uom"),
                                GridUtils.prossRowSetDataType_Double(map,"digit"),
                                GridUtils.prossRowSetDataType_String(map,"stcode")    ,
                                GridUtils.prossRowSetDataType_String(map,"stname")    ,
                                GridUtils.prossRowSetDataType_String(map,"ItemMemo"),
                                GridUtils.prossRowSetDataType_String(map,"soDocCode"),
                                GridUtils.prossRowSetDataType_Int(map,"DocItem"),
                                GridUtils.prossRowSetDataType_String(map,"rowid"),
                                GridUtils.prossRowSetDataType_String(map,"DocCode"),
                                GridUtils.prossRowSetDataType_Double(map,"canceldigit"),
                                GridUtils.prossRowSetDataType_String(map,"propertyAddress"),
                                GridUtils.prossRowSetDataType_String(map,"brand"),
                                GridUtils.prossRowSetDataType_String(map,"cv2"),
                                GridUtils.prossRowSetDataType_Double(map,"trademarkPrice"),
                                GridUtils.prossRowSetDataType_Double(map,"price"),
                                GridUtils.prossRowSetDataType_Double(map,"totalmoney"),
                                GridUtils.prossRowSetDataType_String(map,"packingQuantity"),
                                GridUtils.prossRowSetDataType_Double(map,"weight"),
                                GridUtils.prossRowSetDataType_Double(map,"totalWeight"),
                                GridUtils.prossRowSetDataType_Double(map,"discount"),
                                GridUtils.prossRowSetDataType_String(map,"unsubscribeDoccode"),
                                GridUtils.prossRowSetDataType_String(map,"sORowid"),
                                GridUtils.prossRowSetDataType_String(map,"cccode"),
                                GridUtils.prossRowSetDataType_String(map,"ccname")
                        ));
                        flag=true;
                    }
                    t130301Entity.setDetails(detailEntityList);
                    results.add(t130301Entity);
                }
            }
        }catch(Exception e ) {
            if (e instanceof EmptyResultDataAccessException){
                return null ;
            }else {
                e.printStackTrace();
                this.doErrorLog(130301,e);
            }
        }
        return  results;
    }
 
    @Override
    public List<T640201Entity> getT640201List(String docCode,Task task) {
        List<T640201Entity> results=null;
        String sql=" set nocount on \n"+
                "  declare @DefaultVndCode varchar(50), @DefaultVndName varchar(80) ,@postdocstatus int\n" +
                " declare @docCode varchar(20),@docDate datetime,@docType varchar(50),@weixiuWay varchar(20),@preSendDate datetime,@cltCode varchar(20),@cltName varchar(80)  , @mydocStatus int="+task.getCurrentDocStatus()+",@myDocCode varchar(50)="+GridUtils.prossSqlParm(docCode)+" \n" +
                "    ,@refCode varchar(50), @tel varchar(50), @propertyAddress varchar(200), @actionname varchar(100) ,@paigongname varchar(50), \n" +
                "    @shopGuideCode varchar(50), @neibushejicode varchar(50), @hDMemo varchar(400), @serverCode varchar(50),@approvalMemo varchar(200),\n" +
                "   @docStatus int, @docStatusName varchar(50),@cshopCode varchar(50),@cshopName varchar(200) ,@cVenCode varchar(50),@cVenName varchar(200),@EnterName varchar(80) ,\n" +
                "   @rowid varchar(20),@DocItem int ,@matcode varchar(50),@matname varchar(120) ,@Special varchar(80),\n" +
                "   @uom varchar(20),@digit money,@stcode varchar(20),@stname varchar(50),@ItemMemo varchar(400),\n" +
                "   @locationName varchar(200),@brand varchar(50) ,@refcodeitem varchar(50), @price money,  @totalmoney2 money,@shopGuideName varchar(50),\n" +
                "   @cccode varchar(50),@ccname varchar(80),@errMsg varchar(500)\n" +
                "\n" +
                " declare @myrowcount int,@myerror int\n" +
                " declare @table table (docCode varchar(20),docDate datetime,docType varchar(50),weixiuWay varchar(20),preSendDate datetime,cltCode varchar(20),cltName varchar(80)  ,\n" +
                "    refCode varchar(50), tel varchar(50), propertyAddress varchar(200), actionname varchar(100) ,paigongname varchar(50), \n" +
                "    shopGuideCode varchar(50), neibushejicode varchar(50), hDMemo varchar(400), serverCode varchar(50),approvalMemo varchar(200),\n" +
                "   docStatus int, docStatusName varchar(50),cshopCode varchar(50),cshopName varchar(200) ,cVenCode varchar(50),cVenName varchar(200),EnterName varchar(80) ,\n" +
                "   rowid varchar(20),DocItem int, matcode varchar(50),matname varchar(120) ,Special varchar(80),\n" +
                "   uom varchar(20),digit money,stcode varchar(20),stname varchar(50),ItemMemo varchar(400),\n" +
                "   locationName varchar(200),brand varchar(50) ,refcodeitem varchar(50), price money,totalmoney2 money,shopGuideName varchar(50),errMsg varchar(500),cccode varchar(50),ccname varchar(80))\n" +
                "  \n" +
                " declare @ObjMatCode varchar(50),@ObjMatName varchar(120) ,@ObjSpecial varchar(120) ,@FormId int = 640201 \n" +
                " select top 1 @DefaultVndCode = a.DefaultVndCode ,@DefaultVndName = b.vndName \n" +
                " from t110561 a left join t110302 b on a.DefaultVndCode = b.vndCode \n" +
                " if isnull(@DefaultVndCode,'') = '' \n" +
                " begin \n" +
                "   raiserror('请在 110561 功能号中维护【缺省供应商编号】',16,1) \n" +
                "    return \n" +
                " end \n" +
                " declare mycurDeli cursor for\n" +
                " select  b.docCode,b.docDate,b.docType,b.weixiuWay,b.preSendDate,b.cltCode,b.cltName  ,\n" +
                "    b.refCode, b.tel, b.propertyAddress, b.actionname, b.paigongname, b.shopGuideCode, b.neibushejicode, b.hDMemo, b.serverCode, b.approvalMemo,\n" +
                "    b.docStatus, b.docStatusName,b.EnterName ,\n" +
                "    c.rowid,c.DocItem,c.matcode,c.matname,c.special,\n" +
                "    c.uom,c.digit,c.stcode,c.stname,c.ItemMemo,c.locationName,c.brand ,c.refcodeitem, c.price,  c.totalmoney2, c.shopGuideName,\n" +
                "    b.cccode ,d.ccname \n" +
                " from t640201H b \n" +
                " join t640201D c on b.doccode = c.doccode \n" +
                " left join t110601 d on b.cccode = d.cccode\n" +
                "  join t110503 e on c.matcode = e.matcode \n" +
                " where  isnull(b.cccode,'') <> '' \n" +
                " and   b.DocStatus=@mydocStatus \n" +
                " and   b.DocCode=@myDocCode \n" +
                " and isnull(e.vndcode,'') = @DefaultVndCode  \n" +
                " order by b.DocCode\n" +
                " open mycurDeli \n" +
                " fetch next from mycurDeli into @docCode,@docDate,@docType,@weixiuWay,@preSendDate,@cltCode,@cltName  ,\n" +
                "    @refCode, @tel, @propertyAddress, @actionname,@paigongname, @shopGuideCode, @neibushejicode, @hDMemo, @serverCode,@approvalMemo,\n" +
                "   @docStatus, @docStatusName,@EnterName ,\n" +
                "   @rowid,@DocItem,@matcode,@MatName,@special,\n" +
                "   @uom,@digit,@stcode,@stname,@ItemMemo,@locationName,@brand ,@refcodeitem, @price,  @totalmoney2,@shopGuideName,\n" +
                "   @cccode,@ccname\n" +
                " while @@fetch_status = 0 \n" +
                " begin\n" +
                "     --检查该客户是否存在\n" +
                "     if not exists(select 1 from t110203 where cltcode = @cltcode) \n" +
                "      begin  \n" +
                "         set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据【'+ isnull(@doccode,'') + '】客户编号【'+ isnull(@cltcode,'') + '】不存在,请在 110203 中新增该客户编号' \n" +
                "      end \n" +
                "      --检查与德立对照表是否存在或有重复设置照表\n" +
                "      select  @cvenCode = cvenCode,@cvenName = cvenName,@cshopCode=cshopCode,@cshopName=cshopName from t110606 where cccode = @CcCode and isnull(cccode,'') <> '' \n" +
                "      select @myrowcount = @@ROWCOUNT,@myerror = @@ERROR\n" +
                "      if @myrowcount = 0 or isnull(@cvenCode,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应代理商编号中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount = 0 or isnull(@cshopCode,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应门店编号中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount = 0 or isnull(@cvenName,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应代理商名称中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount = 0 or isnull(@cshopName,'') = ''  set @errMsg = case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'当前单据所在的部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】,在德立系统对应门店名称中不存在,请在 110606 功能号维护对照关系' \n" +
                "      if @myrowcount <> 1  set @errMsg =case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end + '在 110606 功能号找到多条部门【'+isnull(@CcCode,'') + '】【'+ isnull(@CcName,'') + '】对照关系,请去掉重复的,保留一条即可'\n" +
                "      --检查物料主数据 是否有对照表关系 \n" +
                "      select @ObjMatCode = ObjMatCode,@ObjMatName = ObjMatName ,@ObjSpecial = ObjSpecial\n" +
                "      from t110560 a where a.ObjCode =  @DefaultVndCode and a.matcode = @matcode \n" +
                "      select @myrowcount = @@ROWCOUNT,@myerror = @@ERROR\n" +
                "      if @myrowcount = 0 or isnull(@ObjMatCode,'') = '' \n" +
                "      begin\n" +
                "       set @errMsg =case when isnull(@errMsg,'') = '' then '' else @errMsg + ';' end +'物料编号【'+ isnull(@matcode,'') + '】【'+isnull(@matname,'') + '】在 110560 中没找到业务伙伴属于【'+isnull(@DefaultVndCode,'') + '】【'+isnull(@DefaultVndName,'')+'】对照关系,请在 110560 中预先维护好'  \n" +
                "      end \n" +
                "      if isnull(@errMsg,'') <> '' \n" +
                "      begin\n" +
                "         if exists(select 1 from t110562 where doccode = @docCode and rowid = @rowid )\n" +
                "         begin\n" +
                "             update a set PushStatus = 0,PushDate = getdate(),PushTimes = isnull(PushTimes,0) + 1,PushMsg = @errMsg\n" +
                "             from t110562 a \n" +
                "             where a.doccode = @docCode and a.rowid = @rowid \n" +
                "         end else \n" +
                "         begin\n" +
                "             insert into t110562(FormId,DocCode,DocItem,RowId,MatCode,MatName,Special,Uom,\n" +
                "             Digit,Price,TotalMoney,StCode,StName,ItemMemo,PushStatus,PushDate,PushTimes,PushMsg)\n" +
                "             values (@FormId,@DocCode,@DocItem,@RowId,@MatCode,@MatName,@Special,@Uom,\n" +
                "             @Digit,@Price,@TotalMoney2,@StCode,@StName,@ItemMemo,0,getdate(),1,@errMsg)\n" +
                "         end \n" +
                "      end else \n" +
                "      begin\n" +
                "        insert into @table (docCode,docDate,docType,weixiuWay,preSendDate,cltCode,cltName  ,\n" +
                "            refCode, tel, propertyAddress, actionname,paigongname, shopGuideCode, neibushejicode, hDMemo, serverCode,approvalMemo,\n" +
                "            docStatus, docStatusName,EnterName , rowid,DocItem,matcode,MatName,\n" +
                "            uom,digit,stcode,stname,ItemMemo,locationName,brand ,refcodeitem, price,  totalmoney2,shopGuideName,\n" +
                "            cshopCode,cshopName ,cVenCode,cVenName,ccCode,ccName )\n" +
                "        values(@docCode,@docDate,@docType,@weixiuWay,@preSendDate,@cltCode,@cltName  ,\n" +
                "            @refCode, @tel, @propertyAddress, @actionname,@paigongname, @shopGuideCode, @neibushejicode, @hDMemo, @serverCode,@approvalMemo,\n" +
                "            @docStatus, @docStatusName,@EnterName , \n" +
                "            @rowid,@DocItem,@ObjMatCode ,@ObjMatName,\n" +
                "            @uom,@digit,@stcode,@stname,@ItemMemo,@locationName,@brand ,@refcodeitem, @price,  @totalmoney2,@shopGuideName,\n" +
                "            @cshopCode,@cshopName ,@cVenCode,@cVenName,@ccCode,@ccName)\n" +
                "      end \n" +
 
                "     fetch next from mycurDeli into @docCode,@docDate,@docType,@weixiuWay,@preSendDate,@cltCode,@cltName  ,\n" +
                "        @refCode, @tel, @propertyAddress, @actionname,@paigongname, @shopGuideCode, @neibushejicode, @hDMemo, @serverCode,@approvalMemo,\n" +
                "       @docStatus, @docStatusName,@EnterName ,\n" +
                "       @rowid,@DocItem,@matcode,@MatName,@special,\n" +
                "       @uom,@digit,@stcode,@stname,@ItemMemo,@locationName,@brand ,@refcodeitem, @price,  @totalmoney2,@shopGuideName,\n" +
                "       @cccode,@ccname\n" +
                " end \n" +
                " close mycurDeli\n" +
                " deallocate mycurDeli\n" +
                " select docCode,docDate,docType,weixiuWay,preSendDate,cltCode,cltName  ,\n" +
                "            refCode, tel, propertyAddress, actionname,paigongname, shopGuideCode, neibushejicode, hDMemo, serverCode,approvalMemo,\n" +
                "            docStatus, docStatusName,EnterName , rowid,DocItem,matcode,matName,\n" +
                "            uom,digit,stcode,stname,ItemMemo,locationName,brand ,refcodeitem, price,  totalmoney2,shopGuideName,\n" +
                "            cshopCode,cshopName ,cVenCode,cVenName,ccCode,ccName\n" +
                " from @table " ;
 
 
        try {
            //取主表
            List<Map<String,Object>> list= this.jdbcTemplate.queryForList(sql);
            if(list!=null&&list.size()>0){
                results=new ArrayList<>();
                Set<Object> distinctDoccdeList = list.stream().map(x -> x.get("docCode")).collect(Collectors.toSet());//取出集合中不重复单号
 
                for (Object dist : distinctDoccdeList) {
                    List<Map<String,Object>> t640201List = list.stream().filter(x -> dist.equals(x.get("docCode"))).collect(Collectors.toList());
                    boolean flag=false ;//
                    List<T640201DetailEntity> detailEntityList=new ArrayList<>();
                    T640201Entity t640201Entity =new T640201Entity();
 
                    for(Map<String,Object> map : t640201List) {
                        if (!flag) {//表示第一次,则要取主表
                            t640201Entity.setCustomer(new T640201HeadEntity(
                                    GridUtils.prossRowSetDataType_String(map,"docCode"),
                                    GridUtils.prossRowSetDataType_Date(map,"docDate"),
                                    GridUtils.prossRowSetDataType_Date(map,"preSendDate")    ,
                                    GridUtils.prossRowSetDataType_String(map,"docType"),
                                    GridUtils.prossRowSetDataType_String(map,"weixiuWay")    ,
                                    GridUtils.prossRowSetDataType_String(map,"cltCode"),
                                    GridUtils.prossRowSetDataType_String(map,"cltName"),
                                    GridUtils.prossRowSetDataType_String(map,"refCode"),
                                    GridUtils.prossRowSetDataType_String(map,"tel"),
                                    GridUtils.prossRowSetDataType_String(map,"propertyAddress"),
                                    GridUtils.prossRowSetDataType_String(map,"actionname"),
                                    GridUtils.prossRowSetDataType_String(map,"paigongname"),
                                    GridUtils.prossRowSetDataType_String(map,"shopGuideCode"),
                                    GridUtils.prossRowSetDataType_String(map,"neibushejicode"),
                                    GridUtils.prossRowSetDataType_String(map,"hDMemo"),
                                    GridUtils.prossRowSetDataType_String(map,"serverCode"),
                                    GridUtils.prossRowSetDataType_String(map,"approvalMemo"),
                                    GridUtils.prossRowSetDataType_Int(map,"docStatus"),
                                    GridUtils.prossRowSetDataType_String(map,"docStatusName"),
                                    GridUtils.prossRowSetDataType_String(map,"cVenCode"),
                                    GridUtils.prossRowSetDataType_String(map,"cVenName"),
                                    GridUtils.prossRowSetDataType_String(map,"cshopCode"),
                                    GridUtils.prossRowSetDataType_String(map,"cshopName"),
                                    GridUtils.prossRowSetDataType_String(map,"enterName")
                            ));
                        }
                        detailEntityList.add(new T640201DetailEntity(
                                GridUtils.prossRowSetDataType_String(map,"matCode"),
                                GridUtils.prossRowSetDataType_String(map,"matName"),
                                GridUtils.prossRowSetDataType_String(map,"special"),
                                GridUtils.prossRowSetDataType_String(map,"uom"),
                                GridUtils.prossRowSetDataType_Double(map,"digit"),
                                GridUtils.prossRowSetDataType_String(map,"locationName"),
                                GridUtils.prossRowSetDataType_String(map,"brand"),
                                GridUtils.prossRowSetDataType_String(map,"stcode")    ,
                                GridUtils.prossRowSetDataType_String(map,"stname")    ,
                                GridUtils.prossRowSetDataType_String(map,"ItemMemo"),
                                GridUtils.prossRowSetDataType_Int(map,"DocItem"),
                                GridUtils.prossRowSetDataType_String(map,"rowid"),
                                GridUtils.prossRowSetDataType_String(map,"DocCode"),
                                GridUtils.prossRowSetDataType_String(map,"refcodeitem"),
                                GridUtils.prossRowSetDataType_Double(map,"price"),
                                GridUtils.prossRowSetDataType_Double(map,"totalmoney2"),
                                GridUtils.prossRowSetDataType_String(map,"shopGuideName") ));
                        flag=true;
                    }
                    t640201Entity.setOrders(detailEntityList);
                    results.add(t640201Entity);
 
 
                }
            }
        }catch(Exception e ) {
            if (e instanceof EmptyResultDataAccessException){
                return null ;
            }else {
                e.printStackTrace();
                this.doErrorLog(640201,e);
            }
        }
        return  results;
    }
 
    @Override
    public T640109Entity getT640109(String doccode, String docitem, String rowid) {
        T640109Entity results=null;
        String sql=" set nocount on \n"
                + " declare @DefaultVndCode varchar(50),@DefaultVndName varchar(80) ,@mycccode varchar(50),@myccname varchar(80),@mycshopcode varchar(50) \n" +
                " declare @cltcode varchar(50) ,@matcode varchar(50),@matname varchar(120),@myrowcount int,@myerror int \n"
                +" declare @doccode varchar(50) =? ,@rowid varchar(20) = ? \n"
                +" declare @refcodeitem varchar(50),@refrowid varchar(50) ,@vndcode varchar(50) \n"
                + " select top 1 @DefaultVndCode = a.DefaultVndCode ,@DefaultVndName = b.vndName \n"
                +" from t110561 a left join t110302 b on a.DefaultVndCode = b.vndCode \n"
                + " if isnull(@DefaultVndCode,'') = '' \n"
                + " begin \n"
                + "    raiserror('请在 110561 功能号中维护【缺省供应商编号】',16,1) \n"
                + "    return \n"
                + " end \n"
                + " select @mycccode=a.cccode,@myccname = c.ccname,@cltcode = a.cltcode ,@matcode = b.matcode,@matname = b.matname ,@refcodeitem=b.refcodeitem,@refrowid=b.refrowid \n" +
                " from t640109H a join t640109D b on a.doccode = b.doccode \n" +
                " left join t110601 c on a.cccode = c.cccode \n" +
                " where a.doccode = @doccode and b.rowid = @rowid \n" +
                " select @myrowcount = @@rowcount , @myerror = @@error \n" +
                " if @myrowcount = 0 \n" +
                " begin \n" +
                "    raiserror('当前单据【单号:%s】【rowid: %s】不存在',16,1,@doccode,@rowid ) \n" +
                "    return \n" +
                " end \n" +
                " select @vndcode = vndcode from t110503 where matcode = @matcode \n" +
                " select @myrowcount = @@rowcount , @myerror = @@error \n" +
                " if @myrowcount = 0 \n" +
                " begin \n" +
                "    raiserror('当前物料【%s】不存在,请在 110503 中预先维护!',16,1,@matcode ) \n" +
                "    return \n" +
                " end \n" +
                " if isnull(@vndcode,'') = '' \n" +
                " begin \n" +
                "    raiserror('当前物料【%s】不是德立物料,请在 110503 维护默认供应商为【%s】,然后重试此操作!',16,1,@matcode,@DefaultVndCode ) \n" +
                "    return \n" +
                " end \n" +
                " if isnull(@mycccode,'') = '' \n" +
                " begin \n" +
                "    raiserror('当前单据【%s】部门编号不能为空',16,1,@doccode) \n" +
                "    return \n" +
                " end \n" +
                " if isnull(@myccname,'') = '' \n" +
                " begin \n" +
                "    raiserror('当前单据【%s】部门参数【%s】不存在(可能名称为空值),请在 110601 中维护该部门编号及其名称',16,1,@doccode,@mycccode) \n" +
                "    return \n" +
                " end \n" +
                " if not exists(select 1 from t110203 where cltcode = @cltcode) \n" +
                " begin \n" +
                "    raiserror('当前单据【%s】客户编号【%s】不存在,请在 110203 中新增该客户编号',16,1,@doccode,@cltcode) \n" +
                "    return \n" +
                " end \n" +
                " if isnull(@refcodeitem,'') = '' \n" +
                " begin \n" +
                "    raiserror('当前单据【%s】refcodeitem不能为空',16,1,@doccode,@refcodeitem) \n" +
                "    return \n" +
                " end \n" +
                " if isnull(@refrowid,'') = '' \n" +
                " begin \n" +
                "    raiserror('当前单据【%s】refrowid不能为空',16,1,@doccode,@refrowid) \n" +
                "    return \n" +
                " end \n" +
                " select  @mycshopcode=a.cshopCode from t110606 a where a.cccode = @mycccode \n" +
                " select @myrowcount = @@rowcount , @myerror = @@error \n" +
                " if @myrowcount = 0 or isnull(@mycshopcode,'') = '' \n" +
                " begin \n" +
                "    raiserror('当前单据所在的部门【%s】【%s】,在德立系统对应门店编号中不存在,请在 110606 功能号维护对照关系',16,1,@mycccode,@myccname) \n" +
                "    return \n" +
                " end \n" +
                " if @myrowcount <> 1 \n" +
                " begin \n" +
                "     raiserror('在 110606 功能号找到多条部门【%s】【%s】对照关系,请去掉重复的,保留一条即可',16,1,@mycccode,@myccname) \n" +
                "     return \n" +
                "  end \n" +
                " if not exists(select 1 from t110560 a where a.ObjCode =  @DefaultVndCode and a.matcode = @matcode )\n" +
                " begin \n" +
                "    raiserror('物料编号【%s】【%s】在 110560 中没找到业务伙伴属于【%s】【%s】对照关系,请在 110560 中预先维护好',16,1,@matcode,@matname,@DefaultVndCode,@DefaultVndName) \n" +
                "    return \n" +
                " end \n" +
                " select  @matname=a.matname from t110560 a where a.matcode  = @matcode \n" +
                " select @myrowcount = @@rowcount , @myerror = @@error \n" +
                " if @myrowcount <> 1 \n" +
                " begin \n" +
                "     raiserror('在 t110560 功能号找到多个物料【%s】【%s】,请去掉重复的,保留一条即可',16,1,@matcode,@matname) \n" +
                "     return \n" +
                "  end " +
                 " select b.docCode,b.docDate,b.preSendDate,b.factdate,b.docType,b.cltCode,\n" +
                "   b.cltName,b.meterName,b.tel,b.propertyAddress,b.sellerName,b.shopGuideName,\n" +
                "   b.shejiCode,b.shejiName,b.hDMemo,b.attachmentDate,b.approvalMemo,\n" +
                "   b.approvalMemo2,b.approvalMemo3,\n" +
                "   b.approvalMemo4,b.docStatus, b.docStatusName,b.refCode,b.EnterName, b.cccode,\n" +
                "   a.cshopCode,a.cshopName ,a.cVenCode,a.cVenName,  \n" +
                "   c.DocCode,c.rowid,c.DocItem,\n" +
                "   d.ObjMatCode as matCode,d.ObjMatName as matName,d.ObjSpecial as special,\n" +
                "   c.uom,c.digit,c.locationName,c.ItemMemo,c.refcodeitem,c.refrowid  \n"+
                " from t640109H b join t110606 a on a.ccCode=b.ccCode \n" +
                " join t640109D c on b.doccode = c.doccode \n" +
                " join t110560 d on d.ObjCode =  @DefaultVndCode and c.matcode = d.matcode \n" +
                " join t110203 e on b.cltcode = e.cltcode \n" +
                " where  b.doccode=@doccode and c.rowid=@rowid \n" +
                " order by b.DocCode \n" ;
 
        try {
            Map<String,Object> map= this.jdbcTemplate.queryForMap(sql,doccode,rowid);
            if(map!=null&&map.size()>0){
                List<T640109DetailEntity> detailEntityList=new ArrayList<>();
                detailEntityList.add(new T640109DetailEntity(
                        GridUtils.prossRowSetDataType_String(map,"matCode"),
                        GridUtils.prossRowSetDataType_String(map,"matName"),
                        GridUtils.prossRowSetDataType_String(map,"uom"),
                        GridUtils.prossRowSetDataType_Double(map,"digit"),
                        GridUtils.prossRowSetDataType_String(map,"ItemMemo"),
                        GridUtils.prossRowSetDataType_Int(map,"DocItem"),
                        GridUtils.prossRowSetDataType_String(map,"rowid"),
                        GridUtils.prossRowSetDataType_String(map,"DocCode"),
                        GridUtils.prossRowSetDataType_String(map,"locationName")    ,
                        GridUtils.prossRowSetDataType_String(map,"special"),
                        GridUtils.prossRowSetDataType_String(map, "refcodeitem"),
                        0,
                        GridUtils.prossRowSetDataType_String(map, "refrowid")
                ));
 
                //主表
                if(results==null){    results=new T640109Entity();}
                results.setCustomer(new T640109HeadEntity(
                        GridUtils.prossRowSetDataType_String(map,"docCode"),
                        GridUtils.prossRowSetDataType_Date(map,"docdate"),
                        GridUtils.prossRowSetDataType_Date(map,"preSendDate"),
                        GridUtils.prossRowSetDataType_Date(map,"factdate"),
                        GridUtils.prossRowSetDataType_String(map,"docType"),
                        GridUtils.prossRowSetDataType_String(map,"cltCode"),
                        GridUtils.prossRowSetDataType_String(map,"cltName"),
                        GridUtils.prossRowSetDataType_String(map,"meterName"),
                        GridUtils.prossRowSetDataType_String(map,"tel")    ,
                        GridUtils.prossRowSetDataType_String(map,"propertyAddress")    ,
                        GridUtils.prossRowSetDataType_String(map,"sellerName"),
                        GridUtils.prossRowSetDataType_String(map,"shopGuideName"),
                        GridUtils.prossRowSetDataType_String(map,"shejiCode"),
                        GridUtils.prossRowSetDataType_String(map,"shejiName"),
                        GridUtils.prossRowSetDataType_String(map,"hDMemo"),
                        GridUtils.prossRowSetDataType_Date(map,"attachmentDate"),
                        GridUtils.prossRowSetDataType_String(map,"approvalMemo"),
                        GridUtils.prossRowSetDataType_String(map,"approvalMemo2"),
                        GridUtils.prossRowSetDataType_String(map,"approvalMemo3"),
                        GridUtils.prossRowSetDataType_String(map,"approvalMemo4"),
                        GridUtils.prossRowSetDataType_Int(map,"docStatus"),
                        GridUtils.prossRowSetDataType_String(map,"docStatusName"),
                        GridUtils.prossRowSetDataType_String(map,"refCode"),
                        GridUtils.prossRowSetDataType_String(map,"cVenCode"),
                        GridUtils.prossRowSetDataType_String(map,"cVenName"),
                        GridUtils.prossRowSetDataType_String(map,"cshopCode"),
                        GridUtils.prossRowSetDataType_String(map,"cshopName"),
                        GridUtils.prossRowSetDataType_String(map,"cccode"),
                        GridUtils.prossRowSetDataType_String(map,"EnterName")
                ));
                results.setDetails(detailEntityList);
            }
        }catch(Exception e ) {
            if (e instanceof EmptyResultDataAccessException){
                return null ;
            }else {
                e.printStackTrace();
                throw new ApplicationException(e.getCause()!=null?e.getCause().getMessage():e.getMessage());
                //    this.doErrorLog(640109,e);
            }
        }
        return  results;
    }
 
    @Override
    public Integer bindUserAccount(DataSourceEntity dataSource) {
        return this.jdbcTemplate.update("set nocount  on \n update a set a.DeliUserCode =? , a.DeliUserId =? from gsystem a where id=?",dataSource.getDeliUserCode(),dataSource.getDeliUserId(),dataSource.getDbId());
    }
 
    @Override
    public Integer unbindUserAccount(DataSourceEntity dataSource) {
        return this.jdbcTemplate.update("set nocount  on \n update a set a.DeliUserCode =null , a.DeliUserId =null from gsystem a where id=?",dataSource.getDbId());
    }
}