jinlin
2024-12-03 10c858f5e43b37c2db4c1396a8db312cbbdf29a5
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
package com.zt.life.sync.controller;
 
import com.zt.common.annotation.LogOperation;
import com.zt.common.annotation.QueryParam;
import com.zt.common.constant.Constant;
import com.zt.common.db.query.QueryFilter;
import com.zt.common.servlet.PageResult;
import com.zt.common.servlet.Result;
import com.zt.common.validator.AssertUtils;
import com.zt.life.sync.dto.SyncConfigDto;
import com.zt.life.sync.model.SyncConfig;
import com.zt.life.sync.service.SyncConfigService;
import com.zt.life.sync.service.SyncConfigTableService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@RestController
@RequestMapping("/maintain/SyncConfig")
public class SyncConfigController {
 
    @Autowired
    SyncConfigService syncConfigService;
    @Autowired
    SyncConfigTableService syncConfigTableService;
 
    @GetMapping("page")
    @ApiOperation("分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.Q.PAGE, value = Constant.QV.PAGE, required = true, dataType = Constant.QT.INT),
            @ApiImplicitParam(name = Constant.Q.LIMIT, value = Constant.QV.LIMIT, required = true, dataType = Constant.QT.INT),
            @ApiImplicitParam(name = Constant.Q.ORDER_FIELD, value = Constant.QV.ORDER_FIELD, dataType = Constant.QT.STRING),
            @ApiImplicitParam(name = Constant.Q.ORDER, value = Constant.QV.ORDER, dataType = Constant.QT.STRING),
            @ApiImplicitParam(name = "tabledesc", value = "数据表说明", dataType = Constant.QT.STRING, format = "TableDesc^LK"),
            @ApiImplicitParam(name = "src", value = "源", dataType = Constant.QT.STRING, format = "src^EQ"),
            @ApiImplicitParam(name = "dst", value = "目的", dataType = Constant.QT.STRING, format = "dst^EQ") })
    public PageResult<SyncConfigDto> page(@ApiIgnore @QueryParam QueryFilter queryFilter) {
        List<SyncConfigDto> page = syncConfigService.page(queryFilter);
        PageResult<SyncConfigDto> ok = PageResult.ok(page);
        return ok;
    }
 
    @GetMapping("{id}")
    @ApiOperation("信息")
    public Result<SyncConfig> get(@PathVariable("id") Long id) {
        SyncConfig data = syncConfigService.get(id);
 
        return Result.ok(data);
    }
 
    @PostMapping
    @ApiOperation("新增")
    @LogOperation("同步配置--->新增")
    public Result insert(@RequestBody SyncConfigDto syncConfigDto) {
        syncConfigService.insert(syncConfigDto);
        return Result.ok();
    }
 
    @PutMapping
    @ApiOperation("修改")
    @LogOperation("同步配置--->修改")
    public Result update(@RequestBody SyncConfigDto syncConfigDto) {
        syncConfigService.update(syncConfigDto);
        return Result.ok();
    }
 
    @DeleteMapping
    @ApiOperation("删除")
    @LogOperation("同步配置--->删除")
    public Result delete(@RequestBody Long[] ids) {
        // 效验数据
        AssertUtils.isArrayEmpty(ids, "id");
        syncConfigService.deleteLogic(ids);
        if (ids != null && ids.length > 0) {
            Map<String, Object> map = new HashMap<>();
            map.put("sync_config_id", ids[0]);
            syncConfigTableService.deleteByMap(map);
        }
        return Result.ok();
    }
 
    @GetMapping("getTableNameList")
    @ApiOperation("查表名")
    public Result<List<Map<String, String>>> getTableNameList() {
        List<Map<String, String>> resultList = new ArrayList<>();
        List<String> tableNameList = syncConfigService.getTableNameList();
        for (String tableName : tableNameList) {
            Map<String, String> map = new HashMap<>();
            map.put("id", tableName);
            map.put("name", tableName);
            resultList.add(map);
        }
        return Result.ok(resultList);
    }
}