| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700 |
- 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<SysGeographyPositionMapper, SysGeographyPosition> 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<String> collectIds = new ArrayList<>();
- if (!"admin".equals(userId)) {
- List<String> arrayList = new ArrayList<>();
- List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
- .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0));
- collectIds = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
- if (collectIds.size() == 0) return sysGeographyPositionVo;
- List<String> idList = queryList(collectIds, arrayList);
- collectIds.addAll(idList);
- }
- // 类型:1。机构 2.用户
- Integer type = sysGeographyPositionDto.getType();
- if (type == 1) {
- List<SysGeographyPosition> list = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>()
- .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<SysGeographyPositionInfoVo> 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<SysDept>()
- .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<String> ids = new ArrayList<>();
- List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
- .eq(SysUser::getLeaderId, sysGeographyPositionDto.getQueryId()).ne(SysUser::getStatus, 0));
- List<String> collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
- if (collect.size() == 0) return sysGeographyPositionVo;
- List<String> idList = queryList(collect, ids);
- collect.addAll(idList);
- List<SysGeographyPosition> list = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>()
- .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<SysGeographyPositionInfoVo> 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<SysDept>()
- .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<SysGeographyPosition> list = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>()
- .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<SysGeographyPositionInfoVo> 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<SysDept>()
- .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<String> queryList(List<String> collect, List<String> ids) {
- int size = collect.size();
- if (size > 0) {
- List<String> strings = new ArrayList<>();
- for (String id : collect) {
- List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
- .eq(SysUser::getLeaderId, id).ne(SysUser::getStatus, 0));
- // List<SysUser> sysUsers = sysUserMapper.querySourceId(id);
- if (sysUsers.size() > 0) {
- List<String> 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<SysDept>()
- .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<SysGeographyPositionRecord> queryPositionList(SysGeographyPositionPageDto sysGeographyPositionPageDto) {
- Page<SysGeographyPositionRecord> page = new Page<>(sysGeographyPositionPageDto.getPageNum(), sysGeographyPositionPageDto.getPageSize());
- LambdaQueryWrapper<SysGeographyPositionRecord> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(StringUtils.isNotEmpty(sysGeographyPositionPageDto.getId()), SysGeographyPositionRecord::getUserId, sysGeographyPositionPageDto.getId());
- wrapper.orderByDesc(SysGeographyPositionRecord::getCreateTime);
- Page<SysGeographyPositionRecord> insOrdersPage = sysGeographyPositionRecordService.page(page, wrapper);
- List<SysGeographyPositionRecord> 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<String> collect = new ArrayList<>();
- if (!"admin".equals(userId)) {
- List<String> ids = new ArrayList<>();
- List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
- .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0));
- collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
- if (collect.size() == 0) return sysPcAddressNumVo;
- List<String> idList = queryList(collect, ids);
- collect.addAll(idList);
- }
- Long all = sysGeographyPositionMapper.selectCount(new LambdaQueryWrapper<SysGeographyPosition>()
- .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<SysGeographyPosition>()
- .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<SysGeographyPosition>()
- .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<SysGeographyPosition>()
- .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<RegionInfoVo> queryRegionInfo(SysGeographyPositionDto sysGeographyPositionDto) {
- List<RegionInfoVo> regionInfoVos = new ArrayList<>();
- //admin 可看所有,其他下只能看下面管理的人员
- String userId = BaseController.getUserId();
- List<String> collect = new ArrayList<>();
- if (!"admin".equals(userId)) {
- List<String> ids = new ArrayList<>();
- List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
- .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0));
- collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
- if (collect.size() == 0) return regionInfoVos;
- List<String> idList = queryList(collect, ids);
- collect.addAll(idList);
- }
- //全部:null 渠道:1 代理:2
- List<SysGeographyPosition> sysGeographyPositionList = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>()
- .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<String, List<SysGeographyPosition>> 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<String, List<SysGeographyPosition>> entry : map.entrySet()) {
- RegionInfoVo regionInfoVo = new RegionInfoVo();
- regionInfoVo.setDistrictName(entry.getKey());
- regionInfoVo.setNumber(entry.getValue().size());
- regionInfoVos.add(regionInfoVo);
- }
- return regionInfoVos;
- }
- @Override
- public List<SysGeographyPositionInfoVo> findLocationsWithinRadius(AdressRangeDto adressRangeDto) {
- geoService.addLocationGeography(list(), APP_GEO_KEY);
- List<String> 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<SysGeographyPosition> sysGeographyPositions = listByIds(nearbyIds);
- List<SysGeographyPositionInfoVo> 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<SysDept>()
- .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0));
- if (sysDept == null) continue;
- sysGeographyPositionInfoVo.setDeptName(sysDept.getName());
- }
- return sysGeographyPositionInfoVoList;
- }
- @Override
- public BasePageResult<SysGeographyPositionInfoVo> queryPcAddressInfo(PcAddressInfoDto addressInfoDto) {
- Page<SysGeographyPosition> page = new Page<>(addressInfoDto.getPageNum(), addressInfoDto.getPageSize());
- //admin 可看所有,其他下只能看下面管理的人员
- String userId = BaseController.getUserId();
- List<String> collectIds = new ArrayList<>();
- if (!"admin".equals(userId)) {
- List<String> ids = new ArrayList<>();
- List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
- .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0));
- collectIds = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
- if (collectIds.size() > 0) {
- List<String> idList = queryList(collectIds, ids);
- collectIds.addAll(idList);
- }
- }
- Page<SysGeographyPosition> insOrdersPage;
- Integer type = addressInfoDto.getType();
- if (type == 1) {
- LambdaQueryWrapper<SysGeographyPosition> 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<String> ids = new ArrayList<>();
- List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
- .eq(SysUser::getLeaderId, addressInfoDto.getQueryId()).ne(SysUser::getStatus, 0));
- List<String> collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
- if (collect.size() > 0) {
- List<String> idList = queryList(collect, ids);
- collect.addAll(idList);
- }
- LambdaQueryWrapper<SysGeographyPosition> 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<SysGeographyPosition> 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<SysGeographyPosition> records = insOrdersPage.getRecords();
- List<SysGeographyPositionInfoVo> 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<SysDept>()
- .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<String> getcollectIds() {
- String userId = BaseController.getUserId();
- List<String> collectIds = new ArrayList<>();
- if (!"admin".equals(userId)) {
- List<String> ids = new ArrayList<>();
- List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
- .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0));
- collectIds = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
- if (collectIds.size() > 0) {
- List<String> idList = queryList(collectIds, ids);
- collectIds.addAll(idList);
- }
- }
- return collectIds;
- }
- @Override
- public BasePageResult<SysGeographyPositionInfoVo> queryGeographyRecord(PcAddressInfoDto addressInfoDto) {
- Page page = new Page(addressInfoDto.getPageNum(), addressInfoDto.getPageSize());
- IPage<SysGeographyPositionInfoVo> sysGeographyPositionList;
- //登陆人的下属id
- String userId = BaseController.getUserId();
- List<String> collectIds =new ArrayList<>();
- if (!"admin".equals(userId)) {
- //admin看所有人
- List<String> ids = new ArrayList<>();
- List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
- .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<String> 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<String> ids = new ArrayList<>();
- List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
- .eq(SysUser::getLeaderId, addressInfoDto.getQueryId()).ne(SysUser::getStatus, 0));
- List<String> collect= sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
- if (collect.size()>0) {
- List<String> 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<SysGeographyPositionInfoVo> 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<String> collect = new ArrayList<>();
- if (!"admin".equals(userId)) {
- List<String> ids = new ArrayList<>();
- List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
- .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0));
- collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
- if (collect.size() == 0) return appGeographyHistoryInfoVo;
- List<String> 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<SysGeographyPositionRecord> 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<String, Object> result = sysGeographyPositionRecordService.getMap(queryWrapper);
- Long total = (Long) result.get("total");
- appGeographyHistoryInfoVo.setOnlineNum(total);
- List<PcAddressHistoryTimeVo> geographyPosition = sysGeographyPositionRecordMapper.getGeographyPosition(startTime,source,collect);
- appGeographyHistoryInfoVo.setList(geographyPosition);
- List<SysGeographyPositionRecord> 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<SysGeographyPositionRecord> 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<String, Object> result = sysGeographyPositionRecordService.getMap(queryWrapper);
- Long total = (Long) result.get("total");
- appGeographyHistoryInfoVo.setOnlineNum(total);
- List<PcAddressHistoryTimeVo> geographyPosition = sysGeographyPositionRecordMapper.getGeographyPositionSection(startTime,endTime,source,collect);
- appGeographyHistoryInfoVo.setList(geographyPosition);
- List<SysGeographyPositionRecord> sysGeographyPositionRecords =sysGeographyPositionRecordMapper.getGeographyPositionHistory(startTime,endTime,source,collect);
- extracted(sysGeographyPositionRecords);
- System.out.println("********************" + sysGeographyPositionRecords.size());
- appGeographyHistoryInfoVo.setPositionRecordList(sysGeographyPositionRecords);
- }
- return appGeographyHistoryInfoVo;
- }
- private void extracted(List<SysGeographyPositionRecord> 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<SysGeographyPosition> getOnlinePeople() {
- return sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>().eq(SysGeographyPosition::getStatus,1));
- }
- }
|