mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
package com.panzhihua.service_community.api;
 
 
import cn.hutool.core.util.ArrayUtil;
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.apache.commons.lang3.ArrayUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
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,@RequestParam("userId")Long userId){
        Long[] idArray={4L,17959L,16522L,16196L,16214L,17949L,89234L};
        if("panzhihua".equals(name)){
            List<ComAreaCounty> list=comAreaTownCommunityDao.selectArea();
            list.forEach(lis->{
                List<ComAreaCounty> townList=comAreaTownCommunityDao.selectTown(lis.getValue());
                townList.forEach(tow->{
                    List<ComAreaCounty> list1=new ArrayList<>();
                    if(ArrayUtil.contains(idArray,userId)){
                        list1=comAreaTownCommunityDao.selectCommunity(tow.getValue(),"学园社区");
                    }
                    else {
                        list1=comAreaTownCommunityDao.selectCommunity(tow.getValue(),"");
                    }
                    if("大渡口街道".equals(tow.getValue())){
                        ComAreaCounty comAreaCounty=list1.get(0);
                        list1.remove(0);
                        list1.add(2,comAreaCounty);
                    }
                    tow.setChildren(list1);
                });
                lis.setChildren(townList);
            });
            return R.ok(list);
        }
        else {
            List<ComAreaCounty> townList=comAreaTownCommunityDao.selectTown(name);
            if(!CollectionUtils.isEmpty(townList)){
                townList.forEach(tow->{
                    List<ComAreaCounty> list1=new ArrayList<>();
                    if(ArrayUtil.contains(idArray,userId)){
                        list1=comAreaTownCommunityDao.selectCommunity(tow.getValue(),"学园社区");
                    }
                    else {
                        list1=comAreaTownCommunityDao.selectCommunity(tow.getValue(),"");
                    }
                    tow.setChildren(list1);
                });
                return R.ok(townList);
            }
            else {
                List<ComAreaCounty> list1=new ArrayList<>();
                if(ArrayUtil.contains(idArray,userId)){
                    list1=comAreaTownCommunityDao.selectCommunity(name,"学园社区");
                }
                else {
                    list1=comAreaTownCommunityDao.selectCommunity(name,"");
                }
                return R.ok(list1);
            }
        }
 
    }
}