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
package com.panzhihua.westcommittee.controller;
 
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.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.west.SystemUserVo;
import com.panzhihua.westcommittee.model.entity.ComAct;
import com.panzhihua.westcommittee.model.entity.ComStreet;
import com.panzhihua.westcommittee.model.entity.Complaint;
import com.panzhihua.westcommittee.model.entity.SystemUser;
import com.panzhihua.westcommittee.model.query.AnalyticStatisticsQuery;
import com.panzhihua.westcommittee.model.query.AppStaticsQuery;
import com.panzhihua.westcommittee.model.vo.*;
import com.panzhihua.westcommittee.service.IComActService;
import com.panzhihua.westcommittee.service.IComStreetService;
import com.panzhihua.westcommittee.service.IComplaintService;
import com.panzhihua.westcommittee.service.IdentityInformationService;
import com.panzhihua.westcommittee.service.impl.StaticsService;
import com.panzhihua.westcommittee.warpper.IdentityInformation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.validation.Valid;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @author mitao
 * @date 2025/5/9
 */
@Api(tags = {"【2.0.1】统计分析相关接口"})
@RestController
@RequestMapping("/applet/statics")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class StaticsController extends BaseController {
    private final StaticsService staticsService;
    private final IdentityInformationService identityInformationService;
    private final IComStreetService comStreetService;
    private final IComActService comActService;
    private final IComplaintService complaintService;
 
    @GetMapping("/region-tree")
    @ApiOperation("获取区域树")
    public R<List<RegionVO>> regionTree() {
        LoginUserInfoVO loginUserInfo = getLoginUserInfo();
        return R.ok(staticsService.queryRegionTree(loginUserInfo));
    }
    @PostMapping("/part-one")
    @ApiOperation("获取统计分析-第一部分(处理满意率+诉求单量统计上面部分)")
    public R<AnalyticStatisticsOneVo> queryStaticsPartOne(@RequestBody AppStaticsQuery query) {
        LoginUserInfoVO loginUserInfo = getLoginUserInfo();
        return R.ok(staticsService.queryStaticsPartOne(query,loginUserInfo));
    }
    @PostMapping("/part-two")
    @ApiOperation("获取统计分析-第二部分(诉求单量统计柱状图)")
    public R<List<AnalyticStatisticsTwoVo>> queryStaticsPartTwo(@RequestBody AppStaticsQuery query) {
        LoginUserInfoVO loginUserInfo = getLoginUserInfo();
        return R.ok(staticsService.queryStaticsPartTwo(query,loginUserInfo));
    }
    @PostMapping("/part-three")
    @ApiOperation("获取统计分析-第三部分(问题类型排名)")
    public R<List<AnalyticStatisticsThreeVo>> queryStaticsPartThree(@RequestBody AppStaticsQuery query) {
        LoginUserInfoVO loginUserInfo = getLoginUserInfo();
        return R.ok(staticsService.queryStaticsPartThree(query,loginUserInfo));
    }
    @PostMapping("/part-four")
    @ApiOperation("获取统计分析-第四部分(评价占比)")
    public R<AnalyticStatisticsFourVo> queryStaticsPartFour(@RequestBody AppStaticsQuery query) {
        LoginUserInfoVO loginUserInfo = getLoginUserInfo();
        return R.ok(staticsService.queryStaticsPartFour(query,loginUserInfo));
    }
 
 
    @PostMapping("/data")
    @ApiOperation(value = "分析统计", tags = {"西区纪委小程序-分析统计"})
    public R<AnalyticStatisticsDataVo> data(@Valid @RequestBody AnalyticStatisticsQuery query){
        LoginUserInfoVO loginUserInfo = getLoginUserInfo();
        IdentityInformation identityInformation = identityInformationService.getIdentityInformation(loginUserInfo);
        SystemUser systemUser = identityInformation.getSystemUser();
        AnalyticStatisticsDataVo analyticStatisticsDataVo = new AnalyticStatisticsDataVo();
        if(systemUser==null || systemUser.getSystemRoleId()>2){
            return R.ok(analyticStatisticsDataVo);
        }
        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.setAnalyticStatisticsOneVo(analyticStatisticsOneVo);
        analyticStatisticsDataVo.setAnalyticStatisticsTwoVos(analyticStatisticsTwoVos);
        analyticStatisticsDataVo.setAnalyticStatisticsThreeVos(analyticStatisticsThreeVos);
        analyticStatisticsDataVo.setAnalyticStatisticsFourVo(analyticStatisticsFourVos);
        return R.ok(analyticStatisticsDataVo);
    }
 
 
}