迁移 商品单位
This commit is contained in:
@@ -81,7 +81,7 @@ public class CodeGen {
|
||||
//设置表前缀和只生成哪些表,setGenerateTable 未配置时,生成所有表
|
||||
globalConfig.getStrategyConfig()
|
||||
.setTablePrefix("tb_")
|
||||
.setGenerateTable("tb_user_info");
|
||||
.setGenerateTable("tb_shop_prod_unit");
|
||||
|
||||
EntityConfig entityConfig = globalConfig.getEntityConfig();
|
||||
if (isOldVersion) {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.czg.mergedata.controller;
|
||||
|
||||
import com.czg.mergedata.common.resp.CzgResult;
|
||||
import com.czg.mergedata.cur.service.CurShopProdUnitService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author GYJoker
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/product")
|
||||
public class ProductController {
|
||||
|
||||
@Resource
|
||||
private CurShopProdUnitService curShopProdUnitService;
|
||||
|
||||
@RequestMapping("/mergeUnit")
|
||||
public CzgResult<String> mergeUnit() {
|
||||
return curShopProdUnitService.mergeProductUnit();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
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_unit")
|
||||
public class CurShopProdUnit implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 单位名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 单位类型 number-计数 weight-记重
|
||||
*/
|
||||
private String unitType;
|
||||
|
||||
/**
|
||||
* 单位来源 1-系统预设 0-商家创建
|
||||
*/
|
||||
private Integer isSystem;
|
||||
|
||||
/**
|
||||
* 状态 0-禁用 1-启用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
}
|
||||
@@ -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.CurShopProdUnit;
|
||||
|
||||
/**
|
||||
* 商品单位 映射层。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-17
|
||||
*/
|
||||
@UseDataSource("ds1")
|
||||
public interface CurShopProdUnitMapper extends BaseMapper<CurShopProdUnit> {
|
||||
|
||||
}
|
||||
@@ -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.CurShopProdUnit;
|
||||
|
||||
/**
|
||||
* 商品单位 服务层。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-17
|
||||
*/
|
||||
public interface CurShopProdUnitService extends IService<CurShopProdUnit> {
|
||||
|
||||
CzgResult<String> mergeProductUnit();
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.czg.mergedata.cur.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.czg.mergedata.common.resp.CzgResult;
|
||||
import com.czg.mergedata.common.utils.PageUtils;
|
||||
import com.czg.mergedata.cur.service.CurShopIdRelationService;
|
||||
import com.czg.mergedata.old.entity.OldShopUnit;
|
||||
import com.czg.mergedata.old.service.OldShopUnitService;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.mergedata.cur.entity.CurShopProdUnit;
|
||||
import com.czg.mergedata.cur.mapper.CurShopProdUnitMapper;
|
||||
import com.czg.mergedata.cur.service.CurShopProdUnitService;
|
||||
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 CurShopProdUnitServiceImpl extends ServiceImpl<CurShopProdUnitMapper, CurShopProdUnit> implements CurShopProdUnitService {
|
||||
|
||||
@Resource
|
||||
private CurShopIdRelationService curShopIdRelationService;
|
||||
|
||||
@Resource
|
||||
private OldShopUnitService oldShopUnitService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<String> mergeProductUnit() {
|
||||
Map<Long, Long> oldAndCurShopIdMap = curShopIdRelationService.getOldShopIdRelation();
|
||||
|
||||
mergeUnit(oldAndCurShopIdMap);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void mergeUnit(Map<Long, Long> oldAndCurShopIdMap) {
|
||||
Page<OldShopUnit> page = oldShopUnitService.page(PageUtils.buildPage());
|
||||
|
||||
while (page.hasNext() || page.getPageNumber() == 1) {
|
||||
saveUnitInfo(page.getRecords(), oldAndCurShopIdMap);
|
||||
page = oldShopUnitService.page(PageUtils.buildPage(page.getPageNumber() + 1));
|
||||
}
|
||||
}
|
||||
|
||||
private void saveUnitInfo(List<OldShopUnit> oldShopUnits, Map<Long, Long> oldAndCurShopIdMap) {
|
||||
List<CurShopProdUnit> curShopProdUnits = new ArrayList<>();
|
||||
for (OldShopUnit oldShopUnit : oldShopUnits) {
|
||||
CurShopProdUnit curShopProdUnit = new CurShopProdUnit();
|
||||
|
||||
Long shopId = oldAndCurShopIdMap.get(Long.valueOf(oldShopUnit.getShopId()));
|
||||
|
||||
curShopProdUnit.setId(Long.valueOf(oldShopUnit.getId()));
|
||||
curShopProdUnit.setName(oldShopUnit.getName());
|
||||
curShopProdUnit.setUnitType(oldShopUnit.getUnitType());
|
||||
curShopProdUnit.setIsSystem("1".equals(oldShopUnit.getShopId()) ? 1 : 0);
|
||||
curShopProdUnit.setStatus(oldShopUnit.getStatus());
|
||||
curShopProdUnit.setShopId(shopId == null ? 1L : shopId);
|
||||
curShopProdUnit.setCreateTime(DateUtil.toLocalDateTime(oldShopUnit.getCreatedAt() == null ? new Date() : new Date(oldShopUnit.getCreatedAt())));
|
||||
|
||||
curShopProdUnits.add(curShopProdUnit);
|
||||
}
|
||||
|
||||
saveBatch(curShopProdUnits);
|
||||
}
|
||||
}
|
||||
73
src/main/java/com/czg/mergedata/old/entity/OldShopUnit.java
Normal file
73
src/main/java/com/czg/mergedata/old/entity/OldShopUnit.java
Normal file
@@ -0,0 +1,73 @@
|
||||
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_unit")
|
||||
public class OldShopUnit implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 单位名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 小数位(个数大于0,表示小数据精度位数)
|
||||
*/
|
||||
private Integer decimalsDigits;
|
||||
|
||||
/**
|
||||
* 单位类型(weight代表重量,小数单位,为number代表个数)
|
||||
*/
|
||||
private String unitType;
|
||||
|
||||
/**
|
||||
* 0后台添加 -1系统默认 (公斤、瓶)
|
||||
*/
|
||||
private Integer isSystem;
|
||||
|
||||
/**
|
||||
* 预留字段1-正常
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
private String merchantId;
|
||||
|
||||
/**
|
||||
* 店铺Id
|
||||
*/
|
||||
private String shopId;
|
||||
|
||||
private Long createdAt;
|
||||
|
||||
private Long updatedAt;
|
||||
|
||||
}
|
||||
@@ -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.OldShopUnit;
|
||||
|
||||
/**
|
||||
* 商品单位 映射层。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-17
|
||||
*/
|
||||
@UseDataSource("ds2")
|
||||
public interface OldShopUnitMapper extends BaseMapper<OldShopUnit> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.mergedata.old.service;
|
||||
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.mergedata.old.entity.OldShopUnit;
|
||||
|
||||
/**
|
||||
* 商品单位 服务层。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-17
|
||||
*/
|
||||
public interface OldShopUnitService extends IService<OldShopUnit> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.mergedata.old.service.impl;
|
||||
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.mergedata.old.entity.OldShopUnit;
|
||||
import com.czg.mergedata.old.mapper.OldShopUnitMapper;
|
||||
import com.czg.mergedata.old.service.OldShopUnitService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 商品单位 服务层实现。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-17
|
||||
*/
|
||||
@Service
|
||||
public class OldShopUnitServiceImpl extends ServiceImpl<OldShopUnitMapper, OldShopUnit> implements OldShopUnitService{
|
||||
|
||||
}
|
||||
7
src/main/resources/mapper/cur/ShopProdUnitMapper.xml
Normal file
7
src/main/resources/mapper/cur/ShopProdUnitMapper.xml
Normal 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.CurShopProdUnitMapper">
|
||||
|
||||
</mapper>
|
||||
7
src/main/resources/mapper/old/ShopUnitMapper.xml
Normal file
7
src/main/resources/mapper/old/ShopUnitMapper.xml
Normal 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.OldShopUnitMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user