| | |
| | | |
| | | |
| | | 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.utlis.DateUtils; |
| | | import com.panzhihua.sangeshenbian.model.entity.Complaint; |
| | | import com.panzhihua.common.model.vos.sangeshenbian.SystemUserVo; |
| | | import com.panzhihua.sangeshenbian.model.entity.*; |
| | | import com.panzhihua.sangeshenbian.model.query.AnalyticStatisticsQuery; |
| | | import com.panzhihua.sangeshenbian.model.vo.AnalyticStatisticsOneVo; |
| | | import com.panzhihua.sangeshenbian.model.vo.AnalyticStatisticsThreeVo; |
| | | import com.panzhihua.sangeshenbian.model.vo.AnalyticStatisticsTwoVo; |
| | | import com.panzhihua.sangeshenbian.service.IComplaintService; |
| | | import com.panzhihua.sangeshenbian.model.vo.*; |
| | | import com.panzhihua.sangeshenbian.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.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | 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> |
| | |
| | | @RestController |
| | | @RequestMapping("/analytic-statistics") |
| | | @Validated |
| | | public class AnalyticStatisticsController { |
| | | 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; |
| | | |
| | | |
| | | |
| | | @PostMapping("/data") |
| | | @ApiOperation(value = "分析统计", tags = {"三个身边后台-分析统计"}) |
| | | public R<?> data(@Valid @RequestBody AnalyticStatisticsQuery query){ |
| | | // TODO 判断当前账号的层级 如果包含市级 可以查看所有 包含区县多个 包含镇多个 包含村多个 |
| | | LambdaQueryWrapper<Complaint> wrapper = new LambdaQueryWrapper<Complaint>().eq(Complaint::getCityCode, query.getCityCode()); |
| | | public R<AnalyticStatisticsDataVo> data(@Valid @RequestBody AnalyticStatisticsQuery query){ |
| | | SystemUserVo loginUserInfoSanGeShenBian = getLoginUserInfoSanGeShenBian(); |
| | | Integer id = loginUserInfoSanGeShenBian.getId(); |
| | | List<SystemUserLevel> listBySystemUsers = systemUserLevelService.getListBySystemUserId(id); |
| | | if(listBySystemUsers.size()==0){ |
| | | // 没有权限 |
| | | return R.ok(new AnalyticStatisticsDataVo()); |
| | | } |
| | | LambdaQueryWrapper<Complaint> wrapper = new LambdaQueryWrapper<>(); |
| | | SystemUserLevel systemUserLevel = listBySystemUsers.stream().filter(e -> e.getLevel() == 1).findFirst().orElse(null); |
| | | if(query.getCityCode()!=null){ |
| | | // 判断是否有市级权限 |
| | | if(systemUserLevel==null){ |
| | | throw new ServiceException("没有市级权限"); |
| | | } |
| | | wrapper.eq(Complaint::getCityCode, query.getCityCode()); |
| | | } |
| | | if(query.getDistrictCode()!=null){ |
| | | // 判断是否有区县权限 |
| | | List<SystemUserLevel> systemUserLevels2 = listBySystemUsers.stream().filter(e -> e.getLevel() == 2 && e.getDistrictsCode().equals(query.getDistrictCode().toString())).collect(Collectors.toList()); |
| | | // 没有市权限 也没有该区权限 |
| | | if(systemUserLevels2.size()==0 && systemUserLevel==null){ |
| | | throw new ServiceException("没有该区县权限"); |
| | | } |
| | | wrapper.eq(Complaint::getDistrictsCode, query.getDistrictCode()); |
| | | } |
| | | if(query.getStreetId()!=null){ |
| | | // 获取街道上一级查看是否有上级权限 |
| | | ComStreet comStreet = comStreetService.getById(query.getStreetId()); |
| | | if(comStreet==null){ |
| | | throw new ServiceException("没有该街道权限"); |
| | | } |
| | | List<SystemUserLevel> systemUserLevels2 = listBySystemUsers.stream().filter(e -> e.getLevel() == 2 && e.getDistrictsCode().equals(comStreet.getAreaCode().toString())).collect(Collectors.toList()); |
| | | // 判断是否有街道权限 |
| | | List<SystemUserLevel> systemUserLevels3 = listBySystemUsers.stream().filter(e -> e.getLevel() == 3 && e.getStreetId().equals(query.getStreetId().toString())).collect(Collectors.toList()); |
| | | // 没有市级 上级区县 本级街道权限 |
| | | if(systemUserLevels3.size()==0 && systemUserLevel==null && systemUserLevels2.size()==0){ |
| | | throw new ServiceException("没有该街道权限"); |
| | | } |
| | | wrapper.eq(Complaint::getStreetId, query.getStreetId()); |
| | | } |
| | | if(query.getCommunityId()!=null){ |
| | | |
| | | ComAct comAct = comActService.getById(query.getCommunityId()); |
| | | if (comAct == null) { |
| | | throw new ServiceException("没有该社区权限"); |
| | | } |
| | | // 查看是否有上级街道权限 |
| | | List<SystemUserLevel> systemUserLevels2 = listBySystemUsers.stream().filter(e -> e.getLevel() == 3 && e.getStreetId().equals(comAct.getStreetId().toString())).collect(Collectors.toList()); |
| | | |
| | | // 查看是否有上级区权限 |
| | | List<SystemUserLevel> systemUserLevels3 = listBySystemUsers.stream().filter(e -> e.getLevel() == 2 && e.getDistrictsCode().equals(comAct.getAreaCode())).collect(Collectors.toList()); |
| | | |
| | | // 查看是否有本级权限 |
| | | List<SystemUserLevel> systemUserLevels4 = listBySystemUsers.stream().filter(e -> e.getLevel() == 4 && e.getCommunityId().equals(query.getCommunityId())).collect(Collectors.toList()); |
| | | |
| | | // 判断是否有上面的4个权限 |
| | | if(systemUserLevels4.size()==0 && systemUserLevels3.size()==0 && systemUserLevels2.size()==0 && systemUserLevel==null){ |
| | | throw new ServiceException("没有该社区权限"); |
| | | } |
| | | wrapper.eq(Complaint::getCommunityId, query.getCommunityId()); |
| | | } |
| | | // 都为空 查他有的 |
| | | if(query.getCityCode()==null && query.getDistrictCode()==null && query.getStreetId()==null && query.getCommunityId()==null){ |
| | | // 看是否直接是市级账号 |
| | | if(systemUserLevel==null){ |
| | | List<String> districtsCodes=new ArrayList<>(); |
| | | List<String> streetIds=new ArrayList<>(); |
| | | List<Long> communityIds=new ArrayList<>(); |
| | | // 不是市级 查看是否是区县账号 |
| | | List<SystemUserLevel> systemUserLevels2 = listBySystemUsers.stream().filter(e -> e.getLevel() == 2).collect(Collectors.toList()); |
| | | if(!systemUserLevels2.isEmpty()){ |
| | | // 区县账号 找出code |
| | | districtsCodes = systemUserLevels2.stream().map(SystemUserLevel::getDistrictsCode).collect(Collectors.toList()); |
| | | }else { |
| | | districtsCodes.add("0"); |
| | | } |
| | | |
| | | List<SystemUserLevel> systemUserLevels3 = listBySystemUsers.stream().filter(e -> e.getLevel() == 3).collect(Collectors.toList()); |
| | | if(!systemUserLevels3.isEmpty()){ |
| | | // 街道账号 找出id 且不在上面的区县下的街道 |
| | | List<String> finalDistrictsCodes1 = districtsCodes; |
| | | streetIds = systemUserLevels3.stream().filter(e -> !finalDistrictsCodes1.contains(e.getDistrictsCode())).map(SystemUserLevel::getStreetId).collect(Collectors.toList()); |
| | | }else { |
| | | streetIds.add("0"); |
| | | } |
| | | |
| | | List<SystemUserLevel> systemUserLevels4 = listBySystemUsers.stream().filter(e -> e.getLevel() == 4).collect(Collectors.toList()); |
| | | if(!systemUserLevels4.isEmpty()){ |
| | | // community账号 找出id 且不在上面的街道下的社区 |
| | | List<String> finalStreetIds1 = streetIds; |
| | | List<String> finalDistrictsCodes2 = districtsCodes; |
| | | communityIds = systemUserLevels4.stream().filter(e -> !finalStreetIds1.contains(e.getStreetId()) && !finalDistrictsCodes2.contains(e.getDistrictsCode())).map(SystemUserLevel::getCommunityId).collect(Collectors.toList()); |
| | | }else { |
| | | communityIds.add(0L); |
| | | } |
| | | List<String> finalDistrictsCodes = districtsCodes; |
| | | List<String> finalStreetIds = streetIds; |
| | | List<Long> finalCommunityIds = communityIds; |
| | | wrapper.and(wrapper1 -> { |
| | | wrapper1.in(Complaint::getDistrictsCode, finalDistrictsCodes).or().in(Complaint::getStreetId, finalStreetIds).or().in(Complaint::getCommunityId, finalCommunityIds); |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | |
| | | AnalyticStatisticsOneVo analyticStatisticsOneVo = complaintService.analyticStatisticsOne(query,complaints,simpleDateFormat); |
| | | |
| | | // 第二部分数据 |
| | | List<AnalyticStatisticsTwoVo> analyticStatisticsTwoVos =complaintService.analyticStatisticsTwo(query,complaints,simpleDateFormat); |
| | | List<AnalyticStatisticsTwoVo> analyticStatisticsTwoVos =complaintService.analyticStatisticsTwo(query.getTime(),complaints,simpleDateFormat); |
| | | |
| | | // 第三部分数据 |
| | | List<AnalyticStatisticsThreeVo> analyticStatisticsThreeVos =complaintService.analyticStatisticsThree(query,complaints); |
| | | List<AnalyticStatisticsThreeVo> analyticStatisticsThreeVos =complaintService.analyticStatisticsThree(query.getRank(), complaints); |
| | | |
| | | return R.ok(analyticStatisticsThreeVos); |
| | | // 第四部分数据 |
| | | 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); |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | String beforeDay = DateUtils.getBeforeDay(6); |
| | | System.out.println(beforeDay); |
| | | |
| | | |
| | | @GetMapping("/getRegion") |
| | | @ApiOperation(value = "分析统计--获取市-区县-街道-社区", tags = {"三个身边后台-分析统计--获取市-区县-街道-社区"}) |
| | | public R<AnalyticStatisticsRegionVo> getRegion(){ |
| | | SystemUserVo loginUserInfoSanGeShenBian = getLoginUserInfoSanGeShenBian(); |
| | | Integer id = loginUserInfoSanGeShenBian.getId(); |
| | | List<SystemUserLevel> listBySystemUsers = systemUserLevelService.getListBySystemUserId(id); |
| | | // 如果有市级权限 展示所有 |
| | | SystemUserLevel systemUserLevel = listBySystemUsers.stream().filter(e -> e.getLevel() == 1).findFirst().orElse(null); |
| | | |
| | | AnalyticStatisticsRegionVo analyticStatisticsRegionVo = new AnalyticStatisticsRegionVo(); |
| | | if(systemUserLevel!=null){ |
| | | // 查询所有的县 街道 社区 |
| | | List<BcRegion> list = bcRegionService.list(new LambdaQueryWrapper<BcRegion>().eq(BcRegion::getParentId, 510400)); |
| | | |
| | | List<ComStreet> list1 = comStreetService.list(new LambdaQueryWrapper<ComStreet>().eq(ComStreet::getCityCode, 510400)); |
| | | |
| | | List<ComAct> list2 = comActService.list(new LambdaQueryWrapper<ComAct>().eq(ComAct::getState,0).eq(ComAct::getCityCode, 510400)); |
| | | analyticStatisticsRegionVo.setBcRegions(list); |
| | | analyticStatisticsRegionVo.setComStreets(list1); |
| | | analyticStatisticsRegionVo.setComActs(list2); |
| | | |
| | | return R.ok(analyticStatisticsRegionVo); |
| | | } |
| | | |
| | | // 有区县级权限 |
| | | List<SystemUserLevel> systemUserLevels = listBySystemUsers.stream().filter(e -> e.getLevel() == 2).collect(Collectors.toList()); |
| | | // 拥有的区县code |
| | | List<String> collect = systemUserLevels.stream().map(SystemUserLevel::getDistrictsCode).collect(Collectors.toList()); |
| | | if(collect.size()==0){ |
| | | collect.add("0"); |
| | | } |
| | | // 找出这个区县的 |
| | | List<BcRegion> list = bcRegionService.list(new LambdaQueryWrapper<BcRegion>().eq(BcRegion::getParentId, 510400).in(BcRegion::getRegionCode, collect)); |
| | | // 区县街道 |
| | | List<ComStreet> list1 = comStreetService.list(new LambdaQueryWrapper<ComStreet>().in(ComStreet::getAreaCode, collect)); |
| | | |
| | | // 区县社区 |
| | | List<ComAct> list2 = comActService.list(new LambdaQueryWrapper<ComAct>().in(ComAct::getAreaCode, collect).eq(ComAct::getState,0)); |
| | | |
| | | // 有街道权限 排除上个查询出来的 |
| | | List<SystemUserLevel> systemUserLevels1 = listBySystemUsers.stream().filter(e -> e.getLevel() == 3 && !collect.contains(e.getDistrictsCode())).collect(Collectors.toList()); |
| | | List<String> collect1 = systemUserLevels1.stream().map(SystemUserLevel::getStreetId).collect(Collectors.toList()); |
| | | if(collect1.size()==0){ |
| | | collect1.add("0"); |
| | | } |
| | | |
| | | // 区县街道 |
| | | List<ComStreet> list3 = comStreetService.list(new LambdaQueryWrapper<ComStreet>().in(ComStreet::getStreetId, collect1)); |
| | | |
| | | // 区县社区 |
| | | List<ComAct> list4 = comActService.list(new LambdaQueryWrapper<ComAct>().in(ComAct::getStreetId, collect1).eq(ComAct::getState,0)); |
| | | |
| | | list1.addAll(list3); |
| | | list2.addAll(list4); |
| | | |
| | | // 有社区权限 排除上个查询出来的 |
| | | List<SystemUserLevel> systemUserLevels2 = listBySystemUsers.stream().filter(e -> e.getLevel() == 4 && !collect.contains(e.getDistrictsCode()) && !collect1.contains(e.getStreetId())).collect(Collectors.toList()); |
| | | List<Long> collect2 = systemUserLevels2.stream().map(SystemUserLevel::getCommunityId).collect(Collectors.toList()); |
| | | if(collect2.size()==0){ |
| | | collect2.add(0l); |
| | | } |
| | | |
| | | // 区县社区 |
| | | List<ComAct> list6 = comActService.list(new LambdaQueryWrapper<ComAct>().in(ComAct::getCommunityId, collect2).eq(ComAct::getState,0)); |
| | | list2.addAll(list6); |
| | | |
| | | analyticStatisticsRegionVo.setBcRegions(list); |
| | | analyticStatisticsRegionVo.setComStreets(list1); |
| | | analyticStatisticsRegionVo.setComActs(list2); |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | } |