迁移 pad 点餐

This commit is contained in:
GYJ
2025-02-19 10:47:00 +08:00
parent aaf2dc361d
commit 788987dc7c
14 changed files with 412 additions and 5 deletions

View File

@@ -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_shop_table_booking");
.setGenerateTable("tb_pad_layout");
EntityConfig entityConfig = globalConfig.getEntityConfig();
if (isOldVersion) {

View File

@@ -0,0 +1,23 @@
package com.czg.mergedata.controller;
import com.czg.mergedata.common.resp.CzgResult;
import com.czg.mergedata.cur.service.CurPadLayoutService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author GYJoker
*/
@RestController
@RequestMapping("/pad")
public class PadController {
@Resource
private CurPadLayoutService curPadLayoutService;
@RequestMapping("/mergePad")
public CzgResult<String> mergePad() {
return curPadLayoutService.mergeData();
}
}

View File

@@ -0,0 +1,75 @@
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-19
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_pad_layout")
public class CurPadLayout implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 布局版式名称
*/
private String name;
/**
* 布局版式代码
*/
private String code;
/**
* 允许展示最大商品数
*/
private Integer maximum;
/**
* 详细描述
*/
private String remark;
/**
* 排序号,升序
*/
private Integer sort;
/**
* 创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
/**
* 删除标志 0-正常 1-已删除
*/
private Integer isDel;
}

View File

@@ -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.CurPadLayout;
import org.apache.ibatis.annotations.Select;
/**
* Pad商品布局版式 映射层。
*
* @author mac
* @since 2025-02-19
*/
@UseDataSource("ds1")
public interface CurPadLayoutMapper extends BaseMapper<CurPadLayout> {
@Select("truncate tb_pad_layout")
void truncateTable();
}

View File

@@ -3,6 +3,7 @@ package com.czg.mergedata.cur.mapper;
import com.mybatisflex.annotation.UseDataSource;
import com.mybatisflex.core.BaseMapper;
import com.czg.mergedata.cur.entity.CurPadProductCategoryDetail;
import org.apache.ibatis.annotations.Select;
/**
* Pad商品自定义分类明细 映射层。
@@ -12,5 +13,6 @@ import com.czg.mergedata.cur.entity.CurPadProductCategoryDetail;
*/
@UseDataSource("ds1")
public interface CurPadProductCategoryDetailMapper extends BaseMapper<CurPadProductCategoryDetail> {
@Select("truncate tb_pad_product_category_detail")
void truncateTable();
}

View File

@@ -3,6 +3,7 @@ package com.czg.mergedata.cur.mapper;
import com.mybatisflex.annotation.UseDataSource;
import com.mybatisflex.core.BaseMapper;
import com.czg.mergedata.cur.entity.CurPadProductCategory;
import org.apache.ibatis.annotations.Select;
/**
* Pad商品自定义分类 映射层。
@@ -12,5 +13,6 @@ import com.czg.mergedata.cur.entity.CurPadProductCategory;
*/
@UseDataSource("ds1")
public interface CurPadProductCategoryMapper extends BaseMapper<CurPadProductCategory> {
@Select("truncate tb_pad_product_category")
void truncateTable();
}

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.CurPadLayout;
/**
* Pad商品布局版式 服务层。
*
* @author mac
* @since 2025-02-19
*/
public interface CurPadLayoutService extends IService<CurPadLayout> {
CzgResult<String> mergeData();
}

View File

@@ -0,0 +1,135 @@
package com.czg.mergedata.cur.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.czg.mergedata.common.resp.CzgResult;
import com.czg.mergedata.common.utils.PageUtils;
import com.czg.mergedata.cur.entity.CurPadLayout;
import com.czg.mergedata.cur.entity.CurPadProductCategory;
import com.czg.mergedata.cur.entity.CurPadProductCategoryDetail;
import com.czg.mergedata.cur.mapper.CurPadLayoutMapper;
import com.czg.mergedata.cur.mapper.CurPadProductCategoryDetailMapper;
import com.czg.mergedata.cur.mapper.CurPadProductCategoryMapper;
import com.czg.mergedata.cur.service.CurPadLayoutService;
import com.czg.mergedata.cur.service.CurShopIdRelationService;
import com.czg.mergedata.old.entity.OldPadLayout;
import com.czg.mergedata.old.entity.OldPadProductCategory;
import com.czg.mergedata.old.entity.OldPadProductCategoryDetail;
import com.czg.mergedata.old.service.OldPadLayoutService;
import com.czg.mergedata.old.service.OldPadProductCategoryDetailService;
import com.czg.mergedata.old.service.OldPadProductCategoryService;
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.List;
import java.util.Map;
/**
* Pad商品布局版式 服务层实现。
*
* @author mac
* @since 2025-02-19
*/
@Service
public class CurPadLayoutServiceImpl extends ServiceImpl<CurPadLayoutMapper, CurPadLayout> implements CurPadLayoutService {
@Resource
private CurShopIdRelationService curShopIdRelationService;
@Resource
private CurPadProductCategoryMapper curPadProductCategoryMapper;
@Resource
private CurPadProductCategoryDetailMapper curPadProductCategoryDetailMapper;
@Resource
private OldPadLayoutService oldPadLayoutService;
@Resource
private OldPadProductCategoryService oldPadProductCategoryService;
@Resource
private OldPadProductCategoryDetailService oldPadProductCategoryDetailService;
@Override
@Transactional
public CzgResult<String> mergeData() {
getMapper().truncateTable();
curPadProductCategoryMapper.truncateTable();
curPadProductCategoryDetailMapper.truncateTable();
Map<Long, Long> oldAndCurShopIdMap = curShopIdRelationService.getOldShopIdRelation();
execPadLayout();
execPadProductCategory(oldAndCurShopIdMap);
execPadProductCategoryDetail();
return CzgResult.success("迁移成功");
}
private void execPadLayout() {
Page<OldPadLayout> page = oldPadLayoutService.page(PageUtils.buildPage());
while (!page.getRecords().isEmpty()) {
savePadLayout(page.getRecords());
page = oldPadLayoutService.page(PageUtils.buildPage(page.getPageNumber() + 1));
}
}
private void execPadProductCategory(Map<Long, Long> oldAndCurShopIdMap) {
Page<OldPadProductCategory> page = oldPadProductCategoryService.page(PageUtils.buildPage());
while (!page.getRecords().isEmpty()) {
savePadProductCategory(page.getRecords(), oldAndCurShopIdMap);
page = oldPadProductCategoryService.page(PageUtils.buildPage(page.getPageNumber() + 1));
}
}
private void execPadProductCategoryDetail() {
Page<OldPadProductCategoryDetail> page = oldPadProductCategoryDetailService.page(PageUtils.buildPage());
while (!page.getRecords().isEmpty()) {
savePadProductCategoryDetail(page.getRecords());
page = oldPadProductCategoryDetailService.page(PageUtils.buildPage(page.getPageNumber() + 1));
}
}
private void savePadLayout(List<OldPadLayout> oldPadLayoutList) {
List<CurPadLayout> curPadLayoutList = new ArrayList<>();
for (OldPadLayout oldPadLayout : oldPadLayoutList) {
CurPadLayout curPadLayout = BeanUtil.toBean(oldPadLayout, CurPadLayout.class);
curPadLayout.setIsDel(oldPadLayout.getDelFlag());
curPadLayoutList.add(curPadLayout);
}
saveBatch(curPadLayoutList);
}
private void savePadProductCategory(List<OldPadProductCategory> oldPadProductCategoryList, Map<Long, Long> oldAndCurShopIdMap) {
List<CurPadProductCategory> curPadProductCategoryList = new ArrayList<>();
for (OldPadProductCategory oldPadProductCategory : oldPadProductCategoryList) {
CurPadProductCategory curPadProductCategory = BeanUtil.toBean(oldPadProductCategory, CurPadProductCategory.class);
curPadProductCategory.setShopId(oldAndCurShopIdMap.get(oldPadProductCategory.getShopId()));
curPadProductCategoryList.add(curPadProductCategory);
}
curPadProductCategoryMapper.insertBatch(curPadProductCategoryList);
}
private void savePadProductCategoryDetail(List<OldPadProductCategoryDetail> oldPadProductCategoryDetailList) {
List<CurPadProductCategoryDetail> curPadProductCategoryDetailList = new ArrayList<>();
for (OldPadProductCategoryDetail oldPadProductCategoryDetail : oldPadProductCategoryDetailList) {
CurPadProductCategoryDetail curPadProductCategoryDetail = BeanUtil.toBean(oldPadProductCategoryDetail, CurPadProductCategoryDetail.class);
curPadProductCategoryDetailList.add(curPadProductCategoryDetail);
}
curPadProductCategoryDetailMapper.insertBatch(curPadProductCategoryDetailList);
}
}

View File

@@ -0,0 +1,75 @@
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-19
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_pad_layout")
public class OldPadLayout implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 布局版式名称
*/
private String name;
/**
* 布局版式代码
*/
private String code;
/**
* 允许展示最大商品数
*/
private Integer maximum;
/**
* 详细描述
*/
private String remark;
/**
* 排序号,升序
*/
private Integer sort;
/**
* 创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
/**
* 删除标志 0-正常 1-已删除
*/
private Integer delFlag;
}

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.OldPadLayout;
/**
* Pad商品布局版式 映射层。
*
* @author mac
* @since 2025-02-19
*/
@UseDataSource("ds2")
public interface OldPadLayoutMapper extends BaseMapper<OldPadLayout> {
}

View File

@@ -0,0 +1,14 @@
package com.czg.mergedata.old.service;
import com.mybatisflex.core.service.IService;
import com.czg.mergedata.old.entity.OldPadLayout;
/**
* Pad商品布局版式 服务层。
*
* @author mac
* @since 2025-02-19
*/
public interface OldPadLayoutService extends IService<OldPadLayout> {
}

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.OldPadLayout;
import com.czg.mergedata.old.mapper.OldPadLayoutMapper;
import com.czg.mergedata.old.service.OldPadLayoutService;
import org.springframework.stereotype.Service;
/**
* Pad商品布局版式 服务层实现。
*
* @author mac
* @since 2025-02-19
*/
@Service
public class OldPadLayoutServiceImpl extends ServiceImpl<OldPadLayoutMapper, OldPadLayout> implements OldPadLayoutService{
}

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.CurPadLayoutMapper">
</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.OldPadLayoutMapper">
</mapper>