迁移 商品SKU
This commit is contained in:
parent
267d054451
commit
f725704a80
|
|
@ -81,7 +81,7 @@ public class CodeGen {
|
|||
//设置表前缀和只生成哪些表,setGenerateTable 未配置时,生成所有表
|
||||
globalConfig.getStrategyConfig()
|
||||
.setTablePrefix("tb_")
|
||||
.setGenerateTable("tb_product");
|
||||
.setGenerateTable("tb_product_sku");
|
||||
|
||||
EntityConfig entityConfig = globalConfig.getEntityConfig();
|
||||
if (isOldVersion) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
package com.czg.mergedata.controller;
|
||||
|
||||
import com.czg.mergedata.common.resp.CzgResult;
|
||||
import com.czg.mergedata.cur.service.CurProductService;
|
||||
import com.czg.mergedata.cur.service.CurShopProdCategoryService;
|
||||
import com.czg.mergedata.cur.service.CurShopProdSpecService;
|
||||
import com.czg.mergedata.cur.service.CurShopProdUnitService;
|
||||
import com.czg.mergedata.cur.service.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
|
@ -28,24 +26,32 @@ public class ProductController {
|
|||
@Resource
|
||||
private CurProductService curProductService;
|
||||
|
||||
@RequestMapping("/mergeUnit")
|
||||
@Resource
|
||||
private CurProdSkuService curProdSkuService;
|
||||
|
||||
@GetMapping("/mergeUnit")
|
||||
public CzgResult<String> mergeUnit() {
|
||||
return curShopProdUnitService.mergeProductUnit();
|
||||
}
|
||||
|
||||
@RequestMapping("/mergeSpec")
|
||||
@GetMapping("/mergeSpec")
|
||||
public CzgResult<String> mergeSpec() {
|
||||
return curShopProdSpecService.mergeProductSpec();
|
||||
}
|
||||
|
||||
@RequestMapping("/mergeCategory")
|
||||
@GetMapping("/mergeCategory")
|
||||
public CzgResult<String> mergeCategory() {
|
||||
return curShopProdCategoryService.mergeData();
|
||||
}
|
||||
|
||||
@RequestMapping("/mergeProduct")
|
||||
@GetMapping("/mergeProduct")
|
||||
public CzgResult<String> mergeProduct() {
|
||||
return curProductService.mergeData();
|
||||
}
|
||||
|
||||
@GetMapping("/mergeSku")
|
||||
public CzgResult<String> mergeSku() {
|
||||
return curProdSkuService.mergeData();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,127 @@
|
|||
package com.czg.mergedata.cur.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 商品SKU 实体类。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-18
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("tb_prod_sku")
|
||||
public class CurProdSku implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 条形码
|
||||
*/
|
||||
private String barCode;
|
||||
|
||||
/**
|
||||
* 商品Id
|
||||
*/
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 原价
|
||||
*/
|
||||
private BigDecimal originPrice;
|
||||
|
||||
/**
|
||||
* 成本价
|
||||
*/
|
||||
private BigDecimal costPrice;
|
||||
|
||||
/**
|
||||
* 会员价
|
||||
*/
|
||||
private BigDecimal memberPrice;
|
||||
|
||||
/**
|
||||
* 售价
|
||||
*/
|
||||
private BigDecimal salePrice;
|
||||
|
||||
/**
|
||||
* 起售数量
|
||||
*/
|
||||
private Integer suitNum;
|
||||
|
||||
/**
|
||||
* 规格详情
|
||||
*/
|
||||
private String specInfo;
|
||||
|
||||
/**
|
||||
* sku图片
|
||||
*/
|
||||
private String coverImg;
|
||||
|
||||
/**
|
||||
* 重量
|
||||
*/
|
||||
private BigDecimal weight;
|
||||
|
||||
/**
|
||||
* 销量
|
||||
*/
|
||||
private BigDecimal realSalesNumber;
|
||||
|
||||
/**
|
||||
* 是否售罄
|
||||
*/
|
||||
private Integer isPauseSale;
|
||||
|
||||
/**
|
||||
* 是否上架
|
||||
*/
|
||||
private Boolean isGrounding;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除字段 0否 1 删除
|
||||
*/
|
||||
private Integer isDel;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.czg.mergedata.cur.mapper;
|
||||
|
||||
import com.mybatisflex.annotation.UseDataSource;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.mergedata.cur.entity.CurProdSku;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* 商品SKU 映射层。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-18
|
||||
*/
|
||||
@UseDataSource("ds1")
|
||||
public interface CurProdSkuMapper extends BaseMapper<CurProdSku> {
|
||||
@Select("truncate tb_prod_sku ")
|
||||
void truncateTable();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.czg.mergedata.cur.service;
|
||||
|
||||
import com.czg.mergedata.common.resp.CzgResult;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.mergedata.cur.entity.CurProdSku;
|
||||
|
||||
/**
|
||||
* 商品SKU 服务层。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-18
|
||||
*/
|
||||
public interface CurProdSkuService extends IService<CurProdSku> {
|
||||
CzgResult<String> mergeData();
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package com.czg.mergedata.cur.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.czg.mergedata.common.resp.CzgResult;
|
||||
import com.czg.mergedata.common.utils.PageUtils;
|
||||
import com.czg.mergedata.cur.service.CurShopIdRelationService;
|
||||
import com.czg.mergedata.old.entity.OldProductSku;
|
||||
import com.czg.mergedata.old.service.OldProductSkuService;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.mergedata.cur.entity.CurProdSku;
|
||||
import com.czg.mergedata.cur.mapper.CurProdSkuMapper;
|
||||
import com.czg.mergedata.cur.service.CurProdSkuService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 商品SKU 服务层实现。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-18
|
||||
*/
|
||||
@Service
|
||||
public class CurProdSkuServiceImpl extends ServiceImpl<CurProdSkuMapper, CurProdSku> implements CurProdSkuService{
|
||||
|
||||
@Resource
|
||||
private CurShopIdRelationService curShopIdRelationService;
|
||||
|
||||
@Resource
|
||||
private OldProductSkuService oldProductSkuService;
|
||||
|
||||
@Override
|
||||
public CzgResult<String> mergeData() {
|
||||
getMapper().truncateTable();
|
||||
|
||||
Map<Long, Long> oldAndCurShopIdMap = curShopIdRelationService.getOldShopIdRelation();
|
||||
|
||||
execProSku(oldAndCurShopIdMap);
|
||||
|
||||
return CzgResult.success("迁移成功");
|
||||
}
|
||||
|
||||
private void execProSku(Map<Long, Long> oldAndCurShopIdMap) {
|
||||
Page<OldProductSku> page = oldProductSkuService.page(PageUtils.buildPage());
|
||||
|
||||
while (!page.getRecords().isEmpty()) {
|
||||
saveProSku(page.getRecords(), oldAndCurShopIdMap);
|
||||
|
||||
page = oldProductSkuService.page(PageUtils.buildPage(page.getPageNumber() + 1));
|
||||
}
|
||||
}
|
||||
|
||||
private void saveProSku(List<OldProductSku> oldProductSkuList, Map<Long, Long> oldAndCurShopIdMap) {
|
||||
List<CurProdSku> curProdSkuList = new ArrayList<>();
|
||||
|
||||
for (OldProductSku oldProductSku : oldProductSkuList) {
|
||||
CurProdSku curProdSku = new CurProdSku();
|
||||
|
||||
curProdSku.setId(Long.valueOf(oldProductSku.getId()));
|
||||
curProdSku.setShopId(oldAndCurShopIdMap.get(Long.valueOf(oldProductSku.getShopId())));
|
||||
curProdSku.setBarCode(oldProductSku.getBarCode());
|
||||
curProdSku.setProductId(Long.valueOf(oldProductSku.getProductId()));
|
||||
curProdSku.setOriginPrice(oldProductSku.getOriginPrice());
|
||||
curProdSku.setCostPrice(oldProductSku.getCostPrice());
|
||||
curProdSku.setMemberPrice(oldProductSku.getMemberPrice());
|
||||
curProdSku.setSalePrice(oldProductSku.getSalePrice());
|
||||
curProdSku.setSuitNum(oldProductSku.getSuit());
|
||||
curProdSku.setSpecInfo(oldProductSku.getSpecSnap());
|
||||
curProdSku.setCoverImg(oldProductSku.getCoverImg());
|
||||
curProdSku.setWeight(oldProductSku.getWeight() == null ? BigDecimal.ZERO : BigDecimal.valueOf(oldProductSku.getWeight()));
|
||||
curProdSku.setRealSalesNumber(oldProductSku.getRealSalesNumber() == null ? BigDecimal.ZERO : BigDecimal.valueOf(oldProductSku.getRealSalesNumber()));
|
||||
curProdSku.setIsPauseSale(oldProductSku.getIsPauseSale());
|
||||
curProdSku.setIsGrounding(oldProductSku.getIsGrounding());
|
||||
curProdSku.setCreateTime(DateUtil.toLocalDateTime(oldProductSku.getCreatedAt() == null ? new Date() : new Date(oldProductSku.getCreatedAt())));
|
||||
curProdSku.setIsDel(oldProductSku.getIsDel());
|
||||
|
||||
curProdSkuList.add(curProdSku);
|
||||
}
|
||||
|
||||
saveBatch(curProdSkuList);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
package com.czg.mergedata.old.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 商品SKU 实体类。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-18
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("tb_product_sku")
|
||||
public class OldProductSku implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 自增id
|
||||
*/
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Integer id;
|
||||
|
||||
private String shopId;
|
||||
|
||||
/**
|
||||
* 条形码
|
||||
*/
|
||||
private String barCode;
|
||||
|
||||
/**
|
||||
* 商品Id
|
||||
*/
|
||||
private String productId;
|
||||
|
||||
/**
|
||||
* 原价
|
||||
*/
|
||||
private BigDecimal originPrice;
|
||||
|
||||
/**
|
||||
* 成本价
|
||||
*/
|
||||
private BigDecimal costPrice;
|
||||
|
||||
/**
|
||||
* 会员价
|
||||
*/
|
||||
private BigDecimal memberPrice;
|
||||
|
||||
private BigDecimal mealPrice;
|
||||
|
||||
/**
|
||||
* 售价
|
||||
*/
|
||||
private BigDecimal salePrice;
|
||||
|
||||
/**
|
||||
* 进货参考价
|
||||
*/
|
||||
private BigDecimal guidePrice;
|
||||
|
||||
private BigDecimal strategyPrice;
|
||||
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
private Double stockNumber;
|
||||
|
||||
/**
|
||||
* 标签详情
|
||||
*/
|
||||
private String specInfo;
|
||||
|
||||
/**
|
||||
* 标签镜像
|
||||
*/
|
||||
private String specSnap;
|
||||
|
||||
private String coverImg;
|
||||
|
||||
private Double weight;
|
||||
|
||||
private Float volume;
|
||||
|
||||
/**
|
||||
* 销量
|
||||
*/
|
||||
private Double realSalesNumber;
|
||||
|
||||
/**
|
||||
* 一级分销金额
|
||||
*/
|
||||
private BigDecimal firstShared;
|
||||
|
||||
/**
|
||||
* 二级分销金额
|
||||
*/
|
||||
private BigDecimal secondShared;
|
||||
|
||||
private Long createdAt;
|
||||
|
||||
private Long updatedAt;
|
||||
|
||||
/**
|
||||
* 是否暂停销售
|
||||
*/
|
||||
private Integer isPauseSale;
|
||||
|
||||
/**
|
||||
* 逻辑删除字段 0否 1 删除
|
||||
*/
|
||||
private Integer isDel;
|
||||
|
||||
/**
|
||||
* 起售数量
|
||||
*/
|
||||
private Integer suit;
|
||||
|
||||
/**
|
||||
* 是否上架
|
||||
*/
|
||||
private Boolean isGrounding;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.czg.mergedata.old.mapper;
|
||||
|
||||
import com.mybatisflex.annotation.UseDataSource;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.mergedata.old.entity.OldProductSku;
|
||||
|
||||
/**
|
||||
* 商品SKU 映射层。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-18
|
||||
*/
|
||||
@UseDataSource("ds2")
|
||||
public interface OldProductSkuMapper extends BaseMapper<OldProductSku> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.czg.mergedata.old.service;
|
||||
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.mergedata.old.entity.OldProductSku;
|
||||
|
||||
/**
|
||||
* 商品SKU 服务层。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-18
|
||||
*/
|
||||
public interface OldProductSkuService extends IService<OldProductSku> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.czg.mergedata.old.service.impl;
|
||||
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.mergedata.old.entity.OldProductSku;
|
||||
import com.czg.mergedata.old.mapper.OldProductSkuMapper;
|
||||
import com.czg.mergedata.old.service.OldProductSkuService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 商品SKU 服务层实现。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-18
|
||||
*/
|
||||
@Service
|
||||
public class OldProductSkuServiceImpl extends ServiceImpl<OldProductSkuMapper, OldProductSku> implements OldProductSkuService{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.mergedata.cur.mapper.CurProdSkuMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.mergedata.old.mapper.OldProductSkuMapper">
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue