ChannelMapServiceImpl.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. package com.ruoyi.demo.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.github.pagehelper.PageHelper;
  5. import com.github.pagehelper.PageInfo;
  6. import com.ruoyi.demo.entity.*;
  7. import com.ruoyi.demo.entity.bo.*;
  8. import com.ruoyi.demo.entity.vo.ChannelMapAceeptVo;
  9. import com.ruoyi.demo.mapper.*;
  10. import com.ruoyi.demo.service.ChannelMapService;
  11. import com.ruoyi.demo.utils.InitMapUtil;
  12. import com.ruoyi.demo.utils.WdRedisStoreage;
  13. import io.netty.util.concurrent.CompleteFuture;
  14. import lombok.RequiredArgsConstructor;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.data.redis.core.RedisTemplate;
  17. import org.springframework.stereotype.Service;
  18. import org.springframework.transaction.annotation.Transactional;
  19. import java.math.BigDecimal;
  20. import java.util.ArrayList;
  21. import java.util.Arrays;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.concurrent.CompletableFuture;
  25. import java.util.stream.Collectors;
  26. @RequiredArgsConstructor
  27. @Service
  28. @Transactional
  29. public class ChannelMapServiceImpl implements ChannelMapService {
  30. @Autowired
  31. private AddrCategoryDao addrCategoryDao;
  32. @Autowired
  33. InitMapUtil initMapUtil;
  34. @Autowired
  35. AttentionPoolDao attentionPoolDao;
  36. @Autowired
  37. WdInfoDao wdInfoDao;
  38. @Autowired
  39. RedisTemplate redisTemplate;
  40. @Autowired
  41. WdRedisStoreage wdRedisStoreage;
  42. @Autowired
  43. StoreWdDao storeWdDao;
  44. @Autowired
  45. HouseWdDao houseWdDao;
  46. @Autowired
  47. BuildWdDao buildWdDao;
  48. @Autowired
  49. TrafficWdDao trafficWdDao;
  50. @Autowired
  51. EnterpriseWdDao enterpriseWdDao;
  52. /**
  53. * 地图模式:查看所有地区的网点数量(v1.0)
  54. * @param channelMapAceeptVo
  55. * @return
  56. */
  57. /* @Override
  58. public WdCount area(ChannelMapAceeptVo channelMapAceeptVo) {
  59. //1.根据不同级别得到 需要封装的 地区码
  60. List<String> addrCodeList = new ArrayList<>();
  61. if ("province".equals(channelMapAceeptVo.getRankType())) {
  62. //省码
  63. for (String s : channelMapAceeptVo.getAddrCode()) {
  64. String substring = s.substring(0, 2);
  65. addrCodeList.add(substring);
  66. }
  67. } else if ("city".equals(channelMapAceeptVo.getRankType())) {
  68. //省的所有市
  69. for (String s : channelMapAceeptVo.getAddrCode()) {
  70. String substring = s.substring(0, 2);
  71. addrCodeList.add(substring);
  72. }
  73. } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
  74. //市的所有区
  75. for (String s : channelMapAceeptVo.getAddrCode()) {
  76. String substring = s.substring(0, 4);
  77. addrCodeList.add(substring);
  78. }
  79. } else {
  80. return null;
  81. }
  82. //2.找到所有需要封装的 地区信息
  83. QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
  84. if ("province".equals(channelMapAceeptVo.getRankType())) {
  85. queryWrapper.eq("city", "");
  86. } else if ("city".equals(channelMapAceeptVo.getRankType())) {
  87. queryWrapper.eq("district", "").and(addrCategoryQueryWrapper -> {
  88. addrCategoryQueryWrapper.ne("city", "");
  89. });
  90. } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
  91. queryWrapper.ne("district", "");
  92. }
  93. queryWrapper.and(addrCategoryQueryWrapper -> {
  94. addrCategoryQueryWrapper.or(addrCategoryQueryWrapper1 -> {
  95. for (String s : addrCodeList) {
  96. addrCategoryQueryWrapper1.likeRight("addr_code", s).or();
  97. }
  98. });
  99. });
  100. List<AddrCategory> addrCategories = addrCategoryDao.selectList(queryWrapper);
  101. //3.组装地区信息
  102. List<WdCountBody> result = new ArrayList<>();
  103. HashMap<String,Integer> statistics = new HashMap<>(); //统计信息
  104. for (AddrCategory addrCategory : addrCategories) {
  105. WdCountBody wdCountBody = new WdCountBody();
  106. //组装
  107. wdCountBody.setLat(addrCategory.getLatGd());
  108. wdCountBody.setLng(addrCategory.getLngGd());
  109. wdCountBody.setAddrCode(addrCategory.getAddrCode());
  110. if ("province".equals(channelMapAceeptVo.getRankType())) {
  111. wdCountBody.setName(addrCategory.getProvince());
  112. statistics.put(addrCategory.getAddrCode().substring(0,2),0);
  113. } else if ("city".equals(channelMapAceeptVo.getRankType())) {
  114. wdCountBody.setName(addrCategory.getCity());
  115. statistics.put(addrCategory.getAddrCode().substring(0,4),0);
  116. } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
  117. wdCountBody.setName(addrCategory.getDistrict());
  118. statistics.put(addrCategory.getAddrCode().substring(0,6),0);
  119. }
  120. result.add(wdCountBody);
  121. }
  122. //4.组装条件构造器找到网点信息网点
  123. //2.1 渠道、地区分类
  124. QueryWrapper<WdInfo> queryWrapper2 = new QueryWrapper<>();
  125. queryWrapper2.select("addr_code","count(*) as audit");
  126. queryWrapper2.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
  127. for (String s : addrCodeList) {
  128. originWdInfoQueryWrapper.likeRight("addr_code", s).or();
  129. }
  130. });
  131. //搜索字段
  132. if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
  133. queryWrapper2.and(originWdInfoQueryWrapper -> {
  134. originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
  135. });
  136. }
  137. //城市等级分类
  138. if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
  139. List<String> tierCode = new ArrayList<>();
  140. for (String s : channelMapAceeptVo.getCityTier()) {
  141. List<String> list = initMapUtil.getInitCityTierListMap(s);
  142. if (list != null){
  143. tierCode.addAll(list);
  144. }
  145. }
  146. queryWrapper.and(wdInfoQueryWrapper -> {
  147. for (String s : tierCode) {
  148. wdInfoQueryWrapper.likeRight("addr_code", s).or();
  149. }
  150. });
  151. }
  152. queryWrapper2.groupBy("addr_code");
  153. //5.统计
  154. int total = 0;
  155. List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper2);
  156. for (WdInfo wdInfo : wdInfos) {
  157. if("province".equals(channelMapAceeptVo.getRankType())){
  158. statistics.put(wdInfo.getAddrCode().substring(0,2),statistics.get(wdInfo.getAddrCode().substring(0,2))+wdInfo.getAudit());
  159. } else if ("city".equals(channelMapAceeptVo.getRankType())) {
  160. statistics.put(wdInfo.getAddrCode().substring(0,4),statistics.get(wdInfo.getAddrCode().substring(0,4))+wdInfo.getAudit());
  161. } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
  162. statistics.put(wdInfo.getAddrCode().substring(0,6),statistics.get(wdInfo.getAddrCode().substring(0,6))+wdInfo.getAudit());
  163. }
  164. total+=+wdInfo.getAudit();
  165. }
  166. //5.计算radio
  167. for (WdCountBody wdCountBody : result) {
  168. String code = null;
  169. if("province".equals(channelMapAceeptVo.getRankType())){
  170. code = wdCountBody.getAddrCode().substring(0,2);
  171. }else if("city".equals(channelMapAceeptVo.getRankType())){
  172. code = wdCountBody.getAddrCode().substring(0,4);
  173. }else if("zone".equals(channelMapAceeptVo.getRankType())){
  174. code = wdCountBody.getAddrCode().substring(0,6);
  175. }
  176. if(statistics.get(code) != null){
  177. wdCountBody.setCount(statistics.get(code));
  178. }else {
  179. wdCountBody.setCount(0);
  180. }
  181. if (total != 0){
  182. BigDecimal bigDecimal = new BigDecimal((float) wdCountBody.getCount() / total);
  183. float v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
  184. wdCountBody.setRadio(v);
  185. }
  186. else
  187. wdCountBody.setRadio(0.0f);
  188. }
  189. WdCount wdCount = new WdCount();
  190. wdCount.setWdCountBodyList(result);
  191. wdCount.setTotal(total);
  192. return wdCount;
  193. }*/
  194. /**
  195. * 地图模式:查看所有地区的网点数量(v2.0)
  196. * @param channelMapAceeptVo
  197. * @return
  198. */
  199. @Override
  200. public WdCount area(ChannelMapAceeptVo channelMapAceeptVo) {
  201. //1.根据不同级别得到 需要查询的 网点地区码
  202. CompletableFuture<List<String>> completableFuture1 = CompletableFuture.supplyAsync(() -> {
  203. return findWdAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
  204. });
  205. //2.找到所有需要封装的 地区信息
  206. CompletableFuture<List<AddrCategory>> completableFuture2 = CompletableFuture.supplyAsync(() -> {
  207. return findCenterAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
  208. });
  209. List<AddrCategory> addrCategories = completableFuture2.join();
  210. //3.组装地区信息
  211. List<WdCountBody> result = new ArrayList<>();
  212. HashMap<String,Integer> statistics = new HashMap<>(); //初始化统计信息
  213. for (AddrCategory addrCategory : addrCategories) {
  214. WdCountBody wdCountBody = new WdCountBody();
  215. //组装
  216. wdCountBody.setLat(addrCategory.getLatGd());
  217. wdCountBody.setLng(addrCategory.getLngGd());
  218. wdCountBody.setAddrCode(addrCategory.getAddrCode());
  219. if ("province".equals(channelMapAceeptVo.getRankType())) {
  220. wdCountBody.setName(addrCategory.getProvince());
  221. statistics.put(addrCategory.getAddrCode().substring(0,2),0);
  222. } else if ("city".equals(channelMapAceeptVo.getRankType())) {
  223. wdCountBody.setName(addrCategory.getCity());
  224. statistics.put(addrCategory.getAddrCode().substring(0,4),0);
  225. } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
  226. wdCountBody.setName(addrCategory.getDistrict());
  227. statistics.put(addrCategory.getAddrCode().substring(0,6),0);
  228. }
  229. result.add(wdCountBody);
  230. }
  231. //4.组装条件构造器找到网点信息网点
  232. //2.1 渠道、地区分类
  233. List<String> wdAddrCodes = completableFuture1.join();
  234. QueryWrapper<WdInfo> queryWrapper2 = new QueryWrapper<>();
  235. queryWrapper2.select("addr_code","count(*) as audit");
  236. queryWrapper2.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
  237. originWdInfoQueryWrapper.in("addr_code",wdAddrCodes);
  238. });
  239. //搜索字段
  240. if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
  241. queryWrapper2.and(originWdInfoQueryWrapper -> {
  242. originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
  243. });
  244. }
  245. //城市等级分类
  246. if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
  247. List<String> tierCode = new ArrayList<>();
  248. for (String s : channelMapAceeptVo.getCityTier()) {
  249. List<String> list = initMapUtil.getInitCityTierListMap(s);
  250. if (list != null){
  251. tierCode.addAll(list);
  252. }
  253. }
  254. queryWrapper2.and(wdInfoQueryWrapper -> {
  255. wdInfoQueryWrapper.in("addr_code",tierCode);
  256. });
  257. }
  258. queryWrapper2.groupBy("addr_code");
  259. //5.统计
  260. int total = 0;
  261. List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper2);
  262. for (WdInfo wdInfo : wdInfos) {
  263. if("province".equals(channelMapAceeptVo.getRankType())){
  264. statistics.put(wdInfo.getAddrCode().substring(0,2),statistics.get(wdInfo.getAddrCode().substring(0,2))+wdInfo.getAudit());
  265. } else if ("city".equals(channelMapAceeptVo.getRankType())) {
  266. statistics.put(wdInfo.getAddrCode().substring(0,4),statistics.get(wdInfo.getAddrCode().substring(0,4))+wdInfo.getAudit());
  267. } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
  268. statistics.put(wdInfo.getAddrCode().substring(0,6),statistics.get(wdInfo.getAddrCode().substring(0,6))+wdInfo.getAudit());
  269. }
  270. total+=+wdInfo.getAudit();
  271. }
  272. //5.计算radio
  273. for (WdCountBody wdCountBody : result) {
  274. String code = null;
  275. if("province".equals(channelMapAceeptVo.getRankType())){
  276. code = wdCountBody.getAddrCode().substring(0,2);
  277. }else if("city".equals(channelMapAceeptVo.getRankType())){
  278. code = wdCountBody.getAddrCode().substring(0,4);
  279. }else if("zone".equals(channelMapAceeptVo.getRankType())){
  280. code = wdCountBody.getAddrCode().substring(0,6);
  281. }
  282. if(statistics.get(code) != null){
  283. wdCountBody.setCount(statistics.get(code));
  284. }else {
  285. wdCountBody.setCount(0);
  286. }
  287. if (total != 0){
  288. BigDecimal bigDecimal = new BigDecimal((float) wdCountBody.getCount() / total);
  289. float v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
  290. wdCountBody.setRadio(v);
  291. }
  292. else
  293. wdCountBody.setRadio(0.0f);
  294. }
  295. //5.封装结果
  296. WdCount wdCount = new WdCount();
  297. wdCount.setWdCountBodyList(result);
  298. wdCount.setTotal(total);
  299. return wdCount;
  300. }
  301. /**
  302. * 地图模式:查看省级地区的网点数量(v2.0)
  303. * @param channelMapAceeptVo
  304. * @return
  305. */
  306. @Override
  307. public WdCount areaProvince(ChannelMapAceeptVo channelMapAceeptVo) {
  308. //1.找到所有需要封装的 地区信息
  309. List<AddrCategory> addrCategories = findCenterAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
  310. //2.组装地区信息
  311. List<WdCountBody> result = new ArrayList<>();
  312. HashMap<String,Integer> statistics = new HashMap<>(); //初始化统计信息
  313. for (AddrCategory addrCategory : addrCategories) {
  314. WdCountBody wdCountBody = new WdCountBody();
  315. //组装
  316. wdCountBody.setLat(addrCategory.getLatGd());
  317. wdCountBody.setLng(addrCategory.getLngGd());
  318. wdCountBody.setAddrCode(addrCategory.getAddrCode());
  319. wdCountBody.setName(addrCategory.getProvince());
  320. statistics.put(addrCategory.getAddrCode().substring(0,2),0);
  321. result.add(wdCountBody);
  322. }
  323. //3.找到符合条件的网点信息
  324. QueryWrapper<WdInfo> queryWrapper2 = new QueryWrapper<>();
  325. queryWrapper2.select("addr_code","count(*) as audit");
  326. assembleQueryWrapper(queryWrapper2,channelMapAceeptVo);
  327. queryWrapper2.groupBy("addr_code");
  328. //4.统计各个地区网点数量
  329. int total = 0;
  330. List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper2);
  331. for (WdInfo wdInfo : wdInfos) {
  332. statistics.put(wdInfo.getAddrCode().substring(0,2),statistics.get(wdInfo.getAddrCode().substring(0,2))+wdInfo.getAudit());
  333. total+=+wdInfo.getAudit();
  334. }
  335. //5.计算radio
  336. for (WdCountBody wdCountBody : result) {
  337. String code = null;
  338. code = wdCountBody.getAddrCode().substring(0,2);
  339. if(statistics.get(code) != null){
  340. wdCountBody.setCount(statistics.get(code));
  341. }else {
  342. wdCountBody.setCount(0);
  343. }
  344. if (total != 0){
  345. BigDecimal bigDecimal = new BigDecimal((float) wdCountBody.getCount() / total);
  346. float v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
  347. wdCountBody.setRadio(v);
  348. }
  349. else
  350. wdCountBody.setRadio(0.0f);
  351. }
  352. //5.封装结果
  353. WdCount wdCount = new WdCount();
  354. wdCount.setWdCountBodyList(result);
  355. wdCount.setTotal(total);
  356. return wdCount;
  357. }
  358. /**
  359. * 地图模式:查看市级地区的网点数量(v2.0)
  360. * @param channelMapAceeptVo
  361. * @return
  362. */
  363. @Override
  364. public WdCount areaCity(ChannelMapAceeptVo channelMapAceeptVo) {
  365. //1.根据不同级别得到 需要查询的 网点地区码
  366. CompletableFuture<List<String>> completableFuture1 = CompletableFuture.supplyAsync(() -> {
  367. return findWdAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
  368. });
  369. //2.找到所有需要封装的 地区信息
  370. CompletableFuture<List<AddrCategory>> completableFuture2 = CompletableFuture.supplyAsync(() -> {
  371. return findCenterAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
  372. });
  373. List<AddrCategory> addrCategories = completableFuture2.join();
  374. //3.组装地区信息
  375. List<WdCountBody> result = new ArrayList<>();
  376. HashMap<String,Integer> statistics = new HashMap<>(); //初始化统计信息
  377. for (AddrCategory addrCategory : addrCategories) {
  378. WdCountBody wdCountBody = new WdCountBody();
  379. //组装
  380. wdCountBody.setLat(addrCategory.getLatGd());
  381. wdCountBody.setLng(addrCategory.getLngGd());
  382. wdCountBody.setAddrCode(addrCategory.getAddrCode());
  383. wdCountBody.setName(addrCategory.getCity());
  384. statistics.put(addrCategory.getAddrCode().substring(0,4),0);
  385. result.add(wdCountBody);
  386. }
  387. //4.组装条件构造器找到网点信息网点
  388. //2.1 渠道、地区分类
  389. List<String> wdAddrCodes = completableFuture1.join();
  390. QueryWrapper<WdInfo> queryWrapper2 = new QueryWrapper<>();
  391. queryWrapper2.select("addr_code","count(*) as audit");
  392. queryWrapper2.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
  393. originWdInfoQueryWrapper.in("addr_code",wdAddrCodes);
  394. });
  395. //搜索字段
  396. if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
  397. queryWrapper2.and(originWdInfoQueryWrapper -> {
  398. originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
  399. });
  400. }
  401. //城市等级分类
  402. if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
  403. List<String> tierCode = new ArrayList<>();
  404. for (String s : channelMapAceeptVo.getCityTier()) {
  405. List<String> list = initMapUtil.getInitCityTierListMap(s);
  406. if (list != null){
  407. tierCode.addAll(list);
  408. }
  409. }
  410. queryWrapper2.and(wdInfoQueryWrapper -> {
  411. wdInfoQueryWrapper.in("addr_code",tierCode);
  412. });
  413. }
  414. queryWrapper2.groupBy("addr_code");
  415. //5.统计
  416. int total = 0;
  417. List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper2);
  418. for (WdInfo wdInfo : wdInfos) {
  419. statistics.put(wdInfo.getAddrCode().substring(0,4),statistics.get(wdInfo.getAddrCode().substring(0,4))+wdInfo.getAudit());
  420. total+=+wdInfo.getAudit();
  421. }
  422. //5.计算radio
  423. for (WdCountBody wdCountBody : result) {
  424. String code = null;
  425. code = wdCountBody.getAddrCode().substring(0,4);
  426. if(statistics.get(code) != null){
  427. wdCountBody.setCount(statistics.get(code));
  428. }else {
  429. wdCountBody.setCount(0);
  430. }
  431. if (total != 0){
  432. BigDecimal bigDecimal = new BigDecimal((float) wdCountBody.getCount() / total);
  433. float v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
  434. wdCountBody.setRadio(v);
  435. }
  436. else
  437. wdCountBody.setRadio(0.0f);
  438. }
  439. //5.封装结果
  440. WdCount wdCount = new WdCount();
  441. wdCount.setWdCountBodyList(result);
  442. wdCount.setTotal(total);
  443. return wdCount;
  444. }
  445. /**
  446. * 地图模式:查看区级地区的网点数量(v2.0)
  447. * @param channelMapAceeptVo
  448. * @return
  449. */
  450. @Override
  451. public WdCount areaZone(ChannelMapAceeptVo channelMapAceeptVo) {
  452. //1.根据不同级别得到 需要查询的 网点地区码
  453. CompletableFuture<List<String>> completableFuture1 = CompletableFuture.supplyAsync(() -> {
  454. return findWdAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
  455. });
  456. //2.找到所有需要封装的 地区信息
  457. CompletableFuture<List<AddrCategory>> completableFuture2 = CompletableFuture.supplyAsync(() -> {
  458. return findCenterAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
  459. });
  460. List<AddrCategory> addrCategories = completableFuture2.join();
  461. //3.组装地区信息
  462. List<WdCountBody> result = new ArrayList<>();
  463. HashMap<String,Integer> statistics = new HashMap<>(); //初始化统计信息
  464. for (AddrCategory addrCategory : addrCategories) {
  465. WdCountBody wdCountBody = new WdCountBody();
  466. //组装
  467. wdCountBody.setLat(addrCategory.getLatGd());
  468. wdCountBody.setLng(addrCategory.getLngGd());
  469. wdCountBody.setAddrCode(addrCategory.getAddrCode());
  470. wdCountBody.setName(addrCategory.getDistrict());
  471. statistics.put(addrCategory.getAddrCode().substring(0,6),0);
  472. result.add(wdCountBody);
  473. }
  474. //4.组装条件构造器找到网点信息网点
  475. //2.1 渠道、地区分类
  476. List<String> wdAddrCodes = completableFuture1.join();
  477. QueryWrapper<WdInfo> queryWrapper2 = new QueryWrapper<>();
  478. queryWrapper2.select("addr_code","count(*) as audit");
  479. queryWrapper2.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
  480. originWdInfoQueryWrapper.in("addr_code",wdAddrCodes);
  481. });
  482. //搜索字段
  483. if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
  484. queryWrapper2.and(originWdInfoQueryWrapper -> {
  485. originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
  486. });
  487. }
  488. //城市等级分类
  489. if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
  490. List<String> tierCode = new ArrayList<>();
  491. for (String s : channelMapAceeptVo.getCityTier()) {
  492. List<String> list = initMapUtil.getInitCityTierListMap(s);
  493. if (list != null){
  494. tierCode.addAll(list);
  495. }
  496. }
  497. queryWrapper2.and(wdInfoQueryWrapper -> {
  498. wdInfoQueryWrapper.in("addr_code",tierCode);
  499. });
  500. }
  501. queryWrapper2.groupBy("addr_code");
  502. //5.统计
  503. int total = 0;
  504. List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper2);
  505. for (WdInfo wdInfo : wdInfos) {
  506. statistics.put(wdInfo.getAddrCode().substring(0,6),statistics.get(wdInfo.getAddrCode().substring(0,6))+wdInfo.getAudit());
  507. total+=+wdInfo.getAudit();
  508. }
  509. //5.计算radio
  510. for (WdCountBody wdCountBody : result) {
  511. String code = null;
  512. code = wdCountBody.getAddrCode().substring(0,6);
  513. if(statistics.get(code) != null){
  514. wdCountBody.setCount(statistics.get(code));
  515. }else {
  516. wdCountBody.setCount(0);
  517. }
  518. if (total != 0){
  519. BigDecimal bigDecimal = new BigDecimal((float) wdCountBody.getCount() / total);
  520. float v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
  521. wdCountBody.setRadio(v);
  522. }
  523. else
  524. wdCountBody.setRadio(0.0f);
  525. }
  526. //5.封装结果
  527. WdCount wdCount = new WdCount();
  528. wdCount.setWdCountBodyList(result);
  529. wdCount.setTotal(total);
  530. return wdCount;
  531. }
  532. /**
  533. * 获取网点列表
  534. * @param channelMapAceeptVo
  535. * @return
  536. */
  537. @Override
  538. public HashMap list(ChannelMapAceeptVo channelMapAceeptVo) {
  539. //1.根据条件获取网点
  540. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  541. assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
  542. Page<WdInfo> page = new Page<>(channelMapAceeptVo.getPageNum(), channelMapAceeptVo.getPageSize());
  543. Page<WdInfo> page1 = wdInfoDao.selectPage(page, queryWrapper);
  544. //2.获取标签并组装
  545. List<WdTopologicalInfoBo> result = new ArrayList<>(); //返回的封装网点数据集
  546. for (WdInfo wdInfo : page1.getRecords()) {
  547. WdTopologicalInfoBo wdTopologicalInfoBo = new WdTopologicalInfoBo(wdInfo);
  548. wdTopologicalInfoBo.setAddrCodeInfo(initMapUtil.getInitAddrCodeMap(wdInfo.getAddrCode()));
  549. List<String> tags = wdRedisStoreage.getWdTag(wdInfo);
  550. wdTopologicalInfoBo.setTag(tags);
  551. result.add(wdTopologicalInfoBo);
  552. }
  553. //3.返回结果集
  554. page1.setRecords(null);
  555. HashMap data = new HashMap();
  556. data.put("data",result);
  557. data.put("page",page1);
  558. return data;
  559. }
  560. /**
  561. * 获取区下的具体网点信息
  562. * @param channelMapAceeptVo
  563. * @return
  564. */
  565. @Override
  566. public Page<WdInfo> point(ChannelMapAceeptVo channelMapAceeptVo) {
  567. //1.查找符合条件的网点
  568. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  569. queryWrapper.eq("addr_code",channelMapAceeptVo.getAddrCode()[0])
  570. .and(wdInfoQueryWrapper -> {
  571. wdInfoQueryWrapper.in("wd_type_code", channelMapAceeptVo.getChannel());
  572. });
  573. if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
  574. queryWrapper.and(originWdInfoQueryWrapper -> {
  575. originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText());
  576. });
  577. }
  578. Page<WdInfo> page = new Page<>(channelMapAceeptVo.getPageNum(), channelMapAceeptVo.getPageSize());
  579. Page<WdInfo> page1 = wdInfoDao.selectPage(page, queryWrapper);
  580. return page1;
  581. }
  582. /**
  583. * 获取网点详细信息
  584. * @param wdId
  585. * @return
  586. */
  587. @Override
  588. public WdInfo getWdInfo(String wdId) {
  589. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  590. queryWrapper.eq("wd_id",wdId);
  591. WdInfo wdInfo = wdInfoDao.selectOne(queryWrapper);
  592. if(wdInfo == null)
  593. return wdInfo;
  594. if("1".equals(wdInfo.getWdTypeCode())){
  595. //门店网点
  596. QueryWrapper<StoreWd> queryWrapper1 = new QueryWrapper<>();
  597. queryWrapper1.eq("wd_id",wdId);
  598. StoreWd storeWd = storeWdDao.selectOne(queryWrapper1);
  599. StoreWdInfoBo storeWdInfoBo = new StoreWdInfoBo(wdInfo);
  600. storeWdInfoBo.setStoreWd(storeWd);
  601. storeWdInfoBo.setTags(wdRedisStoreage.getWdTag(wdInfo));
  602. storeWdInfoBo.setAddrCode(initMapUtil.getInitAddrCodeMap(storeWdInfoBo.getAddrCode()));
  603. return storeWdInfoBo;
  604. }else if("2".equals(wdInfo.getWdTypeCode())){
  605. //小区网点
  606. QueryWrapper<HouseWd> queryWrapper1 = new QueryWrapper<>();
  607. queryWrapper1.eq("wd_id",wdId);
  608. HouseWd houseWd = houseWdDao.selectOne(queryWrapper1);
  609. HouseWdInfoBo houseWdInfoBo = new HouseWdInfoBo(wdInfo);
  610. houseWdInfoBo.setHouseWd(houseWd);
  611. houseWdInfoBo.setTags(wdRedisStoreage.getWdTag(wdInfo));
  612. houseWdInfoBo.setAddrCode(initMapUtil.getInitAddrCodeMap(houseWdInfoBo.getAddrCode()));
  613. return houseWdInfoBo;
  614. }else if("3".equals(wdInfo.getWdTypeCode())){
  615. //楼宇网点
  616. QueryWrapper<BuildWd> queryWrapper1 = new QueryWrapper<>();
  617. queryWrapper1.eq("wd_id",wdId);
  618. BuildWd buildWd = buildWdDao.selectOne(queryWrapper1);
  619. BuildWdInfoBo buildWdInfoBo = new BuildWdInfoBo(wdInfo);
  620. buildWdInfoBo.setBuildWd(buildWd);
  621. buildWdInfoBo.setTags(wdRedisStoreage.getWdTag(wdInfo));
  622. buildWdInfoBo.setAddrCode(initMapUtil.getInitAddrCodeMap(buildWdInfoBo.getAddrCode()));
  623. return buildWdInfoBo;
  624. }else if("4".equals(wdInfo.getWdTypeCode())){
  625. //交通设施网点
  626. QueryWrapper<TrafficWd> queryWrapper1 = new QueryWrapper<>();
  627. queryWrapper1.eq("wd_id",wdId);
  628. TrafficWd trafficWd = trafficWdDao.selectOne(queryWrapper1);
  629. TrafficWdInfoBo trafficWdInfoBo = new TrafficWdInfoBo(wdInfo);
  630. trafficWdInfoBo.setTrafficWd(trafficWd);
  631. trafficWdInfoBo.setTags(wdRedisStoreage.getWdTag(wdInfo));
  632. trafficWdInfoBo.setAddrCode(initMapUtil.getInitAddrCodeMap(trafficWdInfoBo.getAddrCode()));
  633. return trafficWdInfoBo;
  634. }else if("5".equals(wdInfo.getWdTypeCode())){
  635. //企业网点
  636. QueryWrapper<EnterpriseWd> queryWrapper1 = new QueryWrapper<>();
  637. queryWrapper1.eq("wd_id",wdId);
  638. EnterpriseWd enterpriseWd = enterpriseWdDao.selectOne(queryWrapper1);
  639. EnterpriseWdInfoBo enterpriseWdInfoBo = new EnterpriseWdInfoBo(wdInfo);
  640. enterpriseWdInfoBo.setEnterpriseWd(enterpriseWd);
  641. enterpriseWdInfoBo.setTags(wdRedisStoreage.getWdTag(wdInfo));
  642. enterpriseWdInfoBo.setAddrCode(initMapUtil.getInitAddrCodeMap(enterpriseWdInfoBo.getAddrCode()));
  643. return enterpriseWdInfoBo;
  644. }
  645. return wdInfo;
  646. }
  647. /**
  648. * 封装网点过滤条件(v2.0)
  649. * @param queryWrapper
  650. * @param channelMapAceeptVo
  651. */
  652. public void assembleQueryWrapper(QueryWrapper<WdInfo> queryWrapper,ChannelMapAceeptVo channelMapAceeptVo){
  653. //1.根据不同级别得到需要查询的 地区码
  654. List<String> wdAddrCode = findWdAddrCode(channelMapAceeptVo.getRankType(), channelMapAceeptVo.getAddrCode());
  655. //店龄
  656. if(channelMapAceeptVo.getStoreAge() != null && !channelMapAceeptVo.getStoreAge().equals("")){
  657. queryWrapper.and(wdInfoQueryWrapper -> {
  658. wdInfoQueryWrapper.eq("store_age",channelMapAceeptVo.getStoreAge());
  659. });
  660. }
  661. //地区过滤
  662. queryWrapper.and(wdInfoQueryWrapper -> {
  663. wdInfoQueryWrapper.in("addr_code", wdAddrCode);
  664. });
  665. //渠道过滤
  666. if(channelMapAceeptVo.getChannel() != null && channelMapAceeptVo.getChannel().length != 6){
  667. queryWrapper.and(wdInfoQueryWrapper -> {
  668. wdInfoQueryWrapper.in("wd_type_code", channelMapAceeptVo.getChannel());
  669. });
  670. }
  671. //城市等级分类
  672. if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
  673. List<String> tierCode = new ArrayList<>();
  674. for (String s : channelMapAceeptVo.getCityTier()) {
  675. List<String> list = initMapUtil.getInitCityTierListMap(s);
  676. if (list != null){
  677. tierCode.addAll(list);
  678. }
  679. }
  680. queryWrapper.and(wdInfoQueryWrapper -> {
  681. wdInfoQueryWrapper.in("addr_code",tierCode);
  682. });
  683. }
  684. //是否关联品牌
  685. if(channelMapAceeptVo.getIsBrand() != null && !channelMapAceeptVo.getIsBrand().equals("")){
  686. queryWrapper.and(wdInfoQueryWrapper -> {
  687. wdInfoQueryWrapper.isNotNull("brand_name");
  688. });
  689. }
  690. //是否有联系方式
  691. if(channelMapAceeptVo.getIsTelephone() != null && !channelMapAceeptVo.getIsTelephone().equals("")){
  692. queryWrapper.and(wdInfoQueryWrapper -> {
  693. wdInfoQueryWrapper.isNotNull("teletphone");
  694. });
  695. }
  696. //搜索字段
  697. if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText() .trim().equals("")) {
  698. queryWrapper.and(originWdInfoQueryWrapper -> {
  699. originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
  700. });
  701. }
  702. //排序字段查询
  703. if (channelMapAceeptVo.getOrderby() != null && !channelMapAceeptVo.getOrderby().trim().equals("")) {
  704. PageHelper.orderBy(channelMapAceeptVo.getOrderby());
  705. }
  706. }
  707. /**
  708. * 找到所有满足条件的网点addrCode
  709. * @param rankType
  710. * @param addrCode
  711. * @return
  712. */
  713. private List<String> findWdAddrCode(String rankType,String[] addrCode){
  714. //1.根据不同级别得到 找到所有 完整的 区码
  715. List<String> addrCodeList = new ArrayList<>();
  716. if ("province".equals(rankType)) {
  717. //addrCode:省码
  718. for (String string:addrCode)
  719. addrCodeList.add(string.substring(0, 2));
  720. } else if ("city".equals(rankType)) {
  721. //addrCode:省码(只允许有一个)
  722. String substring = addrCode[0].substring(0, 2); //根据该省码找到旗下的所有的区
  723. addrCodeList.add(substring);
  724. } else if ("zone".equals(rankType)) {
  725. //addrCode:市码(只允许有一个)
  726. String substring = addrCode[0].substring(0, 4); //根据该市码找到旗下的所有的区
  727. addrCodeList.add(substring);
  728. } else {
  729. for (String string:addrCode)
  730. addrCodeList.add(string.substring(0, 2));
  731. }
  732. //2.找到所有完整的区码
  733. QueryWrapper<AddrCategory> queryWrapper1 = new QueryWrapper<>();
  734. queryWrapper1.ne("district", "");
  735. queryWrapper1.and(addrCategoryQueryWrapper -> {
  736. for (String s : addrCodeList) {
  737. addrCategoryQueryWrapper.likeRight("addr_code", s).or();
  738. }
  739. });
  740. List<AddrCategory> addrCategories1 = addrCategoryDao.selectList(queryWrapper1);
  741. List<String> collect = addrCategories1.stream().map(item -> {
  742. return item.getAddrCode();
  743. }).collect(Collectors.toList());
  744. return collect;
  745. }
  746. /**
  747. * 找到需要展示的中心addrCode
  748. * @param rankType
  749. * @param addrCode
  750. * @return
  751. */
  752. private List<AddrCategory> findCenterAddrCode(String rankType,String[] addrCode){
  753. //1.根据不同级别得到 找到所有 完整的 区码
  754. List<String> addrCodeList = new ArrayList<>();
  755. if ("province".equals(rankType)) {
  756. //addrCode:省码
  757. addrCodeList.addAll(Arrays.asList(addrCode));
  758. } else if ("city".equals(rankType)) {
  759. //addrCode:省码(只允许有一个)
  760. String substring = addrCode[0].substring(0, 2); //根据该省码找到旗下的所有的区
  761. addrCodeList.add(substring);
  762. } else if ("zone".equals(rankType)) {
  763. //addrCode:市码(只允许有一个)
  764. String substring = addrCode[0].substring(0, 4); //根据该市码找到旗下的所有的区
  765. addrCodeList.add(substring);
  766. } else {
  767. return null;
  768. }
  769. //2.找到所有需要封装的 地区信息
  770. QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
  771. if ("province".equals(rankType)) {
  772. queryWrapper.eq("city", "");
  773. } else if ("city".equals(rankType)) {
  774. queryWrapper.eq("district", "").and(addrCategoryQueryWrapper -> {
  775. addrCategoryQueryWrapper.ne("city", "");
  776. });
  777. } else if ("zone".equals(rankType)) {
  778. queryWrapper.ne("district", "");
  779. }
  780. queryWrapper.and(addrCategoryQueryWrapper -> {
  781. for (String s : addrCodeList) {
  782. addrCategoryQueryWrapper.likeRight("addr_code", s).or();
  783. }
  784. });
  785. List<AddrCategory> addrCategories = addrCategoryDao.selectList(queryWrapper);
  786. return addrCategories;
  787. }
  788. }