打印相关

This commit is contained in:
yinjinlu-pc\尹金路 2024-06-13 11:27:42 +08:00
parent e804d20b07
commit 2251817e41
22 changed files with 5839 additions and 0 deletions

37
ktg-print/pom.xml Normal file
View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ktg</artifactId>
<groupId>com.ktg</groupId>
<version>3.8.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ktg-print</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.65.Final</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.20.3</version>
</dependency>
<dependency>
<groupId>com.ktg</groupId>
<artifactId>ktg-common</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,106 @@
package com.ktg.print.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ktg.print.domain.PrintPrinterConfig;
import com.ktg.print.service.IPrintPrinterConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.common.core.page.TableDataInfo;
/**
* 打印机配置Controller
*
* @author yinjinlu
* @date 2023-09-01
*/
@RestController
@RequestMapping("/print/printerconfig")
public class PrintPrinterConfigController extends BaseController
{
@Autowired
private IPrintPrinterConfigService printPrinterConfigService;
/**
* 查询打印机配置列表
*/
@PreAuthorize("@ss.hasPermi('print:printerconfig:list')")
@GetMapping("/list")
public TableDataInfo list(PrintPrinterConfig printPrinterConfig)
{
startPage();
List<PrintPrinterConfig> list = printPrinterConfigService.selectPrintPrinterConfigList(printPrinterConfig);
return getDataTable(list);
}
/**
* 导出打印机配置列表
*/
@PreAuthorize("@ss.hasPermi('print:printerconfig:export')")
@Log(title = "打印机配置", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, PrintPrinterConfig printPrinterConfig)
{
List<PrintPrinterConfig> list = printPrinterConfigService.selectPrintPrinterConfigList(printPrinterConfig);
ExcelUtil<PrintPrinterConfig> util = new ExcelUtil<PrintPrinterConfig>(PrintPrinterConfig.class);
util.exportExcel(response, list, "打印机配置数据");
}
/**
* 获取打印机配置详细信息
*/
@PreAuthorize("@ss.hasPermi('print:printerconfig:query')")
@GetMapping(value = "/{printerId}")
public AjaxResult getInfo(@PathVariable("printerId") Long printerId)
{
return AjaxResult.success(printPrinterConfigService.selectPrintPrinterConfigByPrinterId(printerId));
}
/**
* 新增打印机配置
*/
@PreAuthorize("@ss.hasPermi('print:printerconfig:add')")
@Log(title = "打印机配置", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody PrintPrinterConfig printPrinterConfig)
{
return toAjax(printPrinterConfigService.insertPrintPrinterConfig(printPrinterConfig));
}
/**
* 修改打印机配置
*/
@PreAuthorize("@ss.hasPermi('print:printerconfig:edit')")
@Log(title = "打印机配置", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody PrintPrinterConfig printPrinterConfig)
{
return toAjax(printPrinterConfigService.updatePrintPrinterConfig(printPrinterConfig));
}
/**
* 删除打印机配置
*/
@PreAuthorize("@ss.hasPermi('print:printerconfig:remove')")
@Log(title = "打印机配置", businessType = BusinessType.DELETE)
@DeleteMapping("/{printerIds}")
public AjaxResult remove(@PathVariable Long[] printerIds)
{
return toAjax(printPrinterConfigService.deletePrintPrinterConfigByPrinterIds(printerIds));
}
}

View File

@ -0,0 +1,105 @@
package com.ktg.print.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.enums.BusinessType;
import com.ktg.print.domain.PrintTemplate;
import com.ktg.print.service.IPrintTemplateService;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.common.core.page.TableDataInfo;
/**
* 打印模板配置Controller
*
* @author yinjinlu
* @date 2024-04-17
*/
@RestController
@RequestMapping("/print/template")
public class PrintTemplateController extends BaseController
{
@Autowired
private IPrintTemplateService printTemplateService;
/**
* 查询打印模板配置列表
*/
@PreAuthorize("@ss.hasPermi('print:template:list')")
@GetMapping("/list")
public TableDataInfo list(PrintTemplate printTemplate)
{
startPage();
List<PrintTemplate> list = printTemplateService.selectPrintTemplateList(printTemplate);
return getDataTable(list);
}
/**
* 导出打印模板配置列表
*/
@PreAuthorize("@ss.hasPermi('print:template:export')")
@Log(title = "打印模板配置", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, PrintTemplate printTemplate)
{
List<PrintTemplate> list = printTemplateService.selectPrintTemplateList(printTemplate);
ExcelUtil<PrintTemplate> util = new ExcelUtil<PrintTemplate>(PrintTemplate.class);
util.exportExcel(response, list, "打印模板配置数据");
}
/**
* 获取打印模板配置详细信息
*/
@PreAuthorize("@ss.hasPermi('print:template:query')")
@GetMapping(value = "/{templateId}")
public AjaxResult getInfo(@PathVariable("templateId") Long templateId)
{
return AjaxResult.success(printTemplateService.selectPrintTemplateByTemplateId(templateId));
}
/**
* 新增打印模板配置
*/
@PreAuthorize("@ss.hasPermi('print:template:add')")
@Log(title = "打印模板配置", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody PrintTemplate printTemplate)
{
printTemplateService.insertPrintTemplate(printTemplate);
return AjaxResult.success(printTemplate);
}
/**
* 修改打印模板配置
*/
@PreAuthorize("@ss.hasPermi('print:template:edit')")
@Log(title = "打印模板配置", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody PrintTemplate printTemplate)
{
return toAjax(printTemplateService.updatePrintTemplate(printTemplate));
}
/**
* 删除打印模板配置
*/
@PreAuthorize("@ss.hasPermi('print:template:remove')")
@Log(title = "打印模板配置", businessType = BusinessType.DELETE)
@DeleteMapping("/{templateIds}")
public AjaxResult remove(@PathVariable Long[] templateIds)
{
return toAjax(printTemplateService.deletePrintTemplateByTemplateIds(templateIds));
}
}

View File

@ -0,0 +1,276 @@
package com.ktg.print.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ktg.common.annotation.Excel;
import com.ktg.common.core.domain.BaseEntity;
/**
* 打印机配置对象 print_printer_config
*
* @author yinjinlu
* @date 2023-09-01
*/
public class PrintPrinterConfig extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 打印机ID */
private Long printerId;
/** 打印机类型 */
@Excel(name = "打印机类型")
private String printerType;
/** 打印机名称 */
@Excel(name = "打印机名称")
private String printerName;
/** 品牌 */
@Excel(name = "品牌")
private String brand;
/** 型号 */
@Excel(name = "型号")
private String printerModel;
/** 连接类型 */
@Excel(name = "连接类型")
private String connectionType;
/** 图片URL */
@Excel(name = "图片URL")
private String printerUrl;
/** 打印机IP */
@Excel(name = "打印机IP")
private String printerIp;
/** 打印机端口 */
@Excel(name = "打印机端口")
private Long printerPort;
/** 打印客户端SID */
@Excel(name = "打印客户端SID")
private String clientSid;
/** 打印客户端IP */
@Excel(name = "打印客户端IP")
private String clientIp;
/** 打印客户端端口 */
@Excel(name = "打印客户端端口")
private Long clientPort;
/** 启用状态 */
@Excel(name = "启用状态")
private String enableFlag;
/** 打印机状态 */
@Excel(name = "打印机状态")
private String status;
/** 预留字段1 */
private String attr1;
/** 预留字段2 */
private String attr2;
/** 预留字段3 */
private Long attr3;
/** 预留字段4 */
private Long attr4;
public void setPrinterId(Long printerId)
{
this.printerId = printerId;
}
public Long getPrinterId()
{
return printerId;
}
public void setPrinterType(String printerType)
{
this.printerType = printerType;
}
public String getPrinterType()
{
return printerType;
}
public void setPrinterName(String printerName)
{
this.printerName = printerName;
}
public String getPrinterName()
{
return printerName;
}
public void setBrand(String brand)
{
this.brand = brand;
}
public String getBrand()
{
return brand;
}
public void setPrinterModel(String printerModel)
{
this.printerModel = printerModel;
}
public String getPrinterModel()
{
return printerModel;
}
public void setConnectionType(String connectionType)
{
this.connectionType = connectionType;
}
public String getConnectionType()
{
return connectionType;
}
public void setPrinterUrl(String printerUrl)
{
this.printerUrl = printerUrl;
}
public String getPrinterUrl()
{
return printerUrl;
}
public void setPrinterIp(String printerIp)
{
this.printerIp = printerIp;
}
public String getPrinterIp()
{
return printerIp;
}
public void setPrinterPort(Long printerPort)
{
this.printerPort = printerPort;
}
public Long getPrinterPort()
{
return printerPort;
}
public void setClientSid(String clientSid)
{
this.clientSid = clientSid;
}
public String getClientSid()
{
return clientSid;
}
public void setClientIp(String clientIp)
{
this.clientIp = clientIp;
}
public String getClientIp()
{
return clientIp;
}
public void setClientPort(Long clientPort)
{
this.clientPort = clientPort;
}
public Long getClientPort()
{
return clientPort;
}
public void setEnableFlag(String enableFlag)
{
this.enableFlag = enableFlag;
}
public String getEnableFlag()
{
return enableFlag;
}
public void setStatus(String status)
{
this.status = status;
}
public String getStatus()
{
return status;
}
public void setAttr1(String attr1)
{
this.attr1 = attr1;
}
public String getAttr1()
{
return attr1;
}
public void setAttr2(String attr2)
{
this.attr2 = attr2;
}
public String getAttr2()
{
return attr2;
}
public void setAttr3(Long attr3)
{
this.attr3 = attr3;
}
public Long getAttr3()
{
return attr3;
}
public void setAttr4(Long attr4)
{
this.attr4 = attr4;
}
public Long getAttr4()
{
return attr4;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("printerId", getPrinterId())
.append("printerType", getPrinterType())
.append("printerName", getPrinterName())
.append("brand", getBrand())
.append("printerModel", getPrinterModel())
.append("connectionType", getConnectionType())
.append("printerUrl", getPrinterUrl())
.append("printerIp", getPrinterIp())
.append("printerPort", getPrinterPort())
.append("clientSid", getClientSid())
.append("clientIp", getClientIp())
.append("clientPort", getClientPort())
.append("enableFlag", getEnableFlag())
.append("status", getStatus())
.append("remark", getRemark())
.append("attr1", getAttr1())
.append("attr2", getAttr2())
.append("attr3", getAttr3())
.append("attr4", getAttr4())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.toString();
}
}

View File

@ -0,0 +1,223 @@
package com.ktg.print.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ktg.common.annotation.Excel;
import com.ktg.common.core.domain.BaseEntity;
/**
* 打印模板配置对象 print_template
*
* @author yinjinlu
* @date 2024-04-17
*/
public class PrintTemplate extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 模板ID */
private Long templateId;
/** 模板编号 */
@Excel(name = "模板编号")
private String templateCode;
/** 模板名称 */
@Excel(name = "模板名称")
private String templateName;
/** 模板类型 */
@Excel(name = "模板类型")
private String templateType;
/** 模板内容 */
@Excel(name = "模板内容")
private String templateJson;
private String paperType;
private Integer templateWidth;
private Integer templateHeight;
/** 是否默认 */
@Excel(name = "是否默认")
private String isDefault;
/** 启用状态 */
@Excel(name = "启用状态")
private String enableFlag;
/** 预留字段1 */
private String attr1;
/** 预留字段2 */
private String attr2;
/** 预留字段3 */
private Long attr3;
/** 预留字段4 */
private Long attr4;
/** $column.columnComment */
@Excel(name = "启用状态")
private String templatePic;
public void setTemplateId(Long templateId)
{
this.templateId = templateId;
}
public Long getTemplateId()
{
return templateId;
}
public void setTemplateCode(String templateCode)
{
this.templateCode = templateCode;
}
public String getTemplateCode()
{
return templateCode;
}
public void setTemplateName(String templateName)
{
this.templateName = templateName;
}
public String getTemplateName()
{
return templateName;
}
public void setTemplateType(String templateType)
{
this.templateType = templateType;
}
public String getTemplateType()
{
return templateType;
}
public void setTemplateJson(String templateJson)
{
this.templateJson = templateJson;
}
public String getTemplateJson()
{
return templateJson;
}
public String getPaperType() {
return paperType;
}
public void setPaperType(String paperType) {
this.paperType = paperType;
}
public Integer getTemplateWidth() {
return templateWidth;
}
public void setTemplateWidth(Integer templateWidth) {
this.templateWidth = templateWidth;
}
public Integer getTemplateHeight() {
return templateHeight;
}
public void setTemplateHeight(Integer templateHeight) {
this.templateHeight = templateHeight;
}
public void setIsDefault(String isDefault)
{
this.isDefault = isDefault;
}
public String getIsDefault()
{
return isDefault;
}
public void setEnableFlag(String enableFlag)
{
this.enableFlag = enableFlag;
}
public String getEnableFlag()
{
return enableFlag;
}
public void setAttr1(String attr1)
{
this.attr1 = attr1;
}
public String getAttr1()
{
return attr1;
}
public void setAttr2(String attr2)
{
this.attr2 = attr2;
}
public String getAttr2()
{
return attr2;
}
public void setAttr3(Long attr3)
{
this.attr3 = attr3;
}
public Long getAttr3()
{
return attr3;
}
public void setAttr4(Long attr4)
{
this.attr4 = attr4;
}
public Long getAttr4()
{
return attr4;
}
public void setTemplatePic(String templatePic)
{
this.templatePic = templatePic;
}
public String getTemplatePic()
{
return templatePic;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("templateId", getTemplateId())
.append("templateCode", getTemplateCode())
.append("templateName", getTemplateName())
.append("templateType", getTemplateType())
.append("templateJson", getTemplateJson())
.append("isDefault", getIsDefault())
.append("enableFlag", getEnableFlag())
.append("remark", getRemark())
.append("attr1", getAttr1())
.append("attr2", getAttr2())
.append("attr3", getAttr3())
.append("attr4", getAttr4())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("templatePic", getTemplatePic())
.toString();
}
}

View File

@ -0,0 +1,63 @@
package com.ktg.print.mapper;
import com.ktg.print.domain.PrintPrinterConfig;
import java.util.List;
/**
* 打印机配置Mapper接口
*
* @author yinjinlu
* @date 2023-09-01
*/
public interface PrintPrinterConfigMapper
{
/**
* 查询打印机配置
*
* @param printerId 打印机配置主键
* @return 打印机配置
*/
public PrintPrinterConfig selectPrintPrinterConfigByPrinterId(Long printerId);
/**
* 查询打印机配置列表
*
* @param printPrinterConfig 打印机配置
* @return 打印机配置集合
*/
public List<PrintPrinterConfig> selectPrintPrinterConfigList(PrintPrinterConfig printPrinterConfig);
/**
* 新增打印机配置
*
* @param printPrinterConfig 打印机配置
* @return 结果
*/
public int insertPrintPrinterConfig(PrintPrinterConfig printPrinterConfig);
/**
* 修改打印机配置
*
* @param printPrinterConfig 打印机配置
* @return 结果
*/
public int updatePrintPrinterConfig(PrintPrinterConfig printPrinterConfig);
/**
* 删除打印机配置
*
* @param printerId 打印机配置主键
* @return 结果
*/
public int deletePrintPrinterConfigByPrinterId(Long printerId);
/**
* 批量删除打印机配置
*
* @param printerIds 需要删除的数据主键集合
* @return 结果
*/
public int deletePrintPrinterConfigByPrinterIds(Long[] printerIds);
}

View File

@ -0,0 +1,61 @@
package com.ktg.print.mapper;
import java.util.List;
import com.ktg.print.domain.PrintTemplate;
/**
* 打印模板配置Mapper接口
*
* @author yinjinlu
* @date 2024-04-17
*/
public interface PrintTemplateMapper
{
/**
* 查询打印模板配置
*
* @param templateId 打印模板配置主键
* @return 打印模板配置
*/
public PrintTemplate selectPrintTemplateByTemplateId(Long templateId);
/**
* 查询打印模板配置列表
*
* @param printTemplate 打印模板配置
* @return 打印模板配置集合
*/
public List<PrintTemplate> selectPrintTemplateList(PrintTemplate printTemplate);
/**
* 新增打印模板配置
*
* @param printTemplate 打印模板配置
* @return 结果
*/
public int insertPrintTemplate(PrintTemplate printTemplate);
/**
* 修改打印模板配置
*
* @param printTemplate 打印模板配置
* @return 结果
*/
public int updatePrintTemplate(PrintTemplate printTemplate);
/**
* 删除打印模板配置
*
* @param templateId 打印模板配置主键
* @return 结果
*/
public int deletePrintTemplateByTemplateId(Long templateId);
/**
* 批量删除打印模板配置
*
* @param templateIds 需要删除的数据主键集合
* @return 结果
*/
public int deletePrintTemplateByTemplateIds(Long[] templateIds);
}

View File

@ -0,0 +1,35 @@
package com.ktg.print.printserver;
import com.ktg.print.protocol.PrintMessageProto;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Component
public class PrintClientInfoMessageHandler extends SimpleChannelInboundHandler<PrintMessageProto.PrintClientInfoMessage> {
//接收到客户端发送的客户端信息后才会保存client信息
private Map<String, Channel> clients = new ConcurrentHashMap<>();
private ChannelGroup group = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
@Override
protected void channelRead0(ChannelHandlerContext channelHandlerContext, PrintMessageProto.PrintClientInfoMessage clientInfoMessag) throws Exception {
if(!clients.containsKey(clientInfoMessag.getSid())){
clients.put(clientInfoMessag.getSid(),channelHandlerContext.channel());
}
channelHandlerContext.fireChannelRead(clientInfoMessag);
group.add(channelHandlerContext.channel());
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
group.remove(ctx.channel());
}
}

View File

@ -0,0 +1,30 @@
package com.ktg.print.printserver;
import com.ktg.print.protocol.PrintMessageProto;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.protobuf.ProtobufDecoder;
import io.netty.handler.codec.protobuf.ProtobufEncoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class PrintServerChannelInitializer extends ChannelInitializer {
@Autowired
private PrintServerDefaultHandler serverDefaultHandler;
@Autowired
private PrintClientInfoMessageHandler printClientInfoMessageHandler;
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(new ProtobufVarint32FrameDecoder());
ch.pipeline().addLast(new ProtobufDecoder(PrintMessageProto.PrintClientInfoMessage.getDefaultInstance()));
ch.pipeline().addLast(new ProtobufEncoder());
ch.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender());
ch.pipeline().addLast(printClientInfoMessageHandler);
ch.pipeline().addLast(serverDefaultHandler);
}
}

View File

@ -0,0 +1,18 @@
package com.ktg.print.printserver;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
public class PrintServerCloseListener implements DisposableBean {
@Resource
private PrinterServer printerServer;
@Override
public void destroy() throws Exception {
printerServer.stop();
}
}

View File

@ -0,0 +1,70 @@
package com.ktg.print.printserver;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.CharsetUtil;
import io.netty.util.concurrent.GlobalEventExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Component
@ChannelHandler.Sharable
public class PrintServerDefaultHandler extends ChannelInboundHandlerAdapter {
private static final Logger logger = LoggerFactory.getLogger("PrinterServerHandler");
/**
* 客户端连接建立
* @param ctx
* @throws Exception
*/
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
logger.info("打印机客户端已连接!");
}
/**
* 客户端连接移除
* @param ctx
* @throws Exception
*/
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
logger.info("打印机客户端已断开!");
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg){
try{
ByteBuf data = (ByteBuf) msg;
logger.info("msg recived:"+data.toString(CharsetUtil.UTF_8));
String replyMessage = "Server reply: " + data.toString(CharsetUtil.UTF_8)+"\n";
ByteBuf replyByteBuf = ctx.alloc().buffer();
replyByteBuf.writeBytes(replyMessage.getBytes());
ctx.writeAndFlush(replyByteBuf);
}catch (Exception e){
logger.error(e.getMessage());
}
}
/**
* 异常发生关闭通道移除客户端
* @param ctx
* @param cause
* @throws Exception
*/
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
ctx.channel().close();
}
}

View File

@ -0,0 +1,20 @@
package com.ktg.print.printserver;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
public class PrintServerOpenListener implements ApplicationRunner {
@Resource
private PrinterServer printerServer;
@Override
public void run(ApplicationArguments args) throws Exception {
printerServer.start();
}
}

View File

@ -0,0 +1,67 @@
package com.ktg.print.printserver;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.protobuf.ProtobufDecoder;
import io.netty.handler.codec.protobuf.ProtobufEncoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* 基于netty的socket服务器端与标签打印机的客户端建立长连接实现网络远程打印
*/
@Component
public class PrinterServer {
@Autowired
private PrintServerChannelInitializer printServerChannelInitializer;
@Value("${netty.server.port}")
private int port;
@Value("${netty.server.threadcount}")
private int bossThreadCount;
private EventLoopGroup bossGroup;
private EventLoopGroup workerGroup;
private Channel serverChannel;
PrinterServer(){
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
}
public void start(){
try {
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(printServerChannelInitializer);
ChannelFuture channelFuture = serverBootstrap.bind(port).sync();
serverChannel = channelFuture.channel();
serverChannel.closeFuture().sync();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
public void stop(){
if(serverChannel !=null){
serverChannel.close();
serverChannel = null;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,36 @@
syntax = "proto3";
package com.ktg.print.protocol;
option java_package = "com.ktg.print.protocol";
option java_outer_classname = "PrintMessageProto";
message IQCPrintMessage {
string sampleCode = 1;
string qcObject = 2;
string sampleTime = 3;
string batchCode = 4;
}
message PQCPrintMessage {
string sampleCode = 1;
string qcObject = 2;
string sampleTime = 3;
string sampleLocation = 4;
}
message OQCPrintMessage {
string sampleCode = 1;
string qcObject = 2;
string sampleTime = 3;
string batchCode = 4;
string packageType = 5;
}
//
message PrintClientInfoMessage {
string ip = 1;
string location = 2;
string sid = 3;
}

View File

@ -0,0 +1,62 @@
package com.ktg.print.service;
import com.ktg.print.domain.PrintPrinterConfig;
import java.util.List;
/**
* 打印机配置Service接口
*
* @author yinjinlu
* @date 2023-09-01
*/
public interface IPrintPrinterConfigService
{
/**
* 查询打印机配置
*
* @param printerId 打印机配置主键
* @return 打印机配置
*/
public PrintPrinterConfig selectPrintPrinterConfigByPrinterId(Long printerId);
/**
* 查询打印机配置列表
*
* @param printPrinterConfig 打印机配置
* @return 打印机配置集合
*/
public List<PrintPrinterConfig> selectPrintPrinterConfigList(PrintPrinterConfig printPrinterConfig);
/**
* 新增打印机配置
*
* @param printPrinterConfig 打印机配置
* @return 结果
*/
public int insertPrintPrinterConfig(PrintPrinterConfig printPrinterConfig);
/**
* 修改打印机配置
*
* @param printPrinterConfig 打印机配置
* @return 结果
*/
public int updatePrintPrinterConfig(PrintPrinterConfig printPrinterConfig);
/**
* 批量删除打印机配置
*
* @param printerIds 需要删除的打印机配置主键集合
* @return 结果
*/
public int deletePrintPrinterConfigByPrinterIds(Long[] printerIds);
/**
* 删除打印机配置信息
*
* @param printerId 打印机配置主键
* @return 结果
*/
public int deletePrintPrinterConfigByPrinterId(Long printerId);
}

View File

@ -0,0 +1,61 @@
package com.ktg.print.service;
import java.util.List;
import com.ktg.print.domain.PrintTemplate;
/**
* 打印模板配置Service接口
*
* @author yinjinlu
* @date 2024-04-17
*/
public interface IPrintTemplateService
{
/**
* 查询打印模板配置
*
* @param templateId 打印模板配置主键
* @return 打印模板配置
*/
public PrintTemplate selectPrintTemplateByTemplateId(Long templateId);
/**
* 查询打印模板配置列表
*
* @param printTemplate 打印模板配置
* @return 打印模板配置集合
*/
public List<PrintTemplate> selectPrintTemplateList(PrintTemplate printTemplate);
/**
* 新增打印模板配置
*
* @param printTemplate 打印模板配置
* @return 结果
*/
public int insertPrintTemplate(PrintTemplate printTemplate);
/**
* 修改打印模板配置
*
* @param printTemplate 打印模板配置
* @return 结果
*/
public int updatePrintTemplate(PrintTemplate printTemplate);
/**
* 批量删除打印模板配置
*
* @param templateIds 需要删除的打印模板配置主键集合
* @return 结果
*/
public int deletePrintTemplateByTemplateIds(Long[] templateIds);
/**
* 删除打印模板配置信息
*
* @param templateId 打印模板配置主键
* @return 结果
*/
public int deletePrintTemplateByTemplateId(Long templateId);
}

View File

@ -0,0 +1,96 @@
package com.ktg.print.service.impl;
import java.util.List;
import com.ktg.common.utils.DateUtils;
import com.ktg.print.domain.PrintPrinterConfig;
import com.ktg.print.mapper.PrintPrinterConfigMapper;
import com.ktg.print.service.IPrintPrinterConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 打印机配置Service业务层处理
*
* @author yinjinlu
* @date 2023-09-01
*/
@Service
public class PrintPrinterConfigServiceImpl implements IPrintPrinterConfigService
{
@Autowired
private PrintPrinterConfigMapper printPrinterConfigMapper;
/**
* 查询打印机配置
*
* @param printerId 打印机配置主键
* @return 打印机配置
*/
@Override
public PrintPrinterConfig selectPrintPrinterConfigByPrinterId(Long printerId)
{
return printPrinterConfigMapper.selectPrintPrinterConfigByPrinterId(printerId);
}
/**
* 查询打印机配置列表
*
* @param printPrinterConfig 打印机配置
* @return 打印机配置
*/
@Override
public List<PrintPrinterConfig> selectPrintPrinterConfigList(PrintPrinterConfig printPrinterConfig)
{
return printPrinterConfigMapper.selectPrintPrinterConfigList(printPrinterConfig);
}
/**
* 新增打印机配置
*
* @param printPrinterConfig 打印机配置
* @return 结果
*/
@Override
public int insertPrintPrinterConfig(PrintPrinterConfig printPrinterConfig)
{
printPrinterConfig.setCreateTime(DateUtils.getNowDate());
return printPrinterConfigMapper.insertPrintPrinterConfig(printPrinterConfig);
}
/**
* 修改打印机配置
*
* @param printPrinterConfig 打印机配置
* @return 结果
*/
@Override
public int updatePrintPrinterConfig(PrintPrinterConfig printPrinterConfig)
{
printPrinterConfig.setUpdateTime(DateUtils.getNowDate());
return printPrinterConfigMapper.updatePrintPrinterConfig(printPrinterConfig);
}
/**
* 批量删除打印机配置
*
* @param printerIds 需要删除的打印机配置主键
* @return 结果
*/
@Override
public int deletePrintPrinterConfigByPrinterIds(Long[] printerIds)
{
return printPrinterConfigMapper.deletePrintPrinterConfigByPrinterIds(printerIds);
}
/**
* 删除打印机配置信息
*
* @param printerId 打印机配置主键
* @return 结果
*/
@Override
public int deletePrintPrinterConfigByPrinterId(Long printerId)
{
return printPrinterConfigMapper.deletePrintPrinterConfigByPrinterId(printerId);
}
}

View File

@ -0,0 +1,96 @@
package com.ktg.print.service.impl;
import java.util.List;
import com.ktg.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.print.mapper.PrintTemplateMapper;
import com.ktg.print.domain.PrintTemplate;
import com.ktg.print.service.IPrintTemplateService;
/**
* 打印模板配置Service业务层处理
*
* @author yinjinlu
* @date 2024-04-17
*/
@Service
public class PrintTemplateServiceImpl implements IPrintTemplateService
{
@Autowired
private PrintTemplateMapper printTemplateMapper;
/**
* 查询打印模板配置
*
* @param templateId 打印模板配置主键
* @return 打印模板配置
*/
@Override
public PrintTemplate selectPrintTemplateByTemplateId(Long templateId)
{
return printTemplateMapper.selectPrintTemplateByTemplateId(templateId);
}
/**
* 查询打印模板配置列表
*
* @param printTemplate 打印模板配置
* @return 打印模板配置
*/
@Override
public List<PrintTemplate> selectPrintTemplateList(PrintTemplate printTemplate)
{
return printTemplateMapper.selectPrintTemplateList(printTemplate);
}
/**
* 新增打印模板配置
*
* @param printTemplate 打印模板配置
* @return 结果
*/
@Override
public int insertPrintTemplate(PrintTemplate printTemplate)
{
printTemplate.setCreateTime(DateUtils.getNowDate());
return printTemplateMapper.insertPrintTemplate(printTemplate);
}
/**
* 修改打印模板配置
*
* @param printTemplate 打印模板配置
* @return 结果
*/
@Override
public int updatePrintTemplate(PrintTemplate printTemplate)
{
printTemplate.setUpdateTime(DateUtils.getNowDate());
return printTemplateMapper.updatePrintTemplate(printTemplate);
}
/**
* 批量删除打印模板配置
*
* @param templateIds 需要删除的打印模板配置主键
* @return 结果
*/
@Override
public int deletePrintTemplateByTemplateIds(Long[] templateIds)
{
return printTemplateMapper.deletePrintTemplateByTemplateIds(templateIds);
}
/**
* 删除打印模板配置信息
*
* @param templateId 打印模板配置主键
* @return 结果
*/
@Override
public int deletePrintTemplateByTemplateId(Long templateId)
{
return printTemplateMapper.deletePrintTemplateByTemplateId(templateId);
}
}

View File

@ -0,0 +1,9 @@
package com.ktg.print.util;
/**
* 负责将模板内容转换为具体的标签打印机协议
*/
public class ContentConverter {
}

View File

@ -0,0 +1,151 @@
<?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.ktg.print.mapper.PrintPrinterConfigMapper">
<resultMap type="PrintPrinterConfig" id="PrintPrinterConfigResult">
<result property="printerId" column="printer_id" />
<result property="printerType" column="printer_type" />
<result property="printerName" column="printer_name" />
<result property="brand" column="brand" />
<result property="printerModel" column="printer_model" />
<result property="connectionType" column="connection_type" />
<result property="printerUrl" column="printer_url" />
<result property="printerIp" column="printer_ip" />
<result property="printerPort" column="printer_port" />
<result property="clientSid" column="client_sid" />
<result property="clientIp" column="client_ip" />
<result property="clientPort" column="client_port" />
<result property="enableFlag" column="enable_flag" />
<result property="status" column="status" />
<result property="remark" column="remark" />
<result property="attr1" column="attr1" />
<result property="attr2" column="attr2" />
<result property="attr3" column="attr3" />
<result property="attr4" column="attr4" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectPrintPrinterConfigVo">
select printer_id, printer_type, printer_name, brand, printer_model, connection_type, printer_url, printer_ip, printer_port, client_sid, client_ip, client_port, enable_flag, status, remark, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time from print_printer_config
</sql>
<select id="selectPrintPrinterConfigList" parameterType="PrintPrinterConfig" resultMap="PrintPrinterConfigResult">
<include refid="selectPrintPrinterConfigVo"/>
<where>
<if test="printerType != null and printerType != ''"> and printer_type = #{printerType}</if>
<if test="printerName != null and printerName != ''"> and printer_name like concat('%', #{printerName}, '%')</if>
<if test="brand != null and brand != ''"> and brand = #{brand}</if>
<if test="printerModel != null and printerModel != ''"> and printer_model = #{printerModel}</if>
<if test="connectionType != null and connectionType != ''"> and connection_type = #{connectionType}</if>
<if test="printerUrl != null and printerUrl != ''"> and printer_url = #{printerUrl}</if>
<if test="printerIp != null and printerIp != ''"> and printer_ip = #{printerIp}</if>
<if test="printerPort != null "> and printer_port = #{printerPort}</if>
<if test="clientSid != null and clientSid != ''"> and client_sid = #{clientSid}</if>
<if test="clientIp != null and clientIp != ''"> and client_ip = #{clientIp}</if>
<if test="clientPort != null "> and client_port = #{clientPort}</if>
<if test="enableFlag != null and enableFlag != ''"> and enable_flag = #{enableFlag}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
</where>
</select>
<select id="selectPrintPrinterConfigByPrinterId" parameterType="Long" resultMap="PrintPrinterConfigResult">
<include refid="selectPrintPrinterConfigVo"/>
where printer_id = #{printerId}
</select>
<insert id="insertPrintPrinterConfig" parameterType="PrintPrinterConfig" useGeneratedKeys="true" keyProperty="printerId">
insert into print_printer_config
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="printerType != null">printer_type,</if>
<if test="printerName != null and printerName != ''">printer_name,</if>
<if test="brand != null">brand,</if>
<if test="printerModel != null">printer_model,</if>
<if test="connectionType != null">connection_type,</if>
<if test="printerUrl != null">printer_url,</if>
<if test="printerIp != null">printer_ip,</if>
<if test="printerPort != null">printer_port,</if>
<if test="clientSid != null">client_sid,</if>
<if test="clientIp != null">client_ip,</if>
<if test="clientPort != null">client_port,</if>
<if test="enableFlag != null">enable_flag,</if>
<if test="status != null">status,</if>
<if test="remark != null">remark,</if>
<if test="attr1 != null">attr1,</if>
<if test="attr2 != null">attr2,</if>
<if test="attr3 != null">attr3,</if>
<if test="attr4 != null">attr4,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="printerType != null">#{printerType},</if>
<if test="printerName != null and printerName != ''">#{printerName},</if>
<if test="brand != null">#{brand},</if>
<if test="printerModel != null">#{printerModel},</if>
<if test="connectionType != null">#{connectionType},</if>
<if test="printerUrl != null">#{printerUrl},</if>
<if test="printerIp != null">#{printerIp},</if>
<if test="printerPort != null">#{printerPort},</if>
<if test="clientSid != null">#{clientSid},</if>
<if test="clientIp != null">#{clientIp},</if>
<if test="clientPort != null">#{clientPort},</if>
<if test="enableFlag != null">#{enableFlag},</if>
<if test="status != null">#{status},</if>
<if test="remark != null">#{remark},</if>
<if test="attr1 != null">#{attr1},</if>
<if test="attr2 != null">#{attr2},</if>
<if test="attr3 != null">#{attr3},</if>
<if test="attr4 != null">#{attr4},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updatePrintPrinterConfig" parameterType="PrintPrinterConfig">
update print_printer_config
<trim prefix="SET" suffixOverrides=",">
<if test="printerType != null">printer_type = #{printerType},</if>
<if test="printerName != null and printerName != ''">printer_name = #{printerName},</if>
<if test="brand != null">brand = #{brand},</if>
<if test="printerModel != null">printer_model = #{printerModel},</if>
<if test="connectionType != null">connection_type = #{connectionType},</if>
<if test="printerUrl != null">printer_url = #{printerUrl},</if>
<if test="printerIp != null">printer_ip = #{printerIp},</if>
<if test="printerPort != null">printer_port = #{printerPort},</if>
<if test="clientSid != null">client_sid = #{clientSid},</if>
<if test="clientIp != null">client_ip = #{clientIp},</if>
<if test="clientPort != null">client_port = #{clientPort},</if>
<if test="enableFlag != null">enable_flag = #{enableFlag},</if>
<if test="status != null">status = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="attr1 != null">attr1 = #{attr1},</if>
<if test="attr2 != null">attr2 = #{attr2},</if>
<if test="attr3 != null">attr3 = #{attr3},</if>
<if test="attr4 != null">attr4 = #{attr4},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where printer_id = #{printerId}
</update>
<delete id="deletePrintPrinterConfigByPrinterId" parameterType="Long">
delete from print_printer_config where printer_id = #{printerId}
</delete>
<delete id="deletePrintPrinterConfigByPrinterIds" parameterType="String">
delete from print_printer_config where printer_id in
<foreach item="printerId" collection="array" open="(" separator="," close=")">
#{printerId}
</foreach>
</delete>
</mapper>

View File

@ -0,0 +1,135 @@
<?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.ktg.print.mapper.PrintTemplateMapper">
<resultMap type="PrintTemplate" id="PrintTemplateResult">
<result property="templateId" column="template_id" />
<result property="templateCode" column="template_code" />
<result property="templateName" column="template_name" />
<result property="templateType" column="template_type" />
<result property="templateJson" column="template_json" />
<result property="paperType" column="paper_type" />
<result property="templateWidth" column="template_width" />
<result property="templateHeight" column="template_height" />
<result property="isDefault" column="is_default" />
<result property="enableFlag" column="enable_flag" />
<result property="remark" column="remark" />
<result property="attr1" column="attr1" />
<result property="attr2" column="attr2" />
<result property="attr3" column="attr3" />
<result property="attr4" column="attr4" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="templatePic" column="template_pic" />
</resultMap>
<sql id="selectPrintTemplateVo">
select template_id, template_code, template_name, template_type, template_json, paper_type, template_width, template_height, is_default, enable_flag, remark, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time, template_pic from print_template
</sql>
<select id="selectPrintTemplateList" parameterType="PrintTemplate" resultMap="PrintTemplateResult">
<include refid="selectPrintTemplateVo"/>
<where>
<if test="templateCode != null and templateCode != ''"> and template_code = #{templateCode}</if>
<if test="templateName != null and templateName != ''"> and template_name like concat('%', #{templateName}, '%')</if>
<if test="templateType != null and templateType != ''"> and template_type = #{templateType}</if>
<if test="templateJson != null and templateJson != ''"> and template_json = #{templateJson}</if>
<if test="paperType != null and paperType != ''"> and paper_type = #{paperType}</if>
<if test="isDefault != null and isDefault != ''"> and is_default = #{isDefault}</if>
<if test="enableFlag != null and enableFlag != ''"> and enable_flag = #{enableFlag}</if>
<if test="templatePic != null and templatePic != ''"> and template_pic = #{templatePic}</if>
</where>
</select>
<select id="selectPrintTemplateByTemplateId" parameterType="Long" resultMap="PrintTemplateResult">
<include refid="selectPrintTemplateVo"/>
where template_id = #{templateId}
</select>
<insert id="insertPrintTemplate" parameterType="PrintTemplate" useGeneratedKeys="true" keyProperty="templateId">
insert into print_template
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="templateCode != null and templateCode != ''">template_code,</if>
<if test="templateName != null">template_name,</if>
<if test="templateType != null and templateType != ''">template_type,</if>
<if test="templateJson != null">template_json,</if>
<if test="paperType != null">paper_type,</if>
<if test="templateWidth != null">template_width,</if>
<if test="templateHeight != null">template_height,</if>
<if test="isDefault != null">is_default,</if>
<if test="enableFlag != null">enable_flag,</if>
<if test="remark != null">remark,</if>
<if test="attr1 != null">attr1,</if>
<if test="attr2 != null">attr2,</if>
<if test="attr3 != null">attr3,</if>
<if test="attr4 != null">attr4,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="templatePic != null">template_pic,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="templateCode != null and templateCode != ''">#{templateCode},</if>
<if test="templateName != null">#{templateName},</if>
<if test="templateType != null and templateType != ''">#{templateType},</if>
<if test="templateJson != null">#{templateJson},</if>
<if test="paperType != null">#{paperType},</if>
<if test="templateWidth != null">#{templateWidth},</if>
<if test="templateHeight != null">#{templateHeight},</if>
<if test="isDefault != null">#{isDefault},</if>
<if test="enableFlag != null">#{enableFlag},</if>
<if test="remark != null">#{remark},</if>
<if test="attr1 != null">#{attr1},</if>
<if test="attr2 != null">#{attr2},</if>
<if test="attr3 != null">#{attr3},</if>
<if test="attr4 != null">#{attr4},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="templatePic != null">#{templatePic},</if>
</trim>
</insert>
<update id="updatePrintTemplate" parameterType="PrintTemplate">
update print_template
<trim prefix="SET" suffixOverrides=",">
<if test="templateCode != null and templateCode != ''">template_code = #{templateCode},</if>
<if test="templateName != null">template_name = #{templateName},</if>
<if test="templateType != null and templateType != ''">template_type = #{templateType},</if>
<if test="templateJson != null">template_json = #{templateJson},</if>
<if test="paperType != null">paper_type = #{paperType},</if>
<if test="templateWidth != null">template_width = #{templateWidth},</if>
<if test="templateHeight != null">template_height = #{templateHeight},</if>
<if test="isDefault != null">is_default = #{isDefault},</if>
<if test="enableFlag != null">enable_flag = #{enableFlag},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="attr1 != null">attr1 = #{attr1},</if>
<if test="attr2 != null">attr2 = #{attr2},</if>
<if test="attr3 != null">attr3 = #{attr3},</if>
<if test="attr4 != null">attr4 = #{attr4},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="templatePic != null">template_pic = #{templatePic},</if>
</trim>
where template_id = #{templateId}
</update>
<delete id="deletePrintTemplateByTemplateId" parameterType="Long">
delete from print_template where template_id = #{templateId}
</delete>
<delete id="deletePrintTemplateByTemplateIds" parameterType="String">
delete from print_template where template_id in
<foreach item="templateId" collection="array" open="(" separator="," close=")">
#{templateId}
</foreach>
</delete>
</mapper>