迁移 商品 SKU 分组

This commit is contained in:
GYJ 2025-03-13 13:40:39 +08:00
parent c544cf5d81
commit b9c2436822
5 changed files with 35 additions and 47 deletions

View File

@ -1,7 +1,6 @@
package com.czg.mergedata.cur.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONArray;
import com.czg.mergedata.common.resp.CzgResult;
import com.czg.mergedata.common.utils.PageUtils;
@ -10,7 +9,6 @@ import com.czg.mergedata.cur.entity.CurProdGroupRelation;
import com.czg.mergedata.cur.mapper.CurProdGroupMapper;
import com.czg.mergedata.cur.mapper.CurProdGroupRelationMapper;
import com.czg.mergedata.cur.service.CurProdGroupService;
import com.czg.mergedata.cur.service.CurShopIdRelationService;
import com.czg.mergedata.old.entity.OldProductGroup;
import com.czg.mergedata.old.service.OldProductGroupService;
import com.mybatisflex.core.paginate.Page;
@ -19,11 +17,9 @@ import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 商品分组 服务层实现
@ -32,14 +28,11 @@ import java.util.Map;
* @since 2025-02-18
*/
@Service
public class CurProdGroupServiceImpl extends ServiceImpl<CurProdGroupMapper, CurProdGroup> implements CurProdGroupService{
public class CurProdGroupServiceImpl extends ServiceImpl<CurProdGroupMapper, CurProdGroup> implements CurProdGroupService {
@Resource
private CurProdGroupRelationMapper curProdGroupRelationMapper;
@Resource
private CurShopIdRelationService curShopIdRelationService;
@Resource
private OldProductGroupService oldProductGroupService;
@ -49,23 +42,21 @@ public class CurProdGroupServiceImpl extends ServiceImpl<CurProdGroupMapper, Cur
getMapper().truncateTable();
curProdGroupRelationMapper.truncateTable();
Map<Long, Long> oldAndCurShopIdMap = curShopIdRelationService.getOldShopIdRelation();
execProdGroup(oldAndCurShopIdMap);
execProdGroup();
return CzgResult.success("迁移成功");
}
private void execProdGroup(Map<Long, Long> oldAndCurShopIdMap) {
private void execProdGroup() {
Page<OldProductGroup> page = oldProductGroupService.page(PageUtils.buildPage());
while (!page.getRecords().isEmpty()) {
saveProdGroup(page.getRecords(), oldAndCurShopIdMap);
saveProdGroup(page.getRecords());
page = oldProductGroupService.page(PageUtils.buildPage(page.getPageNumber() + 1));
}
}
private void saveProdGroup(List<OldProductGroup> oldProductGroupList, Map<Long, Long> oldAndCurShopIdMap) {
private void saveProdGroup(List<OldProductGroup> oldProductGroupList) {
List<CurProdGroup> curProdGroupList = new ArrayList<>();
List<CurProdGroupRelation> curProdGroupRelationList = new ArrayList<>();
@ -74,7 +65,7 @@ public class CurProdGroupServiceImpl extends ServiceImpl<CurProdGroupMapper, Cur
curProdGroup.setId(Long.valueOf(oldProductGroup.getId()));
curProdGroup.setName(oldProductGroup.getName());
curProdGroup.setShopId(oldAndCurShopIdMap.get(Long.valueOf(oldProductGroup.getId())));
curProdGroup.setShopId(Long.valueOf(oldProductGroup.getId()));
curProdGroup.setPic(oldProductGroup.getPic());
curProdGroup.setStatus(oldProductGroup.getIsShow());
curProdGroup.setSort(oldProductGroup.getSort());

View File

@ -3,14 +3,13 @@ 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.cur.entity.CurProdSku;
import com.czg.mergedata.cur.mapper.CurProdSkuMapper;
import com.czg.mergedata.cur.service.CurProdSkuService;
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;
@ -18,7 +17,6 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 商品SKU 服务层实现
@ -27,10 +25,7 @@ import java.util.Map;
* @since 2025-02-18
*/
@Service
public class CurProdSkuServiceImpl extends ServiceImpl<CurProdSkuMapper, CurProdSku> implements CurProdSkuService{
@Resource
private CurShopIdRelationService curShopIdRelationService;
public class CurProdSkuServiceImpl extends ServiceImpl<CurProdSkuMapper, CurProdSku> implements CurProdSkuService {
@Resource
private OldProductSkuService oldProductSkuService;
@ -39,31 +34,29 @@ public class CurProdSkuServiceImpl extends ServiceImpl<CurProdSkuMapper, CurProd
public CzgResult<String> mergeData() {
getMapper().truncateTable();
Map<Long, Long> oldAndCurShopIdMap = curShopIdRelationService.getOldShopIdRelation();
execProSku(oldAndCurShopIdMap);
execProSku();
return CzgResult.success("迁移成功");
}
private void execProSku(Map<Long, Long> oldAndCurShopIdMap) {
private void execProSku() {
Page<OldProductSku> page = oldProductSkuService.page(PageUtils.buildPage());
while (!page.getRecords().isEmpty()) {
saveProSku(page.getRecords(), oldAndCurShopIdMap);
saveProSku(page.getRecords());
page = oldProductSkuService.page(PageUtils.buildPage(page.getPageNumber() + 1));
}
}
private void saveProSku(List<OldProductSku> oldProductSkuList, Map<Long, Long> oldAndCurShopIdMap) {
private void saveProSku(List<OldProductSku> oldProductSkuList) {
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.setShopId(Long.valueOf(oldProductSku.getShopId()));
curProdSku.setBarCode(oldProductSku.getBarCode());
curProdSku.setProductId(Long.valueOf(oldProductSku.getProductId()));
curProdSku.setOriginPrice(oldProductSku.getOriginPrice());

View File

@ -9,11 +9,9 @@ import com.czg.mergedata.common.utils.PageUtils;
import com.czg.mergedata.cur.entity.CurProduct;
import com.czg.mergedata.cur.mapper.CurProductMapper;
import com.czg.mergedata.cur.service.CurProductService;
import com.czg.mergedata.cur.service.CurShopIdRelationService;
import com.czg.mergedata.old.entity.OldProduct;
import com.czg.mergedata.old.service.OldProductService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.row.Db;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
@ -22,7 +20,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 商品 服务层实现
@ -33,9 +30,6 @@ import java.util.Map;
@Service
public class CurProductServiceImpl extends ServiceImpl<CurProductMapper, CurProduct> implements CurProductService {
@Resource
private CurShopIdRelationService curShopIdRelationService;
@Resource
private OldProductService oldProductService;
@ -44,24 +38,22 @@ public class CurProductServiceImpl extends ServiceImpl<CurProductMapper, CurProd
public CzgResult<String> mergeData() {
getMapper().truncateTable();
Map<Long, Long> oldAndCurShopIdMap = curShopIdRelationService.getOldShopIdRelation();
execProduct(oldAndCurShopIdMap);
execProduct();
return CzgResult.success("迁移成功");
}
private void execProduct(Map<Long, Long> oldAndCurShopIdMap) {
private void execProduct() {
Page<OldProduct> page = oldProductService.page(PageUtils.buildPage());
while (!page.getRecords().isEmpty()) {
saveProduct(page.getRecords(), oldAndCurShopIdMap);
saveProduct(page.getRecords());
page = oldProductService.page(PageUtils.buildPage(page.getPageNumber() + 1));
}
}
private void saveProduct(List<OldProduct> products, Map<Long, Long> oldAndCurShopIdMap) {
private void saveProduct(List<OldProduct> products) {
List<CurProduct> productList = new ArrayList<>();
for (OldProduct oldProduct : products) {
@ -70,7 +62,7 @@ public class CurProductServiceImpl extends ServiceImpl<CurProductMapper, CurProd
curProduct.setId(Long.valueOf(oldProduct.getId()));
curProduct.setCategoryId(StrUtil.isBlank(oldProduct.getCategoryId()) ? null : Long.valueOf(oldProduct.getCategoryId()));
curProduct.setSpecId(oldProduct.getSpecId() == null ? null : Long.valueOf(oldProduct.getSpecId()));
curProduct.setShopId(oldAndCurShopIdMap.get(Long.valueOf(oldProduct.getShopId())));
curProduct.setShopId(Long.valueOf(oldProduct.getShopId()));
curProduct.setName(oldProduct.getName());
curProduct.setShortTitle(oldProduct.getShortTitle());
curProduct.setType(getProductType(oldProduct));

View File

@ -6,7 +6,6 @@ import com.czg.mergedata.common.resp.CzgResult;
import com.czg.mergedata.common.utils.PageUtils;
import com.czg.mergedata.cur.entity.CurShopProdCategory;
import com.czg.mergedata.cur.mapper.CurShopProdCategoryMapper;
import com.czg.mergedata.cur.service.CurShopIdRelationService;
import com.czg.mergedata.cur.service.CurShopProdCategoryService;
import com.czg.mergedata.old.entity.OldShopCategory;
import com.czg.mergedata.old.service.OldShopCategoryService;
@ -19,7 +18,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 商品分类 服务层实现

View File

@ -95,7 +95,21 @@
#### 执行表
- tb_shop_prod_category 表
### 13. 商品
> /merge/product/mergeProduct
#### 执行表
- tb_product 表
### 14. 商品 SKU
> /merge/product/mergeSku
#### 执行表
- tb_prod_sku 表
### 15. 商品分组
> /merge/product/mergeGroup
#### 执行表
- tb_prod_group 表
- tb_prod_group_relation 表