迁移 打印机

This commit is contained in:
GYJ 2025-03-14 18:08:29 +08:00
parent c814b70b5f
commit 4d67bbf24e
23 changed files with 921 additions and 3 deletions

View File

@ -18,8 +18,8 @@ public class CodeGen {
private final static String DATABASE = "czg_cashier_test";
private final static String OLD_DATABASE = "fycashier";
// 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_order_info", "tb_order_detail");
.setGenerateTable("tb_print_machine_log", "tb_print_machine");
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.CurPrintMachineService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author GYJoker
*/
@RestController
@RequestMapping("/print")
public class PrintController {
@Resource
private CurPrintMachineService curPrintMachineService;
@RequestMapping("/machine")
public CzgResult<String> mergeMachine() {
return curPrintMachineService.mergePrintData();
}
}

View File

@ -0,0 +1,119 @@
package com.czg.mergedata.cur.entity;
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-03-14
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_print_machine")
public class CurPrintMachine implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Integer id;
/**
* 设备名称
*/
private String name;
/**
* 现在打印机支持USB 网络蓝牙
*/
private String connectionType;
/**
* ip地址
*/
private String address;
/**
* 端口
*/
private String port;
/**
* 打印类型分类label标签cash小票kitchen出品
*/
private String subType;
/**
* 0 禁用 1启用
*/
private Integer status;
/**
* 店铺Id
*/
private Long shopId;
/**
* 分类Id
*/
private String categoryIds;
/**
* 现在打印机支持USB 网络两种
*/
private String contentType;
private LocalDateTime createTime;
private LocalDateTime updateTime;
/**
* 分类
*/
private String categoryList;
/**
* 排序
*/
private Integer sort;
/**
* 小票尺寸 58mm 80mm
*/
private String receiptSize;
/**
* 分类打印 0-所有 1-部分分类 2-部分商品
*/
private String classifyPrint;
/**
* 打印数量 c1m1^2=顾客+商家[2张] m1^1=商家[1张] c1^1顾客[1张] c2m1^3顾客2+商家1[3张]
*/
private String printQty;
/**
* 打印方式 all-全部打印 normal-仅打印结账单前台one-仅打印制作单厨房
*/
private String printMethod;
/**
* 打印类型JSON数组 refund-确认退款单 handover-交班单 queue-排队取号 order订单结算单
*/
private String printType;
}

View File

@ -0,0 +1,158 @@
package com.czg.mergedata.cur.entity;
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-03-14
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_print_machine_log")
public class CurPrintMachineLog implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 打印机类型 本地打印机-local USB打印机-USB 云打印机-network
*/
private String connectionType;
/**
* 打印机品牌 云想印 = yxyPrinter飞鹅 = fePrinter 本地 = local USB = printer
*/
private String contentType;
/**
* 打印小票 标签-label 出品-kitchen 小票-cash
*/
private String subType;
/**
* 打印机名称
*/
private String name;
/**
* IP地址/打印机编号
*/
private String address;
/**
* 端口/打印机秘钥
*/
private String port;
/**
* 小票尺寸 58mm 80mm
*/
private String receiptSize;
/**
* 分类打印 0-所以 1-部分分类 2-部分商品
*/
private String classifyPrint;
/**
* 桌台打印 0-所有 1-部分
*/
private String tablePrint;
/**
* 打印数量 c1m1^2=顾客+商家[2张] m1^1=商家[1张] c1^1顾客[1张] c2m1^3=顾客2+商家1[3张]
*/
private String printQty;
/**
* 打印方式 normal-普通出单 one-一菜一品 callTicket-排队取号
*/
private String printMethod;
/**
* 打印类型 JSON数组字符串数据 1-确认退款单 2-交班单 3-排队取号[1,2,3]
*/
private String printType;
/**
* 打印票据 0-全部打印 1-仅厨房 2-仅前台
*/
private String printReceipt;
/**
* 打印内容
*/
private String printContent;
/**
* 店铺id
*/
private String shopId;
/**
* 业务类型
*/
private String bizType;
/**
* 打印人id
*/
private Long createUserId;
/**
* 打印人名称
*/
private String createUserName;
/**
* 打印任务创建时间
*/
private LocalDateTime createTime;
/**
* 打印任务id用于复查打印状态云想印=orderId
*/
private String taskId;
/**
* 实际打印时间
*/
private LocalDateTime printTime;
/**
* 失败标识 1- 0-
*/
private Integer failFlag;
/**
* 响应代码
*/
private String respCode;
/**
* 响应消息
*/
private String respMsg;
}

View File

@ -0,0 +1,17 @@
package com.czg.mergedata.cur.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.mergedata.cur.entity.CurPrintMachineLog;
import org.apache.ibatis.annotations.Select;
/**
* 店铺小票打印记录 映射层
*
* @author mac
* @since 2025-03-14
*/
public interface CurPrintMachineLogMapper extends BaseMapper<CurPrintMachineLog> {
@Select("truncate tb_print_machine_log")
void truncateTable();
}

View File

@ -0,0 +1,17 @@
package com.czg.mergedata.cur.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.mergedata.cur.entity.CurPrintMachine;
import org.apache.ibatis.annotations.Select;
/**
* 打印机设备 映射层
*
* @author mac
* @since 2025-03-14
*/
public interface CurPrintMachineMapper extends BaseMapper<CurPrintMachine> {
@Select("truncate tb_print_machine")
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.CurPrintMachineLog;
/**
* 店铺小票打印记录 服务层
*
* @author mac
* @since 2025-03-14
*/
public interface CurPrintMachineLogService extends IService<CurPrintMachineLog> {
}

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.CurPrintMachine;
/**
* 打印机设备 服务层
*
* @author mac
* @since 2025-03-14
*/
public interface CurPrintMachineService extends IService<CurPrintMachine> {
CzgResult<String> mergePrintData();
}

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.CurPrintMachineLog;
import com.czg.mergedata.cur.mapper.CurPrintMachineLogMapper;
import com.czg.mergedata.cur.service.CurPrintMachineLogService;
import org.springframework.stereotype.Service;
/**
* 店铺小票打印记录 服务层实现
*
* @author mac
* @since 2025-03-14
*/
@Service
public class CurPrintMachineLogServiceImpl extends ServiceImpl<CurPrintMachineLogMapper, CurPrintMachineLog> implements CurPrintMachineLogService{
}

View File

@ -0,0 +1,100 @@
package com.czg.mergedata.cur.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateUtil;
import com.czg.mergedata.common.resp.CzgResult;
import com.czg.mergedata.cur.entity.CurPrintMachineLog;
import com.czg.mergedata.cur.mapper.CurPrintMachineLogMapper;
import com.czg.mergedata.cur.service.CurPrintMachineLogService;
import com.czg.mergedata.old.entity.OldPrintMachine;
import com.czg.mergedata.old.entity.OldPrintMachineLog;
import com.czg.mergedata.old.service.OldPrintMachineLogService;
import com.czg.mergedata.old.service.OldPrintMachineService;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.mergedata.cur.entity.CurPrintMachine;
import com.czg.mergedata.cur.mapper.CurPrintMachineMapper;
import com.czg.mergedata.cur.service.CurPrintMachineService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
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.concurrent.CompletableFuture;
/**
* 打印机设备 服务层实现
*
* @author mac
* @since 2025-03-14
*/
@Slf4j
@Service
public class CurPrintMachineServiceImpl extends ServiceImpl<CurPrintMachineMapper, CurPrintMachine> implements CurPrintMachineService{
@Resource
private CurPrintMachineLogMapper curPrintMachineLogMapper;
@Resource
private OldPrintMachineService oldPrintMachineService;
@Resource
private CurPrintMachineLogService curPrintMachineLogService;
@Resource
private OldPrintMachineLogService oldPrintMachineLogService;
@Override
@Transactional
public CzgResult<String> mergePrintData() {
getMapper().truncateTable();
curPrintMachineLogMapper.truncateTable();
mergeMachineData();
mergeLogData();
return CzgResult.success("success");
}
private void mergeMachineData() {
List<OldPrintMachine> list = oldPrintMachineService.list();
List<CurPrintMachine> curList = new ArrayList<>();
for (OldPrintMachine oldPrintMachine : list) {
CurPrintMachine curPrintMachine = BeanUtil.toBean(oldPrintMachine, CurPrintMachine.class);
curPrintMachine.setCreateTime(DateUtil.toLocalDateTime(oldPrintMachine.getCreatedAt() == null ? new Date() : new Date(oldPrintMachine.getCreatedAt())));
curPrintMachine.setUpdateTime(DateUtil.toLocalDateTime(oldPrintMachine.getUpdatedAt() == null ? new Date() : new Date(oldPrintMachine.getUpdatedAt())));
curList.add(curPrintMachine);
}
saveBatch(curList);
}
private void mergeLogData() {
List<OldPrintMachineLog> list = oldPrintMachineLogService.list();
List<List<OldPrintMachineLog>> lists = ListUtil.splitAvg(list, 7);
List<CompletableFuture<Void>> futures = new ArrayList<>();
for (List<OldPrintMachineLog> oldPrintMachineLogs : lists) {
futures.add(CompletableFuture.runAsync(() -> {
List<CurPrintMachineLog> curList = new ArrayList<>();
for (OldPrintMachineLog oldPrintMachineLog : oldPrintMachineLogs) {
CurPrintMachineLog curPrintMachineLog = BeanUtil.toBean(oldPrintMachineLog, CurPrintMachineLog.class);
curList.add(curPrintMachineLog);
}
curPrintMachineLogService.saveBatch(curList);
log.info("save {} log data", curList.size());
}));
}
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).whenComplete((result, error) -> log.info("merge log data complete"));
}
}

View File

@ -0,0 +1,148 @@
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-03-14
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_print_machine")
public class OldPrintMachine implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Integer id;
/**
* 设备名称
*/
private String name;
/**
* printer
*/
private String type;
/**
* 现在打印机支持USB 网络蓝牙
*/
private String connectionType;
/**
* ip地址
*/
private String address;
/**
* 端口
*/
private String port;
/**
* 打印类型分类label标签cash小票kitchen出品
*/
private String subType;
/**
* 状态 online
*/
private Integer status;
/**
* 店铺Id
*/
private String shopId;
/**
* 分类Id
*/
private String categoryIds;
/**
* 现在打印机支持USB 网络两种
*/
private String contentType;
/**
* 主配置
*/
private String config;
private Long createdAt;
private Long updatedAt;
/**
* 分类
*/
private String categoryList;
/**
* 排序
*/
private Integer sort;
/**
* Android打印机需要标识设备ID
*/
private String vendorId;
/**
* Android打印机需要标识设备ID
*/
private String productId;
/**
* 小票尺寸 58mm 80mm
*/
private String receiptSize;
/**
* 分类打印 0-所有 1-部分分类 2-部分商品
*/
private String classifyPrint;
/**
* 桌台打印 0-所有 1-部分 废弃
*/
private String tablePrint;
/**
* 打印数量 c1m1^2=顾客+商家[2张] m1^1=商家[1张] c1^1顾客[1张] c2m1^3顾客2+商家1[3张]
*/
private String printQty;
/**
* 打印方式 all-全部打印 normal-仅打印结账单前台one-仅打印制作单厨房
*/
private String printMethod;
/**
* 打印类型JSON数组 refund-确认退款单 handover-交班单 queue-排队取号
*/
private String printType;
/**
* 打印单据 0-全部打印 1-仅厨房 2-仅前台 废弃
*/
private String printReceipt;
}

View File

@ -0,0 +1,158 @@
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.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 店铺小票打印记录 实体类
*
* @author mac
* @since 2025-03-14
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_print_machine_log")
public class OldPrintMachineLog implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 打印机类型 本地打印机-local USB打印机-USB 云打印机-network
*/
private String connectionType;
/**
* 打印机品牌 云想印 = yxyPrinter飞鹅 = fePrinter 本地 = local USB = printer
*/
private String contentType;
/**
* 打印小票 标签-label 出品-kitchen 小票-cash
*/
private String subType;
/**
* 打印机名称
*/
private String name;
/**
* IP地址/打印机编号
*/
private String address;
/**
* 端口/打印机秘钥
*/
private String port;
/**
* 小票尺寸 58mm 80mm
*/
private String receiptSize;
/**
* 分类打印 0-所以 1-部分分类 2-部分商品
*/
private String classifyPrint;
/**
* 桌台打印 0-所有 1-部分
*/
private String tablePrint;
/**
* 打印数量 c1m1^2=顾客+商家[2张] m1^1=商家[1张] c1^1顾客[1张] c2m1^3=顾客2+商家1[3张]
*/
private String printQty;
/**
* 打印方式 normal-普通出单 one-一菜一品 callTicket-排队取号
*/
private String printMethod;
/**
* 打印类型 JSON数组字符串数据 1-确认退款单 2-交班单 3-排队取号[1,2,3]
*/
private String printType;
/**
* 打印票据 0-全部打印 1-仅厨房 2-仅前台
*/
private String printReceipt;
/**
* 打印内容
*/
private String printContent;
/**
* 店铺id
*/
private String shopId;
/**
* 业务类型
*/
private String bizType;
/**
* 打印人id
*/
private Long createUserId;
/**
* 打印人名称
*/
private String createUserName;
/**
* 打印任务创建时间
*/
private LocalDateTime createTime;
/**
* 打印任务id用于复查打印状态云想印=orderId
*/
private String taskId;
/**
* 实际打印时间
*/
private LocalDateTime printTime;
/**
* 失败标识 1- 0-
*/
private Integer failFlag;
/**
* 响应代码
*/
private String respCode;
/**
* 响应消息
*/
private String respMsg;
}

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.OldPrintMachineLog;
/**
* 店铺小票打印记录 映射层
*
* @author mac
* @since 2025-03-14
*/
@UseDataSource("ds2")
public interface OldPrintMachineLogMapper extends BaseMapper<OldPrintMachineLog> {
}

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.OldPrintMachine;
/**
* 打印机设备 映射层
*
* @author mac
* @since 2025-03-14
*/
@UseDataSource("ds2")
public interface OldPrintMachineMapper extends BaseMapper<OldPrintMachine> {
}

View File

@ -0,0 +1,14 @@
package com.czg.mergedata.old.service;
import com.mybatisflex.core.service.IService;
import com.czg.mergedata.old.entity.OldPrintMachineLog;
/**
* 店铺小票打印记录 服务层
*
* @author mac
* @since 2025-03-14
*/
public interface OldPrintMachineLogService extends IService<OldPrintMachineLog> {
}

View File

@ -0,0 +1,14 @@
package com.czg.mergedata.old.service;
import com.mybatisflex.core.service.IService;
import com.czg.mergedata.old.entity.OldPrintMachine;
/**
* 打印机设备 服务层
*
* @author mac
* @since 2025-03-14
*/
public interface OldPrintMachineService extends IService<OldPrintMachine> {
}

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.OldPrintMachineLog;
import com.czg.mergedata.old.mapper.OldPrintMachineLogMapper;
import com.czg.mergedata.old.service.OldPrintMachineLogService;
import org.springframework.stereotype.Service;
/**
* 店铺小票打印记录 服务层实现
*
* @author mac
* @since 2025-03-14
*/
@Service
public class OldPrintMachineLogServiceImpl extends ServiceImpl<OldPrintMachineLogMapper, OldPrintMachineLog> implements OldPrintMachineLogService{
}

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.OldPrintMachine;
import com.czg.mergedata.old.mapper.OldPrintMachineMapper;
import com.czg.mergedata.old.service.OldPrintMachineService;
import org.springframework.stereotype.Service;
/**
* 打印机设备 服务层实现
*
* @author mac
* @since 2025-03-14
*/
@Service
public class OldPrintMachineServiceImpl extends ServiceImpl<OldPrintMachineMapper, OldPrintMachine> implements OldPrintMachineService{
}

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.CurPrintMachineLogMapper">
</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.CurPrintMachineMapper">
</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.OldPrintMachineLogMapper">
</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.OldPrintMachineMapper">
</mapper>

View File

@ -130,3 +130,10 @@
> /merge/order/mergeRefundOrder
### 19. 打印机
> /merge/print/machine
#### 执行表
- tb_print_machine 表
- tb_print_machine_log 表