商品购物车初始化

dev
Wang XinLong 2024-03-29 19:04:56 +08:00
parent a6ef7feb5e
commit bf10f0c2d8
29 changed files with 1128 additions and 0 deletions

View File

@ -0,0 +1,33 @@
<?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</artifactId>
<version>3.6.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>muyu-common-cache</artifactId>
<description>
muyu-common-cache缓存基准
</description>
<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>
<!-- common 缓存 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-common-redis</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,43 @@
package com.muyu.common.cache;
public interface Cache<K, V> {
/**
* key
*/
public String keyPre();
/**
*
*/
public String encode(K key);
/**
*
*/
public K decode(String redisKey);
/**
* keyvalue
*/
public V get(K key);
/**
* /
*/
public void put(K key, V value);
/**
*
*/
public void remove(K key);
/**
*
*/
public void refreshTime(K key);
/**
*
*/
public void refreshData(K key);
}

View File

@ -0,0 +1,97 @@
package com.muyu.common.cache.abs;
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;
public abstract class CacheAbs<K, V> implements Cache<K, V> {
@Autowired
private RedisService redisService;
/**
*
*
* @param key ID
* @return
*/
@Override
public String encode(K key) {
return keyPre() + key;
}
/**
* keyvalue
*
* @param key
* @return
*/
@Override
public V get(K key) {
V value = redisService.getCacheObject(encode(key));
if (value == null) {
value = getData(key);
if (value == null) {
value = defaultValue();
}
}
this.put(key, value);
return value;
}
/**
* /
*
* @param key
* @param value
*/
@Override
public void put(K key, V value) {
this.redisService.setCacheObject(encode(key), value);
}
/**
*
*
* @param key
*/
@Override
public void remove(K key) {
this.redisService.deleteObject(encode(key));
}
/**
*
*
* @param key
*/
@Override
public void refreshTime(K key) {
this.redisService.expire(encode(key), 60, TimeUnit.SECONDS);
}
/**
*
*
* @param key
*/
@Override
public void refreshData(K key) {
this.put(key, getData(key));
}
/**
*
*
* @param key ID
* @return
*/
public abstract V getData(K key);
/**
*
*/
public abstract V defaultValue();
}

View File

@ -18,6 +18,7 @@
<module>muyu-common-datascope</module>
<module>muyu-common-datasource</module>
<module>muyu-common-system</module>
<module>muyu-common-cache</module>
</modules>
<artifactId>muyu-common</artifactId>

View File

@ -0,0 +1,35 @@
<?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-product</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>muyu-product-cache</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-cache</artifactId>
</dependency>
<!-- 商品模块 common 依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-product-common</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,52 @@
package com.muyu.product.cache;
import com.muyu.common.cache.abs.CacheAbs;
import com.muyu.common.core.text.Convert;
import com.muyu.product.domain.ProjectInfo;
import org.springframework.beans.factory.annotation.Autowired;
public class ProjectInfoCache extends CacheAbs<Long, ProjectInfo> {
@Autowired
private ProjectInfoData projectInfoData;
/**
* key
*
* @return key
*/
@Override
public String keyPre() {
return "project:info:";
}
/**
*
*
* @param redisKey
* @return ID
*/
@Override
public Long decode(String redisKey) {
return Convert.toLong(redisKey.replace(keyPre(), ""), 0L);
}
/**
*
*
* @param key ID
* @return
*/
@Override
public ProjectInfo getData(Long key) {
return projectInfoData.getData(key);
}
/**
*
*/
@Override
public ProjectInfo defaultValue() {
return new ProjectInfo();
}
}

View File

@ -0,0 +1,14 @@
package com.muyu.product.cache;
import com.muyu.product.domain.ProjectInfo;
public interface ProjectInfoData {
/**
*
* @param key ID
* @return
*/
public ProjectInfo getData(Long key);
}

View File

@ -18,6 +18,12 @@
</properties>
<dependencies>
<!-- 商品模块 缓存 依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-product-cache</artifactId>
</dependency>
<!-- 商品模块 common 依赖 -->
<dependency>
<groupId>com.muyu</groupId>

View File

@ -242,22 +242,28 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
public ProjectDetailResp getDetailInfo(Long id) {
// 商品信息获取
ProjectInfo projectInfo = this.getById(id);
// 品牌信息
BrandInfo brandInfo = this.brandInfoService.getById(projectInfo.getBrandId());
// 品类集合
List<CategoryInfo> categoryInfoList = this.categoryInfoService.listByIds(new ArrayList<>() {{
add(projectInfo.getMainType());
add(projectInfo.getParentType());
add(projectInfo.getType());
}});
// 商品sku集合
List<ProjectSkuInfo> projectSkuInfoList = this.projectSkuInfoService.list(new LambdaQueryWrapper<>() {{
eq(ProjectSkuInfo::getProjectId, id);
}});
// 商品和属性集合
List<AsProductAttributeInfo> productAttributeInfoList = this.asProductAttributeInfoService.list(new LambdaQueryWrapper<>() {{
eq(AsProductAttributeInfo::getProductId, id);
}});
// 商品规格
List<RuleAttrAddModel> ruleAttrModelList = this.ruleAttrInfoService.list(new LambdaQueryWrapper<>() {{
eq(RuleAttrInfo::getRuleId, projectInfo.getRuleId());
@ -272,6 +278,7 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
ArrayList<TemplateAttributeModel> templateAttributeList = new ArrayList<>() {{
addAll(templateAttribute.getTemplateAttributeList());
}};
// 商品属性组和商品属性的id
ArrayList<Long> notInAttributeIdList = new ArrayList<>();
List<Long> attributeGroupIdList = templateAttributeGroupList.stream()
@ -287,6 +294,7 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
if(!attributeIdList.isEmpty()){
notInAttributeIdList.addAll(attributeIdList);
}
// 添加商品的自由属性
List<AsProductAttributeInfo> productAttributeList = this.asProductAttributeInfoService.list(new LambdaQueryWrapper<>() {{
eq(AsProductAttributeInfo::getProductId, projectInfo.getId());
@ -306,6 +314,7 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
.map(TemplateAttributeModel::attributeInfoBuild)
.toList();
}
// 把自由属性添加到商品属性的集合中
if(!projectAttributeList.isEmpty()){
templateAttributeList.addAll(projectAttributeList);

View File

@ -15,6 +15,7 @@
<module>muyu-product-common</module>
<module>muyu-product-remote</module>
<module>muyu-product-server</module>
<module>muyu-product-cache</module>
</modules>
<properties>

View File

@ -0,0 +1,27 @@
<?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,106 @@
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 com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.shop.cart.domain.req.CartInfoEditReq;
import com.muyu.shop.cart.domain.req.CartInfoQueryReq;
import com.muyu.shop.cart.domain.req.CartInfoSaveReq;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* 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 com.muyu.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* 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 com.muyu.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* 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 com.muyu.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* 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,117 @@
<?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,106 @@
package com.muyu.shop.cart.controller;
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.core.web.page.TableDataInfo;
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.CartInfoEditReq;
import com.muyu.shop.cart.domain.req.CartInfoQueryReq;
import com.muyu.shop.cart.domain.req.CartInfoSaveReq;
import com.muyu.shop.cart.service.CartInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 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,14 @@
package com.muyu.shop.cart.mapper;
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,23 @@
package com.muyu.shop.cart.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.shop.cart.domain.CartInfo;
import java.util.List;
/**
* 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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.ObjUtils;
import com.muyu.shop.cart.domain.CartInfo;
import com.muyu.shop.cart.mapper.CartInfoMapper;
import com.muyu.shop.cart.service.CartInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 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,29 @@
# Tomcat
server:
port: 9506
# Spring
spring:
application:
# 应用名称
name: muyu-shop-cart
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 111.229.37.54:8848
config:
# 配置中心地址
server-addr: 111.229.37.54:8848
namespace: a7ca2016-3e34-485e-95ea-e0ea98d6c647
# 配置文件格式
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

@ -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>

28
pom.xml
View File

@ -150,6 +150,13 @@
<version>${muyu.version}</version>
</dependency>
<!-- 缓存基准模块 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-common-cache</artifactId>
<version>${muyu.version}</version>
</dependency>
<!-- 接口模块 -->
<dependency>
<groupId>com.muyu</groupId>
@ -220,6 +227,27 @@
<version>${muyu.version}</version>
</dependency>
<!-- 商品模块 缓存 依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-product-cache</artifactId>
<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>