mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:19:19 +08:00
refactor: 重构内部推广费模块
This commit is contained in:
+35
-12
@@ -6,8 +6,10 @@ import org.springframework.stereotype.Component;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.brushorder.mapper.BrushOrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.brushorder.model.po.BrushOrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.overview.model.agg.OverviewAggRows;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.mapper.PromotionFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.po.PromotionFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.mapper.AdFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.po.AdFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.mapper.ProductMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
@@ -16,6 +18,8 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 工作台费用侧:推广费 / 刷单仍读 MySQL 小表(不进 Mongo)。
|
||||
@@ -24,8 +28,9 @@ import java.util.Map;
|
||||
@RequiredArgsConstructor
|
||||
public class BiWorkbenchFeeLoader {
|
||||
|
||||
private final PromotionFeeMapper promotionFeeMapper;
|
||||
private final AdFeeMapper adFeeMapper;
|
||||
private final BrushOrderMapper brushOrderMapper;
|
||||
private final ProductMapper productMapper;
|
||||
|
||||
public FeeBundle load(Long companyId, List<Long> shopIds, LocalDate start, LocalDate end) {
|
||||
if (companyId == null || shopIds == null || shopIds.isEmpty() || start == null || end == null) {
|
||||
@@ -37,24 +42,24 @@ public class BiWorkbenchFeeLoader {
|
||||
|
||||
private List<OverviewAggRows.PromotionRow> loadPromotionRows(
|
||||
Long companyId, List<Long> shopIds, LocalDate start, LocalDate end) {
|
||||
List<PromotionFeePO> fees = promotionFeeMapper.selectList(new LambdaQueryWrapper<PromotionFeePO>()
|
||||
.eq(PromotionFeePO::getCompanyId, companyId)
|
||||
.in(PromotionFeePO::getShopId, shopIds)
|
||||
.ge(PromotionFeePO::getFeeDate, start)
|
||||
.le(PromotionFeePO::getFeeDate, end));
|
||||
List<AdFeePO> fees = adFeeMapper.selectList(new LambdaQueryWrapper<AdFeePO>()
|
||||
.eq(AdFeePO::getCompanyId, companyId)
|
||||
.in(AdFeePO::getShopId, shopIds)
|
||||
.ge(AdFeePO::getFeeDate, start)
|
||||
.le(AdFeePO::getFeeDate, end));
|
||||
Map<Long, Long> productCategoryIds = loadProductCategoryIds(fees);
|
||||
Map<String, OverviewAggRows.PromotionRow> merged = new HashMap<>();
|
||||
for (PromotionFeePO fee : fees) {
|
||||
for (AdFeePO fee : fees) {
|
||||
if (fee == null || fee.getShopId() == null) {
|
||||
continue;
|
||||
}
|
||||
Long productId = fee.getProductId();
|
||||
Long categoryId = fee.getCategoryId();
|
||||
String key = fee.getShopId() + ":" + productId + ":" + categoryId;
|
||||
String key = fee.getShopId() + ":" + productId;
|
||||
OverviewAggRows.PromotionRow row = merged.computeIfAbsent(key, k -> {
|
||||
OverviewAggRows.PromotionRow r = new OverviewAggRows.PromotionRow();
|
||||
r.setShopId(fee.getShopId());
|
||||
r.setProductId(productId);
|
||||
r.setCategoryId(categoryId);
|
||||
r.setCategoryId(productId != null ? productCategoryIds.get(productId) : null);
|
||||
r.setFeeAmount(BigDecimal.ZERO);
|
||||
return r;
|
||||
});
|
||||
@@ -63,6 +68,24 @@ public class BiWorkbenchFeeLoader {
|
||||
return new ArrayList<>(merged.values());
|
||||
}
|
||||
|
||||
private Map<Long, Long> loadProductCategoryIds(List<AdFeePO> fees) {
|
||||
List<Long> productIds = fees.stream()
|
||||
.map(AdFeePO::getProductId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (productIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<Long, Long> map = new HashMap<>();
|
||||
for (ProductPO p : productMapper.selectBatchIds(productIds)) {
|
||||
if (p != null && p.getId() != null) {
|
||||
map.put(p.getId(), p.getCategoryId());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private List<OverviewAggRows.BrushRow> loadBrushRows(
|
||||
Long companyId, List<Long> shopIds, LocalDate start, LocalDate end) {
|
||||
LocalDateTime startDt = start.atStartOfDay();
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.adfee.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.dto.CreateAdFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.dto.AdFeeFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.dto.UpdateAdFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.vo.AdFeeFieldVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.vo.AdFeeFieldConstants;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.vo.AdFeeVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.service.AdFeeService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 广告费记录控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/ec/ad-fee")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "电商-广告费记录管理", description = "广告费记录相关接口")
|
||||
public class AdFeeController {
|
||||
|
||||
private final AdFeeService adFeeService;
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "创建广告费记录", description = "创建新的广告费记录")
|
||||
@RequirePermission(value = "ec:order:create", description = "创建广告费记录", allowSuper = true)
|
||||
public ApiResponse<Long> createAdFee(@Valid @RequestBody CreateAdFeeDTO dto) {
|
||||
Long id = adFeeService.createAdFee(dto);
|
||||
return ApiResponse.success("广告费记录创建成功", id);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "更新广告费记录", description = "更新广告费记录信息")
|
||||
@RequirePermission(value = "ec:order:update", description = "更新广告费记录", allowSuper = true)
|
||||
public ApiResponse<Void> updateAdFee(@Valid @RequestBody UpdateAdFeeDTO dto) {
|
||||
adFeeService.updateAdFee(dto);
|
||||
return ApiResponse.success("广告费记录更新成功");
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@Operation(summary = "删除广告费记录", description = "删除指定的广告费记录")
|
||||
@RequirePermission(value = "ec:order:delete", description = "删除广告费记录", allowSuper = true)
|
||||
public ApiResponse<Void> deleteAdFee(
|
||||
@Parameter(description = "记录ID", required = true) @PathVariable Long id) {
|
||||
adFeeService.deleteAdFee(id);
|
||||
return ApiResponse.success("广告费记录删除成功");
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@Operation(summary = "查询广告费记录详情", description = "根据ID查询广告费记录详情")
|
||||
@RequirePermission(value = "ec:order:read", description = "查询广告费记录详情", allowSuper = true)
|
||||
public ApiResponse<AdFeeVO> getAdFeeById(
|
||||
@Parameter(description = "记录ID", required = true) @PathVariable Long id) {
|
||||
AdFeeVO vo = adFeeService.getAdFeeById(id);
|
||||
return ApiResponse.success("获取广告费记录详情成功", vo);
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "分页查询广告费记录", description = "分页查询广告费记录列表")
|
||||
@RequirePermission(value = "ec:order:read", description = "查询广告费记录列表", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<AdFeeVO>> getAdFeePage(
|
||||
@Valid @RequestBody PageQueryDTO<AdFeeFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<AdFeeVO> result = adFeeService.getAdFeePage(pageQueryDTO);
|
||||
return ApiResponse.success("获取广告费记录列表成功", result);
|
||||
}
|
||||
|
||||
@GetMapping("/fields")
|
||||
@Operation(summary = "获取广告费导入字段定义", description = "获取广告费导入时可映射的系统字段列表")
|
||||
@RequirePermission(value = "ec:order:read", description = "查询导入字段", allowSuper = true)
|
||||
public ApiResponse<List<AdFeeFieldVO>> getAdFeeFields() {
|
||||
return ApiResponse.success("获取广告费导入字段成功", AdFeeFieldConstants.FIELDS);
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.adfee.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.po.AdFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.dto.AdFeeFilterDTO;
|
||||
|
||||
/**
|
||||
* 广告费记录Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface AdFeeMapper extends BaseMapper<AdFeePO> {
|
||||
|
||||
/**
|
||||
* 分页查询广告费记录
|
||||
*/
|
||||
IPage<AdFeePO> selectPageWithFilter(Page<AdFeePO> page, @Param("filter") AdFeeFilterDTO filter);
|
||||
}
|
||||
+5
-17
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto;
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.adfee.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -6,11 +6,11 @@ import lombok.Data;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 推广费记录筛选DTO
|
||||
* 广告费记录筛选DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "推广费记录筛选DTO")
|
||||
public class PromotionFeeFilterDTO {
|
||||
@Schema(description = "广告费记录筛选DTO")
|
||||
public class AdFeeFilterDTO {
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
@@ -18,24 +18,12 @@ public class PromotionFeeFilterDTO {
|
||||
@Schema(description = "店铺ID", example = "1")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 推广费类型ID
|
||||
*/
|
||||
@Schema(description = "推广费类型ID", example = "1")
|
||||
private Long feeTypeId;
|
||||
|
||||
/**
|
||||
* 商品ID(可选)
|
||||
*/
|
||||
@Schema(description = "商品ID(可选)", example = "1")
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 类目ID(可选)
|
||||
*/
|
||||
@Schema(description = "类目ID(可选)", example = "1")
|
||||
private Long categoryId;
|
||||
|
||||
/**
|
||||
* 推广费发生日期开始
|
||||
*/
|
||||
@@ -47,4 +35,4 @@ public class PromotionFeeFilterDTO {
|
||||
*/
|
||||
@Schema(description = "推广费发生日期结束", example = "2024-01-31")
|
||||
private LocalDate feeDateEnd;
|
||||
}
|
||||
}
|
||||
+5
-25
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto;
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.adfee.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@@ -8,18 +8,11 @@ import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 更新推广费记录DTO
|
||||
* 创建广告费记录DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新推广费记录DTO")
|
||||
public class UpdatePromotionFeeDTO {
|
||||
|
||||
/**
|
||||
* 推广费记录ID
|
||||
*/
|
||||
@Schema(description = "推广费记录ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "推广费记录ID不能为空")
|
||||
private Long id;
|
||||
@Schema(description = "创建广告费记录DTO")
|
||||
public class CreateAdFeeDTO {
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
@@ -28,19 +21,6 @@ public class UpdatePromotionFeeDTO {
|
||||
@NotNull(message = "店铺ID不能为空")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 推广费类型ID
|
||||
*/
|
||||
@Schema(description = "推广费类型ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "推广费类型ID不能为空")
|
||||
private Long feeTypeId;
|
||||
|
||||
/**
|
||||
* 类目ID(可选,类目级推广费)
|
||||
*/
|
||||
@Schema(description = "类目ID(可选)", example = "1")
|
||||
private Long categoryId;
|
||||
|
||||
/**
|
||||
* 商品ID(可选,关联到具体商品)
|
||||
*/
|
||||
@@ -72,4 +52,4 @@ public class UpdatePromotionFeeDTO {
|
||||
*/
|
||||
@Schema(description = "备注", example = "双十一期间推广费用")
|
||||
private String remark;
|
||||
}
|
||||
}
|
||||
+12
-18
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto;
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.adfee.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@@ -8,11 +8,18 @@ import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 创建推广费记录DTO
|
||||
* 更新广告费记录DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建推广费记录DTO")
|
||||
public class CreatePromotionFeeDTO {
|
||||
@Schema(description = "更新广告费记录DTO")
|
||||
public class UpdateAdFeeDTO {
|
||||
|
||||
/**
|
||||
* 广告费记录ID
|
||||
*/
|
||||
@Schema(description = "广告费记录ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "广告费记录ID不能为空")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
@@ -21,19 +28,6 @@ public class CreatePromotionFeeDTO {
|
||||
@NotNull(message = "店铺ID不能为空")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 推广费类型ID
|
||||
*/
|
||||
@Schema(description = "推广费类型ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "推广费类型ID不能为空")
|
||||
private Long feeTypeId;
|
||||
|
||||
/**
|
||||
* 类目ID(可选,类目级推广费)
|
||||
*/
|
||||
@Schema(description = "类目ID(可选)", example = "1")
|
||||
private Long categoryId;
|
||||
|
||||
/**
|
||||
* 商品ID(可选,关联到具体商品)
|
||||
*/
|
||||
@@ -65,4 +59,4 @@ public class CreatePromotionFeeDTO {
|
||||
*/
|
||||
@Schema(description = "备注", example = "双十一期间推广费用")
|
||||
private String remark;
|
||||
}
|
||||
}
|
||||
+8
-20
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.model.po;
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.adfee.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
@@ -9,15 +9,15 @@ import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 电商-推广费记录实体
|
||||
* 电商-广告费记录实体(表 ec_ad_fee)
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("ec_promotion_fee")
|
||||
public class PromotionFeePO {
|
||||
@TableName("ec_ad_fee")
|
||||
public class AdFeePO {
|
||||
|
||||
/**
|
||||
* 推广费记录ID
|
||||
* 广告费记录ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
@@ -34,18 +34,6 @@ public class PromotionFeePO {
|
||||
@TableField("shop_id")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 类目ID(可选,无商品时可用于类目级推广费)
|
||||
*/
|
||||
@TableField("category_id")
|
||||
private Long categoryId;
|
||||
|
||||
/**
|
||||
* 推广费类型ID
|
||||
*/
|
||||
@TableField("fee_type_id")
|
||||
private Long feeTypeId;
|
||||
|
||||
/**
|
||||
* 商品ID(可选)
|
||||
*/
|
||||
@@ -53,19 +41,19 @@ public class PromotionFeePO {
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 推广活动名称
|
||||
* 广告活动名称
|
||||
*/
|
||||
@TableField("campaign_name")
|
||||
private String campaignName;
|
||||
|
||||
/**
|
||||
* 推广费金额
|
||||
* 广告费金额
|
||||
*/
|
||||
@TableField("fee_amount")
|
||||
private BigDecimal feeAmount;
|
||||
|
||||
/**
|
||||
* 推广费发生日期
|
||||
* 广告费发生日期
|
||||
*/
|
||||
@TableField("fee_date")
|
||||
private LocalDate feeDate;
|
||||
+5
-5
@@ -1,18 +1,18 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.adfee.model.vo;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PromotionFeeFieldConstants {
|
||||
public class AdFeeFieldConstants {
|
||||
|
||||
public static final List<PromotionFeeFieldVO> FIELDS = Arrays.asList(
|
||||
public static final List<AdFeeFieldVO> FIELDS = Arrays.asList(
|
||||
create("campaignName", "推广活动名称", "推广活动名称", true, 1, "string"),
|
||||
create("feeAmount", "推广费金额", "推广费金额(元)", true, 2, "number")
|
||||
);
|
||||
|
||||
private static PromotionFeeFieldVO create(String fieldName, String fieldLabel, String fileFieldName,
|
||||
private static AdFeeFieldVO create(String fieldName, String fieldLabel, String fileFieldName,
|
||||
boolean required, int sort, String dataType) {
|
||||
PromotionFeeFieldVO vo = new PromotionFeeFieldVO();
|
||||
AdFeeFieldVO vo = new AdFeeFieldVO();
|
||||
vo.setFieldName(fieldName);
|
||||
vo.setFieldLabel(fieldLabel);
|
||||
vo.setFileFieldName(fileFieldName);
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.adfee.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "推广费导入字段信息VO")
|
||||
public class PromotionFeeFieldVO {
|
||||
@Schema(description = "广告费导入字段信息VO")
|
||||
public class AdFeeFieldVO {
|
||||
|
||||
@Schema(description = "数据库字段名", example = "campaign_name")
|
||||
private String fieldName;
|
||||
+6
-30
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.adfee.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -8,16 +8,16 @@ import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 推广费记录VO
|
||||
* 广告费记录VO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "推广费记录VO")
|
||||
public class PromotionFeeVO {
|
||||
@Schema(description = "广告费记录VO")
|
||||
public class AdFeeVO {
|
||||
|
||||
/**
|
||||
* 推广费记录ID
|
||||
* 广告费记录ID
|
||||
*/
|
||||
@Schema(description = "推广费记录ID", example = "1")
|
||||
@Schema(description = "广告费记录ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
@@ -38,30 +38,6 @@ public class PromotionFeeVO {
|
||||
@Schema(description = "店铺名称", example = "旗舰店")
|
||||
private String shopName;
|
||||
|
||||
/**
|
||||
* 推广费类型ID
|
||||
*/
|
||||
@Schema(description = "推广费类型ID", example = "1")
|
||||
private Long feeTypeId;
|
||||
|
||||
/**
|
||||
* 推广费类型名称
|
||||
*/
|
||||
@Schema(description = "推广费类型名称", example = "直通车")
|
||||
private String feeTypeName;
|
||||
|
||||
/**
|
||||
* 类目ID(可选)
|
||||
*/
|
||||
@Schema(description = "类目ID(可选)", example = "1")
|
||||
private Long categoryId;
|
||||
|
||||
/**
|
||||
* 类目名称
|
||||
*/
|
||||
@Schema(description = "类目名称", example = "数码")
|
||||
private String categoryName;
|
||||
|
||||
/**
|
||||
* 商品ID(可选)
|
||||
*/
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.adfee.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.dto.CreateAdFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.dto.AdFeeFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.dto.UpdateAdFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.vo.AdFeeVO;
|
||||
|
||||
/**
|
||||
* 广告费记录服务接口
|
||||
*/
|
||||
public interface AdFeeService {
|
||||
|
||||
/**
|
||||
* 创建广告费记录
|
||||
*/
|
||||
Long createAdFee(CreateAdFeeDTO dto);
|
||||
|
||||
/**
|
||||
* 更新广告费记录
|
||||
*/
|
||||
void updateAdFee(UpdateAdFeeDTO dto);
|
||||
|
||||
/**
|
||||
* 删除广告费记录
|
||||
*/
|
||||
void deleteAdFee(Long id);
|
||||
|
||||
/**
|
||||
* 根据ID查询广告费记录
|
||||
*/
|
||||
AdFeeVO getAdFeeById(Long id);
|
||||
|
||||
/**
|
||||
* 分页查询广告费记录
|
||||
*/
|
||||
PageResultVO<AdFeeVO> getAdFeePage(PageQueryDTO<AdFeeFilterDTO> pageQueryDTO);
|
||||
}
|
||||
+94
-28
@@ -1,5 +1,6 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.service.impl;
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.adfee.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVParser;
|
||||
@@ -12,8 +13,8 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.importtask.model.po.ImportTaskPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.importtask.util.ImportTaskMessageAppender;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.mapper.PromotionFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.po.PromotionFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.mapper.AdFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.po.AdFeePO;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.BigDecimal;
|
||||
@@ -22,17 +23,18 @@ import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 推广费导入处理器
|
||||
* 广告费导入处理器
|
||||
* 负责解析 CSV/Excel 文件中的推广费数据,按字段映射提取 campaignName/feeAmount,
|
||||
* 从文件列中直接读取 feeTypeId/categoryId/productId,批量写入 ec_promotion_fee 表。
|
||||
* 从文件列中直接读取 productId,按 product_id + fee_date 联合唯一 upsert 写入 ec_ad_fee。
|
||||
*/
|
||||
@Service
|
||||
public class PromotionFeeImportProcessor extends ServiceImpl<PromotionFeeMapper, PromotionFeePO> {
|
||||
public class AdFeeImportProcessor extends ServiceImpl<AdFeeMapper, AdFeePO> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(PromotionFeeImportProcessor.class);
|
||||
/** 每批插入条数 */
|
||||
private static final Logger log = LoggerFactory.getLogger(AdFeeImportProcessor.class);
|
||||
/** 每批处理条数 */
|
||||
private static final int BATCH_SIZE = 500;
|
||||
/** 推广费金额不合规时的统一失败原因 */
|
||||
private static final String INVALID_FEE_AMOUNT_REASON = "推广费金额为空或须大于0";
|
||||
@@ -52,33 +54,99 @@ public class PromotionFeeImportProcessor extends ServiceImpl<PromotionFeeMapper,
|
||||
return new ImportResult(0, 0, 0, "文件中没有有效数据");
|
||||
}
|
||||
|
||||
List<AdFeePO> records = collapseByProductDate(parseResult.records);
|
||||
int success = 0;
|
||||
int insertFailCount = 0;
|
||||
int upsertFailCount = 0;
|
||||
ImportTaskMessageAppender detailMessages = parseResult.detailMessages;
|
||||
|
||||
for (int i = 0; i < parseResult.records.size(); i += BATCH_SIZE) {
|
||||
int end = Math.min(i + BATCH_SIZE, parseResult.records.size());
|
||||
List<PromotionFeePO> batch = parseResult.records.subList(i, end);
|
||||
for (int i = 0; i < records.size(); i += BATCH_SIZE) {
|
||||
int end = Math.min(i + BATCH_SIZE, records.size());
|
||||
List<AdFeePO> batch = records.subList(i, end);
|
||||
try {
|
||||
saveBatch(batch);
|
||||
success += batch.size();
|
||||
success += upsertBatch(batch);
|
||||
} catch (Exception e) {
|
||||
insertFailCount += batch.size();
|
||||
int startRow = parseResult.recordStartRows.get(i);
|
||||
int endRow = parseResult.recordStartRows.get(end - 1);
|
||||
detailMessages.appendDetailLine(String.format("第%d~%d行:批量插入失败,%s",
|
||||
startRow, endRow, e.getMessage()));
|
||||
log.error("批量插入推广费记录失败", e);
|
||||
upsertFailCount += batch.size();
|
||||
detailMessages.appendDetailLine(String.format("第%d~%d条:批量写入失败,%s",
|
||||
i + 1, end, e.getMessage()));
|
||||
log.error("批量写入广告费记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
return new ImportResult(
|
||||
parseResult.totalCount,
|
||||
success,
|
||||
parseResult.failCount + insertFailCount,
|
||||
parseResult.failCount + upsertFailCount,
|
||||
detailMessages.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* 同文件内相同 productId + feeDate 保留最后一行,避免撞唯一键。
|
||||
*/
|
||||
private List<AdFeePO> collapseByProductDate(List<AdFeePO> records) {
|
||||
LinkedHashMap<String, AdFeePO> withProduct = new LinkedHashMap<>();
|
||||
List<AdFeePO> withoutProduct = new ArrayList<>();
|
||||
for (AdFeePO po : records) {
|
||||
if (po.getProductId() == null) {
|
||||
withoutProduct.add(po);
|
||||
continue;
|
||||
}
|
||||
withProduct.put(po.getProductId() + "|" + po.getFeeDate(), po);
|
||||
}
|
||||
List<AdFeePO> result = new ArrayList<>(withProduct.values());
|
||||
result.addAll(withoutProduct);
|
||||
return result;
|
||||
}
|
||||
|
||||
private int upsertBatch(List<AdFeePO> batch) {
|
||||
if (batch.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
LocalDate feeDate = batch.get(0).getFeeDate();
|
||||
List<Long> productIds = batch.stream()
|
||||
.map(AdFeePO::getProductId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Map<Long, AdFeePO> existingByProduct = new HashMap<>();
|
||||
if (!productIds.isEmpty() && feeDate != null) {
|
||||
List<AdFeePO> existing = list(new LambdaQueryWrapper<AdFeePO>()
|
||||
.eq(AdFeePO::getFeeDate, feeDate)
|
||||
.in(AdFeePO::getProductId, productIds));
|
||||
for (AdFeePO po : existing) {
|
||||
existingByProduct.put(po.getProductId(), po);
|
||||
}
|
||||
}
|
||||
|
||||
List<AdFeePO> toInsert = new ArrayList<>();
|
||||
List<AdFeePO> toUpdate = new ArrayList<>();
|
||||
for (AdFeePO incoming : batch) {
|
||||
if (incoming.getProductId() == null) {
|
||||
toInsert.add(incoming);
|
||||
continue;
|
||||
}
|
||||
AdFeePO existing = existingByProduct.get(incoming.getProductId());
|
||||
if (existing == null) {
|
||||
toInsert.add(incoming);
|
||||
continue;
|
||||
}
|
||||
existing.setShopId(incoming.getShopId());
|
||||
existing.setCampaignName(incoming.getCampaignName());
|
||||
existing.setFeeAmount(incoming.getFeeAmount());
|
||||
existing.setRemark(incoming.getRemark());
|
||||
existing.setUpdateBy(incoming.getUpdateBy());
|
||||
toUpdate.add(existing);
|
||||
}
|
||||
|
||||
if (!toInsert.isEmpty()) {
|
||||
saveBatch(toInsert);
|
||||
}
|
||||
if (!toUpdate.isEmpty()) {
|
||||
updateBatchById(toUpdate);
|
||||
}
|
||||
return batch.size();
|
||||
}
|
||||
|
||||
private ParseResult parseCsv(File file, Charset charset,
|
||||
Map<String, String> fieldMapping, String feeDateStr,
|
||||
ImportTaskPO task) throws IOException {
|
||||
@@ -190,12 +258,10 @@ public class PromotionFeeImportProcessor extends ServiceImpl<PromotionFeeMapper,
|
||||
|
||||
BigDecimal feeAmount = new BigDecimal(normalizeFeeAmount(feeAmountStr));
|
||||
|
||||
PromotionFeePO po = new PromotionFeePO();
|
||||
AdFeePO po = new AdFeePO();
|
||||
po.setCompanyId(task.getCompanyId());
|
||||
po.setShopId(task.getShopId());
|
||||
po.setFeeDate(feeDate);
|
||||
po.setFeeTypeId(parseLong(cellGetter.apply("feeTypeId")));
|
||||
po.setCategoryId(parseLong(cellGetter.apply("categoryId")));
|
||||
po.setProductId(parseLong(cellGetter.apply("productId")));
|
||||
po.setCampaignName(campaignName);
|
||||
po.setFeeAmount(feeAmount);
|
||||
@@ -325,7 +391,7 @@ public class PromotionFeeImportProcessor extends ServiceImpl<PromotionFeeMapper,
|
||||
}
|
||||
|
||||
private static class ParseResult {
|
||||
final List<PromotionFeePO> records = new ArrayList<>();
|
||||
final List<AdFeePO> records = new ArrayList<>();
|
||||
/** 与 records 一一对应,用于插入失败时标注行号 */
|
||||
final List<Integer> recordStartRows = new ArrayList<>();
|
||||
final ImportTaskMessageAppender detailMessages = new ImportTaskMessageAppender();
|
||||
@@ -334,17 +400,17 @@ public class PromotionFeeImportProcessor extends ServiceImpl<PromotionFeeMapper,
|
||||
}
|
||||
|
||||
private static class RowBuildResult {
|
||||
final PromotionFeePO po;
|
||||
final AdFeePO po;
|
||||
final String failReason;
|
||||
final String campaignName;
|
||||
|
||||
private RowBuildResult(PromotionFeePO po, String failReason, String campaignName) {
|
||||
private RowBuildResult(AdFeePO po, String failReason, String campaignName) {
|
||||
this.po = po;
|
||||
this.failReason = failReason;
|
||||
this.campaignName = campaignName;
|
||||
}
|
||||
|
||||
static RowBuildResult ok(PromotionFeePO po) {
|
||||
static RowBuildResult ok(AdFeePO po) {
|
||||
return new RowBuildResult(po, null, null);
|
||||
}
|
||||
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.adfee.service.impl;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.mapper.AdFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.dto.CreateAdFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.dto.AdFeeFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.dto.UpdateAdFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.po.AdFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.model.vo.AdFeeVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.service.AdFeeService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 广告费记录服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class AdFeeServiceImpl implements AdFeeService {
|
||||
|
||||
private final AdFeeMapper adFeeMapper;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final ShopService shopService;
|
||||
private final ProductService productService;
|
||||
|
||||
public AdFeeServiceImpl(AdFeeMapper adFeeMapper,
|
||||
CurrentUserContext currentUserContext,
|
||||
ShopService shopService,
|
||||
ProductService productService) {
|
||||
this.adFeeMapper = adFeeMapper;
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.shopService = shopService;
|
||||
this.productService = productService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建广告费记录
|
||||
* @param dto 创建广告费记录DTO
|
||||
* @return 广告费记录ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createAdFee(CreateAdFeeDTO dto) {
|
||||
assertProductDateUnique(dto.getProductId(), dto.getFeeDate(), null);
|
||||
AdFeePO po = new AdFeePO();
|
||||
BeanCopyUtils.copyProperties(dto, po);
|
||||
po.setCompanyId(currentUserContext.getCurrentCompanyId());
|
||||
po.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
po.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
adFeeMapper.insert(po);
|
||||
return po.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新广告费记录
|
||||
* @param dto 更新广告费记录DTO
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateAdFee(UpdateAdFeeDTO dto) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
AdFeePO existing = adFeeMapper.selectById(dto.getId());
|
||||
if (existing == null || !existing.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("广告费记录不存在");
|
||||
}
|
||||
assertProductDateUnique(dto.getProductId(), dto.getFeeDate(), dto.getId());
|
||||
AdFeePO po = new AdFeePO();
|
||||
BeanCopyUtils.copyProperties(dto, po);
|
||||
po.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
po.setCompanyId(companyId);
|
||||
adFeeMapper.updateById(po);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除广告费记录
|
||||
* @param id 广告费记录ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAdFee(Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
AdFeePO existing = adFeeMapper.selectById(id);
|
||||
if (existing == null || !existing.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("广告费记录不存在");
|
||||
}
|
||||
adFeeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询广告费记录
|
||||
* @param id 广告费记录ID
|
||||
* @return 广告费记录VO
|
||||
*/
|
||||
@Override
|
||||
public AdFeeVO getAdFeeById(Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
AdFeePO po = adFeeMapper.selectById(id);
|
||||
if (po == null || !po.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("广告费记录不存在");
|
||||
}
|
||||
return convertToVO(po);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取广告费记录分页列表
|
||||
* @param pageQueryDTO 分页查询DTO
|
||||
* @return 分页结果VO
|
||||
*/
|
||||
@Override
|
||||
public PageResultVO<AdFeeVO> getAdFeePage(PageQueryDTO<AdFeeFilterDTO> pageQueryDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
Page<AdFeePO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
|
||||
LambdaQueryWrapper<AdFeePO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(AdFeePO::getCompanyId, companyId);
|
||||
|
||||
AdFeeFilterDTO filter = pageQueryDTO.getFilters();
|
||||
if (filter != null) {
|
||||
if (filter.getShopId() != null) {
|
||||
wrapper.eq(AdFeePO::getShopId, filter.getShopId());
|
||||
}
|
||||
if (filter.getProductId() != null) {
|
||||
wrapper.eq(AdFeePO::getProductId, filter.getProductId());
|
||||
}
|
||||
if (filter.getFeeDateStart() != null) {
|
||||
wrapper.ge(AdFeePO::getFeeDate, filter.getFeeDateStart());
|
||||
}
|
||||
if (filter.getFeeDateEnd() != null) {
|
||||
wrapper.le(AdFeePO::getFeeDate, filter.getFeeDateEnd());
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.orderByDesc(AdFeePO::getFeeDate)
|
||||
.orderByDesc(AdFeePO::getCreateTime);
|
||||
|
||||
IPage<AdFeePO> pageResult = adFeeMapper.selectPage(page, wrapper);
|
||||
|
||||
List<AdFeeVO> voList = pageResult.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*/
|
||||
private AdFeeVO convertToVO(AdFeePO po) {
|
||||
AdFeeVO vo = new AdFeeVO();
|
||||
BeanCopyUtils.copyProperties(po, vo);
|
||||
|
||||
// 填充店铺名称
|
||||
if (po.getShopId() != null) {
|
||||
try {
|
||||
var shop = shopService.getById(po.getShopId());
|
||||
if (shop != null) {
|
||||
vo.setShopName(shop.getName());
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// 填充商品名称和编码
|
||||
if (po.getProductId() != null) {
|
||||
try {
|
||||
ProductPO product = productService.getById(po.getProductId());
|
||||
if (product != null) {
|
||||
vo.setProductName(product.getName());
|
||||
vo.setProductCode(product.getProductCode());
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品 + 推广日期联合唯一(product_id 为空时不校验)
|
||||
*/
|
||||
private void assertProductDateUnique(Long productId, LocalDate feeDate, Long excludeId) {
|
||||
if (productId == null || feeDate == null) {
|
||||
return;
|
||||
}
|
||||
LambdaQueryWrapper<AdFeePO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(AdFeePO::getProductId, productId)
|
||||
.eq(AdFeePO::getFeeDate, feeDate);
|
||||
if (excludeId != null) {
|
||||
wrapper.ne(AdFeePO::getId, excludeId);
|
||||
}
|
||||
Long count = adFeeMapper.selectCount(wrapper);
|
||||
if (count != null && count > 0) {
|
||||
throw new BusinessException("该商品在此推广日期已存在广告费记录");
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -17,7 +17,7 @@ import top.xyquan.ecomdmbbackend.modules.ec.order.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.mapper.ProductMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductSkuCostService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductSkuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.service.impl.PromotionFeeImportProcessor;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.adfee.service.impl.AdFeeImportProcessor;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.mapper.ShopProductRelationMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.service.OssService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.service.SysFileService;
|
||||
@@ -52,7 +52,7 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
|
||||
// 提取出的处理器(构造时组装,不单独持有 helper 的中间依赖)
|
||||
private final OrderImportProcessor orderImportProcessor;
|
||||
private final PromotionFeeImportProcessor promotionFeeImportProcessor;
|
||||
private final AdFeeImportProcessor adFeeImportProcessor;
|
||||
private final LicenseFeatureGuard licenseFeatureGuard;
|
||||
|
||||
public ImportTaskProcessorServiceImpl(ImportTaskService importTaskService,
|
||||
@@ -67,7 +67,7 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
SqlSessionFactory sqlSessionFactory,
|
||||
OssService ossService,
|
||||
SysFileService sysFileService,
|
||||
PromotionFeeImportProcessor promotionFeeImportProcessor,
|
||||
AdFeeImportProcessor adFeeImportProcessor,
|
||||
LicenseFeatureGuard licenseFeatureGuard) {
|
||||
this.importTaskService = importTaskService;
|
||||
this.licenseFeatureGuard = licenseFeatureGuard;
|
||||
@@ -76,7 +76,7 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
this.objectMapper = objectMapper;
|
||||
this.ossService = ossService;
|
||||
this.sysFileService = sysFileService;
|
||||
this.promotionFeeImportProcessor = promotionFeeImportProcessor;
|
||||
this.adFeeImportProcessor = adFeeImportProcessor;
|
||||
|
||||
ProductSkuImportHelper productSkuImportHelper = new ProductSkuImportHelper(
|
||||
productMapper, productSkuService, productSkuCostService, shopProductRelationMapper);
|
||||
@@ -101,7 +101,7 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
} else if ("product".equals(task.getType())) {
|
||||
updateTaskStatus(taskId, "failed", "商品导入功能暂未实现", 0, 0, 0);
|
||||
} else if ("promotion_record".equals(task.getType())) {
|
||||
processPromotionFeeImport(task);
|
||||
processAdFeeImport(task);
|
||||
} else {
|
||||
throw new BusinessException("不支持的导入类型: " + task.getType());
|
||||
}
|
||||
@@ -209,7 +209,7 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
}
|
||||
}
|
||||
|
||||
private void processPromotionFeeImport(ImportTaskPO task) throws Exception {
|
||||
private void processAdFeeImport(ImportTaskPO task) throws Exception {
|
||||
com.fasterxml.jackson.databind.JsonNode rootNode;
|
||||
try {
|
||||
rootNode = objectMapper.readTree(task.getMapping());
|
||||
@@ -250,7 +250,7 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
csvFile = localFile;
|
||||
} else {
|
||||
String fileExt = isExcel ? (filename.toLowerCase().endsWith(".xlsx") ? ".xlsx" : ".xls") : ".csv";
|
||||
tempOssFile = java.io.File.createTempFile("import-promotion-fee-", fileExt);
|
||||
tempOssFile = java.io.File.createTempFile("import-ad-fee-", fileExt);
|
||||
if (!ossService.downloadFile(storagePath, tempOssFile)) {
|
||||
throw new BusinessException("从对象存储下载文件失败");
|
||||
}
|
||||
@@ -259,10 +259,10 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
|
||||
// 前端 wizard 生成的 patched CSV 固定为 UTF-8,避免被误判为 GBK 导致表头乱码
|
||||
boolean isPatchedPromotionCsv = filename != null
|
||||
&& filename.toLowerCase().contains("promotion_fee_import_patched");
|
||||
&& filename.toLowerCase().contains("ad_fee_import_patched");
|
||||
Charset charset = isExcel || isPatchedPromotionCsv ? StandardCharsets.UTF_8
|
||||
: detectFileEncoding(new java.io.BufferedInputStream(new java.io.FileInputStream(csvFile)));
|
||||
PromotionFeeImportProcessor.ImportResult result = promotionFeeImportProcessor.processImport(
|
||||
AdFeeImportProcessor.ImportResult result = adFeeImportProcessor.processImport(
|
||||
task, csvFile, charset, fieldMapping, feeDateStr);
|
||||
|
||||
String finalStatus = result.failCount == 0 ? "success" : (result.successCount > 0 ? "success" : "failed");
|
||||
|
||||
-83
@@ -1,83 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.CreatePromotionFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.PromotionFeeFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.UpdatePromotionFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.PromotionFeeFieldVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.PromotionFeeFieldConstants;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.PromotionFeeVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.service.PromotionFeeService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 推广费记录控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/ec/promotion-fee")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "电商-推广费记录管理", description = "推广费记录相关接口")
|
||||
public class PromotionFeeController {
|
||||
|
||||
private final PromotionFeeService promotionFeeService;
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "创建推广费记录", description = "创建新的推广费记录")
|
||||
@RequirePermission(value = "ec:order:create", description = "创建推广费记录", allowSuper = true)
|
||||
public ApiResponse<Long> createPromotionFee(@Valid @RequestBody CreatePromotionFeeDTO dto) {
|
||||
Long id = promotionFeeService.createPromotionFee(dto);
|
||||
return ApiResponse.success("推广费记录创建成功", id);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "更新推广费记录", description = "更新推广费记录信息")
|
||||
@RequirePermission(value = "ec:order:update", description = "更新推广费记录", allowSuper = true)
|
||||
public ApiResponse<Void> updatePromotionFee(@Valid @RequestBody UpdatePromotionFeeDTO dto) {
|
||||
promotionFeeService.updatePromotionFee(dto);
|
||||
return ApiResponse.success("推广费记录更新成功");
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@Operation(summary = "删除推广费记录", description = "删除指定的推广费记录")
|
||||
@RequirePermission(value = "ec:order:delete", description = "删除推广费记录", allowSuper = true)
|
||||
public ApiResponse<Void> deletePromotionFee(
|
||||
@Parameter(description = "记录ID", required = true) @PathVariable Long id) {
|
||||
promotionFeeService.deletePromotionFee(id);
|
||||
return ApiResponse.success("推广费记录删除成功");
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@Operation(summary = "查询推广费记录详情", description = "根据ID查询推广费记录详情")
|
||||
@RequirePermission(value = "ec:order:read", description = "查询推广费记录详情", allowSuper = true)
|
||||
public ApiResponse<PromotionFeeVO> getPromotionFeeById(
|
||||
@Parameter(description = "记录ID", required = true) @PathVariable Long id) {
|
||||
PromotionFeeVO vo = promotionFeeService.getPromotionFeeById(id);
|
||||
return ApiResponse.success("获取推广费记录详情成功", vo);
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "分页查询推广费记录", description = "分页查询推广费记录列表")
|
||||
@RequirePermission(value = "ec:order:read", description = "查询推广费记录列表", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<PromotionFeeVO>> getPromotionFeePage(
|
||||
@Valid @RequestBody PageQueryDTO<PromotionFeeFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<PromotionFeeVO> result = promotionFeeService.getPromotionFeePage(pageQueryDTO);
|
||||
return ApiResponse.success("获取推广费记录列表成功", result);
|
||||
}
|
||||
|
||||
@GetMapping("/fields")
|
||||
@Operation(summary = "获取推广费导入字段定义", description = "获取推广费导入时可映射的系统字段列表")
|
||||
@RequirePermission(value = "ec:order:read", description = "查询导入字段", allowSuper = true)
|
||||
public ApiResponse<List<PromotionFeeFieldVO>> getPromotionFeeFields() {
|
||||
return ApiResponse.success("获取推广费导入字段成功", PromotionFeeFieldConstants.FIELDS);
|
||||
}
|
||||
}
|
||||
-86
@@ -1,86 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.CreatePromotionFeeTypeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.UpdatePromotionFeeTypeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.PromotionFeeTypeVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.service.PromotionFeeTypeService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 推广费类型控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/ec/promotion-fee-type")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "电商-推广费类型管理", description = "推广费类型相关接口")
|
||||
public class PromotionFeeTypeController {
|
||||
|
||||
private final PromotionFeeTypeService promotionFeeTypeService;
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "创建推广费类型", description = "创建新的推广费类型")
|
||||
@RequirePermission(value = "ec:order:create", description = "创建推广费类型", allowSuper = true)
|
||||
public ApiResponse<Long> createPromotionFeeType(@Valid @RequestBody CreatePromotionFeeTypeDTO dto) {
|
||||
Long id = promotionFeeTypeService.createPromotionFeeType(dto);
|
||||
return ApiResponse.success("推广费类型创建成功", id);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "更新推广费类型", description = "更新推广费类型信息")
|
||||
@RequirePermission(value = "ec:order:update", description = "更新推广费类型", allowSuper = true)
|
||||
public ApiResponse<Void> updatePromotionFeeType(@Valid @RequestBody UpdatePromotionFeeTypeDTO dto) {
|
||||
promotionFeeTypeService.updatePromotionFeeType(dto);
|
||||
return ApiResponse.success("推广费类型更新成功");
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@Operation(summary = "删除推广费类型", description = "删除指定的推广费类型")
|
||||
@RequirePermission(value = "ec:order:delete", description = "删除推广费类型", allowSuper = true)
|
||||
public ApiResponse<Void> deletePromotionFeeType(
|
||||
@Parameter(description = "类型ID", required = true) @PathVariable Long id) {
|
||||
promotionFeeTypeService.deletePromotionFeeType(id);
|
||||
return ApiResponse.success("推广费类型删除成功");
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@Operation(summary = "查询推广费类型详情", description = "根据ID查询推广费类型详情")
|
||||
@RequirePermission(value = "ec:order:read", description = "查询推广费类型详情", allowSuper = true)
|
||||
public ApiResponse<PromotionFeeTypeVO> getPromotionFeeTypeById(
|
||||
@Parameter(description = "类型ID", required = true) @PathVariable Long id) {
|
||||
PromotionFeeTypeVO vo = promotionFeeTypeService.getPromotionFeeTypeById(id);
|
||||
return ApiResponse.success("获取推广费类型详情成功", vo);
|
||||
}
|
||||
|
||||
@GetMapping("/active")
|
||||
@Operation(summary = "查询启用的推广费类型列表", description = "查询所有启用的推广费类型")
|
||||
@RequirePermission(value = "ec:order:read", description = "查询启用的推广费类型", allowSuper = true)
|
||||
public ApiResponse<List<PromotionFeeTypeVO>> getActivePromotionFeeTypeList() {
|
||||
List<PromotionFeeTypeVO> list = promotionFeeTypeService.getActivePromotionFeeTypeList();
|
||||
return ApiResponse.success("获取启用的推广费类型列表成功", list);
|
||||
}
|
||||
|
||||
@GetMapping("/all")
|
||||
@Operation(summary = "查询所有推广费类型列表", description = "查询所有推广费类型(包括禁用的)")
|
||||
@RequirePermission(value = "ec:order:read", description = "查询所有推广费类型", allowSuper = true)
|
||||
public ApiResponse<List<PromotionFeeTypeVO>> getAllPromotionFeeTypeList() {
|
||||
List<PromotionFeeTypeVO> list = promotionFeeTypeService.getAllPromotionFeeTypeList();
|
||||
return ApiResponse.success("获取所有推广费类型列表成功", list);
|
||||
}
|
||||
|
||||
@PostMapping("/init")
|
||||
@Operation(summary = "初始化推广费类型数据", description = "为当前公司初始化默认的推广费类型数据")
|
||||
@RequirePermission(value = "ec:order:create", description = "初始化推广费类型", allowSuper = true)
|
||||
public ApiResponse<Void> initPromotionFeeType() {
|
||||
promotionFeeTypeService.initPromotionFeeTypeForCurrentCompany();
|
||||
return ApiResponse.success("推广费类型初始化成功");
|
||||
}
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.po.PromotionFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.PromotionFeeFilterDTO;
|
||||
|
||||
/**
|
||||
* 推广费记录Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface PromotionFeeMapper extends BaseMapper<PromotionFeePO> {
|
||||
|
||||
/**
|
||||
* 分页查询推广费记录
|
||||
*/
|
||||
IPage<PromotionFeePO> selectPageWithFilter(Page<PromotionFeePO> page, @Param("filter") PromotionFeeFilterDTO filter);
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.po.PromotionFeeTypePO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 推广费类型Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface PromotionFeeTypeMapper extends BaseMapper<PromotionFeeTypePO> {
|
||||
|
||||
/**
|
||||
* 查询启用的推广费类型列表
|
||||
*/
|
||||
List<PromotionFeeTypePO> selectActiveTypeList();
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(description = "批量导入推广费 DTO")
|
||||
public class BatchImportPromotionFeeDTO {
|
||||
|
||||
@NotEmpty(message = "推广费记录不能为空")
|
||||
@Valid
|
||||
@Schema(description = "推广费记录列表")
|
||||
private List<CreatePromotionFeeDTO> items;
|
||||
}
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建推广费类型DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建推广费类型DTO")
|
||||
public class CreatePromotionFeeTypeDTO {
|
||||
|
||||
/**
|
||||
* 类型名称
|
||||
*/
|
||||
@Schema(description = "类型名称", example = "直通车", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "类型名称不能为空")
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 类型描述
|
||||
*/
|
||||
@Schema(description = "类型描述", example = "淘宝直通车推广费用")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 计算方式 1固定金额 2按比例 3按点击 4按展示
|
||||
*/
|
||||
@Schema(description = "计算方式", example = "1", allowableValues = {"1", "2", "3", "4"})
|
||||
private Integer calculationMethod;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否启用 0禁用 1启用
|
||||
*/
|
||||
@Schema(description = "是否启用", example = "1", allowableValues = {"0", "1"})
|
||||
private Integer isActive;
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 更新推广费类型DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新推广费类型DTO")
|
||||
public class UpdatePromotionFeeTypeDTO {
|
||||
|
||||
/**
|
||||
* 推广费类型ID
|
||||
*/
|
||||
@Schema(description = "推广费类型ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "推广费类型ID不能为空")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 类型编码
|
||||
*/
|
||||
@Schema(description = "类型编码", example = "DIRECT_TRAFFIC", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "类型编码不能为空")
|
||||
private String typeCode;
|
||||
|
||||
/**
|
||||
* 类型名称
|
||||
*/
|
||||
@Schema(description = "类型名称", example = "直通车", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "类型名称不能为空")
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 类型描述
|
||||
*/
|
||||
@Schema(description = "类型描述", example = "淘宝直通车推广费用")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 计算方式 1固定金额 2按比例 3按点击 4按展示
|
||||
*/
|
||||
@Schema(description = "计算方式", example = "1", allowableValues = {"1", "2", "3", "4"})
|
||||
private Integer calculationMethod;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否启用 0禁用 1启用
|
||||
*/
|
||||
@Schema(description = "是否启用", example = "1", allowableValues = {"0", "1"})
|
||||
private Integer isActive;
|
||||
}
|
||||
-82
@@ -1,82 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 电商-推广费类型实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("ec_promotion_fee_type")
|
||||
public class PromotionFeeTypePO {
|
||||
|
||||
/**
|
||||
* 推广费类型ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 公司ID
|
||||
*/
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 类型名称
|
||||
*/
|
||||
@TableField("type_name")
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 类型描述
|
||||
*/
|
||||
@TableField("description")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 计算方式 1固定金额 2按比例 3按点击 4按展示
|
||||
*/
|
||||
@TableField("calculation_method")
|
||||
private Integer calculationMethod;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@TableField("sort_order")
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否启用 0禁用 1启用
|
||||
*/
|
||||
@TableField("is_active")
|
||||
private Integer isActive;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(description = "推广费批量导入结果")
|
||||
public class BatchImportPromotionFeeResultVO {
|
||||
|
||||
@Schema(description = "总数量")
|
||||
private Integer totalCount;
|
||||
|
||||
@Schema(description = "成功数量")
|
||||
private Integer successCount;
|
||||
|
||||
@Schema(description = "失败数量")
|
||||
private Integer failureCount;
|
||||
|
||||
@Schema(description = "成功创建的记录ID")
|
||||
private List<Long> successIds;
|
||||
|
||||
@Schema(description = "失败记录")
|
||||
private List<ImportFailureRecord> failureRecords;
|
||||
|
||||
@Data
|
||||
@Schema(description = "导入失败记录")
|
||||
public static class ImportFailureRecord {
|
||||
|
||||
@Schema(description = "失败行号")
|
||||
private Integer rowNumber;
|
||||
|
||||
@Schema(description = "店铺ID")
|
||||
private Long shopId;
|
||||
|
||||
@Schema(description = "失败原因")
|
||||
private String failureReason;
|
||||
}
|
||||
}
|
||||
-92
@@ -1,92 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 推广费类型VO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "推广费类型VO")
|
||||
public class PromotionFeeTypeVO {
|
||||
|
||||
/**
|
||||
* 推广费类型ID
|
||||
*/
|
||||
@Schema(description = "推广费类型ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 公司ID
|
||||
*/
|
||||
@Schema(description = "公司ID", example = "1")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 类型编码
|
||||
*/
|
||||
@Schema(description = "类型编码", example = "DIRECT_TRAFFIC")
|
||||
private String typeCode;
|
||||
|
||||
/**
|
||||
* 类型名称
|
||||
*/
|
||||
@Schema(description = "类型名称", example = "直通车")
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 类型描述
|
||||
*/
|
||||
@Schema(description = "类型描述", example = "淘宝直通车推广费用")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 计算方式 1固定金额 2按比例 3按点击 4按展示
|
||||
*/
|
||||
@Schema(description = "计算方式", example = "1")
|
||||
private Integer calculationMethod;
|
||||
|
||||
/**
|
||||
* 计算方式描述
|
||||
*/
|
||||
@Schema(description = "计算方式描述", example = "按点击")
|
||||
private String calculationMethodDesc;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否启用 0禁用 1启用
|
||||
*/
|
||||
@Schema(description = "是否启用", example = "1")
|
||||
private Integer isActive;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间", example = "2024-01-01T10:00:00")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间", example = "2024-01-01T10:00:00")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@Schema(description = "创建人ID", example = "1")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@Schema(description = "更新人ID", example = "1")
|
||||
private Long updateBy;
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.BatchImportPromotionFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.CreatePromotionFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.PromotionFeeFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.UpdatePromotionFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.BatchImportPromotionFeeResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.PromotionFeeVO;
|
||||
|
||||
/**
|
||||
* 推广费记录服务接口
|
||||
*/
|
||||
public interface PromotionFeeService {
|
||||
|
||||
/**
|
||||
* 创建推广费记录
|
||||
*/
|
||||
Long createPromotionFee(CreatePromotionFeeDTO dto);
|
||||
|
||||
/**
|
||||
* 更新推广费记录
|
||||
*/
|
||||
void updatePromotionFee(UpdatePromotionFeeDTO dto);
|
||||
|
||||
/**
|
||||
* 删除推广费记录
|
||||
*/
|
||||
void deletePromotionFee(Long id);
|
||||
|
||||
/**
|
||||
* 根据ID查询推广费记录
|
||||
*/
|
||||
PromotionFeeVO getPromotionFeeById(Long id);
|
||||
|
||||
/**
|
||||
* 分页查询推广费记录
|
||||
*/
|
||||
PageResultVO<PromotionFeeVO> getPromotionFeePage(PageQueryDTO<PromotionFeeFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 批量导入推广费记录
|
||||
*/
|
||||
BatchImportPromotionFeeResultVO batchImportPromotionFees(BatchImportPromotionFeeDTO dto);
|
||||
}
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.CreatePromotionFeeTypeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.UpdatePromotionFeeTypeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.PromotionFeeTypeVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 推广费类型服务接口
|
||||
*/
|
||||
public interface PromotionFeeTypeService {
|
||||
|
||||
/**
|
||||
* 创建推广费类型
|
||||
*/
|
||||
Long createPromotionFeeType(CreatePromotionFeeTypeDTO dto);
|
||||
|
||||
/**
|
||||
* 更新推广费类型
|
||||
*/
|
||||
void updatePromotionFeeType(UpdatePromotionFeeTypeDTO dto);
|
||||
|
||||
/**
|
||||
* 删除推广费类型
|
||||
*/
|
||||
void deletePromotionFeeType(Long id);
|
||||
|
||||
/**
|
||||
* 根据ID查询推广费类型
|
||||
*/
|
||||
PromotionFeeTypeVO getPromotionFeeTypeById(Long id);
|
||||
|
||||
/**
|
||||
* 查询启用的推广费类型列表
|
||||
*/
|
||||
List<PromotionFeeTypeVO> getActivePromotionFeeTypeList();
|
||||
|
||||
/**
|
||||
* 查询所有推广费类型列表
|
||||
*/
|
||||
List<PromotionFeeTypeVO> getAllPromotionFeeTypeList();
|
||||
|
||||
/**
|
||||
* 初始化公司推广费类型数据
|
||||
*/
|
||||
void initPromotionFeeTypeForCompany(Long companyId);
|
||||
|
||||
/**
|
||||
* 初始化公司推广费类型数据(指定创建人)
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
* @param creatorId 创建人ID
|
||||
*/
|
||||
void initPromotionFeeTypeForCompany(Long companyId, Long creatorId);
|
||||
|
||||
/**
|
||||
* 初始化当前公司推广费类型数据
|
||||
*/
|
||||
void initPromotionFeeTypeForCurrentCompany();
|
||||
}
|
||||
-289
@@ -1,289 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.service.impl;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.mapper.PromotionFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.BatchImportPromotionFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.CreatePromotionFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.PromotionFeeFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.UpdatePromotionFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.po.PromotionFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.BatchImportPromotionFeeResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.PromotionFeeVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.service.PromotionFeeService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.service.PromotionFeeTypeService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.category.model.po.CategoryPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.category.service.CategoryService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 推广费记录服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class PromotionFeeServiceImpl implements PromotionFeeService {
|
||||
|
||||
private final PromotionFeeMapper promotionFeeMapper;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final ShopService shopService;
|
||||
private final PromotionFeeTypeService promotionFeeTypeService;
|
||||
private final ProductService productService;
|
||||
private final CategoryService categoryService;
|
||||
|
||||
public PromotionFeeServiceImpl(PromotionFeeMapper promotionFeeMapper,
|
||||
CurrentUserContext currentUserContext,
|
||||
ShopService shopService,
|
||||
PromotionFeeTypeService promotionFeeTypeService,
|
||||
ProductService productService,
|
||||
CategoryService categoryService) {
|
||||
this.promotionFeeMapper = promotionFeeMapper;
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.shopService = shopService;
|
||||
this.promotionFeeTypeService = promotionFeeTypeService;
|
||||
this.productService = productService;
|
||||
this.categoryService = categoryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建推广费记录
|
||||
* @param dto 创建推广费记录DTO
|
||||
* @return 推广费记录ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createPromotionFee(CreatePromotionFeeDTO dto) {
|
||||
assertOptionalCategoryInCompany(dto.getCategoryId());
|
||||
PromotionFeePO po = new PromotionFeePO();
|
||||
BeanCopyUtils.copyProperties(dto, po);
|
||||
po.setCompanyId(currentUserContext.getCurrentCompanyId());
|
||||
po.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
po.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
promotionFeeMapper.insert(po);
|
||||
return po.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新推广费记录
|
||||
* @param dto 更新推广费记录DTO
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updatePromotionFee(UpdatePromotionFeeDTO dto) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
PromotionFeePO existing = promotionFeeMapper.selectById(dto.getId());
|
||||
if (existing == null || !existing.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("推广费记录不存在");
|
||||
}
|
||||
assertOptionalCategoryInCompany(dto.getCategoryId());
|
||||
PromotionFeePO po = new PromotionFeePO();
|
||||
BeanCopyUtils.copyProperties(dto, po);
|
||||
po.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
po.setCompanyId(companyId);
|
||||
promotionFeeMapper.updateById(po);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除推广费记录
|
||||
* @param id 推广费记录ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deletePromotionFee(Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
PromotionFeePO existing = promotionFeeMapper.selectById(id);
|
||||
if (existing == null || !existing.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("推广费记录不存在");
|
||||
}
|
||||
promotionFeeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询推广费记录
|
||||
* @param id 推广费记录ID
|
||||
* @return 推广费记录VO
|
||||
*/
|
||||
@Override
|
||||
public PromotionFeeVO getPromotionFeeById(Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
PromotionFeePO po = promotionFeeMapper.selectById(id);
|
||||
if (po == null || !po.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("推广费记录不存在");
|
||||
}
|
||||
return convertToVO(po);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取推广费记录分页列表
|
||||
* @param pageQueryDTO 分页查询DTO
|
||||
* @return 分页结果VO
|
||||
*/
|
||||
@Override
|
||||
public PageResultVO<PromotionFeeVO> getPromotionFeePage(PageQueryDTO<PromotionFeeFilterDTO> pageQueryDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
Page<PromotionFeePO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
|
||||
LambdaQueryWrapper<PromotionFeePO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PromotionFeePO::getCompanyId, companyId);
|
||||
|
||||
PromotionFeeFilterDTO filter = pageQueryDTO.getFilters();
|
||||
if (filter != null) {
|
||||
if (filter.getShopId() != null) {
|
||||
wrapper.eq(PromotionFeePO::getShopId, filter.getShopId());
|
||||
}
|
||||
if (filter.getFeeTypeId() != null) {
|
||||
wrapper.eq(PromotionFeePO::getFeeTypeId, filter.getFeeTypeId());
|
||||
}
|
||||
if (filter.getProductId() != null) {
|
||||
wrapper.eq(PromotionFeePO::getProductId, filter.getProductId());
|
||||
}
|
||||
if (filter.getCategoryId() != null) {
|
||||
wrapper.eq(PromotionFeePO::getCategoryId, filter.getCategoryId());
|
||||
}
|
||||
if (filter.getFeeDateStart() != null) {
|
||||
wrapper.ge(PromotionFeePO::getFeeDate, filter.getFeeDateStart());
|
||||
}
|
||||
if (filter.getFeeDateEnd() != null) {
|
||||
wrapper.le(PromotionFeePO::getFeeDate, filter.getFeeDateEnd());
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.orderByDesc(PromotionFeePO::getFeeDate)
|
||||
.orderByDesc(PromotionFeePO::getCreateTime);
|
||||
|
||||
IPage<PromotionFeePO> pageResult = promotionFeeMapper.selectPage(page, wrapper);
|
||||
|
||||
List<PromotionFeeVO> voList = pageResult.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*/
|
||||
private PromotionFeeVO convertToVO(PromotionFeePO po) {
|
||||
PromotionFeeVO vo = new PromotionFeeVO();
|
||||
BeanCopyUtils.copyProperties(po, vo);
|
||||
|
||||
// 填充店铺名称
|
||||
if (po.getShopId() != null) {
|
||||
try {
|
||||
var shop = shopService.getById(po.getShopId());
|
||||
if (shop != null) {
|
||||
vo.setShopName(shop.getName());
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// 填充推广费类型名称
|
||||
if (po.getFeeTypeId() != null) {
|
||||
try {
|
||||
var feeTypeVO = promotionFeeTypeService.getPromotionFeeTypeById(po.getFeeTypeId());
|
||||
if (feeTypeVO != null) {
|
||||
vo.setFeeTypeName(feeTypeVO.getTypeName());
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// 填充商品名称和编码
|
||||
if (po.getProductId() != null) {
|
||||
try {
|
||||
ProductPO product = productService.getById(po.getProductId());
|
||||
if (product != null) {
|
||||
vo.setProductName(product.getName());
|
||||
vo.setProductCode(product.getProductCode());
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (po.getCategoryId() != null) {
|
||||
try {
|
||||
CategoryPO category = categoryService.getById(po.getCategoryId());
|
||||
if (category != null) {
|
||||
vo.setCategoryName(category.getName());
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} else if (po.getProductId() != null) {
|
||||
// 列表/详情展示:记录未选类目时,带出商品所属类目(便于与「仅选商品」的旧数据对齐)
|
||||
try {
|
||||
ProductPO p = productService.getById(po.getProductId());
|
||||
if (p != null && p.getCategoryId() != null) {
|
||||
vo.setCategoryId(p.getCategoryId());
|
||||
CategoryPO category = categoryService.getById(p.getCategoryId());
|
||||
if (category != null) {
|
||||
vo.setCategoryName(category.getName());
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public BatchImportPromotionFeeResultVO batchImportPromotionFees(BatchImportPromotionFeeDTO dto) {
|
||||
List<CreatePromotionFeeDTO> items = dto.getItems();
|
||||
List<Long> successIds = new ArrayList<>();
|
||||
List<BatchImportPromotionFeeResultVO.ImportFailureRecord> failureRecords = new ArrayList<>();
|
||||
|
||||
int successCount = 0;
|
||||
int failureCount = 0;
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
CreatePromotionFeeDTO item = items.get(i);
|
||||
try {
|
||||
Long id = createPromotionFee(item);
|
||||
successIds.add(id);
|
||||
successCount++;
|
||||
} catch (Exception e) {
|
||||
BatchImportPromotionFeeResultVO.ImportFailureRecord record =
|
||||
new BatchImportPromotionFeeResultVO.ImportFailureRecord();
|
||||
record.setRowNumber(i + 1);
|
||||
record.setShopId(item.getShopId());
|
||||
record.setFailureReason(e.getMessage());
|
||||
failureRecords.add(record);
|
||||
failureCount++;
|
||||
}
|
||||
}
|
||||
|
||||
BatchImportPromotionFeeResultVO result = new BatchImportPromotionFeeResultVO();
|
||||
result.setTotalCount(items.size());
|
||||
result.setSuccessCount(successCount);
|
||||
result.setFailureCount(failureCount);
|
||||
result.setSuccessIds(successIds);
|
||||
result.setFailureRecords(failureRecords);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void assertOptionalCategoryInCompany(Long categoryId) {
|
||||
if (categoryId == null) {
|
||||
return;
|
||||
}
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
CategoryPO category = categoryService.getById(categoryId);
|
||||
if (category == null || !companyId.equals(category.getCompanyId())) {
|
||||
throw new BusinessException("类目不存在或不属于当前公司");
|
||||
}
|
||||
}
|
||||
}
|
||||
-276
@@ -1,276 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.promotion.service.impl;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.mapper.PromotionFeeTypeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.CreatePromotionFeeTypeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.UpdatePromotionFeeTypeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.po.PromotionFeeTypePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.PromotionFeeTypeVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.service.PromotionFeeTypeService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 推广费类型服务实现类
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
|
||||
|
||||
private final PromotionFeeTypeMapper promotionFeeTypeMapper;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
/**
|
||||
* 创建推广费类型
|
||||
* @param dto 创建推广费类型DTO
|
||||
* @return 推广费类型ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createPromotionFeeType(CreatePromotionFeeTypeDTO dto) {
|
||||
// 检查类型名称是否重复
|
||||
LambdaQueryWrapper<PromotionFeeTypePO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PromotionFeeTypePO::getCompanyId, currentUserContext.getCurrentCompanyId())
|
||||
.eq(PromotionFeeTypePO::getTypeName, dto.getTypeName());
|
||||
if (promotionFeeTypeMapper.selectCount(wrapper) > 0) {
|
||||
throw new RuntimeException("该类型名称已存在");
|
||||
}
|
||||
|
||||
PromotionFeeTypePO po = new PromotionFeeTypePO();
|
||||
BeanCopyUtils.copyProperties(dto, po);
|
||||
po.setCompanyId(currentUserContext.getCurrentCompanyId());
|
||||
po.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
po.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
promotionFeeTypeMapper.insert(po);
|
||||
return po.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新推广费类型
|
||||
* @param dto 更新推广费类型DTO
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updatePromotionFeeType(UpdatePromotionFeeTypeDTO dto) {
|
||||
PromotionFeeTypePO po = new PromotionFeeTypePO();
|
||||
BeanCopyUtils.copyProperties(dto, po);
|
||||
po.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
promotionFeeTypeMapper.updateById(po);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除推广费类型
|
||||
* @param id 推广费类型ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deletePromotionFeeType(Long id) {
|
||||
// 硬删除推广费类型(外键约束会自动处理相关数据)
|
||||
promotionFeeTypeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询推广费类型
|
||||
* @param id 推广费类型ID
|
||||
* @return 推广费类型VO
|
||||
*/
|
||||
@Override
|
||||
public PromotionFeeTypeVO getPromotionFeeTypeById(Long id) {
|
||||
PromotionFeeTypePO po = promotionFeeTypeMapper.selectById(id);
|
||||
if (po == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PromotionFeeTypeVO vo = new PromotionFeeTypeVO();
|
||||
BeanCopyUtils.copyProperties(po, vo);
|
||||
|
||||
// 设置计算方式描述
|
||||
if (po.getCalculationMethod() != null) {
|
||||
switch (po.getCalculationMethod()) {
|
||||
case 1:
|
||||
vo.setCalculationMethodDesc("固定金额");
|
||||
break;
|
||||
case 2:
|
||||
vo.setCalculationMethodDesc("按比例");
|
||||
break;
|
||||
case 3:
|
||||
vo.setCalculationMethodDesc("按点击");
|
||||
break;
|
||||
case 4:
|
||||
vo.setCalculationMethodDesc("按展示");
|
||||
break;
|
||||
default:
|
||||
vo.setCalculationMethodDesc("未知");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有启用的推广费类型列表
|
||||
* @return 推广费类型VO列表
|
||||
*/
|
||||
@Override
|
||||
public List<PromotionFeeTypeVO> getActivePromotionFeeTypeList() {
|
||||
LambdaQueryWrapper<PromotionFeeTypePO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PromotionFeeTypePO::getCompanyId, currentUserContext.getCurrentCompanyId())
|
||||
.eq(PromotionFeeTypePO::getIsActive, 1)
|
||||
.orderByAsc(PromotionFeeTypePO::getSortOrder);
|
||||
|
||||
List<PromotionFeeTypePO> poList = promotionFeeTypeMapper.selectList(wrapper);
|
||||
return poList.stream()
|
||||
.map(po -> {
|
||||
PromotionFeeTypeVO vo = new PromotionFeeTypeVO();
|
||||
BeanCopyUtils.copyProperties(po, vo);
|
||||
|
||||
// 设置计算方式描述
|
||||
if (po.getCalculationMethod() != null) {
|
||||
switch (po.getCalculationMethod()) {
|
||||
case 1:
|
||||
vo.setCalculationMethodDesc("固定金额");
|
||||
break;
|
||||
case 2:
|
||||
vo.setCalculationMethodDesc("按比例");
|
||||
break;
|
||||
case 3:
|
||||
vo.setCalculationMethodDesc("按点击");
|
||||
break;
|
||||
case 4:
|
||||
vo.setCalculationMethodDesc("按展示");
|
||||
break;
|
||||
default:
|
||||
vo.setCalculationMethodDesc("未知");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return vo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有推广费类型列表
|
||||
* @return 推广费类型VO列表
|
||||
*/
|
||||
@Override
|
||||
public List<PromotionFeeTypeVO> getAllPromotionFeeTypeList() {
|
||||
LambdaQueryWrapper<PromotionFeeTypePO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PromotionFeeTypePO::getCompanyId, currentUserContext.getCurrentCompanyId())
|
||||
.orderByAsc(PromotionFeeTypePO::getSortOrder);
|
||||
|
||||
List<PromotionFeeTypePO> poList = promotionFeeTypeMapper.selectList(wrapper);
|
||||
return poList.stream()
|
||||
.map(po -> {
|
||||
PromotionFeeTypeVO vo = new PromotionFeeTypeVO();
|
||||
BeanCopyUtils.copyProperties(po, vo);
|
||||
|
||||
// 设置计算方式描述
|
||||
if (po.getCalculationMethod() != null) {
|
||||
switch (po.getCalculationMethod()) {
|
||||
case 1:
|
||||
vo.setCalculationMethodDesc("固定金额");
|
||||
break;
|
||||
case 2:
|
||||
vo.setCalculationMethodDesc("按比例");
|
||||
break;
|
||||
case 3:
|
||||
vo.setCalculationMethodDesc("按点击");
|
||||
break;
|
||||
case 4:
|
||||
vo.setCalculationMethodDesc("按展示");
|
||||
break;
|
||||
default:
|
||||
vo.setCalculationMethodDesc("未知");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return vo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化公司推广费类型数据
|
||||
* @param companyId 公司ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void initPromotionFeeTypeForCompany(Long companyId) {
|
||||
initPromotionFeeTypeForCompany(companyId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initPromotionFeeTypeForCompany(Long companyId, Long creatorId) {
|
||||
// 检查是否已经初始化过
|
||||
LambdaQueryWrapper<PromotionFeeTypePO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PromotionFeeTypePO::getCompanyId, companyId);
|
||||
if (promotionFeeTypeMapper.selectCount(wrapper) > 0) {
|
||||
return; // 已经初始化过,直接返回
|
||||
}
|
||||
|
||||
// 初始化推广费类型数据
|
||||
List<PromotionFeeTypePO> initialTypes = List.of(
|
||||
createPromotionFeeTypePO(companyId, "直通车", "淘宝直通车推广费用", 3, 1, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "钻展", "钻石展位推广费用", 4, 2, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "超级推荐", "超级推荐推广费用", 3, 3, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "平台佣金", "平台交易佣金", 2, 4, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "分销佣金", "分销商佣金", 2, 5, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "活动费用", "平台活动参与费用", 1, 6, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "站外广告", "站外广告投放费用", 1, 7, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "直播推广", "直播推广费用", 1, 8, creatorId)
|
||||
);
|
||||
|
||||
// 批量插入
|
||||
for (PromotionFeeTypePO type : initialTypes) {
|
||||
promotionFeeTypeMapper.insert(type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化当前公司推广费类型数据
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void initPromotionFeeTypeForCurrentCompany() {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
if (companyId == null) {
|
||||
throw new RuntimeException("用户未关联公司");
|
||||
}
|
||||
initPromotionFeeTypeForCompany(companyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建推广费类型PO对象
|
||||
* @param companyId 公司ID
|
||||
* @param typeName 类型名称
|
||||
* @param description 描述
|
||||
* @param calculationMethod 计算方式
|
||||
* @param sortOrder 排序
|
||||
* @return 推广费类型PO对象
|
||||
*/
|
||||
private PromotionFeeTypePO createPromotionFeeTypePO(Long companyId, String typeName, String description, Integer calculationMethod, Integer sortOrder, Long creatorId) {
|
||||
PromotionFeeTypePO po = new PromotionFeeTypePO();
|
||||
po.setCompanyId(companyId);
|
||||
po.setTypeName(typeName);
|
||||
po.setDescription(description);
|
||||
po.setCalculationMethod(calculationMethod);
|
||||
po.setSortOrder(sortOrder);
|
||||
po.setIsActive(1);
|
||||
// create_by / update_by 可为 null(外键 ON DELETE SET NULL);禁止写死不存在的用户 id
|
||||
po.setCreateBy(creatorId);
|
||||
po.setUpdateBy(creatorId);
|
||||
return po;
|
||||
}
|
||||
}
|
||||
-4
@@ -11,8 +11,6 @@ public final class OpenApiScopeConstants {
|
||||
|
||||
public static final String ORDER_IMPORT = "open:scope:order:import";
|
||||
public static final String ORDER_READ = "open:scope:order:read";
|
||||
public static final String PROMOTION_FEE_IMPORT = "open:scope:promotion_fee:import";
|
||||
public static final String PROMOTION_FEE_READ = "open:scope:promotion_fee:read";
|
||||
public static final String IMPORT_TASK_READ = "open:scope:import_task:read";
|
||||
public static final String META_READ = "open:scope:meta:read";
|
||||
public static final String PDD_GOODS_AD_FEE_IMPORT = "open:scope:pdd_goods_ad_fee:import";
|
||||
@@ -22,8 +20,6 @@ public final class OpenApiScopeConstants {
|
||||
public static final List<String> ALL = List.of(
|
||||
ORDER_IMPORT,
|
||||
ORDER_READ,
|
||||
PROMOTION_FEE_IMPORT,
|
||||
PROMOTION_FEE_READ,
|
||||
IMPORT_TASK_READ,
|
||||
META_READ,
|
||||
PDD_GOODS_AD_FEE_IMPORT,
|
||||
|
||||
-11
@@ -11,8 +11,6 @@ import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.status.model.vo.OrderStatusMetaVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.status.support.OrderStatusMetaSupport;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.PromotionFeeTypeVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.service.PromotionFeeTypeService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.ShopFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.vo.ShopVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.service.ShopService;
|
||||
@@ -27,7 +25,6 @@ import java.util.List;
|
||||
public class OpenMetaController {
|
||||
|
||||
private final ShopService shopService;
|
||||
private final PromotionFeeTypeService promotionFeeTypeService;
|
||||
|
||||
@PostMapping("/shop/list")
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.META_READ, description = "查询店铺列表")
|
||||
@@ -44,12 +41,4 @@ public class OpenMetaController {
|
||||
public ApiResponse<List<OrderStatusMetaVO>> getAllOrderStatuses() {
|
||||
return ApiResponse.success("获取订单状态列表成功", OrderStatusMetaSupport.allMeta());
|
||||
}
|
||||
|
||||
@GetMapping("/promotion-fee-type/list")
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.META_READ, description = "查询推广费类型列表")
|
||||
@Operation(summary = "获取启用的推广费类型列表")
|
||||
public ApiResponse<List<PromotionFeeTypeVO>> getActivePromotionFeeTypeList() {
|
||||
List<PromotionFeeTypeVO> list = promotionFeeTypeService.getActivePromotionFeeTypeList();
|
||||
return ApiResponse.success("获取推广费类型列表成功", list);
|
||||
}
|
||||
}
|
||||
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequireOpenScope;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.dto.BatchImportPromotionFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.BatchImportPromotionFeeResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.PromotionFeeFieldConstants;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.vo.PromotionFeeFieldVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.service.PromotionFeeService;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.constants.OpenApiScopeConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/open/v1/ec/promotion-fee")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "开放接口-推广费", description = "API Key 认证,镜像 /ec/promotion-fee")
|
||||
public class OpenPromotionFeeController {
|
||||
|
||||
private final PromotionFeeService promotionFeeService;
|
||||
|
||||
@GetMapping("/fields")
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.PROMOTION_FEE_READ, description = "查询推广费字段")
|
||||
@Operation(summary = "获取推广费导入字段定义")
|
||||
public ApiResponse<List<PromotionFeeFieldVO>> getPromotionFeeFields() {
|
||||
return ApiResponse.success("获取推广费字段成功", PromotionFeeFieldConstants.FIELDS);
|
||||
}
|
||||
|
||||
@PostMapping("/batch-import")
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.PROMOTION_FEE_IMPORT, description = "批量导入推广费")
|
||||
@Operation(summary = "批量导入推广费")
|
||||
public ApiResponse<BatchImportPromotionFeeResultVO> batchImportPromotionFees(
|
||||
@Valid @RequestBody BatchImportPromotionFeeDTO dto) {
|
||||
BatchImportPromotionFeeResultVO result = promotionFeeService.batchImportPromotionFees(dto);
|
||||
return ApiResponse.success("批量导入推广费成功", result);
|
||||
}
|
||||
}
|
||||
-7
@@ -19,7 +19,6 @@ import top.xyquan.ecomdmbbackend.modules.org.company.model.vo.CompanyVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.company.service.CompanyService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.service.SysFileService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileUploadVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.service.PromotionFeeTypeService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.company.menu.service.CompanyMenuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.department.service.DepartmentService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.position.service.PositionService;
|
||||
@@ -54,7 +53,6 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final SysFileService sysFileService;
|
||||
private final PromotionFeeTypeService promotionFeeTypeService;
|
||||
private final CompanyMenuService companyMenuService;
|
||||
private final DepartmentService departmentService;
|
||||
private final PositionService positionService;
|
||||
@@ -65,14 +63,12 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
|
||||
private final LicenseValidator licenseValidator;
|
||||
|
||||
public CompanyServiceImpl(@Lazy CurrentUserContext currentUserContext, SysFileService sysFileService,
|
||||
PromotionFeeTypeService promotionFeeTypeService,
|
||||
CompanyMenuService companyMenuService, DepartmentService departmentService,
|
||||
PositionService positionService, MenuService menuService,
|
||||
@Lazy UserService userService, @Lazy CompanyMemberService companyMemberService,
|
||||
PasswordEncoder passwordEncoder, LicenseValidator licenseValidator) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.sysFileService = sysFileService;
|
||||
this.promotionFeeTypeService = promotionFeeTypeService;
|
||||
this.companyMenuService = companyMenuService;
|
||||
this.departmentService = departmentService;
|
||||
this.positionService = positionService;
|
||||
@@ -157,9 +153,6 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
|
||||
// 将拥有者加入公司成员(owner角色)
|
||||
companyMemberService.create(ownerUser.getId(), company.getId(), CompanyMemberRole.owner, null, creatorId);
|
||||
|
||||
// 初始化推广费类型数据
|
||||
promotionFeeTypeService.initPromotionFeeTypeForCompany(company.getId(), creatorId);
|
||||
|
||||
// 初始化公司菜单(非超级菜单)
|
||||
initCompanyMenus(company.getId());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user