迁移 商品 分类

This commit is contained in:
GYJ 2025-03-13 13:27:09 +08:00
parent 88df994553
commit c544cf5d81
2 changed files with 13 additions and 11 deletions

View File

@ -30,9 +30,6 @@ import java.util.Map;
@Service
public class CurShopProdCategoryServiceImpl extends ServiceImpl<CurShopProdCategoryMapper, CurShopProdCategory> implements CurShopProdCategoryService {
@Resource
private CurShopIdRelationService curShopIdRelationService;
@Resource
private OldShopCategoryService oldShopCategoryService;
@ -41,30 +38,28 @@ public class CurShopProdCategoryServiceImpl extends ServiceImpl<CurShopProdCateg
public CzgResult<String> mergeData() {
getMapper().truncateTable();
Map<Long, Long> oldAndCurShopIdMap = curShopIdRelationService.getOldShopIdRelation();
execMergeCategory(oldAndCurShopIdMap);
execMergeCategory();
return CzgResult.success("迁移成功");
}
private void execMergeCategory(Map<Long, Long> oldAndCurShopIdMap) {
private void execMergeCategory() {
Page<OldShopCategory> page = oldShopCategoryService.page(PageUtils.buildPage());
while (!page.getRecords().isEmpty()) {
saveCategory(page.getRecords(), oldAndCurShopIdMap);
saveCategory(page.getRecords());
page = oldShopCategoryService.page(PageUtils.buildPage(page.getPageNumber() + 1));
}
}
private void saveCategory(List<OldShopCategory> oldShopCategoryList, Map<Long, Long> oldShopIdMap) {
private void saveCategory(List<OldShopCategory> oldShopCategoryList) {
List<CurShopProdCategory> curShopProdCategories = new ArrayList<>();
for (OldShopCategory oldShopCategory : oldShopCategoryList) {
Long shopId = oldShopIdMap.get(Long.valueOf(oldShopCategory.getShopId()));
Long shopId = Long.valueOf(oldShopCategory.getShopId());
CurShopProdCategory curShopProdCategory = new CurShopProdCategory();
curShopProdCategory.setId(Long.valueOf(oldShopCategory.getId()));
curShopProdCategory.setShopId(shopId == null ? 1L : shopId);
curShopProdCategory.setShopId(shopId);
curShopProdCategory.setName(oldShopCategory.getName());
curShopProdCategory.setShortName(oldShopCategory.getShortName());
curShopProdCategory.setPid(StrUtil.isBlank(oldShopCategory.getPid()) ? 1L : Long.parseLong(oldShopCategory.getPid()));

View File

@ -90,5 +90,12 @@
#### 执行表
- tb_shop_prod_spec 表
### 12. 商品分类
> /merge/product/mergeCategory
#### 执行表
- tb_shop_prod_category 表