SysGeographyPositionServiceImpl.java 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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.vo.*;
  19. import com.ydtech.modules.admin.service.GeoService;
  20. import com.ydtech.modules.admin.service.SysGeographyPositionRecordService;
  21. import com.ydtech.modules.admin.service.SysGeographyPositionService;
  22. import com.ydtech.modules.admin.service.SysUserService;
  23. import com.ydtech.modules.base.controller.BaseController;
  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. String userId = BaseController.getUserId();
  53. List<String> collectIds = new ArrayList<>();
  54. if (!"admin".equals(userId)) {
  55. List<String> arrayList = new ArrayList<>();
  56. List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
  57. .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0));
  58. collectIds = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
  59. if (collectIds.size() == 0) return sysGeographyPositionVo;
  60. List<String> idList = queryList(collectIds, arrayList);
  61. collectIds.addAll(idList);
  62. }
  63. // 类型:1。机构 2.用户
  64. Integer type = sysGeographyPositionDto.getType();
  65. if (type == 1) {
  66. List<SysGeographyPosition> list = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>()
  67. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  68. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  69. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  70. .in(SysGeographyPosition::getSource, Arrays.asList("1", "2"))
  71. .in(CollectionUtil.isNotEmpty(collectIds), SysGeographyPosition::getId, collectIds)
  72. .likeRight(StringUtils.isNotEmpty(sysGeographyPositionDto.getQueryId()), SysGeographyPosition::getId, sysGeographyPositionDto.getQueryId())
  73. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getSource()), SysGeographyPosition::getSource, sysGeographyPositionDto.getSource())
  74. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus())
  75. .orderByDesc(SysGeographyPosition::getCreateTime));
  76. if (list.size() == 0) return new SysGeographyPositionVo();
  77. List<SysGeographyPositionInfoVo> sysGeographyPositionList = BeanUtil.copyToList(list, SysGeographyPositionInfoVo.class);
  78. //填充机构名
  79. for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionList) {
  80. SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId());
  81. if (sysUser == null) continue;
  82. sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName());
  83. SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>()
  84. .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0));
  85. if (sysDept == null) continue;
  86. String deptName = getDeptName(sysUser.getDeptId());
  87. // sysGeographyPositionInfoVo.setDeptName(sysDept.getName());
  88. sysGeographyPositionInfoVo.setDeptName(deptName);
  89. }
  90. sysGeographyPositionVo.setList(sysGeographyPositionList);
  91. }else if (type == 2){
  92. //查询人员下属管理所有人员
  93. List<String> ids = new ArrayList<>();
  94. List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
  95. .eq(SysUser::getLeaderId, sysGeographyPositionDto.getQueryId()).ne(SysUser::getStatus, 0));
  96. List<String> collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
  97. if (collect.size() == 0) return sysGeographyPositionVo;
  98. List<String> idList = queryList(collect, ids);
  99. collect.addAll(idList);
  100. List<SysGeographyPosition> list = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>()
  101. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  102. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  103. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  104. .in(SysGeographyPosition::getSource, Arrays.asList("1", "2"))
  105. .in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect)
  106. .in(CollectionUtil.isNotEmpty(collectIds), SysGeographyPosition::getId, collectIds)
  107. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getSource()), SysGeographyPosition::getSource, sysGeographyPositionDto.getSource())
  108. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus())
  109. .orderByDesc(SysGeographyPosition::getCreateTime));
  110. if (list.size() == 0) return new SysGeographyPositionVo();
  111. List<SysGeographyPositionInfoVo> sysGeographyPositionList = BeanUtil.copyToList(list, SysGeographyPositionInfoVo.class);
  112. //填充机构名
  113. for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionList) {
  114. SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId());
  115. if (sysUser == null) continue;
  116. sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName());
  117. SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>()
  118. .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0));
  119. if (sysDept == null) continue;
  120. String deptName = getDeptName(sysUser.getDeptId());
  121. // sysGeographyPositionInfoVo.setDeptName(sysDept.getName());
  122. sysGeographyPositionInfoVo.setDeptName(deptName);
  123. }
  124. sysGeographyPositionVo.setList(sysGeographyPositionList);
  125. }else {
  126. List<SysGeographyPosition> list = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>()
  127. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  128. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  129. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  130. .in(SysGeographyPosition::getSource, Arrays.asList("1", "2"))
  131. .in(CollectionUtil.isNotEmpty(collectIds), SysGeographyPosition::getId, collectIds)
  132. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getSource()), SysGeographyPosition::getSource, sysGeographyPositionDto.getSource())
  133. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus())
  134. .orderByDesc(SysGeographyPosition::getCreateTime));
  135. if (list.size() == 0) return new SysGeographyPositionVo();
  136. List<SysGeographyPositionInfoVo> sysGeographyPositionList = BeanUtil.copyToList(list, SysGeographyPositionInfoVo.class);
  137. //填充机构名
  138. for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionList) {
  139. SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId());
  140. if (sysUser == null) continue;
  141. sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName());
  142. SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>()
  143. .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0));
  144. if (sysDept == null) continue;
  145. String deptName = getDeptName(sysUser.getDeptId());
  146. // sysGeographyPositionInfoVo.setDeptName(sysDept.getName());
  147. sysGeographyPositionInfoVo.setDeptName(deptName);
  148. }
  149. sysGeographyPositionVo.setList(sysGeographyPositionList);
  150. }
  151. return sysGeographyPositionVo;
  152. }
  153. private List<String> queryList(List<String> collect, List<String> ids) {
  154. int size = collect.size();
  155. if (size > 0) {
  156. List<String> strings = new ArrayList<>();
  157. for (String id : collect) {
  158. List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
  159. .eq(SysUser::getLeaderId, id).ne(SysUser::getStatus, 0));
  160. // List<SysUser> sysUsers = sysUserMapper.querySourceId(id);
  161. if (sysUsers.size() > 0) {
  162. List<String> list = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
  163. strings.addAll(list);
  164. ids.addAll(list);
  165. if (collect.indexOf(id) + 1 == size) {
  166. queryList(strings, ids);
  167. }
  168. }
  169. }
  170. }
  171. return ids;
  172. }
  173. private String getDeptName(String deptId) {
  174. StringBuilder stringBuilder = new StringBuilder();
  175. SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>()
  176. .eq(SysDept::getId, deptId).eq(SysDept::getDelFlag, 0));
  177. if (StringUtils.isEmpty(sysDept.getComlevel())) {
  178. SysDept sysDept5 = sysDeptMapper.selectById(sysDept.getParentId());
  179. if (sysDept5 == null) {
  180. stringBuilder.append(sysDept.getName());
  181. }else {
  182. SysDept sysDept4 = sysDeptMapper.selectById(sysDept5.getParentId());
  183. if (sysDept4 == null) {
  184. stringBuilder.append(sysDept5.getName()).append("-").append(sysDept.getName());
  185. }else {
  186. SysDept sysDept3 = sysDeptMapper.selectById(sysDept4.getParentId());
  187. if (sysDept3 == null) {
  188. stringBuilder.append(sysDept4.getName())
  189. .append("-").append(sysDept5.getName()).append("-").append(sysDept.getName());
  190. }else {
  191. SysDept sysDept2 = sysDeptMapper.selectById(sysDept3.getParentId());
  192. if (sysDept2 == null) {
  193. stringBuilder.append(sysDept3.getName()).append("-").append(sysDept4.getName())
  194. .append("-").append(sysDept5.getName()).append("-").append(sysDept.getName());
  195. }else {
  196. stringBuilder.append(sysDept2.getName()).append("-").append(sysDept3.getName())
  197. .append("-").append(sysDept4.getName()).append("-").append(sysDept5.getName()).append("-").append(sysDept.getName());
  198. }
  199. }
  200. }
  201. }
  202. }else if (sysDept.getComlevel().equals("5")) {
  203. SysDept sysDept4 = sysDeptMapper.selectById(sysDept.getParentId());
  204. if (sysDept4 == null) {
  205. stringBuilder.append(sysDept.getName());
  206. }else {
  207. SysDept sysDept3 = sysDeptMapper.selectById(sysDept4.getParentId());
  208. if (sysDept3 == null) {
  209. stringBuilder.append(sysDept4.getName()).append("-").append(sysDept.getName());
  210. }else {
  211. SysDept sysDept2 = sysDeptMapper.selectById(sysDept3.getParentId());
  212. if (sysDept2 == null) {
  213. stringBuilder.append(sysDept3.getName()).append("-").append(sysDept4.getName()).append("-").append(sysDept.getName());
  214. }else {
  215. stringBuilder.append(sysDept2.getName()).append("-").append(sysDept3.getName()).append("-").append(sysDept4.getName()).append("-").append(sysDept.getName());
  216. }
  217. }
  218. }
  219. }else if (sysDept.getComlevel().equals("4")) {
  220. SysDept sysDept3 = sysDeptMapper.selectById(sysDept.getParentId());
  221. if (sysDept3 == null) {
  222. stringBuilder.append(sysDept.getName());
  223. }else {
  224. SysDept sysDept2 = sysDeptMapper.selectById(sysDept3.getParentId());
  225. if (sysDept2 == null) {
  226. stringBuilder.append(sysDept3.getName()).append("-").append(sysDept.getName());
  227. }else {
  228. stringBuilder.append(sysDept2.getName()).append("-").append(sysDept3.getName()).append("-").append(sysDept.getName());
  229. }
  230. }
  231. }else if (sysDept.getComlevel().equals("3")) {
  232. SysDept sysDept2 = sysDeptMapper.selectById(sysDept.getParentId());
  233. if (sysDept2 == null) {
  234. stringBuilder.append(sysDept.getName());
  235. }else {
  236. stringBuilder.append(sysDept2.getName()).append("-").append(sysDept.getName());
  237. }
  238. }else if (sysDept.getComlevel().equals("2")) {
  239. stringBuilder.append(sysDept.getName());
  240. }
  241. String s = stringBuilder.toString();
  242. if (s.contains("总部-")) {
  243. stringBuilder.replace(0,3,"");
  244. }
  245. return stringBuilder.toString();
  246. }
  247. @Override
  248. public BasePageResult<SysGeographyPositionRecord> queryPositionList(SysGeographyPositionPageDto sysGeographyPositionPageDto) {
  249. Page<SysGeographyPositionRecord> page = new Page<>(sysGeographyPositionPageDto.getPageNum(), sysGeographyPositionPageDto.getPageSize());
  250. LambdaQueryWrapper<SysGeographyPositionRecord> wrapper = new LambdaQueryWrapper<>();
  251. wrapper.eq(StringUtils.isNotEmpty(sysGeographyPositionPageDto.getId()), SysGeographyPositionRecord::getUserId, sysGeographyPositionPageDto.getId());
  252. wrapper.orderByDesc(SysGeographyPositionRecord::getCreateTime);
  253. Page<SysGeographyPositionRecord> insOrdersPage = sysGeographyPositionRecordService.page(page, wrapper);
  254. List<SysGeographyPositionRecord> records = insOrdersPage.getRecords();
  255. if (records.size()>0) {
  256. for (SysGeographyPositionRecord record : records) {
  257. SysUser sysUser = sysUserService.getById(record.getUserId());
  258. if (sysUser == null) continue;
  259. record.setLeaderName(sysUser.getLeaderName());
  260. String deptName = getDeptName(sysUser.getDeptId());
  261. record.setDeptName(deptName);
  262. }
  263. }
  264. return new BasePageResult<>(sysGeographyPositionPageDto.getPageNum(), page.getSize(), insOrdersPage.getTotal(), page.getPages(),
  265. insOrdersPage.getRecords());
  266. }
  267. @Override
  268. public SysPcAddressNumVo queryPcNum(SysGeographyPositionDto sysGeographyPositionDto) {
  269. SysPcAddressNumVo sysPcAddressNumVo = new SysPcAddressNumVo();
  270. String userId = BaseController.getUserId();
  271. List<String> collect = new ArrayList<>();
  272. if (!"admin".equals(userId)) {
  273. List<String> ids = new ArrayList<>();
  274. List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
  275. .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0));
  276. collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
  277. if (collect.size() == 0) return sysPcAddressNumVo;
  278. List<String> idList = queryList(collect, ids);
  279. collect.addAll(idList);
  280. }
  281. Long all = sysGeographyPositionMapper.selectCount(new LambdaQueryWrapper<SysGeographyPosition>()
  282. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  283. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  284. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  285. .in(SysGeographyPosition::getSource, Arrays.asList("1", "2"))
  286. .in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect)
  287. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus()));
  288. Long channelNum = sysGeographyPositionMapper.selectCount(new LambdaQueryWrapper<SysGeographyPosition>()
  289. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  290. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  291. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  292. .eq(SysGeographyPosition::getSource, 1)
  293. .in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect)
  294. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus()));
  295. Long proxyNum = sysGeographyPositionMapper.selectCount(new LambdaQueryWrapper<SysGeographyPosition>()
  296. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  297. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  298. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  299. .eq(SysGeographyPosition::getSource, 2)
  300. .in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect)
  301. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus()));
  302. Long onlineNum = sysGeographyPositionMapper.selectCount(new LambdaQueryWrapper<SysGeographyPosition>()
  303. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  304. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  305. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  306. .in(SysGeographyPosition::getSource, Arrays.asList("1", "2"))
  307. .in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect)
  308. .eq(sysGeographyPositionDto.getStatus() == null, SysGeographyPosition::getStatus, 1)
  309. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus()));
  310. sysPcAddressNumVo.setAllNum(all);
  311. sysPcAddressNumVo.setProxyNum(proxyNum);
  312. sysPcAddressNumVo.setChannelNum(channelNum);
  313. sysPcAddressNumVo.setOnlineNum(onlineNum);
  314. return sysPcAddressNumVo;
  315. }
  316. @Override
  317. public List<RegionInfoVo> queryRegionInfo(SysGeographyPositionDto sysGeographyPositionDto) {
  318. List<RegionInfoVo> regionInfoVos = new ArrayList<>();
  319. //admin 可看所有,其他下只能看下面管理的人员
  320. String userId = BaseController.getUserId();
  321. List<String> collect = new ArrayList<>();
  322. if (!"admin".equals(userId)) {
  323. List<String> ids = new ArrayList<>();
  324. List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
  325. .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0));
  326. collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
  327. if (collect.size() == 0) return regionInfoVos;
  328. List<String> idList = queryList(collect, ids);
  329. collect.addAll(idList);
  330. }
  331. //全部:null 渠道:1 代理:2
  332. List<SysGeographyPosition> sysGeographyPositionList = sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>()
  333. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getProvince()), SysGeographyPosition::getProvince, sysGeographyPositionDto.getProvince())
  334. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getCity()), SysGeographyPosition::getCity, sysGeographyPositionDto.getCity())
  335. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getDistrict()), SysGeographyPosition::getDistrict, sysGeographyPositionDto.getDistrict())
  336. .in(SysGeographyPosition::getSource, Arrays.asList("1", "2"))
  337. .in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect)
  338. .eq(StringUtils.isNotEmpty(sysGeographyPositionDto.getSource()), SysGeographyPosition::getSource, sysGeographyPositionDto.getSource())
  339. .eq(sysGeographyPositionDto.getStatus() != null, SysGeographyPosition::getStatus, sysGeographyPositionDto.getStatus()));
  340. if (CollectionUtil.isEmpty(sysGeographyPositionList)) return regionInfoVos;
  341. Map<String, List<SysGeographyPosition>> map;
  342. if (StringUtils.isEmpty(sysGeographyPositionDto.getProvince())) {
  343. map = sysGeographyPositionList.stream().collect(Collectors.groupingBy(SysGeographyPosition::getProvince));
  344. } else {
  345. if (StringUtils.isNotEmpty(sysGeographyPositionDto.getCity())) {
  346. map = sysGeographyPositionList.stream().collect(Collectors.groupingBy(SysGeographyPosition::getDistrict));
  347. } else {
  348. map = sysGeographyPositionList.stream().collect(Collectors.groupingBy(SysGeographyPosition::getCity));
  349. }
  350. }
  351. for (Map.Entry<String, List<SysGeographyPosition>> entry : map.entrySet()) {
  352. RegionInfoVo regionInfoVo = new RegionInfoVo();
  353. regionInfoVo.setDistrictName(entry.getKey());
  354. regionInfoVo.setNumber(entry.getValue().size());
  355. regionInfoVos.add(regionInfoVo);
  356. }
  357. return regionInfoVos;
  358. }
  359. @Override
  360. public List<SysGeographyPositionInfoVo> findLocationsWithinRadius(AdressRangeDto adressRangeDto) {
  361. geoService.addLocationGeography(list(), APP_GEO_KEY);
  362. List<String> nearbyIds = geoService.findNearbyIds(APP_GEO_KEY, adressRangeDto.getLongitude(), adressRangeDto.getLatitude(), adressRangeDto.getRadius());
  363. if (nearbyIds.size() == 0) return new ArrayList<>();
  364. geoService.move(nearbyIds, APP_GEO_KEY);
  365. List<SysGeographyPosition> sysGeographyPositions = listByIds(nearbyIds);
  366. List<SysGeographyPositionInfoVo> sysGeographyPositionInfoVoList = BeanUtil.copyToList(sysGeographyPositions, SysGeographyPositionInfoVo.class);
  367. if (sysGeographyPositionInfoVoList.size() == 0) return sysGeographyPositionInfoVoList;
  368. for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionInfoVoList) {
  369. SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId());
  370. if (sysUser == null) continue;
  371. SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>()
  372. .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0));
  373. if (sysDept == null) continue;
  374. sysGeographyPositionInfoVo.setDeptName(sysDept.getName());
  375. }
  376. return sysGeographyPositionInfoVoList;
  377. }
  378. @Override
  379. public BasePageResult<SysGeographyPositionInfoVo> queryPcAddressInfo(PcAddressInfoDto addressInfoDto) {
  380. Page<SysGeographyPosition> page = new Page<>(addressInfoDto.getPageNum(), addressInfoDto.getPageSize());
  381. //admin 可看所有,其他下只能看下面管理的人员
  382. String userId = BaseController.getUserId();
  383. List<String> collectIds = new ArrayList<>();
  384. if (!"admin".equals(userId)) {
  385. List<String> ids = new ArrayList<>();
  386. List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
  387. .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0));
  388. collectIds = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
  389. if (collectIds.size() > 0) {
  390. List<String> idList = queryList(collectIds, ids);
  391. collectIds.addAll(idList);
  392. }
  393. }
  394. Page<SysGeographyPosition> insOrdersPage;
  395. Integer type = addressInfoDto.getType();
  396. if (type == 1) {
  397. LambdaQueryWrapper<SysGeographyPosition> wrapper = new LambdaQueryWrapper<>();
  398. wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLng()), SysGeographyPosition::getLongitude, addressInfoDto.getLng());
  399. wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLat()), SysGeographyPosition::getLatitude, addressInfoDto.getLat());
  400. wrapper.in(SysGeographyPosition::getSource, Arrays.asList("1", "2"));
  401. wrapper.in(CollectionUtil.isNotEmpty(collectIds), SysGeographyPosition::getId, collectIds);
  402. wrapper.likeRight(StringUtils.isNotEmpty(addressInfoDto.getQueryId()), SysGeographyPosition::getId, addressInfoDto.getQueryId());
  403. wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getSource()), SysGeographyPosition::getSource, addressInfoDto.getSource());
  404. wrapper.orderByDesc(SysGeographyPosition::getCreateTime);
  405. insOrdersPage = page(page, wrapper);
  406. }else if (type == 2) {
  407. //查询人员下属管理所有人员
  408. List<String> ids = new ArrayList<>();
  409. List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
  410. .eq(SysUser::getLeaderId, addressInfoDto.getQueryId()).ne(SysUser::getStatus, 0));
  411. List<String> collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
  412. if (collect.size() > 0) {
  413. List<String> idList = queryList(collect, ids);
  414. collect.addAll(idList);
  415. }
  416. LambdaQueryWrapper<SysGeographyPosition> wrapper = new LambdaQueryWrapper<>();
  417. wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLng()), SysGeographyPosition::getLongitude, addressInfoDto.getLng());
  418. wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLat()), SysGeographyPosition::getLatitude, addressInfoDto.getLat());
  419. wrapper.in(SysGeographyPosition::getSource, Arrays.asList("1", "2"));
  420. wrapper.in(CollectionUtil.isNotEmpty(collectIds), SysGeographyPosition::getId, collectIds);
  421. wrapper.in(CollectionUtil.isNotEmpty(collect), SysGeographyPosition::getId, collect);
  422. wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getSource()), SysGeographyPosition::getSource, addressInfoDto.getSource());
  423. wrapper.orderByDesc(SysGeographyPosition::getCreateTime);
  424. insOrdersPage = page(page, wrapper);
  425. }else {
  426. LambdaQueryWrapper<SysGeographyPosition> wrapper = new LambdaQueryWrapper<>();
  427. wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLng()), SysGeographyPosition::getLongitude, addressInfoDto.getLng());
  428. wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getLat()), SysGeographyPosition::getLatitude, addressInfoDto.getLat());
  429. wrapper.in(SysGeographyPosition::getSource, Arrays.asList("1", "2"));
  430. wrapper.in(CollectionUtil.isNotEmpty(collectIds), SysGeographyPosition::getId, collectIds);
  431. wrapper.eq(StringUtils.isNotEmpty(addressInfoDto.getSource()), SysGeographyPosition::getSource, addressInfoDto.getSource());
  432. wrapper.orderByDesc(SysGeographyPosition::getCreateTime);
  433. insOrdersPage = page(page, wrapper);
  434. }
  435. List<SysGeographyPosition> records = insOrdersPage.getRecords();
  436. List<SysGeographyPositionInfoVo> sysGeographyPositionList = BeanUtil.copyToList(records, SysGeographyPositionInfoVo.class);
  437. //填充机构名
  438. for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : sysGeographyPositionList) {
  439. SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getId());
  440. if (sysUser == null) continue;
  441. sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName());
  442. SysDept sysDept = sysDeptMapper.selectOne(new LambdaQueryWrapper<SysDept>()
  443. .eq(SysDept::getId, sysUser.getDeptId()).eq(SysDept::getDelFlag, 0));
  444. if (sysDept == null) continue;
  445. String deptName = getDeptName(sysUser.getDeptId());
  446. sysGeographyPositionInfoVo.setDeptName(deptName);
  447. }
  448. return new BasePageResult<>(addressInfoDto.getPageNum(), page.getSize(), insOrdersPage.getTotal(), page.getPages(),
  449. sysGeographyPositionList);
  450. }
  451. private List<String> getcollectIds() {
  452. String userId = BaseController.getUserId();
  453. List<String> collectIds = new ArrayList<>();
  454. if (!"admin".equals(userId)) {
  455. List<String> ids = new ArrayList<>();
  456. List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
  457. .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0));
  458. collectIds = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
  459. if (collectIds.size() > 0) {
  460. List<String> idList = queryList(collectIds, ids);
  461. collectIds.addAll(idList);
  462. }
  463. }
  464. return collectIds;
  465. }
  466. @Override
  467. public BasePageResult<SysGeographyPositionInfoVo> queryGeographyRecord(PcAddressInfoDto addressInfoDto) {
  468. Page page = new Page(addressInfoDto.getPageNum(), addressInfoDto.getPageSize());
  469. IPage<SysGeographyPositionInfoVo> sysGeographyPositionList;
  470. //登陆人的下属id
  471. String userId = BaseController.getUserId();
  472. List<String> collectIds =new ArrayList<>();
  473. if (!"admin".equals(userId)) {
  474. //admin看所有人
  475. List<String> ids = new ArrayList<>();
  476. List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
  477. .eq(SysUser::getLeaderId, BaseController.getUserId()).ne(SysUser::getStatus, 0));
  478. collectIds = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
  479. if (collectIds .size()==0) return new BasePageResult<>(addressInfoDto.getPageNum(), addressInfoDto.getPageSize(), 0L, 0L, null);
  480. List<String> idList = queryList(collectIds, ids);
  481. collectIds.addAll(idList);
  482. }
  483. addressInfoDto.setCollectIds(collectIds);
  484. // 类型:1。机构树 2.用户树 0:默认查询
  485. Integer type = addressInfoDto.getType();
  486. if (type == 1) {
  487. sysGeographyPositionList = sysGeographyPositionRecordMapper.queryGeographyHistory(page,addressInfoDto);
  488. }else if (type == 2) {
  489. List<String> ids = new ArrayList<>();
  490. List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
  491. .eq(SysUser::getLeaderId, addressInfoDto.getQueryId()).ne(SysUser::getStatus, 0));
  492. List<String> collect= sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
  493. if (collect.size()>0) {
  494. List<String> idList = queryList(collect, ids);
  495. collect.addAll(idList);
  496. }
  497. addressInfoDto.setQueryId(null);
  498. addressInfoDto.setCollect(collect);
  499. sysGeographyPositionList = sysGeographyPositionRecordMapper.queryGeographyHistory(page,addressInfoDto);
  500. }else {
  501. sysGeographyPositionList = sysGeographyPositionRecordMapper.queryGeographyHistory(page,addressInfoDto);
  502. }
  503. List<SysGeographyPositionInfoVo> records = sysGeographyPositionList.getRecords();
  504. //填充机构名
  505. for (SysGeographyPositionInfoVo sysGeographyPositionInfoVo : records) {
  506. SysUser sysUser = sysUserService.getById(sysGeographyPositionInfoVo.getUserId());
  507. if (sysUser == null) continue;
  508. sysGeographyPositionInfoVo.setLeaderName(sysUser.getLeaderName());
  509. String deptName = getDeptName(sysUser.getDeptId());
  510. sysGeographyPositionInfoVo.setDeptName(deptName);
  511. }
  512. return new BasePageResult<>(addressInfoDto.getPageNum(), addressInfoDto.getPageSize(), sysGeographyPositionList.getTotal(), sysGeographyPositionList.getPages(),
  513. records);
  514. }
  515. @Override
  516. public AppGeographyHistoryInfoVo getGeographyPosition(String startTime, String endTime, String source) {
  517. AppGeographyHistoryInfoVo appGeographyHistoryInfoVo = new AppGeographyHistoryInfoVo();
  518. //admin 可看所有,其他下只能看下面管理的人员
  519. String userId = BaseController.getUserId();
  520. List<String> collect = new ArrayList<>();
  521. if (!"admin".equals(userId)) {
  522. List<String> ids = new ArrayList<>();
  523. List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
  524. .eq(SysUser::getLeaderId, userId).ne(SysUser::getStatus, 0));
  525. collect = sysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
  526. if (collect.size() == 0) return appGeographyHistoryInfoVo;
  527. List<String> idList = queryList(collect, ids);
  528. collect.addAll(idList);
  529. }
  530. if (StringUtils.isEmpty(startTime) || startTime.equals(endTime)) {
  531. if (StringUtils.isNullOrEmpty(startTime)) {
  532. Date date = new Date();
  533. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  534. startTime = simpleDateFormat.format(date);
  535. }
  536. QueryWrapper<SysGeographyPositionRecord> queryWrapper = new QueryWrapper<>();
  537. // 指定 COUNT(DISTINCT user_id) 查询
  538. queryWrapper.select("COUNT(DISTINCT user_id) AS total")
  539. .likeRight(StringUtils.isNotEmpty(startTime), "create_time", startTime)
  540. .in("source", Arrays.asList(1, 2))
  541. .in(CollectionUtil.isNotEmpty(collect), "user_id", collect)
  542. .eq(StringUtils.isNotEmpty(source),"source",source);
  543. Map<String, Object> result = sysGeographyPositionRecordService.getMap(queryWrapper);
  544. Long total = (Long) result.get("total");
  545. appGeographyHistoryInfoVo.setOnlineNum(total);
  546. List<PcAddressHistoryTimeVo> geographyPosition = sysGeographyPositionRecordMapper.getGeographyPosition(startTime,source,collect);
  547. appGeographyHistoryInfoVo.setList(geographyPosition);
  548. List<SysGeographyPositionRecord> sysGeographyPositionRecords =sysGeographyPositionRecordMapper.getGeographyPositionRecord(startTime,source,collect);
  549. extracted(sysGeographyPositionRecords);
  550. System.out.println("********************" + sysGeographyPositionRecords.size());
  551. appGeographyHistoryInfoVo.setPositionRecordList(sysGeographyPositionRecords);
  552. }else {
  553. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  554. startTime = startTime + " 00:00:01";
  555. endTime = endTime + " 23:59:59";
  556. try {
  557. Date parse = simpleDateFormat.parse(startTime);
  558. Date parse1 = simpleDateFormat.parse(endTime);
  559. startTime = simpleDateFormat.format(parse);
  560. endTime = simpleDateFormat.format(parse1);
  561. } catch (ParseException e) {
  562. throw new RuntimeException(e);
  563. }
  564. QueryWrapper<SysGeographyPositionRecord> queryWrapper = new QueryWrapper<>();
  565. queryWrapper.select("COUNT(DISTINCT user_id) AS total")
  566. .between("create_time", startTime, endTime)
  567. .in("source", Arrays.asList(1, 2))
  568. .in(CollectionUtil.isNotEmpty(collect), "user_id", collect)
  569. .eq(StringUtils.isNotEmpty(source),"source",source);
  570. Map<String, Object> result = sysGeographyPositionRecordService.getMap(queryWrapper);
  571. Long total = (Long) result.get("total");
  572. appGeographyHistoryInfoVo.setOnlineNum(total);
  573. List<PcAddressHistoryTimeVo> geographyPosition = sysGeographyPositionRecordMapper.getGeographyPositionSection(startTime,endTime,source,collect);
  574. appGeographyHistoryInfoVo.setList(geographyPosition);
  575. List<SysGeographyPositionRecord> sysGeographyPositionRecords =sysGeographyPositionRecordMapper.getGeographyPositionHistory(startTime,endTime,source,collect);
  576. extracted(sysGeographyPositionRecords);
  577. System.out.println("********************" + sysGeographyPositionRecords.size());
  578. appGeographyHistoryInfoVo.setPositionRecordList(sysGeographyPositionRecords);
  579. }
  580. return appGeographyHistoryInfoVo;
  581. }
  582. private void extracted(List<SysGeographyPositionRecord> sysGeographyPositionRecords) {
  583. for (SysGeographyPositionRecord sysGeographyPositionRecord : sysGeographyPositionRecords) {
  584. SysUser sysUser = sysUserService.getById(sysGeographyPositionRecord.getUserId());
  585. if (sysUser == null) continue;
  586. sysGeographyPositionRecord.setLeaderName(sysUser.getLeaderName());
  587. String deptName = getDeptName(sysUser.getDeptId());
  588. sysGeographyPositionRecord.setDeptName(deptName);
  589. }
  590. }
  591. @Override
  592. public List<SysGeographyPosition> getOnlinePeople() {
  593. return sysGeographyPositionMapper.selectList(new LambdaQueryWrapper<SysGeographyPosition>().eq(SysGeographyPosition::getStatus,1));
  594. }
  595. }