迁移用户数据

This commit is contained in:
GYJ 2025-02-15 17:39:50 +08:00
parent b064092501
commit f27c9cc23c
32 changed files with 892 additions and 32 deletions

2
.gitignore vendored
View File

@ -31,4 +31,4 @@ build/
### VS Code ###
.vscode/
#/logs/
/logs/

View File

@ -42,7 +42,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.36</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -78,6 +78,12 @@
<artifactId>HikariCP</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.35</version>
</dependency>
</dependencies>
<build>
@ -90,6 +96,7 @@
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
</path>
</annotationProcessorPaths>
</configuration>

View File

@ -2,11 +2,13 @@ package com.czg.mergedata;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* @author GY_Joker
*/
@SpringBootApplication
@EnableTransactionManagement
public class MergeDataApplication {
public static void main(String[] args) {

View File

@ -0,0 +1,8 @@
package com.czg.mergedata.common.constants;
/**
* @author GYJoker
*/
public class Constants {
}

View File

@ -0,0 +1,78 @@
package com.czg.mergedata.common.exception;
import com.czg.mergedata.common.resp.CzgRespCode;
import com.czg.mergedata.common.resp.CzgResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author GYJoker
*/
@RestControllerAdvice
@Slf4j
public class CzgControllerAdvice {
@ResponseBody
@ExceptionHandler(value = Exception.class)
@ResponseStatus(HttpStatus.OK)
public CzgResult<Object> errorHandler(Exception ex) {
setErrorLog(ex);
log.error("", ex);
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR);
}
@ResponseBody
@ExceptionHandler(value = HttpMessageNotReadableException.class)
@ResponseStatus(HttpStatus.OK)
public CzgResult<Object> invalidFormatExceptionErrorHandler(HttpMessageNotReadableException ex) {
setErrorLog(ex);
return CzgResult.failure(ex.getRootCause() == null ? ex.getMessage() : ex.getRootCause().getMessage());
}
@ResponseBody
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.OK)
public CzgResult<Object> requestParamException(MethodArgumentNotValidException ex) {
setErrorLog(ex);
List<ObjectError> allErrors = ex.getBindingResult().getAllErrors();
String message = allErrors.stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining(";"));
return CzgResult.failure(CzgRespCode.PARAM_ERROR.getCode(), message);
}
/**
* 处理自定义异常
*/
@ExceptionHandler(CzgException.class)
public CzgResult<Object> handleCzgException(CzgException ex) {
return CzgResult.failure(ex.getCode(), ex.getMsg());
}
/**
* 处理Hutool的断言抛出异常
*/
@ExceptionHandler(IllegalArgumentException.class)
public CzgResult<Object> handleAssertException(IllegalArgumentException ex) {
return CzgResult.failure(CzgRespCode.PARAM_ERROR.getCode(), ex.getMessage());
}
@ExceptionHandler(DuplicateKeyException.class)
public CzgResult<Object> handleDuplicateKeyException(DuplicateKeyException ex) {
setErrorLog(ex);
return CzgResult.failure(CzgRespCode.RECORD_EXISTED);
}
private void setErrorLog(Exception ex) {
log.error(ex.getMessage());
}
}

View File

@ -0,0 +1,31 @@
package com.czg.mergedata.common.exception;
import com.czg.mergedata.common.resp.CzgRespCode;
import lombok.Getter;
import lombok.Setter;
/**
* 自定义异常
*
* @author admin admin@cashier.com
* @since 1.0.0
*/
@Setter
@Getter
public class CzgException extends RuntimeException {
private int code;
private String msg;
public CzgException(String msg) {
super(msg);
this.code = CzgRespCode.FAILURE.getCode();
this.msg = msg;
}
public CzgException(String msg, Throwable e) {
super(msg, e);
this.code = CzgRespCode.FAILURE.getCode();
this.msg = msg;
}
}

View File

@ -0,0 +1,30 @@
package com.czg.mergedata.common.resp;
import lombok.Getter;
/**
* @author GYJoker
*/
@Getter
public enum CzgRespCode {
SUCCESS(200, "操作成功"),
FAILURE(500, "操作失败"),
NOT_LOGIN(501, "登录失效"),
SYSTEM_ERROR(555, "系统内部错误"),
RECORD_NOT_EXIST(601, "记录不存在"),
RECORD_EXISTED(602, "记录已存在"),
PARAM_ERROR(603, "参数错误"),
UNAUTHORIZED(401, "未授权"),
UN_PERMISSION(402, "无此接口权限"),
UN_ROLE(403, "角色权限不足");
private final int code;
private final String msg;
CzgRespCode(int code, String msg) {
this.code = code;
this.msg = msg;
}
}

View File

@ -0,0 +1,62 @@
package com.czg.mergedata.common.resp;
import lombok.Data;
import java.io.Serializable;
/**
* Result类用于封装请求响应的结果包含状态码消息和数据
* @author GYJ
*/
@Data
public class CzgResult<T> implements Serializable {
private int code;
private String msg;
private T data;
// 私有构造函数用于在类内部创建实例强制通过静态方法来获取Result对象
private CzgResult(int code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
// 以下是三个静态方法分别用于创建不同状态的Result对象
// 创建成功的响应结果对象默认消息和无数据情况
public static <T> CzgResult<T> success() {
return new CzgResult<>(200, "操作成功", null);
}
// 创建成功的响应结果对象携带指定的数据
public static <T> CzgResult<T> success(T data) {
return new CzgResult<>(200, "操作成功", data);
}
// 创建带有自定义消息的成功响应结果对象携带指定的数据
public static <T> CzgResult<T> success(String msg, T data) {
return new CzgResult<>(200, msg, data);
}
// 创建失败的响应结果对象默认消息和无数据情况
public static <T> CzgResult<T> failure() {
return new CzgResult<>(500, "操作失败", null);
}
// 创建失败的响应结果对象携带指定的自定义消息
public static <T> CzgResult<T> failure(String msg) {
return new CzgResult<>(500, msg, null);
}
// 创建带有自定义状态码和消息的失败响应结果对象无数据情况
public static <T> CzgResult<T> failure(int code, String msg) {
return new CzgResult<>(code, msg, null);
}
public static <T> CzgResult<T> failure(CzgRespCode respCode) {
return new CzgResult<>(respCode.getCode(), respCode.getMsg(), null);
}
}

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) {
//配置数据源
@ -57,7 +57,7 @@ public class CodeGen {
ServiceImplConfig implConfig = globalConfig.getServiceImplConfig();
implConfig.setSuperClass(ServiceImpl.class);
implConfig.setClassSuffix("Impl");
implConfig.setClassSuffix("ServiceImpl");
if (isOldVersion) {
implConfig.setClassPrefix("Old");
} else {
@ -81,7 +81,7 @@ public class CodeGen {
//设置表前缀和只生成哪些表setGenerateTable 未配置时生成所有表
globalConfig.getStrategyConfig()
.setTablePrefix("tb_")
.setGenerateTable("tb_shop_staff");
.setGenerateTable("tb_merchant_account");
EntityConfig entityConfig = globalConfig.getEntityConfig();
if (isOldVersion) {

View File

@ -0,0 +1,28 @@
package com.czg.mergedata.common.utils;
import com.mybatisflex.core.paginate.Page;
/**
* @author GYJoker
*/
public class PageUtils {
public static final Long PAGE_SIZE = 100L;
public static <T> Page<T> buildPage() {
return buildPage(1L);
}
public static <T> Page<T> buildPage(Long page) {
return buildPage(page, PAGE_SIZE);
}
public static <T> Page<T> buildPage(Long page, Long size) {
if (page == null || page <= 0) {
page = 1L;
}
if (size == null || size <= 0) {
size = PAGE_SIZE;
}
return new Page<>(page, size);
}
}

View File

@ -1,5 +1,8 @@
package com.czg.mergedata.controller;
import com.czg.mergedata.common.resp.CzgResult;
import com.czg.mergedata.cur.service.CurSysUserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -9,4 +12,12 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
public class UserController {
@Resource
private CurSysUserService curSysUserService;
@RequestMapping("/mergeShopInfo")
public CzgResult<String> mergeShopInfo() {
return curSysUserService.mergeShopInfo();
}
}

View File

@ -0,0 +1,36 @@
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-15
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("shop_id_relation")
public class CurShopIdRelation implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id
private Long curShopId;
@Id
private Long oldShopId;
}

View File

@ -0,0 +1,14 @@
package com.czg.mergedata.cur.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.mergedata.cur.entity.CurShopIdRelation;
/**
* 映射层
*
* @author mac
* @since 2025-02-15
*/
public interface CurShopIdRelationMapper extends BaseMapper<CurShopIdRelation> {
}

View File

@ -0,0 +1,14 @@
package com.czg.mergedata.cur.service;
import com.mybatisflex.core.service.IService;
import com.czg.mergedata.cur.entity.CurShopIdRelation;
/**
* 服务层
*
* @author mac
* @since 2025-02-15
*/
public interface CurShopIdRelationService extends IService<CurShopIdRelation> {
}

View File

@ -1,5 +1,6 @@
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.CurSysUser;
@ -11,4 +12,5 @@ import com.czg.mergedata.cur.entity.CurSysUser;
*/
public interface CurSysUserService extends IService<CurSysUser> {
CzgResult<String> mergeShopInfo();
}

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.CurShopIdRelation;
import com.czg.mergedata.cur.mapper.CurShopIdRelationMapper;
import com.czg.mergedata.cur.service.CurShopIdRelationService;
import org.springframework.stereotype.Service;
/**
* 服务层实现
*
* @author mac
* @since 2025-02-15
*/
@Service
public class CurShopIdRelationServiceImpl extends ServiceImpl<CurShopIdRelationMapper, CurShopIdRelation> implements CurShopIdRelationService{
}

View File

@ -13,6 +13,6 @@ import org.springframework.stereotype.Service;
* @since 2025-02-15
*/
@Service
public class CurShopInfoImpl extends ServiceImpl<CurShopInfoMapper, CurShopInfo> implements CurShopInfoService{
public class CurShopInfoServiceImpl extends ServiceImpl<CurShopInfoMapper, CurShopInfo> implements CurShopInfoService{
}

View File

@ -13,6 +13,6 @@ import org.springframework.stereotype.Service;
* @since 2025-02-15
*/
@Service
public class CurShopStaffImpl extends ServiceImpl<CurShopStaffMapper, CurShopStaff> implements CurShopStaffService{
public class CurShopStaffServiceImpl extends ServiceImpl<CurShopStaffMapper, CurShopStaff> implements CurShopStaffService{
}

View File

@ -1,18 +0,0 @@
package com.czg.mergedata.cur.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.mergedata.cur.entity.CurSysUser;
import com.czg.mergedata.cur.mapper.CurSysUserMapper;
import com.czg.mergedata.cur.service.CurSysUserService;
import org.springframework.stereotype.Service;
/**
* 系统用户 服务层实现
*
* @author mac
* @since 2025-02-15
*/
@Service
public class CurSysUserImpl extends ServiceImpl<CurSysUserMapper, CurSysUser> implements CurSysUserService{
}

View File

@ -0,0 +1,307 @@
package com.czg.mergedata.cur.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.SecureUtil;
import com.czg.mergedata.common.resp.CzgResult;
import com.czg.mergedata.common.utils.PageUtils;
import com.czg.mergedata.cur.entity.CurShopInfo;
import com.czg.mergedata.cur.entity.CurShopStaff;
import com.czg.mergedata.cur.entity.CurSysUser;
import com.czg.mergedata.cur.mapper.CurSysUserMapper;
import com.czg.mergedata.cur.service.CurShopInfoService;
import com.czg.mergedata.cur.service.CurShopStaffService;
import com.czg.mergedata.cur.service.CurSysUserService;
import com.czg.mergedata.old.entity.OldMerchantAccount;
import com.czg.mergedata.old.entity.OldPlussShopStaff;
import com.czg.mergedata.old.entity.OldShopInfo;
import com.czg.mergedata.old.entity.OldSysUser;
import com.czg.mergedata.old.service.OldMerchantAccountService;
import com.czg.mergedata.old.service.OldPlussShopStaffService;
import com.czg.mergedata.old.service.OldShopInfoService;
import com.czg.mergedata.old.service.OldSysUserService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.*;
/**
* 系统用户 服务层实现
*
* @author mac
* @since 2025-02-15
*/
@Service
public class CurSysUserServiceImpl extends ServiceImpl<CurSysUserMapper, CurSysUser> implements CurSysUserService {
@Resource
private OldSysUserService oldSysUserService;
@Resource
private OldShopInfoService oldShopInfoService;
@Resource
private CurShopInfoService curShopInfoService;
@Resource
private OldMerchantAccountService oldMerchantAccountService;
@Resource
private OldPlussShopStaffService oldStaffService;
@Resource
private CurShopStaffService curStaffService;
@Override
@Transactional(rollbackFor = Exception.class)
public CzgResult<String> mergeShopInfo() {
// 账号和店铺id映射
Map<String, Long> orginAccountAndShopIdMap = new HashMap<>();
// 老新系统店铺 id 映射
Map<Long, Long> oldAndCurShopIdMap = new HashMap<>();
Map<Long, Long> curAndOldShopIdMap = new HashMap<>();
List<CurSysUser> curSysUsers = execSysUser();
// curSysUsers.forEach(curSysUser -> {
// if (!curSysUser.getAccount().contains("@")) {
// orginAccountAndShopIdMap.put(curSysUser.getAccount(), curSysUser.getId());
// }
// });
//
// List<CurShopInfo> curShopInfos = execShopInfo(orginAccountAndShopIdMap, oldAndCurShopIdMap, curAndOldShopIdMap);
// execStaffInfo(oldAndCurShopIdMap, curAndOldShopIdMap);
return CzgResult.success("处理成功");
}
private List<CurSysUser> execSysUser() {
List<CurSysUser> sysUserList = new ArrayList<>();
// QueryWrapper queryWrapper = new QueryWrapper();
// queryWrapper.gt(OldSysUser::getUserId, 1);
OldSysUser byId = oldSysUserService.getById(1);
// Page<OldSysUser> page = oldSysUserService.page(PageUtils.buildPage());
// List<OldSysUser> list = oldSysUserService.list(new QueryWrapper().ge(OldSysUser::getUserId, 1));
// Page<OldSysUser> page = oldSysUserService.page(PageUtils.buildPage(), queryWrapper);
// Page<OldSysUser> page = oldSysUserService.page(PageUtils.buildPage());
//
// long startUserId = 100L;
//
// while (page.hasNext() || page.getPageNumber() == 1) {
// List<OldSysUser> oldSysUsers = page.getRecords();
// List<CurSysUser> curSysUsers = saveOldUser(oldSysUsers, startUserId);
// sysUserList.addAll(curSysUsers);
//
// page = oldSysUserService.page(PageUtils.buildPage(page.getPageNumber() + 1));
// startUserId += page.getPageSize();
// }
return sysUserList;
}
private List<CurShopInfo> execShopInfo(Map<String, Long> orginAccountAndShopIdMap, Map<Long, Long> oldAndCurShopIdMap,
Map<Long, Long> curAndOldShopIdMap) {
List<CurShopInfo> curShopInfoList = new ArrayList<>();
Page<OldShopInfo> page = oldShopInfoService.page(PageUtils.buildPage());
while (page.hasNext() || page.getPageNumber() == 1) {
List<OldShopInfo> oldShopInfos = page.getRecords();
List<CurShopInfo> curShopInfos = saveOldShopInfo(oldShopInfos, orginAccountAndShopIdMap, oldAndCurShopIdMap, curAndOldShopIdMap);
curShopInfoList.addAll(curShopInfos);
page = oldShopInfoService.page(PageUtils.buildPage());
}
return curShopInfoList;
}
private void execStaffInfo(Map<Long, Long> oldAndCurShopIdMap, Map<Long, Long> curAndOldShopIdMap) {
Page<OldPlussShopStaff> page = oldStaffService.page(PageUtils.buildPage());
while (page.hasNext() || page.getPageNumber() == 1) {
List<OldPlussShopStaff> oldShopStaffs = page.getRecords();
saveOldStaffInfo(oldShopStaffs, oldAndCurShopIdMap, curAndOldShopIdMap);
page = oldStaffService.page(PageUtils.buildPage());
}
}
private List<CurSysUser> saveOldUser(List<OldSysUser> oldSysUsers, long startUserId) {
if (oldSysUsers == null || oldSysUsers.isEmpty()) {
return new ArrayList<>();
}
List<CurSysUser> curSysUsers = new ArrayList<>();
for (int i = 0; i < oldSysUsers.size(); i++) {
OldSysUser oldSysUser = oldSysUsers.get(i);
long userId = startUserId + i;
String password = SecureUtil.md5(userId + "czg123456");
CurSysUser curSysUser = new CurSysUser();
curSysUser.setId(userId);
curSysUser.setAccount(oldSysUser.getUsername());
curSysUser.setNickName(oldSysUser.getNickName());
curSysUser.setGender(oldSysUser.getGender());
curSysUser.setPhone(oldSysUser.getPhone());
curSysUser.setEmail(oldSysUser.getEmail());
curSysUser.setAvatar(oldSysUser.getAvatarPath());
curSysUser.setPassword(password);
curSysUser.setIsAdmin(oldSysUser.getIsAdmin());
curSysUser.setStauts(oldSysUser.getEnabled().intValue());
curSysUser.setCreateUserId(1L);
curSysUser.setUpdateUserId(1L);
curSysUser.setCreateTime(oldSysUser.getCreateTime());
curSysUser.setUpdateTime(LocalDateTime.now());
curSysUsers.add(curSysUser);
}
saveBatch(curSysUsers);
return curSysUsers;
}
private List<CurShopInfo> saveOldShopInfo(List<OldShopInfo> oldShopInfos, Map<String, Long> orginAccountAndShopIdMap,
Map<Long, Long> oldAndCurShopIdMap, Map<Long, Long> curAndOldShopIdMap) {
if (oldShopInfos == null || oldShopInfos.isEmpty()) {
return new ArrayList<>();
}
List<CurShopInfo> curShopInfos = new ArrayList<>();
for (OldShopInfo oldShopInfo : oldShopInfos) {
// 新的 shopId 新系统的 sys_user_id
Long shopId = orginAccountAndShopIdMap.get(oldShopInfo.getAccount());
oldAndCurShopIdMap.put(oldShopInfo.getId(), shopId);
curAndOldShopIdMap.put(shopId, oldShopInfo.getId());
CurShopInfo curShopInfo = new CurShopInfo();
curShopInfo.setId(shopId);
curShopInfo.setSubTitle(oldShopInfo.getSubTitle());
curShopInfo.setShopName(oldShopInfo.getShopName());
curShopInfo.setChainName(oldShopInfo.getChainName());
curShopInfo.setBackImg(oldShopInfo.getBackImg());
curShopInfo.setFrontImg(oldShopInfo.getFrontImg());
curShopInfo.setContactName(oldShopInfo.getContactName());
curShopInfo.setPhone(oldShopInfo.getPhone());
curShopInfo.setLogo(oldShopInfo.getLogo());
curShopInfo.setCoverImg(oldShopInfo.getCoverImg());
curShopInfo.setDetail(oldShopInfo.getDetail());
curShopInfo.setRegisterType(oldShopInfo.getRegisterType());
curShopInfo.setShopType(oldShopInfo.getType());
curShopInfo.setTubeType(oldShopInfo.getTubeType());
curShopInfo.setBusinessStartDay(oldShopInfo.getBusinessStartDay());
curShopInfo.setBusinessEndDay(oldShopInfo.getBusinessEndDay());
curShopInfo.setBusinessTime(oldShopInfo.getBusinessTime());
curShopInfo.setProfiles(oldShopInfo.getProfiles());
curShopInfo.setOnSale(oldShopInfo.getOnSale());
curShopInfo.setStatus(oldShopInfo.getStatus());
curShopInfo.setExpireTime(DateUtil.toLocalDateTime(new Date(oldShopInfo.getExpireAt())));
curShopInfo.setCreateTime(DateUtil.toLocalDateTime(new Date(oldShopInfo.getCreatedAt())));
curShopInfo.setShopQrcode(oldShopInfo.getShopQrcode());
curShopInfo.setTag(oldShopInfo.getTag());
curShopInfo.setLat(oldShopInfo.getLat());
curShopInfo.setLng(oldShopInfo.getLng());
curShopInfo.setProfiles(oldShopInfo.getProfiles());
curShopInfo.setCities(oldShopInfo.getCities());
curShopInfo.setDistricts(oldShopInfo.getDistricts());
curShopInfo.setIsCustomAmount(Integer.parseInt(oldShopInfo.getIsCustom()));
curShopInfo.setIsReturnPwd(Integer.parseInt(oldShopInfo.getIsReturn()));
curShopInfo.setIsMemberInPwd(Integer.parseInt(oldShopInfo.getIsMemberIn()));
curShopInfo.setIsMemberReturnPwd(Integer.parseInt(oldShopInfo.getIsMemberReturn()));
curShopInfo.setIsTableFee(oldShopInfo.getIsTableFee());
curShopInfo.setIsMemberPrice(oldShopInfo.getIsMemberPrice());
curShopInfo.setIsAccountPay(oldShopInfo.getIsUseVip() == null ? 0 : oldShopInfo.getIsUseVip());
curShopInfo.setConsumeColony(oldShopInfo.getConsumeColony());
curShopInfo.setEatModel(oldShopInfo.getEatModel());
curShopInfo.setSmallQrcode(oldShopInfo.getSmallQrcode());
curShopInfo.setPaymentQrcode(oldShopInfo.getPaymentQrcode());
curShopInfo.setBookingSms(oldShopInfo.getBookingSms());
}
curShopInfoService.saveBatch(curShopInfos);
updateCurlShopBindInfo(curShopInfos, oldAndCurShopIdMap, curAndOldShopIdMap);
return curShopInfos;
}
/**
* 处理门店绑定开票信息
*/
private void updateCurlShopBindInfo(List<CurShopInfo> curShopInfos, Map<Long, Long> oldAndCurShopIdMap,
Map<Long, Long> curAndOldShopIdMap) {
List<Long> oldShopIds = new ArrayList<>();
for (CurShopInfo curShopInfo : curShopInfos) {
oldShopIds.add(curShopInfo.getId());
}
// 查询旧的 店铺绑定的开票信息
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.in(OldMerchantAccount::getShopId, oldShopIds);
List<OldMerchantAccount> merchantAccounts = oldMerchantAccountService.list(queryWrapper);
Map<Long, OldMerchantAccount> oldMerchantAccountMap = new HashMap<>();
for (OldMerchantAccount oldMerchantAccount : merchantAccounts) {
oldMerchantAccountMap.put(Long.valueOf(oldMerchantAccount.getShopId()), oldMerchantAccount);
}
// 处理新的 店铺绑定的开票信息
for (CurShopInfo curShopInfo : curShopInfos) {
Long oldShopId = curAndOldShopIdMap.get(curShopInfo.getId());
OldMerchantAccount oldMerchantAccount = oldMerchantAccountMap.get(oldShopId);
if (oldMerchantAccount == null) {
continue;
}
curShopInfo.setOperationPwd(oldMerchantAccount.getPwd());
curShopInfo.setBindAccount(oldMerchantAccount.getBindAccount());
curShopInfo.setArticle(oldMerchantAccount.getArticle());
curShopInfo.setSdType(oldMerchantAccount.getSdType());
curShopInfo.setSdType(oldMerchantAccount.getSdType());
}
curShopInfoService.updateBatch(curShopInfos);
}
private void saveOldStaffInfo(List<OldPlussShopStaff> oldShopStaffs, Map<Long, Long> oldAndCurShopIdMap,
Map<Long, Long> curAndOldShopIdMap) {
List<CurShopStaff> curShopStaffs = new ArrayList<>();
List<CurSysUser> curSysUsers = new ArrayList<>();
for (OldPlussShopStaff oldShopStaff : oldShopStaffs) {
CurShopStaff curShopStaff = new CurShopStaff();
Long curShopId = oldAndCurShopIdMap.get(Long.valueOf(oldShopStaff.getShopId()));
curShopStaff.setCode(oldShopStaff.getCode());
curShopStaff.setName(oldShopStaff.getName());
curShopStaff.setMaxDiscountAmount(oldShopStaff.getMaxDiscountAmount());
curShopStaff.setDiscountType(oldShopStaff.getDiscountType());
curShopStaff.setStatus(oldShopStaff.getStatus());
curShopStaff.setShopId(curShopId);
curShopStaff.setType(oldShopStaff.getType());
curShopStaff.setIsManage(oldShopStaff.getIsManage());
curShopStaff.setIsPc(oldShopStaff.getIsPc());
curShopStaff.setCreateTime(DateUtil.toLocalDateTime(new Date(oldShopStaff.getCreatedAt())));
curShopStaffs.add(curShopStaff);
CurSysUser curSysUser = getOne(new QueryWrapper().eq(CurSysUser::getAccount, oldShopStaff.getShopId() + "@" + oldShopStaff.getAccount()));
if (curSysUser != null) {
curSysUser.setAccount(curShopId + "@" + curSysUser.getAccount());
curSysUsers.add(curSysUser);
}
}
curStaffService.saveBatch(curShopStaffs);
updateBatch(curSysUsers);
}
}

View File

@ -0,0 +1,150 @@
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-15
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_merchant_account")
public class OldMerchantAccount implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 自增id
*/
@Id(keyType = KeyType.Auto)
private Integer id;
/**
* 登陆帐号
*/
private String account;
/**
* 登陆密码
*/
private String password;
/**
* 商家Id
*/
private String merchantId;
/**
* 门店Id
*/
private String shopId;
private String shopSnap;
/**
* 是否管理员
*/
private Integer isAdmin;
/**
* 是否商户1商户帐号0-店铺帐号
*/
private Integer isMercantile;
/**
* 姓名
*/
private String name;
/**
* 性别:0女 1
*/
private Integer sex;
/**
* 邮箱
*/
private String email;
/**
* 头像
*/
private String headImg;
/**
* 联系电话
*/
private String telephone;
/**
* 状态
*/
private Boolean status;
/**
* 排序
*/
private Integer sort;
private Integer roleId;
/**
* 最后登陆时间
*/
private Integer lastLoginAt;
/**
* 公众号openId
*/
private String mpOpenId;
/**
* 是否接收消息通知
*/
private Integer msgAble;
private Long createdAt;
private Long updatedAt;
/**
* 操作密码
*/
private String pwd;
/**
* 开票系统账号
*/
private String bindAccount;
/**
* 项目分类
*/
private String article;
/**
* 数电发票类型
*/
private String sdType;
/**
* 税率
*/
private String taxAmount;
}

View File

@ -0,0 +1,14 @@
package com.czg.mergedata.old.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.mergedata.old.entity.OldMerchantAccount;
/**
* 商家登陆帐号 映射层
*
* @author mac
* @since 2025-02-15
*/
public interface OldMerchantAccountMapper extends BaseMapper<OldMerchantAccount> {
}

View File

@ -0,0 +1,14 @@
package com.czg.mergedata.old.service;
import com.mybatisflex.core.service.IService;
import com.czg.mergedata.old.entity.OldMerchantAccount;
/**
* 商家登陆帐号 服务层
*
* @author mac
* @since 2025-02-15
*/
public interface OldMerchantAccountService extends IService<OldMerchantAccount> {
}

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.OldMerchantAccount;
import com.czg.mergedata.old.mapper.OldMerchantAccountMapper;
import com.czg.mergedata.old.service.OldMerchantAccountService;
import org.springframework.stereotype.Service;
/**
* 商家登陆帐号 服务层实现
*
* @author mac
* @since 2025-02-15
*/
@Service
public class OldMerchantAccountServiceImpl extends ServiceImpl<OldMerchantAccountMapper, OldMerchantAccount> implements OldMerchantAccountService{
}

View File

@ -13,6 +13,6 @@ import org.springframework.stereotype.Service;
* @since 2025-02-15
*/
@Service
public class OldPlussShopStaffImpl extends ServiceImpl<OldPlussShopStaffMapper, OldPlussShopStaff> implements OldPlussShopStaffService{
public class OldPlussShopStaffServiceImpl extends ServiceImpl<OldPlussShopStaffMapper, OldPlussShopStaff> implements OldPlussShopStaffService{
}

View File

@ -13,6 +13,6 @@ import org.springframework.stereotype.Service;
* @since 2025-02-15
*/
@Service
public class OldShopInfoImpl extends ServiceImpl<OldShopInfoMapper, OldShopInfo> implements OldShopInfoService{
public class OldShopInfoServiceImpl extends ServiceImpl<OldShopInfoMapper, OldShopInfo> implements OldShopInfoService{
}

View File

@ -13,6 +13,6 @@ import org.springframework.stereotype.Service;
* @since 2025-02-15
*/
@Service
public class OldSysUserImpl extends ServiceImpl<OldSysUserMapper, OldSysUser> implements OldSysUserService{
public class OldSysUserServiceImpl extends ServiceImpl<OldSysUserMapper, OldSysUser> implements OldSysUserService{
}

View File

@ -2,12 +2,12 @@ spring:
datasource:
cur:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://rm-bp1kn7h89nz62cno1ro.mysql.rds.aliyuncs.com:3306/czg_cashier?useUnicode=true&characterEncoding=utf-8
jdbc-url: jdbc:mysql://rm-bp1kn7h89nz62cno1ro.mysql.rds.aliyuncs.com:3306/czg_cashier?useUnicode=true&characterEncoding=utf-8
username: cashier
password: Cashier@1@
old:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://rm-bp1kn7h89nz62cno1ro.mysql.rds.aliyuncs.com:3306/fycashier_test?useUnicode=true&characterEncoding=utf-8
jdbc-url: jdbc:mysql://rm-bp1kn7h89nz62cno1ro.mysql.rds.aliyuncs.com:3306/fycashier_test?useUnicode=true&characterEncoding=utf-8
username: cashier
password: Cashier@1@

View File

@ -1,5 +1,5 @@
server:
port: 8100
port: 8900
servlet:
context-path: /merge
@ -13,3 +13,6 @@ logging:
config: classpath:logback.xml
mybatis:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

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.CurShopIdRelationMapper">
</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.OldMerchantAccountMapper">
</mapper>

View File

@ -0,0 +1,17 @@
# 收银机数据迁移关系
## 1 系统用户、商户、员工
### 1.1 系统用户
1. 系统用户全部迁移到新数据库
2. 密码默认为 czg123456
### 1.2 商户
1. 迁移所有商户数据
2. 根据 account -> 对应 sys_user username 将shop_info id设置为 sys_user id
#### 1.2.1 保存新的 shop_id 和 原来shop_id 对应关系
> 表名shop_id_relation