package com.ydtech.modules.admin.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ydtech.modules.admin.dao.SysDeptMapper; import com.ydtech.modules.admin.dao.SysGeographyPositionMapper; import com.ydtech.modules.admin.dao.SysGeographyPositionRecordMapper; import com.ydtech.modules.admin.dao.SysUserMapper; import com.ydtech.modules.admin.model.SysDept; import com.ydtech.modules.admin.model.SysGeographyPosition; import com.ydtech.modules.admin.model.SysGeographyPositionRecord; import com.ydtech.modules.admin.model.SysUser; import com.ydtech.modules.admin.model.dto.*; import com.ydtech.modules.admin.model.vo.*; import com.ydtech.modules.admin.service.GeoService; import com.ydtech.modules.admin.service.SysGeographyPositionRecordService; import com.ydtech.modules.admin.service.SysGeographyPositionService; import com.ydtech.modules.admin.service.SysUserService; import com.ydtech.modules.base.controller.BaseController; import com.ydtech.modules.order.entity.BasePageResult; import com.ydtech.utils.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @Service("SysGeographyPositionService") public class SysGeographyPositionServiceImpl extends ServiceImpl implements SysGeographyPositionService { @Resource private SysGeographyPositionMapper sysGeographyPositionMapper; @Resource private SysGeographyPositionRecordMapper sysGeographyPositionRecordMapper; @Resource private SysGeographyPositionRecordService sysGeographyPositionRecordService; @Resource private SysUserService sysUserService; @Resource private SysDeptMapper sysDeptMapper; @Resource private SysUserMapper sysUserMapper; @Resource private GeoService geoService; private static final String APP_GEO_KEY = "APPLocations"; @Override public SysGeographyPositionVo queryPosition(SysGeographyPositionDto sysGeographyPositionDto) { SysGeographyPositionVo sysGeographyPositionVo = new SysGeographyPositionVo(); String userId = BaseController.getUserId(); List collectIds = new ArrayList<>(); if (!"admin".equals(userId)) { List arrayList = new ArrayList<>(); List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper() .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0)); collectIds = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList()); if (collectIds.size() == 0) return sysGeographyPositionVo; List idList = queryList(collectIds, arrayList); collectIds.addAll(idList); } // 类型:1。机构 2.用户 Integer type = sysGeographyPositionDto.getType(); if (type == 1) { List list = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper() .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict()) .in(SysGeographyPosition::getSource, Arrays.asList("1", "2")) .in(CollectionUtil.isNotEmpty(collectIds), SysGeographyPosition::getId, collectIds) .likeRight(StringUtils.isNotEmpty(sysGeographyPositionDto.getQueryId()), SysGeographyPosition::getId, sysGeographyPositionDto.getQueryId()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getSource()), SysGeographyPosition::getSource, sysGeographyPositionDto.getSource()) .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus()) .orderByDesc(SysGeographyPosition::getCreateTime)); if (list.size() == 0) return new SysGeographyPositionVo(); List sysGeographyPositionList = BeanUtil.copyToList(list, SysGeographyPositionInfoVo.class); //填充机构名 for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionList) { SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId()); if (sysUser == null) continue; sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName()); SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper() .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0)); if (sysDept == null) continue; String deptName = getDeptName(sysUser.getDeptId()); // sysGeographyPositionInfoVo.setDeptName(sysDept.getName()); sysGeographyPositionInfoVo.setDeptName(deptName); } sysGeographyPositionVo.setList(sysGeographyPositionList); }else if (type == 2){ //查询人员下属管理所有人员 List ids = new ArrayList<>(); List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper() .eq(SysUser::getLeaderId, sysGeographyPositionDto.getQueryId()).ne(SysUser::getStatus, 0)); List collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList()); if (collect.size() == 0) return sysGeographyPositionVo; List idList = queryList(collect, ids); collect.addAll(idList); List list = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper() .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict()) .in(SysGeographyPosition::getSource, Arrays.asList("1", "2")) .in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect) .in(CollectionUtil.isNotEmpty(collectIds), SysGeographyPosition::getId, collectIds) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getSource()), SysGeographyPosition::getSource, sysGeographyPositionDto.getSource()) .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus()) .orderByDesc(SysGeographyPosition::getCreateTime)); if (list.size() == 0) return new SysGeographyPositionVo(); List sysGeographyPositionList = BeanUtil.copyToList(list, SysGeographyPositionInfoVo.class); //填充机构名 for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionList) { SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId()); if (sysUser == null) continue; sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName()); SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper() .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0)); if (sysDept == null) continue; String deptName = getDeptName(sysUser.getDeptId()); // sysGeographyPositionInfoVo.setDeptName(sysDept.getName()); sysGeographyPositionInfoVo.setDeptName(deptName); } sysGeographyPositionVo.setList(sysGeographyPositionList); }else { List list = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper() .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict()) .in(SysGeographyPosition::getSource, Arrays.asList("1", "2")) .in(CollectionUtil.isNotEmpty(collectIds), SysGeographyPosition::getId, collectIds) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getSource()), SysGeographyPosition::getSource, sysGeographyPositionDto.getSource()) .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus()) .orderByDesc(SysGeographyPosition::getCreateTime)); if (list.size() == 0) return new SysGeographyPositionVo(); List sysGeographyPositionList = BeanUtil.copyToList(list, SysGeographyPositionInfoVo.class); //填充机构名 for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionList) { SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId()); if (sysUser == null) continue; sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName()); SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper() .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0)); if (sysDept == null) continue; String deptName = getDeptName(sysUser.getDeptId()); // sysGeographyPositionInfoVo.setDeptName(sysDept.getName()); sysGeographyPositionInfoVo.setDeptName(deptName); } sysGeographyPositionVo.setList(sysGeographyPositionList); } return sysGeographyPositionVo; } private List queryList(List collect, List ids) { int size = collect.size(); if (size > 0) { List strings = new ArrayList<>(); for (String id : collect) { List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper() .eq(SysUser::getLeaderId, id).ne(SysUser::getStatus, 0)); // List sysUsers = sysUserMapper.querySourceId(id); if (sysUsers.size() > 0) { List list = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList()); strings.addAll(list); ids.addAll(list); if (collect.indexOf(id) + 1 == size) { queryList(strings, ids); } } } } return ids; } private String getDeptName(String deptId) { StringBuilder stringBuilder = new StringBuilder(); SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper() .eq(SysDept::getId, deptId).eq(SysDept::getDelFlag, 0)); if (StringUtils.isEmpty(sysDept.getComlevel())) { SysDept sysDept5 = sysDeptMapper.selectById(sysDept.getParentId()); if (sysDept5 == null) { stringBuilder.append(sysDept.getName()); }else { SysDept sysDept4 = sysDeptMapper.selectById(sysDept5.getParentId()); if (sysDept4 == null) { stringBuilder.append(sysDept5.getName()).append("-").append(sysDept.getName()); }else { SysDept sysDept3 = sysDeptMapper.selectById(sysDept4.getParentId()); if (sysDept3 == null) { stringBuilder.append(sysDept4.getName()) .append("-").append(sysDept5.getName()).append("-").append(sysDept.getName()); }else { SysDept sysDept2 = sysDeptMapper.selectById(sysDept3.getParentId()); if (sysDept2 == null) { stringBuilder.append(sysDept3.getName()).append("-").append(sysDept4.getName()) .append("-").append(sysDept5.getName()).append("-").append(sysDept.getName()); }else { stringBuilder.append(sysDept2.getName()).append("-").append(sysDept3.getName()) .append("-").append(sysDept4.getName()).append("-").append(sysDept5.getName()).append("-").append(sysDept.getName()); } } } } }else if (sysDept.getComlevel().equals("5")) { SysDept sysDept4 = sysDeptMapper.selectById(sysDept.getParentId()); if (sysDept4 == null) { stringBuilder.append(sysDept.getName()); }else { SysDept sysDept3 = sysDeptMapper.selectById(sysDept4.getParentId()); if (sysDept3 == null) { stringBuilder.append(sysDept4.getName()).append("-").append(sysDept.getName()); }else { SysDept sysDept2 = sysDeptMapper.selectById(sysDept3.getParentId()); if (sysDept2 == null) { stringBuilder.append(sysDept3.getName()).append("-").append(sysDept4.getName()).append("-").append(sysDept.getName()); }else { stringBuilder.append(sysDept2.getName()).append("-").append(sysDept3.getName()).append("-").append(sysDept4.getName()).append("-").append(sysDept.getName()); } } } }else if (sysDept.getComlevel().equals("4")) { SysDept sysDept3 = sysDeptMapper.selectById(sysDept.getParentId()); if (sysDept3 == null) { stringBuilder.append(sysDept.getName()); }else { SysDept sysDept2 = sysDeptMapper.selectById(sysDept3.getParentId()); if (sysDept2 == null) { stringBuilder.append(sysDept3.getName()).append("-").append(sysDept.getName()); }else { stringBuilder.append(sysDept2.getName()).append("-").append(sysDept3.getName()).append("-").append(sysDept.getName()); } } }else if (sysDept.getComlevel().equals("3")) { SysDept sysDept2 = sysDeptMapper.selectById(sysDept.getParentId()); if (sysDept2 == null) { stringBuilder.append(sysDept.getName()); }else { stringBuilder.append(sysDept2.getName()).append("-").append(sysDept.getName()); } }else if (sysDept.getComlevel().equals("2")) { stringBuilder.append(sysDept.getName()); } String s = stringBuilder.toString(); if (s.contains("总部-")) { stringBuilder.replace(0,3,""); } return stringBuilder.toString(); } @Override public BasePageResult queryPositionList(SysGeographyPositionPageDto sysGeographyPositionPageDto) { Page page = new Page<>(sysGeographyPositionPageDto.getPageNum(), sysGeographyPositionPageDto.getPageSize()); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(StringUtils.isNotEmpty(sysGeographyPositionPageDto.getId()), SysGeographyPositionRecord::getUserId, sysGeographyPositionPageDto.getId()); wrapper.orderByDesc(SysGeographyPositionRecord::getCreateTime); Page insOrdersPage = sysGeographyPositionRecordService.page(page, wrapper); List records = insOrdersPage.getRecords(); if (records.size()>0) { for (SysGeographyPositionRecord record : records) { SysUser sysUser = sysUserService.getById(record.getUserId()); if (sysUser == null) continue; record.setLeaderName(sysUser.getLeaderName()); String deptName = getDeptName(sysUser.getDeptId()); record.setDeptName(deptName); } } return new BasePageResult<>(sysGeographyPositionPageDto.getPageNum(), page.getSize(), insOrdersPage.getTotal(), page.getPages(), insOrdersPage.getRecords()); } @Override public SysPcAddressNumVo queryPcNum(SysGeographyPositionDto sysGeographyPositionDto) { SysPcAddressNumVo sysPcAddressNumVo = new SysPcAddressNumVo(); String userId = BaseController.getUserId(); List collect = new ArrayList<>(); if (!"admin".equals(userId)) { List ids = new ArrayList<>(); List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper() .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0)); collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList()); if (collect.size() == 0) return sysPcAddressNumVo; List idList = queryList(collect, ids); collect.addAll(idList); } Long all = sysGeographyPositionMapper.selectCount(new LambdaQueryWrapper() .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict()) .in(SysGeographyPosition::getSource, Arrays.asList("1", "2")) .in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect) .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus())); Long channelNum = sysGeographyPositionMapper.selectCount(new LambdaQueryWrapper() .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict()) .eq(SysGeographyPosition::getSource, 1) .in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect) .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus())); Long proxyNum = sysGeographyPositionMapper.selectCount(new LambdaQueryWrapper() .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict()) .eq(SysGeographyPosition::getSource, 2) .in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect) .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus())); Long onlineNum = sysGeographyPositionMapper.selectCount(new LambdaQueryWrapper() .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict()) .in(SysGeographyPosition::getSource, Arrays.asList("1", "2")) .in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect) .eq(sysGeographyPositionDto.getStatus() == null, SysGeographyPosition::getStatus, 1) .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus())); sysPcAddressNumVo.setAllNum(all); sysPcAddressNumVo.setProxyNum(proxyNum); sysPcAddressNumVo.setChannelNum(channelNum); sysPcAddressNumVo.setOnlineNum(onlineNum); return sysPcAddressNumVo; } @Override public List queryRegionInfo(SysGeographyPositionDto sysGeographyPositionDto) { List regionInfoVos = new ArrayList<>(); //admin 可看所有,其他下只能看下面管理的人员 String userId = BaseController.getUserId(); List collect = new ArrayList<>(); if (!"admin".equals(userId)) { List ids = new ArrayList<>(); List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper() .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0)); collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList()); if (collect.size() == 0) return regionInfoVos; List idList = queryList(collect, ids); collect.addAll(idList); } //全部:null 渠道:1 代理:2 List sysGeographyPositionList = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper() .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity()) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict()) .in(SysGeographyPosition::getSource, Arrays.asList("1", "2")) .in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect) .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getSource()), SysGeographyPosition::getSource, sysGeographyPositionDto.getSource()) .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus())); if (CollectionUtil.isEmpty(sysGeographyPositionList)) return regionInfoVos; Map> map; if (StringUtils.isEmpty(sysGeographyPositionDto.getProvince())) { map = sysGeographyPositionList.stream().collect(Collectors.groupingBy(SysGeographyPosition::getProvince)); } else { if (StringUtils.isNotEmpty(sysGeographyPositionDto.getCity())) { map = sysGeographyPositionList.stream().collect(Collectors.groupingBy(SysGeographyPosition::getDistrict)); } else { map = sysGeographyPositionList.stream().collect(Collectors.groupingBy(SysGeographyPosition::getCity)); } } for (Map.Entry> entry : map.entrySet()) { RegionInfoVo regionInfoVo = new RegionInfoVo(); regionInfoVo.setDistrictName(entry.getKey()); regionInfoVo.setNumber(entry.getValue().size()); regionInfoVos.add(regionInfoVo); } return regionInfoVos; } @Override public List findLocationsWithinRadius(AdressRangeDto adressRangeDto) { geoService.addLocationGeography(list(), APP_GEO_KEY); List nearbyIds = geoService.findNearbyIds(APP_GEO_KEY, adressRangeDto.getLongitude(), adressRangeDto.getLatitude(), adressRangeDto.getRadius()); if (nearbyIds.size() == 0) return new ArrayList<>(); geoService.move(nearbyIds, APP_GEO_KEY); List sysGeographyPositions = listByIds(nearbyIds); List sysGeographyPositionInfoVoList = BeanUtil.copyToList(sysGeographyPositions, SysGeographyPositionInfoVo.class); if (sysGeographyPositionInfoVoList.size() == 0) return sysGeographyPositionInfoVoList; for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionInfoVoList) { SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId()); if (sysUser == null) continue; SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper() .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0)); if (sysDept == null) continue; sysGeographyPositionInfoVo.setDeptName(sysDept.getName()); } return sysGeographyPositionInfoVoList; } @Override public BasePageResult queryPcAddressInfo(PcAddressInfoDto addressInfoDto) { Page page = new Page<>(addressInfoDto.getPageNum(), addressInfoDto.getPageSize()); //admin 可看所有,其他下只能看下面管理的人员 String userId = BaseController.getUserId(); List collectIds = new ArrayList<>(); if (!"admin".equals(userId)) { List ids = new ArrayList<>(); List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper() .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0)); collectIds = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList()); if (collectIds.size() > 0) { List idList = queryList(collectIds, ids); collectIds.addAll(idList); } } Page insOrdersPage; Integer type = addressInfoDto.getType(); if (type == 1) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLng()), SysGeographyPosition::getLongitude, addressInfoDto.getLng()); wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLat()), SysGeographyPosition::getLatitude, addressInfoDto.getLat()); wrapper.in(SysGeographyPosition::getSource, Arrays.asList("1", "2")); wrapper.in(CollectionUtil.isNotEmpty(collectIds), SysGeographyPosition::getId, collectIds); wrapper.likeRight(StringUtils.isNotEmpty(addressInfoDto.getQueryId()), SysGeographyPosition::getId, addressInfoDto.getQueryId()); wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getSource()), SysGeographyPosition::getSource, addressInfoDto.getSource()); wrapper.orderByDesc(SysGeographyPosition::getCreateTime); insOrdersPage = page(page, wrapper); }else if (type == 2) { //查询人员下属管理所有人员 List ids = new ArrayList<>(); List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper() .eq(SysUser::getLeaderId, addressInfoDto.getQueryId()).ne(SysUser::getStatus, 0)); List collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList()); if (collect.size() > 0) { List idList = queryList(collect, ids); collect.addAll(idList); } LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLng()), SysGeographyPosition::getLongitude, addressInfoDto.getLng()); wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLat()), SysGeographyPosition::getLatitude, addressInfoDto.getLat()); wrapper.in(SysGeographyPosition::getSource, Arrays.asList("1", "2")); wrapper.in(CollectionUtil.isNotEmpty(collectIds), SysGeographyPosition::getId, collectIds); wrapper.in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect); wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getSource()), SysGeographyPosition::getSource, addressInfoDto.getSource()); wrapper.orderByDesc(SysGeographyPosition::getCreateTime); insOrdersPage = page(page, wrapper); }else { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLng()), SysGeographyPosition::getLongitude, addressInfoDto.getLng()); wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLat()), SysGeographyPosition::getLatitude, addressInfoDto.getLat()); wrapper.in(SysGeographyPosition::getSource, Arrays.asList("1", "2")); wrapper.in(CollectionUtil.isNotEmpty(collectIds), SysGeographyPosition::getId, collectIds); wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getSource()), SysGeographyPosition::getSource, addressInfoDto.getSource()); wrapper.orderByDesc(SysGeographyPosition::getCreateTime); insOrdersPage = page(page, wrapper); } List records = insOrdersPage.getRecords(); List sysGeographyPositionList = BeanUtil.copyToList(records, SysGeographyPositionInfoVo.class); //填充机构名 for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionList) { SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId()); if (sysUser == null) continue; sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName()); SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper() .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0)); if (sysDept == null) continue; String deptName = getDeptName(sysUser.getDeptId()); sysGeographyPositionInfoVo.setDeptName(deptName); } return new BasePageResult<>(addressInfoDto.getPageNum(), page.getSize(), insOrdersPage.getTotal(), page.getPages(), sysGeographyPositionList); } private List getcollectIds() { String userId = BaseController.getUserId(); List collectIds = new ArrayList<>(); if (!"admin".equals(userId)) { List ids = new ArrayList<>(); List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper() .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0)); collectIds = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList()); if (collectIds.size() > 0) { List idList = queryList(collectIds, ids); collectIds.addAll(idList); } } return collectIds; } @Override public BasePageResult queryGeographyRecord(PcAddressInfoDto addressInfoDto) { Page page = new Page(addressInfoDto.getPageNum(), addressInfoDto.getPageSize()); IPage sysGeographyPositionList; //登陆人的下属id String userId = BaseController.getUserId(); List collectIds =new ArrayList<>(); if (!"admin".equals(userId)) { //admin看所有人 List ids = new ArrayList<>(); List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper() .eq(SysUser::getLeaderId, BaseController.getUserId()).ne(SysUser::getStatus, 0)); collectIds = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList()); if (collectIds .size()==0) return new BasePageResult<>(addressInfoDto.getPageNum(), addressInfoDto.getPageSize(), 0L, 0L, null); List idList = queryList(collectIds, ids); collectIds.addAll(idList); } addressInfoDto.setCollectIds(collectIds); // 类型:1。机构树 2.用户树 0:默认查询 Integer type = addressInfoDto.getType(); if (type == 1) { sysGeographyPositionList = sysGeographyPositionRecordMapper.queryGeographyHistory(page,addressInfoDto); }else if (type == 2) { List ids = new ArrayList<>(); List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper() .eq(SysUser::getLeaderId, addressInfoDto.getQueryId()).ne(SysUser::getStatus, 0)); List collect= sysUsers.stream().map(SysUser::getId).collect(Collectors.toList()); if (collect.size()>0) { List idList = queryList(collect, ids); collect.addAll(idList); } addressInfoDto.setQueryId(null); addressInfoDto.setCollect(collect); sysGeographyPositionList = sysGeographyPositionRecordMapper.queryGeographyHistory(page,addressInfoDto); }else { sysGeographyPositionList = sysGeographyPositionRecordMapper.queryGeographyHistory(page,addressInfoDto); } List records = sysGeographyPositionList.getRecords(); //填充机构名 for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : records) { SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getUserId()); if (sysUser == null) continue; sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName()); String deptName = getDeptName(sysUser.getDeptId()); sysGeographyPositionInfoVo.setDeptName(deptName); } return new BasePageResult<>(addressInfoDto.getPageNum(), addressInfoDto.getPageSize(), sysGeographyPositionList.getTotal(), sysGeographyPositionList.getPages(), records); } @Override public AppGeographyHistoryInfoVo getGeographyPosition(String startTime, String endTime, String source) { AppGeographyHistoryInfoVo appGeographyHistoryInfoVo = new AppGeographyHistoryInfoVo(); //admin 可看所有,其他下只能看下面管理的人员 String userId = BaseController.getUserId(); List collect = new ArrayList<>(); if (!"admin".equals(userId)) { List ids = new ArrayList<>(); List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper() .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0)); collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList()); if (collect.size() == 0) return appGeographyHistoryInfoVo; List idList = queryList(collect, ids); collect.addAll(idList); } if (StringUtils.isEmpty(startTime) || startTime.equals(endTime)) { if (StringUtils.isNullOrEmpty(startTime)) { Date date = new Date(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); startTime = simpleDateFormat.format(date); } QueryWrapper queryWrapper = new QueryWrapper<>(); // 指定 COUNT(DISTINCT user_id) 查询 queryWrapper.select("COUNT(DISTINCT user_id) AS total") .likeRight(StringUtils.isNotEmpty(startTime), "create_time", startTime) .in("source", Arrays.asList(1, 2)) .in(CollectionUtil.isNotEmpty(collect), "user_id", collect) .eq(StringUtils.isNotEmpty(source),"source",source); Map result = sysGeographyPositionRecordService.getMap(queryWrapper); Long total = (Long) result.get("total"); appGeographyHistoryInfoVo.setOnlineNum(total); List geographyPosition = sysGeographyPositionRecordMapper.getGeographyPosition(startTime,source,collect); appGeographyHistoryInfoVo.setList(geographyPosition); List sysGeographyPositionRecords =sysGeographyPositionRecordMapper.getGeographyPositionRecord(startTime,source,collect); extracted(sysGeographyPositionRecords); System.out.println("********************" + sysGeographyPositionRecords.size()); appGeographyHistoryInfoVo.setPositionRecordList(sysGeographyPositionRecords); }else { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); startTime = startTime + " 00:00:01"; endTime = endTime + " 23:59:59"; try { Date parse = simpleDateFormat.parse(startTime); Date parse1 = simpleDateFormat.parse(endTime); startTime = simpleDateFormat.format(parse); endTime = simpleDateFormat.format(parse1); } catch (ParseException e) { throw new RuntimeException(e); } QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.select("COUNT(DISTINCT user_id) AS total") .between("create_time", startTime, endTime) .in("source", Arrays.asList(1, 2)) .in(CollectionUtil.isNotEmpty(collect), "user_id", collect) .eq(StringUtils.isNotEmpty(source),"source",source); Map result = sysGeographyPositionRecordService.getMap(queryWrapper); Long total = (Long) result.get("total"); appGeographyHistoryInfoVo.setOnlineNum(total); List geographyPosition = sysGeographyPositionRecordMapper.getGeographyPositionSection(startTime,endTime,source,collect); appGeographyHistoryInfoVo.setList(geographyPosition); List sysGeographyPositionRecords =sysGeographyPositionRecordMapper.getGeographyPositionHistory(startTime,endTime,source,collect); extracted(sysGeographyPositionRecords); System.out.println("********************" + sysGeographyPositionRecords.size()); appGeographyHistoryInfoVo.setPositionRecordList(sysGeographyPositionRecords); } return appGeographyHistoryInfoVo; } private void extracted(List sysGeographyPositionRecords) { for (SysGeographyPositionRecord sysGeographyPositionRecord : sysGeographyPositionRecords) { SysUser sysUser = sysUserService.getById(sysGeographyPositionRecord.getUserId()); if (sysUser == null) continue; sysGeographyPositionRecord.setLeaderName(sysUser.getLeaderName()); String deptName = getDeptName(sysUser.getDeptId()); sysGeographyPositionRecord.setDeptName(deptName); } } @Override public List getOnlinePeople() { return sysGeographyPositionMapper.selectList(new LambdaQueryWrapper().eq(SysGeographyPosition::getStatus,1)); } }