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();
|
}
|
|
}
|