diff --git a/code_gen_history/V5_Order_1/codegen-OrderSource.zip b/code_gen_history/V5_Order_1/codegen-OrderSource.zip new file mode 100644 index 0000000000..66a370c04d Binary files /dev/null and b/code_gen_history/V5_Order_1/codegen-OrderSource.zip differ diff --git a/yudao-module-haoka/yudao-module-haoka-api/src/main/java/cn/iocoder/yudao/module/haoka/enums/ErrorCodeConstants.java b/yudao-module-haoka/yudao-module-haoka-api/src/main/java/cn/iocoder/yudao/module/haoka/enums/ErrorCodeConstants.java index b415d29f4d..cc41165168 100644 --- a/yudao-module-haoka/yudao-module-haoka-api/src/main/java/cn/iocoder/yudao/module/haoka/enums/ErrorCodeConstants.java +++ b/yudao-module-haoka/yudao-module-haoka-api/src/main/java/cn/iocoder/yudao/module/haoka/enums/ErrorCodeConstants.java @@ -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, "订单来源-直播间配置不存在"); + } diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/ordersource/OrderSourceController.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/ordersource/OrderSourceController.java new file mode 100644 index 0000000000..0c3c60b729 --- /dev/null +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/ordersource/OrderSourceController.java @@ -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 createOrderSource(@Valid @RequestBody OrderSourceSaveReqVO createReqVO) { + return success(orderSourceService.createOrderSource(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新订单来源配置") + @PreAuthorize("@ss.hasPermission('haoka:order-source:update')") + public CommonResult 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 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 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> getOrderSourcePage(@Valid OrderSourcePageReqVO pageReqVO) { + PageResult 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 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> 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 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 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 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 getOrderSourceLive(@RequestParam("id") Long id) { + return success(orderSourceService.getOrderSourceLive(id)); + } + +} \ No newline at end of file diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/ordersource/vo/OrderSourcePageReqVO.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/ordersource/vo/OrderSourcePageReqVO.java new file mode 100644 index 0000000000..b6defe75d7 --- /dev/null +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/ordersource/vo/OrderSourcePageReqVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/ordersource/vo/OrderSourceRespVO.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/ordersource/vo/OrderSourceRespVO.java new file mode 100644 index 0000000000..9714e8b78f --- /dev/null +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/ordersource/vo/OrderSourceRespVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/ordersource/vo/OrderSourceSaveReqVO.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/ordersource/vo/OrderSourceSaveReqVO.java new file mode 100644 index 0000000000..aff5d430c1 --- /dev/null +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/controller/admin/ordersource/vo/OrderSourceSaveReqVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/dataobject/orders/OrdersDO.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/dataobject/orders/OrdersDO.java index 1156e58aba..e95b53fad2 100644 --- a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/dataobject/orders/OrdersDO.java +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/dataobject/orders/OrdersDO.java @@ -29,7 +29,7 @@ public class OrdersDO extends BaseDO { /** * 订单ID */ - @TableId + @TableId(type = IdType.ASSIGN_ID) private Long id; /** * 生产商ID diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/dataobject/ordersource/OrderSourceDO.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/dataobject/ordersource/OrderSourceDO.java new file mode 100644 index 0000000000..21a15307b9 --- /dev/null +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/dataobject/ordersource/OrderSourceDO.java @@ -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") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 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; + +} \ No newline at end of file diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/dataobject/ordersource/OrderSourceLiveDO.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/dataobject/ordersource/OrderSourceLiveDO.java new file mode 100644 index 0000000000..1a8517e401 --- /dev/null +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/dataobject/ordersource/OrderSourceLiveDO.java @@ -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") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 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; + +} \ No newline at end of file diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/mysql/ordersource/OrderSourceLiveMapper.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/mysql/ordersource/OrderSourceLiveMapper.java new file mode 100644 index 0000000000..161c90f20c --- /dev/null +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/mysql/ordersource/OrderSourceLiveMapper.java @@ -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 { + + default PageResult selectPage(PageParam reqVO, Long sourceId) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eq(OrderSourceLiveDO::getSourceId, sourceId) + .orderByDesc(OrderSourceLiveDO::getId)); + } + + default int deleteBySourceId(Long sourceId) { + return delete(OrderSourceLiveDO::getSourceId, sourceId); + } + +} \ No newline at end of file diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/mysql/ordersource/OrderSourceMapper.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/mysql/ordersource/OrderSourceMapper.java new file mode 100644 index 0000000000..fef4857ca7 --- /dev/null +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/dal/mysql/ordersource/OrderSourceMapper.java @@ -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 { + + default PageResult selectPage(OrderSourcePageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(OrderSourceDO::getSourceRemark, reqVO.getSourceRemark()) + .eqIfPresent(OrderSourceDO::getChannel, reqVO.getChannel()) + .betweenIfPresent(OrderSourceDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(OrderSourceDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/service/ordersource/OrderSourceService.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/service/ordersource/OrderSourceService.java new file mode 100644 index 0000000000..de282721e4 --- /dev/null +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/service/ordersource/OrderSourceService.java @@ -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 getOrderSourcePage(OrderSourcePageReqVO pageReqVO); + + // ==================== 子表(订单来源-直播间配置) ==================== + + /** + * 获得订单来源-直播间配置分页 + * + * @param pageReqVO 分页查询 + * @param sourceId 来源ID + * @return 订单来源-直播间配置分页 + */ + PageResult 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); + +} \ No newline at end of file diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/service/ordersource/OrderSourceServiceImpl.java b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/service/ordersource/OrderSourceServiceImpl.java new file mode 100644 index 0000000000..b464fdd6c1 --- /dev/null +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/java/cn/iocoder/yudao/module/haoka/service/ordersource/OrderSourceServiceImpl.java @@ -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 getOrderSourcePage(OrderSourcePageReqVO pageReqVO) { + return orderSourceMapper.selectPage(pageReqVO); + } + + // ==================== 子表(订单来源-直播间配置) ==================== + + @Override + public PageResult 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); + } + +} \ No newline at end of file diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/main/resources/mapper/ordersource/OrderSourceMapper.xml b/yudao-module-haoka/yudao-module-haoka-biz/src/main/resources/mapper/ordersource/OrderSourceMapper.xml new file mode 100644 index 0000000000..6cf518bebc --- /dev/null +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/main/resources/mapper/ordersource/OrderSourceMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/yudao-module-haoka/yudao-module-haoka-biz/src/test/java/cn/iocoder/yudao/module/haoka/service/ordersource/OrderSourceServiceImplTest.java b/yudao-module-haoka/yudao-module-haoka-biz/src/test/java/cn/iocoder/yudao/module/haoka/service/ordersource/OrderSourceServiceImplTest.java new file mode 100644 index 0000000000..2390071711 --- /dev/null +++ b/yudao-module-haoka/yudao-module-haoka-biz/src/test/java/cn/iocoder/yudao/module/haoka/service/ordersource/OrderSourceServiceImplTest.java @@ -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 pageResult = orderSourceService.getOrderSourcePage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbOrderSource, pageResult.getList().get(0)); + } + +} \ No newline at end of file diff --git a/yudao-server/src/main/resources/db/migration/V5.0.2_order_source_create_table.sql b/yudao-server/src/main/resources/db/migration/V5.0.2_order_source_create_table.sql new file mode 100644 index 0000000000..0449ff84a2 --- /dev/null +++ b/yudao-server/src/main/resources/db/migration/V5.0.2_order_source_create_table.sql @@ -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"; \ No newline at end of file diff --git a/yudao-server/src/main/resources/db/migration/V5.0.2_order_source_insert_api_menu.sql b/yudao-server/src/main/resources/db/migration/V5.0.2_order_source_insert_api_menu.sql new file mode 100644 index 0000000000..be8dcdf080 --- /dev/null +++ b/yudao-server/src/main/resources/db/migration/V5.0.2_order_source_insert_api_menu.sql @@ -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 +); \ No newline at end of file diff --git a/yudao-server/src/main/resources/db/migration/V5.0.3_order_source_live_create_table.sql b/yudao-server/src/main/resources/db/migration/V5.0.3_order_source_live_create_table.sql new file mode 100644 index 0000000000..dce970d2d4 --- /dev/null +++ b/yudao-server/src/main/resources/db/migration/V5.0.3_order_source_live_create_table.sql @@ -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"; \ No newline at end of file