迁移 商品分组
This commit is contained in:
parent
f725704a80
commit
db62a13566
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ public class ProductController {
|
|||
@Resource
|
||||
private CurProdSkuService curProdSkuService;
|
||||
|
||||
@Resource
|
||||
private CurProdGroupService curProdGroupService;
|
||||
|
||||
@GetMapping("/mergeUnit")
|
||||
public CzgResult<String> mergeUnit() {
|
||||
return curShopProdUnitService.mergeProductUnit();
|
||||
|
|
@ -54,4 +57,9 @@ public class ProductController {
|
|||
return curProdSkuService.mergeData();
|
||||
}
|
||||
|
||||
@GetMapping("/mergeGroup")
|
||||
public CzgResult<String> mergeGroup() {
|
||||
return curProdGroupService.mergeData();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
@ -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<CurProdGroup> {
|
||||
|
||||
@Select("truncate tb_prod_group")
|
||||
void truncateTable();
|
||||
}
|
||||
|
|
@ -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<CurProdGroupRelation> {
|
||||
@Select("truncate tb_prod_group_relation")
|
||||
void truncateTable();
|
||||
}
|
||||
|
|
@ -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<CurProdGroupRelation> {
|
||||
|
||||
}
|
||||
|
|
@ -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<CurProdGroup> {
|
||||
|
||||
CzgResult<String> mergeData();
|
||||
|
||||
}
|
||||
|
|
@ -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<CurProdGroupRelationMapper, CurProdGroupRelation> implements CurProdGroupRelationService{
|
||||
|
||||
}
|
||||
|
|
@ -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<CurProdGroupMapper, CurProdGroup> implements CurProdGroupService{
|
||||
|
||||
@Resource
|
||||
private CurProdGroupRelationMapper curProdGroupRelationMapper;
|
||||
|
||||
@Resource
|
||||
private CurShopIdRelationService curShopIdRelationService;
|
||||
|
||||
@Resource
|
||||
private OldProductGroupService oldProductGroupService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<String> mergeData() {
|
||||
getMapper().truncateTable();
|
||||
curProdGroupRelationMapper.truncateTable();
|
||||
|
||||
Map<Long, Long> oldAndCurShopIdMap = curShopIdRelationService.getOldShopIdRelation();
|
||||
|
||||
execProdGroup(oldAndCurShopIdMap);
|
||||
|
||||
return CzgResult.success("迁移成功");
|
||||
}
|
||||
|
||||
private void execProdGroup(Map<Long, Long> oldAndCurShopIdMap) {
|
||||
Page<OldProductGroup> 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<OldProductGroup> oldProductGroupList, Map<Long, Long> oldAndCurShopIdMap) {
|
||||
List<CurProdGroup> curProdGroupList = new ArrayList<>();
|
||||
List<CurProdGroupRelation> 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<Long> 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
@ -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<OldProductGroup> {
|
||||
|
||||
}
|
||||
|
|
@ -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<OldProductGroup> {
|
||||
|
||||
}
|
||||
|
|
@ -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<OldProductGroupMapper, OldProductGroup> implements OldProductGroupService{
|
||||
|
||||
}
|
||||
|
|
@ -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.CurProdGroupMapper">
|
||||
|
||||
</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.cur.mapper.CurProdGroupRelationMapper">
|
||||
|
||||
</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.OldProductGroupMapper">
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue