guoshilong
2023-06-21 b37bdc2060e6bd7bf8cb2b2d844fe45a549d210a
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
package cn.gistack.sm.sjztmd.controller;
 
import cn.gistack.sm.exam.entity.ExamPlan;
import cn.gistack.sm.sjztmd.entity.AttAdBase;
import cn.gistack.sm.sjztmd.service.IAttAdBaseService;
import cn.gistack.sm.sjztmd.vo.AttAdBaseVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.node.ForestNodeMerger;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
 
import java.util.List;
import java.util.Map;
 
/**
 * @ClassName AttAdBaseController
 * @Description TODO
 * @Author aix
 * @Date 2023/4/21 20:09
 * @Version 1.0
 */
@Slf4j
@Api(tags = "中台行政区划")
@RestController
@RequestMapping("/sjztmd/attad")
@AllArgsConstructor
public class AttAdBaseController extends BladeController {
 
    private final IAttAdBaseService attAdBaseService;
 
    @ApiOperation(value = "中台行政区划-添加", notes = "中台行政区划-添加")
    @PostMapping(value = "/save")
    public R add(AttAdBase attAdBase) {
        return R.data(attAdBaseService.save(attAdBase));
    }
 
    @ApiOperation(value = "中台行政区划-修改", notes = "中台行政区划-修改")
    @PostMapping(value = "/edit")
    public R edit(AttAdBase attAdBase) {
        return R.data(attAdBaseService.updateById(attAdBase));
    }
 
    @ApiOperation(value = "中台行政区划-添加修改", notes = "中台行政区划-添加修改")
    @PostMapping(value = "/submit")
    public R submit(AttAdBase attAdBase) {
        return R.data(attAdBaseService.saveOrUpdate(attAdBase));
    }
 
    @ApiOperation(value = "中台行政区划-删除", notes = "中台行政区划-删除")
    @GetMapping(value = "/remove")
    public R edit(String guid) {
        return R.data(attAdBaseService.removeById(guid));
    }
 
    @ApiOperation(value = "中台行政区划-查询详情", notes = "中台行政区划-查询详情")
    @GetMapping(value = "/getDetail")
    public R getDetail(AttAdBase attAdBase) {
        AttAdBaseVO one = attAdBaseService.getDetail(attAdBase);
        return R.data(one);
    }
 
    @ApiOperation(value = "中台行政区划-分页列表查询", notes = "中台行政区划-分页列表查询")
    @GetMapping(value = "/list")
    public R queryPageList(AttAdBase attAdBase, Query query) {
        IPage<AttAdBase> pageList = attAdBaseService.page(Condition.getPage(query), Condition.getQueryWrapper(attAdBase));
        return R.data(pageList);
    }
 
    @GetMapping("/select")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "code", value = "区划编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "name", value = "区划名称", paramType = "query", dataType = "string")
    })
    @ApiOperation(value = "加载树列表", notes = "传入code")
    public R<List<AttAdBaseVO>> select(String parentCode, @ApiIgnore @RequestParam Map<String, Object> obj) {
        String code = obj.get("code").toString();
        if (code.substring(0,4).indexOf("00") > -1) {
            obj.put("code",code.substring(0,2));
        } else if (code.substring(0,6).indexOf("00") > -1) {
            obj.put("code",code.substring(0,4));
        }
        List<AttAdBaseVO> list = attAdBaseService.lazyTree(parentCode, obj);
        return R.data(listNodeLazyVO(list));
    }
 
    @GetMapping("/selectAll")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "code", value = "区划编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "name", value = "区划名称", paramType = "query", dataType = "string")
    })
    @ApiOperation(value = "加载树列表", notes = "传入code")
    public R<List<AttAdBaseVO>> selectAll(String parentCode, @ApiIgnore @RequestParam Map<String, Object> obj) {
        if (ObjectUtil.isNotEmpty(obj.get("code"))){
            String code = obj.get("code").toString();
            if (code.substring(0,4).indexOf("00") > -1) {
                obj.put("code",code.substring(0,2));
            } else if (code.substring(0,6).indexOf("00") > -1) {
                obj.put("code",code.substring(0,4));
            } else if (code.substring(0,8).indexOf("00") > -1) {
                obj.put("code",code.substring(0,6));
            }
        }
        List<AttAdBaseVO> list = attAdBaseService.lazyTreeAll(parentCode, obj);
        return R.data(listNodeLazyVO(list));
    }
 
    /**
     * 查询区域菜单树-带层级
     * @param parentCode
     * @param obj
     * @return
     */
    @GetMapping("/selectAttAdBaseTree")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "code", value = "区划编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "name", value = "区划名称", paramType = "query", dataType = "string")
    })
    @ApiOperation(value = "加载树列表", notes = "传入code")
    public R selectAttAdBaseTree(String parentCode, @ApiIgnore @RequestParam Map<String, Object> obj) {
        String code = obj.get("code").toString();
        if (code.substring(0,4).indexOf("00") > -1) {
            obj.put("code",code.substring(0,2));
        } else if (code.substring(0,6).indexOf("00") > -1) {
            obj.put("code",code.substring(0,4));
        }
        // 查询并返回
        return R.data(attAdBaseService.selectAttAdBaseTree(parentCode, obj));
    }
 
    /**
     * 懒加载列表 懒加载待优化
     */
    @GetMapping("/lazy-tree")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "code", value = "区划编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "name", value = "区划名称", paramType = "query", dataType = "string")
    })
    @ApiOperation(value = "懒加载列表", notes = "传入code")
    public R<List<AttAdBaseVO>> lazyTree(String parentCode, @ApiIgnore @RequestParam Map<String, Object> obj) {
        List<AttAdBaseVO> list = attAdBaseService.lazyTree(parentCode, obj);
        return R.data(listNodeLazyVO(list));
    }
 
    private List<AttAdBaseVO> listNodeLazyVO(List<AttAdBaseVO> list) {
        return ForestNodeMerger.merge(list);
    }
 
}