zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
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
package cn.autoform.web.service.datamanagement;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
 
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
 
import com.alibaba.fastjson.TypeReference;
 
import cn.autoform.bean.BudgetData;
import cn.autoform.bean.BudgetTitle;
import cn.autoform.bean.FormSolidiFication;
 
import cn.autoform.bean.ProcessBudget;
import cn.autoform.bean.ReleData;
import cn.autoform.bean.TableName;
import cn.autoform.bean.form.AssociatedFormData;
import cn.autoform.bean.form.CpnType;
import cn.autoform.bean.form.JoinFormData;
import cn.autoform.bean.form.RequestFormBase;
import cn.autoform.bean.page.PageResult;
import cn.autoform.db.entity.FieldPropertyEntity;
import cn.autoform.db.entity.FormDataMangerEntity;
import cn.autoform.db.entity.FormFieldEntity;
import cn.autoform.db.exten.ServicesFormData;
import cn.autoform.db.exten.SelectForm;
import cn.autoform.db.exten.SubForm;
import cn.autoform.factory.FormFactory;
import cn.autoform.fw.exception.FormClientException;
import cn.autoform.fw.exception.RestResult;
import cn.autoform.fw.utility.ConstMap;
import cn.autoform.fw.utility.FormDataUtil;
import cn.autoform.util.tool.JSONTool;
import cn.autoform.util.tool.RequestContext;
import cn.autoform.web.client.FormClient;
import cn.autoform.web.client.util.auto.OnlyCharacters;
import cn.autoform.web.client.util.auto.ParamFactory;
import cn.autoform.web.mapper.datamanagement.DataManagementMapper;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
@Service
public class DataManagementService {
 
    private static final Map<String, String> DBTYPE = new HashMap<>();
    
    static {
        // 单行文本
        DBTYPE.put("text", ConstMap.VARCHAR150);
        // 单选按钮
        DBTYPE.put("radio", ConstMap.VARCHAR50);
        // 下拉列表框
        DBTYPE.put("dropdownlist", ConstMap.LONGTEXT);
        // 日期控件
        DBTYPE.put("calendar", ConstMap.VARCHAR30);
        // 复选框
        DBTYPE.put("checkbox", ConstMap.LONGTEXT);
        // 子表单
        DBTYPE.put("subform", ConstMap.VARCHAR30);
        // 数字
        DBTYPE.put("number", ConstMap.VARCHAR30);
        // 多行文本
        DBTYPE.put("textarea", ConstMap.LONGTEXT);
        // HTML
        DBTYPE.put("htmlediter", ConstMap.LONGTEXT);
        // 条码
        DBTYPE.put("barcode", ConstMap.VARCHAR30);
        // 二维码
        DBTYPE.put("qrcode", ConstMap.VARCHAR200);
        // 图片
        DBTYPE.put("image", ConstMap.LONGTEXT);
        // 文件上传
        DBTYPE.put("fileupload", ConstMap.LONGTEXT);
        // 数型控件   
        DBTYPE.put("tree", ConstMap.LONGTEXT);
        // 金额组件
        DBTYPE.put("amount", ConstMap.LONGTEXT);
    }
 
    @Autowired
    private DataManagementMapper dataManagementMapper = null;
    
    @Autowired
    private FormClient formClient = null;
    
//    @Autowired
//    private FormFactory formFactory;
 
    public List<FormFieldEntity> queryFormFields(String formID, String tenantID) {
        return dataManagementMapper.queryFormFields(formID, tenantID);
    }
    
    public List<FormFieldEntity> getFormFieldMain(String formID, String tenantID) {
        return dataManagementMapper.getFormFieldMain(formID, tenantID);
    }
 
 
    public Map<String, FieldPropertyEntity> queryFormFieldsAboutData(String formID, String tenantID,
            Integer columnOrderNum) {
        return dataManagementMapper.queryFormFieldsAboutData(formID, tenantID, columnOrderNum);
    }
 
    public Map<String, FormFieldEntity> queryFormFields2(String formID, String tenantID) {
        Map<String, FormFieldEntity> info = dataManagementMapper.queryFormFields2(formID, tenantID);
        // 过滤选项卡。
        info.entrySet().stream().forEach(entry->{
            if(Objects.equals(entry.getValue().getFieldtype(), CpnType.subform.toString())) {
                entry.getValue().setParentsubFormNum(0);
            }
        });
        return info;
    }
 
    public Map<Integer, FormDataMangerEntity> queryFormdataManagers2(String formID, String tenantID) {
        return dataManagementMapper.queryFormdataManagers2(formID, tenantID);
    }
 
    public void excuteFormDataInsert(String excuteSql) {
        dataManagementMapper.excuteFormDataInsert(excuteSql);
    }
 
    public FormDataMangerEntity queryFormdataManagersFor(String formID, String tenantID) {
        return dataManagementMapper.queryFormdataManagersFor(formID, tenantID);
    }
 
    public void updateFormdataManagersFor(FormDataMangerEntity entity) {
        dataManagementMapper.updateFormdataManagersFor(entity);
    }
 
    //根据formID查询基本表的表名
    public String getBaseTableName(String formID, String tenantID){
        return dataManagementMapper.getBaseTableName(formID, tenantID);
    } 
    
    public List<String> queryCloudMainValue(String excuteSql){
        return dataManagementMapper.queryCloudMainValue(excuteSql);
    }
    
    public List<String> queryServicesMainValue(String sql){
        return null;
    }
    
    //查询控件属性
    public List<FieldPropertyEntity> queryFormFieldProperty(String formID, String tenantID, Integer columnOrderNum){
        return dataManagementMapper.queryFormFieldProperty(formID, tenantID, columnOrderNum);
    }
 
    public List<FieldPropertyEntity> queryFormFieldProperty(String formID, String tenantID, String field){
        return dataManagementMapper.queryFormFieldPropertyByField(formID, tenantID, field);
    }
    
    //查询表中下拉框,等多选主数据相关控件
    public List<FormFieldEntity> queryFormMainField(String formID, String tenantID){
        return dataManagementMapper.queryFormMainField(formID, tenantID);
    }
    
    public List<FormFieldEntity> queryFormSubField(String formID, String tenantID){
        return dataManagementMapper.queryFormSubField(formID, tenantID);
    }
    
    public List<FormFieldEntity> queryFormAllField(String formID, String tenantID){
        return dataManagementMapper.queryFormAllField(formID, tenantID);
    }
    public SelectForm queryFormDataList(String formID, String tenantID) {
 
        SelectForm mainForm = new SelectForm();
        mainForm.setTenantID(tenantID);
        
        // 取得表单数据管理
        List<FormDataMangerEntity> formDataMangerList = dataManagementMapper.queryFormdataMangers(formID, tenantID);
        if (formDataMangerList == null || formDataMangerList.isEmpty()) {
            return null;
        }
 
        List<FormFieldEntity> formFieldsList = dataManagementMapper.queryFormFields3(formID, tenantID);
 
        StringBuilder sqlSelectMain = new StringBuilder(
                "/*!mycat:sql= select tenantid from FORMDATAMANAGER WHERE TENANTID = '%s' AND FROMID = '%s' */ SELECT %s FROM ");
        for (FormDataMangerEntity formDataMangerEntity : formDataMangerList) {
            if (formDataMangerEntity.getFormdataNum() == 0) {
                sqlSelectMain.append(formDataMangerEntity.getFormdatatable());
                mainForm.setFormName("_" + tenantID  + "_" + formDataMangerEntity.getFormdatatable().substring(8));
            }
        }
 
        StringBuilder sqlSelcetFields = new StringBuilder();
        sqlSelcetFields.append(" DATAROWNUM,");
        
         Map<String,Object> fields = new HashMap<>();
        
        for (FormFieldEntity formFieldEntity : formFieldsList) {
            if (formFieldEntity.getParentsubFormNum() == 0
                    && DBTYPE.containsKey(formFieldEntity.getFieldtype())) {
                if (!ConstMap.SUBFORM.equals(formFieldEntity.getFieldtype())) {
                    String fieldName = ConstMap.FIELD + formFieldEntity.getColumnOrderNum();
                    sqlSelcetFields.append(" IFNULL(");
                    sqlSelcetFields.append(fieldName);
                    sqlSelcetFields.append(" , '') AS '");
                    sqlSelcetFields.append(fieldName);
                    sqlSelcetFields.append("',");
                    fields.put(fieldName,fieldName);
                } else {
                    sqlSelcetFields.append(formFieldEntity.getColumnOrderNum());
                    sqlSelcetFields.append(" AS");
                    sqlSelcetFields.append(" FIELD");
                    sqlSelcetFields.append(formFieldEntity.getColumnOrderNum());
                    sqlSelcetFields.append(",");
                    //fields.put(formFieldEntity.getColumnOrderNum().toString(), " FIELD" + formFieldEntity.getColumnOrderNum());        
                    }
            }
        }
        sqlSelcetFields.deleteCharAt(sqlSelcetFields.length() - 1);
 
        StringBuilder whereSql = new StringBuilder(" WHERE ");
        whereSql.append(" deleteFlg = '0'");
        whereSql.append(" AND TENANTID = '");
        whereSql.append(tenantID);
        whereSql.append("'");
 
        sqlSelectMain.append(whereSql);
 
        mainForm.setFields(fields);
        return mainForm;
                //dataManagementMapper.queryFormdatas(executeSql);
    }
 
    public Map<String, Object> queryFormDataList(String formID, String tenantID, Integer datarowNum) {
        SelectForm selectForm = new SelectForm();
        selectForm.setDataRowNum(datarowNum);
        selectForm.setTenantID(tenantID);
 
        // 取得表单数据管理
        List<FormDataMangerEntity> formDataMangerList = dataManagementMapper.queryFormdataMangers(formID, tenantID);
 
        List<FormFieldEntity> formFieldsList = dataManagementMapper.queryFormFields3(formID, tenantID);
 
        StringBuilder sqlSelectMain = new StringBuilder(
                "/*!mycat:sql= select tenantid from FORMDATAMANAGER WHERE TENANTID = '%s' AND FROMID = '%s' */ SELECT %s FROM ");
        for (FormDataMangerEntity formDataMangerEntity : formDataMangerList) {
            if (formDataMangerEntity.getFormdataNum() == 0) {
                sqlSelectMain.append(formDataMangerEntity.getFormdatatable());
                selectForm.setFormName("_" + tenantID  + "_" + formDataMangerEntity.getFormdatatable().substring(8));
            }
        }
 
         Map<String,Object> selectMap = new HashMap<>();
        
        StringBuilder sqlSelcetFields = new StringBuilder();
        sqlSelcetFields.append(" DATAROWNUM,");
        for (FormFieldEntity formFieldEntity : formFieldsList) {
            if (formFieldEntity.getParentsubFormNum() == 0
                    && DBTYPE.containsKey(formFieldEntity.getFieldtype())) {
                if (!ConstMap.SUBFORM.equals(formFieldEntity.getFieldtype())) {
                    String fieldName = ConstMap.FIELD + formFieldEntity.getColumnOrderNum();
                    sqlSelcetFields.append(" IFNULL(");
                    sqlSelcetFields.append(fieldName);
                    sqlSelcetFields.append(" , '') AS ");
                    sqlSelcetFields.append(formFieldEntity.getFieldKey());
                    sqlSelcetFields.append(",");
                    selectMap.put(fieldName,formFieldEntity.getFieldKey());
                } else {
                    sqlSelcetFields.append("'");
                    sqlSelcetFields.append(formFieldEntity.getFieldKey());
                    sqlSelcetFields.append("'");
                    sqlSelcetFields.append(" AS ");
                    sqlSelcetFields.append(ConstMap.FIELD + formFieldEntity.getColumnOrderNum());
                    sqlSelcetFields.append(",");
                    selectMap.put(String.format("'%s'", formFieldEntity.getFieldKey()), ConstMap.FIELD + formFieldEntity.getColumnOrderNum());
                }
            }
        }
        
        selectForm.setFields(selectMap);
//        sqlSelcetFields.deleteCharAt(sqlSelcetFields.length() - 1);
//
//        StringBuilder whereSql = new StringBuilder(" WHERE ");
//        whereSql.append(" deleteFlg = '0'");
//        whereSql.append(" AND TENANTID = '");
//        whereSql.append(tenantID);
//        whereSql.append("'");
//
//        whereSql.append(" AND SUBDATAROWNUM = 0 AND ");
//        whereSql.append(" DATAROWNUM = ");
//        whereSql.append(datarowNum);
//        sqlSelectMain.append(whereSql);
 
//        String executeSql = String.format(sqlSelectMain.toString(), tenantID, formID, sqlSelcetFields.toString());
        Map<String,Object> data = new HashMap<>();
//        data.put("main", dataManagementMapper.queryFormdatas(executeSql).get(0));
        data.put("selectForm", selectForm);
        return data;
    }
 
    /**
     * 删除表单数据
     * 
     * @param formID 表单ID
     * @param tenantID 租户ID
     * @param datarowNum 数据行番
     */
    public ServicesFormData removeFormData(String formID, String tenantID, JSONArray datarowNumArray) {
 
        List<FormDataMangerEntity> formDataMangers = dataManagementMapper.queryFormdataMangers(formID, tenantID);
        
        ServicesFormData formData = new ServicesFormData();
        SubForm subForm = null;
        
        List<SubForm> subFormList = new ArrayList<SubForm>();
        for(int i= 0; i< formDataMangers.size(); i++) {
            subForm = new SubForm();
            if(i == 0) {
                formData.setFormID("_" + tenantID  + "_" + formDataMangers.get(i).getFormdatatable().substring(8));
            }else{
                subForm.setFormID("_" + tenantID  + "_" + formDataMangers.get(i).getFormdatatable().substring(8));
                subFormList.add(subForm);
            }
            formDataMangers.get(i).getFormdatatable();            
        }
        formData.setSubFormList(subFormList);
        
        StringBuilder updateSql = new StringBuilder();
 
        updateSql.append(
                "/*!mycat:sql= select tenantid from FORMDATAMANAGER WHERE TENANTID = '%s' AND FROMID = '%s' */ UPDATE ");
        
        updateSql.append(" SET DELETEFLG = '1' WHERE ");
 
        updateSql.append(" TENANTID = '%s' AND DATAROWNUM IN (");
 
        for (Object dataRowNum : datarowNumArray) {
            updateSql.append(dataRowNum);
            updateSql.append(ConstMap.COMMA);
        }
        updateSql.deleteCharAt(updateSql.length() - 1);
 
        updateSql.append(")");
 
 
        return formData;
    }
 
    /**
     * 删除表单数据
     * 
     * @param sql
     */
    public void removeFormData(String sql) {
        dataManagementMapper.removeFormData(sql);
    }
 
    public void updateFormData(String updateSql) {
        dataManagementMapper.updateFormData(updateSql);
    }
    
    public String getTitleProperty(String formID, String tenantID, Integer columnOrderNum){
        List<FieldPropertyEntity> file =  queryFormFieldProperty(formID, tenantID, columnOrderNum);
        String field = null;
        try{
            field = file
                    .stream()
                        .filter(fieldP -> "title".equals(fieldP.getProperty()))
                            .collect(Collectors.toList())
                                .get(0)
                                    .getValue();
                 
        
        }catch(Exception e){
            return "";
        }
        return field;
    }
    
    public List<Map<String, Object>> querySubFormDataList(String formID, String tenantID, Integer formdataNum,
            Integer datarowNum) {
        
        SubForm subForm = new SubForm();
        subForm.setDataRowNum(datarowNum);
        subForm.setSubDataRowNum(datarowNum);
        subForm.setFormDataNum(formdataNum);
 
        // 取得表单数据管理
        List<FormDataMangerEntity> formDataMangerList = dataManagementMapper.queryFormdataMangers1(formID, tenantID,
                formdataNum);
 
        if (formDataMangerList.isEmpty()) {
            return null;
        }
 
        List<FormFieldEntity> formFieldsList = dataManagementMapper.queryFormFields3(formID, tenantID);
 
        StringBuilder sqlSelectMain = new StringBuilder(
                "/*!mycat:sql= select tenantid from FORMDATAMANAGER WHERE TENANTID = '%s' AND FROMID = '%s' */ SELECT %s FROM ");
        for (FormDataMangerEntity formDataMangerEntity : formDataMangerList) {
            if (formDataMangerEntity.getFormdataNum() == formdataNum) {
                subForm.setFormName("formdata" + formDataMangerEntity.getFormdatatable().substring(8));
                sqlSelectMain.append(formDataMangerEntity.getFormdatatable());
            }
        }
 
        StringBuilder sqlSelcetFields = new StringBuilder();
        sqlSelcetFields.append(" DATAROWNUM,");
        
        Map<String,Object> fieldMap = new HashMap<>();
        for (FormFieldEntity formFieldEntity : formFieldsList) {
            if (formFieldEntity.getParentsubFormNum() == formdataNum
                    && DBTYPE.containsKey(formFieldEntity.getFieldtype())) {
                if (!ConstMap.SUBFORM.equals(formFieldEntity.getFieldtype())) {
                    String fieldName = ConstMap.FIELD + formFieldEntity.getColumnOrderNum();
                    sqlSelcetFields.append(" IFNULL(");
                    sqlSelcetFields.append(fieldName);
                    sqlSelcetFields.append(" , '') AS ");
                    sqlSelcetFields.append(formFieldEntity.getFieldKey());
                    sqlSelcetFields.append(",");
                    fieldMap.put(formFieldEntity.getFieldKey(), formFieldEntity.getFieldKey());
                } else {
                    sqlSelcetFields.append(formFieldEntity.getColumnOrderNum());
                    sqlSelcetFields.append(" AS ");
                    sqlSelcetFields.append(formFieldEntity.getFieldKey());
                    sqlSelcetFields.append(",");
                }
            }
        }
        
        subForm.setFields(fieldMap);
        
        sqlSelcetFields.deleteCharAt(sqlSelcetFields.length() - 1);
 
        StringBuilder whereSql = new StringBuilder(" WHERE ");
 
        whereSql.append(" deleteFlg = '0'");
        whereSql.append(" AND DATAROWNUM = ");
        whereSql.append(datarowNum);
        whereSql.append(" AND TENANTID = '");
        whereSql.append(tenantID);
        whereSql.append("'");
        
//        sqlSelectMain.append(sqlSelcetFields);
        sqlSelectMain.append(whereSql);
        
         List<Map<String, Object>> lis =  new ArrayList<>();
         lis.add(new ModelMap("subForm",subForm));
         return lis;
    }
    
    public List<Map<String, Object>> queryCloudSubFormDataList(String formID, String tenantID, Integer formdataNum,
            Integer datarowNum) {
 
        // 取得表单数据管理
        List<FormDataMangerEntity> formDataMangerList = dataManagementMapper.queryFormdataMangers1(formID, tenantID,
                formdataNum);
 
        if (formDataMangerList.isEmpty()) {
            return null;
        }
 
        List<FormFieldEntity> formFieldsList = dataManagementMapper.queryFormFields3(formID, tenantID);
 
        StringBuilder sqlSelectMain = new StringBuilder(
                "/*!mycat:sql= select tenantid from FORMDATAMANAGER WHERE TENANTID = '%s' AND FROMID = '%s' */ SELECT %s FROM ");
        for (FormDataMangerEntity formDataMangerEntity : formDataMangerList) {
            if (formDataMangerEntity.getFormdataNum() == formdataNum) {
                sqlSelectMain.append(formDataMangerEntity.getFormdatatable());
            }
        }
 
        StringBuilder sqlSelcetFields = new StringBuilder();
        sqlSelcetFields.append(" DATAROWNUM,");
        for (FormFieldEntity formFieldEntity : formFieldsList) {
            if (formFieldEntity.getParentsubFormNum() == formdataNum
                    && DBTYPE.containsKey(formFieldEntity.getFieldtype())) {
                if (!ConstMap.SUBFORM.equals(formFieldEntity.getFieldtype())) {
//                    String fieldName = ConstMap.FIELD + formFieldEntity.getColumnOrderNum();
                    sqlSelcetFields.append(" IFNULL(");
//                    sqlSelcetFields.append(fieldName);
                    sqlSelcetFields.append(formFieldEntity.getFieldKey());
                    sqlSelcetFields.append(" , '') AS '");
                    sqlSelcetFields.append(formFieldEntity.getFieldKey());
                    sqlSelcetFields.append("',");
                } else {
                    sqlSelcetFields.append(formFieldEntity.getColumnOrderNum());
                    sqlSelcetFields.append(" AS '");
                    sqlSelcetFields.append(formFieldEntity.getFieldKey());
                    sqlSelcetFields.append("',");
                }
            }
        }
        sqlSelcetFields.deleteCharAt(sqlSelcetFields.length() - 1);
 
        StringBuilder whereSql = new StringBuilder(" WHERE ");
 
        whereSql.append(" deleteFlg = '0'");
        whereSql.append(" AND PARENTDATAROWNUM = ");
        whereSql.append(datarowNum);
        whereSql.append(" AND TENANTID = '");
        whereSql.append(tenantID);
        whereSql.append("'");
 
        sqlSelectMain.append(whereSql);
 
        String executeSql = String.format(sqlSelectMain.toString(), tenantID, formID, sqlSelcetFields.toString());
 
        return dataManagementMapper.queryFormdatas(executeSql);
    }
    
    public void updateFormFieldState(FormFieldEntity formFieldentity) {
        dataManagementMapper.updateFormFieldState(formFieldentity);
    }
    
    public void updateMainFormFieldService(FormFieldEntity formFieldentity) {
        dataManagementMapper.updateMainFormFieldService(formFieldentity);
    }
    
    public List<Map<String,Object>> queryCodeAutoAttr(String formID, String tenantID,String columnordernum){
        return dataManagementMapper.queryCodeAutoAttr(formID, tenantID,columnordernum);
    }
    
    public List<Map<String,Object>> queryAutoAttr(String formID, String tenantID){
        return dataManagementMapper.queryAutoAttr(formID, tenantID);
    }
    
    
    public Integer addFormStateData(Map<String,String> formState){
        return dataManagementMapper.addFormStateData(formState);
    }
    
    /**
     * 根据别名查询表单中对应控件属性
     * @param formID
     * @param tenantID
     * @param fieldKey
     * @return
     */
    public FormFieldEntity queryFormFieldPropertyByFieldKey(String formID, String tenantID, String fieldKey){
        return dataManagementMapper.queryFormFieldPropertyByFieldKey(formID, tenantID, fieldKey);
    }
    
    /**
     * 得到自动生成number
     * @param formID
     * @param tenantID
     * @param field
     * @param dataRowNum
     * @return
     */
    public String getAutoNumber(String formID, String tenantID, String field ,Integer dataRowNum){
        StringBuilder prfix = new StringBuilder();
        Map<String ,String> param = new HashMap<>();
        queryFormFieldProperty(formID, tenantID, field)
            .stream().filter(formField -> "prefixs".equals(formField.getProperty())
                        ||  "autoTypeNumber".equals(formField.getProperty())
                            ||"autoTypePrefix".equals(formField.getProperty()))
                .forEach(formField -> {
                    if("prefixs".equals(formField.getProperty())){
                        List<Map<String, Object>> prefixs = JSONTool.toObj(formField.getValue(),new TypeReference<List<Map<String, Object>>>(){});
                        prfix.append(prefixs.get(0).get("itemtext_1") + "$in{" + prefixs.get(0).get("itemtext_2") +"}");
                    }else{
                        param.put(formField.getProperty(), formField.getValue());
                    }
                });
        if(!param.isEmpty()){
            prfix.append( param.get("autoTypePrefix")+ "$in{" + param.get("autoTypeNumber") +"}");
        }
        ParamFactory.setBegain(dataRowNum.toString());
        return OnlyCharacters.getOnlyStr(prfix.toString());
    }
    
    /**
     * 获得关联函数对应数据
     * @param associatedFormData
     * @return
     * @throws TimeoutException
     * @throws FormClientException 
     */
    public Map<String,Object> getAssociateData(BudgetData budgetData) throws TimeoutException, FormClientException{
//        associatedFormData.setPageNum(RequestContext.getPageNum());
//        associatedFormData.setPageSize(RequestContext.getPageSize());
        return this.formClient.getAssociateData(budgetData);
    }
    /**
     * 获得关联函数标题
     * @param key
     * @return
     * @throws TimeoutException
     * @throws FormClientException 
     */
    public List<BudgetTitle> getAssociateTitle(Map<String, Object> key) throws TimeoutException, FormClientException{
        return this.formClient.getAssociateTitle(key);
    }
    
    /**
     * 获得表单上下文
     * @param formID
     * @param tenantID
     * @return
     */
    public Map<String,Object> getFormContext(String formID, String tenantID){
        return this.dataManagementMapper.getFormContext(formID, tenantID);
    }
    
    /**
     * 获得表单数据上下文
     * @param formID
     * @param tenantID
     * @return
     */
    public Map<String,Object> getFormDataContext(RequestFormBase requestFormBase){
        String formName = FormDataUtil.getFormTableName(requestFormBase.getTenantID(), requestFormBase.getFormID());
        return this.dataManagementMapper.getFormDataContext(requestFormBase.getFormID(),requestFormBase.getTenantID()
                ,requestFormBase.getDatarowNum(), formName);
    }
    
    public Object getBudget(ProcessBudget processBudget) throws TimeoutException, FormClientException{
        return this.formClient.getBudget(processBudget);
    }
    
    /**
     * 查询控件别名
     * @param formID
     * @param tenantID
     * @return
     */
    public List<Map<String,Object>> queryFormFiled(String formID,String tenantID){
        return dataManagementMapper.queryFormFiled(formID, tenantID);
    }
    
    /**
     * 表单固化准备参数
     * @throws TimeoutException 
     */
    public FormSolidiFication formSolidiFication(String formId,Integer dataRowNum,String tenantId) throws TimeoutException{
        List<FormDataMangerEntity> formDataMangerList = dataManagementMapper.queryFormdataMangers(formId, tenantId);
        FormSolidiFication fs = new FormSolidiFication();
        fs.setFormId(formId);
        fs.setTenantId(tenantId);
        fs.setDataRowNum(dataRowNum);
        for(FormDataMangerEntity f: formDataMangerList){
            if(f.getFormdataNum()!=0){
                fs.getTableList().add(new TableName(f.getFormdataNum(),f.getFormdatatable()));
            }
        
        }
        return fs;
        
    }
}