liujie
2025-07-11 c3892d8e7378ea9441689ebe7009b3e02160b7a1
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
package com.panzhihua.westcommittee.api;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.west.SystemUserVo;
import com.panzhihua.westcommittee.model.entity.*;
import com.panzhihua.westcommittee.model.query.AnalyticStatisticsQuery;
import com.panzhihua.westcommittee.model.vo.*;
import com.panzhihua.westcommittee.service.*;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.validation.Valid;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 分析统计 前端控制器
 * </p>
 *
 * @author 
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/analytic-statistics")
@Validated
public class AnalyticStatisticsController extends BaseController {
 
    @Autowired
    private IComplaintService complaintService;
 
    @Autowired
    private ISystemUserLevelService systemUserLevelService;
 
    @Resource
    private IBcRegionService bcRegionService;
 
    @Resource
    private IComStreetService comStreetService;
 
    @Resource
    private IComActService comActService;
 
    @Resource
    private ISystemUserService iSystemUserService;
 
 
 
    @PostMapping("/data")
    @ApiOperation(value = "分析统计", tags = {"西区纪委后台-分析统计"})
    public R<AnalyticStatisticsDataVo> data(@Valid @RequestBody AnalyticStatisticsQuery query){
        SystemUserVo loginUserInfo = getLoginUserInfoWest();
        Integer id = loginUserInfo.getId();
        SystemUser systemUser = iSystemUserService.getById(id);
        Integer accountLevel = systemUser.getAccountLevel();
        LambdaQueryWrapper<Complaint> wrapper = new LambdaQueryWrapper<>();
        if(query.getDistrictCode()!=null){
            // 没有市权限 也没有该区权限
            if(accountLevel!=2){
                throw new ServiceException("没有该区县权限");
            }
            wrapper.eq(Complaint::getSuperiorId, query.getDistrictCode());
        }
        if(query.getStreetId()!=null){
            // 获取街道上一级查看是否有上级权限
            ComStreet comStreet = comStreetService.getById(query.getStreetId());
            if(comStreet==null){
                throw new ServiceException("没有该街道权限");
            }
            // 没有市级 上级区县  本级街道权限
            if(accountLevel==2 || (accountLevel==3 && systemUser.getDistrictsCode().equals(query.getDistrictCode().toString()))){
                wrapper.eq(Complaint::getSuperiorId, query.getStreetId());
            }else {
                throw new ServiceException("没有该街道权限");
            }
 
        }
        if(query.getCommunityId()!=null){
 
            ComAct comAct = comActService.getById(query.getCommunityId());
            if (comAct == null) {
                throw new ServiceException("没有该社区权限");
            }
 
            // 判断是否有上面的4个权限
            if(accountLevel==2 ||  (accountLevel==3 && systemUser.getDistrictsCode().equals(comAct.getStreetId().toString()) || accountLevel==4 && systemUser.getCommunityId().equals(comAct.getCommunityId()))){
                wrapper.eq(Complaint::getSuperiorId, query.getCommunityId());
            }else {
                throw new ServiceException("没有该社区权限");
            }
        }
 
        // 都为空 查他有的
        if(query.getCityCode()==null && query.getDistrictCode()==null && query.getStreetId()==null && query.getCommunityId()==null){
            if(systemUser.getSystemRoleId()==1 || systemUser.getSystemRoleId()==2){
                if(systemUser.getSystemRoleId()==1){
                    wrapper.ne(Complaint::getProblemType,"纪委").or(w->w.isNull(Complaint::getProblemType));
                }
                if(accountLevel==3){
                    String streetId = systemUser.getStreetId();
                    List<Long> ids = comActService.list(new LambdaQueryWrapper<ComAct>().eq(ComAct::getStreetId, streetId)).stream().map(ComAct::getCommunityId).collect(Collectors.toList());
                    wrapper.eq(Complaint::getNowLevel,systemUser.getAccountLevel()).or(wrapper1 ->wrapper1.in(Complaint::getSuperiorId,ids).eq(Complaint::getNowLevel,4));
                }
                if(accountLevel==4){
                    wrapper.eq(Complaint::getNowLevel,systemUser.getAccountLevel());
                }
            }else {
                wrapper.eq(Complaint::getNowLevel,systemUser.getAccountLevel())
                        .eq(Complaint::getAssignPersonId,systemUser.getOneDepartmentId());
            }
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<Complaint> complaints =complaintService.list(wrapper);
        // 第一部分数据
        AnalyticStatisticsOneVo analyticStatisticsOneVo = complaintService.analyticStatisticsOne(query,complaints,simpleDateFormat,systemUser.getAccountLevel());
 
        // 第二部分数据
        List<AnalyticStatisticsTwoVo> analyticStatisticsTwoVos =complaintService.analyticStatisticsTwo(query.getTime(),complaints,simpleDateFormat);
 
        // 第三部分数据
        List<AnalyticStatisticsThreeVo> analyticStatisticsThreeVos =complaintService.analyticStatisticsThree(query.getRank(), complaints);
 
        // 第四部分数据
        AnalyticStatisticsFourVo analyticStatisticsFourVos =complaintService.analyticStatisticsFour(complaints);
 
        AnalyticStatisticsDataVo analyticStatisticsDataVo = new AnalyticStatisticsDataVo();
        analyticStatisticsDataVo.setAnalyticStatisticsOneVo(analyticStatisticsOneVo);
        analyticStatisticsDataVo.setAnalyticStatisticsTwoVos(analyticStatisticsTwoVos);
        analyticStatisticsDataVo.setAnalyticStatisticsThreeVos(analyticStatisticsThreeVos);
        analyticStatisticsDataVo.setAnalyticStatisticsFourVo(analyticStatisticsFourVos);
 
        return R.ok(analyticStatisticsDataVo);
    }
 
 
 
 
    @GetMapping("/getRegion")
    @ApiOperation(value = "分析统计--获取市-区县-街道-社区", tags = {"西区纪委后台-分析统计--获取市-区县-街道-社区"})
    public R<AnalyticStatisticsRegionVo> getRegion(){
        SystemUserVo loginUserInfo = getLoginUserInfoWest();
        Integer id = loginUserInfo.getId();
 
        SystemUser systemUser = iSystemUserService.getById(id);
        // 如果有区权限  展示所有
        AnalyticStatisticsRegionVo analyticStatisticsRegionVo = new AnalyticStatisticsRegionVo();
        if(systemUser.getAccountLevel()==2){
            // 查询所有的县 街道 社区
            List<ComStreet> list1 = comStreetService.list(new LambdaQueryWrapper<ComStreet>().eq(ComStreet::getAppId, "wx0cef797390444b75"));
            List<ComAct> list2 = comActService.list(new LambdaQueryWrapper<ComAct>().eq(ComAct::getState,0).eq(ComAct::getAppId, "wx0cef797390444b75"));
            analyticStatisticsRegionVo.setComStreets(list1);
            analyticStatisticsRegionVo.setComActs(list2);
            return R.ok(analyticStatisticsRegionVo);
        }
 
        if(systemUser.getAccountLevel()==3){
            // 查询所有的县 街道 社区
            List<ComStreet> list1 = comStreetService.list(new LambdaQueryWrapper<ComStreet>().eq(ComStreet::getStreetId, systemUser.getStreetId()).eq(ComStreet::getAppId, "wx0cef797390444b75"));
            List<ComAct> list2 = comActService.list(new LambdaQueryWrapper<ComAct>().eq(ComAct::getStreetId, systemUser.getStreetId()).eq(ComAct::getState,0).eq(ComAct::getAppId, "wx0cef797390444b75"));
            analyticStatisticsRegionVo.setComStreets(list1);
            analyticStatisticsRegionVo.setComActs(list2);
            return R.ok(analyticStatisticsRegionVo);
        }
 
        if(systemUser.getAccountLevel()==4){
            // 查询所有的县 街道 社区
            List<ComAct> list2 = comActService.list(new LambdaQueryWrapper<ComAct>().eq(ComAct::getCommunityId, systemUser.getCommunityId()).eq(ComAct::getState,0).eq(ComAct::getAppId, "wx0cef797390444b75"));
            analyticStatisticsRegionVo.setComActs(list2);
            return R.ok(analyticStatisticsRegionVo);
        }
 
        return R.ok(analyticStatisticsRegionVo);
 
    }
 
 
    @GetMapping("/getNextRegion")
    @ApiOperation(value = "分析统计--获取下一级树", tags = {"西区纪委后台-分析统计--获取市-区县-街道-社区"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区 传regionCode  街道streetId", required = true, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "1区  2街道", required = true, dataType = "Integer")
    })
    public R<?> getNextRegion(@RequestParam String id, @RequestParam Integer type){
        if(type==1){
            List<ComStreet> list3 = comStreetService.list(new LambdaQueryWrapper<ComStreet>().eq(ComStreet::getAreaCode, id));
            return R.ok(list3);
        }
        if(type==2){
            List<ComAct> list3 = comActService.list(new LambdaQueryWrapper<ComAct>().eq(ComAct::getStreetId, id).eq(ComAct::getState,0));
            return R.ok(list3);
        }
        return R.ok();
    }
 
    @GetMapping("/getLastRegion")
    @ApiOperation(value = "分析统计--获取上级回显", tags = {"西区纪委后台-分析统计--获取市-区县-街道-社区"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "街道streetId 社区 communityId", required = true, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "2街道 3社区", required = true, dataType = "Integer")
    })
    public R<AnalyticStatisticsRegionVo> getLastRegion(@RequestParam String id, @RequestParam Integer type){
        AnalyticStatisticsRegionVo analyticStatisticsRegionVo = new AnalyticStatisticsRegionVo();
        if(type==2){
            ComStreet comStreet = comStreetService.getOne(new LambdaQueryWrapper<ComStreet>().eq(ComStreet::getStreetId, id));
            // 找出这个区县的
            List<BcRegion> list = bcRegionService.list(new LambdaQueryWrapper<BcRegion>().eq(BcRegion::getParentId, 510400).eq(BcRegion::getRegionCode, comStreet.getAreaCode()));
            analyticStatisticsRegionVo.setBcRegions(list);
            return R.ok(analyticStatisticsRegionVo);
        }
        if(type==3){
            ComAct comAct = comActService.getOne(new LambdaQueryWrapper<ComAct>().eq(ComAct::getCommunityId, id));
            // 找出这个区县的
            List<BcRegion> list = bcRegionService.list(new LambdaQueryWrapper<BcRegion>().eq(BcRegion::getParentId, 510400).eq(BcRegion::getRegionCode, comAct.getAreaCode()));
            analyticStatisticsRegionVo.setBcRegions(list);
            List<ComStreet> list3 = comStreetService.list(new LambdaQueryWrapper<ComStreet>().eq(ComStreet::getStreetId, comAct.getStreetId()));
            analyticStatisticsRegionVo.setComStreets(list3);
            return R.ok(analyticStatisticsRegionVo);
        }
        return R.ok();
    }
 
}