ChannelAnalyseServiceImpl.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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.constant.RedisContant;
  7. import com.ruoyi.demo.entity.*;
  8. import com.ruoyi.demo.entity.bo.Histogram;
  9. import com.ruoyi.demo.entity.bo.StoreWdCategoryCount;
  10. import com.ruoyi.demo.entity.bo.StoreWdCategoryCountBody;
  11. import com.ruoyi.demo.entity.vo.ChannelAnalyseAceeptVo;
  12. import com.ruoyi.demo.entity.vo.ChannelMapAceeptVo;
  13. import com.ruoyi.demo.entity.vo.TagAnalyse;
  14. import com.ruoyi.demo.mapper.*;
  15. import com.ruoyi.demo.service.ChannelAnalyseService;
  16. import com.ruoyi.demo.utils.InitMapUtil;
  17. import com.ruoyi.demo.utils.WdRedisStoreage;
  18. import lombok.extern.slf4j.Slf4j;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.beans.factory.annotation.Qualifier;
  21. import org.springframework.data.geo.Circle;
  22. import org.springframework.data.geo.Distance;
  23. import org.springframework.data.geo.GeoResults;
  24. import org.springframework.data.geo.Point;
  25. import org.springframework.data.redis.connection.RedisGeoCommands;
  26. import org.springframework.data.redis.core.RedisTemplate;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import org.springframework.web.client.RestTemplate;
  30. import java.math.BigDecimal;
  31. import java.util.*;
  32. import java.util.concurrent.CompletableFuture;
  33. import java.util.concurrent.ConcurrentHashMap;
  34. import java.util.concurrent.ExecutionException;
  35. import java.util.concurrent.ExecutorService;
  36. import java.util.stream.Collectors;
  37. @Slf4j
  38. @Service
  39. @Transactional
  40. public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
  41. @Autowired
  42. private AddrCategoryDao addrCategoryDao;
  43. @Autowired
  44. WdInfoDao wdInfoDao;
  45. @Autowired
  46. InitMapUtil initMapUtil;
  47. @Autowired
  48. BrandMapper brandMapper;
  49. @Autowired
  50. WdTopologicalInfoDao wdTopologicalInfoDao;
  51. @Autowired
  52. private WdRedisStoreage wdRedisStoreage;
  53. @Autowired
  54. private StoreWdDao storeWdDao;
  55. @Autowired
  56. @Qualifier("executor")
  57. ExecutorService executor;
  58. /**
  59. * 网点城市等级分布统计
  60. * @param channelMapAceeptVo 渠道地图过滤请求接收体
  61. * @return
  62. */
  63. @Override
  64. public HashMap cityTier(ChannelMapAceeptVo channelMapAceeptVo) {
  65. //1.初始化统计结果
  66. HashMap<String, Long> result = new HashMap<>();
  67. result.put("一线", 0L);
  68. result.put("新一线", 0L);
  69. result.put("二线", 0L);
  70. result.put("三线", 0L);
  71. result.put("四线", 0L);
  72. result.put("五线", 0L);
  73. result.put("其他", 0L);
  74. //2.获取所有符合条件的网点信息
  75. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  76. queryWrapper.select("addr_code","count(*) as audit");
  77. assembleQueryWrapper(queryWrapper,channelMapAceeptVo); //封装过滤条件
  78. queryWrapper.groupBy("addr_code");
  79. List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
  80. //3.统计各个城市等级的网点数量
  81. for (WdInfo wdInfo : wdInfos) {
  82. //通过 网点区码 得到 该网点属于几线城市 例如:4509010000 -> 二线
  83. String initCityTierMap = initMapUtil.getInitCityTierMap(wdInfo.getAddrCode());
  84. if (initCityTierMap != null) {
  85. result.put(initCityTierMap, result.get(initCityTierMap) + wdInfo.getAudit());
  86. } else
  87. result.put("其他", result.get("其他") + wdInfo.getAudit());
  88. }
  89. return result;
  90. }
  91. /**
  92. * 品牌列表
  93. * @param channelAnalyseAceeptVo 渠道地图过滤请求接收体
  94. * @return
  95. */
  96. @Override
  97. public Page<Brand> brandList(ChannelAnalyseAceeptVo channelAnalyseAceeptVo) {
  98. QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
  99. if (channelAnalyseAceeptVo.getSearchText() != null && !channelAnalyseAceeptVo.getSearchText().equals(""))
  100. queryWrapper.like("brand_name",channelAnalyseAceeptVo.getSearchText());
  101. Page<Brand> page = new Page<>();
  102. page.setSize(channelAnalyseAceeptVo.getPageSize());
  103. page.setCurrent(channelAnalyseAceeptVo.getPageNum());
  104. Page<Brand> brandPage = brandMapper.selectPage(page, queryWrapper);
  105. return brandPage;
  106. }
  107. //TODO 待优化
  108. @Override
  109. public HashMap<String, Object> tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
  110. //1.根据条件的到位网点信息
  111. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  112. queryWrapper.select("wd_id");
  113. assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
  114. List<WdInfo> queryWd = wdInfoDao.selectList(queryWrapper);
  115. //2.得到网点Id
  116. List<String> collect = queryWd.stream().map(item -> {
  117. return RedisContant.WD_TAG + "_" + item.getWdId();
  118. }).collect(Collectors.toList());
  119. queryWd = null;
  120. //3.切割网点分批次获取网点标签
  121. ConcurrentHashMap<String, Integer> concurrentHashMap = new ConcurrentHashMap<>();
  122. concurrentHashMap.put("total",0);
  123. int split = 4000; //每次获取的网点次数
  124. int splitCount = collect.size()%split == 0 ? (collect.size()/split) : (collect.size()/split + 1); //共计次数
  125. int p1 = 0,p2 = split;
  126. ArrayList<CompletableFuture<Void>> splitList = new ArrayList<>();
  127. for (int i=1;i<=splitCount;i++){
  128. if (p2 > collect.size())
  129. p2 = collect.size();
  130. List<String> list2 = collect.subList(p1, p2);
  131. //创建线程任务
  132. CompletableFuture<Void> future = CompletableFuture.runAsync(()->{
  133. tagAnalyseItem(concurrentHashMap,list2); //统计
  134. },executor);
  135. splitList.add(future);
  136. p1 = p2;
  137. p2+=split;
  138. }
  139. //3.统计
  140. CompletableFuture.allOf(splitList.toArray(new CompletableFuture[splitList.size()])).join();
  141. splitList = null;
  142. //4.封装统计值
  143. HashMap<String, Object> result = new HashMap<>();
  144. List<TagAnalyse> list = new ArrayList<>();
  145. Integer total = concurrentHashMap.get("total");
  146. for (String s : concurrentHashMap.keySet()) {
  147. if (s.equals("total"))
  148. continue;
  149. TagAnalyse tagAnalyse = new TagAnalyse();
  150. tagAnalyse.setName(s);
  151. tagAnalyse.setCount(concurrentHashMap.get(s));
  152. BigDecimal bigDecimal = new BigDecimal((double) tagAnalyse.getCount() / total);
  153. double v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  154. tagAnalyse.setRadio(v);
  155. list.add(tagAnalyse);
  156. }
  157. //5.对结果集进行排序
  158. Collections.sort(list, new Comparator<TagAnalyse>() {
  159. @Override
  160. public int compare(TagAnalyse o1, TagAnalyse o2) {
  161. return o2.getCount() - o1.getCount();
  162. }
  163. });
  164. //5.分页返回结果集
  165. int i = 1;
  166. int start = 0,end = channelMapAceeptVo.getPageSize();
  167. while(start<list.size()){
  168. if(end>=list.size())
  169. end = list.size();
  170. result.put(""+i++,new ArrayList(list.subList(start,end)));
  171. start=end;
  172. end += channelMapAceeptVo.getPageSize();
  173. }
  174. result.put("pages",i-1);
  175. result.put("total",list.size());
  176. return result;
  177. }
  178. //TODO 待优化
  179. public void tagAnalyseItem(ConcurrentHashMap<String,Integer> concurrentHashMap, List<String> keys){
  180. //2.获取网点周边标签,并进行统计
  181. int total = 0;
  182. List<List<String>> wdTagList = wdRedisStoreage.getWdTagList(keys);
  183. for (List<String> list : wdTagList) {
  184. if (list == null || list.size() == 0)
  185. continue;
  186. for (String s : list) {
  187. s += "边";
  188. Integer integer = concurrentHashMap.get(s);
  189. if (integer == null)
  190. concurrentHashMap.put(s,1);
  191. else
  192. concurrentHashMap.put(s,integer+1);
  193. }
  194. total++;
  195. }
  196. wdTagList = null;
  197. concurrentHashMap.put("total",concurrentHashMap.get("total")+total);
  198. }
  199. /**
  200. * 网点分类统计
  201. * @param channelMapAceeptVo 渠道地图过滤请求接收体
  202. * @return
  203. */
  204. @Override
  205. public List<StoreWdCategoryCount> category(ChannelMapAceeptVo channelMapAceeptVo) {
  206. //1.查询所有符合的门店网点
  207. channelMapAceeptVo.setChannel(new String[]{"1"});
  208. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  209. queryWrapper.select("wd_id");
  210. assembleQueryWrapper(queryWrapper,channelMapAceeptVo); //封装过滤条件
  211. List<StoreWd> storeWds = storeWdDao.category(queryWrapper);
  212. //2.统计各个分类的网点数量 HashMap<分类code,门店网点分类数量对象>
  213. HashMap<String,StoreWdCategoryCount> hashMap = new HashMap<>();
  214. for (StoreWd storeWd : storeWds) {
  215. //分类为null、空跳过
  216. if(storeWd.getManageTypeCode() == null || storeWd.getManageTypeCode().equals(""))
  217. continue;
  218. //2.1 通过 分类Code 得到 具体的分类实体
  219. ManageType manageType = initMapUtil.getInitManageType(storeWd.getManageTypeCode());
  220. //2.2 通过 分类Code 得到 门店网点分类数量对象
  221. String s = storeWd.getManageTypeCode().substring(0, 4) + "00";
  222. StoreWdCategoryCount storeWdCategoryCount = hashMap.get(s);
  223. if (storeWdCategoryCount == null){
  224. //创建 门店网点分类数量体
  225. StoreWdCategoryCountBody storeWdCategoryCountBody = createStoreWdCategoryCountBody(manageType);
  226. storeWdCategoryCountBody.setManageTypeCode(storeWd.getManageTypeCode()); //分类code
  227. storeWdCategoryCountBody.setCount(storeWd.getCommentCount()); //数量
  228. //初始化 门店网点分类数量对象
  229. StoreWdCategoryCount storeWdCategoryCount1 = new StoreWdCategoryCount();
  230. storeWdCategoryCount1.setManageTypeCode(s);
  231. storeWdCategoryCount1.setName(initMapUtil.getInitManageType(s).getMidCategory());
  232. storeWdCategoryCount1.setCount(storeWd.getCommentCount());
  233. //将 门店网点分类数量体 封装进 门店网点数量对象
  234. ArrayList<StoreWdCategoryCountBody> list = new ArrayList<>();
  235. list.add(storeWdCategoryCountBody);
  236. storeWdCategoryCount1.setStoreWdCategoryCountBodyList(list);
  237. hashMap.put(s,storeWdCategoryCount1);
  238. }else {
  239. //创建 门店网点分类数量体
  240. StoreWdCategoryCountBody storeWdCategoryCountBody = createStoreWdCategoryCountBody(manageType);
  241. storeWdCategoryCountBody.setManageTypeCode(storeWd.getManageTypeCode());
  242. storeWdCategoryCountBody.setCount(storeWd.getCommentCount());
  243. //将 门店网点分类数量体 封装进 门店网点数量对象
  244. storeWdCategoryCount.getStoreWdCategoryCountBodyList().add(storeWdCategoryCountBody);
  245. storeWdCategoryCount.setCount(storeWdCategoryCountBody.getCount()+storeWdCategoryCount.getCount());
  246. //hashMap.put(s,storeWdCategoryCount);
  247. }
  248. }
  249. //3.组装结果集
  250. List<StoreWdCategoryCount> storeWdCategoryCounts = new ArrayList<>();
  251. for (String s : hashMap.keySet()) {
  252. storeWdCategoryCounts.add(hashMap.get(s));
  253. }
  254. return storeWdCategoryCounts;
  255. }
  256. /**
  257. * 创建门店网点分类体
  258. * @param manageType 具体的分类实体
  259. * @return
  260. */
  261. public StoreWdCategoryCountBody createStoreWdCategoryCountBody(ManageType manageType){
  262. StoreWdCategoryCountBody storeWdCategoryCountBody = new StoreWdCategoryCountBody();
  263. if(manageType.getSubCategory() != null && !manageType.getSubCategory().equals("")){
  264. storeWdCategoryCountBody.setName(manageType.getSubCategory());
  265. }else if(manageType.getMidCategory() != null && !manageType.getMidCategory().equals("")){
  266. storeWdCategoryCountBody.setName(manageType.getMidCategory());
  267. }else if (manageType.getBigCategory() != null && !manageType.getBigCategory().equals("")){
  268. storeWdCategoryCountBody.setName(manageType.getBigCategory());
  269. }
  270. return storeWdCategoryCountBody;
  271. }
  272. /**
  273. * 网点营业状态统计
  274. * @param channelMapAceeptVo 渠道地图过滤请求接收体
  275. * @return
  276. */
  277. @Override
  278. public HashMap businessStatusAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
  279. //1.查询所有符合的门店网点
  280. channelMapAceeptVo.setChannel(new String[]{"1"});
  281. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  282. queryWrapper.select("wd_id");
  283. assembleQueryWrapper(queryWrapper,channelMapAceeptVo); //封装过滤条件
  284. List<StoreWd> storeWds = storeWdDao.businessStatusAnalyse(queryWrapper);
  285. //2.统计 HashMap<营业状态,直方图统计体>
  286. ArrayList<Histogram> list = new ArrayList<>();
  287. int total = 0;
  288. for (StoreWd storeWd : storeWds) {
  289. total+=storeWd.getCommentCount();
  290. Histogram histogram = new Histogram();
  291. histogram.setName(storeWd.getBusinessStatus());
  292. histogram.setCount(storeWd.getCommentCount());
  293. list.add(histogram);
  294. }
  295. //3.返回结果集
  296. HashMap<String, Object> result = new HashMap<>();
  297. result.put("total",total);
  298. result.put("data",list);
  299. return result;
  300. }
  301. /**
  302. * 楼宇类别统计
  303. * @param channelMapAceeptVo
  304. * @return
  305. */
  306. @Override
  307. public ArrayList<Histogram> aroundBuildAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
  308. //1.查询所有符合的网点
  309. channelMapAceeptVo.setChannel(new String[]{"3"});
  310. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  311. queryWrapper.select("type_code_by","count(*) as audit");
  312. assembleQueryWrapper(queryWrapper,channelMapAceeptVo); //封装过滤条件
  313. queryWrapper.and(queryWrapper1 -> {
  314. queryWrapper1.isNotNull("type_code_by");
  315. });
  316. queryWrapper.groupBy("type_code_by");
  317. List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
  318. //2.统计楼宇类别数量
  319. int total = 0;
  320. HashMap<String,Integer> hashMap = new HashMap<>();
  321. for (WdInfo wdInfo : wdInfos) {
  322. String typeCodeBy = wdInfo.getTypeCodeBy().substring(0,2);
  323. Integer integer = hashMap.get(typeCodeBy);
  324. if (integer == null){
  325. hashMap.put(typeCodeBy,wdInfo.getAudit());
  326. }else {
  327. hashMap.put(typeCodeBy,hashMap.get(typeCodeBy)+wdInfo.getAudit());
  328. }
  329. total+=wdInfo.getAudit();
  330. }
  331. //3.分装统计结果
  332. ArrayList<Histogram> list = new ArrayList<>();
  333. for (String s : hashMap.keySet()) {
  334. Integer integer = hashMap.get(s);
  335. String initTypeByMap = initMapUtil.getInitTypeByMap(s + "0000").replace(":",""); //根据需求取大类
  336. Histogram histogram = new Histogram();
  337. histogram.setName(initTypeByMap);
  338. histogram.setCount(integer);
  339. list.add(histogram);
  340. }
  341. return list;
  342. }
  343. /**
  344. * 获取人均消费直方图
  345. * @param channelMapAceeptVo
  346. * @return
  347. */
  348. @Override
  349. public ArrayList<Histogram> perCapitaConsumpAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
  350. //1.查询所有符合的网点
  351. channelMapAceeptVo.setChannel(new String[]{"1"});
  352. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  353. queryWrapper.select("wd_id");
  354. assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
  355. List<StoreWd> storeWds = storeWdDao.perCapitaConsumpAnalyse(queryWrapper);
  356. //初始化
  357. //初始化
  358. String[] arr = new String[]{"0~20","20~50","50~100","100~200","200以上"};
  359. ArrayList<Histogram> list = new ArrayList<>();
  360. for (String s:arr){
  361. list.add(new Histogram(s,0));
  362. }
  363. //2.统计各个人均消费的数量
  364. for (StoreWd storeWd : storeWds) {
  365. if (storeWd.getPerCapitaConsumption() != null){
  366. if (storeWd.getPerCapitaConsumption() >= 0 && storeWd.getPerCapitaConsumption()<20){
  367. Histogram histogram = list.get(0);
  368. histogram.setCount(histogram.getCount()+1);
  369. }else if(storeWd.getPerCapitaConsumption() >= 20 && storeWd.getPerCapitaConsumption()<50){
  370. Histogram histogram = list.get(1);
  371. histogram.setCount(histogram.getCount()+1);
  372. }else if(storeWd.getPerCapitaConsumption() >= 50 && storeWd.getPerCapitaConsumption()< 100){
  373. Histogram histogram = list.get(2);
  374. histogram.setCount(histogram.getCount()+1);
  375. }else if(storeWd.getPerCapitaConsumption() >= 100 && storeWd.getPerCapitaConsumption()< 200){
  376. Histogram histogram = list.get(3);
  377. histogram.setCount(histogram.getCount()+1);
  378. }else {
  379. Histogram histogram = list.get(4);
  380. histogram.setCount(histogram.getCount()+1);
  381. }
  382. }
  383. }
  384. //3.分装统计结果
  385. return list;
  386. }
  387. /**
  388. * 获取聚道分析-店龄 / 经营时长统计
  389. * @param channelMapAceeptVo
  390. * @return
  391. */
  392. @Override
  393. public ArrayList<Histogram> operateTimeAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
  394. //1.查询所有符合的网点
  395. channelMapAceeptVo.setChannel(new String[]{"1"});
  396. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  397. queryWrapper.select("wd_id");
  398. assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
  399. List<StoreWd> storeWds = storeWdDao.operateTimeAnalyse(queryWrapper);
  400. //2.统计经营时长
  401. //初始化
  402. String[] arr = new String[]{"0~5","6~10","11~15","16~24"};
  403. ArrayList<Histogram> list = new ArrayList<>();
  404. for (String s:arr){
  405. list.add(new Histogram(s,0));
  406. }
  407. for (StoreWd storeWd : storeWds) {
  408. Integer opentime = Integer.valueOf(storeWd.getOpentime().substring(0,2));
  409. Integer closetime = Integer.valueOf(storeWd.getClosetime().substring(0,2));
  410. int i = closetime - opentime;
  411. if (i >=0 && i <=5){
  412. Histogram histogram = list.get(0);
  413. histogram.setCount(histogram.getCount()+1);
  414. }else if (i >= 6 && i <= 10){
  415. Histogram histogram = list.get(1);
  416. histogram.setCount(histogram.getCount()+1);
  417. }else if(i >= 11 && i <= 15){
  418. Histogram histogram = list.get(2);
  419. histogram.setCount(histogram.getCount()+1);
  420. }else if(i >= 16){
  421. Histogram histogram = list.get(3);
  422. histogram.setCount(histogram.getCount()+1);
  423. }
  424. }
  425. //3.返回结果
  426. return list;
  427. }
  428. /**
  429. * 封装网点过滤条件(v1.0)
  430. * @param queryWrapper
  431. * @param channelMapAceeptVo
  432. */
  433. // public void assembleQueryWrapper(QueryWrapper<WdInfo> queryWrapper,ChannelMapAceeptVo channelMapAceeptVo){
  434. // //1.根据不同级别得到需要查询的 地区码
  435. // List<String> addrCodeList = new ArrayList<>();
  436. // if ("province".equals(channelMapAceeptVo.getRankType())) {
  437. // //省码
  438. // for (String s : channelMapAceeptVo.getAddrCode()) {
  439. // String substring = s.substring(0, 2);
  440. // addrCodeList.add(substring);
  441. // }
  442. // } else if ("city".equals(channelMapAceeptVo.getRankType())) {
  443. // //省的所有市
  444. // for (String s : channelMapAceeptVo.getAddrCode()) {
  445. // String substring = s.substring(0, 2);
  446. // addrCodeList.add(substring);
  447. // }
  448. // } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
  449. // //市的所有区
  450. // for (String s : channelMapAceeptVo.getAddrCode()) {
  451. // String substring = s.substring(0, 4);
  452. // addrCodeList.add(substring);
  453. // }
  454. // } else if ("district".equals(channelMapAceeptVo.getRankType())){
  455. // //区的所有街道
  456. // for (String s : channelMapAceeptVo.getAddrCode()) {
  457. // String substring = s.substring(0, 6);
  458. // addrCodeList.add(substring);
  459. // }
  460. // }else {
  461. // //省码
  462. // for (String s : channelMapAceeptVo.getAddrCode()) {
  463. // String substring = s.substring(0, 2);
  464. // addrCodeList.add(substring);
  465. // }
  466. // }
  467. //
  468. // queryWrapper.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
  469. // for (String s : addrCodeList) {
  470. // originWdInfoQueryWrapper.likeRight("addr_code", s).or();
  471. // }
  472. // });
  473. //
  474. // //搜索字段
  475. // if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText() .trim().equals("")) {
  476. // queryWrapper.and(originWdInfoQueryWrapper -> {
  477. // originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
  478. // });
  479. // }
  480. //
  481. // //城市等级分类
  482. // if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
  483. // List<String> tierCode = new ArrayList<>();
  484. // for (String s : channelMapAceeptVo.getCityTier()) {
  485. // List<String> list = initMapUtil.getInitCityTierListMap(s);
  486. // if (list != null){
  487. // tierCode.addAll(list);
  488. // }
  489. // }
  490. // queryWrapper.and(wdInfoQueryWrapper -> {
  491. // for (String s : tierCode) {
  492. // wdInfoQueryWrapper.likeRight("addr_code", s).or();
  493. // }
  494. // });
  495. // }
  496. //
  497. // //排序字段查询
  498. // if (channelMapAceeptVo.getOrderby() != null && !channelMapAceeptVo.getOrderby().trim().equals("")) {
  499. // PageHelper.orderBy(channelMapAceeptVo.getOrderby());
  500. // }
  501. //
  502. // }
  503. /**
  504. * 封装网点过滤条件(v2.0)
  505. * @param queryWrapper
  506. * @param channelMapAceeptVo
  507. */
  508. public void assembleQueryWrapper(QueryWrapper<WdInfo> queryWrapper,ChannelMapAceeptVo channelMapAceeptVo){
  509. //1.根据不同级别得到需要查询的 地区码
  510. List<String> wdAddrCode = findWdAddrCode(channelMapAceeptVo.getRankType(), channelMapAceeptVo.getAddrCode());
  511. //是否有联系方式
  512. if(channelMapAceeptVo.getIsTelephone() != null && !channelMapAceeptVo.getIsTelephone().equals("")){
  513. queryWrapper.and(wdInfoQueryWrapper -> {
  514. wdInfoQueryWrapper.eq("is_telephone",channelMapAceeptVo.getIsTelephone().equals("true") ? 1:0);
  515. });
  516. }
  517. //是否关联品牌
  518. if(channelMapAceeptVo.getIsBrand() != null && !channelMapAceeptVo.getIsBrand().equals("")){
  519. queryWrapper.and(wdInfoQueryWrapper -> {
  520. wdInfoQueryWrapper.eq("is_brand",channelMapAceeptVo.getIsTelephone().equals("true") ? 1:0);
  521. });
  522. }
  523. //店龄
  524. if(channelMapAceeptVo.getStoreAge() != null && !channelMapAceeptVo.getStoreAge().equals("")){
  525. queryWrapper.and(wdInfoQueryWrapper -> {
  526. wdInfoQueryWrapper.eq("store_age",channelMapAceeptVo.getStoreAge());
  527. });
  528. }
  529. //组织结构
  530. if(channelMapAceeptVo.getOrganization() != null && !channelMapAceeptVo.getOrganization().equals("")){
  531. queryWrapper.and(wdInfoQueryWrapper -> {
  532. wdInfoQueryWrapper.eq("organization",channelMapAceeptVo.getOrganization());
  533. });
  534. }
  535. //地区过滤
  536. queryWrapper.and(wdInfoQueryWrapper -> {
  537. wdInfoQueryWrapper.in("addr_code", wdAddrCode);
  538. });
  539. //渠道过滤
  540. if(channelMapAceeptVo.getChannel() != null && channelMapAceeptVo.getChannel().length != 6){
  541. queryWrapper.and(wdInfoQueryWrapper -> {
  542. wdInfoQueryWrapper.in("wd_type_code", channelMapAceeptVo.getChannel());
  543. });
  544. }
  545. //城市等级分类
  546. if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
  547. List<String> tierCode = new ArrayList<>();
  548. for (String s : channelMapAceeptVo.getCityTier()) {
  549. List<String> list = initMapUtil.getInitCityTierListMap(s);
  550. if (list != null){
  551. tierCode.addAll(list);
  552. }
  553. }
  554. if(!tierCode.isEmpty()){
  555. queryWrapper.and(wdInfoQueryWrapper -> {
  556. wdInfoQueryWrapper.in("addr_code",tierCode);
  557. });
  558. }
  559. }
  560. //搜索字段
  561. if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText() .trim().equals("")) {
  562. queryWrapper.and(originWdInfoQueryWrapper -> {
  563. originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
  564. });
  565. }
  566. //排序字段查询
  567. if (channelMapAceeptVo.getOrderby() != null && !channelMapAceeptVo.getOrderby().trim().equals("")) {
  568. PageHelper.orderBy(channelMapAceeptVo.getOrderby());
  569. }
  570. }
  571. /**
  572. * 找到所有满足条件的网点addrCode
  573. * @param rankType
  574. * @param addrCode
  575. * @return
  576. */
  577. private List<String> findWdAddrCode(String rankType,String[] addrCode){
  578. //1.根据不同级别得到 找到所有 完整的 区码
  579. List<String> addrCodeList = new ArrayList<>();
  580. if ("province".equals(rankType)) {
  581. //addrCode:省码
  582. for (String string:addrCode)
  583. addrCodeList.add(string.substring(0, 2));
  584. } else if ("city".equals(rankType)) {
  585. //addrCode:省码(只允许有一个)
  586. String substring = addrCode[0].substring(0, 2); //根据该省码找到旗下的所有的区
  587. addrCodeList.add(substring);
  588. } else if ("zone".equals(rankType)) {
  589. //addrCode:市码(只允许有一个)
  590. String substring = addrCode[0].substring(0, 4); //根据该市码找到旗下的所有的区
  591. addrCodeList.add(substring);
  592. } else {
  593. for (String string:addrCode)
  594. addrCodeList.add(string.substring(0, 2));
  595. }
  596. //2.找到所有完整的区码
  597. QueryWrapper<AddrCategory> queryWrapper1 = new QueryWrapper<>();
  598. queryWrapper1.select("addr_code");
  599. queryWrapper1.eq("type", "zone");
  600. queryWrapper1.and(addrCategoryQueryWrapper -> {
  601. for (String s : addrCodeList) {
  602. addrCategoryQueryWrapper.likeRight("addr_code", s).or();
  603. }
  604. });
  605. List<AddrCategory> addrCategories1 = addrCategoryDao.selectList(queryWrapper1);
  606. List<String> collect = addrCategories1.stream().map(item -> {
  607. return item.getAddrCode();
  608. }).collect(Collectors.toList());
  609. return collect;
  610. }
  611. }