完成支付、电子面单、模板消息队列等功能
This commit is contained in:
@ -27,6 +27,11 @@
|
||||
<artifactId>yshop-module-product-biz</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-module-member-biz</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 业务组件 -->
|
||||
<dependency>
|
||||
|
||||
@ -1,32 +1,21 @@
|
||||
package co.yixiang.yshop.module.cart.controller.admin.storecart;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.framework.common.pojo.CommonResult;
|
||||
import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import co.yixiang.yshop.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import co.yixiang.yshop.framework.operatelog.core.annotations.OperateLog;
|
||||
import static co.yixiang.yshop.framework.operatelog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.*;
|
||||
import co.yixiang.yshop.module.cart.dal.dataobject.storecart.StoreCartDO;
|
||||
import co.yixiang.yshop.module.cart.convert.storecart.StoreCartConvert;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.StoreCartPageReqVO;
|
||||
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.StoreCartRespVO;
|
||||
import co.yixiang.yshop.module.cart.service.storecart.StoreCartService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 购物车")
|
||||
@RestController
|
||||
@ -37,20 +26,6 @@ public class StoreCartController {
|
||||
@Resource
|
||||
private StoreCartService storeCartService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建购物车")
|
||||
@PreAuthorize("@ss.hasPermission('cart:store-cart:create')")
|
||||
public CommonResult<Long> createStoreCart(@Valid @RequestBody StoreCartCreateReqVO createReqVO) {
|
||||
return success(storeCartService.createStoreCart(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新购物车")
|
||||
@PreAuthorize("@ss.hasPermission('cart:store-cart:update')")
|
||||
public CommonResult<Boolean> updateStoreCart(@Valid @RequestBody StoreCartUpdateReqVO updateReqVO) {
|
||||
storeCartService.updateStoreCart(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除购物车")
|
||||
@ -61,42 +36,15 @@ public class StoreCartController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得购物车")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('cart:store-cart:query')")
|
||||
public CommonResult<StoreCartRespVO> getStoreCart(@RequestParam("id") Long id) {
|
||||
StoreCartDO storeCart = storeCartService.getStoreCart(id);
|
||||
return success(StoreCartConvert.INSTANCE.convert(storeCart));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得购物车列表")
|
||||
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
|
||||
@PreAuthorize("@ss.hasPermission('cart:store-cart:query')")
|
||||
public CommonResult<List<StoreCartRespVO>> getStoreCartList(@RequestParam("ids") Collection<Long> ids) {
|
||||
List<StoreCartDO> list = storeCartService.getStoreCartList(ids);
|
||||
return success(StoreCartConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得购物车分页")
|
||||
@PreAuthorize("@ss.hasPermission('cart:store-cart:query')")
|
||||
public CommonResult<PageResult<StoreCartRespVO>> getStoreCartPage(@Valid StoreCartPageReqVO pageVO) {
|
||||
PageResult<StoreCartDO> pageResult = storeCartService.getStoreCartPage(pageVO);
|
||||
return success(StoreCartConvert.INSTANCE.convertPage(pageResult));
|
||||
return success(storeCartService.getStoreCartPage(pageVO));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出购物车 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('cart:store-cart:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportStoreCartExcel(@Valid StoreCartExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<StoreCartDO> list = storeCartService.getStoreCartList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<StoreCartExcelVO> datas = StoreCartConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "购物车.xls", "数据", StoreCartExcelVO.class, datas);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
package co.yixiang.yshop.module.cart.controller.admin.storecart.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 购物车创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class StoreCartCreateReqVO extends StoreCartBaseVO {
|
||||
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
package co.yixiang.yshop.module.cart.controller.admin.storecart.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
|
||||
/**
|
||||
* 购物车 Excel VO
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Data
|
||||
public class StoreCartExcelVO {
|
||||
|
||||
@ExcelProperty("购物车表ID")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("用户ID")
|
||||
private Long uid;
|
||||
|
||||
@ExcelProperty("类型")
|
||||
private String type;
|
||||
|
||||
@ExcelProperty("商品ID")
|
||||
private Long productId;
|
||||
|
||||
@ExcelProperty("商品属性")
|
||||
private String productAttrUnique;
|
||||
|
||||
@ExcelProperty("商品数量")
|
||||
private Integer cartNum;
|
||||
|
||||
@ExcelProperty("0 = 未购买 1 = 已购买")
|
||||
private Integer isPay;
|
||||
|
||||
@ExcelProperty("是否为立即购买")
|
||||
private Integer isNew;
|
||||
|
||||
@ExcelProperty("拼团id")
|
||||
private Integer combinationId;
|
||||
|
||||
@ExcelProperty("秒杀产品ID")
|
||||
private Integer seckillId;
|
||||
|
||||
@ExcelProperty("砍价id")
|
||||
private Integer bargainId;
|
||||
|
||||
@ExcelProperty("添加时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
package co.yixiang.yshop.module.cart.controller.admin.storecart.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageParam;
|
||||
import java.time.LocalDateTime;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 购物车 Excel 导出 Request VO,参数和 StoreCartPageReqVO 是一致的")
|
||||
@Data
|
||||
public class StoreCartExportReqVO {
|
||||
|
||||
@Schema(description = "用户ID", example = "10667")
|
||||
private Long uid;
|
||||
|
||||
@Schema(description = "类型", example = "1")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "商品ID", example = "1696")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "商品属性")
|
||||
private String productAttrUnique;
|
||||
|
||||
@Schema(description = "商品数量")
|
||||
private Short cartNum;
|
||||
|
||||
@Schema(description = "0 = 未购买 1 = 已购买")
|
||||
private Boolean isPay;
|
||||
|
||||
@Schema(description = "是否为立即购买")
|
||||
private Boolean isNew;
|
||||
|
||||
@Schema(description = "拼团id", example = "13847")
|
||||
private Integer combinationId;
|
||||
|
||||
@Schema(description = "秒杀产品ID", example = "8790")
|
||||
private Integer seckillId;
|
||||
|
||||
@Schema(description = "砍价id", example = "21581")
|
||||
private Integer bargainId;
|
||||
|
||||
@Schema(description = "添加时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
@ -16,4 +16,10 @@ public class StoreCartRespVO extends StoreCartBaseVO {
|
||||
@Schema(description = "添加时间", required = true)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "商品名称", required = true)
|
||||
private String StoreName;
|
||||
|
||||
@Schema(description = "用户昵称", required = true)
|
||||
private String nickname;
|
||||
|
||||
}
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
package co.yixiang.yshop.module.cart.controller.admin.storecart.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 购物车更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class StoreCartUpdateReqVO extends StoreCartBaseVO {
|
||||
|
||||
@Schema(description = "购物车表ID", required = true, example = "11256")
|
||||
@NotNull(message = "购物车表ID不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
||||
@ -20,10 +20,6 @@ public interface StoreCartConvert {
|
||||
|
||||
StoreCartConvert INSTANCE = Mappers.getMapper(StoreCartConvert.class);
|
||||
|
||||
StoreCartDO convert(StoreCartCreateReqVO bean);
|
||||
|
||||
StoreCartDO convert(StoreCartUpdateReqVO bean);
|
||||
|
||||
StoreCartRespVO convert(StoreCartDO bean);
|
||||
|
||||
AppStoreCartQueryVo convert01(StoreCartDO bean);
|
||||
@ -32,6 +28,5 @@ public interface StoreCartConvert {
|
||||
|
||||
PageResult<StoreCartRespVO> convertPage(PageResult<StoreCartDO> page);
|
||||
|
||||
List<StoreCartExcelVO> convertList02(List<StoreCartDO> list);
|
||||
|
||||
}
|
||||
|
||||
@ -35,21 +35,7 @@ public interface StoreCartMapper extends BaseMapperX<StoreCartDO> {
|
||||
.orderByDesc(StoreCartDO::getId));
|
||||
}
|
||||
|
||||
default List<StoreCartDO> selectList(StoreCartExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<StoreCartDO>()
|
||||
.eqIfPresent(StoreCartDO::getUid, reqVO.getUid())
|
||||
.eqIfPresent(StoreCartDO::getType, reqVO.getType())
|
||||
.eqIfPresent(StoreCartDO::getProductId, reqVO.getProductId())
|
||||
.eqIfPresent(StoreCartDO::getProductAttrUnique, reqVO.getProductAttrUnique())
|
||||
.eqIfPresent(StoreCartDO::getCartNum, reqVO.getCartNum())
|
||||
.eqIfPresent(StoreCartDO::getIsPay, reqVO.getIsPay())
|
||||
.eqIfPresent(StoreCartDO::getIsNew, reqVO.getIsNew())
|
||||
.eqIfPresent(StoreCartDO::getCombinationId, reqVO.getCombinationId())
|
||||
.eqIfPresent(StoreCartDO::getSeckillId, reqVO.getSeckillId())
|
||||
.eqIfPresent(StoreCartDO::getBargainId, reqVO.getBargainId())
|
||||
.betweenIfPresent(StoreCartDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(StoreCartDO::getId));
|
||||
}
|
||||
|
||||
|
||||
@Select("select IFNULL(sum(cart_num),0) from yshop_store_cart " +
|
||||
"where is_pay=0 and deleted=0 and is_new=0 and uid=#{uid}")
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
package co.yixiang.yshop.module.cart.service.storecart;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.*;
|
||||
import co.yixiang.yshop.module.cart.dal.dataobject.storecart.StoreCartDO;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.StoreCartPageReqVO;
|
||||
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.StoreCartRespVO;
|
||||
|
||||
/**
|
||||
* 购物车 Service 接口
|
||||
@ -13,20 +11,6 @@ import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
*/
|
||||
public interface StoreCartService {
|
||||
|
||||
/**
|
||||
* 创建购物车
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createStoreCart(@Valid StoreCartCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新购物车
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateStoreCart(@Valid StoreCartUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除购物车
|
||||
@ -35,21 +19,6 @@ public interface StoreCartService {
|
||||
*/
|
||||
void deleteStoreCart(Long id);
|
||||
|
||||
/**
|
||||
* 获得购物车
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 购物车
|
||||
*/
|
||||
StoreCartDO getStoreCart(Long id);
|
||||
|
||||
/**
|
||||
* 获得购物车列表
|
||||
*
|
||||
* @param ids 编号
|
||||
* @return 购物车列表
|
||||
*/
|
||||
List<StoreCartDO> getStoreCartList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得购物车分页
|
||||
@ -57,14 +26,8 @@ public interface StoreCartService {
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 购物车分页
|
||||
*/
|
||||
PageResult<StoreCartDO> getStoreCartPage(StoreCartPageReqVO pageReqVO);
|
||||
PageResult<StoreCartRespVO> getStoreCartPage(StoreCartPageReqVO pageReqVO);
|
||||
|
||||
|
||||
/**
|
||||
* 获得购物车列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 购物车列表
|
||||
*/
|
||||
List<StoreCartDO> getStoreCartList(StoreCartExportReqVO exportReqVO);
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +1,14 @@
|
||||
package co.yixiang.yshop.module.cart.service.storecart;
|
||||
|
||||
import co.yixiang.yshop.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import co.yixiang.yshop.module.member.dal.mysql.user.MemberUserMapper;
|
||||
import co.yixiang.yshop.module.product.dal.dataobject.storeproduct.StoreProductDO;
|
||||
import co.yixiang.yshop.module.product.dal.mysql.storeproduct.StoreProductMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.lang.reflect.Member;
|
||||
import java.util.*;
|
||||
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.*;
|
||||
import co.yixiang.yshop.module.cart.dal.dataobject.storecart.StoreCartDO;
|
||||
@ -26,24 +31,11 @@ public class StoreCartServiceImpl implements StoreCartService {
|
||||
|
||||
@Resource
|
||||
private StoreCartMapper storeCartMapper;
|
||||
@Resource
|
||||
private StoreProductMapper storeProductMapper;
|
||||
@Resource
|
||||
private MemberUserMapper memberUserMapper;
|
||||
|
||||
@Override
|
||||
public Long createStoreCart(StoreCartCreateReqVO createReqVO) {
|
||||
// 插入
|
||||
StoreCartDO storeCart = StoreCartConvert.INSTANCE.convert(createReqVO);
|
||||
storeCartMapper.insert(storeCart);
|
||||
// 返回
|
||||
return storeCart.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStoreCart(StoreCartUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateStoreCartExists(updateReqVO.getId());
|
||||
// 更新
|
||||
StoreCartDO updateObj = StoreCartConvert.INSTANCE.convert(updateReqVO);
|
||||
storeCartMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteStoreCart(Long id) {
|
||||
@ -59,24 +51,20 @@ public class StoreCartServiceImpl implements StoreCartService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StoreCartDO getStoreCart(Long id) {
|
||||
return storeCartMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StoreCartDO> getStoreCartList(Collection<Long> ids) {
|
||||
return storeCartMapper.selectBatchIds(ids);
|
||||
public PageResult<StoreCartRespVO> getStoreCartPage(StoreCartPageReqVO pageReqVO) {
|
||||
PageResult<StoreCartDO> pageResult = storeCartMapper.selectPage(pageReqVO);
|
||||
PageResult<StoreCartRespVO> storeCartRespVO = StoreCartConvert.INSTANCE.convertPage(pageResult);
|
||||
for (StoreCartRespVO storeCartRespVO1 : storeCartRespVO.getList()) {
|
||||
StoreProductDO storeProductDO = storeProductMapper.selectById(storeCartRespVO1.getProductId());
|
||||
MemberUserDO memberUserDO = memberUserMapper.selectById(storeCartRespVO1.getUid());
|
||||
storeCartRespVO1.setNickname(memberUserDO.getNickname());
|
||||
storeCartRespVO1.setStoreName(storeProductDO.getStoreName());
|
||||
}
|
||||
return storeCartRespVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<StoreCartDO> getStoreCartPage(StoreCartPageReqVO pageReqVO) {
|
||||
return storeCartMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StoreCartDO> getStoreCartList(StoreCartExportReqVO exportReqVO) {
|
||||
return storeCartMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
文档可见:https://www.yixiang.co/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
|
||||
@ -1,231 +0,0 @@
|
||||
package co.yixiang.yshop.module.cart.service.storecart;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import co.yixiang.yshop.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.*;
|
||||
import co.yixiang.yshop.module.cart.dal.dataobject.storecart.StoreCartDO;
|
||||
import co.yixiang.yshop.module.cart.dal.mysql.storecart.StoreCartMapper;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static co.yixiang.yshop.module.cart.enums.ErrorCodeConstants.*;
|
||||
import static co.yixiang.yshop.framework.test.core.util.AssertUtils.*;
|
||||
import static co.yixiang.yshop.framework.test.core.util.RandomUtils.*;
|
||||
import static co.yixiang.yshop.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static co.yixiang.yshop.framework.common.util.object.ObjectUtils.*;
|
||||
import static co.yixiang.yshop.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link StoreCartServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Import(StoreCartServiceImpl.class)
|
||||
public class StoreCartServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private StoreCartServiceImpl storeCartService;
|
||||
|
||||
@Resource
|
||||
private StoreCartMapper storeCartMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateStoreCart_success() {
|
||||
// 准备参数
|
||||
StoreCartCreateReqVO reqVO = randomPojo(StoreCartCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long storeCartId = storeCartService.createStoreCart(reqVO);
|
||||
// 断言
|
||||
assertNotNull(storeCartId);
|
||||
// 校验记录的属性是否正确
|
||||
StoreCartDO storeCart = storeCartMapper.selectById(storeCartId);
|
||||
assertPojoEquals(reqVO, storeCart);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateStoreCart_success() {
|
||||
// mock 数据
|
||||
StoreCartDO dbStoreCart = randomPojo(StoreCartDO.class);
|
||||
storeCartMapper.insert(dbStoreCart);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
StoreCartUpdateReqVO reqVO = randomPojo(StoreCartUpdateReqVO.class, o -> {
|
||||
o.setId(dbStoreCart.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
storeCartService.updateStoreCart(reqVO);
|
||||
// 校验是否更新正确
|
||||
StoreCartDO storeCart = storeCartMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, storeCart);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateStoreCart_notExists() {
|
||||
// 准备参数
|
||||
StoreCartUpdateReqVO reqVO = randomPojo(StoreCartUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> storeCartService.updateStoreCart(reqVO), STORE_CART_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteStoreCart_success() {
|
||||
// mock 数据
|
||||
StoreCartDO dbStoreCart = randomPojo(StoreCartDO.class);
|
||||
storeCartMapper.insert(dbStoreCart);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbStoreCart.getId();
|
||||
|
||||
// 调用
|
||||
storeCartService.deleteStoreCart(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(storeCartMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteStoreCart_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> storeCartService.deleteStoreCart(id), STORE_CART_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetStoreCartPage() {
|
||||
// mock 数据
|
||||
StoreCartDO dbStoreCart = randomPojo(StoreCartDO.class, o -> { // 等会查询到
|
||||
o.setUid(null);
|
||||
o.setType(null);
|
||||
o.setProductId(null);
|
||||
o.setProductAttrUnique(null);
|
||||
o.setCartNum(null);
|
||||
o.setIsPay(null);
|
||||
o.setIsNew(null);
|
||||
o.setCombinationId(null);
|
||||
o.setSeckillId(null);
|
||||
o.setBargainId(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
storeCartMapper.insert(dbStoreCart);
|
||||
// 测试 uid 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setUid(null)));
|
||||
// 测试 type 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setType(null)));
|
||||
// 测试 productId 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setProductId(null)));
|
||||
// 测试 productAttrUnique 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setProductAttrUnique(null)));
|
||||
// 测试 cartNum 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setCartNum(null)));
|
||||
// 测试 isPay 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setIsPay(null)));
|
||||
// 测试 isNew 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setIsNew(null)));
|
||||
// 测试 combinationId 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setCombinationId(null)));
|
||||
// 测试 seckillId 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setSeckillId(null)));
|
||||
// 测试 bargainId 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setBargainId(null)));
|
||||
// 测试 createTime 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
StoreCartPageReqVO reqVO = new StoreCartPageReqVO();
|
||||
reqVO.setUid(null);
|
||||
reqVO.setType(null);
|
||||
reqVO.setProductId(null);
|
||||
reqVO.setProductAttrUnique(null);
|
||||
reqVO.setCartNum(null);
|
||||
reqVO.setIsPay(null);
|
||||
reqVO.setIsNew(null);
|
||||
reqVO.setCombinationId(null);
|
||||
reqVO.setSeckillId(null);
|
||||
reqVO.setBargainId(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<StoreCartDO> pageResult = storeCartService.getStoreCartPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbStoreCart, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetStoreCartList() {
|
||||
// mock 数据
|
||||
StoreCartDO dbStoreCart = randomPojo(StoreCartDO.class, o -> { // 等会查询到
|
||||
o.setUid(null);
|
||||
o.setType(null);
|
||||
o.setProductId(null);
|
||||
o.setProductAttrUnique(null);
|
||||
o.setCartNum(null);
|
||||
o.setIsPay(null);
|
||||
o.setIsNew(null);
|
||||
o.setCombinationId(null);
|
||||
o.setSeckillId(null);
|
||||
o.setBargainId(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
storeCartMapper.insert(dbStoreCart);
|
||||
// 测试 uid 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setUid(null)));
|
||||
// 测试 type 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setType(null)));
|
||||
// 测试 productId 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setProductId(null)));
|
||||
// 测试 productAttrUnique 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setProductAttrUnique(null)));
|
||||
// 测试 cartNum 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setCartNum(null)));
|
||||
// 测试 isPay 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setIsPay(null)));
|
||||
// 测试 isNew 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setIsNew(null)));
|
||||
// 测试 combinationId 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setCombinationId(null)));
|
||||
// 测试 seckillId 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setSeckillId(null)));
|
||||
// 测试 bargainId 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setBargainId(null)));
|
||||
// 测试 createTime 不匹配
|
||||
storeCartMapper.insert(cloneIgnoreId(dbStoreCart, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
StoreCartExportReqVO reqVO = new StoreCartExportReqVO();
|
||||
reqVO.setUid(null);
|
||||
reqVO.setType(null);
|
||||
reqVO.setProductId(null);
|
||||
reqVO.setProductAttrUnique(null);
|
||||
reqVO.setCartNum(null);
|
||||
reqVO.setIsPay(null);
|
||||
reqVO.setIsNew(null);
|
||||
reqVO.setCombinationId(null);
|
||||
reqVO.setSeckillId(null);
|
||||
reqVO.setBargainId(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
List<StoreCartDO> list = storeCartService.getStoreCartList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbStoreCart, list.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user