diff --git a/ad-distribute-common/common-core/src/main/java/com/baiye/util/GeoUtil.java b/ad-distribute-common/common-core/src/main/java/com/baiye/util/GeoUtil.java new file mode 100644 index 0000000..634d3b4 --- /dev/null +++ b/ad-distribute-common/common-core/src/main/java/com/baiye/util/GeoUtil.java @@ -0,0 +1,69 @@ +package com.baiye.util; + +import lombok.RequiredArgsConstructor; +import org.springframework.data.geo.Distance; +import org.springframework.data.geo.GeoResult; +import org.springframework.data.geo.GeoResults; +import org.springframework.data.geo.Point; +import org.springframework.data.redis.connection.RedisGeoCommands; +import org.springframework.stereotype.Component; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author jt + */ +@Component +@RequiredArgsConstructor +public class GeoUtil { + + private final RedisUtils redisUtils; + + /** + * 将经纬度信息添加到redis中 + * + * @param key 标识 + * @param longitude 经度 + * @param latitude 纬度 + */ + public void geoAdd(String key, double longitude, double latitude, String geoKey) { + Point point = new Point(longitude, latitude); + RedisGeoCommands.GeoLocation geoLocation = new RedisGeoCommands.GeoLocation(key, point); + redisUtils.set(geoKey, geoLocation); + } + + /** + * 两个人之间的距离 + * + * @param key1 + * @param key2 + * @return + */ + public double distanceBetween(String geoKey, String key1, String key2) { + return redisUtils.distance(geoKey, key1, key2); + } + + /** + * 查询距离某个人指定范围内的人,包括距离多少米 + * + * @param key + * @param distance + * @return + */ + public Map distanceInclude(String geoKey, String key, double distance) { + Map map = new LinkedHashMap<>(); + + GeoResults> geoResults = redisUtils.radius(geoKey, key, new Distance(distance)); + if (geoResults != null) { + for (GeoResult> geoResult : geoResults) { + // 与目标点相距的距离信息 + Distance geoResultDistance = geoResult.getDistance(); + // 该点的信息 + RedisGeoCommands.GeoLocation geoResultContent = geoResult.getContent(); + map.put(geoResultContent.getName().toString(), geoResultDistance.getValue()); + } + } + return map; + } +} \ No newline at end of file diff --git a/ad-distribute-common/common-core/src/main/java/com/baiye/util/RedisUtils.java b/ad-distribute-common/common-core/src/main/java/com/baiye/util/RedisUtils.java index e78dfc1..d8f1b64 100644 --- a/ad-distribute-common/common-core/src/main/java/com/baiye/util/RedisUtils.java +++ b/ad-distribute-common/common-core/src/main/java/com/baiye/util/RedisUtils.java @@ -9,11 +9,11 @@ import com.baiye.enums.MailRequestEnum; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.extern.slf4j.Slf4j; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.geo.Distance; +import org.springframework.data.geo.GeoResults; import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.RedisGeoCommands; import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.RedisConnectionUtils; import org.springframework.data.redis.core.RedisTemplate; @@ -22,6 +22,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.*; +import java.util.List; import java.util.concurrent.TimeUnit; @Component @@ -29,690 +30,728 @@ import java.util.concurrent.TimeUnit; @Slf4j public class RedisUtils { @Resource - private RedisTemplate redisTemplate; - - - private String onlineKey = "online-token-"; - - /** - * 指定缓存失效时间 - * - * @param key 键 - * @param time 时间(秒) - */ - public boolean expire(String key, long time) { - try { - if (time > 0) { - redisTemplate.expire(key, time, TimeUnit.SECONDS); - } - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - return true; - } - - /** - * 指定缓存失效时间 - * - * @param key 键 - * @param time 时间(秒) - * @param timeUnit 单位 - */ - public boolean expire(String key, long time, TimeUnit timeUnit) { - try { - if (time > 0) { - redisTemplate.expire(key, time, timeUnit); - } - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - return true; - } - - /** - * 根据 key 获取过期时间 - * - * @param key 键 不能为null - * @return 时间(秒) 返回0代表为永久有效 - */ - public long getExpire(String key) { - return redisTemplate.getExpire(key, TimeUnit.SECONDS); - } - - /** - * 查找匹配key - * - * @param pattern key - * @return / - */ - public List scan(String pattern) { - ScanOptions options = ScanOptions.scanOptions().match(pattern).build(); - RedisConnectionFactory factory = redisTemplate.getConnectionFactory(); - RedisConnection rc = Objects.requireNonNull(factory).getConnection(); - Cursor cursor = rc.scan(options); - List result = new ArrayList<>(); - while (cursor.hasNext()) { - result.add(new String(cursor.next())); - } - try { - RedisConnectionUtils.releaseConnection(rc, factory); - } catch (Exception e) { - log.error(e.getMessage(), e); - } - return result; - } - - /** - * 分页查询 key - * - * @param patternKey key - * @param page 页码 - * @param size 每页数目 - * @return / - */ - public List findKeysForPage(String patternKey, int page, int size) { - ScanOptions options = ScanOptions.scanOptions().match(patternKey).build(); - RedisConnectionFactory factory = redisTemplate.getConnectionFactory(); - RedisConnection rc = Objects.requireNonNull(factory).getConnection(); - Cursor cursor = rc.scan(options); - List result = new ArrayList<>(size); - int tmpIndex = 0; - int fromIndex = page * size; - int toIndex = page * size + size; - while (cursor.hasNext()) { - if (tmpIndex >= fromIndex && tmpIndex < toIndex) { - result.add(new String(cursor.next())); - tmpIndex++; - continue; - } - // 获取到满足条件的数据后,就可以退出了 - if (tmpIndex >= toIndex) { - break; - } - tmpIndex++; - cursor.next(); - } - try { - RedisConnectionUtils.releaseConnection(rc, factory); - } catch (Exception e) { - log.error(e.getMessage(), e); - } - return result; - } - - /** - * 判断key是否存在 - * - * @param key 键 - * @return true 存在 false不存在 - */ - public boolean hasKey(String key) { - try { - return redisTemplate.hasKey(key); - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - /** - * 删除缓存 - * - * @param key 可以传一个值 或多个 - */ - public void del(String... keys) { - if (keys != null && keys.length > 0) { - if (keys.length == 1) { - boolean result = redisTemplate.delete(keys[0]); - log.debug("--------------------------------------------"); - log.debug(new StringBuilder("删除缓存:").append(keys[0]).append(",结果:").append(result).toString()); - log.debug("--------------------------------------------"); - } else { - Set keySet = new HashSet<>(); - for (String key : keys) { - keySet.addAll(redisTemplate.keys(key)); - } - long count = redisTemplate.delete(keySet); - log.debug("--------------------------------------------"); - log.debug("成功删除缓存:" + keySet.toString()); - log.debug("缓存删除数量:" + count + "个"); - log.debug("--------------------------------------------"); - } - } - } - - // ============================String============================= - - /** - * 普通缓存获取 - * - * @param key 键 - * @return 值 - */ - public Object get(String key) { - return key == null ? null : redisTemplate.opsForValue().get(key); - } - - /** - * 批量获取 - * - * @param keys - * @return - */ - public List multiGet(List keys) { - List list = redisTemplate.opsForValue().multiGet(Sets.newHashSet(keys)); - List resultList = Lists.newArrayList(); - Optional.ofNullable(list).ifPresent(e -> list.forEach(ele -> Optional.ofNullable(ele).ifPresent(resultList::add))); - return resultList; - } - - /** - * 普通缓存放入 - * - * @param key 键 - * @param value 值 - * @return true成功 false失败 - */ - public boolean set(String key, Object value) { - try { - redisTemplate.opsForValue().set(key, value); - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - /** - * 普通缓存放入并设置时间 - * - * @param key 键 - * @param value 值 - * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 - * @return true成功 false 失败 - */ - public boolean set(String key, Object value, long time) { - try { - if (time > 0) { - redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); - } else { - set(key, value); - } - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - /** - * 普通缓存放入并设置时间 - * - * @param key 键 - * @param value 值 - * @param time 时间 - * @param timeUnit 类型 - * @return true成功 false 失败 - */ - public boolean set(String key, Object value, long time, TimeUnit timeUnit) { - try { - if (time > 0) { - redisTemplate.opsForValue().set(key, value, time, timeUnit); - } else { - set(key, value); - } - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - // ================================Map================================= - - /** - * HashGet - * - * @param key 键 不能为null - * @param item 项 不能为null - * @return 值 - */ - public Object hget(String key, String item) { - return redisTemplate.opsForHash().get(key, item); - } - - /** - * 获取hashKey对应的所有键值 - * - * @param key 键 - * @return 对应的多个键值 - */ - public Map hmget(String key) { - return redisTemplate.opsForHash().entries(key); - - } - - /** - * HashSet - * - * @param key 键 - * @param map 对应多个键值 - * @return true 成功 false 失败 - */ - public boolean hmset(String key, Map map) { - try { - redisTemplate.opsForHash().putAll(key, map); - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - /** - * HashSet 并设置时间 - * - * @param key 键 - * @param map 对应多个键值 - * @param time 时间(秒) - * @return true成功 false失败 - */ - public boolean hmset(String key, Map map, long time) { - try { - redisTemplate.opsForHash().putAll(key, map); - if (time > 0) { - expire(key, time); - } - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - /** - * 向一张hash表中放入数据,如果不存在将创建 - * - * @param key 键 - * @param item 项 - * @param value 值 - * @return true 成功 false失败 - */ - public boolean hset(String key, String item, Object value) { - try { - redisTemplate.opsForHash().put(key, item, value); - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - /** - * 向一张hash表中放入数据,如果不存在将创建 - * - * @param key 键 - * @param item 项 - * @param value 值 - * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 - * @return true 成功 false失败 - */ - public boolean hset(String key, String item, Object value, long time) { - try { - redisTemplate.opsForHash().put(key, item, value); - if (time > 0) { - expire(key, time); - } - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - /** - * 删除hash表中的值 - * - * @param key 键 不能为null - * @param item 项 可以使多个 不能为null - */ - public void hdel(String key, Object... item) { - redisTemplate.opsForHash().delete(key, item); - } - - /** - * 判断hash表中是否有该项的值 - * - * @param key 键 不能为null - * @param item 项 不能为null - * @return true 存在 false不存在 - */ - public boolean hHasKey(String key, String item) { - return redisTemplate.opsForHash().hasKey(key, item); - } - - /** - * hash递增 如果不存在,就会创建一个 并把新增后的值返回 - * - * @param key 键 - * @param item 项 - * @param by 要增加几(大于0) - * @return - */ - public double hincr(String key, String item, double by) { - return redisTemplate.opsForHash().increment(key, item, by); - } - - /** - * hash递减 - * - * @param key 键 - * @param item 项 - * @param by 要减少记(小于0) - * @return - */ - public double hdecr(String key, String item, double by) { - return redisTemplate.opsForHash().increment(key, item, -by); - } - - // ============================set============================= - - /** - * 根据key获取Set中的所有值 - * - * @param key 键 - * @return - */ - public Set sGet(String key) { - try { - return redisTemplate.opsForSet().members(key); - } catch (Exception e) { - log.error(e.getMessage(), e); - return null; - } - } - - /** - * 根据value从一个set中查询,是否存在 - * - * @param key 键 - * @param value 值 - * @return true 存在 false不存在 - */ - public boolean sHasKey(String key, Object value) { - try { - return redisTemplate.opsForSet().isMember(key, value); - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - /** - * 将数据放入set缓存 - * - * @param key 键 - * @param values 值 可以是多个 - * @return 成功个数 - */ - public long sSet(String key, Object... values) { - try { - return redisTemplate.opsForSet().add(key, values); - } catch (Exception e) { - log.error(e.getMessage(), e); - return 0; - } - } - - /** - * 将set数据放入缓存 - * - * @param key 键 - * @param time 时间(秒) - * @param values 值 可以是多个 - * @return 成功个数 - */ - public long sSetAndTime(String key, long time, Object... values) { - try { - Long count = redisTemplate.opsForSet().add(key, values); - if (time > 0) { - expire(key, time); - } - return count; - } catch (Exception e) { - log.error(e.getMessage(), e); - return 0; - } - } - - /** - * 获取set缓存的长度 - * - * @param key 键 - * @return - */ - public long sGetSetSize(String key) { - try { - return redisTemplate.opsForSet().size(key); - } catch (Exception e) { - log.error(e.getMessage(), e); - return 0; - } - } - - /** - * 移除值为value的 - * - * @param key 键 - * @param values 值 可以是多个 - * @return 移除的个数 - */ - public long setRemove(String key, Object... values) { - try { - Long count = redisTemplate.opsForSet().remove(key, values); - return count; - } catch (Exception e) { - log.error(e.getMessage(), e); - return 0; - } - } - - // ===============================list================================= - - /** - * 获取list缓存的内容 - * - * @param key 键 - * @param start 开始 - * @param end 结束 0 到 -1代表所有值 - * @return - */ - public List lGet(String key, long start, long end) { - try { - return redisTemplate.opsForList().range(key, start, end); - } catch (Exception e) { - log.error(e.getMessage(), e); - return null; - } - } - - /** - * 获取list缓存的长度 - * - * @param key 键 - * @return - */ - public long lGetListSize(String key) { - try { - return redisTemplate.opsForList().size(key); - } catch (Exception e) { - log.error(e.getMessage(), e); - return 0; - } - } - - /** - * 通过索引 获取list中的值 - * - * @param key 键 - * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 - * @return - */ - public Object lGetIndex(String key, long index) { - try { - return redisTemplate.opsForList().index(key, index); - } catch (Exception e) { - log.error(e.getMessage(), e); - return null; - } - } - - /** - * 将list放入缓存 - * - * @param key 键 - * @param value 值 - * @return - */ - public boolean lSet(String key, Object value) { - try { - redisTemplate.opsForList().rightPush(key, value); - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - /** - * 将list放入缓存 - * - * @param key 键 - * @param value 值 - * @param time 时间(秒) - * @return - */ - public boolean lSet(String key, Object value, long time) { - try { - redisTemplate.opsForList().rightPush(key, value); - if (time > 0) { - expire(key, time); - } - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - /** - * 将list放入缓存 - * - * @param key 键 - * @param value 值 - * @return - */ - public boolean lSet(String key, List value) { - try { - redisTemplate.opsForList().rightPushAll(key, value); - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - /** - * 将list放入缓存 - * - * @param key 键 - * @param value 值 - * @param time 时间(秒) - * @return - */ - public boolean lSet(String key, List value, long time) { - try { - redisTemplate.opsForList().rightPushAll(key, value); - if (time > 0) { - expire(key, time); - } - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - /** - * 根据索引修改list中的某条数据 - * - * @param key 键 - * @param index 索引 - * @param value 值 - * @return / - */ - public boolean lUpdateIndex(String key, long index, Object value) { - try { - redisTemplate.opsForList().set(key, index, value); - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - - /** - * 移除N个值为value - * - * @param key 键 - * @param count 移除多少个 - * @param value 值 - * @return 移除的个数 - */ - public long lRemove(String key, long count, Object value) { - try { - return redisTemplate.opsForList().remove(key, count, value); - } catch (Exception e) { - log.error(e.getMessage(), e); - return 0; - } - } - - /** - * @param prefix 前缀 - * @param ids id - */ - public void delByKeys(String prefix, Set ids) { - Set keys = new HashSet<>(); - for (Long id : ids) { - keys.addAll(redisTemplate.keys(new StringBuffer(prefix).append(id).toString())); - } - long count = redisTemplate.delete(keys); - // 此处提示可自行删除 - log.debug("--------------------------------------------"); - log.debug("成功删除缓存:" + keys.toString()); - log.debug("缓存删除数量:" + count + "个"); - log.debug("--------------------------------------------"); - } - - /** - * 批次获取 - * - * @param prefix - * @param ids - */ - public String acquisitionBatch(String cacheType) { - String format = DateUtil.format(DateUtil.date(), DatePattern.PURE_DATE_PATTERN); - Integer num = (Integer) get(cacheType.concat(format)); - Integer batch = ObjectUtil.isNull(num) ? - DefaultNumberConstants.ONE_NUMBER : num + DefaultNumberConstants.ONE_NUMBER; - // 保存批次号 - set(cacheType.concat(format), batch, DefaultNumberConstants.ONE_NUMBER, TimeUnit.DAYS); - String parameter = MailRequestEnum.find(cacheType).getType(); - return parameter.concat(StrPool.DASHED). - concat(format).concat(StrPool.DASHED).concat(String.valueOf(batch)); - - } + private RedisTemplate redisTemplate; + + + private String onlineKey = "online-token-"; + + /** + * 指定缓存失效时间 + * + * @param key 键 + * @param time 时间(秒) + */ + public boolean expire(String key, long time) { + try { + if (time > 0) { + redisTemplate.expire(key, time, TimeUnit.SECONDS); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + return true; + } + + /** + * 指定缓存失效时间 + * + * @param key 键 + * @param time 时间(秒) + * @param timeUnit 单位 + */ + public boolean expire(String key, long time, TimeUnit timeUnit) { + try { + if (time > 0) { + redisTemplate.expire(key, time, timeUnit); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + return true; + } + + /** + * 根据 key 获取过期时间 + * + * @param key 键 不能为null + * @return 时间(秒) 返回0代表为永久有效 + */ + public long getExpire(String key) { + return redisTemplate.getExpire(key, TimeUnit.SECONDS); + } + + /** + * 查找匹配key + * + * @param pattern key + * @return / + */ + public List scan(String pattern) { + ScanOptions options = ScanOptions.scanOptions().match(pattern).build(); + RedisConnectionFactory factory = redisTemplate.getConnectionFactory(); + RedisConnection rc = Objects.requireNonNull(factory).getConnection(); + Cursor cursor = rc.scan(options); + List result = new ArrayList<>(); + while (cursor.hasNext()) { + result.add(new String(cursor.next())); + } + try { + RedisConnectionUtils.releaseConnection(rc, factory); + } catch (Exception e) { + log.error(e.getMessage(), e); + } + return result; + } + + /** + * 分页查询 key + * + * @param patternKey key + * @param page 页码 + * @param size 每页数目 + * @return / + */ + public List findKeysForPage(String patternKey, int page, int size) { + ScanOptions options = ScanOptions.scanOptions().match(patternKey).build(); + RedisConnectionFactory factory = redisTemplate.getConnectionFactory(); + RedisConnection rc = Objects.requireNonNull(factory).getConnection(); + Cursor cursor = rc.scan(options); + List result = new ArrayList<>(size); + int tmpIndex = 0; + int fromIndex = page * size; + int toIndex = page * size + size; + while (cursor.hasNext()) { + if (tmpIndex >= fromIndex && tmpIndex < toIndex) { + result.add(new String(cursor.next())); + tmpIndex++; + continue; + } + // 获取到满足条件的数据后,就可以退出了 + if (tmpIndex >= toIndex) { + break; + } + tmpIndex++; + cursor.next(); + } + try { + RedisConnectionUtils.releaseConnection(rc, factory); + } catch (Exception e) { + log.error(e.getMessage(), e); + } + return result; + } + + /** + * 判断key是否存在 + * + * @param key 键 + * @return true 存在 false不存在 + */ + public boolean hasKey(String key) { + try { + return redisTemplate.hasKey(key); + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + /** + * 删除缓存 + * + * @param key 可以传一个值 或多个 + */ + public void del(String... keys) { + if (keys != null && keys.length > 0) { + if (keys.length == 1) { + boolean result = redisTemplate.delete(keys[0]); + log.debug("--------------------------------------------"); + log.debug(new StringBuilder("删除缓存:").append(keys[0]).append(",结果:").append(result).toString()); + log.debug("--------------------------------------------"); + } else { + Set keySet = new HashSet<>(); + for (String key : keys) { + keySet.addAll(redisTemplate.keys(key)); + } + long count = redisTemplate.delete(keySet); + log.debug("--------------------------------------------"); + log.debug("成功删除缓存:" + keySet.toString()); + log.debug("缓存删除数量:" + count + "个"); + log.debug("--------------------------------------------"); + } + } + } + + // ============================String============================= + + /** + * 普通缓存获取 + * + * @param key 键 + * @return 值 + */ + public Object get(String key) { + return key == null ? null : redisTemplate.opsForValue().get(key); + } + + /** + * 批量获取 + * + * @param keys + * @return + */ + public List multiGet(List keys) { + List list = redisTemplate.opsForValue().multiGet(Sets.newHashSet(keys)); + List resultList = Lists.newArrayList(); + Optional.ofNullable(list).ifPresent(e -> list.forEach(ele -> Optional.ofNullable(ele).ifPresent(resultList::add))); + return resultList; + } + + /** + * 普通缓存放入 + * + * @param key 键 + * @param value 值 + * @return true成功 false失败 + */ + public boolean set(String key, Object value) { + try { + redisTemplate.opsForValue().set(key, value); + return true; + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + /** + * 普通缓存放入并设置时间 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 + * @return true成功 false 失败 + */ + public boolean set(String key, Object value, long time) { + try { + if (time > 0) { + redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); + } else { + set(key, value); + } + return true; + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + /** + * 普通缓存放入并设置时间 + * + * @param key 键 + * @param value 值 + * @param time 时间 + * @param timeUnit 类型 + * @return true成功 false 失败 + */ + public boolean set(String key, Object value, long time, TimeUnit timeUnit) { + try { + if (time > 0) { + redisTemplate.opsForValue().set(key, value, time, timeUnit); + } else { + set(key, value); + } + return true; + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + // ================================Map================================= + + /** + * HashGet + * + * @param key 键 不能为null + * @param item 项 不能为null + * @return 值 + */ + public Object hget(String key, String item) { + return redisTemplate.opsForHash().get(key, item); + } + + /** + * 获取hashKey对应的所有键值 + * + * @param key 键 + * @return 对应的多个键值 + */ + public Map hmget(String key) { + return redisTemplate.opsForHash().entries(key); + + } + + /** + * HashSet + * + * @param key 键 + * @param map 对应多个键值 + * @return true 成功 false 失败 + */ + public boolean hmset(String key, Map map) { + try { + redisTemplate.opsForHash().putAll(key, map); + return true; + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + /** + * HashSet 并设置时间 + * + * @param key 键 + * @param map 对应多个键值 + * @param time 时间(秒) + * @return true成功 false失败 + */ + public boolean hmset(String key, Map map, long time) { + try { + redisTemplate.opsForHash().putAll(key, map); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + /** + * 向一张hash表中放入数据,如果不存在将创建 + * + * @param key 键 + * @param item 项 + * @param value 值 + * @return true 成功 false失败 + */ + public boolean hset(String key, String item, Object value) { + try { + redisTemplate.opsForHash().put(key, item, value); + return true; + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + /** + * 向一张hash表中放入数据,如果不存在将创建 + * + * @param key 键 + * @param item 项 + * @param value 值 + * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 + * @return true 成功 false失败 + */ + public boolean hset(String key, String item, Object value, long time) { + try { + redisTemplate.opsForHash().put(key, item, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + /** + * 删除hash表中的值 + * + * @param key 键 不能为null + * @param item 项 可以使多个 不能为null + */ + public void hdel(String key, Object... item) { + redisTemplate.opsForHash().delete(key, item); + } + + /** + * 判断hash表中是否有该项的值 + * + * @param key 键 不能为null + * @param item 项 不能为null + * @return true 存在 false不存在 + */ + public boolean hHasKey(String key, String item) { + return redisTemplate.opsForHash().hasKey(key, item); + } + + /** + * hash递增 如果不存在,就会创建一个 并把新增后的值返回 + * + * @param key 键 + * @param item 项 + * @param by 要增加几(大于0) + * @return + */ + public double hincr(String key, String item, double by) { + return redisTemplate.opsForHash().increment(key, item, by); + } + + /** + * hash递减 + * + * @param key 键 + * @param item 项 + * @param by 要减少记(小于0) + * @return + */ + public double hdecr(String key, String item, double by) { + return redisTemplate.opsForHash().increment(key, item, -by); + } + + // ============================set============================= + + /** + * 根据key获取Set中的所有值 + * + * @param key 键 + * @return + */ + public Set sGet(String key) { + try { + return redisTemplate.opsForSet().members(key); + } catch (Exception e) { + log.error(e.getMessage(), e); + return null; + } + } + + /** + * 根据value从一个set中查询,是否存在 + * + * @param key 键 + * @param value 值 + * @return true 存在 false不存在 + */ + public boolean sHasKey(String key, Object value) { + try { + return redisTemplate.opsForSet().isMember(key, value); + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + /** + * 将数据放入set缓存 + * + * @param key 键 + * @param values 值 可以是多个 + * @return 成功个数 + */ + public long sSet(String key, Object... values) { + try { + return redisTemplate.opsForSet().add(key, values); + } catch (Exception e) { + log.error(e.getMessage(), e); + return 0; + } + } + + /** + * 将set数据放入缓存 + * + * @param key 键 + * @param time 时间(秒) + * @param values 值 可以是多个 + * @return 成功个数 + */ + public long sSetAndTime(String key, long time, Object... values) { + try { + Long count = redisTemplate.opsForSet().add(key, values); + if (time > 0) { + expire(key, time); + } + return count; + } catch (Exception e) { + log.error(e.getMessage(), e); + return 0; + } + } + + /** + * 获取set缓存的长度 + * + * @param key 键 + * @return + */ + public long sGetSetSize(String key) { + try { + return redisTemplate.opsForSet().size(key); + } catch (Exception e) { + log.error(e.getMessage(), e); + return 0; + } + } + + /** + * 移除值为value的 + * + * @param key 键 + * @param values 值 可以是多个 + * @return 移除的个数 + */ + public long setRemove(String key, Object... values) { + try { + Long count = redisTemplate.opsForSet().remove(key, values); + return count; + } catch (Exception e) { + log.error(e.getMessage(), e); + return 0; + } + } + + // ===============================list================================= + + /** + * 获取list缓存的内容 + * + * @param key 键 + * @param start 开始 + * @param end 结束 0 到 -1代表所有值 + * @return + */ + public List lGet(String key, long start, long end) { + try { + return redisTemplate.opsForList().range(key, start, end); + } catch (Exception e) { + log.error(e.getMessage(), e); + return null; + } + } + + /** + * 获取list缓存的长度 + * + * @param key 键 + * @return + */ + public long lGetListSize(String key) { + try { + return redisTemplate.opsForList().size(key); + } catch (Exception e) { + log.error(e.getMessage(), e); + return 0; + } + } + + /** + * 通过索引 获取list中的值 + * + * @param key 键 + * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 + * @return + */ + public Object lGetIndex(String key, long index) { + try { + return redisTemplate.opsForList().index(key, index); + } catch (Exception e) { + log.error(e.getMessage(), e); + return null; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @return + */ + public boolean lSet(String key, Object value) { + try { + redisTemplate.opsForList().rightPush(key, value); + return true; + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) + * @return + */ + public boolean lSet(String key, Object value, long time) { + try { + redisTemplate.opsForList().rightPush(key, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @return + */ + public boolean lSet(String key, List value) { + try { + redisTemplate.opsForList().rightPushAll(key, value); + return true; + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) + * @return + */ + public boolean lSet(String key, List value, long time) { + try { + redisTemplate.opsForList().rightPushAll(key, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + /** + * 根据索引修改list中的某条数据 + * + * @param key 键 + * @param index 索引 + * @param value 值 + * @return / + */ + public boolean lUpdateIndex(String key, long index, Object value) { + try { + redisTemplate.opsForList().set(key, index, value); + return true; + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + + /** + * 移除N个值为value + * + * @param key 键 + * @param count 移除多少个 + * @param value 值 + * @return 移除的个数 + */ + public long lRemove(String key, long count, Object value) { + try { + return redisTemplate.opsForList().remove(key, count, value); + } catch (Exception e) { + log.error(e.getMessage(), e); + return 0; + } + } + + /** + * @param prefix 前缀 + * @param ids id + */ + public void delByKeys(String prefix, Set ids) { + Set keys = new HashSet<>(); + for (Long id : ids) { + keys.addAll(redisTemplate.keys(new StringBuffer(prefix).append(id).toString())); + } + long count = redisTemplate.delete(keys); + // 此处提示可自行删除 + log.debug("--------------------------------------------"); + log.debug("成功删除缓存:" + keys.toString()); + log.debug("缓存删除数量:" + count + "个"); + log.debug("--------------------------------------------"); + } + + /** + * 批次获取 + * + * @param prefix + * @param ids + */ + public String acquisitionBatch(String cacheType) { + String format = DateUtil.format(DateUtil.date(), DatePattern.PURE_DATE_PATTERN); + Integer num = (Integer) get(cacheType.concat(format)); + Integer batch = ObjectUtil.isNull(num) ? + DefaultNumberConstants.ONE_NUMBER : num + DefaultNumberConstants.ONE_NUMBER; + // 保存批次号 + set(cacheType.concat(format), batch, DefaultNumberConstants.ONE_NUMBER, TimeUnit.DAYS); + String parameter = MailRequestEnum.find(cacheType).getType(); + return parameter.concat(StrPool.DASHED). + concat(format).concat(StrPool.DASHED).concat(String.valueOf(batch)); + + } + + /** + * 存储经纬度 + * + * @param key id + * @param point 经维度 + * @param name 名称 + */ + public void set(String key, RedisGeoCommands.GeoLocation geoLocation) { + redisTemplate.opsForGeo().add(key, geoLocation); + } + + /** + * 两个人之间的距离 + * + * @param geoKey + * @param key1 + * @param key2 + * @return + */ + public Double distance(String geoKey, String key1, String key2) { + Distance distance = redisTemplate.opsForGeo().distance(geoKey, key1, key2); + return distance.getValue(); + } + + /** + * 查询距离某个人指定范围内的人 + * + * @param geoKey + * @param key + * @param distance + * @return + */ + public GeoResults> radius(String geoKey, String key, Distance distance) { + RedisGeoCommands.GeoRadiusCommandArgs geoRadiusCommandArgs = RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs(); + GeoResults> radius = redisTemplate.opsForGeo().radius(geoKey, key, distance, geoRadiusCommandArgs.includeDistance()); + return radius; + } } diff --git a/admin/src/main/java/com/baiye/modules/distribute/controller/StoreController.java b/admin/src/main/java/com/baiye/modules/distribute/controller/StoreController.java index 6050068..18976b2 100644 --- a/admin/src/main/java/com/baiye/modules/distribute/controller/StoreController.java +++ b/admin/src/main/java/com/baiye/modules/distribute/controller/StoreController.java @@ -2,11 +2,13 @@ package com.baiye.modules.distribute.controller; import com.baiye.domain.PageParam; import com.baiye.domain.PageResult; +import com.baiye.modules.distribute.dto.StoreDTO; import com.baiye.modules.distribute.entity.StoreEntity; import com.baiye.modules.distribute.qo.StoreQo; import com.baiye.modules.distribute.service.StoreService; import com.baiye.modules.distribute.vo.StoreVO; import com.baiye.result.R; +import com.baiye.util.GeoUtil; import com.baiye.validation.group.CreateGroup; import com.baiye.validation.group.UpdateGroup; import io.swagger.v3.oas.annotations.Operation; @@ -15,6 +17,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.util.List; + /** * @author wjt * @date 2023/9/5 @@ -26,11 +30,26 @@ import org.springframework.web.bind.annotation.*; public class StoreController { private final StoreService storeService; + private final GeoUtil geoUtil; - @GetMapping("/queryAll") + @GetMapping("/queryPage") @Operation(summary = "分页查询门店") - public R> queryStore(@Validated PageParam pageParam, StoreQo storeQo) { - return R.ok(storeService.queryStore(pageParam, storeQo)); + public R> queryStorePage(@Validated PageParam pageParam, StoreQo storeQo) { + return R.ok(storeService.queryStorePage(pageParam, storeQo)); + } + + @GetMapping("/queryAll") + @Operation(summary = "不分页查询门店") + public R> queryStore(StoreQo storeQo) { + return R.ok(storeService.queryStore(storeQo)); + } + + @GetMapping("/queryRange") + @Operation(summary = "查询范围内所有的门店") + public R> queryRangeStore(@RequestParam("longitude") Double longitude, + @RequestParam("latitude") Double latitude, + @RequestParam("distance") Double distance) { + return R.ok(storeService.queryRangeStore(longitude, latitude, distance)); } @PostMapping("/add") diff --git a/admin/src/main/java/com/baiye/modules/distribute/dto/StoreDTO.java b/admin/src/main/java/com/baiye/modules/distribute/dto/StoreDTO.java new file mode 100644 index 0000000..1d1ba06 --- /dev/null +++ b/admin/src/main/java/com/baiye/modules/distribute/dto/StoreDTO.java @@ -0,0 +1,34 @@ +package com.baiye.modules.distribute.dto; + +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springdoc.api.annotations.ParameterObject; + +import java.math.BigDecimal; + +/** + * @author wjt + * @date 2023/9/13 + */ +@Data +@Schema(title = "门店管理dto") +@ParameterObject +public class StoreDTO { + @Parameter(description = "门店名称") + private String storeName; + @Parameter(description = "门店id") + private String id; + @Parameter(description = "纬度") + private BigDecimal latitude; + @Parameter(description = "经度") + private BigDecimal longitude; + @Parameter(description = "联系方式") + private String nid; + @Parameter(description = "门店地址") + private String address; + @Parameter(description = "距离/米") + private Double distance; + @Parameter(description = "序号") + private Integer index; +} diff --git a/admin/src/main/java/com/baiye/modules/distribute/entity/StoreEntity.java b/admin/src/main/java/com/baiye/modules/distribute/entity/StoreEntity.java index df6aaf0..dbc5ca0 100644 --- a/admin/src/main/java/com/baiye/modules/distribute/entity/StoreEntity.java +++ b/admin/src/main/java/com/baiye/modules/distribute/entity/StoreEntity.java @@ -12,6 +12,7 @@ import lombok.Getter; import lombok.Setter; import javax.validation.constraints.NotNull; +import java.math.BigDecimal; /** * @author wjt @@ -40,7 +41,8 @@ public class StoreEntity extends LogicDeletedBaseEntity { @Schema(title = "门店状态 0-正常 1-未营业") @NotNull(message = "门店状态不能为空", groups = {CreateGroup.class}) private Integer storeStatus; - + @Schema(title = "nid") + private String nid; @Schema(title = "省份") private String province; @@ -50,6 +52,9 @@ public class StoreEntity extends LogicDeletedBaseEntity { @Schema(title = "区县") private String county; + @Schema(title = "详细地址") + private String detail; + @Schema(title = "营业开始时间") @NotNull(message = "营业时间不能为空", groups = {CreateGroup.class}) private String tradeStartTime; @@ -61,4 +66,12 @@ public class StoreEntity extends LogicDeletedBaseEntity { @TableField(exist = false) @NotNull(message = "地址不能为空", groups = {CreateGroup.class}) private String address; + + @Schema(title = "经度") + @NotNull(message = "经度不能为空", groups = {CreateGroup.class}) + private BigDecimal longitude; + + @Schema(title = "玮度") + @NotNull(message = "玮度不能为空", groups = {CreateGroup.class}) + private BigDecimal latitude; } diff --git a/admin/src/main/java/com/baiye/modules/distribute/mapper/StoreMapper.java b/admin/src/main/java/com/baiye/modules/distribute/mapper/StoreMapper.java index eb8b546..a8d31e4 100644 --- a/admin/src/main/java/com/baiye/modules/distribute/mapper/StoreMapper.java +++ b/admin/src/main/java/com/baiye/modules/distribute/mapper/StoreMapper.java @@ -30,8 +30,7 @@ public interface StoreMapper extends ExtendMapper { .eqIfPresent(StoreEntity::getProvince, qo.getProvince()) .eqIfPresent(StoreEntity::getCity, qo.getCity()) .eqIfPresent(StoreEntity::getCounty, qo.getCounty()) - .eq(StoreEntity::getDeleted, 0) - + .eq(StoreEntity::getCreateBy, qo.getCreateBy()) // .geIfPresent(StoreEntity::getTradeStartTime, qo.getTradeEndTime()) // .leIfPresent(StoreEntity::getTradeEndTime, qo.getTradeStartTime()) diff --git a/admin/src/main/java/com/baiye/modules/distribute/qo/StoreQo.java b/admin/src/main/java/com/baiye/modules/distribute/qo/StoreQo.java index 3f37491..ce35de5 100644 --- a/admin/src/main/java/com/baiye/modules/distribute/qo/StoreQo.java +++ b/admin/src/main/java/com/baiye/modules/distribute/qo/StoreQo.java @@ -37,9 +37,11 @@ public class StoreQo { @Parameter(description = "添加的结束时间") private Date createEndTime; -// @Parameter(description = "营业开始时间") + // @Parameter(description = "营业开始时间") // private String tradeStartTime; // // @Parameter(description = "营业结束时间") // private String tradeEndTime; + @Parameter(description = "创建人") + private Long createBy; } diff --git a/admin/src/main/java/com/baiye/modules/distribute/service/StoreService.java b/admin/src/main/java/com/baiye/modules/distribute/service/StoreService.java index 6dd0234..9aaeac2 100644 --- a/admin/src/main/java/com/baiye/modules/distribute/service/StoreService.java +++ b/admin/src/main/java/com/baiye/modules/distribute/service/StoreService.java @@ -3,10 +3,13 @@ package com.baiye.modules.distribute.service; import com.baiye.domain.PageParam; import com.baiye.domain.PageResult; import com.baiye.extend.mybatis.plus.service.ExtendService; +import com.baiye.modules.distribute.dto.StoreDTO; import com.baiye.modules.distribute.entity.StoreEntity; import com.baiye.modules.distribute.qo.StoreQo; import com.baiye.modules.distribute.vo.StoreVO; +import java.util.List; + /** * @author wjt * @date 2023/9/5 @@ -20,7 +23,15 @@ public interface StoreService extends ExtendService { * @param storeQo 查询条件 * @return 分页结果 */ - PageResult queryStore(PageParam pageParam, StoreQo storeQo); + PageResult queryStorePage(PageParam pageParam, StoreQo storeQo); + + /** + * 不分页查询门店 + * + * @param storeQo 查询条件 + * @return 查询结果 + */ + List queryStore(StoreQo storeQo); /** * 新增 @@ -42,4 +53,15 @@ public interface StoreService extends ExtendService { * @param storeId 门店id */ void deleteStore(Long storeId); + + + /** + * 查询范围内所有的门店 + * + * @param longitude + * @param latitude + * @param distance + * @return + */ + List queryRangeStore(Double longitude, Double latitude, Double distance); } diff --git a/admin/src/main/java/com/baiye/modules/distribute/service/impl/StoreServiceImpl.java b/admin/src/main/java/com/baiye/modules/distribute/service/impl/StoreServiceImpl.java index b4f1fb8..5f3ab6d 100644 --- a/admin/src/main/java/com/baiye/modules/distribute/service/impl/StoreServiceImpl.java +++ b/admin/src/main/java/com/baiye/modules/distribute/service/impl/StoreServiceImpl.java @@ -1,20 +1,31 @@ package com.baiye.modules.distribute.service.impl; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.RandomUtil; import com.baiye.domain.PageParam; import com.baiye.domain.PageResult; +import com.baiye.exception.BadRequestException; import com.baiye.extend.mybatis.plus.service.impl.ExtendServiceImpl; +import com.baiye.modules.distribute.dto.StoreDTO; import com.baiye.modules.distribute.entity.StoreEntity; import com.baiye.modules.distribute.mapper.StoreMapper; import com.baiye.modules.distribute.qo.StoreQo; import com.baiye.modules.distribute.service.CustomStoreService; import com.baiye.modules.distribute.service.StoreService; import com.baiye.modules.distribute.vo.StoreVO; +import com.baiye.security.util.SecurityUtils; +import com.baiye.util.GeoUtil; +import com.baiye.util.RedisUtils; import com.baiye.utils.AddressSplitterUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -29,11 +40,13 @@ import java.util.stream.Collectors; public class StoreServiceImpl extends ExtendServiceImpl implements StoreService { private final CustomStoreService customStoreService; - + private final RedisUtils redisUtils; + private final GeoUtil geoUtil; + private final String storeRedisKey = "store::"; @Override - public PageResult queryStore(PageParam pageParam, StoreQo storeQo) { - + public PageResult queryStorePage(PageParam pageParam, StoreQo storeQo) { + storeQo.setCreateBy(SecurityUtils.getCurrentUserId()); PageResult storeEntityPageResult = baseMapper.queryPage(pageParam, storeQo); List records = storeEntityPageResult.getRecords(); if (CollUtil.isNotEmpty(records)) { @@ -48,14 +61,34 @@ public class StoreServiceImpl extends ExtendServiceImpl queryStore(StoreQo qo) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + if (qo.getStoreName() != null) { + wrapper.like(StoreEntity::getStoreName, qo.getStoreName()); + } + wrapper.eq(StoreEntity::getCreateBy, SecurityUtils.getCurrentUserId()); + wrapper.orderByDesc(StoreEntity::getCreateTime); + List storeEntities = baseMapper.selectList(wrapper); + return Convert.toList(StoreVO.class, storeEntities); + } + @Override public void addStore(StoreEntity storeEntity) { + //同一个公司门店名不能重复 + Long currentUserId = SecurityUtils.getCurrentUserId(); + StoreEntity storeEntity1 = baseMapper.selectOne(new LambdaQueryWrapper().eq(StoreEntity::getCreateBy, currentUserId).eq(StoreEntity::getStoreName, storeEntity.getStoreName())); + if (storeEntity1 != null) { + throw new BadRequestException("门店名称重复"); + } String address = storeEntity.getAddress(); Map map = AddressSplitterUtil.getAddress(address); storeEntity.setProvince(map.get("province")); storeEntity.setCity(map.get("city")); storeEntity.setCounty(map.get("county")); + storeEntity.setDetail(map.get("detail")); baseMapper.insert(storeEntity); + addStoreRedis(storeEntity); } @Override @@ -86,4 +119,63 @@ public class StoreServiceImpl extends ExtendServiceImpl queryRangeStore(Double longitude, Double latitude, Double distance) { + List list = new ArrayList<>(); +// Long whichUserId = SecurityUtils.getWhichUserId(); +// log.info("父id:{}",whichUserId); + Long userId = 1L; + + List storeEntities = baseMapper.selectList(new LambdaQueryWrapper().eq(StoreEntity::getCreateBy, userId)); + Map map = new HashMap<>(); + if (CollUtil.isNotEmpty(storeEntities)) { + redisUtils.del(userId.toString()); + for (StoreEntity storeEntity : storeEntities) { + geoUtil.geoAdd(storeEntity.getId().toString(), storeEntity.getLongitude().doubleValue(), storeEntity.getLatitude().doubleValue(), userId.toString()); + } + String key = RandomUtil.randomString(4); + geoUtil.geoAdd(key, longitude, latitude, userId.toString()); + map = geoUtil.distanceInclude(userId.toString(), key, distance); + } + + if (map != null) { + int index = 0; + for (Map.Entry range : map.entrySet()) { + String key = range.getKey(); + StoreDTO storeRedis = getStoreRedis(key); + if (storeRedis != null && storeRedis.getId() != null) { + storeRedis.setDistance(range.getValue()); + storeRedis.setIndex(index); + list.add(storeRedis); + index++; + } + } + } + return list; + } + + public StoreDTO getStoreRedis(String id) { + + Object o = redisUtils.get(storeRedisKey + id); + if (o != null) { + return BeanUtil.toBean(o, StoreDTO.class); + } else { + StoreEntity storeEntity = baseMapper.selectById(id); + StoreDTO storeDTO = new StoreDTO(); + if (storeEntity != null && storeEntity.getId() != null) { + BeanUtil.copyProperties(storeEntity, storeDTO); + storeDTO.setAddress(storeEntity.getCounty() + storeEntity.getDetail()); + redisUtils.set(storeRedisKey + storeEntity.getId(), storeDTO); + } + return storeDTO; + } + } + + public void addStoreRedis(StoreEntity storeEntity) { + StoreDTO storeDTO = new StoreDTO(); + BeanUtil.copyProperties(storeEntity, storeDTO); + storeDTO.setAddress(storeEntity.getCounty() + storeEntity.getDetail()); + redisUtils.set(storeRedisKey + storeEntity.getId(), storeDTO); + } } diff --git a/admin/src/main/java/com/baiye/modules/distribute/vo/StoreVO.java b/admin/src/main/java/com/baiye/modules/distribute/vo/StoreVO.java index 246016a..15d2bcd 100644 --- a/admin/src/main/java/com/baiye/modules/distribute/vo/StoreVO.java +++ b/admin/src/main/java/com/baiye/modules/distribute/vo/StoreVO.java @@ -1,8 +1,12 @@ package com.baiye.modules.distribute.vo; +import com.baiye.validation.group.CreateGroup; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import javax.validation.constraints.NotNull; +import java.math.BigDecimal; + /** * @author wjt @@ -46,4 +50,9 @@ public class StoreVO { @Schema(title = "营业时间") private String tradeTime; + @Schema(title = "经度") + private BigDecimal latitude; + + @Schema(title = "玮度") + private BigDecimal longitude; }