SysGeographyPositionServiceImpl.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. package com.ydtech.modules.admin.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollectionUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.baomidou.mybatisplus.core.metadata.IPage;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  9. import com.ydtech.modules.admin.dao.SysDeptMapper;
  10. import com.ydtech.modules.admin.dao.SysGeographyPositionMapper;
  11. import com.ydtech.modules.admin.dao.SysGeographyPositionRecordMapper;
  12. import com.ydtech.modules.admin.dao.SysUserMapper;
  13. import com.ydtech.modules.admin.model.SysDept;
  14. import com.ydtech.modules.admin.model.SysGeographyPosition;
  15. import com.ydtech.modules.admin.model.SysGeographyPositionRecord;
  16. import com.ydtech.modules.admin.model.SysUser;
  17. import com.ydtech.modules.admin.model.dto.*;
  18. import com.ydtech.modules.admin.model.po.SysPcAddress;
  19. import com.ydtech.modules.admin.model.vo.*;
  20. import com.ydtech.modules.admin.service.GeoService;
  21. import com.ydtech.modules.admin.service.SysGeographyPositionRecordService;
  22. import com.ydtech.modules.admin.service.SysGeographyPositionService;
  23. import com.ydtech.modules.admin.service.SysUserService;
  24. import com.ydtech.modules.order.entity.BasePageResult;
  25. import com.ydtech.utils.StringUtils;
  26. import org.springframework.stereotype.Service;
  27. import javax.annotation.Resource;
  28. import java.text.ParseException;
  29. import java.text.SimpleDateFormat;
  30. import java.util.*;
  31. import java.util.stream.Collectors;
  32. @Service("SysGeographyPositionService")
  33. public class SysGeographyPositionServiceImpl extends ServiceImpl<SysGeographyPositionMapper, SysGeographyPosition> implements SysGeographyPositionService {
  34. @Resource
  35. private SysGeographyPositionMapper sysGeographyPositionMapper;
  36. @Resource
  37. private SysGeographyPositionRecordMapper sysGeographyPositionRecordMapper;
  38. @Resource
  39. private SysGeographyPositionRecordService sysGeographyPositionRecordService;
  40. @Resource
  41. private SysUserService sysUserService;
  42. @Resource
  43. private SysDeptMapper sysDeptMapper;
  44. @Resource
  45. private SysUserMapper sysUserMapper;
  46. @Resource
  47. private GeoService geoService;
  48. private static final String APP_GEO_KEY = "APPLocations";
  49. @Override
  50. public SysGeographyPositionVo queryPosition(SysGeographyPositionDto sysGeographyPositionDto) {
  51. SysGeographyPositionVo sysGeographyPositionVo = new SysGeographyPositionVo();
  52. // 类型:1。机构 2.用户
  53. Integer type = sysGeographyPositionDto.getType();
  54. if (type == 1) {
  55. List<SysGeographyPosition> list = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>()
  56. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  57. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  58. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  59. .in(SysGeographyPosition::getSource, Arrays.asList("1", "2"))
  60. .likeRight(StringUtils.isNotEmpty(sysGeographyPositionDto.getQueryId()), SysGeographyPosition::getId, sysGeographyPositionDto.getQueryId())
  61. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getSource()), SysGeographyPosition::getSource, sysGeographyPositionDto.getSource())
  62. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus())
  63. .orderByDesc(SysGeographyPosition::getCreateTime));
  64. if (list.size() == 0) return new SysGeographyPositionVo();
  65. List<SysGeographyPositionInfoVo> sysGeographyPositionList = BeanUtil.copyToList(list, SysGeographyPositionInfoVo.class);
  66. //填充机构名
  67. for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionList) {
  68. SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId());
  69. if (sysUser == null) continue;
  70. sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName());
  71. SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>()
  72. .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0));
  73. if (sysDept == null) continue;
  74. String deptName = getDeptName(sysUser.getDeptId());
  75. // sysGeographyPositionInfoVo.setDeptName(sysDept.getName());
  76. sysGeographyPositionInfoVo.setDeptName(deptName);
  77. }
  78. sysGeographyPositionVo.setList(sysGeographyPositionList);
  79. }else if (type == 2){
  80. List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
  81. .eq(SysUser::getLeaderId, sysGeographyPositionDto.getQueryId()).ne(SysUser::getStatus, 0));
  82. List<String> collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
  83. List<String> ids = new ArrayList<>();
  84. List<String> idList = queryList(collect, ids);
  85. collect.addAll(idList);
  86. if (collect.size() == 0) {
  87. return sysGeographyPositionVo;
  88. }
  89. List<SysGeographyPosition> list = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>()
  90. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  91. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  92. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  93. .in(SysGeographyPosition::getSource, Arrays.asList("1", "2"))
  94. .in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect)
  95. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getSource()), SysGeographyPosition::getSource, sysGeographyPositionDto.getSource())
  96. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus())
  97. .orderByDesc(SysGeographyPosition::getCreateTime));
  98. if (list.size() == 0) return new SysGeographyPositionVo();
  99. List<SysGeographyPositionInfoVo> sysGeographyPositionList = BeanUtil.copyToList(list, SysGeographyPositionInfoVo.class);
  100. //填充机构名
  101. for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionList) {
  102. SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId());
  103. if (sysUser == null) continue;
  104. sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName());
  105. SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>()
  106. .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0));
  107. if (sysDept == null) continue;
  108. String deptName = getDeptName(sysUser.getDeptId());
  109. // sysGeographyPositionInfoVo.setDeptName(sysDept.getName());
  110. sysGeographyPositionInfoVo.setDeptName(deptName);
  111. }
  112. sysGeographyPositionVo.setList(sysGeographyPositionList);
  113. }else {
  114. List<SysGeographyPosition> list = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>()
  115. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  116. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  117. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  118. .in(SysGeographyPosition::getSource, Arrays.asList("1", "2"))
  119. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getSource()), SysGeographyPosition::getSource, sysGeographyPositionDto.getSource())
  120. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus())
  121. .orderByDesc(SysGeographyPosition::getCreateTime));
  122. if (list.size() == 0) return new SysGeographyPositionVo();
  123. List<SysGeographyPositionInfoVo> sysGeographyPositionList = BeanUtil.copyToList(list, SysGeographyPositionInfoVo.class);
  124. //填充机构名
  125. for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionList) {
  126. SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId());
  127. if (sysUser == null) continue;
  128. sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName());
  129. SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>()
  130. .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0));
  131. if (sysDept == null) continue;
  132. String deptName = getDeptName(sysUser.getDeptId());
  133. // sysGeographyPositionInfoVo.setDeptName(sysDept.getName());
  134. sysGeographyPositionInfoVo.setDeptName(deptName);
  135. }
  136. sysGeographyPositionVo.setList(sysGeographyPositionList);
  137. }
  138. return sysGeographyPositionVo;
  139. }
  140. private List<String> queryList(List<String> collect, List<String> ids) {
  141. if (collect.size() > 0) {
  142. for (String id : collect) {
  143. List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
  144. .eq(SysUser::getLeaderId, id).ne(SysUser::getStatus, 0));
  145. if (sysUsers.size() > 0) {
  146. List<String> list = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
  147. ids.addAll(list);
  148. queryList(list, ids);
  149. }
  150. }
  151. }
  152. return ids;
  153. }
  154. private String getDeptName(String deptId) {
  155. StringBuilder stringBuilder = new StringBuilder();
  156. SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>()
  157. .eq(SysDept::getId, deptId).eq(SysDept::getDelFlag, 0));
  158. if (StringUtils.isEmpty(sysDept.getComlevel())) {
  159. SysDept sysDept5 = sysDeptMapper.selectById(sysDept.getParentId());
  160. SysDept sysDept4 = sysDeptMapper.selectById(sysDept5.getParentId());
  161. SysDept sysDept3 = sysDeptMapper.selectById(sysDept4.getParentId());
  162. SysDept sysDept2 = sysDeptMapper.selectById(sysDept3.getParentId());
  163. stringBuilder.append(sysDept2.getName()).append("-").append(sysDept3.getName())
  164. .append("-").append(sysDept4.getName()).append("-").append(sysDept5.getName()).append("-").append(sysDept.getName());
  165. }else if (sysDept.getComlevel().equals("5")) {
  166. SysDept sysDept4 = sysDeptMapper.selectById(sysDept.getParentId());
  167. SysDept sysDept3 = sysDeptMapper.selectById(sysDept4.getParentId());
  168. SysDept sysDept2 = sysDeptMapper.selectById(sysDept3.getParentId());
  169. stringBuilder.append(sysDept2.getName()).append("-").append(sysDept3.getName()).append("-").append(sysDept4.getName()).append("-").append(sysDept.getName());
  170. }else if (sysDept.getComlevel().equals("4")) {
  171. SysDept sysDept3 = sysDeptMapper.selectById(sysDept.getParentId());
  172. SysDept sysDept2 = sysDeptMapper.selectById(sysDept3.getParentId());
  173. stringBuilder.append(sysDept2.getName()).append("-").append(sysDept3.getName()).append("-").append(sysDept.getName());
  174. }else if (sysDept.getComlevel().equals("3")) {
  175. SysDept sysDept2 = sysDeptMapper.selectById(sysDept.getParentId());
  176. stringBuilder.append(sysDept2.getName()).append("-").append(sysDept.getName());
  177. }else if (sysDept.getComlevel().equals("2")) {
  178. stringBuilder.append(sysDept.getName());
  179. }
  180. return stringBuilder.toString();
  181. }
  182. @Override
  183. public BasePageResult<SysGeographyPositionRecord> queryPositionList(SysGeographyPositionPageDto sysGeographyPositionPageDto) {
  184. Page<SysGeographyPositionRecord> page = new Page<>(sysGeographyPositionPageDto.getPageNum(), sysGeographyPositionPageDto.getPageSize());
  185. LambdaQueryWrapper<SysGeographyPositionRecord> wrapper = new LambdaQueryWrapper<>();
  186. wrapper.eq(StringUtils.isNotEmpty(sysGeographyPositionPageDto.getId()), SysGeographyPositionRecord::getUserId, sysGeographyPositionPageDto.getId());
  187. wrapper.orderByDesc(SysGeographyPositionRecord::getCreateTime);
  188. Page<SysGeographyPositionRecord> insOrdersPage = sysGeographyPositionRecordService.page(page, wrapper);
  189. List<SysGeographyPositionRecord> records = insOrdersPage.getRecords();
  190. if (records.size()>0) {
  191. for (SysGeographyPositionRecord record : records) {
  192. SysUser sysUser = sysUserService.getById(record.getUserId());
  193. if (sysUser == null) continue;
  194. record.setLeaderName(sysUser.getLeaderName());
  195. String deptName = getDeptName(sysUser.getDeptId());
  196. record.setDeptName(deptName);
  197. }
  198. }
  199. return new BasePageResult<>(sysGeographyPositionPageDto.getPageNum(), page.getSize(), insOrdersPage.getTotal(), page.getPages(),
  200. insOrdersPage.getRecords());
  201. }
  202. @Override
  203. public SysPcAddressNumVo queryPcNum(SysGeographyPositionDto sysGeographyPositionDto) {
  204. SysPcAddressNumVo sysPcAddressNumVo = new SysPcAddressNumVo();
  205. Long all = sysGeographyPositionMapper.selectCount(new LambdaQueryWrapper<SysGeographyPosition>()
  206. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  207. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  208. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  209. .in(SysGeographyPosition::getSource, Arrays.asList("1", "2"))
  210. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus()));
  211. Long channelNum = sysGeographyPositionMapper.selectCount(new LambdaQueryWrapper<SysGeographyPosition>()
  212. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  213. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  214. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  215. .eq(SysGeographyPosition::getSource, 1)
  216. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus()));
  217. Long proxyNum = sysGeographyPositionMapper.selectCount(new LambdaQueryWrapper<SysGeographyPosition>()
  218. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  219. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  220. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  221. .eq(SysGeographyPosition::getSource, 2)
  222. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus()));
  223. Long onlineNum = sysGeographyPositionMapper.selectCount(new LambdaQueryWrapper<SysGeographyPosition>()
  224. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  225. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  226. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  227. .in(SysGeographyPosition::getSource, Arrays.asList("1", "2"))
  228. .eq(sysGeographyPositionDto.getStatus() == null, SysGeographyPosition::getStatus, 1)
  229. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus()));
  230. sysPcAddressNumVo.setAllNum(all);
  231. sysPcAddressNumVo.setProxyNum(proxyNum);
  232. sysPcAddressNumVo.setChannelNum(channelNum);
  233. sysPcAddressNumVo.setOnlineNum(onlineNum);
  234. return sysPcAddressNumVo;
  235. }
  236. @Override
  237. public List<RegionInfoVo> queryRegionInfo(SysGeographyPositionDto sysGeographyPositionDto) {
  238. List<RegionInfoVo> regionInfoVos = new ArrayList<>();
  239. //全部:null 渠道:1 代理:2
  240. List<SysGeographyPosition> sysGeographyPositionList = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>()
  241. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  242. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  243. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  244. .in(SysGeographyPosition::getSource, Arrays.asList("1", "2"))
  245. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getSource()), SysGeographyPosition::getSource, sysGeographyPositionDto.getSource())
  246. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus()));
  247. if (CollectionUtil.isEmpty(sysGeographyPositionList)) return regionInfoVos;
  248. Map<String, List<SysGeographyPosition>> map;
  249. if (StringUtils.isEmpty(sysGeographyPositionDto.getProvince())) {
  250. map = sysGeographyPositionList.stream().collect(Collectors.groupingBy(SysGeographyPosition::getProvince));
  251. } else {
  252. if (StringUtils.isNotEmpty(sysGeographyPositionDto.getCity())) {
  253. map = sysGeographyPositionList.stream().collect(Collectors.groupingBy(SysGeographyPosition::getDistrict));
  254. } else {
  255. map = sysGeographyPositionList.stream().collect(Collectors.groupingBy(SysGeographyPosition::getCity));
  256. }
  257. }
  258. for (Map.Entry<String, List<SysGeographyPosition>> entry : map.entrySet()) {
  259. RegionInfoVo regionInfoVo = new RegionInfoVo();
  260. regionInfoVo.setDistrictName(entry.getKey());
  261. regionInfoVo.setNumber(entry.getValue().size());
  262. regionInfoVos.add(regionInfoVo);
  263. }
  264. return regionInfoVos;
  265. }
  266. @Override
  267. public List<SysGeographyPositionInfoVo> findLocationsWithinRadius(AdressRangeDto adressRangeDto) {
  268. geoService.addLocationGeography(list(), APP_GEO_KEY);
  269. List<String> nearbyIds = geoService.findNearbyIds(APP_GEO_KEY, adressRangeDto.getLongitude(), adressRangeDto.getLatitude(), adressRangeDto.getRadius());
  270. if (nearbyIds.size() == 0) return new ArrayList<>();
  271. geoService.move(nearbyIds, APP_GEO_KEY);
  272. List<SysGeographyPosition> sysGeographyPositions = listByIds(nearbyIds);
  273. List<SysGeographyPositionInfoVo> sysGeographyPositionInfoVoList = BeanUtil.copyToList(sysGeographyPositions, SysGeographyPositionInfoVo.class);
  274. if (sysGeographyPositionInfoVoList.size() == 0) return sysGeographyPositionInfoVoList;
  275. for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionInfoVoList) {
  276. SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId());
  277. if (sysUser == null) continue;
  278. SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>()
  279. .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0));
  280. if (sysDept == null) continue;
  281. sysGeographyPositionInfoVo.setDeptName(sysDept.getName());
  282. }
  283. return sysGeographyPositionInfoVoList;
  284. }
  285. @Override
  286. public BasePageResult<SysGeographyPositionInfoVo> queryPcAddressInfo(PcAddressInfoDto addressInfoDto) {
  287. Page<SysGeographyPosition> page = new Page<>(addressInfoDto.getPageNum(), addressInfoDto.getPageSize());
  288. LambdaQueryWrapper<SysGeographyPosition> wrapper = new LambdaQueryWrapper<>();
  289. wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLng()), SysGeographyPosition::getLongitude, addressInfoDto.getLng());
  290. wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLat()), SysGeographyPosition::getLatitude, addressInfoDto.getLat());
  291. wrapper.in(SysGeographyPosition::getSource, Arrays.asList("1", "2"));
  292. wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getSource()), SysGeographyPosition::getSource, addressInfoDto.getSource());
  293. wrapper.orderByDesc(SysGeographyPosition::getCreateTime);
  294. Page<SysGeographyPosition> insOrdersPage = page(page, wrapper);
  295. List<SysGeographyPosition> records = insOrdersPage.getRecords();
  296. List<SysGeographyPositionInfoVo> sysGeographyPositionList = BeanUtil.copyToList(records, SysGeographyPositionInfoVo.class);
  297. //填充机构名
  298. for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionList) {
  299. SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId());
  300. sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName());
  301. if (sysUser == null) continue;
  302. SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>()
  303. .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0));
  304. if (sysDept == null) continue;
  305. String deptName = getDeptName(sysUser.getDeptId());
  306. sysGeographyPositionInfoVo.setDeptName(deptName);
  307. // sysGeographyPositionInfoVo.setDeptName(sysDept.getName());
  308. }
  309. return new BasePageResult<>(addressInfoDto.getPageNum(), page.getSize(), insOrdersPage.getTotal(), page.getPages(),
  310. sysGeographyPositionList);
  311. }
  312. @Override
  313. public BasePageResult<SysGeographyPositionInfoVo> queryGeographyRecord(PcAddressInfoDto addressInfoDto) {
  314. Page page = new Page(addressInfoDto.getPageNum(), addressInfoDto.getPageSize());
  315. IPage<SysGeographyPositionInfoVo> sysGeographyPositionList = sysGeographyPositionRecordMapper.queryGeographyHistory(page,addressInfoDto);
  316. List<SysGeographyPositionInfoVo> records = sysGeographyPositionList.getRecords();
  317. //填充机构名
  318. for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : records) {
  319. SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getUserId());
  320. if (sysUser == null) continue;
  321. SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>()
  322. .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0));
  323. if (sysDept == null) continue;
  324. sysGeographyPositionInfoVo.setDeptName(sysDept.getName());
  325. }
  326. return new BasePageResult<>(addressInfoDto.getPageNum(), addressInfoDto.getPageSize(), sysGeographyPositionList.getTotal(), sysGeographyPositionList.getPages(),
  327. records);
  328. }
  329. @Override
  330. public AppGeographyHistoryInfoVo getGeographyPosition(String startTime, String endTime, String source) {
  331. AppGeographyHistoryInfoVo appGeographyHistoryInfoVo = new AppGeographyHistoryInfoVo();
  332. if (StringUtils.isEmpty(startTime) || startTime.equals(endTime)) {
  333. if (StringUtils.isNullOrEmpty(startTime)) {
  334. Date date = new Date();
  335. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  336. startTime = simpleDateFormat.format(date);
  337. }
  338. QueryWrapper<SysGeographyPositionRecord> queryWrapper = new QueryWrapper<>();
  339. // 指定 COUNT(DISTINCT user_id) 查询
  340. queryWrapper.select("COUNT(DISTINCT user_id) AS total")
  341. .likeRight(StringUtils.isNotEmpty(startTime), "create_time", startTime)
  342. .in("source", Arrays.asList(1, 2))
  343. .eq(StringUtils.isNotEmpty(source),"source",source);;
  344. Map<String, Object> result = sysGeographyPositionRecordService.getMap(queryWrapper);
  345. Long total = (Long) result.get("total");
  346. appGeographyHistoryInfoVo.setOnlineNum(total);
  347. List<PcAddressHistoryTimeVo> geographyPosition = sysGeographyPositionRecordMapper.getGeographyPosition(startTime,source);
  348. appGeographyHistoryInfoVo.setList(geographyPosition);
  349. List<SysGeographyPositionRecord> sysGeographyPositionRecords =sysGeographyPositionRecordMapper.getGeographyPositionRecord(startTime,source);
  350. extracted(sysGeographyPositionRecords);
  351. System.out.println("********************" + sysGeographyPositionRecords.size());
  352. appGeographyHistoryInfoVo.setPositionRecordList(sysGeographyPositionRecords);
  353. }else {
  354. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  355. startTime = startTime + " 00:00:01";
  356. endTime = endTime + " 23:59:59";
  357. try {
  358. Date parse = simpleDateFormat.parse(startTime);
  359. Date parse1 = simpleDateFormat.parse(endTime);
  360. startTime = simpleDateFormat.format(parse);
  361. endTime = simpleDateFormat.format(parse1);
  362. } catch (ParseException e) {
  363. throw new RuntimeException(e);
  364. }
  365. QueryWrapper<SysGeographyPositionRecord> queryWrapper = new QueryWrapper<>();
  366. queryWrapper.select("COUNT(DISTINCT user_id) AS total")
  367. .between("create_time", startTime, endTime)
  368. .in("source", Arrays.asList(1, 2))
  369. .eq(StringUtils.isNotEmpty(source),"source",source);;
  370. Map<String, Object> result = sysGeographyPositionRecordService.getMap(queryWrapper);
  371. Long total = (Long) result.get("total");
  372. appGeographyHistoryInfoVo.setOnlineNum(total);
  373. List<PcAddressHistoryTimeVo> geographyPosition = sysGeographyPositionRecordMapper.getGeographyPositionSection(startTime,endTime,source);
  374. appGeographyHistoryInfoVo.setList(geographyPosition);
  375. List<SysGeographyPositionRecord> sysGeographyPositionRecords =sysGeographyPositionRecordMapper.getGeographyPositionHistory(startTime,endTime,source);
  376. extracted(sysGeographyPositionRecords);
  377. System.out.println("********************" + sysGeographyPositionRecords.size());
  378. appGeographyHistoryInfoVo.setPositionRecordList(sysGeographyPositionRecords);
  379. }
  380. return appGeographyHistoryInfoVo;
  381. }
  382. private void extracted(List<SysGeographyPositionRecord> sysGeographyPositionRecords) {
  383. for (SysGeographyPositionRecord sysGeographyPositionRecord : sysGeographyPositionRecords) {
  384. SysUser sysUser = sysUserService.getById(sysGeographyPositionRecord.getUserId());
  385. if (sysUser == null) continue;
  386. sysGeographyPositionRecord.setLeaderName(sysUser.getLeaderName());
  387. SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId());
  388. if (sysDept == null) continue;
  389. sysGeographyPositionRecord.setDeptName(sysDept.getName());
  390. }
  391. }
  392. @Override
  393. public List<SysGeographyPosition> getOnlinePeople() {
  394. return sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>().eq(SysGeographyPosition::getStatus,1));
  395. }
  396. }