123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908 |
- package com.ruoyi.demo.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import com.ruoyi.demo.entity.*;
- import com.ruoyi.demo.entity.bo.*;
- import com.ruoyi.demo.entity.vo.ChannelMapAceeptVo;
- import com.ruoyi.demo.mapper.*;
- import com.ruoyi.demo.service.ChannelMapService;
- import com.ruoyi.demo.utils.InitMapUtil;
- import com.ruoyi.demo.utils.WdRedisStoreage;
- import io.netty.util.concurrent.CompleteFuture;
- import lombok.RequiredArgsConstructor;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.List;
- import java.util.concurrent.CompletableFuture;
- import java.util.stream.Collectors;
- @RequiredArgsConstructor
- @Service
- @Transactional
- public class ChannelMapServiceImpl implements ChannelMapService {
- @Autowired
- private AddrCategoryDao addrCategoryDao;
- @Autowired
- InitMapUtil initMapUtil;
- @Autowired
- AttentionPoolDao attentionPoolDao;
- @Autowired
- WdInfoDao wdInfoDao;
- @Autowired
- RedisTemplate redisTemplate;
- @Autowired
- WdRedisStoreage wdRedisStoreage;
- @Autowired
- StoreWdDao storeWdDao;
- @Autowired
- HouseWdDao houseWdDao;
- @Autowired
- BuildWdDao buildWdDao;
- @Autowired
- TrafficWdDao trafficWdDao;
- @Autowired
- EnterpriseWdDao enterpriseWdDao;
- /**
- * 地图模式:查看所有地区的网点数量(v1.0)
- * @param channelMapAceeptVo
- * @return
- */
- /* @Override
- public WdCount area(ChannelMapAceeptVo channelMapAceeptVo) {
- //1.根据不同级别得到 需要封装的 地区码
- List<String> addrCodeList = new ArrayList<>();
- if ("province".equals(channelMapAceeptVo.getRankType())) {
- //省码
- for (String s : channelMapAceeptVo.getAddrCode()) {
- String substring = s.substring(0, 2);
- addrCodeList.add(substring);
- }
- } else if ("city".equals(channelMapAceeptVo.getRankType())) {
- //省的所有市
- for (String s : channelMapAceeptVo.getAddrCode()) {
- String substring = s.substring(0, 2);
- addrCodeList.add(substring);
- }
- } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
- //市的所有区
- for (String s : channelMapAceeptVo.getAddrCode()) {
- String substring = s.substring(0, 4);
- addrCodeList.add(substring);
- }
- } else {
- return null;
- }
- //2.找到所有需要封装的 地区信息
- QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
- if ("province".equals(channelMapAceeptVo.getRankType())) {
- queryWrapper.eq("city", "");
- } else if ("city".equals(channelMapAceeptVo.getRankType())) {
- queryWrapper.eq("district", "").and(addrCategoryQueryWrapper -> {
- addrCategoryQueryWrapper.ne("city", "");
- });
- } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
- queryWrapper.ne("district", "");
- }
- queryWrapper.and(addrCategoryQueryWrapper -> {
- addrCategoryQueryWrapper.or(addrCategoryQueryWrapper1 -> {
- for (String s : addrCodeList) {
- addrCategoryQueryWrapper1.likeRight("addr_code", s).or();
- }
- });
- });
- List<AddrCategory> addrCategories = addrCategoryDao.selectList(queryWrapper);
- //3.组装地区信息
- List<WdCountBody> result = new ArrayList<>();
- HashMap<String,Integer> statistics = new HashMap<>(); //统计信息
- for (AddrCategory addrCategory : addrCategories) {
- WdCountBody wdCountBody = new WdCountBody();
- //组装
- wdCountBody.setLat(addrCategory.getLatGd());
- wdCountBody.setLng(addrCategory.getLngGd());
- wdCountBody.setAddrCode(addrCategory.getAddrCode());
- if ("province".equals(channelMapAceeptVo.getRankType())) {
- wdCountBody.setName(addrCategory.getProvince());
- statistics.put(addrCategory.getAddrCode().substring(0,2),0);
- } else if ("city".equals(channelMapAceeptVo.getRankType())) {
- wdCountBody.setName(addrCategory.getCity());
- statistics.put(addrCategory.getAddrCode().substring(0,4),0);
- } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
- wdCountBody.setName(addrCategory.getDistrict());
- statistics.put(addrCategory.getAddrCode().substring(0,6),0);
- }
- result.add(wdCountBody);
- }
- //4.组装条件构造器找到网点信息网点
- //2.1 渠道、地区分类
- QueryWrapper<WdInfo> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.select("addr_code","count(*) as audit");
- queryWrapper2.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
- for (String s : addrCodeList) {
- originWdInfoQueryWrapper.likeRight("addr_code", s).or();
- }
- });
- //搜索字段
- if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
- queryWrapper2.and(originWdInfoQueryWrapper -> {
- originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
- });
- }
- //城市等级分类
- if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
- List<String> tierCode = new ArrayList<>();
- for (String s : channelMapAceeptVo.getCityTier()) {
- List<String> list = initMapUtil.getInitCityTierListMap(s);
- if (list != null){
- tierCode.addAll(list);
- }
- }
- queryWrapper.and(wdInfoQueryWrapper -> {
- for (String s : tierCode) {
- wdInfoQueryWrapper.likeRight("addr_code", s).or();
- }
- });
- }
- queryWrapper2.groupBy("addr_code");
- //5.统计
- int total = 0;
- List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper2);
- for (WdInfo wdInfo : wdInfos) {
- if("province".equals(channelMapAceeptVo.getRankType())){
- statistics.put(wdInfo.getAddrCode().substring(0,2),statistics.get(wdInfo.getAddrCode().substring(0,2))+wdInfo.getAudit());
- } else if ("city".equals(channelMapAceeptVo.getRankType())) {
- statistics.put(wdInfo.getAddrCode().substring(0,4),statistics.get(wdInfo.getAddrCode().substring(0,4))+wdInfo.getAudit());
- } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
- statistics.put(wdInfo.getAddrCode().substring(0,6),statistics.get(wdInfo.getAddrCode().substring(0,6))+wdInfo.getAudit());
- }
- total+=+wdInfo.getAudit();
- }
- //5.计算radio
- for (WdCountBody wdCountBody : result) {
- String code = null;
- if("province".equals(channelMapAceeptVo.getRankType())){
- code = wdCountBody.getAddrCode().substring(0,2);
- }else if("city".equals(channelMapAceeptVo.getRankType())){
- code = wdCountBody.getAddrCode().substring(0,4);
- }else if("zone".equals(channelMapAceeptVo.getRankType())){
- code = wdCountBody.getAddrCode().substring(0,6);
- }
- if(statistics.get(code) != null){
- wdCountBody.setCount(statistics.get(code));
- }else {
- wdCountBody.setCount(0);
- }
- if (total != 0){
- BigDecimal bigDecimal = new BigDecimal((float) wdCountBody.getCount() / total);
- float v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
- wdCountBody.setRadio(v);
- }
- else
- wdCountBody.setRadio(0.0f);
- }
- WdCount wdCount = new WdCount();
- wdCount.setWdCountBodyList(result);
- wdCount.setTotal(total);
- return wdCount;
- }*/
- /**
- * 地图模式:查看所有地区的网点数量(v2.0)
- * @param channelMapAceeptVo
- * @return
- */
- @Override
- public WdCount area(ChannelMapAceeptVo channelMapAceeptVo) {
- //1.根据不同级别得到 需要查询的 网点地区码
- CompletableFuture<List<String>> completableFuture1 = CompletableFuture.supplyAsync(() -> {
- return findWdAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
- });
- //2.找到所有需要封装的 地区信息
- CompletableFuture<List<AddrCategory>> completableFuture2 = CompletableFuture.supplyAsync(() -> {
- return findCenterAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
- });
- List<AddrCategory> addrCategories = completableFuture2.join();
- //3.组装地区信息
- List<WdCountBody> result = new ArrayList<>();
- HashMap<String,Integer> statistics = new HashMap<>(); //初始化统计信息
- for (AddrCategory addrCategory : addrCategories) {
- WdCountBody wdCountBody = new WdCountBody();
- //组装
- wdCountBody.setLat(addrCategory.getLatGd());
- wdCountBody.setLng(addrCategory.getLngGd());
- wdCountBody.setAddrCode(addrCategory.getAddrCode());
- if ("province".equals(channelMapAceeptVo.getRankType())) {
- wdCountBody.setName(addrCategory.getProvince());
- statistics.put(addrCategory.getAddrCode().substring(0,2),0);
- } else if ("city".equals(channelMapAceeptVo.getRankType())) {
- wdCountBody.setName(addrCategory.getCity());
- statistics.put(addrCategory.getAddrCode().substring(0,4),0);
- } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
- wdCountBody.setName(addrCategory.getDistrict());
- statistics.put(addrCategory.getAddrCode().substring(0,6),0);
- }
- result.add(wdCountBody);
- }
- //4.组装条件构造器找到网点信息网点
- //2.1 渠道、地区分类
- List<String> wdAddrCodes = completableFuture1.join();
- QueryWrapper<WdInfo> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.select("addr_code","count(*) as audit");
- queryWrapper2.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
- originWdInfoQueryWrapper.in("addr_code",wdAddrCodes);
- });
- //搜索字段
- if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
- queryWrapper2.and(originWdInfoQueryWrapper -> {
- originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
- });
- }
- //城市等级分类
- if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
- List<String> tierCode = new ArrayList<>();
- for (String s : channelMapAceeptVo.getCityTier()) {
- List<String> list = initMapUtil.getInitCityTierListMap(s);
- if (list != null){
- tierCode.addAll(list);
- }
- }
- queryWrapper2.and(wdInfoQueryWrapper -> {
- wdInfoQueryWrapper.in("addr_code",tierCode);
- });
- }
- queryWrapper2.groupBy("addr_code");
- //5.统计
- int total = 0;
- List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper2);
- for (WdInfo wdInfo : wdInfos) {
- if("province".equals(channelMapAceeptVo.getRankType())){
- statistics.put(wdInfo.getAddrCode().substring(0,2),statistics.get(wdInfo.getAddrCode().substring(0,2))+wdInfo.getAudit());
- } else if ("city".equals(channelMapAceeptVo.getRankType())) {
- statistics.put(wdInfo.getAddrCode().substring(0,4),statistics.get(wdInfo.getAddrCode().substring(0,4))+wdInfo.getAudit());
- } else if ("zone".equals(channelMapAceeptVo.getRankType())) {
- statistics.put(wdInfo.getAddrCode().substring(0,6),statistics.get(wdInfo.getAddrCode().substring(0,6))+wdInfo.getAudit());
- }
- total+=+wdInfo.getAudit();
- }
- //5.计算radio
- for (WdCountBody wdCountBody : result) {
- String code = null;
- if("province".equals(channelMapAceeptVo.getRankType())){
- code = wdCountBody.getAddrCode().substring(0,2);
- }else if("city".equals(channelMapAceeptVo.getRankType())){
- code = wdCountBody.getAddrCode().substring(0,4);
- }else if("zone".equals(channelMapAceeptVo.getRankType())){
- code = wdCountBody.getAddrCode().substring(0,6);
- }
- if(statistics.get(code) != null){
- wdCountBody.setCount(statistics.get(code));
- }else {
- wdCountBody.setCount(0);
- }
- if (total != 0){
- BigDecimal bigDecimal = new BigDecimal((float) wdCountBody.getCount() / total);
- float v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
- wdCountBody.setRadio(v);
- }
- else
- wdCountBody.setRadio(0.0f);
- }
- //5.封装结果
- WdCount wdCount = new WdCount();
- wdCount.setWdCountBodyList(result);
- wdCount.setTotal(total);
- return wdCount;
- }
- /**
- * 地图模式:查看省级地区的网点数量(v2.0)
- * @param channelMapAceeptVo
- * @return
- */
- @Override
- public WdCount areaProvince(ChannelMapAceeptVo channelMapAceeptVo) {
- //1.找到所有需要封装的 地区信息
- List<AddrCategory> addrCategories = findCenterAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
- //2.组装地区信息
- List<WdCountBody> result = new ArrayList<>();
- HashMap<String,Integer> statistics = new HashMap<>(); //初始化统计信息
- for (AddrCategory addrCategory : addrCategories) {
- WdCountBody wdCountBody = new WdCountBody();
- //组装
- wdCountBody.setLat(addrCategory.getLatGd());
- wdCountBody.setLng(addrCategory.getLngGd());
- wdCountBody.setAddrCode(addrCategory.getAddrCode());
- wdCountBody.setName(addrCategory.getProvince());
- statistics.put(addrCategory.getAddrCode().substring(0,2),0);
- result.add(wdCountBody);
- }
- //3.找到符合条件的网点信息
- QueryWrapper<WdInfo> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.select("addr_code","count(*) as audit");
- assembleQueryWrapper(queryWrapper2,channelMapAceeptVo);
- queryWrapper2.groupBy("addr_code");
- //4.统计各个地区网点数量
- int total = 0;
- List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper2);
- for (WdInfo wdInfo : wdInfos) {
- statistics.put(wdInfo.getAddrCode().substring(0,2),statistics.get(wdInfo.getAddrCode().substring(0,2))+wdInfo.getAudit());
- total+=+wdInfo.getAudit();
- }
- //5.计算radio
- for (WdCountBody wdCountBody : result) {
- String code = null;
- code = wdCountBody.getAddrCode().substring(0,2);
- if(statistics.get(code) != null){
- wdCountBody.setCount(statistics.get(code));
- }else {
- wdCountBody.setCount(0);
- }
- if (total != 0){
- BigDecimal bigDecimal = new BigDecimal((float) wdCountBody.getCount() / total);
- float v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
- wdCountBody.setRadio(v);
- }
- else
- wdCountBody.setRadio(0.0f);
- }
- //5.封装结果
- WdCount wdCount = new WdCount();
- wdCount.setWdCountBodyList(result);
- wdCount.setTotal(total);
- return wdCount;
- }
- /**
- * 地图模式:查看市级地区的网点数量(v2.0)
- * @param channelMapAceeptVo
- * @return
- */
- @Override
- public WdCount areaCity(ChannelMapAceeptVo channelMapAceeptVo) {
- //1.根据不同级别得到 需要查询的 网点地区码
- CompletableFuture<List<String>> completableFuture1 = CompletableFuture.supplyAsync(() -> {
- return findWdAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
- });
- //2.找到所有需要封装的 地区信息
- CompletableFuture<List<AddrCategory>> completableFuture2 = CompletableFuture.supplyAsync(() -> {
- return findCenterAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
- });
- List<AddrCategory> addrCategories = completableFuture2.join();
- //3.组装地区信息
- List<WdCountBody> result = new ArrayList<>();
- HashMap<String,Integer> statistics = new HashMap<>(); //初始化统计信息
- for (AddrCategory addrCategory : addrCategories) {
- WdCountBody wdCountBody = new WdCountBody();
- //组装
- wdCountBody.setLat(addrCategory.getLatGd());
- wdCountBody.setLng(addrCategory.getLngGd());
- wdCountBody.setAddrCode(addrCategory.getAddrCode());
- wdCountBody.setName(addrCategory.getCity());
- statistics.put(addrCategory.getAddrCode().substring(0,4),0);
- result.add(wdCountBody);
- }
- //4.组装条件构造器找到网点信息网点
- //2.1 渠道、地区分类
- List<String> wdAddrCodes = completableFuture1.join();
- QueryWrapper<WdInfo> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.select("addr_code","count(*) as audit");
- queryWrapper2.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
- originWdInfoQueryWrapper.in("addr_code",wdAddrCodes);
- });
- //搜索字段
- if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
- queryWrapper2.and(originWdInfoQueryWrapper -> {
- originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
- });
- }
- //城市等级分类
- if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
- List<String> tierCode = new ArrayList<>();
- for (String s : channelMapAceeptVo.getCityTier()) {
- List<String> list = initMapUtil.getInitCityTierListMap(s);
- if (list != null){
- tierCode.addAll(list);
- }
- }
- queryWrapper2.and(wdInfoQueryWrapper -> {
- wdInfoQueryWrapper.in("addr_code",tierCode);
- });
- }
- queryWrapper2.groupBy("addr_code");
- //5.统计
- int total = 0;
- List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper2);
- for (WdInfo wdInfo : wdInfos) {
- statistics.put(wdInfo.getAddrCode().substring(0,4),statistics.get(wdInfo.getAddrCode().substring(0,4))+wdInfo.getAudit());
- total+=+wdInfo.getAudit();
- }
- //5.计算radio
- for (WdCountBody wdCountBody : result) {
- String code = null;
- code = wdCountBody.getAddrCode().substring(0,4);
- if(statistics.get(code) != null){
- wdCountBody.setCount(statistics.get(code));
- }else {
- wdCountBody.setCount(0);
- }
- if (total != 0){
- BigDecimal bigDecimal = new BigDecimal((float) wdCountBody.getCount() / total);
- float v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
- wdCountBody.setRadio(v);
- }
- else
- wdCountBody.setRadio(0.0f);
- }
- //5.封装结果
- WdCount wdCount = new WdCount();
- wdCount.setWdCountBodyList(result);
- wdCount.setTotal(total);
- return wdCount;
- }
- /**
- * 地图模式:查看区级地区的网点数量(v2.0)
- * @param channelMapAceeptVo
- * @return
- */
- @Override
- public WdCount areaZone(ChannelMapAceeptVo channelMapAceeptVo) {
- //1.根据不同级别得到 需要查询的 网点地区码
- CompletableFuture<List<String>> completableFuture1 = CompletableFuture.supplyAsync(() -> {
- return findWdAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
- });
- //2.找到所有需要封装的 地区信息
- CompletableFuture<List<AddrCategory>> completableFuture2 = CompletableFuture.supplyAsync(() -> {
- return findCenterAddrCode(channelMapAceeptVo.getRankType(),channelMapAceeptVo.getAddrCode());
- });
- List<AddrCategory> addrCategories = completableFuture2.join();
- //3.组装地区信息
- List<WdCountBody> result = new ArrayList<>();
- HashMap<String,Integer> statistics = new HashMap<>(); //初始化统计信息
- for (AddrCategory addrCategory : addrCategories) {
- WdCountBody wdCountBody = new WdCountBody();
- //组装
- wdCountBody.setLat(addrCategory.getLatGd());
- wdCountBody.setLng(addrCategory.getLngGd());
- wdCountBody.setAddrCode(addrCategory.getAddrCode());
- wdCountBody.setName(addrCategory.getDistrict());
- statistics.put(addrCategory.getAddrCode().substring(0,6),0);
- result.add(wdCountBody);
- }
- //4.组装条件构造器找到网点信息网点
- //2.1 渠道、地区分类
- List<String> wdAddrCodes = completableFuture1.join();
- QueryWrapper<WdInfo> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.select("addr_code","count(*) as audit");
- queryWrapper2.in("wd_type_code", channelMapAceeptVo.getChannel()).and(originWdInfoQueryWrapper -> {
- originWdInfoQueryWrapper.in("addr_code",wdAddrCodes);
- });
- //搜索字段
- if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
- queryWrapper2.and(originWdInfoQueryWrapper -> {
- originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
- });
- }
- //城市等级分类
- if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
- List<String> tierCode = new ArrayList<>();
- for (String s : channelMapAceeptVo.getCityTier()) {
- List<String> list = initMapUtil.getInitCityTierListMap(s);
- if (list != null){
- tierCode.addAll(list);
- }
- }
- queryWrapper2.and(wdInfoQueryWrapper -> {
- wdInfoQueryWrapper.in("addr_code",tierCode);
- });
- }
- queryWrapper2.groupBy("addr_code");
- //5.统计
- int total = 0;
- List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper2);
- for (WdInfo wdInfo : wdInfos) {
- statistics.put(wdInfo.getAddrCode().substring(0,6),statistics.get(wdInfo.getAddrCode().substring(0,6))+wdInfo.getAudit());
- total+=+wdInfo.getAudit();
- }
- //5.计算radio
- for (WdCountBody wdCountBody : result) {
- String code = null;
- code = wdCountBody.getAddrCode().substring(0,6);
- if(statistics.get(code) != null){
- wdCountBody.setCount(statistics.get(code));
- }else {
- wdCountBody.setCount(0);
- }
- if (total != 0){
- BigDecimal bigDecimal = new BigDecimal((float) wdCountBody.getCount() / total);
- float v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
- wdCountBody.setRadio(v);
- }
- else
- wdCountBody.setRadio(0.0f);
- }
- //5.封装结果
- WdCount wdCount = new WdCount();
- wdCount.setWdCountBodyList(result);
- wdCount.setTotal(total);
- return wdCount;
- }
- /**
- * 获取网点列表
- * @param channelMapAceeptVo
- * @return
- */
- @Override
- public HashMap list(ChannelMapAceeptVo channelMapAceeptVo) {
- //1.根据条件获取网点
- QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
- assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
- Page<WdInfo> page = new Page<>(channelMapAceeptVo.getPageNum(), channelMapAceeptVo.getPageSize());
- Page<WdInfo> page1 = wdInfoDao.selectPage(page, queryWrapper);
- //2.获取标签并组装
- List<WdTopologicalInfoBo> result = new ArrayList<>(); //返回的封装网点数据集
- for (WdInfo wdInfo : page1.getRecords()) {
- WdTopologicalInfoBo wdTopologicalInfoBo = new WdTopologicalInfoBo(wdInfo);
- wdTopologicalInfoBo.setAddrCodeInfo(initMapUtil.getInitAddrCodeMap(wdInfo.getAddrCode()));
- List<String> tags = wdRedisStoreage.getWdTag(wdInfo);
- wdTopologicalInfoBo.setTag(tags);
- result.add(wdTopologicalInfoBo);
- }
- //3.返回结果集
- page1.setRecords(null);
- HashMap data = new HashMap();
- data.put("data",result);
- data.put("page",page1);
- return data;
- }
- /**
- * 获取区下的具体网点信息
- * @param channelMapAceeptVo
- * @return
- */
- @Override
- public Page<WdInfo> point(ChannelMapAceeptVo channelMapAceeptVo) {
- //1.查找符合条件的网点
- QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("addr_code",channelMapAceeptVo.getAddrCode()[0])
- .and(wdInfoQueryWrapper -> {
- wdInfoQueryWrapper.in("wd_type_code", channelMapAceeptVo.getChannel());
- });
- if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText().trim().equals("")) {
- queryWrapper.and(originWdInfoQueryWrapper -> {
- originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText());
- });
- }
- Page<WdInfo> page = new Page<>(channelMapAceeptVo.getPageNum(), channelMapAceeptVo.getPageSize());
- Page<WdInfo> page1 = wdInfoDao.selectPage(page, queryWrapper);
- return page1;
- }
- /**
- * 获取网点详细信息
- * @param wdId
- * @return
- */
- @Override
- public WdInfo getWdInfo(String wdId) {
- QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("wd_id",wdId);
- WdInfo wdInfo = wdInfoDao.selectOne(queryWrapper);
- if(wdInfo == null)
- return wdInfo;
- if("1".equals(wdInfo.getWdTypeCode())){
- //门店网点
- QueryWrapper<StoreWd> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.eq("wd_id",wdId);
- StoreWd storeWd = storeWdDao.selectOne(queryWrapper1);
- StoreWdInfoBo storeWdInfoBo = new StoreWdInfoBo(wdInfo);
- storeWdInfoBo.setStoreWd(storeWd);
- storeWdInfoBo.setTags(wdRedisStoreage.getWdTag(wdInfo));
- storeWdInfoBo.setAddrCode(initMapUtil.getInitAddrCodeMap(storeWdInfoBo.getAddrCode()));
- return storeWdInfoBo;
- }else if("2".equals(wdInfo.getWdTypeCode())){
- //小区网点
- QueryWrapper<HouseWd> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.eq("wd_id",wdId);
- HouseWd houseWd = houseWdDao.selectOne(queryWrapper1);
- HouseWdInfoBo houseWdInfoBo = new HouseWdInfoBo(wdInfo);
- houseWdInfoBo.setHouseWd(houseWd);
- houseWdInfoBo.setTags(wdRedisStoreage.getWdTag(wdInfo));
- houseWdInfoBo.setAddrCode(initMapUtil.getInitAddrCodeMap(houseWdInfoBo.getAddrCode()));
- return houseWdInfoBo;
- }else if("3".equals(wdInfo.getWdTypeCode())){
- //楼宇网点
- QueryWrapper<BuildWd> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.eq("wd_id",wdId);
- BuildWd buildWd = buildWdDao.selectOne(queryWrapper1);
- BuildWdInfoBo buildWdInfoBo = new BuildWdInfoBo(wdInfo);
- buildWdInfoBo.setBuildWd(buildWd);
- buildWdInfoBo.setTags(wdRedisStoreage.getWdTag(wdInfo));
- buildWdInfoBo.setAddrCode(initMapUtil.getInitAddrCodeMap(buildWdInfoBo.getAddrCode()));
- return buildWdInfoBo;
- }else if("4".equals(wdInfo.getWdTypeCode())){
- //交通设施网点
- QueryWrapper<TrafficWd> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.eq("wd_id",wdId);
- TrafficWd trafficWd = trafficWdDao.selectOne(queryWrapper1);
- TrafficWdInfoBo trafficWdInfoBo = new TrafficWdInfoBo(wdInfo);
- trafficWdInfoBo.setTrafficWd(trafficWd);
- trafficWdInfoBo.setTags(wdRedisStoreage.getWdTag(wdInfo));
- trafficWdInfoBo.setAddrCode(initMapUtil.getInitAddrCodeMap(trafficWdInfoBo.getAddrCode()));
- return trafficWdInfoBo;
- }else if("5".equals(wdInfo.getWdTypeCode())){
- //企业网点
- QueryWrapper<EnterpriseWd> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.eq("wd_id",wdId);
- EnterpriseWd enterpriseWd = enterpriseWdDao.selectOne(queryWrapper1);
- EnterpriseWdInfoBo enterpriseWdInfoBo = new EnterpriseWdInfoBo(wdInfo);
- enterpriseWdInfoBo.setEnterpriseWd(enterpriseWd);
- enterpriseWdInfoBo.setTags(wdRedisStoreage.getWdTag(wdInfo));
- enterpriseWdInfoBo.setAddrCode(initMapUtil.getInitAddrCodeMap(enterpriseWdInfoBo.getAddrCode()));
- return enterpriseWdInfoBo;
- }
- return wdInfo;
- }
- /**
- * 封装网点过滤条件(v2.0)
- * @param queryWrapper
- * @param channelMapAceeptVo
- */
- public void assembleQueryWrapper(QueryWrapper<WdInfo> queryWrapper,ChannelMapAceeptVo channelMapAceeptVo){
- //1.根据不同级别得到需要查询的 地区码
- List<String> wdAddrCode = findWdAddrCode(channelMapAceeptVo.getRankType(), channelMapAceeptVo.getAddrCode());
- //店龄
- if(channelMapAceeptVo.getStoreAge() != null && !channelMapAceeptVo.getStoreAge().equals("")){
- queryWrapper.and(wdInfoQueryWrapper -> {
- wdInfoQueryWrapper.eq("store_age",channelMapAceeptVo.getStoreAge());
- });
- }
- //地区过滤
- queryWrapper.and(wdInfoQueryWrapper -> {
- wdInfoQueryWrapper.in("addr_code", wdAddrCode);
- });
- //渠道过滤
- if(channelMapAceeptVo.getChannel() != null && channelMapAceeptVo.getChannel().length != 6){
- queryWrapper.and(wdInfoQueryWrapper -> {
- wdInfoQueryWrapper.in("wd_type_code", channelMapAceeptVo.getChannel());
- });
- }
- //城市等级分类
- if(channelMapAceeptVo.getCityTier() != null && channelMapAceeptVo.getCityTier().length > 0){
- List<String> tierCode = new ArrayList<>();
- for (String s : channelMapAceeptVo.getCityTier()) {
- List<String> list = initMapUtil.getInitCityTierListMap(s);
- if (list != null){
- tierCode.addAll(list);
- }
- }
- queryWrapper.and(wdInfoQueryWrapper -> {
- wdInfoQueryWrapper.in("addr_code",tierCode);
- });
- }
- //是否关联品牌
- if(channelMapAceeptVo.getIsBrand() != null && !channelMapAceeptVo.getIsBrand().equals("")){
- queryWrapper.and(wdInfoQueryWrapper -> {
- wdInfoQueryWrapper.isNotNull("brand_name");
- });
- }
- //是否有联系方式
- if(channelMapAceeptVo.getIsTelephone() != null && !channelMapAceeptVo.getIsTelephone().equals("")){
- queryWrapper.and(wdInfoQueryWrapper -> {
- wdInfoQueryWrapper.isNotNull("teletphone");
- });
- }
- //搜索字段
- if (channelMapAceeptVo.getSearchText() != null && !channelMapAceeptVo.getSearchText() .trim().equals("")) {
- queryWrapper.and(originWdInfoQueryWrapper -> {
- originWdInfoQueryWrapper.like("wd_name", channelMapAceeptVo.getSearchText() );
- });
- }
- //排序字段查询
- if (channelMapAceeptVo.getOrderby() != null && !channelMapAceeptVo.getOrderby().trim().equals("")) {
- PageHelper.orderBy(channelMapAceeptVo.getOrderby());
- }
- }
- /**
- * 找到所有满足条件的网点addrCode
- * @param rankType
- * @param addrCode
- * @return
- */
- private List<String> findWdAddrCode(String rankType,String[] addrCode){
- //1.根据不同级别得到 找到所有 完整的 区码
- List<String> addrCodeList = new ArrayList<>();
- if ("province".equals(rankType)) {
- //addrCode:省码
- for (String string:addrCode)
- addrCodeList.add(string.substring(0, 2));
- } else if ("city".equals(rankType)) {
- //addrCode:省码(只允许有一个)
- String substring = addrCode[0].substring(0, 2); //根据该省码找到旗下的所有的区
- addrCodeList.add(substring);
- } else if ("zone".equals(rankType)) {
- //addrCode:市码(只允许有一个)
- String substring = addrCode[0].substring(0, 4); //根据该市码找到旗下的所有的区
- addrCodeList.add(substring);
- } else {
- for (String string:addrCode)
- addrCodeList.add(string.substring(0, 2));
- }
- //2.找到所有完整的区码
- QueryWrapper<AddrCategory> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.ne("district", "");
- queryWrapper1.and(addrCategoryQueryWrapper -> {
- for (String s : addrCodeList) {
- addrCategoryQueryWrapper.likeRight("addr_code", s).or();
- }
- });
- List<AddrCategory> addrCategories1 = addrCategoryDao.selectList(queryWrapper1);
- List<String> collect = addrCategories1.stream().map(item -> {
- return item.getAddrCode();
- }).collect(Collectors.toList());
- return collect;
- }
- /**
- * 找到需要展示的中心addrCode
- * @param rankType
- * @param addrCode
- * @return
- */
- private List<AddrCategory> findCenterAddrCode(String rankType,String[] addrCode){
- //1.根据不同级别得到 找到所有 完整的 区码
- List<String> addrCodeList = new ArrayList<>();
- if ("province".equals(rankType)) {
- //addrCode:省码
- addrCodeList.addAll(Arrays.asList(addrCode));
- } else if ("city".equals(rankType)) {
- //addrCode:省码(只允许有一个)
- String substring = addrCode[0].substring(0, 2); //根据该省码找到旗下的所有的区
- addrCodeList.add(substring);
- } else if ("zone".equals(rankType)) {
- //addrCode:市码(只允许有一个)
- String substring = addrCode[0].substring(0, 4); //根据该市码找到旗下的所有的区
- addrCodeList.add(substring);
- } else {
- return null;
- }
- //2.找到所有需要封装的 地区信息
- QueryWrapper<AddrCategory> queryWrapper = new QueryWrapper<>();
- if ("province".equals(rankType)) {
- queryWrapper.eq("city", "");
- } else if ("city".equals(rankType)) {
- queryWrapper.eq("district", "").and(addrCategoryQueryWrapper -> {
- addrCategoryQueryWrapper.ne("city", "");
- });
- } else if ("zone".equals(rankType)) {
- queryWrapper.ne("district", "");
- }
- queryWrapper.and(addrCategoryQueryWrapper -> {
- for (String s : addrCodeList) {
- addrCategoryQueryWrapper.likeRight("addr_code", s).or();
- }
- });
- List<AddrCategory> addrCategories = addrCategoryDao.selectList(queryWrapper);
- return addrCategories;
- }
- }
|