ChannelAnalyseServiceImpl.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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. queryWrapper.and(queryWrapper2 ->{
  115. queryWrapper2.eq("show_delete",0);
  116. });
  117. List<WdInfo> queryWd = wdInfoDao.selectList(queryWrapper);
  118. //2.获取周边标签
  119. List<String> collect = queryWd.stream().map(item -> {
  120. return RedisContant.WD_TAG + "_" + item.getWdId();
  121. }).collect(Collectors.toList());
  122. queryWd = null;
  123. //切割网点 并 统计分析标签
  124. ConcurrentHashMap<String, Integer> concurrentHashMap = new ConcurrentHashMap<>();
  125. concurrentHashMap.put("total",0);
  126. int split = 8000;
  127. int splitCount = collect.size()/split;
  128. int p1 = 0,p2 = split;
  129. ArrayList<CompletableFuture<Void>> splitList = new ArrayList<>();
  130. for (int i=1;i<=splitCount;i++){
  131. if (p2 > collect.size())
  132. p2 = collect.size();
  133. List<String> list2 = collect.subList(p1, p2);
  134. CompletableFuture<Void> future = CompletableFuture.runAsync(()->{
  135. tagAnalyseItem(concurrentHashMap,list2);
  136. },executor);
  137. splitList.add(future);
  138. p1 = p2;
  139. p2+=split;
  140. }
  141. //3.统计
  142. CompletableFuture.allOf(splitList.toArray(new CompletableFuture[splitList.size()])).join();
  143. splitList = null;
  144. //4.封装统计值
  145. HashMap<String, Object> result = new HashMap<>();
  146. List<TagAnalyse> list = new ArrayList<>();
  147. Integer total = concurrentHashMap.get("total");
  148. for (String s : concurrentHashMap.keySet()) {
  149. if (s.equals("total"))
  150. continue;
  151. TagAnalyse tagAnalyse = new TagAnalyse();
  152. tagAnalyse.setName(s);
  153. tagAnalyse.setCount(concurrentHashMap.get(s));
  154. BigDecimal bigDecimal = new BigDecimal((double) tagAnalyse.getCount() / total);
  155. double v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  156. tagAnalyse.setRadio(v);
  157. list.add(tagAnalyse);
  158. }
  159. //5.对结果集进行排序
  160. Collections.sort(list, new Comparator<TagAnalyse>() {
  161. @Override
  162. public int compare(TagAnalyse o1, TagAnalyse o2) {
  163. return o2.getCount() - o1.getCount();
  164. }
  165. });
  166. //5.分页返回结果集
  167. int i = 1;
  168. int start = 0,end = channelMapAceeptVo.getPageSize();
  169. while(start<list.size()){
  170. if(end>=list.size())
  171. end = list.size();
  172. result.put(""+i++,new ArrayList(list.subList(start,end)));
  173. start=end;
  174. end += channelMapAceeptVo.getPageSize();
  175. }
  176. result.put("pages",i-1);
  177. result.put("total",list.size());
  178. return result;
  179. }
  180. //TODO 待优化
  181. public void tagAnalyseItem(ConcurrentHashMap<String,Integer> concurrentHashMap, List<String> keys){
  182. //2.获取网点周边标签,并进行统计
  183. int total = 0;
  184. List<List<String>> wdTagList = wdRedisStoreage.getWdTagList(keys);
  185. for (List<String> list : wdTagList) {
  186. if (list == null || list.size() == 0)
  187. continue;
  188. for (String s : list) {
  189. s += "边";
  190. Integer integer = concurrentHashMap.get(s);
  191. if (integer == null)
  192. concurrentHashMap.put(s,1);
  193. else
  194. concurrentHashMap.put(s,integer+1);
  195. }
  196. total++;
  197. }
  198. wdTagList = null;
  199. concurrentHashMap.put("total",concurrentHashMap.get("total")+total);
  200. }
  201. /**
  202. * 网点分类统计
  203. * @param channelMapAceeptVo
  204. * @return
  205. */
  206. @Override
  207. public List<StoreWdCategoryCount> category(ChannelMapAceeptVo channelMapAceeptVo) {
  208. //1.查询所有符合的门店网点
  209. channelMapAceeptVo.setChannel(new String[]{"1"});
  210. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  211. queryWrapper.select("wd_id");
  212. assembleQueryWrapper(queryWrapper,channelMapAceeptVo); //封装过滤条件
  213. List<StoreWd> storeWds = storeWdDao.category(queryWrapper);
  214. //2.统计各个分类的网点数量 HashMap<分类code,门店网点分类数量对象>
  215. HashMap<String,StoreWdCategoryCount> hashMap = new HashMap<>();
  216. for (StoreWd storeWd : storeWds) {
  217. //分类为null、空跳过
  218. if(storeWd.getManageTypeCode() == null || storeWd.getManageTypeCode().equals(""))
  219. continue;
  220. //2.1 通过 分类Code 得到 具体的分类实体
  221. ManageType manageType = initMapUtil.getInitManageType(storeWd.getManageTypeCode());
  222. //2.2 通过 分类Code 得到 门店网点分类数量对象
  223. String s = storeWd.getManageTypeCode().substring(0, 4) + "00";
  224. StoreWdCategoryCount storeWdCategoryCount = hashMap.get(s);
  225. if (storeWdCategoryCount == null){
  226. //创建 门店网点分类数量体
  227. StoreWdCategoryCountBody storeWdCategoryCountBody = createStoreWdCategoryCountBody(manageType);
  228. storeWdCategoryCountBody.setManageTypeCode(storeWd.getManageTypeCode()); //分类code
  229. storeWdCategoryCountBody.setCount(storeWd.getCommentCount()); //数量
  230. //初始化 门店网点分类数量对象
  231. StoreWdCategoryCount storeWdCategoryCount1 = new StoreWdCategoryCount();
  232. storeWdCategoryCount1.setManageTypeCode(s);
  233. storeWdCategoryCount1.setName(initMapUtil.getInitManageType(s).getMidCategory());
  234. storeWdCategoryCount1.setCount(storeWd.getCommentCount());
  235. //将 门店网点分类数量体 封装进 门店网点数量对象
  236. ArrayList<StoreWdCategoryCountBody> list = new ArrayList<>();
  237. list.add(storeWdCategoryCountBody);
  238. storeWdCategoryCount1.setStoreWdCategoryCountBodyList(list);
  239. hashMap.put(s,storeWdCategoryCount1);
  240. }else {
  241. //创建 门店网点分类数量体
  242. StoreWdCategoryCountBody storeWdCategoryCountBody = createStoreWdCategoryCountBody(manageType);
  243. storeWdCategoryCountBody.setManageTypeCode(storeWd.getManageTypeCode());
  244. storeWdCategoryCountBody.setCount(storeWd.getCommentCount());
  245. //将 门店网点分类数量体 封装进 门店网点数量对象
  246. storeWdCategoryCount.getStoreWdCategoryCountBodyList().add(storeWdCategoryCountBody);
  247. storeWdCategoryCount.setCount(storeWdCategoryCountBody.getCount()+storeWdCategoryCount.getCount());
  248. //hashMap.put(s,storeWdCategoryCount);
  249. }
  250. }
  251. //3.组装结果集
  252. List<StoreWdCategoryCount> storeWdCategoryCounts = new ArrayList<>();
  253. for (String s : hashMap.keySet()) {
  254. storeWdCategoryCounts.add(hashMap.get(s));
  255. }
  256. return storeWdCategoryCounts;
  257. }
  258. /**
  259. * 创建门店网点分类体
  260. * @param manageType 具体的分类实体
  261. * @return
  262. */
  263. public StoreWdCategoryCountBody createStoreWdCategoryCountBody(ManageType manageType){
  264. StoreWdCategoryCountBody storeWdCategoryCountBody = new StoreWdCategoryCountBody();
  265. if(manageType.getSubCategory() != null && !manageType.getSubCategory().equals("")){
  266. storeWdCategoryCountBody.setName(manageType.getSubCategory());
  267. }else if(manageType.getMidCategory() != null && !manageType.getMidCategory().equals("")){
  268. storeWdCategoryCountBody.setName(manageType.getMidCategory());
  269. }else if (manageType.getBigCategory() != null && !manageType.getBigCategory().equals("")){
  270. storeWdCategoryCountBody.setName(manageType.getBigCategory());
  271. }
  272. return storeWdCategoryCountBody;
  273. }
  274. /**
  275. * 网点营业状态统计
  276. * @param channelMapAceeptVo
  277. * @return
  278. */
  279. @Override
  280. public HashMap businessStatusAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
  281. //1.查询所有符合的门店网点
  282. channelMapAceeptVo.setChannel(new String[]{"1"});
  283. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  284. queryWrapper.select("wd_id");
  285. assembleQueryWrapper(queryWrapper,channelMapAceeptVo); //封装过滤条件
  286. List<StoreWd> storeWds = storeWdDao.businessStatusAnalyse(queryWrapper);
  287. //2.统计 HashMap<营业状态,直方图统计体>
  288. ArrayList<Histogram> list = new ArrayList<>();
  289. int total = 0;
  290. for (StoreWd storeWd : storeWds) {
  291. total+=storeWd.getCommentCount();
  292. Histogram histogram = new Histogram();
  293. histogram.setName(storeWd.getBusinessStatus());
  294. histogram.setCount(storeWd.getCommentCount());
  295. list.add(histogram);
  296. }
  297. //3.返回结果集
  298. HashMap<String, Object> result = new HashMap<>();
  299. result.put("total",total);
  300. result.put("data",list);
  301. return result;
  302. }
  303. /**
  304. * 楼宇类别统计
  305. * @param channelMapAceeptVo
  306. * @return
  307. */
  308. @Override
  309. public ArrayList<Histogram> aroundBuildAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
  310. //1.查询所有符合的网点
  311. channelMapAceeptVo.setChannel(new String[]{"3"});
  312. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  313. queryWrapper.select("type_code_by","count(*) as audit");
  314. assembleQueryWrapper(queryWrapper,channelMapAceeptVo); //封装过滤条件
  315. queryWrapper.and(queryWrapper1 -> {
  316. queryWrapper1.isNotNull("type_code_by");
  317. });
  318. queryWrapper.groupBy("type_code_by");
  319. List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
  320. //2.统计楼宇类别数量
  321. int total = 0;
  322. HashMap<String,Integer> hashMap = new HashMap<>();
  323. for (WdInfo wdInfo : wdInfos) {
  324. String typeCodeBy = wdInfo.getTypeCodeBy().substring(0,2);
  325. Integer integer = hashMap.get(typeCodeBy);
  326. if (integer == null){
  327. hashMap.put(typeCodeBy,wdInfo.getAudit());
  328. }else {
  329. hashMap.put(typeCodeBy,hashMap.get(typeCodeBy)+wdInfo.getAudit());
  330. }
  331. total+=wdInfo.getAudit();
  332. }
  333. //3.分装统计结果
  334. ArrayList<Histogram> list = new ArrayList<>();
  335. for (String s : hashMap.keySet()) {
  336. Integer integer = hashMap.get(s);
  337. String initTypeByMap = initMapUtil.getInitTypeByMap(s + "0000").replace(":",""); //根据需求取大类
  338. Histogram histogram = new Histogram();
  339. histogram.setName(initTypeByMap);
  340. histogram.setCount(integer);
  341. list.add(histogram);
  342. }
  343. return list;
  344. }
  345. /**
  346. * 获取人均消费直方图
  347. * @param channelMapAceeptVo
  348. * @return
  349. */
  350. @Override
  351. public ArrayList<Histogram> perCapitaConsumpAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
  352. //1.查询所有符合的网点
  353. channelMapAceeptVo.setChannel(new String[]{"1"});
  354. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  355. queryWrapper.select("wd_id");
  356. assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
  357. List<StoreWd> storeWds = storeWdDao.perCapitaConsumpAnalyse(queryWrapper);
  358. //初始化
  359. LinkedHashMap<String, Integer> linkedHashMap = new LinkedHashMap<>();
  360. linkedHashMap.put("0~20",0);
  361. linkedHashMap.put("20~50",0);
  362. linkedHashMap.put("50~100",0);
  363. linkedHashMap.put("100~200",0);
  364. linkedHashMap.put("200以上",0);
  365. //2.统计各个人均消费的数量
  366. for (StoreWd storeWd : storeWds) {
  367. if (storeWd.getPerCapitaConsumption() != null){
  368. if (storeWd.getPerCapitaConsumption() >= 0 && storeWd.getPerCapitaConsumption()<20){
  369. linkedHashMap.put("0~20",linkedHashMap.get("0~20")+1);
  370. }else if(storeWd.getPerCapitaConsumption() >= 20 && storeWd.getPerCapitaConsumption()<50){
  371. linkedHashMap.put("20~50",linkedHashMap.get("20~50")+1);
  372. }else if(storeWd.getPerCapitaConsumption() >= 50 && storeWd.getPerCapitaConsumption()< 100){
  373. linkedHashMap.put("50~100",linkedHashMap.get("50~100")+1);
  374. }else if(storeWd.getPerCapitaConsumption() >= 100 && storeWd.getPerCapitaConsumption()< 200){
  375. linkedHashMap.put("100~200",linkedHashMap.get("100~200")+1);
  376. }else {
  377. linkedHashMap.put("200以上",linkedHashMap.get("200以上")+1);
  378. }
  379. }
  380. }
  381. //3.分装统计结果
  382. ArrayList<Histogram> list = new ArrayList<>();
  383. for (String s : linkedHashMap.keySet()) {
  384. Histogram histogram1 = new Histogram(s,linkedHashMap.get(s));
  385. list.add(histogram1);
  386. }
  387. return list;
  388. }
  389. /**
  390. * 获取聚道分析-店龄 / 经营时长统计
  391. * @param channelMapAceeptVo
  392. * @return
  393. */
  394. @Override
  395. public ArrayList<Histogram> operateTimeAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
  396. //1.查询所有符合的网点
  397. channelMapAceeptVo.setChannel(new String[]{"1"});
  398. QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
  399. queryWrapper.select("wd_id");
  400. assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
  401. List<StoreWd> storeWds = storeWdDao.operateTimeAnalyse(queryWrapper);
  402. //2.统计经营时长
  403. HashMap<Integer,Integer> hashMap = new HashMap<>();
  404. for (StoreWd storeWd : storeWds) {
  405. Integer opentime = Integer.valueOf(storeWd.getOpentime().substring(0,2));
  406. Integer closetime = Integer.valueOf(storeWd.getClosetime().substring(0,2));
  407. int i = closetime - opentime;
  408. Integer integer = hashMap.get(i);
  409. if (integer == null)
  410. hashMap.put(i,1);
  411. else
  412. hashMap.put(i,integer+1);
  413. }
  414. //3.分装统计结果
  415. ArrayList<Histogram> list = new ArrayList<>();
  416. for (Integer s : hashMap.keySet()) {
  417. Histogram histogram = new Histogram();
  418. histogram.setName(s+"");
  419. histogram.setCount(hashMap.get(s));
  420. list.add(histogram);
  421. }
  422. return list;
  423. }
  424. /**
  425. * 封装网点过滤条件(v1.0)
  426. * @param queryWrapper
  427. * @param channelMapAceeptVo
  428. */
  429. // public void assembleQueryWrapper(QueryWrapper<WdInfo> queryWrapper,ChannelMapAceeptVo channelMapAceeptVo){
  430. // //1.根据不同级别得到需要查询的 地区码
  431. // List<String> addrCodeList = new ArrayList<>();
  432. // if ("province".equals(channelMapAceeptVo.getRankType())) {
  433. // //省码
  434. // for (String s : channelMapAceeptVo.getAddrCode()) {
  435. // String substring = s.substring(0, 2);
  436. // addrCodeList.add(substring);
  437. // }
  438. // } else if ("city".equals(channelMapAceeptVo.getRankType())) {
  439. // //省的所有市
  440. // for (String s : channelMapAceeptVo.getAddrCode()) {
  441. // String substring = s.substring(0, 2);
  442. // addrCodeList.add(substring);
  443. // }
  444. // } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
  445. // //市的所有区
  446. // for (String s : channelMapAceeptVo.getAddrCode()) {
  447. // String substring = s.substring(0, 4);
  448. // addrCodeList.add(substring);
  449. // }
  450. // } else if ("district".equals(channelMapAceeptVo.getRankType())){
  451. // //区的所有街道
  452. // for (String s : channelMapAceeptVo.getAddrCode()) {
  453. // String substring = s.substring(0, 6);
  454. // addrCodeList.add(substring);
  455. // }
  456. // }else {
  457. // //省码
  458. // for (String s : channelMapAceeptVo.getAddrCode()) {
  459. // String substring = s.substring(0, 2);
  460. // addrCodeList.add(substring);
  461. // }
  462. // }
  463. //
  464. // queryWrapper.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
  465. // for (String s : addrCodeList) {
  466. // originWdInfoQueryWrapper.likeRight("addr_code", s).or();
  467. // }
  468. // });
  469. //
  470. // //搜索字段
  471. // if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText() .trim().equals("")) {
  472. // queryWrapper.and(originWdInfoQueryWrapper -> {
  473. // originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
  474. // });
  475. // }
  476. //
  477. // //城市等级分类
  478. // if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
  479. // List<String> tierCode = new ArrayList<>();
  480. // for (String s : channelMapAceeptVo.getCityTier()) {
  481. // List<String> list = initMapUtil.getInitCityTierListMap(s);
  482. // if (list != null){
  483. // tierCode.addAll(list);
  484. // }
  485. // }
  486. // queryWrapper.and(wdInfoQueryWrapper -> {
  487. // for (String s : tierCode) {
  488. // wdInfoQueryWrapper.likeRight("addr_code", s).or();
  489. // }
  490. // });
  491. // }
  492. //
  493. // //排序字段查询
  494. // if (channelMapAceeptVo.getOrderby() != null && !channelMapAceeptVo.getOrderby().trim().equals("")) {
  495. // PageHelper.orderBy(channelMapAceeptVo.getOrderby());
  496. // }
  497. //
  498. // }
  499. /**
  500. * 封装网点过滤条件(v2.0)
  501. * @param queryWrapper
  502. * @param channelMapAceeptVo
  503. */
  504. public void assembleQueryWrapper(QueryWrapper<WdInfo> queryWrapper,ChannelMapAceeptVo channelMapAceeptVo){
  505. //1.根据不同级别得到需要查询的 地区码
  506. List<String> wdAddrCode = findWdAddrCode(channelMapAceeptVo.getRankType(), channelMapAceeptVo.getAddrCode());
  507. //店龄
  508. if(channelMapAceeptVo.getStoreAge() != null && !channelMapAceeptVo.getStoreAge().equals("")){
  509. queryWrapper.and(wdInfoQueryWrapper -> {
  510. wdInfoQueryWrapper.eq("store_age",channelMapAceeptVo.getStoreAge());
  511. });
  512. }
  513. //地区过滤
  514. queryWrapper.and(wdInfoQueryWrapper -> {
  515. wdInfoQueryWrapper.in("addr_code", wdAddrCode);
  516. });
  517. //渠道过滤
  518. if(channelMapAceeptVo.getChannel() != null && channelMapAceeptVo.getChannel().length != 6){
  519. queryWrapper.and(wdInfoQueryWrapper -> {
  520. wdInfoQueryWrapper.in("wd_type_code", channelMapAceeptVo.getChannel());
  521. });
  522. }
  523. //城市等级分类
  524. if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
  525. List<String> tierCode = new ArrayList<>();
  526. for (String s : channelMapAceeptVo.getCityTier()) {
  527. List<String> list = initMapUtil.getInitCityTierListMap(s);
  528. if (list != null){
  529. tierCode.addAll(list);
  530. }
  531. }
  532. queryWrapper.and(wdInfoQueryWrapper -> {
  533. wdInfoQueryWrapper.in("addr_code",tierCode);
  534. });
  535. }
  536. //是否关联品牌
  537. if(channelMapAceeptVo.getIsBrand() != null && !channelMapAceeptVo.getIsBrand().equals("")){
  538. queryWrapper.and(wdInfoQueryWrapper -> {
  539. wdInfoQueryWrapper.isNotNull("brand_name");
  540. });
  541. }
  542. //是否有联系方式
  543. if(channelMapAceeptVo.getIsTelephone() != null && !channelMapAceeptVo.getIsTelephone().equals("")){
  544. queryWrapper.and(wdInfoQueryWrapper -> {
  545. wdInfoQueryWrapper.isNotNull("teletphone");
  546. });
  547. }
  548. //搜索字段
  549. if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText() .trim().equals("")) {
  550. queryWrapper.and(originWdInfoQueryWrapper -> {
  551. originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
  552. });
  553. }
  554. //排序字段查询
  555. if (channelMapAceeptVo.getOrderby() != null && !channelMapAceeptVo.getOrderby().trim().equals("")) {
  556. PageHelper.orderBy(channelMapAceeptVo.getOrderby());
  557. }
  558. }
  559. /**
  560. * 找到所有满足条件的网点addrCode
  561. * @param rankType
  562. * @param addrCode
  563. * @return
  564. */
  565. private List<String> findWdAddrCode(String rankType,String[] addrCode){
  566. //1.根据不同级别得到 找到所有 完整的 区码
  567. List<String> addrCodeList = new ArrayList<>();
  568. if ("province".equals(rankType)) {
  569. //addrCode:省码
  570. for (String string:addrCode)
  571. addrCodeList.add(string.substring(0, 2));
  572. } else if ("city".equals(rankType)) {
  573. //addrCode:省码(只允许有一个)
  574. String substring = addrCode[0].substring(0, 2); //根据该省码找到旗下的所有的区
  575. addrCodeList.add(substring);
  576. } else if ("zone".equals(rankType)) {
  577. //addrCode:市码(只允许有一个)
  578. String substring = addrCode[0].substring(0, 4); //根据该市码找到旗下的所有的区
  579. addrCodeList.add(substring);
  580. } else {
  581. for (String string:addrCode)
  582. addrCodeList.add(string.substring(0, 2));
  583. }
  584. //2.找到所有完整的区码
  585. QueryWrapper<AddrCategory> queryWrapper1 = new QueryWrapper<>();
  586. queryWrapper1.select("addr_code");
  587. queryWrapper1.ne("district", "");
  588. queryWrapper1.and(addrCategoryQueryWrapper -> {
  589. for (String s : addrCodeList) {
  590. addrCategoryQueryWrapper.likeRight("addr_code", s).or();
  591. }
  592. });
  593. List<AddrCategory> addrCategories1 = addrCategoryDao.selectList(queryWrapper1);
  594. List<String> collect = addrCategories1.stream().map(item -> {
  595. return item.getAddrCode();
  596. }).collect(Collectors.toList());
  597. return collect;
  598. }
  599. /**
  600. * 分装筛选条件(模糊查询)
  601. * @param queryWrapper
  602. * @param channelMapAceeptVo
  603. */
  604. /* public void assembleQueryWrapper(QueryWrapper<WdInfo> queryWrapper,ChannelMapAceeptVo channelMapAceeptVo){
  605. //1.根据不同级别得到需要查询的 地区码
  606. List<String> addrCodeList = new ArrayList<>();
  607. if ("province".equals(channelMapAceeptVo.getRankType())) {
  608. //省码
  609. for (String s : channelMapAceeptVo.getAddrCode()) {
  610. String substring = s.substring(0, 2);
  611. addrCodeList.add(substring);
  612. }
  613. } else if ("city".equals(channelMapAceeptVo.getRankType())) {
  614. //省的所有市
  615. for (String s : channelMapAceeptVo.getAddrCode()) {
  616. String substring = s.substring(0, 2);
  617. addrCodeList.add(substring);
  618. }
  619. } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
  620. //市的所有区
  621. for (String s : channelMapAceeptVo.getAddrCode()) {
  622. String substring = s.substring(0, 4);
  623. addrCodeList.add(substring);
  624. }
  625. } else if ("district".equals(channelMapAceeptVo.getRankType())){
  626. //区的所有街道
  627. for (String s : channelMapAceeptVo.getAddrCode()) {
  628. String substring = s.substring(0, 6);
  629. addrCodeList.add(substring);
  630. }
  631. }else {
  632. //省码
  633. for (String s : channelMapAceeptVo.getAddrCode()) {
  634. String substring = s.substring(0, 2);
  635. addrCodeList.add(substring);
  636. }
  637. }
  638. queryWrapper.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
  639. for (String s : addrCodeList) {
  640. originWdInfoQueryWrapper.likeRight("addr_code", s).or();
  641. }
  642. });
  643. //搜索字段
  644. if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText() .trim().equals("")) {
  645. queryWrapper.and(originWdInfoQueryWrapper -> {
  646. originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
  647. });
  648. }
  649. //城市等级分类
  650. if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
  651. List<String> tierCode = new ArrayList<>();
  652. for (String s : channelMapAceeptVo.getCityTier()) {
  653. List<String> list = initMapUtil.getInitCityTierListMap(s);
  654. if (list != null){
  655. tierCode.addAll(list);
  656. }
  657. }
  658. queryWrapper.and(wdInfoQueryWrapper -> {
  659. for (String s : tierCode) {
  660. wdInfoQueryWrapper.likeRight("addr_code", s).or();
  661. }
  662. });
  663. }
  664. //排序字段查询
  665. if (channelMapAceeptVo.getOrderby() != null && !channelMapAceeptVo.getOrderby().trim().equals("")) {
  666. PageHelper.orderBy(channelMapAceeptVo.getOrderby());
  667. }
  668. }*/
  669. }