ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
package jnpf.base.controller;
 
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jnpf.base.*;
import jnpf.base.entity.DataInterfaceEntity;
import jnpf.base.entity.DictionaryDataEntity;
import jnpf.base.entity.InterfaceOauthEntity;
import jnpf.base.model.datainterface.*;
import jnpf.base.service.DataInterfaceService;
import jnpf.base.service.DictionaryDataService;
import jnpf.base.service.DictionaryTypeService;
import jnpf.base.service.InterfaceOauthService;
import jnpf.base.util.interfaceUtil.InterfaceUtil;
import jnpf.base.vo.DownloadVO;
import jnpf.base.vo.ListVO;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.config.ConfigValueUtil;
import jnpf.constant.DbSensitiveConstant;
import jnpf.constant.MsgCode;
import jnpf.constant.FileTypeConstant;
import jnpf.emnus.ModuleTypeEnum;
import jnpf.exception.DataException;
import jnpf.file.FileApi;
import jnpf.model.ExportModel;
import jnpf.database.util.*;
import jnpf.util.*;
import jnpf.util.enums.DictionaryDataEnum;
import jnpf.util.treeutil.SumTree;
import jnpf.util.treeutil.TreeDotUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import jakarta.validation.Valid;
import java.util.*;
 
/**
 * 数据接口
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
 * @date 2021-03-15 10:29
 */
@Tag(name = "数据接口", description = "DataInterface")
@RestController
@RequestMapping(value = "/DataInterface")
public class DataInterfaceController extends SuperController<DataInterfaceService, DataInterfaceEntity> implements DataInterFaceApi {
    @Autowired
    private DataInterfaceService dataInterfaceService;
    @Autowired
    private DictionaryDataService dictionaryDataService;
    @Autowired
    private DictionaryTypeService dictionaryTypeService;
    @Autowired
    private FileApi fileApi;
 
    @Autowired
    private ConfigValueUtil configValueUtil;
    @Autowired
    private InterfaceOauthService interfaceOauthService;
 
    /**
     * 获取接口列表(分页)
     *
     * @param pagination 分页模型
     * @return
     */
    @Operation(summary = "获取接口列表(分页)")
    @SaCheckPermission("dataCenter.dataInterface")
    @GetMapping
    public ActionResult<PageListVO<DataInterfaceListVO>> getList(PaginationDataInterface pagination) {
        List<DataInterfaceEntity> data = dataInterfaceService.getList(pagination, 0);
        List<DataInterfaceListVO> list = JsonUtil.getJsonToList(data, DataInterfaceListVO.class);
        // 添加tenantId字段
        for (DataInterfaceListVO vo : list) {
            // 类别转换
            if ("1".equals(vo.getType())) {
                vo.setType("SQL操作");
            } else if ("2".equals(vo.getType())) {
                vo.setType("静态数据");
            } else if ("3".equals(vo.getType())) {
                vo.setType("API操作");
            }
            if (StringUtil.isNotEmpty(UserProvider.getUser().getTenantId())) {
                vo.setTenantId(UserProvider.getUser().getTenantId());
            }
        }
        PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
        return ActionResult.page(list, paginationVO);
    }
 
    /**
     * 获取接口列表(工作流选择时调用)
     *
     * @param pagination 分页参数
     * @return ignore
     */
    @Operation(summary = "获取接口列表(工作流选择时调用)")
    @GetMapping("/getList")
    public ActionResult<PageListVO<DataInterfaceGetListVO>> getLists(PaginationDataInterfaceSelector pagination) {
        List<DataInterfaceEntity> data = dataInterfaceService.getList(pagination);
        List<DataInterfaceGetListVO> list = JsonUtil.getJsonToList(data, DataInterfaceGetListVO.class);
        for (DataInterfaceGetListVO vo : list) {
            // 类别转换
            if ("1".equals(vo.getType())) {
                vo.setType("SQL操作");
            } else if ("2".equals(vo.getType())) {
                vo.setType("静态数据");
            } else if ("3".equals(vo.getType())) {
                vo.setType("API操作");
            }
        }
        PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
        return ActionResult.page(list, paginationVO);
    }
 
    /**
     * 获取接口列表下拉框
     *
     * @return
     */
    @Operation(summary = "获取接口列表下拉框")
    @GetMapping("/Selector")
    public ActionResult<List<DataInterfaceTreeVO>> getSelector() {
        List<DataInterfaceTreeModel> tree = new ArrayList<>();
        List<DataInterfaceEntity> data = dataInterfaceService.getList(false);
        List<DictionaryDataEntity> dataEntityList = dictionaryDataService.getList(dictionaryTypeService.getInfoByEnCode(DictionaryDataEnum.SYSTEM_DATAINTERFACE.getDictionaryTypeId()).getId());
        // 获取数据接口外层菜单
        for (DictionaryDataEntity dictionaryDataEntity : dataEntityList) {
            DataInterfaceTreeModel firstModel = JsonUtil.getJsonToBean(dictionaryDataEntity, DataInterfaceTreeModel.class);
            firstModel.setId(dictionaryDataEntity.getId());
            firstModel.setCategory("0");
            long num = data.stream().filter(t -> t.getCategory().equals(dictionaryDataEntity.getId())).count();
            if (num > 0) {
                tree.add(firstModel);
            }
        }
        for (DataInterfaceEntity entity : data) {
            DataInterfaceTreeModel treeModel = JsonUtil.getJsonToBean(entity, DataInterfaceTreeModel.class);
            treeModel.setCategory("1");
            treeModel.setParentId(entity.getCategory());
            treeModel.setId(entity.getId());
            DictionaryDataEntity dataEntity = dictionaryDataService.getInfo(entity.getCategory());
            if (dataEntity != null) {
                tree.add(treeModel);
            }
        }
        List<SumTree<DataInterfaceTreeModel>> sumTrees = TreeDotUtils.convertListToTreeDot(tree);
        List<DataInterfaceTreeVO> list = JsonUtil.getJsonToList(sumTrees, DataInterfaceTreeVO.class);
        ListVO<DataInterfaceTreeVO> vo = new ListVO<>();
        vo.setList(list);
        return ActionResult.success(list);
    }
 
    /**
     * 获取接口参数列表下拉框
     *
     * @param id 主键
     * @return ignore
     */
    @Operation(summary = "获取接口参数列表下拉框")
    @Parameter(name = "id", description = "主键", required = true)
    @SaCheckPermission("dataCenter.dataInterface")
    @GetMapping("/GetParam/{id}")
    public ActionResult<List<DataInterfaceModel>> getSelector(@PathVariable("id") String id) {
        DataInterfaceEntity entity = dataInterfaceService.getInfo(id);
        if (entity!=null) {
            String parameterJson = entity.getParameterJson();
            List<DataInterfaceModel> jsonToList = JsonUtil.getJsonToList(parameterJson, DataInterfaceModel.class);
            return ActionResult.success(jsonToList == null ? new ArrayList<>() : jsonToList);
        }
        return ActionResult.fail(MsgCode.FA001.get());
    }
 
    /**
     * 获取接口数据
     *
     * @param id 主键
     * @return
     */
    @Operation(summary = "获取接口数据")
    @Parameter(name = "id", description = "主键", required = true)
    @SaCheckPermission("dataCenter.dataInterface")
    @GetMapping("/{id}")
    public ActionResult<DataInterfaceVo> getInfo(@PathVariable("id") String id) throws DataException {
        DataInterfaceEntity entity = dataInterfaceService.getInfo(id);
        DataInterfaceVo vo = JsonUtil.getJsonToBean(entity, DataInterfaceVo.class);
        return ActionResult.success(vo);
    }
 
    /**
     * 添加接口
     *
     * @param dataInterfaceCrForm 实体模型
     * @return
     */
    @Operation(summary = "添加接口")
    @Parameter(name = "dataInterfaceCrForm", description = "实体模型", required = true)
    @SaCheckPermission("dataCenter.dataInterface")
    @PostMapping
    public ActionResult create(@RequestBody @Valid DataInterfaceCrForm dataInterfaceCrForm) throws DataException {
        DataInterfaceEntity entity = JsonUtil.getJsonToBean(dataInterfaceCrForm, DataInterfaceEntity.class);
        // 判断是否有敏感字
        String containsSensitive = containsSensitive(entity);
        if (StringUtil.isNotEmpty(containsSensitive)) {
            return ActionResult.fail(MsgCode.SYS006.get(containsSensitive));
        }
        if (dataInterfaceService.isExistByFullNameOrEnCode(entity.getId(), entity.getFullName(), null)) {
            return ActionResult.fail(MsgCode.EXIST001.get());
        }
        if (dataInterfaceService.isExistByFullNameOrEnCode(entity.getId(), null, entity.getEnCode())) {
            return ActionResult.fail(MsgCode.EXIST002.get());
        }
        dataInterfaceService.create(entity);
        return ActionResult.success(MsgCode.SYS005.get());
    }
 
    /**
     * 判断是否有敏感字
     *
     * @param entity
     * @return
     */
    private String containsSensitive(DataInterfaceEntity entity) {
        // 判断是否有敏感字
        if (entity.getType() == 1 && (entity.getAction() != null && entity.getAction() == 3)) {
            DataConfigJsonModel dataConfigJsonModel = JsonUtil.getJsonToBean(entity.getDataConfigJson(), DataConfigJsonModel.class);
            String sql = dataConfigJsonModel.getSqlData().getSql();
            if (StringUtil.isNotEmpty(sql)) {
                return ParameterUtil.checkContainsSensitive(sql, DbSensitiveConstant.SENSITIVE);
            }
        }
        return "";
    }
 
    /**
     * 修改接口
     *
     * @param dataInterfaceUpForm 实体模型
     * @param id 主键
     * @return
     */
    @Operation(summary = "修改接口")
    @Parameters({
            @Parameter(name = "dataInterfaceUpForm", description = "实体模型", required = true),
            @Parameter(name = "id", description = "主键", required = true)
    })
    @SaCheckPermission("dataCenter.dataInterface")
    @PutMapping("/{id}")
    public ActionResult update(@RequestBody @Valid DataInterfaceUpForm dataInterfaceUpForm, @PathVariable("id") String id) throws DataException {
        DataInterfaceEntity entity = JsonUtilEx.getJsonToBeanEx(dataInterfaceUpForm, DataInterfaceEntity.class);
        // 判断是否有敏感字
        String containsSensitive = containsSensitive(entity);
        if (StringUtil.isNotEmpty(containsSensitive)) {
            return ActionResult.fail(MsgCode.SYS006.get(containsSensitive));
        }
        if (dataInterfaceService.isExistByFullNameOrEnCode(id, entity.getFullName(), null)) {
            return ActionResult.fail(MsgCode.EXIST001.get());
        }
        if (dataInterfaceService.isExistByFullNameOrEnCode(id, null, entity.getEnCode())) {
            return ActionResult.fail(MsgCode.EXIST002.get());
        }
        boolean flag = dataInterfaceService.update(entity, id);
        if (!flag) {
            return ActionResult.fail(MsgCode.FA001.get());
        }
        return ActionResult.success(MsgCode.SU004.get());
    }
 
    /**
     * 删除接口
     *
     * @param id 主键
     * @return
     */
    @Operation(summary = "删除接口")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true)
    })
    @SaCheckPermission("dataCenter.dataInterface")
    @DeleteMapping("/{id}")
    public ActionResult delete(@PathVariable String id) {
        DataInterfaceEntity entity = dataInterfaceService.getInfo(id);
        if (entity != null) {
            dataInterfaceService.delete(entity);
            return ActionResult.success(MsgCode.SU003.get());
        }
        return ActionResult.fail(MsgCode.FA001.get());
    }
 
    /**
     * 更新接口状态
     *
     * @param id 主键
     * @return
     */
    @Operation(summary = "更新接口状态")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true)
    })
    @SaCheckPermission("dataCenter.dataInterface")
    @PutMapping("/{id}/Actions/State")
    public ActionResult update(@PathVariable("id") String id) throws DataException {
        DataInterfaceEntity entity = dataInterfaceService.getInfo(id);
        if (entity != null) {
            if (entity.getEnabledMark() == 0) {
                entity.setEnabledMark(1);
            } else {
                entity.setEnabledMark(0);
            }
            dataInterfaceService.update(entity, id);
            return ActionResult.success(MsgCode.SU014.get());
        }
        return ActionResult.fail(MsgCode.FA001.get());
    }
 
    /**
     * 获取接口分页数据
     *
     * @param id 主键
     * @param page 分页参数
     * @return
     */
    @Override
    @Operation(summary = "获取接口分页数据")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
            @Parameter(name = "page", description = "分页参数", required = true)
    })
    @PostMapping("/{id}/Actions/List")
    public ActionResult infoToIdPageList(@PathVariable("id") String id, @RequestBody DataInterfacePage page) {
        ActionResult result = dataInterfaceService.infoToIdPageList(id, page);
        return result;
    }
 
//    /**
//     * 获取接口详情数据
//     *
//     * @param id 主键
//     * @param page 分页参数
//     * @return
//     */
//    @Operation(summary = "获取接口详情数据")
//    @Parameters({
//            @Parameter(name = "id", description = "主键", required = true)
//    })
//    @GetMapping("/{id}/Actions/Info")
//    public ActionResult info(@PathVariable("id") String id, DataInterfacePage page) {
//        Map<String, Object> data = dataInterfaceService.infoToInfo(id, page);
//        return ActionResult.success(data);
//    }
 
    /**
     * 获取接口详情数据
     *
     * @param id 主键
     * @param page 分页参数
     * @return
     */
    @Override
    @Operation(summary = "获取接口详情数据")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
            @Parameter(name = "page", description = "分页参数", required = true)
    })
    @PostMapping("/{id}/Actions/InfoByIds")
    public ActionResult<List<Map<String, Object>>> infoByIds(@PathVariable("id") String id, @RequestBody DataInterfacePage page) {
        List<Map<String, Object>> data = dataInterfaceService.infoToInfo(id, page);
        return ActionResult.success(data);
    }
 
    @Override
    @PostMapping("/getInterfaceList")
    public List<DataInterfaceEntity> getInterfaceList(@RequestBody List<String> id) {
        return dataInterfaceService.getList(id);
    }
 
    /**
     * 测试接口
     *
     * @param id 主键
     * @param objectMap 参数、参数值对象
     * @return
     */
    @Operation(summary = "测试接口")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
            @Parameter(name = "objectMap", description = "参数、参数值对象")
    })
    @PostMapping("/{id}/Actions/Preview")
    @NoDataSourceBind
    public ActionResult callPreview(@PathVariable("id") String id, @RequestBody(required = false) Map<String, Object> objectMap) {
        DataInterfaceParamModel model = JsonUtil.getJsonToBean(objectMap, DataInterfaceParamModel.class);
        Map<String, String> map = null;
        if (model != null) {
            if (configValueUtil.isMultiTenancy()) {
                //切换成租户库
                try{
                    TenantDataSourceUtil.switchTenant(model.getTenantId());
                }catch (Exception e){
                    return ActionResult.fail(ActionResultCode.SessionOverdue.getMessage());
                }
            }
            if (model.getParamList() != null && model.getParamList().size() > 0) {
                map = new HashMap<>(16);
                List<DataInterfaceModel> jsonToList = JsonUtil.getJsonToList(model.getParamList(), DataInterfaceModel.class);
                dataInterfaceService.paramSourceTypeReplaceValue(jsonToList, map);
            }
        }
        ActionResult actionResult = dataInterfaceService.infoToId(id, null, map);
        if (actionResult.getCode() == 200) {
            actionResult.setMsg(MsgCode.SYS007.get());
        }
        return actionResult;
    }
 
    /**
     * 访问接口GET
     *
     * @param id 主键
     * @param map 参数、参数值对象
     * @return
     */
    @Operation(summary = "访问接口GET")
    @GetMapping("/{id}/Actions/Response")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
            @Parameter(name = "map", description = "参数、参数值对象")
    })
    @NoDataSourceBind
    public ActionResult getResponse(@PathVariable("id") String id,@RequestParam(required = false) Map<String,String> map) {
        DataInterfaceActionModel entity;
        try{
            entity= dataInterfaceService.checkParams(map);
            entity.setInvokType("GET");
        }catch (Exception e){
            return ActionResult.fail(e.getMessage());
        }
        String name = null;
        if (configValueUtil.isMultiTenancy()) {
            //切换成租户库
            try{
                TenantDataSourceUtil.switchTenant(entity.getTenantId());
            }catch (Exception e){
                return ActionResult.fail(ActionResultCode.SessionOverdue.getMessage());
            }
        }
        return dataInterfaceService.infoToIdNew(id, name, entity);
    }
 
    /**
     * 访问接口POST
     *
     * @param id 主键
     * @param map 参数、参数值对象
     * @return
     */
    @Operation(summary = "访问接口POST")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
            @Parameter(name = "map", description = "参数、参数值对象")
    })
    @PostMapping("/{id}/Actions/Response")
    @NoDataSourceBind
    public ActionResult postResponse(@PathVariable("id") String id, @RequestBody(required = false) Map<String,String> map) {
        DataInterfaceActionModel entity;
        try{
            entity= dataInterfaceService.checkParams(map);
            entity.setInvokType("POST");
        }catch (Exception e){
            return ActionResult.fail(e.getMessage());
        }
        String name = null;
        if (configValueUtil.isMultiTenancy()) {
            //切换成租户库
            try{
                TenantDataSourceUtil.switchTenant(entity.getTenantId());
            }catch (Exception e){
                return ActionResult.fail(ActionResultCode.SessionOverdue.getMessage());
            }
        }
        return dataInterfaceService.infoToIdNew(id, name, entity);
    }
 
    /**
     * 外部接口获取authorization
     *
     * @param appId 应用id
     * @param intefaceId 接口id
     * @param map 参数、参数值对象
     * @return
     */
    @Operation(summary = "外部接口获取authorization")
    @Parameters({
            @Parameter(name = "appId", description = "应用id", required = true),
            @Parameter(name = "intefaceId", description = "接口id"),
            @Parameter(name = "map", description = "参数、参数值对象")
    })
    @PostMapping("/Actions/GetAuth")
    @NoDataSourceBind
    public ActionResult getAuthorization(@RequestParam("appId") String appId,@RequestParam("intefaceId") String intefaceId, @RequestBody(required = false) Map<String,String> map) {
        InterfaceOauthEntity infoByAppId = interfaceOauthService.getInfoByAppId(appId);
        if(infoByAppId==null){
            return ActionResult.fail(MsgCode.SYS127.get());
        }
        Map<String, String> authorization = InterfaceUtil.getAuthorization(intefaceId,appId,infoByAppId.getAppSecret(), map);
        return ActionResult.success(MsgCode.SU005.get(),authorization);
    }
 
    @Override
    @GetMapping("/getDataInterfaceInfo")
    @NoDataSourceBind
    public DataInterfaceEntity getDataInterfaceInfo(@RequestParam("id") String id, @RequestParam("tenantId") String tenantId) {
        // 判断是否为多租户
        if (configValueUtil.isMultiTenancy()) {
            //切换成租户库
            try{
                TenantDataSourceUtil.switchTenant(tenantId);
            }catch (Exception e){
                throw new RuntimeException("切换租户失败");
            }
        }
        return dataInterfaceService.getInfo(id);
    }
 
    @Override
    @PostMapping("/infoToIdById/{id}")
    public ActionResult infoToIdById(@PathVariable("id") String id, @RequestBody Map<String, String> parameterMap) {
        return dataInterfaceService.infoToId(id,null, parameterMap);
    }
 
    @Override
    @PostMapping("/infoToId/{id}")
    public ActionResult infoToId(@PathVariable("id") String id) {
        return dataInterfaceService.infoToId(id,null,null);
    }
 
    @Override
    @NoDataSourceBind
    @PostMapping("/invokeById")
    public ActionResult invokeById(@RequestBody DataInterfaceInvokeModel dataInterfaceInvokeModel) {
        // 判断是否为多租户
        if (configValueUtil.isMultiTenancy()) {
            //切换成租户库
            try{
                TenantDataSourceUtil.switchTenant(dataInterfaceInvokeModel.getTenantId());
            }catch (Exception e){
                return ActionResult.fail(ActionResultCode.SessionOverdue.getMessage());
            }
        }
        return dataInterfaceService.infoToId(dataInterfaceInvokeModel.getId(),dataInterfaceInvokeModel.getTenantId(),
                dataInterfaceInvokeModel.getMap(), dataInterfaceInvokeModel.getToken(),
                null ,null, dataInterfaceInvokeModel.getPagination(), dataInterfaceInvokeModel.getShowMap());
    }
 
    /**
     * 数据接口导出功能
     *
     * @param id 接口id
     */
    @Operation(summary = "导出数据接口数据")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true)
    })
    @SaCheckPermission("dataCenter.dataInterface")
    @GetMapping("/{id}/Actions/Export")
    public ActionResult exportFile(@PathVariable("id") String id) {
        DataInterfaceEntity entity = dataInterfaceService.getInfo(id);
        //导出文件
        DownloadVO downloadVO = fileApi.exportFile(new ExportModel(entity, FileTypeConstant.TEMPORARY, UserProvider.getUser() != null ? UserProvider.getUser().getId() : "", entity.getFullName(), ModuleTypeEnum.SYSTEM_DATAINTEFASE.getTableName()));
        return ActionResult.success(downloadVO);
    }
 
    /**
     * 数据接口导入功能
     *
     * @param multipartFile
     * @return
     * @throws DataException
     */
    @Operation(summary = "数据接口导入功能")
    @SaCheckPermission("dataCenter.dataInterface")
    @PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ActionResult importFile(@RequestPart("file") MultipartFile multipartFile,
                                   @RequestParam("type") Integer type) throws DataException {
        //判断是否为.json结尾
        if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.SYSTEM_DATAINTEFASE.getTableName())) {
            return ActionResult.fail(MsgCode.IMP002.get());
        }
        try {
            //读取文件内容
            String fileContent = FileUtil.getFileContent(multipartFile);
            DataInterfaceEntity entity = JsonUtil.getJsonToBean(fileContent, DataInterfaceEntity.class);
            // 验证数据是否正常
            if (dictionaryDataService.getInfo(entity.getCategory()) == null) {
                return ActionResult.fail(MsgCode.IMP004.get());
            }
            StringJoiner stringJoiner = new StringJoiner("、");
            QueryWrapper<DataInterfaceEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(DataInterfaceEntity::getId, entity.getId());
            if (dataInterfaceService.count(queryWrapper) > 0) {
                if (Objects.equals(type, 0)) {
                    stringJoiner.add("ID");
                } else {
                    entity.setId(RandomUtil.uuId());
                }
            }
            queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(DataInterfaceEntity::getEnCode, entity.getEnCode());
            if (dataInterfaceService.count(queryWrapper) > 0) {
                stringJoiner.add(MsgCode.IMP009.get());
            }
            queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(DataInterfaceEntity::getFullName, entity.getFullName());
            if (dataInterfaceService.count(queryWrapper) > 0) {
                stringJoiner.add(MsgCode.IMP008.get());
            }
            if (stringJoiner.length() > 0 && ObjectUtil.equal(type, 1)) {
                String copyNum = UUID.randomUUID().toString().substring(0, 5);
                entity.setFullName(entity.getFullName() + ".副本" + copyNum);
                entity.setEnCode(entity.getEnCode() + copyNum);
            } else if (ObjectUtil.equal(type, 0) && stringJoiner.length() > 0) {
                return ActionResult.fail(stringJoiner.toString() + MsgCode.IMP007.get());
            }
            entity.setCreatorTime(new Date());
            entity.setCreatorUserId(UserProvider.getLoginUserId());
            entity.setLastModifyTime(null);
            entity.setLastModifyUserId(null);
            try {
                dataInterfaceService.setIgnoreLogicDelete().removeById(entity);
                entity.setEnabledMark(0);
                dataInterfaceService.setIgnoreLogicDelete().saveOrUpdate(entity);
            } catch (Exception e) {
                throw new DataException(MsgCode.IMP003.get());
            }finally {
                dataInterfaceService.clearIgnoreLogicDelete();
            }
            return ActionResult.success(MsgCode.IMP001.get());
        } catch (Exception e) {
            return ActionResult.fail(MsgCode.IMP004.get());
        }
    }
 
 
    /**
     * 获取接口字段
     *
     * @param id 主键
     * @param objectMap 参数、参数值
     * @return
     */
    @Operation(summary = "获取接口字段")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
            @Parameter(name = "objectMap", description = "参数、参数值")
    })
    @PostMapping("/{id}/Actions/GetFields")
    public ActionResult getFields(@PathVariable("id") String id, @RequestBody(required = false) Map<String, Object> objectMap) {
        DataInterfacePage model = JsonUtil.getJsonToBean(objectMap, DataInterfacePage.class);
        ActionResult actionResult = dataInterfaceService.infoToIdPageList(id, model);
        if (actionResult.getCode() == 200) {
            try{
                Object data = actionResult.getData();
                if (data instanceof List) {
                    List<Map<String,Object>> list=(List)data;
                    List<String> listKey=new ArrayList();
                    for(String key:list.get(0).keySet()){
                        listKey.add(key);
                    }
                    actionResult.setData(listKey);
                }else{
                    Map<String,Object> map=JsonUtil.stringToMap(JSONObject.toJSONString(data, SerializerFeature.WriteMapNullValue));
                    List<Map<String,Object>> list=(List)map.get("list");
                    List<String> listKey=new ArrayList();
                    for(String key:list.get(0).keySet()){
                        listKey.add(key);
                    }
                    actionResult.setData(listKey);
                }
            }catch (Exception e){
                return ActionResult.fail(MsgCode.SYS008.get());
            }
        }
        return actionResult;
    }
    /**
     * 复制数据接口
     *
     * @param id 数据接口ID
     * @return 执行结构
     * @throws DataException ignore
     */
    @Operation(summary = "复制数据接口")
    @Parameters({
            @Parameter(name = "id", description = "数据接口ID", required = true)
    })
    @SaCheckPermission("dataCenter.dataInterface")
    @PostMapping("/{id}/Actions/Copy")
    public ActionResult<?> Copy(@PathVariable("id") String id) throws DataException {
        String copyNum = UUID.randomUUID().toString().substring(0, 5);
        DataInterfaceEntity entity = dataInterfaceService.getInfo(id);
        entity.setFullName(entity.getFullName() + ".副本" + copyNum);
        if(entity.getFullName().length() > 50) return ActionResult.fail(MsgCode.COPY001.get());
        entity.setEnCode(entity.getEnCode() + copyNum);
        entity.setEnabledMark(0);
        dataInterfaceService.create(entity);
        return ActionResult.success(MsgCode.SU007.get());
    }
 
    @Override
    @GetMapping("/getEntity")
    public DataInterfaceEntity getEntity(@RequestParam("id") String id) {
        return dataInterfaceService.getInfo(id);
    }
}