diff --git a/src/main/java/com/czg/mergedata/common/utils/CodeGen.java b/src/main/java/com/czg/mergedata/common/utils/CodeGen.java index 99b653a..ecaf08d 100644 --- a/src/main/java/com/czg/mergedata/common/utils/CodeGen.java +++ b/src/main/java/com/czg/mergedata/common/utils/CodeGen.java @@ -18,8 +18,8 @@ public class CodeGen { private final static String DATABASE = "czg_cashier"; private final static String OLD_DATABASE = "fycashier_test"; -// private final static boolean isOldVersion = false; - private final static boolean isOldVersion = true; + private final static boolean isOldVersion = false; +// private final static boolean isOldVersion = true; public static void main(String[] args) { //配置数据源 @@ -81,7 +81,7 @@ public class CodeGen { //设置表前缀和只生成哪些表,setGenerateTable 未配置时,生成所有表 globalConfig.getStrategyConfig() .setTablePrefix("tb_") - .setGenerateTable("tb_product_sku"); + .setGenerateTable("tb_prod_group_relation"); EntityConfig entityConfig = globalConfig.getEntityConfig(); if (isOldVersion) { diff --git a/src/main/java/com/czg/mergedata/controller/ProductController.java b/src/main/java/com/czg/mergedata/controller/ProductController.java index b502fa0..eca95d9 100644 --- a/src/main/java/com/czg/mergedata/controller/ProductController.java +++ b/src/main/java/com/czg/mergedata/controller/ProductController.java @@ -29,6 +29,9 @@ public class ProductController { @Resource private CurProdSkuService curProdSkuService; + @Resource + private CurProdGroupService curProdGroupService; + @GetMapping("/mergeUnit") public CzgResult mergeUnit() { return curShopProdUnitService.mergeProductUnit(); @@ -54,4 +57,9 @@ public class ProductController { return curProdSkuService.mergeData(); } + @GetMapping("/mergeGroup") + public CzgResult mergeGroup() { + return curProdGroupService.mergeData(); + } + } diff --git a/src/main/java/com/czg/mergedata/cur/entity/CurProdGroup.java b/src/main/java/com/czg/mergedata/cur/entity/CurProdGroup.java new file mode 100644 index 0000000..9d776a5 --- /dev/null +++ b/src/main/java/com/czg/mergedata/cur/entity/CurProdGroup.java @@ -0,0 +1,91 @@ +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.sql.Time; +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-18 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Table("tb_prod_group") +public class CurProdGroup implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * id + */ + @Id(keyType = KeyType.Auto) + private Long id; + + /** + * 分组名称 + */ + private String name; + + /** + * 店铺Id + */ + private Long shopId; + + /** + * 图标 + */ + private String pic; + + /** + * 状态 0-禁用 1-启用 + */ + private Integer status; + + /** + * 排序 + */ + private Integer sort; + + /** + * 排序方式 0-默认; 1-价格从高到低; 2-销量由高到低; + */ + private String sortMode; + + /** + * 开启时间管控 0:否;1:是 + */ + private Integer useTime; + + /** + * 售卖开始时间 + */ + private String saleStartTime; + + /** + * 售卖结束时间 + */ + private String saleEndTime; + + @Column(onInsertValue = "now()") + private LocalDateTime createTime; + + @Column(onInsertValue = "now()", onUpdateValue = "now()") + private LocalDateTime updateTime; + +} diff --git a/src/main/java/com/czg/mergedata/cur/entity/CurProdGroupRelation.java b/src/main/java/com/czg/mergedata/cur/entity/CurProdGroupRelation.java new file mode 100644 index 0000000..f083560 --- /dev/null +++ b/src/main/java/com/czg/mergedata/cur/entity/CurProdGroupRelation.java @@ -0,0 +1,47 @@ +package com.czg.mergedata.cur.entity; + +import com.mybatisflex.annotation.Id; +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-18 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Table("tb_prod_group_relation") +public class CurProdGroupRelation implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 商品id + */ + @Id + private Long productId; + + /** + * 商品分组id + */ + @Id + private Long prodGroupId; + + /** + * 排序值 + */ + private Integer sort; + +} diff --git a/src/main/java/com/czg/mergedata/cur/mapper/CurProdGroupMapper.java b/src/main/java/com/czg/mergedata/cur/mapper/CurProdGroupMapper.java new file mode 100644 index 0000000..1391e2e --- /dev/null +++ b/src/main/java/com/czg/mergedata/cur/mapper/CurProdGroupMapper.java @@ -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.CurProdGroup; +import org.apache.ibatis.annotations.Select; + +/** + * 商品分组 映射层。 + * + * @author mac + * @since 2025-02-18 + */ +@UseDataSource("ds1") +public interface CurProdGroupMapper extends BaseMapper { + + @Select("truncate tb_prod_group") + void truncateTable(); +} diff --git a/src/main/java/com/czg/mergedata/cur/mapper/CurProdGroupRelationMapper.java b/src/main/java/com/czg/mergedata/cur/mapper/CurProdGroupRelationMapper.java new file mode 100644 index 0000000..32ef9c0 --- /dev/null +++ b/src/main/java/com/czg/mergedata/cur/mapper/CurProdGroupRelationMapper.java @@ -0,0 +1,18 @@ +package com.czg.mergedata.cur.mapper; + +import com.mybatisflex.annotation.UseDataSource; +import com.mybatisflex.core.BaseMapper; +import com.czg.mergedata.cur.entity.CurProdGroupRelation; +import org.apache.ibatis.annotations.Select; + +/** + * 商品分组关系 映射层。 + * + * @author mac + * @since 2025-02-18 + */ +@UseDataSource("ds1") +public interface CurProdGroupRelationMapper extends BaseMapper { + @Select("truncate tb_prod_group_relation") + void truncateTable(); +} diff --git a/src/main/java/com/czg/mergedata/cur/service/CurProdGroupRelationService.java b/src/main/java/com/czg/mergedata/cur/service/CurProdGroupRelationService.java new file mode 100644 index 0000000..364f780 --- /dev/null +++ b/src/main/java/com/czg/mergedata/cur/service/CurProdGroupRelationService.java @@ -0,0 +1,14 @@ +package com.czg.mergedata.cur.service; + +import com.mybatisflex.core.service.IService; +import com.czg.mergedata.cur.entity.CurProdGroupRelation; + +/** + * 商品分组关系 服务层。 + * + * @author mac + * @since 2025-02-18 + */ +public interface CurProdGroupRelationService extends IService { + +} diff --git a/src/main/java/com/czg/mergedata/cur/service/CurProdGroupService.java b/src/main/java/com/czg/mergedata/cur/service/CurProdGroupService.java new file mode 100644 index 0000000..005bcfb --- /dev/null +++ b/src/main/java/com/czg/mergedata/cur/service/CurProdGroupService.java @@ -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.CurProdGroup; + +/** + * 商品分组 服务层。 + * + * @author mac + * @since 2025-02-18 + */ +public interface CurProdGroupService extends IService { + + CzgResult mergeData(); + +} diff --git a/src/main/java/com/czg/mergedata/cur/service/impl/CurProdGroupRelationServiceImpl.java b/src/main/java/com/czg/mergedata/cur/service/impl/CurProdGroupRelationServiceImpl.java new file mode 100644 index 0000000..2847088 --- /dev/null +++ b/src/main/java/com/czg/mergedata/cur/service/impl/CurProdGroupRelationServiceImpl.java @@ -0,0 +1,18 @@ +package com.czg.mergedata.cur.service.impl; + +import com.mybatisflex.spring.service.impl.ServiceImpl; +import com.czg.mergedata.cur.entity.CurProdGroupRelation; +import com.czg.mergedata.cur.mapper.CurProdGroupRelationMapper; +import com.czg.mergedata.cur.service.CurProdGroupRelationService; +import org.springframework.stereotype.Service; + +/** + * 商品分组关系 服务层实现。 + * + * @author mac + * @since 2025-02-18 + */ +@Service +public class CurProdGroupRelationServiceImpl extends ServiceImpl implements CurProdGroupRelationService{ + +} diff --git a/src/main/java/com/czg/mergedata/cur/service/impl/CurProdGroupServiceImpl.java b/src/main/java/com/czg/mergedata/cur/service/impl/CurProdGroupServiceImpl.java new file mode 100644 index 0000000..8e4d996 --- /dev/null +++ b/src/main/java/com/czg/mergedata/cur/service/impl/CurProdGroupServiceImpl.java @@ -0,0 +1,102 @@ +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; +import com.czg.mergedata.cur.entity.CurProdGroup; +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; +import com.mybatisflex.spring.service.impl.ServiceImpl; +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; + +/** + * 商品分组 服务层实现。 + * + * @author mac + * @since 2025-02-18 + */ +@Service +public class CurProdGroupServiceImpl extends ServiceImpl implements CurProdGroupService{ + + @Resource + private CurProdGroupRelationMapper curProdGroupRelationMapper; + + @Resource + private CurShopIdRelationService curShopIdRelationService; + + @Resource + private OldProductGroupService oldProductGroupService; + + @Override + @Transactional + public CzgResult mergeData() { + getMapper().truncateTable(); + curProdGroupRelationMapper.truncateTable(); + + Map oldAndCurShopIdMap = curShopIdRelationService.getOldShopIdRelation(); + + execProdGroup(oldAndCurShopIdMap); + + return CzgResult.success("迁移成功"); + } + + private void execProdGroup(Map oldAndCurShopIdMap) { + Page page = oldProductGroupService.page(PageUtils.buildPage()); + + while (!page.getRecords().isEmpty()) { + saveProdGroup(page.getRecords(), oldAndCurShopIdMap); + page = oldProductGroupService.page(PageUtils.buildPage(page.getPageNumber() + 1)); + } + } + + private void saveProdGroup(List oldProductGroupList, Map oldAndCurShopIdMap) { + List curProdGroupList = new ArrayList<>(); + List curProdGroupRelationList = new ArrayList<>(); + + for (OldProductGroup oldProductGroup : oldProductGroupList) { + CurProdGroup curProdGroup = new CurProdGroup(); + + curProdGroup.setId(Long.valueOf(oldProductGroup.getId())); + curProdGroup.setName(oldProductGroup.getName()); + curProdGroup.setShopId(oldAndCurShopIdMap.get(Long.valueOf(oldProductGroup.getId()))); + curProdGroup.setPic(oldProductGroup.getPic()); + curProdGroup.setStatus(oldProductGroup.getIsShow()); + curProdGroup.setSort(oldProductGroup.getSort()); + curProdGroup.setSortMode(oldProductGroup.getSortMode()); + curProdGroup.setUseTime(oldProductGroup.getUseTime()); + curProdGroup.setSaleStartTime(oldProductGroup.getSaleStartTime()); + curProdGroup.setSaleEndTime(oldProductGroup.getSaleEndTime()); + curProdGroup.setCreateTime(DateUtil.toLocalDateTime(oldProductGroup.getCreatedAt() == null ? new Date() : new Date(oldProductGroup.getCreatedAt()))); + + curProdGroupList.add(curProdGroup); + + List list = JSONArray.parseArray(oldProductGroup.getProductIds(), Long.class); + for (Long productId : list) { + CurProdGroupRelation curProdGroupRelation = new CurProdGroupRelation(); + curProdGroupRelation.setProductId(productId); + curProdGroupRelation.setProdGroupId(Long.valueOf(oldProductGroup.getId())); + curProdGroupRelation.setSort(1); + curProdGroupRelationList.add(curProdGroupRelation); + } + } + + saveBatch(curProdGroupList); + curProdGroupRelationMapper.insertBatch(curProdGroupRelationList); + } +} diff --git a/src/main/java/com/czg/mergedata/old/entity/OldProductGroup.java b/src/main/java/com/czg/mergedata/old/entity/OldProductGroup.java new file mode 100644 index 0000000..654f903 --- /dev/null +++ b/src/main/java/com/czg/mergedata/old/entity/OldProductGroup.java @@ -0,0 +1,103 @@ +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-18 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Table("tb_product_group") +public class OldProductGroup implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * id + */ + @Id(keyType = KeyType.Auto) + private Integer id; + + /** + * 分组名称 + */ + private String name; + + /** + * 商户Id + */ + private String merchantId; + + /** + * 店铺Id + */ + private Integer shopId; + + /** + * 图标 + */ + private String pic; + + /** + * 是否显示:1显示 0不显示 + */ + private Integer isShow; + + /** + * 分类描述 + */ + private String detail; + + private String style; + + /** + * 排序 + */ + private Integer sort; + + /** + * 排序方式 0-默认; 1-价格从高到低; 2-销量由高到低; + */ + private String sortMode; + + /** + * 商品Id列表 + */ + private String productIds; + + private Long createdAt; + + private Long updatedAt; + + /** + * 开启时间管控 0:否;1:是 + */ + private Integer useTime; + + /** + * 售卖开始时间 + */ + private String saleStartTime; + + /** + * 售卖结束时间 + */ + private String saleEndTime; + +} diff --git a/src/main/java/com/czg/mergedata/old/mapper/OldProductGroupMapper.java b/src/main/java/com/czg/mergedata/old/mapper/OldProductGroupMapper.java new file mode 100644 index 0000000..bc9b491 --- /dev/null +++ b/src/main/java/com/czg/mergedata/old/mapper/OldProductGroupMapper.java @@ -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.OldProductGroup; + +/** + * 商品分组 映射层。 + * + * @author mac + * @since 2025-02-18 + */ +@UseDataSource("ds2") +public interface OldProductGroupMapper extends BaseMapper { + +} diff --git a/src/main/java/com/czg/mergedata/old/service/OldProductGroupService.java b/src/main/java/com/czg/mergedata/old/service/OldProductGroupService.java new file mode 100644 index 0000000..b1bb29d --- /dev/null +++ b/src/main/java/com/czg/mergedata/old/service/OldProductGroupService.java @@ -0,0 +1,14 @@ +package com.czg.mergedata.old.service; + +import com.mybatisflex.core.service.IService; +import com.czg.mergedata.old.entity.OldProductGroup; + +/** + * 商品分组 服务层。 + * + * @author mac + * @since 2025-02-18 + */ +public interface OldProductGroupService extends IService { + +} diff --git a/src/main/java/com/czg/mergedata/old/service/impl/OldProductGroupServiceImpl.java b/src/main/java/com/czg/mergedata/old/service/impl/OldProductGroupServiceImpl.java new file mode 100644 index 0000000..2fbbde1 --- /dev/null +++ b/src/main/java/com/czg/mergedata/old/service/impl/OldProductGroupServiceImpl.java @@ -0,0 +1,18 @@ +package com.czg.mergedata.old.service.impl; + +import com.mybatisflex.spring.service.impl.ServiceImpl; +import com.czg.mergedata.old.entity.OldProductGroup; +import com.czg.mergedata.old.mapper.OldProductGroupMapper; +import com.czg.mergedata.old.service.OldProductGroupService; +import org.springframework.stereotype.Service; + +/** + * 商品分组 服务层实现。 + * + * @author mac + * @since 2025-02-18 + */ +@Service +public class OldProductGroupServiceImpl extends ServiceImpl implements OldProductGroupService{ + +} diff --git a/src/main/resources/mapper/cur/ProdGroupMapper.xml b/src/main/resources/mapper/cur/ProdGroupMapper.xml new file mode 100644 index 0000000..53b3f51 --- /dev/null +++ b/src/main/resources/mapper/cur/ProdGroupMapper.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/src/main/resources/mapper/cur/ProdGroupRelationMapper.xml b/src/main/resources/mapper/cur/ProdGroupRelationMapper.xml new file mode 100644 index 0000000..9ff2400 --- /dev/null +++ b/src/main/resources/mapper/cur/ProdGroupRelationMapper.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/src/main/resources/mapper/old/ProductGroupMapper.xml b/src/main/resources/mapper/old/ProductGroupMapper.xml new file mode 100644 index 0000000..6a5d675 --- /dev/null +++ b/src/main/resources/mapper/old/ProductGroupMapper.xml @@ -0,0 +1,7 @@ + + + + +