迁移 店铺 coupon

This commit is contained in:
GYJ
2025-02-18 15:02:36 +08:00
parent b2f734ff23
commit 8c42d61bd0
22 changed files with 727 additions and 3 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_group_order_coupon");
.setGenerateTable("tb_coupon_product");
EntityConfig entityConfig = globalConfig.getEntityConfig();
if (isOldVersion) {

View File

@@ -2,6 +2,7 @@ package com.czg.mergedata.controller;
import com.czg.mergedata.common.resp.CzgResult;
import com.czg.mergedata.cur.service.CurCouponCategoryService;
import com.czg.mergedata.cur.service.CurShopCouponService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -16,8 +17,16 @@ public class CouponController {
@Resource
private CurCouponCategoryService curCouponCategoryService;
@Resource
private CurShopCouponService curShopCouponService;
@GetMapping("/category")
public CzgResult<String> mergeCategory() {
return curCouponCategoryService.mergeData();
}
@GetMapping("/shopCoupon")
public CzgResult<String> mergeShopCoupon() {
return curShopCouponService.mergeData();
}
}

View File

@@ -0,0 +1,144 @@
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.math.BigDecimal;
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_shop_coupon")
public class CurShopCoupon implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 自增
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 状态0-关闭 1 正常
*/
private Integer status;
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
/**
* 名称(无意义)
*/
private String title;
private Long shopId;
/**
* 已使用数量
*/
private Integer useNumber;
/**
* 发放数量
*/
private Integer number;
/**
* 剩余数量
*/
private Integer leftNumber;
/**
* 有效期类型,可选值为 fixed固定时间/custom自定义时间
*/
private String validityType;
/**
* 有效天数
*/
private Integer validDays;
/**
* 隔多少天生效
*/
private Integer daysToTakeEffect;
/**
* 有效开始时间
*/
private LocalDateTime validStartTime;
/**
* 有效结束时间
*/
private LocalDateTime validEndTime;
/**
* 周 数组["周一","周二"]
*/
private String userDays;
/**
* all-全时段 custom-指定时段
*/
private String useTimeType;
/**
* 可用开始时间
*/
private Time useStartTime;
/**
* 可用结束时间
*/
private Time useEndTime;
/**
* 1-满减 2-商品
*/
private Integer type;
/**
* 满多少金额
*/
private BigDecimal fullAmount;
/**
* 减多少金额
*/
private BigDecimal discountAmount;
/**
* 描述
*/
private String description;
/**
* 发放人
*/
private String editor;
}

View File

@@ -0,0 +1,57 @@
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-18
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_coupon_product")
public class CurShopCouponProduct implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 活动Id
*/
private Long couponId;
/**
* 商品id
*/
private Long productId;
/**
* 数量
*/
private Integer num;
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
}

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.CurShopCoupon;
import org.apache.ibatis.annotations.Select;
/**
* 优惠券 映射层。
*
* @author mac
* @since 2025-02-18
*/
@UseDataSource("ds1")
public interface CurShopCouponMapper extends BaseMapper<CurShopCoupon> {
@Select("truncate tb_shop_coupon")
void truncateTable();
}

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.CurShopCouponProduct;
import org.apache.ibatis.annotations.Select;
/**
* 活动赠送商品表 映射层。
*
* @author mac
* @since 2025-02-18
*/
@UseDataSource("ds1")
public interface CurShopCouponProductMapper extends BaseMapper<CurShopCouponProduct> {
@Select("truncate tb_shop_coupon_product")
void truncateTable();
}

View File

@@ -0,0 +1,14 @@
package com.czg.mergedata.cur.service;
import com.mybatisflex.core.service.IService;
import com.czg.mergedata.cur.entity.CurShopCouponProduct;
/**
* 活动赠送商品表 服务层。
*
* @author mac
* @since 2025-02-18
*/
public interface CurShopCouponProductService extends IService<CurShopCouponProduct> {
}

View File

@@ -0,0 +1,16 @@
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.CurShopCoupon;
/**
* 优惠券 服务层。
*
* @author mac
* @since 2025-02-18
*/
public interface CurShopCouponService extends IService<CurShopCoupon> {
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.CurShopCouponProduct;
import com.czg.mergedata.cur.mapper.CurShopCouponProductMapper;
import com.czg.mergedata.cur.service.CurShopCouponProductService;
import org.springframework.stereotype.Service;
/**
* 活动赠送商品表 服务层实现。
*
* @author mac
* @since 2025-02-18
*/
@Service
public class CurShopCouponProductServiceImpl extends ServiceImpl<CurShopCouponProductMapper, CurShopCouponProduct> implements CurShopCouponProductService{
}

View File

@@ -0,0 +1,105 @@
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.CurShopCouponProduct;
import com.czg.mergedata.cur.mapper.CurShopCouponProductMapper;
import com.czg.mergedata.cur.service.CurShopIdRelationService;
import com.czg.mergedata.old.entity.OldCouponProduct;
import com.czg.mergedata.old.entity.OldShopCoupon;
import com.czg.mergedata.old.service.OldCouponProductService;
import com.czg.mergedata.old.service.OldShopCouponService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.mergedata.cur.entity.CurShopCoupon;
import com.czg.mergedata.cur.mapper.CurShopCouponMapper;
import com.czg.mergedata.cur.service.CurShopCouponService;
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;
/**
* 优惠券 服务层实现。
*
* @author mac
* @since 2025-02-18
*/
@Service
public class CurShopCouponServiceImpl extends ServiceImpl<CurShopCouponMapper, CurShopCoupon> implements CurShopCouponService{
@Resource
private CurShopIdRelationService curShopIdRelationService;
@Resource
private CurShopCouponProductMapper curShopCouponProductMapper;
@Resource
private OldShopCouponService oldShopCouponService;
@Resource
private OldCouponProductService oldCouponProductService;
@Override
@Transactional
public CzgResult<String> mergeData() {
getMapper().truncateTable();
curShopCouponProductMapper.truncateTable();
Map<Long, Long> oldAndCurShopIdMap = curShopIdRelationService.getOldShopIdRelation();
execShopCoupon(oldAndCurShopIdMap);
execShopCouponProduct();
return CzgResult.success("迁移成功");
}
private void execShopCoupon(Map<Long, Long> oldAndCurShopIdMap) {
Page<OldShopCoupon> page = oldShopCouponService.page(PageUtils.buildPage());
while (!page.getRecords().isEmpty()) {
saveShopCoupon(page.getRecords(), oldAndCurShopIdMap);
page = oldShopCouponService.page(PageUtils.buildPage(page.getPageNumber() + 1));
}
}
private void execShopCouponProduct() {
Page<OldCouponProduct> page = oldCouponProductService.page(PageUtils.buildPage());
while (!page.getRecords().isEmpty()) {
saveShopCouponProduct(page.getRecords());
page = oldCouponProductService.page(PageUtils.buildPage(page.getPageNumber() + 1));
}
}
private void saveShopCoupon(List<OldShopCoupon> oldShopCouponList, Map<Long, Long> oldAndCurShopIdMap) {
List<CurShopCoupon> curShopCoupons = new ArrayList<>();
for (OldShopCoupon oldShopCoupon : oldShopCouponList) {
CurShopCoupon bean = BeanUtil.toBean(oldShopCoupon, CurShopCoupon.class);
Long curShopId = oldAndCurShopIdMap.get(Long.valueOf(oldShopCoupon.getShopId()));
bean.setShopId(curShopId);
curShopCoupons.add(bean);
}
saveBatch(curShopCoupons);
}
private void saveShopCouponProduct(List<OldCouponProduct> oldCouponProductList) {
List<CurShopCouponProduct> curShopCouponProducts = new ArrayList<>();
for (OldCouponProduct oldCouponProduct : oldCouponProductList) {
CurShopCouponProduct bean = BeanUtil.toBean(oldCouponProduct, CurShopCouponProduct.class);
curShopCouponProducts.add(bean);
}
curShopCouponProductMapper.insertBatch(curShopCouponProducts);
}
}

View File

@@ -0,0 +1,57 @@
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;
/**
* 活动赠送商品表 实体类。
*
* @author mac
* @since 2025-02-18
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_coupon_product")
public class OldCouponProduct implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Integer id;
/**
* 活动Id
*/
private Integer couponId;
/**
* 商品id
*/
private Integer productId;
/**
* 数量
*/
private Integer num;
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,144 @@
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.math.BigDecimal;
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_shop_coupon")
public class OldShopCoupon implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 自增
*/
@Id(keyType = KeyType.Auto)
private Integer id;
private String shopId;
/**
* 名称(无意义)
*/
private String title;
/**
* 1-满减 2-商品
*/
private Integer type;
/**
* 满多少金额
*/
private BigDecimal fullAmount;
/**
* 减多少金额
*/
private BigDecimal discountAmount;
/**
* 描述
*/
private String description;
/**
* 发放数量
*/
private Integer number;
/**
* 剩余数量
*/
private Integer leftNumber;
/**
* 有效期类型,可选值为 fixed固定时间/custom自定义时间
*/
private String validityType;
/**
* 有效天数
*/
private Integer validDays;
/**
* 隔多少天生效
*/
private Integer daysToTakeEffect;
/**
* 有效开始时间
*/
private LocalDateTime validStartTime;
/**
* 有效结束时间
*/
private LocalDateTime validEndTime;
/**
* 周 数组["周一","周二"]
*/
private String userDays;
/**
* all-全时段 custom-指定时段
*/
private String useTimeType;
/**
* 可用开始时间
*/
private Time useStartTime;
/**
* 可用结束时间
*/
private Time useEndTime;
/**
* 已使用数量
*/
private Integer useNumber;
/**
* 发放人
*/
private String editor;
/**
* 状态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.old.mapper;
import com.mybatisflex.annotation.UseDataSource;
import com.mybatisflex.core.BaseMapper;
import com.czg.mergedata.old.entity.OldCouponProduct;
/**
* 活动赠送商品表 映射层。
*
* @author mac
* @since 2025-02-18
*/
@UseDataSource("ds2")
public interface OldCouponProductMapper extends BaseMapper<OldCouponProduct> {
}

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.OldShopCoupon;
/**
* 优惠券 映射层。
*
* @author mac
* @since 2025-02-18
*/
@UseDataSource("ds2")
public interface OldShopCouponMapper extends BaseMapper<OldShopCoupon> {
}

View File

@@ -0,0 +1,14 @@
package com.czg.mergedata.old.service;
import com.mybatisflex.core.service.IService;
import com.czg.mergedata.old.entity.OldCouponProduct;
/**
* 活动赠送商品表 服务层。
*
* @author mac
* @since 2025-02-18
*/
public interface OldCouponProductService extends IService<OldCouponProduct> {
}

View File

@@ -0,0 +1,14 @@
package com.czg.mergedata.old.service;
import com.mybatisflex.core.service.IService;
import com.czg.mergedata.old.entity.OldShopCoupon;
/**
* 优惠券 服务层。
*
* @author mac
* @since 2025-02-18
*/
public interface OldShopCouponService extends IService<OldShopCoupon> {
}

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.OldCouponProduct;
import com.czg.mergedata.old.mapper.OldCouponProductMapper;
import com.czg.mergedata.old.service.OldCouponProductService;
import org.springframework.stereotype.Service;
/**
* 活动赠送商品表 服务层实现。
*
* @author mac
* @since 2025-02-18
*/
@Service
public class OldCouponProductServiceImpl extends ServiceImpl<OldCouponProductMapper, OldCouponProduct> implements OldCouponProductService{
}

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.OldShopCoupon;
import com.czg.mergedata.old.mapper.OldShopCouponMapper;
import com.czg.mergedata.old.service.OldShopCouponService;
import org.springframework.stereotype.Service;
/**
* 优惠券 服务层实现。
*
* @author mac
* @since 2025-02-18
*/
@Service
public class OldShopCouponServiceImpl extends ServiceImpl<OldShopCouponMapper, OldShopCoupon> implements OldShopCouponService{
}

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.CurShopCouponMapper">
</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.CurShopCouponProductMapper">
</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.OldCouponProductMapper">
</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.OldShopCouponMapper">
</mapper>