购物车缓存 完善1.0
parent
aed910d491
commit
2bfd4882cf
|
@ -1,61 +0,0 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
/**
|
||||
* 缓存接口基类 CaChe
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/3/27
|
||||
*/
|
||||
public interface CaChe <K,V> {
|
||||
/**
|
||||
* key前缀
|
||||
* @return key前缀
|
||||
*/
|
||||
public String keyPre();
|
||||
|
||||
/**
|
||||
* 编码
|
||||
* @param key
|
||||
* @return 键
|
||||
*/
|
||||
public String encode(K key);
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param redisKey 数据库键
|
||||
* @return ID
|
||||
*/
|
||||
public K decode(String redisKey);
|
||||
|
||||
/**
|
||||
* 通过key获取value值
|
||||
* @param key 键
|
||||
* @return 值
|
||||
*/
|
||||
public V get(K key);
|
||||
|
||||
/**
|
||||
* 缓存添加/修改
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
*/
|
||||
public void put(K key,V value);
|
||||
|
||||
/**
|
||||
* 通过键删除
|
||||
* @param key 键
|
||||
*/
|
||||
public void remove(K key);
|
||||
|
||||
/**
|
||||
* 刷新缓存时间
|
||||
* @param key 键
|
||||
*/
|
||||
public void refreshTime(K key);
|
||||
|
||||
/**
|
||||
* 刷新缓存数据
|
||||
* @param key 键
|
||||
*/
|
||||
public void refreshDate(K key);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.common.cache;
|
||||
|
||||
import com.muyu.common.cache.decoration.DecorationKey;
|
||||
|
||||
/**
|
||||
* @author yangle
|
||||
* @description: 原子序列缓存基准
|
||||
* @Date 2024-4-1 下午 08:07
|
||||
*/
|
||||
public interface AtomicSequenceCache<K> extends DecorationKey<K> {
|
||||
|
||||
/**
|
||||
* 获取存储的值
|
||||
* @param key 键
|
||||
* @return 值
|
||||
*/
|
||||
public Long get(K key);
|
||||
|
||||
/**
|
||||
* 自增
|
||||
*/
|
||||
public Long increment(K key);
|
||||
/**
|
||||
* 自减
|
||||
*/
|
||||
public Long decrement(K key);
|
||||
|
||||
/**
|
||||
* 增加数值
|
||||
*/
|
||||
public Long increment(K key, Long number);
|
||||
|
||||
/**
|
||||
* 减少数值
|
||||
*/
|
||||
public Long decrement(K key, Long number);
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.muyu.common.cache;
|
||||
|
||||
import com.muyu.common.cache.decoration.DecorationKey;
|
||||
|
||||
/**
|
||||
* @author yangle
|
||||
* @description: 缓存接口基类
|
||||
* @Date 2024-3-26 下午 03:25
|
||||
*/
|
||||
public interface Cache <K, V> extends DecorationKey<K> {
|
||||
|
||||
/**
|
||||
* 通过Key获取value值
|
||||
* @param key 键
|
||||
* @return 值
|
||||
*/
|
||||
public V get(K key);
|
||||
|
||||
/**
|
||||
* 缓存添加/修改
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
*/
|
||||
public void put(K key, V value);
|
||||
|
||||
/**
|
||||
* 通过键删除
|
||||
* @param key 键
|
||||
*/
|
||||
public void remove(K key);
|
||||
|
||||
/**
|
||||
* 刷新缓存时间
|
||||
* @param key 键
|
||||
*/
|
||||
public void refreshTime (K key);
|
||||
|
||||
/**
|
||||
* 刷新缓存数据
|
||||
* @param key 键
|
||||
*/
|
||||
public void refreshData (K key);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.common.cache;
|
||||
|
||||
/**
|
||||
* GetData
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/3/29
|
||||
*/
|
||||
public interface GetData<K,V> {
|
||||
/**
|
||||
* 从数据库获取数据
|
||||
* @param key ID
|
||||
* @return 缓存对象
|
||||
*/
|
||||
public abstract V getData(K key);
|
||||
|
||||
/**
|
||||
* 默认值
|
||||
*/
|
||||
public abstract V defaultValue();
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package com.muyu.common.cache;
|
||||
|
||||
import com.muyu.common.cache.decoration.DecorationKey;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author yangle
|
||||
* @description: Hash缓存基准
|
||||
* @Date 2024-3-29 下午 03:16
|
||||
*/
|
||||
public interface HashCache <K, HK, HV> extends DecorationKey<K> {
|
||||
|
||||
|
||||
/**
|
||||
* 编码
|
||||
* @param hashKey ID
|
||||
* @return 键
|
||||
*/
|
||||
public String encodeHashKey(HK hashKey);
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param redisHashKey 数据库键
|
||||
* @return ID
|
||||
*/
|
||||
public HK decodeHashKey(String redisHashKey);
|
||||
|
||||
/**
|
||||
* 通过Key获取所有的map
|
||||
* @param key 数据库键
|
||||
* @return 所有集合Map
|
||||
*/
|
||||
public Map<HK, HV> get(K key);
|
||||
|
||||
/**
|
||||
* 通过键和hashKey获取数据库hashValue
|
||||
* @param key 键
|
||||
* @param hashKey hash键
|
||||
* @return hash值
|
||||
*/
|
||||
public HV get(K key, HK hashKey);
|
||||
|
||||
/**
|
||||
* 通过键和hashKey获取数据库hashValue
|
||||
* @param key 键
|
||||
* @param hashKeyList hash键集合
|
||||
* @return hash值
|
||||
*/
|
||||
public List<HV> get(K key, HK... hashKeyList);
|
||||
|
||||
/**
|
||||
* 获取hash值集合
|
||||
* @param key 键
|
||||
* @return hash值集合
|
||||
*/
|
||||
public List<HV> getToList(K key);
|
||||
|
||||
/**
|
||||
* 存储数据
|
||||
* @param key redis键
|
||||
* @param map hashMap集合
|
||||
*/
|
||||
public void put(K key, Map<HK, HV> map);
|
||||
|
||||
/**
|
||||
* 存储数据
|
||||
* @param key redis键
|
||||
* @param dataList 数据值
|
||||
* @param hashKey hash键
|
||||
*/
|
||||
public void put(K key, List<HV> dataList, Function<HV, HK> hashKey);
|
||||
|
||||
/**
|
||||
* 存储数据
|
||||
* @param key redis键
|
||||
* @param hashKey hash键
|
||||
* @param hashValue hash值
|
||||
*/
|
||||
public void put(K key, HK hashKey, HV hashValue);
|
||||
|
||||
/**
|
||||
* 通过redis键删除
|
||||
* @param key hash键
|
||||
*/
|
||||
public void remove(K key);
|
||||
|
||||
/**
|
||||
* 通过redis键和hash键删除
|
||||
* @param key redis键
|
||||
* @param hashKey hash键
|
||||
*/
|
||||
public void remove(K key, HK hashKey);
|
||||
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
package com.muyu.common.cache.abs;
|
||||
|
||||
import com.muyu.common.cache.AtomicSequenceCache;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* @author yangle
|
||||
* @description: 原子序列缓存抽象类
|
||||
* @Date 2024-4-1 下午 08:33
|
||||
*/
|
||||
public abstract class AtomicSequenceCacheAbs<K> implements AtomicSequenceCache<K> {
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 获取存储的值
|
||||
* @param key 键
|
||||
* @return 值
|
||||
*/
|
||||
@Override
|
||||
public Long get (K key) {
|
||||
return this.redisService.getCacheObject(encode(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 自增
|
||||
* @param key
|
||||
*/
|
||||
@Override
|
||||
public Long increment (K key) {
|
||||
return this.increment(key, 1L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自减
|
||||
*
|
||||
* @param key
|
||||
*/
|
||||
@Override
|
||||
public Long decrement (K key) {
|
||||
return this.decrement(key, 1L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加数值
|
||||
*
|
||||
* @param key
|
||||
* @param number
|
||||
*/
|
||||
@Override
|
||||
public Long increment (K key, Long number) {
|
||||
Long numberValue = redisService.getCacheObject(encode(key));
|
||||
if (numberValue == null){
|
||||
Long data = getData(key);
|
||||
data = data == null ? 0L : data;
|
||||
redisService.setCacheObject(encode(key), data);
|
||||
}
|
||||
return redisService.increment(encode(key), number);
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少数值
|
||||
*
|
||||
* @param key
|
||||
* @param number
|
||||
*/
|
||||
@Override
|
||||
public Long decrement (K key, Long number) {
|
||||
Long numberValue = redisService.getCacheObject(encode(key));
|
||||
if (numberValue == null){
|
||||
Long data = getData(key);
|
||||
data = data == null ? 0L : data;
|
||||
redisService.setCacheObject(encode(key), data);
|
||||
}
|
||||
return redisService.decrement(encode(key), number);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*
|
||||
* @param key ID
|
||||
*
|
||||
* @return 键
|
||||
*/
|
||||
@Override
|
||||
public String encode (K key) {
|
||||
return keyPre() + key;
|
||||
}
|
||||
|
||||
public abstract Long getData(K key);
|
||||
}
|
|
@ -1,59 +1,57 @@
|
|||
package com.muyu.cache.abs;
|
||||
package com.muyu.common.cache.abs;
|
||||
|
||||
import com.muyu.cache.CaChe;
|
||||
import com.muyu.common.cache.Cache;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 缓存抽象类 CacheAbs
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/3/27
|
||||
* @author yangle
|
||||
* @description: 缓存抽象类
|
||||
* @Date 2024-3-27 下午 03:10
|
||||
*/
|
||||
public abstract class CacheAbs<K,V> implements CaChe<K,V> {
|
||||
public abstract class CacheAbs<K, V> implements Cache<K, V> {
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
/**
|
||||
* 编码
|
||||
* @param key Id
|
||||
* @return 值
|
||||
* @param key ID
|
||||
* @return 键
|
||||
*/
|
||||
@Override
|
||||
public String encode(K key) {
|
||||
return keyPre()+key;
|
||||
public String encode (K key) {
|
||||
return keyPre() + key;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过key获取value 值
|
||||
* 通过Key获取value值
|
||||
* @param key 键
|
||||
* @return
|
||||
* @return 值
|
||||
*/
|
||||
@Override
|
||||
public V get(K key) {
|
||||
V value= redisService.getCacheObject(encode(key));
|
||||
public V get (K key) {
|
||||
V value = redisService.getCacheObject(encode(key));
|
||||
if (value == null){
|
||||
value = getData(key);
|
||||
if (value == null ){
|
||||
if (value == null){
|
||||
value = defaultValue();
|
||||
}
|
||||
}
|
||||
this.put(key,value);
|
||||
this.put(key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存添加/修改
|
||||
* @param key 键
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
*/
|
||||
@Override
|
||||
public void put(K key, V value) {
|
||||
this.redisService.setCacheObject(encode(key), value);
|
||||
public void put (K key, V value) {
|
||||
this.redisService.setCacheObject(encode(key), value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,8 +59,8 @@ public abstract class CacheAbs<K,V> implements CaChe<K,V> {
|
|||
* @param key 键
|
||||
*/
|
||||
@Override
|
||||
public void remove(K key) {
|
||||
this.redisService.deleteObject(encode(key));
|
||||
public void remove (K key) {
|
||||
this.redisService.deleteObject(encode(key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,17 +68,18 @@ public abstract class CacheAbs<K,V> implements CaChe<K,V> {
|
|||
* @param key 键
|
||||
*/
|
||||
@Override
|
||||
public void refreshTime(K key) {
|
||||
this.redisService.expire(encode(key), 60, TimeUnit.SECONDS);
|
||||
public void refreshTime (K key) {
|
||||
this.redisService.expire(encode(key), 60, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新缓存数据
|
||||
*
|
||||
* @param key 键
|
||||
*/
|
||||
@Override
|
||||
public void refreshDate(K key) {
|
||||
this.put(key,getData(key));
|
||||
public void refreshData (K key) {
|
||||
this.put(key, getData(key));
|
||||
}
|
||||
|
||||
/**
|
|
@ -0,0 +1,212 @@
|
|||
package com.muyu.common.cache.abs;
|
||||
|
||||
import com.muyu.common.cache.HashCache;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author yangle
|
||||
* @description: hash缓存抽象类
|
||||
* @Date 2024-3-29 下午 07:40
|
||||
*/
|
||||
public abstract class HashCacheAbs<K, HK, HV> implements HashCache<K, HK, HV> {
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*
|
||||
* @param key ID
|
||||
*
|
||||
* @return 键
|
||||
*/
|
||||
@Override
|
||||
public String encode (K key) {
|
||||
return keyPre() + key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编码
|
||||
* @param hashKey ID
|
||||
* @return 键
|
||||
*/
|
||||
@Override
|
||||
public String encodeHashKey (HK hashKey) {
|
||||
return hashKey.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过Key获取所有的map
|
||||
* @param key 数据库键
|
||||
* @return 所有集合Map
|
||||
*/
|
||||
@Override
|
||||
public Map<HK, HV> get (K key) {
|
||||
// 获取为null的情况
|
||||
Map<String, HV> cacheMap = redisService.getCacheMap(encode(key));
|
||||
if (cacheMap == null || cacheMap.isEmpty()){
|
||||
Map<HK, HV> dataMap = getData(key);
|
||||
if (dataMap != null && !dataMap.isEmpty()){
|
||||
cacheMap = encodeMap(dataMap);
|
||||
}else {
|
||||
cacheMap = encodeMap(defaultValue());
|
||||
}
|
||||
redisService.setCacheMap(encode(key), cacheMap);
|
||||
}
|
||||
return decodeMap(cacheMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过键和hashKey获取数据库hashValue
|
||||
*
|
||||
* @param key 键
|
||||
* @param hashKey hash键
|
||||
*
|
||||
* @return hash值
|
||||
*/
|
||||
@Override
|
||||
public HV get (K key, HK hashKey) {
|
||||
HV hashValue = redisService.getCacheMapValue(encode(key), encodeHashKey(hashKey));
|
||||
if (hashValue == null){
|
||||
HV dataValue = getData(key, hashKey);
|
||||
hashValue = dataValue != null ? dataValue : defaultHashValue();
|
||||
put(key, hashKey, hashValue);
|
||||
}
|
||||
return hashValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过键和hashKey获取数据库hashValue
|
||||
*
|
||||
* @param key 键
|
||||
* @param hashKeyList hash键集合
|
||||
*
|
||||
* @return hash值
|
||||
*/
|
||||
@Override
|
||||
public List<HV> get (K key, HK... hashKeyList) {
|
||||
List<String> encodeHashKeyList = Arrays.stream(hashKeyList).map(this::encodeHashKey).toList();
|
||||
return redisService.getMultiCacheMapValue(encode(key), encodeHashKeyList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取hash值集合
|
||||
*
|
||||
* @param key 键
|
||||
*
|
||||
* @return hash值集合
|
||||
*/
|
||||
@Override
|
||||
public List<HV> getToList (K key) {
|
||||
Map<HK, HV> hkhvMap = get(key);
|
||||
return hkhvMap.values().stream().toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储数据
|
||||
*
|
||||
* @param key redis键
|
||||
* @param map hashMap集合
|
||||
*/
|
||||
@Override
|
||||
public void put (K key, Map<HK, HV> map) {
|
||||
redisService.setCacheMap(encode(key), encodeMap(map));
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储数据
|
||||
*
|
||||
* @param key redis键
|
||||
* @param dataList 数据值
|
||||
* @param hashKey hash键
|
||||
*/
|
||||
@Override
|
||||
public void put (K key, List<HV> dataList, Function<HV, HK> hashKey) {
|
||||
Map<HK, HV> dataMap = new HashMap<>();
|
||||
dataList.forEach((data) -> dataMap.put(hashKey.apply(data), data));
|
||||
redisService.setCacheMap(encode(key), encodeMap(dataMap));
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储数据
|
||||
*
|
||||
* @param key redis键
|
||||
* @param hashKey hash键
|
||||
* @param hashValue hash值
|
||||
*/
|
||||
@Override
|
||||
public void put (K key, HK hashKey, HV hashValue) {
|
||||
redisService.setCacheMapValue(encode(key), encodeHashKey(hashKey), hashValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过redis键删除
|
||||
*
|
||||
* @param key hash键
|
||||
*/
|
||||
@Override
|
||||
public void remove (K key) {
|
||||
redisService.deleteObject(encode(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过redis键和hash键删除
|
||||
*
|
||||
* @param key redis键
|
||||
* @param hashKey hash键
|
||||
*/
|
||||
@Override
|
||||
public void remove (K key, HK hashKey) {
|
||||
redisService.deleteCacheMapValue(encode(key), encodeHashKey(hashKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* 原始数据转编码数据
|
||||
* @param dataMap 原始数据
|
||||
* @return 编码数据
|
||||
*/
|
||||
private Map<String, HV> encodeMap(Map<HK, HV> dataMap){
|
||||
Map<String, HV> encodeDataMap = new HashMap<>();
|
||||
dataMap.forEach((hashKey, HashValue) -> encodeDataMap.put(encodeHashKey(hashKey), HashValue));
|
||||
return encodeDataMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编码数据转原始数据
|
||||
* @param encodeDataMap 编码数据
|
||||
* @return 原始数据
|
||||
*/
|
||||
private Map<HK, HV> decodeMap(Map<String, HV> encodeDataMap){
|
||||
Map<HK, HV> dataMap = new HashMap<>();
|
||||
encodeDataMap.forEach((hashKey, hashValue) -> dataMap.put(decodeHashKey(hashKey), hashValue));
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过键获取所有的hash数据
|
||||
* @param key 键
|
||||
* @return
|
||||
*/
|
||||
public abstract Map<HK, HV> getData(K key);
|
||||
|
||||
/**
|
||||
* 通过缓存键和hash键获取hash值
|
||||
* @param key 缓存键
|
||||
* @param hashKey hash键
|
||||
* @return hash值
|
||||
*/
|
||||
public abstract HV getData(K key, HK hashKey);
|
||||
|
||||
/**
|
||||
* 默认值
|
||||
*/
|
||||
public abstract Map<HK, HV> defaultValue();
|
||||
public abstract HV defaultHashValue();
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.common.cache.abs;
|
||||
|
||||
import com.muyu.common.cache.GetData;
|
||||
|
||||
/**
|
||||
* getDataAbs
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/4/1
|
||||
*/
|
||||
public abstract class getDataAbs<K,V> implements GetData<K,V> {
|
||||
|
||||
@Override
|
||||
public V getData(K key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V defaultValue() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.muyu.common.cache.decoration;
|
||||
|
||||
/**
|
||||
* @author yangle
|
||||
* @description: 装饰Key
|
||||
* @Date 2024-3-29 下午 03:19
|
||||
*/
|
||||
public interface DecorationKey <K>{
|
||||
|
||||
/**
|
||||
* key前缀
|
||||
* @return key前缀
|
||||
*/
|
||||
public String keyPre();
|
||||
|
||||
|
||||
/**
|
||||
* 编码
|
||||
* @param key ID
|
||||
* @return 键
|
||||
*/
|
||||
public String encode(K key);
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param redisKey 数据库键
|
||||
* @return ID
|
||||
*/
|
||||
public K decode(String redisKey);
|
||||
}
|
|
@ -39,6 +39,9 @@ public class Result<T> implements Serializable {
|
|||
|
||||
private T data;
|
||||
|
||||
public static <T> Result<T> buildCode(int code,String msg,T data){
|
||||
return restResult(data,code,msg);
|
||||
}
|
||||
public static <T> Result<T> success () {
|
||||
return restResult(null, SUCCESS, null);
|
||||
}
|
||||
|
@ -93,6 +96,7 @@ public class Result<T> implements Serializable {
|
|||
return restResult(null, code, msg);
|
||||
}
|
||||
|
||||
|
||||
private static <T> Result<T> restResult (T data, int code, String msg) {
|
||||
return Result.<T>builder()
|
||||
.code(code)
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.apache.commons.lang3.ObjectUtils;
|
|||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @author yangle
|
||||
* @description: 对象工具类
|
||||
* @Date 2023-10-9 下午 04:56
|
||||
*/
|
||||
|
|
|
@ -229,10 +229,14 @@ public class RedisService {
|
|||
*
|
||||
* @return Hash对象集合
|
||||
*/
|
||||
public <T> List<T> getMultiCacheMapValue (final String key, final Collection<Object> hKeys) {
|
||||
public <T> List<T> getMultiCacheMapValue (final String key, final Collection<?> hKeys) {
|
||||
return redisTemplate.opsForHash().multiGet(key, hKeys);
|
||||
}
|
||||
|
||||
public boolean hashKey(final String key,final String hashkey){
|
||||
return this.redisTemplate.opsForHash().hasKey(key, hashkey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除Hash中的某条数据
|
||||
*
|
||||
|
@ -255,4 +259,24 @@ public class RedisService {
|
|||
public Collection<String> keys (final String pattern) {
|
||||
return redisTemplate.keys(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少序列值
|
||||
* @param key key
|
||||
* @param number 值
|
||||
* @return 操作后的值
|
||||
*/
|
||||
public Long decrement(final String key,Long number){
|
||||
return redisTemplate.opsForValue().decrement(key,number);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加序列值
|
||||
* @param key key
|
||||
* @param number 值
|
||||
* @return 操作后的值
|
||||
*/
|
||||
public Long increment(final String key,Long number){
|
||||
return redisTemplate.opsForValue().increment(key,number);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @author yangle
|
||||
* @description: 验证码
|
||||
* @Date 2023-11-12 下午 03:36
|
||||
*/
|
||||
|
|
|
@ -16,17 +16,20 @@
|
|||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!--缓存基准模块-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-cache</artifactId>
|
||||
|
||||
</dependency>
|
||||
<!--商品模块 common依赖-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-product-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
|
||||
<!-- 缓存基准模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-cache</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 商品模块 common 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-product-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
package com.muyu.product.cache;
|
||||
|
||||
import com.muyu.common.cache.abs.HashCacheAbs;
|
||||
import com.muyu.common.core.text.Convert;
|
||||
import com.muyu.product.cache.datasource.ProjectSkuData;
|
||||
import com.muyu.product.domain.ProjectSkuInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author yangle
|
||||
* @description: 商品sku基本信息
|
||||
* @Date 2024-3-29 下午 03:06
|
||||
*/
|
||||
@Component
|
||||
public class ProjectSkuCache extends HashCacheAbs<Long, String, ProjectSkuInfo> {
|
||||
|
||||
@Autowired
|
||||
private ProjectSkuData projectSkuData;
|
||||
|
||||
|
||||
/**
|
||||
* key前缀
|
||||
* @return key前缀
|
||||
*/
|
||||
@Override
|
||||
public String keyPre () {
|
||||
return "project:sku:";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param redisKey 数据库键
|
||||
* @return ID
|
||||
*/
|
||||
@Override
|
||||
public Long decode (String redisKey) {
|
||||
return Convert.toLong(redisKey.replace(keyPre(), ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param redisHashKey 数据库键
|
||||
* @return ID
|
||||
*/
|
||||
@Override
|
||||
public String decodeHashKey (String redisHashKey) {
|
||||
return redisHashKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过键获取所有的hash数据
|
||||
* @param key 键
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, ProjectSkuInfo> getData (Long key) {
|
||||
return projectSkuData.getData(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过缓存键和hash键获取hash值
|
||||
* @param key 缓存键
|
||||
* @param hashKey hash键
|
||||
*
|
||||
* @return hash值
|
||||
*/
|
||||
@Override
|
||||
public ProjectSkuInfo getData (Long key, String hashKey) {
|
||||
return projectSkuData.getData(key, hashKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认值
|
||||
*/
|
||||
@Override
|
||||
public Map<String, ProjectSkuInfo> defaultValue () {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectSkuInfo defaultHashValue () {
|
||||
return new ProjectSkuInfo();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.muyu.product.cache;
|
||||
|
||||
import com.muyu.common.cache.abs.AtomicSequenceCacheAbs;
|
||||
import com.muyu.common.core.text.Convert;
|
||||
import com.muyu.product.cache.datasource.ProjectSkuStockData;
|
||||
import com.muyu.product.cache.key.SkuStockKey;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author yangle
|
||||
* @description: 商品SKU库存缓存
|
||||
* @Date 2024-3-29 下午 03:06
|
||||
*/
|
||||
@Service
|
||||
public class ProjectSkuStockCache extends AtomicSequenceCacheAbs<SkuStockKey> {
|
||||
|
||||
@Autowired
|
||||
private ProjectSkuStockData projectSkuStockData;
|
||||
|
||||
/**
|
||||
* key前缀
|
||||
*
|
||||
* @return key前缀
|
||||
*/
|
||||
@Override
|
||||
public String keyPre () {
|
||||
return "project:sku:stock:";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编码
|
||||
* @param skuStockKey ID
|
||||
* @return 键
|
||||
*/
|
||||
@Override
|
||||
public String encode (SkuStockKey skuStockKey) {
|
||||
return keyPre() + skuStockKey.getProjectId() + ":" + skuStockKey.getSku();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getData (SkuStockKey key) {
|
||||
return projectSkuStockData.getData(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param redisKey 数据库键
|
||||
* @return ID
|
||||
*/
|
||||
@Override
|
||||
public SkuStockKey decode (String redisKey) {
|
||||
String[] split = redisKey.replace(keyPre(), "").split(":");
|
||||
return SkuStockKey.builder()
|
||||
.projectId(Convert.toLong(split[0]))
|
||||
.sku(split[1])
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
package com.muyu.product.cache;
|
||||
package com.muyu.product.cache.datasource;
|
||||
|
||||
import com.muyu.product.domain.ProjectInfo;
|
||||
|
||||
/**
|
||||
* 缓存数据获取 ProjectInfoData
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/3/27
|
||||
* @author yangle
|
||||
* @description: 缓存数据获取
|
||||
* @Date 2024-3-27 下午 03:34
|
||||
*/
|
||||
public interface ProjectInfoData {
|
||||
|
||||
/**
|
||||
* 从数据库获取数据
|
||||
* @param key ID
|
||||
* @return 缓存对象
|
||||
*/
|
||||
public ProjectInfo getData(Long key);
|
||||
public ProjectInfo getData (Long key);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.product.cache.datasource;
|
||||
|
||||
import com.muyu.product.domain.ProjectSkuInfo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author yangle
|
||||
* @description: 商品SKU数据库读取
|
||||
* @Date 2024-4-1 上午 11:35
|
||||
*/
|
||||
public interface ProjectSkuData {
|
||||
|
||||
/**
|
||||
* 通过键获取所有的hash数据
|
||||
* @param projectId 商品ID
|
||||
* @return
|
||||
*/
|
||||
public Map<String, ProjectSkuInfo> getData (Long projectId) ;
|
||||
|
||||
/**
|
||||
* 通过缓存键和hash键获取hash值
|
||||
* @param projectId 商品ID
|
||||
* @param projectSku 商品SKU
|
||||
*
|
||||
* @return hash值
|
||||
*/
|
||||
public ProjectSkuInfo getData (Long projectId, String projectSku);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.muyu.product.cache.datasource;
|
||||
|
||||
import com.muyu.product.cache.key.SkuStockKey;
|
||||
|
||||
/**
|
||||
* @author yangle
|
||||
* @description: SKU库存
|
||||
* @Date 2024-4-2 上午 10:52
|
||||
*/
|
||||
public interface ProjectSkuStockData {
|
||||
|
||||
public Long getData (SkuStockKey key) ;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.product.cache.key;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author yangle
|
||||
* @description: 商品SKU库存Key
|
||||
* @Date 2024-4-2 上午 10:41
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SkuStockKey {
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
private Long projectId;
|
||||
|
||||
/**
|
||||
* sku
|
||||
*/
|
||||
private String sku;
|
||||
}
|
|
@ -23,5 +23,9 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-shop-cart-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 属性与组中间对象 as_attribute_group
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 品牌商品中间对象 as_brand_project
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -16,7 +16,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 品类属性中间对象 as_category_attribute
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -16,7 +16,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 品类属性组中间对象 as_category_attribute_group
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -16,7 +16,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 品类品牌中间对象 as_category_brand
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -20,7 +20,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品属性对象 as_product_attribute_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -20,7 +20,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 属性组对象 attribute_group
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -21,7 +21,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品属性对象 attribute_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -18,7 +18,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 品牌信息对象 brand_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.util.function.Supplier;
|
|||
/**
|
||||
* 品类信息对象 category_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -18,7 +18,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品评论对象 comment_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -18,7 +18,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 评论点赞对象 comment_like_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.util.function.Supplier;
|
|||
/**
|
||||
* 商品信息对象 project_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -22,7 +22,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品SKU对象 project_sku_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.util.function.Supplier;
|
|||
/**
|
||||
* 规格详情对象 rule_attr_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.util.function.Supplier;
|
|||
/**
|
||||
* 商品规格对象 rule_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.muyu.product.domain.base;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @author yangle
|
||||
* @description: attribute基础方法
|
||||
* @Date 2024-3-1 下午 02:28
|
||||
*/
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @author yangle
|
||||
* @description: 属性组添加模型
|
||||
* @Date 2024-2-28 下午 03:16
|
||||
*/
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.util.function.Supplier;
|
|||
/**
|
||||
* 品类信息对象 category_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @author yangle
|
||||
* @description: 规格属性,添加模型
|
||||
* @Date 2024-3-4 下午 02:28
|
||||
*/
|
||||
|
|
|
@ -12,7 +12,7 @@ import lombok.experimental.SuperBuilder;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @author yangle
|
||||
* @description: 规格保存模型
|
||||
* @Date 2024-3-4 下午 02:33
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package com.muyu.product.domain.model;
|
||||
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 添加购物车模型 ShoppingCardAdd
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/3/31
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ShoppingCardModel extends BaseEntity {
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Integer projectId;
|
||||
|
||||
/**
|
||||
* 商品属性
|
||||
*/
|
||||
private String projectSku;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
private Integer userId;
|
||||
|
||||
/**
|
||||
* 库存
|
||||
*/
|
||||
private Integer num;
|
||||
|
||||
/**
|
||||
* 选中状态
|
||||
*/
|
||||
private Integer isSelected;
|
||||
|
||||
}
|
|
@ -14,7 +14,7 @@ import java.util.function.Function;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @author yangle
|
||||
* @description: 共有属性组
|
||||
* @Date 2024-3-6 下午 02:29
|
||||
*/
|
||||
|
|
|
@ -9,7 +9,7 @@ import lombok.NoArgsConstructor;
|
|||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @author yangle
|
||||
* @description: 共有属性
|
||||
* @Date 2024-3-6 下午 02:30
|
||||
*/
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 属性组对象 attribute_group
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -13,7 +13,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 属性组对象 attribute_group
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 属性组对象 attribute_group
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -13,7 +13,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品属性对象 attribute_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -13,7 +13,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品属性对象 attribute_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -13,7 +13,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品属性对象 attribute_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 品牌信息对象 brand_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 品牌信息对象 brand_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 品牌信息对象 brand_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
/**
|
||||
* 品类信息对象 category_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.TreeEntity;
|
|||
/**
|
||||
* 品类信息对象 category_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
/**
|
||||
* 品类信息对象 category_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品评论对象 comment_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品评论对象 comment_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品评论对象 comment_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 评论点赞对象 comment_like_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 评论点赞对象 comment_like_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 评论点赞对象 comment_like_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.util.List;
|
|||
/**
|
||||
* 商品信息对象 project_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品信息对象 project_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.util.List;
|
|||
/**
|
||||
* 商品信息对象 project_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品SKU对象 project_sku_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品SKU对象 project_sku_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品SKU对象 project_sku_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 规格详情对象 rule_attr_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 规格详情对象 rule_attr_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 规格详情对象 rule_attr_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品规格对象 rule_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
|||
/**
|
||||
* 商品规格对象 rule_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||
/**
|
||||
* 商品规格对象 rule_info
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Data
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @author yangle
|
||||
* @description: 属性组列表对象
|
||||
* @Date 2024-2-28 下午 04:15
|
||||
*/
|
||||
|
|
|
@ -9,7 +9,7 @@ import lombok.experimental.SuperBuilder;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @author yangle
|
||||
* @description: 商品类别公共元素
|
||||
* @Date 2024-3-6 下午 02:25
|
||||
*/
|
||||
|
|
|
@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @author yangle
|
||||
* @description: 类别父通用元素
|
||||
* @Date 2024-3-1 上午 11:02
|
||||
*/
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @author yangle
|
||||
* @description: 规格返回结果集
|
||||
* @Date 2024-3-4 下午 04:08
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package com.muyu.product.domain.resp;
|
||||
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import com.muyu.shop.cart.domain.CartInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 添加购物车模型 ShoppingCardAdd
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/3/31
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ShoppingCardResp extends BaseEntity {
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Integer projectId;
|
||||
|
||||
/**
|
||||
* 商品属性
|
||||
*/
|
||||
private String projectSku;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
private Integer userId;
|
||||
|
||||
/**
|
||||
* 库存
|
||||
*/
|
||||
private Integer num;
|
||||
|
||||
/**
|
||||
* 选中状态
|
||||
*/
|
||||
private Integer isSelected;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
|
||||
}
|
|
@ -18,11 +18,12 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!--商品模块 缓存 依赖-->
|
||||
<!-- 商品模块 缓存 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-product-cache</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 商品模块 common 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
|
@ -89,18 +90,6 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-swagger</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-product-cache</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-product-cache</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @author yangle
|
||||
* @description: 商品启动类
|
||||
* @Date 2024-2-26 下午 04:07
|
||||
*/
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
package com.muyu.product.cache;
|
||||
package com.muyu.product.cache.impl;
|
||||
|
||||
import com.muyu.product.cache.datasource.ProjectInfoData;
|
||||
import com.muyu.product.domain.ProjectInfo;
|
||||
import com.muyu.product.service.ProjectInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 缓存数据获取 ProjectInfoDataImpl
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/3/27
|
||||
* @author yangle
|
||||
* @description: 缓存数据获取
|
||||
* @Date 2024-3-27 下午 03:37
|
||||
*/
|
||||
@Service
|
||||
public class ProjectInfoDataImpl implements ProjectInfoData{
|
||||
public class ProjectInfoDataImpl implements ProjectInfoData {
|
||||
|
||||
@Autowired
|
||||
private ProjectInfoService projectInfoService;
|
||||
|
||||
|
@ -22,7 +23,7 @@ public class ProjectInfoDataImpl implements ProjectInfoData{
|
|||
* @return 缓存对象
|
||||
*/
|
||||
@Override
|
||||
public ProjectInfo getData(Long key){
|
||||
public ProjectInfo getData (Long key) {
|
||||
return projectInfoService.getById(key);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.muyu.product.cache.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.muyu.product.cache.datasource.ProjectSkuData;
|
||||
import com.muyu.product.domain.ProjectSkuInfo;
|
||||
import com.muyu.product.service.ProjectSkuInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author yangle
|
||||
* @description: 商品SKU实现类
|
||||
* @Date 2024-4-1 上午 11:38
|
||||
*/
|
||||
@Service
|
||||
public class ProjectSkuDataImpl implements ProjectSkuData {
|
||||
|
||||
@Autowired
|
||||
private ProjectSkuInfoService projectSkuInfoService;
|
||||
|
||||
/**
|
||||
* 通过键获取所有的hash数据
|
||||
* @param projectId 商品ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, ProjectSkuInfo> getData (Long projectId) {
|
||||
LambdaQueryWrapper<ProjectSkuInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ProjectSkuInfo::getProjectId, projectId);
|
||||
List<ProjectSkuInfo> projectSkuInfoList = projectSkuInfoService.list(queryWrapper);
|
||||
return projectSkuInfoList.stream()
|
||||
.collect(Collectors.toMap(ProjectSkuInfo::getSku, projectSkuInfo -> projectSkuInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过缓存键和hash键获取hash值
|
||||
* @param projectId 商品ID
|
||||
* @param projectSku 商品SKU
|
||||
* @return hash值
|
||||
*/
|
||||
@Override
|
||||
public ProjectSkuInfo getData (Long projectId, String projectSku) {
|
||||
LambdaQueryWrapper<ProjectSkuInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ProjectSkuInfo::getProjectId, projectId);
|
||||
queryWrapper.eq(ProjectSkuInfo::getSku, projectSku);
|
||||
return projectSkuInfoService.getOne(queryWrapper);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.muyu.product.cache.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.muyu.product.cache.datasource.ProjectSkuStockData;
|
||||
import com.muyu.product.cache.key.SkuStockKey;
|
||||
import com.muyu.product.domain.ProjectSkuInfo;
|
||||
import com.muyu.product.service.ProjectSkuInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author yangle
|
||||
* @description: sku库存实现类
|
||||
* @Date 2024-4-2 上午 10:53
|
||||
*/
|
||||
@Service
|
||||
public class ProjectSkuStockDataImpl implements ProjectSkuStockData {
|
||||
|
||||
@Autowired
|
||||
private ProjectSkuInfoService projectSkuInfoService;
|
||||
|
||||
@Override
|
||||
public Long getData (SkuStockKey key) {
|
||||
LambdaQueryWrapper<ProjectSkuInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ProjectSkuInfo::getProjectId, key.getProjectId());
|
||||
queryWrapper.eq(ProjectSkuInfo::getSku, key.getSku());
|
||||
ProjectSkuInfo projectSkuInfo = projectSkuInfoService.getOne(queryWrapper);
|
||||
return projectSkuInfo.getStock();
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
|||
/**
|
||||
* 属性组Controller
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Api(tags = "属性组")
|
||||
|
|
|
@ -29,7 +29,7 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
|||
/**
|
||||
* 商品属性Controller
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Api(tags = "商品属性")
|
||||
|
|
|
@ -30,7 +30,7 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
|||
/**
|
||||
* 品牌信息Controller
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Api(tags = "品牌信息")
|
||||
|
|
|
@ -36,7 +36,7 @@ import com.muyu.product.service.CategoryInfoService;
|
|||
/**
|
||||
* 品类信息Controller
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Api(tags = "品类信息")
|
||||
|
|
|
@ -29,7 +29,7 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
|||
/**
|
||||
* 商品评论Controller
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Api(tags = "商品评论")
|
||||
|
|
|
@ -29,7 +29,7 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
|||
/**
|
||||
* 评论点赞Controller
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Api(tags = "评论点赞")
|
||||
|
|
|
@ -6,14 +6,11 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.muyu.product.domain.AsProductAttributeInfo;
|
||||
import com.muyu.product.domain.ProjectSkuInfo;
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
import com.muyu.product.domain.model.ProductSkuModel;
|
||||
import com.muyu.product.domain.model.ProjectAddModel;
|
||||
import com.muyu.product.domain.resp.ProjectDetailResp;
|
||||
import com.muyu.product.service.AsProductAttributeInfoService;
|
||||
import com.muyu.product.service.ProjectSkuInfoService;
|
||||
import io.swagger.annotations.*;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
@ -39,7 +36,7 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
|||
/**
|
||||
* 商品信息Controller
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Api(tags = "商品信息")
|
||||
|
@ -162,4 +159,8 @@ public class ProjectInfoController extends BaseController {
|
|||
projectInfoService.del(ids);
|
||||
return toAjax(projectInfoService.removeBatchByIds(ids));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
|||
/**
|
||||
* 商品SKUController
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Api(tags = "商品SKU")
|
||||
|
|
|
@ -29,7 +29,7 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
|||
/**
|
||||
* 规格详情Controller
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Api(tags = "规格详情")
|
||||
|
|
|
@ -32,7 +32,7 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
|||
/**
|
||||
* 商品规格Controller
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Api(tags = "商品规格")
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.muyu.product.domain.AsAttributeGroup;
|
|||
/**
|
||||
* 属性与组中间Mapper接口
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
public interface AsAttributeGroupMapper extends BaseMapper<AsAttributeGroup> {
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.muyu.product.domain.AsBrandProject;
|
|||
/**
|
||||
* 品牌商品中间Mapper接口
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
public interface AsBrandProjectMapper extends BaseMapper<AsBrandProject> {
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.muyu.product.domain.AsCategoryAttributeGroup;
|
|||
/**
|
||||
* 品类属性组中间Mapper接口
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
public interface AsCategoryAttributeGroupMapper extends BaseMapper<AsCategoryAttributeGroup> {
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.muyu.product.domain.AsCategoryAttribute;
|
|||
/**
|
||||
* 品类属性中间Mapper接口
|
||||
*
|
||||
* @author DongZeLiang
|
||||
* @author yangle
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
public interface AsCategoryAttributeMapper extends BaseMapper<AsCategoryAttribute> {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue