101captain
2022-04-15 8d8ce4f5e0122ace8ce68c1c675950748ef0db2d
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
package com.panzhihua.service_community.api;
 
 
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.dtos.property.CommonPage;
import com.panzhihua.service_community.dao.ComAreaTownCommunityDao;
import com.panzhihua.common.model.vos.community.acid.ComAreaCounty;
import com.panzhihua.service_community.entity.ComAreaTownCommunity;
import com.panzhihua.service_community.service.ComAreaTownCommunityService;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
 
/**
 * (ComAreaTownCommunity)表控制层
 * projectName 成都呐喊信息技术有限公司-智慧社区项目
 * description: 相关功能
 *
 * @author zzj
 * @since 2022-04-10 17:37:33
 */
@RestController
@RequestMapping("comAreaTownCommunity")
public class ComAreaTownCommunityApi {
    /**
     * 服务对象
     */
    @Resource
    private ComAreaTownCommunityService comAreaTownCommunityService;
    @Resource
    private ComAreaTownCommunityDao comAreaTownCommunityDao;
 
    /**
     * 分页查询所有数据
     *
     * @param commonPage 查询实体
     * @return 所有数据
     */
    @PostMapping("queryAll")
    public R selectAll(@RequestBody CommonPage commonPage) {
        return this.comAreaTownCommunityService.pageList(commonPage);
    }
 
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable("id") Serializable id) {
        return R.ok(this.comAreaTownCommunityService.getById(id));
    }
 
    /**
     * 新增数据
     *
     * @param comAreaTownCommunity 实体对象
     * @return 新增结果
     */
    @PostMapping
    public R insert(@RequestBody ComAreaTownCommunity comAreaTownCommunity) {
        return R.ok(this.comAreaTownCommunityService.save(comAreaTownCommunity));
    }
 
    /**
     * 修改数据
     *
     * @param comAreaTownCommunity 实体对象
     * @return 修改结果
     */
    @PostMapping("/update")
    public R update(@RequestBody ComAreaTownCommunity comAreaTownCommunity) {
        return R.ok(this.comAreaTownCommunityService.updateById(comAreaTownCommunity));
    }
 
    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @GetMapping("del")
    public R delete(@RequestParam("id") Long id) {
        return R.ok(this.comAreaTownCommunityService.removeById(id));
    }
 
    @GetMapping("/areaTownCommunity")
    public R test(@RequestParam("name")String name){
        if("panzhihua".equals(name)){
            List<ComAreaCounty> list=comAreaTownCommunityDao.selectArea();
            list.forEach(lis->{
                List<ComAreaCounty> townList=comAreaTownCommunityDao.selectTown(lis.getValue());
                townList.forEach(tow->{
                    tow.setChildren(comAreaTownCommunityDao.selectCommunity(tow.getValue()));
                });
                lis.setChildren(townList);
            });
            return R.ok(list);
        }
        else {
            List<ComAreaCounty> townList=comAreaTownCommunityDao.selectTown(name);
            if(!CollectionUtils.isEmpty(townList)){
                townList.forEach(tow->{
                    tow.setChildren(comAreaTownCommunityDao.selectCommunity(tow.getValue()));
                });
                return R.ok(townList);
            }
            else {
                List<ComAreaCounty> list=comAreaTownCommunityDao.selectCommunity(name);
                return R.ok(list);
            }
        }
 
    }
}