迁移 商品分类

This commit is contained in:
GYJ 2025-02-17 18:31:50 +08:00
parent 127a96ac8e
commit b81294a493
32 changed files with 881 additions and 1 deletions

View File

@ -81,7 +81,7 @@ public class CodeGen {
//设置表前缀和只生成哪些表setGenerateTable 未配置时生成所有表
globalConfig.getStrategyConfig()
.setTablePrefix("tb_")
.setGenerateTable("tb_shop_prod_spec");
.setGenerateTable("tb_shop_prod_category");
EntityConfig entityConfig = globalConfig.getEntityConfig();
if (isOldVersion) {

View File

@ -1,6 +1,7 @@
package com.czg.mergedata.controller;
import com.czg.mergedata.common.resp.CzgResult;
import com.czg.mergedata.cur.service.CurShopProdCategoryService;
import com.czg.mergedata.cur.service.CurShopProdSpecService;
import com.czg.mergedata.cur.service.CurShopProdUnitService;
import jakarta.annotation.Resource;
@ -20,6 +21,9 @@ public class ProductController {
@Resource
private CurShopProdSpecService curShopProdSpecService;
@Resource
private CurShopProdCategoryService curShopProdCategoryService;
@RequestMapping("/mergeUnit")
public CzgResult<String> mergeUnit() {
return curShopProdUnitService.mergeProductUnit();
@ -30,4 +34,9 @@ public class ProductController {
return curShopProdSpecService.mergeProductSpec();
}
@RequestMapping("/mergeCategory")
public CzgResult<String> mergeCategory() {
return curShopProdCategoryService.mergeData();
}
}

View File

@ -0,0 +1,81 @@
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.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Pad商品自定义分类 实体类
*
* @author mac
* @since 2025-02-17
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_pad_product_category")
public class CurPadProductCategory implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 布局版式id
*/
private Long padLayoutId;
/**
* 自定义名称
*/
private String customName;
/**
* 商品分类id
*/
private Long productCategoryId;
/**
* 店铺id
*/
private Long shopId;
/**
* 排序
*/
private Integer sort;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
/**
* 更新时间
*/
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
}

View File

@ -0,0 +1,55 @@
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.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Pad商品自定义分类明细 实体类
*
* @author mac
* @since 2025-02-17
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_pad_product_category_detail")
public class CurPadProductCategoryDetail implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* Pad商品自定义分类id
*/
private Long padProductCategoryId;
/**
* 商品id
*/
private Long productId;
/**
* 创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,96 @@
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.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 商品分类 实体类
*
* @author mac
* @since 2025-02-17
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_prod_category")
public class CurShopProdCategory implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 分类名称
*/
private String name;
/**
* 简称
*/
private String shortName;
/**
* 上级分类id-为0则表示是顶级
*/
private Long pid;
/**
* 图标
*/
private String pic;
/**
* 店铺Id
*/
private Long shopId;
/**
* 分类描述
*/
private String detail;
/**
* 排序
*/
private Integer sort;
/**
* 关键词
*/
private String keyWord;
/**
* 状态 0-禁用 1-启用
*/
private Integer status;
/**
* 创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
/**
* 更新时间
*/
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
}

View File

@ -0,0 +1,16 @@
package com.czg.mergedata.cur.mapper;
import com.mybatisflex.annotation.UseDataSource;
import com.mybatisflex.core.BaseMapper;
import com.czg.mergedata.cur.entity.CurPadProductCategoryDetail;
/**
* Pad商品自定义分类明细 映射层
*
* @author mac
* @since 2025-02-17
*/
@UseDataSource("ds1")
public interface CurPadProductCategoryDetailMapper extends BaseMapper<CurPadProductCategoryDetail> {
}

View File

@ -0,0 +1,16 @@
package com.czg.mergedata.cur.mapper;
import com.mybatisflex.annotation.UseDataSource;
import com.mybatisflex.core.BaseMapper;
import com.czg.mergedata.cur.entity.CurPadProductCategory;
/**
* Pad商品自定义分类 映射层
*
* @author mac
* @since 2025-02-17
*/
@UseDataSource("ds1")
public interface CurPadProductCategoryMapper extends BaseMapper<CurPadProductCategory> {
}

View File

@ -0,0 +1,16 @@
package com.czg.mergedata.cur.mapper;
import com.mybatisflex.annotation.UseDataSource;
import com.mybatisflex.core.BaseMapper;
import com.czg.mergedata.cur.entity.CurShopProdCategory;
/**
* 商品分类 映射层
*
* @author mac
* @since 2025-02-17
*/
@UseDataSource("ds1")
public interface CurShopProdCategoryMapper extends BaseMapper<CurShopProdCategory> {
}

View File

@ -0,0 +1,14 @@
package com.czg.mergedata.cur.service;
import com.mybatisflex.core.service.IService;
import com.czg.mergedata.cur.entity.CurPadProductCategoryDetail;
/**
* Pad商品自定义分类明细 服务层
*
* @author mac
* @since 2025-02-17
*/
public interface CurPadProductCategoryDetailService extends IService<CurPadProductCategoryDetail> {
}

View File

@ -0,0 +1,17 @@
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.CurPadProductCategory;
/**
* Pad商品自定义分类 服务层
*
* @author mac
* @since 2025-02-17
*/
public interface CurPadProductCategoryService extends IService<CurPadProductCategory> {
CzgResult<String> mergeData();
}

View File

@ -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.CurShopProdCategory;
/**
* 商品分类 服务层
*
* @author mac
* @since 2025-02-17
*/
public interface CurShopProdCategoryService extends IService<CurShopProdCategory> {
CzgResult<String> mergeData();
}

View File

@ -0,0 +1,18 @@
package com.czg.mergedata.cur.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.mergedata.cur.entity.CurPadProductCategoryDetail;
import com.czg.mergedata.cur.mapper.CurPadProductCategoryDetailMapper;
import com.czg.mergedata.cur.service.CurPadProductCategoryDetailService;
import org.springframework.stereotype.Service;
/**
* Pad商品自定义分类明细 服务层实现
*
* @author mac
* @since 2025-02-17
*/
@Service
public class CurPadProductCategoryDetailServiceImpl extends ServiceImpl<CurPadProductCategoryDetailMapper, CurPadProductCategoryDetail> implements CurPadProductCategoryDetailService{
}

View File

@ -0,0 +1,23 @@
package com.czg.mergedata.cur.service.impl;
import com.czg.mergedata.common.resp.CzgResult;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.mergedata.cur.entity.CurPadProductCategory;
import com.czg.mergedata.cur.mapper.CurPadProductCategoryMapper;
import com.czg.mergedata.cur.service.CurPadProductCategoryService;
import org.springframework.stereotype.Service;
/**
* Pad商品自定义分类 服务层实现
*
* @author mac
* @since 2025-02-17
*/
@Service
public class CurPadProductCategoryServiceImpl extends ServiceImpl<CurPadProductCategoryMapper, CurPadProductCategory> implements CurPadProductCategoryService{
@Override
public CzgResult<String> mergeData() {
return null;
}
}

View File

@ -0,0 +1,81 @@
package com.czg.mergedata.cur.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
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;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 商品分类 服务层实现
*
* @author mac
* @since 2025-02-17
*/
@Service
public class CurShopProdCategoryServiceImpl extends ServiceImpl<CurShopProdCategoryMapper, CurShopProdCategory> implements CurShopProdCategoryService {
@Resource
private CurShopIdRelationService curShopIdRelationService;
@Resource
private OldShopCategoryService oldShopCategoryService;
@Override
@Transactional
public CzgResult<String> mergeData() {
Map<Long, Long> oldAndCurShopIdMap = curShopIdRelationService.getOldShopIdRelation();
execMergeCategory(oldAndCurShopIdMap);
return CzgResult.success("迁移成功");
}
private void execMergeCategory(Map<Long, Long> oldAndCurShopIdMap) {
Page<OldShopCategory> page = oldShopCategoryService.page(PageUtils.buildPage());
while (page.hasNext() || page.getPageNumber() == 1) {
saveCategory(page.getRecords(), oldAndCurShopIdMap);
page = oldShopCategoryService.page(PageUtils.buildPage(page.getPageNumber() + 1));
}
}
private void saveCategory(List<OldShopCategory> oldShopCategoryList, Map<Long, Long> oldShopIdMap) {
List<CurShopProdCategory> curShopProdCategories = new ArrayList<>();
for (OldShopCategory oldShopCategory : oldShopCategoryList) {
Long shopId = oldShopIdMap.get(Long.valueOf(oldShopCategory.getShopId()));
CurShopProdCategory curShopProdCategory = new CurShopProdCategory();
curShopProdCategory.setId(Long.valueOf(oldShopCategory.getId()));
curShopProdCategory.setShopId(shopId == null ? 1L : shopId);
curShopProdCategory.setName(oldShopCategory.getName());
curShopProdCategory.setShortName(oldShopCategory.getShortName());
curShopProdCategory.setPid(StrUtil.isBlank(oldShopCategory.getPid()) ? 1L : Long.parseLong(oldShopCategory.getPid()));
curShopProdCategory.setPic(oldShopCategory.getPic());
curShopProdCategory.setDetail(oldShopCategory.getDetail());
curShopProdCategory.setSort(oldShopCategory.getSort());
curShopProdCategory.setKeyWord(oldShopCategory.getKeyWord());
curShopProdCategory.setStatus(1);
curShopProdCategory.setCreateTime(DateUtil.toLocalDateTime(oldShopCategory.getCreatedAt() == null ? new Date() : new Date(oldShopCategory.getCreatedAt())));
curShopProdCategories.add(curShopProdCategory);
}
saveBatch(curShopProdCategories);
}
}

View File

@ -0,0 +1,81 @@
package com.czg.mergedata.old.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.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Pad商品自定义分类 实体类
*
* @author mac
* @since 2025-02-17
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_pad_product_category")
public class OldPadProductCategory implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 布局版式id
*/
private Long padLayoutId;
/**
* 自定义名称
*/
private String customName;
/**
* 商品分类id
*/
private Long productCategoryId;
/**
* 店铺id
*/
private Long shopId;
/**
* 排序
*/
private Integer sort;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
/**
* 更新时间
*/
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
}

View File

@ -0,0 +1,55 @@
package com.czg.mergedata.old.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.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Pad商品自定义分类明细 实体类
*
* @author mac
* @since 2025-02-17
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_pad_product_category_detail")
public class OldPadProductCategoryDetail implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* Pad商品自定义分类id
*/
private Long padProductCategoryId;
/**
* 商品id
*/
private Long productId;
/**
* 创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,101 @@
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.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 店内分类 实体类
*
* @author mac
* @since 2025-02-17
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_category")
public class OldShopCategory implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 自增id
*/
@Id(keyType = KeyType.Auto)
private Integer id;
/**
* 分类名称
*/
private String name;
/**
* 简称
*/
private String shortName;
/**
* 分类层级
*/
private Integer tree;
/**
* 上级分类id-为0则表示是顶级
*/
private String pid;
/**
* 图标
*/
private String pic;
/**
* 商户Id
*/
private String merchantId;
/**
* 店铺Id
*/
private String shopId;
/**
* 颜色格式标识
*/
private String style;
/**
* 是否显示1显示 0不显示
*/
private Integer isShow;
/**
* 分类描述
*/
private String detail;
/**
* 排序
*/
private Integer sort;
/**
* 关键词
*/
private String keyWord;
private Long createdAt;
private Long updatedAt;
}

View File

@ -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.OldPadProductCategoryDetail;
/**
* Pad商品自定义分类明细 映射层
*
* @author mac
* @since 2025-02-17
*/
@UseDataSource("ds2")
public interface OldPadProductCategoryDetailMapper extends BaseMapper<OldPadProductCategoryDetail> {
}

View File

@ -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.OldPadProductCategory;
/**
* Pad商品自定义分类 映射层
*
* @author mac
* @since 2025-02-17
*/
@UseDataSource("ds2")
public interface OldPadProductCategoryMapper extends BaseMapper<OldPadProductCategory> {
}

View File

@ -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.OldShopCategory;
/**
* 店内分类 映射层
*
* @author mac
* @since 2025-02-17
*/
@UseDataSource("ds2")
public interface OldShopCategoryMapper extends BaseMapper<OldShopCategory> {
}

View File

@ -0,0 +1,14 @@
package com.czg.mergedata.old.service;
import com.mybatisflex.core.service.IService;
import com.czg.mergedata.old.entity.OldPadProductCategoryDetail;
/**
* Pad商品自定义分类明细 服务层
*
* @author mac
* @since 2025-02-17
*/
public interface OldPadProductCategoryDetailService extends IService<OldPadProductCategoryDetail> {
}

View File

@ -0,0 +1,14 @@
package com.czg.mergedata.old.service;
import com.mybatisflex.core.service.IService;
import com.czg.mergedata.old.entity.OldPadProductCategory;
/**
* Pad商品自定义分类 服务层
*
* @author mac
* @since 2025-02-17
*/
public interface OldPadProductCategoryService extends IService<OldPadProductCategory> {
}

View File

@ -0,0 +1,14 @@
package com.czg.mergedata.old.service;
import com.mybatisflex.core.service.IService;
import com.czg.mergedata.old.entity.OldShopCategory;
/**
* 店内分类 服务层
*
* @author mac
* @since 2025-02-17
*/
public interface OldShopCategoryService extends IService<OldShopCategory> {
}

View File

@ -0,0 +1,18 @@
package com.czg.mergedata.old.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.mergedata.old.entity.OldPadProductCategoryDetail;
import com.czg.mergedata.old.mapper.OldPadProductCategoryDetailMapper;
import com.czg.mergedata.old.service.OldPadProductCategoryDetailService;
import org.springframework.stereotype.Service;
/**
* Pad商品自定义分类明细 服务层实现
*
* @author mac
* @since 2025-02-17
*/
@Service
public class OldPadProductCategoryDetailServiceImpl extends ServiceImpl<OldPadProductCategoryDetailMapper, OldPadProductCategoryDetail> implements OldPadProductCategoryDetailService{
}

View File

@ -0,0 +1,18 @@
package com.czg.mergedata.old.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.mergedata.old.entity.OldPadProductCategory;
import com.czg.mergedata.old.mapper.OldPadProductCategoryMapper;
import com.czg.mergedata.old.service.OldPadProductCategoryService;
import org.springframework.stereotype.Service;
/**
* Pad商品自定义分类 服务层实现
*
* @author mac
* @since 2025-02-17
*/
@Service
public class OldPadProductCategoryServiceImpl extends ServiceImpl<OldPadProductCategoryMapper, OldPadProductCategory> implements OldPadProductCategoryService{
}

View File

@ -0,0 +1,18 @@
package com.czg.mergedata.old.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.mergedata.old.entity.OldShopCategory;
import com.czg.mergedata.old.mapper.OldShopCategoryMapper;
import com.czg.mergedata.old.service.OldShopCategoryService;
import org.springframework.stereotype.Service;
/**
* 店内分类 服务层实现
*
* @author mac
* @since 2025-02-17
*/
@Service
public class OldShopCategoryServiceImpl extends ServiceImpl<OldShopCategoryMapper, OldShopCategory> implements OldShopCategoryService{
}

View File

@ -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.CurPadProductCategoryDetailMapper">
</mapper>

View File

@ -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.CurPadProductCategoryMapper">
</mapper>

View File

@ -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.CurShopProdCategoryMapper">
</mapper>

View File

@ -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.OldPadProductCategoryDetailMapper">
</mapper>

View File

@ -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.OldPadProductCategoryMapper">
</mapper>

View File

@ -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.OldShopCategoryMapper">
</mapper>