init:初始化订单来源列表查询

This commit is contained in:
Damonny 2024-12-23 02:43:17 +08:00
parent 398395dd4e
commit 06fa269e6c
18 changed files with 873 additions and 1 deletions

Binary file not shown.

View File

@ -29,4 +29,7 @@ public interface ErrorCodeConstants {
ErrorCode ON_SALE_PRODUCT_NOT_EXISTS = new ErrorCode(1_801_001_021, "在售产品不存在");
ErrorCode ORDERS_NOT_EXISTS = new ErrorCode(1_805_001_001, "订单不存在");
ErrorCode ORDER_SOURCE_NOT_EXISTS = new ErrorCode(1_805_002_001, "订单来源配置不存在");
ErrorCode ORDER_SOURCE_LIVE_NOT_EXISTS = new ErrorCode(1_805_003_001, "订单来源-直播间配置不存在");
}

View File

@ -0,0 +1,139 @@
package cn.iocoder.yudao.module.haoka.controller.admin.ordersource;
import org.springframework.web.bind.annotation.*;
import jakarta.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 jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.haoka.controller.admin.ordersource.vo.*;
import cn.iocoder.yudao.module.haoka.dal.dataobject.ordersource.OrderSourceDO;
import cn.iocoder.yudao.module.haoka.dal.dataobject.ordersource.OrderSourceLiveDO;
import cn.iocoder.yudao.module.haoka.service.ordersource.OrderSourceService;
@Tag(name = "管理后台 - 订单来源配置")
@RestController
@RequestMapping("/haoka/order-source")
@Validated
public class OrderSourceController {
@Resource
private OrderSourceService orderSourceService;
@PostMapping("/create")
@Operation(summary = "创建订单来源配置")
@PreAuthorize("@ss.hasPermission('haoka:order-source:create')")
public CommonResult<Long> createOrderSource(@Valid @RequestBody OrderSourceSaveReqVO createReqVO) {
return success(orderSourceService.createOrderSource(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新订单来源配置")
@PreAuthorize("@ss.hasPermission('haoka:order-source:update')")
public CommonResult<Boolean> updateOrderSource(@Valid @RequestBody OrderSourceSaveReqVO updateReqVO) {
orderSourceService.updateOrderSource(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除订单来源配置")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('haoka:order-source:delete')")
public CommonResult<Boolean> deleteOrderSource(@RequestParam("id") Long id) {
orderSourceService.deleteOrderSource(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得订单来源配置")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('haoka:order-source:query')")
public CommonResult<OrderSourceRespVO> getOrderSource(@RequestParam("id") Long id) {
OrderSourceDO orderSource = orderSourceService.getOrderSource(id);
return success(BeanUtils.toBean(orderSource, OrderSourceRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得订单来源配置分页")
@PreAuthorize("@ss.hasPermission('haoka:order-source:query')")
public CommonResult<PageResult<OrderSourceRespVO>> getOrderSourcePage(@Valid OrderSourcePageReqVO pageReqVO) {
PageResult<OrderSourceDO> pageResult = orderSourceService.getOrderSourcePage(pageReqVO);
return success(BeanUtils.toBean(pageResult, OrderSourceRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出订单来源配置 Excel")
@PreAuthorize("@ss.hasPermission('haoka:order-source:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportOrderSourceExcel(@Valid OrderSourcePageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<OrderSourceDO> list = orderSourceService.getOrderSourcePage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "订单来源配置.xls", "数据", OrderSourceRespVO.class,
BeanUtils.toBean(list, OrderSourceRespVO.class));
}
// ==================== 子表订单来源-直播间配置 ====================
@GetMapping("/order-source-live/page")
@Operation(summary = "获得订单来源-直播间配置分页")
@Parameter(name = "sourceId", description = "来源ID")
@PreAuthorize("@ss.hasPermission('haoka:order-source:query')")
public CommonResult<PageResult<OrderSourceLiveDO>> getOrderSourceLivePage(PageParam pageReqVO,
@RequestParam("sourceId") Long sourceId) {
return success(orderSourceService.getOrderSourceLivePage(pageReqVO, sourceId));
}
@PostMapping("/order-source-live/create")
@Operation(summary = "创建订单来源-直播间配置")
@PreAuthorize("@ss.hasPermission('haoka:order-source:create')")
public CommonResult<Long> createOrderSourceLive(@Valid @RequestBody OrderSourceLiveDO orderSourceLive) {
return success(orderSourceService.createOrderSourceLive(orderSourceLive));
}
@PutMapping("/order-source-live/update")
@Operation(summary = "更新订单来源-直播间配置")
@PreAuthorize("@ss.hasPermission('haoka:order-source:update')")
public CommonResult<Boolean> updateOrderSourceLive(@Valid @RequestBody OrderSourceLiveDO orderSourceLive) {
orderSourceService.updateOrderSourceLive(orderSourceLive);
return success(true);
}
@DeleteMapping("/order-source-live/delete")
@Parameter(name = "id", description = "编号", required = true)
@Operation(summary = "删除订单来源-直播间配置")
@PreAuthorize("@ss.hasPermission('haoka:order-source:delete')")
public CommonResult<Boolean> deleteOrderSourceLive(@RequestParam("id") Long id) {
orderSourceService.deleteOrderSourceLive(id);
return success(true);
}
@GetMapping("/order-source-live/get")
@Operation(summary = "获得订单来源-直播间配置")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('haoka:order-source:query')")
public CommonResult<OrderSourceLiveDO> getOrderSourceLive(@RequestParam("id") Long id) {
return success(orderSourceService.getOrderSourceLive(id));
}
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.haoka.controller.admin.ordersource.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 订单来源配置分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class OrderSourcePageReqVO extends PageParam {
@Schema(description = "来源备注", example = "你猜")
private String sourceRemark;
@Schema(description = "渠道ID")
private Long channel;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.haoka.controller.admin.ordersource.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - 订单来源配置 Response VO")
@Data
@ExcelIgnoreUnannotated
public class OrderSourceRespVO {
@Schema(description = "来源ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25277")
@ExcelProperty("来源ID")
private Long id;
@Schema(description = "来源备注", example = "你猜")
@ExcelProperty("来源备注")
private String sourceRemark;
@Schema(description = "渠道ID", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty(value = "渠道ID", converter = DictConvert.class)
@DictFormat("haoka_order_channel") // TODO 代码优化建议设置到对应的 DictTypeConstants 枚举类中
private Long channel;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.haoka.controller.admin.ordersource.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import jakarta.validation.constraints.*;
import cn.iocoder.yudao.module.haoka.dal.dataobject.ordersource.OrderSourceLiveDO;
@Schema(description = "管理后台 - 订单来源配置新增/修改 Request VO")
@Data
public class OrderSourceSaveReqVO {
@Schema(description = "来源ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25277")
private Long id;
@Schema(description = "来源备注", example = "你猜")
private String sourceRemark;
@Schema(description = "渠道ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "渠道ID不能为空")
private Long channel;
}

View File

@ -29,7 +29,7 @@ public class OrdersDO extends BaseDO {
/**
* 订单ID
*/
@TableId
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 生产商ID

View File

@ -0,0 +1,54 @@
package cn.iocoder.yudao.module.haoka.dal.dataobject.ordersource;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 订单来源配置 DO
*
* @author xiongxiong
*/
@TableName("haoka_order_source")
@KeySequence("haoka_order_source_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OrderSourceDO extends BaseDO {
/**
* 来源ID
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 来源备注
*/
private String sourceRemark;
/**
* 渠道ID
*
* 枚举 {@link TODO haoka_order_channel 对应的类}
*/
private Long channel;
/**
* 成本更新时间
*/
private LocalDateTime costUpdatedAt;
/**
* 店铺ID
*/
private Long shopId;
/**
* 卖家ID
*/
private Long sellerId;
}

View File

@ -0,0 +1,63 @@
package cn.iocoder.yudao.module.haoka.dal.dataobject.ordersource;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 订单来源-直播间配置 DO
*
* @author xiongxiong
*/
@TableName("haoka_order_source_live")
@KeySequence("haoka_order_source_live_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OrderSourceLiveDO extends BaseDO {
/**
* 主键ID
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 直播间ID
*/
private Long authorId;
/**
* 来源ID
*/
private Long sourceId;
/**
* 来源可选
*/
private String source;
/**
* 所属店铺ID
*/
private Long shopId;
/**
* 用户ID可选
*/
private Long userId;
/**
* 团队ID可选
*/
private Long deptId;
/**
* 团队名称可选
*/
private String teamName;
/**
* 重命名后的名称可选用于搜索
*/
private String nickName;
}

View File

@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.haoka.dal.mysql.ordersource;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.haoka.dal.dataobject.ordersource.OrderSourceLiveDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 订单来源-直播间配置 Mapper
*
* @author xiongxiong
*/
@Mapper
public interface OrderSourceLiveMapper extends BaseMapperX<OrderSourceLiveDO> {
default PageResult<OrderSourceLiveDO> selectPage(PageParam reqVO, Long sourceId) {
return selectPage(reqVO, new LambdaQueryWrapperX<OrderSourceLiveDO>()
.eq(OrderSourceLiveDO::getSourceId, sourceId)
.orderByDesc(OrderSourceLiveDO::getId));
}
default int deleteBySourceId(Long sourceId) {
return delete(OrderSourceLiveDO::getSourceId, sourceId);
}
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.haoka.dal.mysql.ordersource;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.haoka.dal.dataobject.ordersource.OrderSourceDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.haoka.controller.admin.ordersource.vo.*;
/**
* 订单来源配置 Mapper
*
* @author xiongxiong
*/
@Mapper
public interface OrderSourceMapper extends BaseMapperX<OrderSourceDO> {
default PageResult<OrderSourceDO> selectPage(OrderSourcePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<OrderSourceDO>()
.eqIfPresent(OrderSourceDO::getSourceRemark, reqVO.getSourceRemark())
.eqIfPresent(OrderSourceDO::getChannel, reqVO.getChannel())
.betweenIfPresent(OrderSourceDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(OrderSourceDO::getId));
}
}

View File

@ -0,0 +1,97 @@
package cn.iocoder.yudao.module.haoka.service.ordersource;
import java.util.*;
import jakarta.validation.*;
import cn.iocoder.yudao.module.haoka.controller.admin.ordersource.vo.*;
import cn.iocoder.yudao.module.haoka.dal.dataobject.ordersource.OrderSourceDO;
import cn.iocoder.yudao.module.haoka.dal.dataobject.ordersource.OrderSourceLiveDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 订单来源配置 Service 接口
*
* @author xiongxiong
*/
public interface OrderSourceService {
/**
* 创建订单来源配置
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createOrderSource(@Valid OrderSourceSaveReqVO createReqVO);
/**
* 更新订单来源配置
*
* @param updateReqVO 更新信息
*/
void updateOrderSource(@Valid OrderSourceSaveReqVO updateReqVO);
/**
* 删除订单来源配置
*
* @param id 编号
*/
void deleteOrderSource(Long id);
/**
* 获得订单来源配置
*
* @param id 编号
* @return 订单来源配置
*/
OrderSourceDO getOrderSource(Long id);
/**
* 获得订单来源配置分页
*
* @param pageReqVO 分页查询
* @return 订单来源配置分页
*/
PageResult<OrderSourceDO> getOrderSourcePage(OrderSourcePageReqVO pageReqVO);
// ==================== 子表订单来源-直播间配置 ====================
/**
* 获得订单来源-直播间配置分页
*
* @param pageReqVO 分页查询
* @param sourceId 来源ID
* @return 订单来源-直播间配置分页
*/
PageResult<OrderSourceLiveDO> getOrderSourceLivePage(PageParam pageReqVO, Long sourceId);
/**
* 创建订单来源-直播间配置
*
* @param orderSourceLive 创建信息
* @return 编号
*/
Long createOrderSourceLive(@Valid OrderSourceLiveDO orderSourceLive);
/**
* 更新订单来源-直播间配置
*
* @param orderSourceLive 更新信息
*/
void updateOrderSourceLive(@Valid OrderSourceLiveDO orderSourceLive);
/**
* 删除订单来源-直播间配置
*
* @param id 编号
*/
void deleteOrderSourceLive(Long id);
/**
* 获得订单来源-直播间配置
*
* @param id 编号
* @return 订单来源-直播间配置
*/
OrderSourceLiveDO getOrderSourceLive(Long id);
}

View File

@ -0,0 +1,127 @@
package cn.iocoder.yudao.module.haoka.service.ordersource;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.haoka.controller.admin.ordersource.vo.*;
import cn.iocoder.yudao.module.haoka.dal.dataobject.ordersource.OrderSourceDO;
import cn.iocoder.yudao.module.haoka.dal.dataobject.ordersource.OrderSourceLiveDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.haoka.dal.mysql.ordersource.OrderSourceMapper;
import cn.iocoder.yudao.module.haoka.dal.mysql.ordersource.OrderSourceLiveMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.haoka.enums.ErrorCodeConstants.*;
/**
* 订单来源配置 Service 实现类
*
* @author xiongxiong
*/
@Service
@Validated
public class OrderSourceServiceImpl implements OrderSourceService {
@Resource
private OrderSourceMapper orderSourceMapper;
@Resource
private OrderSourceLiveMapper orderSourceLiveMapper;
@Override
public Long createOrderSource(OrderSourceSaveReqVO createReqVO) {
// 插入
OrderSourceDO orderSource = BeanUtils.toBean(createReqVO, OrderSourceDO.class);
orderSourceMapper.insert(orderSource);
// 返回
return orderSource.getId();
}
@Override
public void updateOrderSource(OrderSourceSaveReqVO updateReqVO) {
// 校验存在
validateOrderSourceExists(updateReqVO.getId());
// 更新
OrderSourceDO updateObj = BeanUtils.toBean(updateReqVO, OrderSourceDO.class);
orderSourceMapper.updateById(updateObj);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteOrderSource(Long id) {
// 校验存在
validateOrderSourceExists(id);
// 删除
orderSourceMapper.deleteById(id);
// 删除子表
deleteOrderSourceLiveBySourceId(id);
}
private void validateOrderSourceExists(Long id) {
if (orderSourceMapper.selectById(id) == null) {
throw exception(ORDER_SOURCE_NOT_EXISTS);
}
}
@Override
public OrderSourceDO getOrderSource(Long id) {
return orderSourceMapper.selectById(id);
}
@Override
public PageResult<OrderSourceDO> getOrderSourcePage(OrderSourcePageReqVO pageReqVO) {
return orderSourceMapper.selectPage(pageReqVO);
}
// ==================== 子表订单来源-直播间配置 ====================
@Override
public PageResult<OrderSourceLiveDO> getOrderSourceLivePage(PageParam pageReqVO, Long sourceId) {
return orderSourceLiveMapper.selectPage(pageReqVO, sourceId);
}
@Override
public Long createOrderSourceLive(OrderSourceLiveDO orderSourceLive) {
orderSourceLiveMapper.insert(orderSourceLive);
return orderSourceLive.getId();
}
@Override
public void updateOrderSourceLive(OrderSourceLiveDO orderSourceLive) {
// 校验存在
validateOrderSourceLiveExists(orderSourceLive.getId());
// 更新
orderSourceLive.setUpdater(null).setUpdateTime(null); // 解决更新情况下updateTime 不更新
orderSourceLiveMapper.updateById(orderSourceLive);
}
@Override
public void deleteOrderSourceLive(Long id) {
// 校验存在
validateOrderSourceLiveExists(id);
// 删除
orderSourceLiveMapper.deleteById(id);
}
@Override
public OrderSourceLiveDO getOrderSourceLive(Long id) {
return orderSourceLiveMapper.selectById(id);
}
private void validateOrderSourceLiveExists(Long id) {
if (orderSourceLiveMapper.selectById(id) == null) {
throw exception(ORDER_SOURCE_LIVE_NOT_EXISTS);
}
}
private void deleteOrderSourceLiveBySourceId(Long sourceId) {
orderSourceLiveMapper.deleteBySourceId(sourceId);
}
}

View File

@ -0,0 +1,12 @@
<?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="cn.iocoder.yudao.module.haoka.dal.mysql.ordersource.OrderSourceMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

View File

@ -0,0 +1,138 @@
package cn.iocoder.yudao.module.haoka.service.ordersource;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import jakarta.annotation.Resource;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.haoka.controller.admin.ordersource.vo.*;
import cn.iocoder.yudao.module.haoka.dal.dataobject.ordersource.OrderSourceDO;
import cn.iocoder.yudao.module.haoka.dal.mysql.ordersource.OrderSourceMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Import;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
import static cn.iocoder.yudao.module.haoka.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@link OrderSourceServiceImpl} 的单元测试类
*
* @author xiongxiong
*/
@Import(OrderSourceServiceImpl.class)
public class OrderSourceServiceImplTest extends BaseDbUnitTest {
@Resource
private OrderSourceServiceImpl orderSourceService;
@Resource
private OrderSourceMapper orderSourceMapper;
@Test
public void testCreateOrderSource_success() {
// 准备参数
OrderSourceSaveReqVO createReqVO = randomPojo(OrderSourceSaveReqVO.class).setId(null);
// 调用
Long orderSourceId = orderSourceService.createOrderSource(createReqVO);
// 断言
assertNotNull(orderSourceId);
// 校验记录的属性是否正确
OrderSourceDO orderSource = orderSourceMapper.selectById(orderSourceId);
assertPojoEquals(createReqVO, orderSource, "id");
}
@Test
public void testUpdateOrderSource_success() {
// mock 数据
OrderSourceDO dbOrderSource = randomPojo(OrderSourceDO.class);
orderSourceMapper.insert(dbOrderSource);// @Sql: 先插入出一条存在的数据
// 准备参数
OrderSourceSaveReqVO updateReqVO = randomPojo(OrderSourceSaveReqVO.class, o -> {
o.setId(dbOrderSource.getId()); // 设置更新的 ID
});
// 调用
orderSourceService.updateOrderSource(updateReqVO);
// 校验是否更新正确
OrderSourceDO orderSource = orderSourceMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, orderSource);
}
@Test
public void testUpdateOrderSource_notExists() {
// 准备参数
OrderSourceSaveReqVO updateReqVO = randomPojo(OrderSourceSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> orderSourceService.updateOrderSource(updateReqVO), ORDER_SOURCE_NOT_EXISTS);
}
@Test
public void testDeleteOrderSource_success() {
// mock 数据
OrderSourceDO dbOrderSource = randomPojo(OrderSourceDO.class);
orderSourceMapper.insert(dbOrderSource);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbOrderSource.getId();
// 调用
orderSourceService.deleteOrderSource(id);
// 校验数据不存在了
assertNull(orderSourceMapper.selectById(id));
}
@Test
public void testDeleteOrderSource_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> orderSourceService.deleteOrderSource(id), ORDER_SOURCE_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetOrderSourcePage() {
// mock 数据
OrderSourceDO dbOrderSource = randomPojo(OrderSourceDO.class, o -> { // 等会查询到
o.setSourceRemark(null);
o.setChannel(null);
o.setCreateTime(null);
});
orderSourceMapper.insert(dbOrderSource);
// 测试 sourceRemark 不匹配
orderSourceMapper.insert(cloneIgnoreId(dbOrderSource, o -> o.setSourceRemark(null)));
// 测试 channel 不匹配
orderSourceMapper.insert(cloneIgnoreId(dbOrderSource, o -> o.setChannel(null)));
// 测试 createTime 不匹配
orderSourceMapper.insert(cloneIgnoreId(dbOrderSource, o -> o.setCreateTime(null)));
// 准备参数
OrderSourcePageReqVO reqVO = new OrderSourcePageReqVO();
reqVO.setSourceRemark(null);
reqVO.setChannel(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<OrderSourceDO> pageResult = orderSourceService.getOrderSourcePage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbOrderSource, pageResult.getList().get(0));
}
}

View File

@ -0,0 +1,19 @@
-- 将该建表 SQL 语句,添加到 yudao-module-haoka-biz 模块的 test/resources/sql/create_tables.sql 文件里
CREATE TABLE IF NOT EXISTS "haoka_order_source" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"source_remark" varchar,
"channel" bigint NOT NULL,
"cost_updated_at" varchar,
"shop_id" bigint,
"seller_id" bigint,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint NOT NULL DEFAULT 0,
PRIMARY KEY ("id")
) COMMENT '订单来源配置';
-- 将该删表 SQL 语句,添加到 yudao-module-haoka-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "haoka_order_source";

View File

@ -0,0 +1,55 @@
-- 菜单 SQL
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status, component_name
)
VALUES (
'订单来源配置管理', '', 2, 0, 2912,
'order-source', '', 'haoka/ordersource/index', 0, 'OrderSource'
);
-- 按钮父菜单ID
-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码
SELECT @parentId := LAST_INSERT_ID();
-- 按钮 SQL
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'订单来源配置查询', 'haoka:order-source:query', 3, 1, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'订单来源配置创建', 'haoka:order-source:create', 3, 2, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'订单来源配置更新', 'haoka:order-source:update', 3, 3, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'订单来源配置删除', 'haoka:order-source:delete', 3, 4, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'订单来源配置导出', 'haoka:order-source:export', 3, 5, @parentId,
'', '', '', 0
);

View File

@ -0,0 +1,22 @@
-- 将该建表 SQL 语句,添加到 yudao-module-haoka-biz 模块的 test/resources/sql/create_tables.sql 文件里
CREATE TABLE IF NOT EXISTS "haoka_order_source_live" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"author_id" bigint NOT NULL,
"source_id" bigint NOT NULL,
"source" varchar,
"shop_id" bigint,
"user_id" bigint,
"dept_id" bigint,
"team_name" varchar,
"nick_name" varchar,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint NOT NULL DEFAULT 0,
PRIMARY KEY ("id")
) COMMENT '订单来源-直播间配置';
-- 将该删表 SQL 语句,添加到 yudao-module-haoka-biz 模块的 test/resources/sql/clean.sql 文件里
DELETE FROM "haoka_order_source_live";