Compare commits

..

13 Commits

Author SHA1 Message Date
Yunfei Du c58caef95f 配置 2024-03-31 09:43:02 +08:00
Yunfei Du 576ce1dac8 Merge remote-tracking branch 'origin/dev' into dev 2024-03-30 11:47:00 +08:00
DongZeLiang acc59fd99b 初始化hash缓存-put 2024-03-30 11:46:46 +08:00
Yunfei Du fdf531ee56 Merge remote-tracking branch 'origin/dev' into dev 2024-03-30 11:30:27 +08:00
DongZeLiang bee6f5678c 初始化hash缓存-get 2024-03-30 11:30:04 +08:00
Yunfei Du 37edeb8aa9 Merge remote-tracking branch 'origin/dev' into dev 2024-03-30 11:21:05 +08:00
DongZeLiang 2bc592c87e 初始化hash缓存-get 2024-03-30 11:19:52 +08:00
DongZeLiang e1d039804c 初始化hash缓存-get 2024-03-30 11:16:04 +08:00
DongZeLiang 41d4175d23 初始化hash缓存 2024-03-30 10:53:47 +08:00
Yunfei Du 5cd96727fd Merge remote-tracking branch 'origin/dev' into dev 2024-03-29 19:42:40 +08:00
DongZeLiang c76dfb1228 初始化hash缓存 2024-03-29 19:41:55 +08:00
Yunfei Du 2618c29454 Merge remote-tracking branch 'origin/dev' into dev 2024-03-29 16:29:48 +08:00
DongZeLiang 39b92736fa 初始化购物车 2024-03-29 15:02:26 +08:00
40 changed files with 1303 additions and 26 deletions

View File

@ -15,9 +15,13 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
config:
# 配置中心地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -1,32 +1,13 @@
package com.muyu.common.cache;
import com.muyu.common.cache.decoration.DecorationKey;
/**
* @author DongZl
* @description:
* @Date 2024-3-26 03:25
*/
public interface Cache <K, V> {
/**
* key
* @return key
*/
public String keyPre();
/**
*
* @param key ID
* @return
*/
public String encode(K key);
/**
*
* @param redisKey
* @return ID
*/
public K decode(String redisKey);
public interface Cache <K, V> extends DecorationKey<K> {
/**
* Keyvalue

View File

@ -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 DongZl
* @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);
/**
* Keymap
* @param key
* @return Map
*/
public Map<HK, HV> get(K key);
/**
* hashKeyhashValue
* @param key
* @param hashKey hash
* @return hash
*/
public HV get(K key, HK hashKey);
/**
* hashKeyhashValue
* @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);
/**
* redishash
* @param key redis
* @param hashKey hash
*/
public void remove(K key, HK hashKey);
}

View File

@ -0,0 +1,170 @@
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.*;
import java.util.function.Function;
/**
* @author DongZl
* @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();
}
/**
* Keymap
* @param key
* @return Map
*/
@Override
public Map<HK, HV> get (K key) {
return decodeMap(redisService.getCacheMap(encode(key)));
}
/**
* hashKeyhashValue
*
* @param key
* @param hashKey hash
*
* @return hash
*/
@Override
public HV get (K key, HK hashKey) {
return redisService.getCacheMapValue(encode(key), encodeHashKey(hashKey));
}
/**
* hashKeyhashValue
*
* @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) {
}
/**
*
*
* @param key redis
* @param hashKey hash
* @param hashValue hash
*/
@Override
public void put (K key, HK hashKey, HV hashValue) {
}
/**
* redis
*
* @param key hash
*/
@Override
public void remove (K key) {
}
/**
* redishash
*
* @param key redis
* @param hashKey hash
*/
@Override
public void remove (K key, HK 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;
}
}

View File

@ -0,0 +1,30 @@
package com.muyu.common.cache.decoration;
/**
* @author DongZl
* @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);
}

View File

@ -229,7 +229,7 @@ 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);
}

View File

@ -15,9 +15,13 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
config:
# 配置中心地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,9 +15,13 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
config:
# 配置中心地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,9 +15,13 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
config:
# 配置中心地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,9 +15,13 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
config:
# 配置中心地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -1,11 +1,17 @@
package com.muyu.product.cache;
import com.muyu.common.cache.HashCache;
import com.muyu.common.cache.abs.CacheAbs;
import com.muyu.common.core.text.Convert;
import com.muyu.product.cache.datasource.ProjectInfoData;
import com.muyu.product.domain.ProjectInfo;
import com.muyu.product.domain.ProjectSkuInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
/**
* @author DongZl
@ -15,8 +21,21 @@ import org.springframework.stereotype.Service;
@Component
public class ProjectInfoCache extends CacheAbs<Long, ProjectInfo> {
public static void main (String[] args) {
Long projectId = 10L;
HashCache<Long, Long, ProjectSkuInfo> hashCache = null;
List<ProjectSkuInfo> projectSkuInfoList = new ArrayList<>(){{
add(new ProjectSkuInfo());
add(new ProjectSkuInfo());
}};
hashCache.put(projectId, projectSkuInfoList, ProjectSkuInfo::getProjectId);
Long[] longArr = new Long[]{10L,11L,12L,13L,14L,15L};
hashCache.get(projectId, longArr);
}
@Autowired
private ProjectInfoData projectInfoData;
/**
* key
*

View File

@ -0,0 +1,9 @@
package com.muyu.product.cache;
/**
* @author DongZl
* @description: sku
* @Date 2024-3-29 03:06
*/
public class ProjectSkuCache {
}

View File

@ -0,0 +1,9 @@
package com.muyu.product.cache;
/**
* @author DongZl
* @description: SKU
* @Date 2024-3-29 03:06
*/
public class ProjectSkuStockCache {
}

View File

@ -1,4 +1,4 @@
package com.muyu.product.cache;
package com.muyu.product.cache.datasource;
import com.muyu.product.domain.ProjectInfo;

View File

@ -1,6 +1,6 @@
package com.muyu.product.cache.impl;
import com.muyu.product.cache.ProjectInfoData;
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;

View File

@ -15,9 +15,13 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
config:
# 配置中心地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -0,0 +1,26 @@
{ 基本信息: {
name: "",
introduction: "",
mianType: "",
parentType: "",
type: "",
image: "",
carouselImages: "",
status: "",
ruleId: "",
branId: "",
remark: ""
},
品类属性: [ {
id: "",
value: "",
} …………
],
商品规格: [ {
SKU: "",(所有的规格属性拼接而成)
"images": "",
库存: "",
价格: "",
} …………
]
}

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>muyu-shop-cart</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>muyu-shop-cart-common</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<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-core</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,105 @@
package com.muyu.shop.cart.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import io.swagger.annotations.*;
import com.muyu.common.core.annotation.Excel;
import com.muyu.shop.cart.domain.req.CartInfoQueryReq;
import com.muyu.shop.cart.domain.req.CartInfoSaveReq;
import com.muyu.shop.cart.domain.req.CartInfoEditReq;
import com.muyu.common.core.web.domain.BaseEntity;
/**
* cart_info
*
* @author DongZeLiang
* @date 2024-03-29
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("cart_info")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "CartInfo", description = "购物车")
public class CartInfo extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(value = "id",type = IdType.AUTO)
@ApiModelProperty(name = "主键", value = "主键")
private Long id;
/** 商品 */
@Excel(name = "商品")
@ApiModelProperty(name = "商品", value = "商品", required = true)
private Long projectId;
/** SKU */
@Excel(name = "SKU")
@ApiModelProperty(name = "SKU", value = "SKU", required = true)
private String projectSku;
/** 用户 */
@Excel(name = "用户")
@ApiModelProperty(name = "用户", value = "用户", required = true)
private Long userId;
/** 数量 */
@Excel(name = "数量")
@ApiModelProperty(name = "数量", value = "数量", required = true)
private Long num;
/** 是否选中 */
@Excel(name = "是否选中")
@ApiModelProperty(name = "是否选中", value = "是否选中", required = true)
private String isSelected;
/**
*
*/
public static CartInfo queryBuild( CartInfoQueryReq cartInfoQueryReq){
return CartInfo.builder()
.projectId(cartInfoQueryReq.getProjectId())
.projectSku(cartInfoQueryReq.getProjectSku())
.userId(cartInfoQueryReq.getUserId())
.num(cartInfoQueryReq.getNum())
.isSelected(cartInfoQueryReq.getIsSelected())
.build();
}
/**
*
*/
public static CartInfo saveBuild(CartInfoSaveReq cartInfoSaveReq){
return CartInfo.builder()
.projectId(cartInfoSaveReq.getProjectId())
.projectSku(cartInfoSaveReq.getProjectSku())
.userId(cartInfoSaveReq.getUserId())
.num(cartInfoSaveReq.getNum())
.isSelected(cartInfoSaveReq.getIsSelected())
.build();
}
/**
*
*/
public static CartInfo editBuild(Long id, CartInfoEditReq cartInfoEditReq){
return CartInfo.builder()
.id(id)
.projectId(cartInfoEditReq.getProjectId())
.projectSku(cartInfoEditReq.getProjectSku())
.userId(cartInfoEditReq.getUserId())
.num(cartInfoEditReq.getNum())
.isSelected(cartInfoEditReq.getIsSelected())
.build();
}
}

View File

@ -0,0 +1,46 @@
package com.muyu.shop.cart.domain.req;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import io.swagger.annotations.*;
import com.muyu.common.core.web.domain.BaseEntity;
/**
* cart_info
*
* @author DongZeLiang
* @date 2024-03-29
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "CartInfoEditReq", description = "购物车")
public class CartInfoEditReq extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 商品 */
@ApiModelProperty(name = "商品", value = "商品", required = true)
private Long projectId;
/** SKU */
@ApiModelProperty(name = "SKU", value = "SKU", required = true)
private String projectSku;
/** 用户 */
@ApiModelProperty(name = "用户", value = "用户", required = true)
private Long userId;
/** 数量 */
@ApiModelProperty(name = "数量", value = "数量", required = true)
private Long num;
/** 是否选中 */
@ApiModelProperty(name = "是否选中", value = "是否选中", required = true)
private String isSelected;
}

View File

@ -0,0 +1,46 @@
package com.muyu.shop.cart.domain.req;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import io.swagger.annotations.*;
import com.muyu.common.core.web.domain.BaseEntity;
/**
* cart_info
*
* @author DongZeLiang
* @date 2024-03-29
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "CartInfoQueryReq", description = "购物车")
public class CartInfoQueryReq extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 商品 */
@ApiModelProperty(name = "商品", value = "商品")
private Long projectId;
/** SKU */
@ApiModelProperty(name = "SKU", value = "SKU")
private String projectSku;
/** 用户 */
@ApiModelProperty(name = "用户", value = "用户")
private Long userId;
/** 数量 */
@ApiModelProperty(name = "数量", value = "数量")
private Long num;
/** 是否选中 */
@ApiModelProperty(name = "是否选中", value = "是否选中")
private String isSelected;
}

View File

@ -0,0 +1,56 @@
package com.muyu.shop.cart.domain.req;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import io.swagger.annotations.*;
import com.muyu.common.core.web.domain.BaseEntity;
/**
* cart_info
*
* @author DongZeLiang
* @date 2024-03-29
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "CartInfoSaveReq", description = "购物车")
public class CartInfoSaveReq extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 主键 */
@ApiModelProperty(name = "主键", value = "主键")
private Long id;
/** 商品 */
@ApiModelProperty(name = "商品", value = "商品", required = true)
private Long projectId;
/** SKU */
@ApiModelProperty(name = "SKU", value = "SKU", required = true)
private String projectSku;
/** 用户 */
@ApiModelProperty(name = "用户", value = "用户", required = true)
private Long userId;
/** 数量 */
@ApiModelProperty(name = "数量", value = "数量", required = true)
private Long num;
/** 是否选中 */
@ApiModelProperty(name = "是否选中", value = "是否选中", required = true)
private String isSelected;
}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>muyu-shop-cart</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>muyu-shop-cart-remote</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 购物车模块 公共依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-shop-cart-common</artifactId>
<version>${muyu.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>muyu-shop-cart</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>muyu-shop-cart-server</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Swagger UI -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.fox.version}</version>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- MuYu Common DataSource -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-common-datasource</artifactId>
</dependency>
<!-- MuYu Common DataScope -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-common-datascope</artifactId>
</dependency>
<!-- MuYu Common Log -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-common-log</artifactId>
</dependency>
<!-- MuYu Common Swagger -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-common-swagger</artifactId>
</dependency>
<!-- 购物车模块 公共依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-shop-cart-common</artifactId>
<version>${muyu.version}</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 加入maven deploy插件当在deploy时忽略些model-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,22 @@
package com.muyu.shop.cart;
import com.muyu.common.security.annotation.EnableCustomConfig;
import com.muyu.common.security.annotation.EnableMyFeignClients;
import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
*
*
* @author muyu
*/
@EnableCustomConfig
@EnableCustomSwagger2
@EnableMyFeignClients
@SpringBootApplication
public class MuYuShopCartApplication {
public static void main (String[] args) {
SpringApplication.run(MuYuShopCartApplication.class, args);
}
}

View File

@ -0,0 +1,111 @@
package com.muyu.shop.cart.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.shop.cart.domain.CartInfo;
import com.muyu.shop.cart.domain.req.CartInfoQueryReq;
import com.muyu.shop.cart.domain.req.CartInfoSaveReq;
import com.muyu.shop.cart.domain.req.CartInfoEditReq;
import com.muyu.shop.cart.service.CartInfoService;
import com.muyu.common.core.web.page.TableDataInfo;
/**
* Controller
*
* @author DongZeLiang
* @date 2024-03-29
*/
@Api(tags = "购物车")
@RestController
@RequestMapping("/Info")
public class CartInfoController extends BaseController {
@Autowired
private CartInfoService cartInfoService;
/**
*
*/
@ApiOperation("获取购物车列表")
@RequiresPermissions("shopCart:Info:list")
@GetMapping("/list")
public Result<TableDataInfo<CartInfo>> list(CartInfoQueryReq cartInfoQueryReq) {
startPage();
List<CartInfo> list = cartInfoService.list(CartInfo.queryBuild(cartInfoQueryReq));
return getDataTable(list);
}
/**
*
*/
@ApiOperation("导出购物车列表")
@RequiresPermissions("shopCart:Info:export")
@Log(title = "购物车", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, CartInfo cartInfo) {
List<CartInfo> list = cartInfoService.list(cartInfo);
ExcelUtil<CartInfo> util = new ExcelUtil<CartInfo>(CartInfo.class);
util.exportExcel(response, list, "购物车数据");
}
/**
*
*/
@ApiOperation("获取购物车详细信息")
@RequiresPermissions("shopCart:Info:query")
@GetMapping(value = "/{id}")
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
public Result<CartInfo> getInfo(@PathVariable("id") Long id) {
return Result.success(cartInfoService.getById(id));
}
/**
*
*/
@RequiresPermissions("shopCart:Info:add")
@Log(title = "购物车", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation("新增购物车")
public Result<String> add(@RequestBody CartInfoSaveReq cartInfoSaveReq) {
return toAjax(cartInfoService.save(CartInfo.saveBuild(cartInfoSaveReq)));
}
/**
*
*/
@RequiresPermissions("shopCart:Info:edit")
@Log(title = "购物车", businessType = BusinessType.UPDATE)
@PutMapping("/{id}")
@ApiOperation("修改购物车")
public Result<String> edit(@PathVariable Long id, @RequestBody CartInfoEditReq cartInfoEditReq) {
return toAjax(cartInfoService.updateById(CartInfo.editBuild(id,cartInfoEditReq)));
}
/**
*
*/
@RequiresPermissions("shopCart:Info:remove")
@Log(title = "购物车", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
@ApiOperation("删除购物车")
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
public Result<String> remove(@PathVariable List<Long> ids) {
return toAjax(cartInfoService.removeBatchByIds(ids));
}
}

View File

@ -0,0 +1,15 @@
package com.muyu.shop.cart.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.shop.cart.domain.CartInfo;
/**
* Mapper
*
* @author DongZeLiang
* @date 2024-03-29
*/
public interface CartInfoMapper extends BaseMapper<CartInfo> {
}

View File

@ -0,0 +1,22 @@
package com.muyu.shop.cart.service;
import java.util.List;
import com.muyu.shop.cart.domain.CartInfo;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* Service
*
* @author DongZeLiang
* @date 2024-03-29
*/
public interface CartInfoService extends IService<CartInfo> {
/**
*
*
* @param cartInfo
* @return
*/
public List<CartInfo> list(CartInfo cartInfo);
}

View File

@ -0,0 +1,61 @@
package com.muyu.shop.cart.service.impl;
import java.util.List;
import com.muyu.common.core.utils.ObjUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.muyu.shop.cart.mapper.CartInfoMapper;
import com.muyu.shop.cart.domain.CartInfo;
import com.muyu.shop.cart.service.CartInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
/**
* Service
*
* @author DongZeLiang
* @date 2024-03-29
*/
@Slf4j
@Service
public class CartInfoServiceImpl extends ServiceImpl<CartInfoMapper, CartInfo> implements CartInfoService {
/**
*
*
* @param cartInfo
* @return
*/
@Override
public List<CartInfo> list(CartInfo cartInfo) {
LambdaQueryWrapper<CartInfo> queryWrapper = new LambdaQueryWrapper<>();
if (ObjUtils.notNull(cartInfo.getProjectId())){
queryWrapper.eq(CartInfo::getProjectId, cartInfo.getProjectId());
}
if (ObjUtils.notNull(cartInfo.getProjectSku())){
queryWrapper.eq(CartInfo::getProjectSku, cartInfo.getProjectSku());
}
if (ObjUtils.notNull(cartInfo.getUserId())){
queryWrapper.eq(CartInfo::getUserId, cartInfo.getUserId());
}
if (ObjUtils.notNull(cartInfo.getNum())){
queryWrapper.eq(CartInfo::getNum, cartInfo.getNum());
}
if (ObjUtils.notNull(cartInfo.getIsSelected())){
queryWrapper.eq(CartInfo::getIsSelected, cartInfo.getIsSelected());
}
return list(queryWrapper);
}
}

View File

@ -0,0 +1,2 @@
Spring Boot Version: ${spring-boot.version}
Spring Application Name: ${spring.application.name}

View File

@ -0,0 +1,32 @@
# Tomcat
server:
port: 9506
# Spring
spring:
application:
# 应用名称
name: muyu-shop-cart
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
config:
# 配置中心地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
logging:
level:
com.muyu.shop.cart.mapper: DEBUG

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="logs/muyu-system"/>
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.muyu" level="info"/>
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn"/>
<root level="info">
<appender-ref ref="console"/>
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info"/>
<appender-ref ref="file_error"/>
</root>
</configuration>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.shop.cart.mapper.CartInfoMapper">
<resultMap type="com.muyu.shop.cart.domain.CartInfo" id="CartInfoResult">
<result property="id" column="id" />
<result property="projectId" column="project_id" />
<result property="projectSku" column="project_sku" />
<result property="userId" column="user_id" />
<result property="num" column="num" />
<result property="isSelected" column="is_selected" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectCartInfoVo">
select id, project_id, project_sku, user_id, num, is_selected, remark, create_by, create_time, update_by, update_time from cart_info
</sql>
</mapper>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>muyu-modules</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>muyu-shop-cart</artifactId>
<packaging>pom</packaging>
<modules>
<module>muyu-shop-cart-common</module>
<module>muyu-shop-cart-remote</module>
<module>muyu-shop-cart-server</module>
</modules>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -15,9 +15,13 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
config:
# 配置中心地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -14,6 +14,7 @@
<module>muyu-job</module>
<module>muyu-file</module>
<module>muyu-product</module>
<module>muyu-shop-cart</module>
</modules>
<artifactId>muyu-modules</artifactId>

View File

@ -15,9 +15,13 @@ spring:
discovery:
# 服务注册地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
config:
# 配置中心地址
server-addr: 111.229.102.61:8848
#命名空间
namespace: muyu
# 配置文件格式
file-extension: yml
# 共享配置

14
pom.xml
View File

@ -234,6 +234,20 @@
<version>${muyu.version}</version>
</dependency>
<!-- 购物车模块 公共依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-shop-cart-common</artifactId>
<version>${muyu.version}</version>
</dependency>
<!-- 购物车模块 远程客户端 依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-shop-cart-remote</artifactId>
<version>${muyu.version}</version>
</dependency>
</dependencies>
</dependencyManagement>