Commit 3cf1e65aaae0299ba9a6a6a26f4f52a3ccf3e825

Authored by lvqi
1 parent 76fde56c

feat(core): 添加云打印功能支持

Showing 31 changed files with 1466 additions and 0 deletions
mqtt-core/pom.xml
... ... @@ -26,6 +26,10 @@
26 26 <groupId>org.projectlombok</groupId>
27 27 <artifactId>lombok</artifactId>
28 28 </dependency>
  29 + <dependency>
  30 + <groupId>org.springframework.boot</groupId>
  31 + <artifactId>spring-boot-starter-data-mongodb</artifactId>
  32 + </dependency>
29 33 </dependencies>
30 34  
31 35 </project>
... ...
mqtt-core/src/main/java/com/diligrp/mqtt/core/model/CloudColumn.java 0 → 100644
  1 +package com.diligrp.mqtt.core.model;
  2 +
  3 +
  4 +/**
  5 + * 打印列
  6 + * @author lvqi
  7 + */
  8 +public class CloudColumn {
  9 + /**
  10 + * 内容值
  11 + */
  12 + private String cv;
  13 + /**
  14 + * 对齐方式
  15 + */
  16 + private String al;
  17 + /**
  18 + * 打印内容颜色
  19 + */
  20 + private String fc;
  21 + /**
  22 + * 打印字体大小
  23 + */
  24 + private String fs;
  25 + /**
  26 + * 打印字体样式
  27 + */
  28 + private String tf;
  29 + /**
  30 + * 文本下划线
  31 + */
  32 + private String tu;
  33 + /**
  34 + * 加粗
  35 + */
  36 + private String tb;
  37 +
  38 + public String getCv() {
  39 + return cv;
  40 + }
  41 +
  42 + public void setCv(String cv) {
  43 + this.cv = cv;
  44 + }
  45 +
  46 + public String getAl() {
  47 + return al;
  48 + }
  49 +
  50 + public void setAl(String al) {
  51 + this.al = al;
  52 + }
  53 +
  54 + public String getFc() {
  55 + return fc;
  56 + }
  57 +
  58 + public void setFc(String fc) {
  59 + this.fc = fc;
  60 + }
  61 +
  62 + public String getFs() {
  63 + return fs;
  64 + }
  65 +
  66 + public void setFs(String fs) {
  67 + this.fs = fs;
  68 + }
  69 +
  70 + public String getTf() {
  71 + return tf;
  72 + }
  73 +
  74 + public void setTf(String tf) {
  75 + this.tf = tf;
  76 + }
  77 +
  78 + public String getTu() {
  79 + return tu;
  80 + }
  81 +
  82 + public void setTu(String tu) {
  83 + this.tu = tu;
  84 + }
  85 +
  86 + public String getTb() {
  87 + return tb;
  88 + }
  89 +
  90 + public void setTb(String tb) {
  91 + this.tb = tb;
  92 + }
  93 +}
... ...
mqtt-core/src/main/java/com/diligrp/mqtt/core/model/CloudMessContent.java 0 → 100644
  1 +package com.diligrp.mqtt.core.model;
  2 +
  3 +
  4 +import java.util.List;
  5 +
  6 +/**
  7 + * @author lvqi
  8 + */
  9 +
  10 +public class CloudMessContent {
  11 + /**
  12 + * 语音播报内容
  13 + */
  14 + private String sc;
  15 + /**
  16 + * 打印内容
  17 + */
  18 + private List<CloudMessPCPart> pc;
  19 +
  20 + public String getSc() {
  21 + return sc;
  22 + }
  23 +
  24 + public void setSc(String sc) {
  25 + this.sc = sc;
  26 + }
  27 +
  28 + public List<CloudMessPCPart> getPc() {
  29 + return pc;
  30 + }
  31 +
  32 + public void setPc(List<CloudMessPCPart> pc) {
  33 + this.pc = pc;
  34 + }
  35 +}
0 36 \ No newline at end of file
... ...
mqtt-core/src/main/java/com/diligrp/mqtt/core/model/CloudMessPCPart.java 0 → 100644
  1 +package com.diligrp.mqtt.core.model;
  2 +
  3 +import java.util.List;
  4 +
  5 +/**
  6 + * @author lvqi
  7 + */
  8 +public class CloudMessPCPart {
  9 + /**
  10 + * 行数据类型
  11 + */
  12 + private String tp;
  13 + /**
  14 + * 行距
  15 + */
  16 + private String ls;
  17 + /**
  18 + * 字符间距
  19 + */
  20 + private String ws;
  21 + /**
  22 + * 列数据
  23 + */
  24 + private List<CloudColumn> cols;
  25 +
  26 + public String getTp() {
  27 + return tp;
  28 + }
  29 +
  30 + public void setTp(String tp) {
  31 + this.tp = tp;
  32 + }
  33 +
  34 + public String getLs() {
  35 + return ls;
  36 + }
  37 +
  38 + public void setLs(String ls) {
  39 + this.ls = ls;
  40 + }
  41 +
  42 + public String getWs() {
  43 + return ws;
  44 + }
  45 +
  46 + public void setWs(String ws) {
  47 + this.ws = ws;
  48 + }
  49 +
  50 + public List<CloudColumn> getCols() {
  51 + return cols;
  52 + }
  53 +
  54 + public void setCols(List<CloudColumn> cols) {
  55 + this.cols = cols;
  56 + }
  57 +}
  58 +
... ...
mqtt-core/src/main/java/com/diligrp/mqtt/core/model/CloudRequest.java 0 → 100644
  1 +package com.diligrp.mqtt.core.model;
  2 +
  3 +
  4 +/**
  5 + * @author lvqi
  6 + */
  7 +public class CloudRequest {
  8 + /**
  9 + * 机构ID
  10 + */
  11 + private String firmId;
  12 + /**
  13 + * 产品ID
  14 + */
  15 + private String productId;
  16 + /**
  17 + * 设备SN
  18 + */
  19 + private String sn;
  20 + /**
  21 + * 打印份数
  22 + */
  23 + private String num;
  24 + /**
  25 + * 消息内容
  26 + */
  27 + private CloudMessContent mess;
  28 + /**
  29 + * 消息ID
  30 + */
  31 + private String messIndex;
  32 + /**
  33 + * 签名
  34 + */
  35 + private String sign;
  36 +
  37 + public String getFirmId() {
  38 + return firmId;
  39 + }
  40 +
  41 + public void setFirmId(String firmId) {
  42 + this.firmId = firmId;
  43 + }
  44 +
  45 + public String getProductId() {
  46 + return productId;
  47 + }
  48 +
  49 + public void setProductId(String productId) {
  50 + this.productId = productId;
  51 + }
  52 +
  53 + public String getSn() {
  54 + return sn;
  55 + }
  56 +
  57 + public void setSn(String sn) {
  58 + this.sn = sn;
  59 + }
  60 +
  61 + public String getNum() {
  62 + return num;
  63 + }
  64 +
  65 + public void setNum(String num) {
  66 + this.num = num;
  67 + }
  68 +
  69 + public CloudMessContent getMess() {
  70 + return mess;
  71 + }
  72 +
  73 + public void setMess(CloudMessContent mess) {
  74 + this.mess = mess;
  75 + }
  76 +
  77 + public String getMessIndex() {
  78 + return messIndex;
  79 + }
  80 +
  81 + public void setMessIndex(String messIndex) {
  82 + this.messIndex = messIndex;
  83 + }
  84 +
  85 + public String getSign() {
  86 + return sign;
  87 + }
  88 +
  89 + public void setSign(String sign) {
  90 + this.sign = sign;
  91 + }
  92 +}
  93 +
... ...
mqtt-core/src/main/java/com/diligrp/mqtt/core/model/ReceiveRelyRecord.java 0 → 100644
  1 +package com.diligrp.mqtt.core.model;
  2 +
  3 +import lombok.Data;
  4 +import org.springframework.data.annotation.Id;
  5 +import org.springframework.data.mongodb.core.mapping.Document;
  6 +
  7 +
  8 +/**
  9 + * 打印信息记录
  10 + *
  11 + * @author lvqi
  12 + */
  13 +@Document("receive_reply_record")
  14 +@Data
  15 +public class ReceiveRelyRecord {
  16 + @Id
  17 + private String id;
  18 +
  19 + private String firm;
  20 +
  21 + private String sn;
  22 + /**
  23 + * 消息ID
  24 + */
  25 + private String messIndex;
  26 +
  27 + private String message;
  28 +
  29 + /**
  30 + * 对业务方的回执信息状态
  31 + */
  32 + private Integer messStatus;
  33 +
  34 + /**
  35 + * 客户端回执状态
  36 + */
  37 + private String replyStatus;
  38 +
  39 +}
... ...
mqtt-core/src/main/java/com/diligrp/mqtt/core/model/SendModel.java
... ... @@ -36,6 +36,8 @@ public class SendModel {
36 36 */
37 37 private String charsetType;
38 38  
  39 + private Map<String, Object> params;
  40 +
39 41 public static SendModel withDefault() {
40 42 var model = new SendModel();
41 43 model.setQos(1);
... ...
mqtt-core/src/main/java/com/diligrp/mqtt/core/type/CloudPrintReplyStatusEnum.java 0 → 100644
  1 +package com.diligrp.mqtt.core.type;
  2 +
  3 +import lombok.Getter;
  4 +
  5 +/**
  6 + * @author lvqi
  7 + */
  8 +@Getter
  9 +public enum CloudPrintReplyStatusEnum {
  10 +
  11 + DATA_FORMAT_ERROR("01", "数据格式错误"),
  12 + DUPLICATE_ORDER("02", "重复订单"),
  13 + PRINTER_OUT_OF_PAPER("03", "打印机缺纸 过热"),
  14 + PRINT_SUCCESS("00", "打印正常");
  15 +
  16 + private final String code;
  17 + private final String message;
  18 +
  19 + CloudPrintReplyStatusEnum(String code, String message) {
  20 + this.code = code;
  21 + this.message = message;
  22 +
  23 + }
  24 +}
... ...
mqtt-core/src/main/java/com/diligrp/mqtt/core/type/FirmEnum.java 0 → 100644
  1 +package com.diligrp.mqtt.core.type;
  2 +
  3 +import lombok.Getter;
  4 +
  5 +/**
  6 + * @author lvqi
  7 + */
  8 +@Getter
  9 +public enum FirmEnum {
  10 + CLOUD("cloud", "云打印");
  11 +
  12 + private final String code;
  13 + private final String name;
  14 +
  15 + FirmEnum(String code, String name) {
  16 + this.code = code;
  17 + this.name = name;
  18 + }
  19 +
  20 +
  21 +
  22 +}
... ...
mqtt-core/src/main/java/com/diligrp/mqtt/core/type/MessStatusEnum.java 0 → 100644
  1 +package com.diligrp.mqtt.core.type;
  2 +
  3 +import lombok.Getter;
  4 +
  5 +/**
  6 + * @author lvqi
  7 + */
  8 +@Getter
  9 +public enum MessStatusEnum {
  10 + SUCCESS(1, "发送服务器成功"),
  11 + FAIL(2, "发送服务器失败"),
  12 + COMMAND_FAIL(3, "构建打印命令失败"),
  13 + SIGN_FAIL(4, "验签失败"),
  14 + FIRM_NOT_EXIST(5, "机构不存在");
  15 +
  16 + MessStatusEnum(Integer code, String message) {
  17 + this.code = code;
  18 + this.message = message;
  19 + }
  20 +
  21 + private final Integer code;
  22 + private final String message;
  23 +
  24 +
  25 +}
... ...
mqtt-core/src/main/java/com/diligrp/mqtt/core/util/BuildCloudPrintCommand.java 0 → 100644
  1 +package com.diligrp.mqtt.core.util;
  2 +
  3 +import com.diligrp.mqtt.core.model.CloudColumn;
  4 +import com.diligrp.mqtt.core.model.CloudMessPCPart;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +import org.springframework.util.CollectionUtils;
  8 +
  9 +import java.io.ByteArrayOutputStream;
  10 +import java.util.List;
  11 +
  12 +/**
  13 + * 构建云打印命令
  14 + *
  15 + * @author lvqi
  16 + */
  17 +public class BuildCloudPrintCommand {
  18 +
  19 + private static final Logger log = LoggerFactory.getLogger(BuildCloudPrintCommand.class);
  20 + private static final String ON = "1";
  21 +
  22 + /**
  23 + * 对齐方式
  24 + */
  25 + private static byte[] alignment(String align) {
  26 + return switch (align) {
  27 + case "1" -> ESCPOSCommand.ALIGN_CENTER;
  28 + case "2" -> ESCPOSCommand.ALIGN_RIGHT;
  29 + default -> ESCPOSCommand.ALIGN_LEFT;
  30 + };
  31 + }
  32 +
  33 + /**
  34 + * 粗体
  35 + */
  36 + private static byte[] emphasizedSetting(String emphasized) {
  37 + if (ON.equals(emphasized)) {
  38 + return new byte[]{ESCPOSCommand.ESC, 0x20, (byte) 1};
  39 + } else {
  40 + return new byte[]{ESCPOSCommand.ESC, 0x20, (byte) 0};
  41 + }
  42 + }
  43 +
  44 + /**
  45 + * 下划线
  46 + */
  47 + private static byte[] underline(String underline) {
  48 + if (ON.equals(underline)) {
  49 + return ESCPOSCommand.UNDERLINE_1;
  50 + } else if ("2".equals(underline)) {
  51 + return ESCPOSCommand.UNDERLINE_2;
  52 + } else {
  53 + return ESCPOSCommand.UNDERLINE_OFF;
  54 + }
  55 +
  56 + }
  57 +
  58 + /**
  59 + * 设置字体大小
  60 + */
  61 + private static byte[] fontSizeByHeightDots(int heightDots) {
  62 + int baseHeight = 24;
  63 + int scale = Math.round((float) heightDots / baseHeight);
  64 +
  65 + scale = Math.max(1, Math.min(scale, 8));
  66 +
  67 + byte n = (byte) (((scale - 1) << 4) | (scale - 1));
  68 + return new byte[]{ESCPOSCommand.GS, 0x21, n};
  69 + }
  70 +
  71 + /**
  72 + * 设置字符间距(单位:dot)
  73 + * n: 0~255
  74 + * ESC SP n
  75 + * 字松一点
  76 + */
  77 + private static byte[] charSpacing(int n) {
  78 + return new byte[]{ESCPOSCommand.ESC, 0x20, (byte) n};
  79 + }
  80 +
  81 + /**
  82 + * 按点走纸(ESC J n)
  83 + * n: 0~255
  84 + * 1 dot ≈ 0.125 mm
  85 + * 8 dots = 1 mm
  86 + */
  87 + private static byte[] feedDots(int n) {
  88 + return new byte[]{ESCPOSCommand.ESC, 0x4A, (byte) n};
  89 + }
  90 +
  91 + /**
  92 + * 列样式重置
  93 + */
  94 + private static byte[] resetColumnStyle() {
  95 + return new byte[]{
  96 + ESCPOSCommand.ESC, 0x61, 0x00,
  97 + ESCPOSCommand.ESC, 0x45, 0x00,
  98 + ESCPOSCommand.GS, 0x21, 0x00,
  99 + ESCPOSCommand.ESC, 0x2D, 0x00
  100 + };
  101 + }
  102 +
  103 + /**
  104 + * 行样式重置
  105 + */
  106 + private static byte[] resetLineStyle() {
  107 + return new byte[]{
  108 + ESCPOSCommand.ESC, 0x20, 0x00,
  109 + ESCPOSCommand.ESC, 0x4A, 0x00,
  110 + };
  111 + }
  112 +
  113 + public static byte[] buildCommand(List<CloudMessPCPart> pc) throws Exception {
  114 + if (!CollectionUtils.isEmpty(pc)) {
  115 + ByteArrayOutputStream out = new ByteArrayOutputStream();
  116 + out.write(ESCPOSCommand.INIT);
  117 + for (CloudMessPCPart part : pc) {
  118 + String tp = part.getTp();
  119 + // 行距
  120 + String ls = part.getLs();
  121 + String ws = part.getWs();
  122 + // 文本行
  123 + if ("1".equals(tp)) {
  124 + List<CloudColumn> cols = part.getCols();
  125 + for (CloudColumn column : cols) {
  126 + String cv = column.getCv();
  127 + String al = column.getAl();
  128 + String fs = column.getFs();
  129 + String tu = column.getTu();
  130 + String tb = column.getTb();
  131 + if (cv == null) {
  132 + continue;
  133 + }
  134 + // ===== 对齐 =====
  135 + out.write(alignment(al));
  136 + // ===== 字体大小 =====
  137 + if (fs != null) {
  138 + out.write(fontSizeByHeightDots(Integer.parseInt(fs)));
  139 + }
  140 + // ===== 加粗 =====
  141 + out.write(emphasizedSetting(tb));
  142 + // ===== 字间距 =====
  143 + if (ws != null) {
  144 + out.write(charSpacing(Integer.parseInt(ws)));
  145 + }
  146 + if (tu != null) {
  147 + out.write(underline(tu));
  148 + }
  149 + out.write(cv.getBytes("GB2312"));
  150 + out.write(resetColumnStyle());
  151 + }
  152 + out.write(ESCPOSCommand.LF);
  153 + out.write(resetLineStyle());
  154 + }
  155 + // ===== 行距 =====
  156 + if (ls != null) {
  157 + out.write(feedDots(Integer.parseInt(ls)));
  158 + }
  159 + }
  160 + // 稳定点走纸
  161 + out.write(feedDots(90));
  162 + return out.toByteArray();
  163 + }
  164 + return null;
  165 + }
  166 +
  167 +
  168 +}
... ...
mqtt-core/src/main/java/com/diligrp/mqtt/core/util/ESCPOSCommand.java 0 → 100644
  1 +package com.diligrp.mqtt.core.util;
  2 +
  3 +/**
  4 + * ESCPOS命令
  5 + *
  6 + * @author lvqi
  7 + */
  8 +
  9 +public class ESCPOSCommand {
  10 + public static final byte ESC = 0x1B;
  11 + public static final byte GS = 0x1D;
  12 + public static final byte LF = 0x0A;
  13 +
  14 + // ===== 初始化 =====
  15 + public static final byte[] INIT = {ESC, 0x40};
  16 +
  17 + // ===== 对齐 =====
  18 + public static final byte[] ALIGN_LEFT = {ESC, 0x61, 0x00};
  19 + public static final byte[] ALIGN_CENTER = {ESC, 0x61, 0x01};
  20 + public static final byte[] ALIGN_RIGHT = {ESC, 0x61, 0x02};
  21 +
  22 + // ===== 下划线 =====
  23 + public static final byte[] UNDERLINE_OFF = {ESC, 0x2D, 0x00};
  24 + public static final byte[] UNDERLINE_1 = {ESC, 0x2D, 0x01};
  25 + public static final byte[] UNDERLINE_2 = {ESC, 0x2D, 0x02};
  26 +
  27 + // ===== 切纸 =====
  28 + public static final byte[] CUT_HALF = {GS, 0x56, 0x01};
  29 +}
... ...
mqtt-web/pom.xml
... ... @@ -36,6 +36,14 @@
36 36 <groupId>org.springframework.boot</groupId>
37 37 <artifactId>spring-boot-starter-data-redis</artifactId>
38 38 </dependency>
  39 + <dependency>
  40 + <groupId>com.mysql</groupId>
  41 + <artifactId>mysql-connector-j</artifactId>
  42 + </dependency>
  43 + <dependency>
  44 + <groupId>com.baomidou</groupId>
  45 + <artifactId>mybatis-plus-spring-boot3-starter</artifactId>
  46 + </dependency>
39 47 </dependencies>
40 48  
41 49 </project>
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/WebConfig.java
1 1 package com.diligrp.mqtt.web;
2 2  
  3 +import org.mybatis.spring.annotation.MapperScan;
3 4 import org.springframework.context.annotation.ComponentScan;
4 5 import org.springframework.context.annotation.Configuration;
5 6  
... ... @@ -10,5 +11,6 @@ import org.springframework.context.annotation.Configuration;
10 11 */
11 12 @Configuration
12 13 @ComponentScan(basePackages = "com.diligrp.mqtt.web")
  14 +@MapperScan("com.diligrp.mqtt.web.mapper")
13 15 public class WebConfig {
14 16 }
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/controller/PlatTenantController.java 0 → 100644
  1 +package com.diligrp.mqtt.web.controller;
  2 +
  3 +import com.diligrp.mqtt.web.model.PlatTenant;
  4 +import com.diligrp.mqtt.web.service.PlatTenantService;
  5 +import jakarta.annotation.Resource;
  6 +import org.springframework.data.domain.Page;
  7 +import org.springframework.data.domain.PageRequest;
  8 +import org.springframework.http.ResponseEntity;
  9 +import org.springframework.web.bind.annotation.*;
  10 +
  11 +
  12 +
  13 +@RestController
  14 +@RequestMapping("platTenant")
  15 +public class PlatTenantController {
  16 +
  17 + @Resource
  18 + private PlatTenantService platTenantService;
  19 +
  20 + /**
  21 + * 分页查询
  22 + *
  23 + * @param platTenant 筛选条件
  24 + * @param pageRequest 分页对象
  25 + * @return 查询结果
  26 + */
  27 + @GetMapping
  28 + public ResponseEntity<Page<PlatTenant>> queryByPage(PlatTenant platTenant, PageRequest pageRequest) {
  29 + return ResponseEntity.ok(this.platTenantService.queryByPage(platTenant, pageRequest));
  30 + }
  31 +
  32 + /**
  33 + * 通过主键查询单条数据
  34 + *
  35 + * @param id 主键
  36 + * @return 单条数据
  37 + */
  38 + @GetMapping("{id}")
  39 + public ResponseEntity<PlatTenant> queryById(@PathVariable("id") Integer id) {
  40 + return ResponseEntity.ok(this.platTenantService.queryById(id));
  41 + }
  42 +
  43 + /**
  44 + * 新增数据
  45 + *
  46 + * @param platTenant 实体
  47 + * @return 新增结果
  48 + */
  49 + @PostMapping
  50 + public ResponseEntity<PlatTenant> add(PlatTenant platTenant) {
  51 + return ResponseEntity.ok(this.platTenantService.insert(platTenant));
  52 + }
  53 +
  54 + /**
  55 + * 编辑数据
  56 + *
  57 + * @param platTenant 实体
  58 + * @return 编辑结果
  59 + */
  60 + @PutMapping
  61 + public ResponseEntity<PlatTenant> edit(PlatTenant platTenant) {
  62 + return ResponseEntity.ok(this.platTenantService.update(platTenant));
  63 + }
  64 +
  65 + /**
  66 + * 删除数据
  67 + *
  68 + * @param id 主键
  69 + * @return 删除是否成功
  70 + */
  71 + @DeleteMapping
  72 + public ResponseEntity<Boolean> deleteById(Integer id) {
  73 + return ResponseEntity.ok(this.platTenantService.deleteById(id));
  74 + }
  75 +
  76 +}
  77 +
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/controller/PrintController.java 0 → 100644
  1 +package com.diligrp.mqtt.web.controller;
  2 +
  3 +import com.diligrp.mqtt.core.model.CloudRequest;
  4 +import com.diligrp.mqtt.web.message.Message;
  5 +import com.diligrp.mqtt.web.service.PrintService;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.web.bind.annotation.*;
  8 +
  9 +
  10 +/**
  11 + * @author lvqi
  12 + */
  13 +@RestController
  14 +@RequestMapping("/print")
  15 +public class PrintController {
  16 + @Autowired
  17 + private PrintService printService;
  18 +
  19 + @PostMapping("/cloud")
  20 + public Message<?> cloudPrint(@RequestBody CloudRequest cloudRequest) {
  21 + return printService.cloudPrint(cloudRequest);
  22 + }
  23 +}
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/controller/PrintDeviceController.java 0 → 100644
  1 +package com.diligrp.mqtt.web.controller;
  2 +
  3 +import com.diligrp.mqtt.web.message.Message;
  4 +import com.diligrp.mqtt.web.service.PrintDeviceService;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.web.bind.annotation.GetMapping;
  7 +import org.springframework.web.bind.annotation.RequestMapping;
  8 +import org.springframework.web.bind.annotation.RequestParam;
  9 +import org.springframework.web.bind.annotation.RestController;
  10 +
  11 +/**
  12 + * @author lvqi
  13 + */
  14 +@RestController
  15 +@RequestMapping("/device")
  16 +public class PrintDeviceController {
  17 + @Autowired
  18 + PrintDeviceService printDeviceService;
  19 +
  20 +
  21 + @GetMapping("/info")
  22 + public Message<?> getMqttInfo(@RequestParam String sn) {
  23 + return Message.success(printDeviceService.queryBySn(sn));
  24 + }
  25 +
  26 +
  27 +}
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/dto/CloudPrinter.java 0 → 100644
  1 +package com.diligrp.mqtt.web.dto;
  2 +
  3 +/**
  4 + * 云打印
  5 + * @author lvqi
  6 + */
  7 +public class CloudPrinter {
  8 + private String rtc;
  9 + private String index;
  10 + private String tts;
  11 + private String print_esc;
  12 + private Integer print_num;
  13 +
  14 + public String getRtc() {
  15 + return rtc;
  16 + }
  17 +
  18 + public void setRtc(String rtc) {
  19 + this.rtc = rtc;
  20 + }
  21 +
  22 + public String getIndex() {
  23 + return index;
  24 + }
  25 +
  26 + public void setIndex(String index) {
  27 + this.index = index;
  28 + }
  29 +
  30 + public String getTts() {
  31 + return tts;
  32 + }
  33 +
  34 + public void setTts(String tts) {
  35 + this.tts = tts;
  36 + }
  37 +
  38 + public String getPrint_esc() {
  39 + return print_esc;
  40 + }
  41 +
  42 + public void setPrint_esc(String print_esc) {
  43 + this.print_esc = print_esc;
  44 + }
  45 +
  46 + public Integer getPrint_num() {
  47 + return print_num;
  48 + }
  49 +
  50 + public void setPrint_num(Integer print_num) {
  51 + this.print_num = print_num;
  52 + }
  53 +}
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/dto/PrintDeviceDto.java 0 → 100644
  1 +package com.diligrp.mqtt.web.dto;
  2 +
  3 +/**
  4 + * @author lvqi
  5 + */
  6 +
  7 +public class PrintDeviceDto {
  8 + private String sn;
  9 +
  10 + private String clientId;
  11 +
  12 + private String username;
  13 +
  14 + private String password;
  15 +
  16 + private String topic;
  17 +
  18 + public String getSn() {
  19 + return sn;
  20 + }
  21 +
  22 + public void setSn(String sn) {
  23 + this.sn = sn;
  24 + }
  25 +
  26 + public String getClientId() {
  27 + return clientId;
  28 + }
  29 +
  30 + public void setClientId(String clientId) {
  31 + this.clientId = clientId;
  32 + }
  33 +
  34 + public String getUsername() {
  35 + return username;
  36 + }
  37 +
  38 + public void setUsername(String username) {
  39 + this.username = username;
  40 + }
  41 +
  42 + public String getPassword() {
  43 + return password;
  44 + }
  45 +
  46 + public void setPassword(String password) {
  47 + this.password = password;
  48 + }
  49 +
  50 + public String getTopic() {
  51 + return topic;
  52 + }
  53 +
  54 + public void setTopic(String topic) {
  55 + this.topic = topic;
  56 + }
  57 +}
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/mapper/PlatTenantMapper.java 0 → 100644
  1 +package com.diligrp.mqtt.web.mapper;
  2 +
  3 +import com.diligrp.mqtt.web.model.PlatTenant;
  4 +import org.apache.ibatis.annotations.Param;
  5 +import org.springframework.data.domain.Pageable;
  6 +import java.util.List;
  7 +
  8 +public interface PlatTenantMapper {
  9 +
  10 + /**
  11 + * 通过ID查询单条数据
  12 + *
  13 + * @param id 主键
  14 + * @return 实例对象
  15 + */
  16 + PlatTenant queryById(Integer id);
  17 +
  18 + /**
  19 + * 查询指定行数据
  20 + *
  21 + * @param platTenant 查询条件
  22 + * @param pageable 分页对象
  23 + * @return 对象列表
  24 + */
  25 + List<PlatTenant> queryAllByLimit(PlatTenant platTenant, @Param("pageable") Pageable pageable);
  26 +
  27 + /**
  28 + * 统计总行数
  29 + *
  30 + * @param platTenant 查询条件
  31 + * @return 总行数
  32 + */
  33 + long count(PlatTenant platTenant);
  34 +
  35 + /**
  36 + * 新增数据
  37 + *
  38 + * @param platTenant 实例对象
  39 + * @return 影响行数
  40 + */
  41 + int insert(PlatTenant platTenant);
  42 +
  43 + /**
  44 + * 批量新增数据(MyBatis原生foreach方法)
  45 + *
  46 + * @param entities List<PlatTenant> 实例对象列表
  47 + * @return 影响行数
  48 + */
  49 + int insertBatch(@Param("entities") List<PlatTenant> entities);
  50 +
  51 + /**
  52 + * 批量新增或按主键更新数据(MyBatis原生foreach方法)
  53 + *
  54 + * @param entities List<PlatTenant> 实例对象列表
  55 + * @return 影响行数
  56 + * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
  57 + */
  58 + int insertOrUpdateBatch(@Param("entities") List<PlatTenant> entities);
  59 +
  60 + /**
  61 + * 修改数据
  62 + *
  63 + * @param platTenant 实例对象
  64 + * @return 影响行数
  65 + */
  66 + int update(PlatTenant platTenant);
  67 +
  68 + /**
  69 + * 通过主键删除数据
  70 + *
  71 + * @param id 主键
  72 + * @return 影响行数
  73 + */
  74 + int deleteById(Integer id);
  75 +
  76 +}
  77 +
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/mapper/PrintDeviceMapper.java 0 → 100644
  1 +package com.diligrp.mqtt.web.mapper;
  2 +
  3 +import com.diligrp.mqtt.web.dto.PrintDeviceDto;
  4 +import org.apache.ibatis.annotations.Mapper;
  5 +import org.apache.ibatis.annotations.Param;
  6 +
  7 +/**
  8 + * 打印设备Mapper
  9 + *
  10 + */
  11 +@Mapper
  12 +public interface PrintDeviceMapper {
  13 +
  14 + PrintDeviceDto queryBySn(@Param("sn") String sn);
  15 +
  16 +
  17 +
  18 +}
  19 +
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/model/PlatTenant.java 0 → 100644
  1 +package com.diligrp.mqtt.web.model;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import java.io.Serializable;
  6 +
  7 +@Data
  8 +public class PlatTenant implements Serializable {
  9 +
  10 + private Integer id;
  11 +
  12 + private String name;
  13 +
  14 + private String privateKey;
  15 +
  16 + private String publicKey;
  17 +
  18 +
  19 +}
  20 +
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/model/PrintDevice.java 0 → 100644
  1 +package com.diligrp.mqtt.web.model;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import java.io.Serializable;
  6 +
  7 +/**
  8 + * @author lvqi
  9 + */
  10 +@Data
  11 +public class PrintDevice implements Serializable {
  12 + private Integer id;
  13 + /**
  14 + * 厂商
  15 + */
  16 + private String firm;
  17 + /**
  18 + * 机构id
  19 + */
  20 + private Integer firmId;
  21 + /**
  22 + * 产品id
  23 + */
  24 + private Integer productId;
  25 + /**
  26 + * 设备编号
  27 + */
  28 + private String sn;
  29 +
  30 + private String clientId;
  31 +
  32 + private String username;
  33 +
  34 + private String password;
  35 +
  36 +
  37 +
  38 +}
  39 +
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/service/PlatTenantService.java 0 → 100644
  1 +package com.diligrp.mqtt.web.service;
  2 +
  3 +import com.diligrp.mqtt.web.model.PlatTenant;
  4 +import org.springframework.data.domain.Page;
  5 +import org.springframework.data.domain.PageRequest;
  6 +
  7 +
  8 +public interface PlatTenantService {
  9 +
  10 + /**
  11 + * 通过ID查询单条数据
  12 + *
  13 + * @param id 主键
  14 + * @return 实例对象
  15 + */
  16 + PlatTenant queryById(Integer id);
  17 +
  18 + /**
  19 + * 分页查询
  20 + *
  21 + * @param platTenant 筛选条件
  22 + * @param pageRequest 分页对象
  23 + * @return 查询结果
  24 + */
  25 + Page<PlatTenant> queryByPage(PlatTenant platTenant, PageRequest pageRequest);
  26 +
  27 + /**
  28 + * 新增数据
  29 + *
  30 + * @param platTenant 实例对象
  31 + * @return 实例对象
  32 + */
  33 + PlatTenant insert(PlatTenant platTenant);
  34 +
  35 + /**
  36 + * 修改数据
  37 + *
  38 + * @param platTenant 实例对象
  39 + * @return 实例对象
  40 + */
  41 + PlatTenant update(PlatTenant platTenant);
  42 +
  43 + /**
  44 + * 通过主键删除数据
  45 + *
  46 + * @param id 主键
  47 + * @return 是否成功
  48 + */
  49 + boolean deleteById(Integer id);
  50 +
  51 +}
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/service/PrintDeviceService.java 0 → 100644
  1 +package com.diligrp.mqtt.web.service;
  2 +
  3 +
  4 +import com.diligrp.mqtt.web.dto.PrintDeviceDto;
  5 +
  6 +/**
  7 + * @author lvqi
  8 + */
  9 +public interface PrintDeviceService {
  10 +
  11 +
  12 + PrintDeviceDto queryBySn(String sn);
  13 +
  14 +
  15 +}
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/service/PrintService.java 0 → 100644
  1 +package com.diligrp.mqtt.web.service;
  2 +
  3 +import com.diligrp.mqtt.web.message.Message;
  4 +import com.diligrp.mqtt.core.model.CloudRequest;
  5 +
  6 +/**
  7 + * @author lvqi
  8 + */
  9 +public interface PrintService {
  10 +
  11 + Message<?> cloudPrint(CloudRequest cloudRequest);
  12 +}
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/service/impl/PlatTenantServiceImpl.java 0 → 100644
  1 +package com.diligrp.mqtt.web.service.impl;
  2 +
  3 +import com.diligrp.mqtt.web.mapper.PlatTenantMapper;
  4 +import com.diligrp.mqtt.web.model.PlatTenant;
  5 +import com.diligrp.mqtt.web.service.PlatTenantService;
  6 +import jakarta.annotation.Resource;
  7 +import org.springframework.stereotype.Service;
  8 +import org.springframework.data.domain.Page;
  9 +import org.springframework.data.domain.PageImpl;
  10 +import org.springframework.data.domain.PageRequest;
  11 +
  12 +import java.security.KeyPair;
  13 +import java.security.KeyPairGenerator;
  14 +import java.security.PrivateKey;
  15 +import java.security.PublicKey;
  16 +import java.util.Base64;
  17 +
  18 +
  19 +@Service("platTenantService")
  20 +public class PlatTenantServiceImpl implements PlatTenantService {
  21 + @Resource
  22 + private PlatTenantMapper platTenantMapper;
  23 +
  24 + /**
  25 + * 通过ID查询单条数据
  26 + *
  27 + * @param id 主键
  28 + * @return 实例对象
  29 + */
  30 + @Override
  31 + public PlatTenant queryById(Integer id) {
  32 + return this.platTenantMapper.queryById(id);
  33 + }
  34 +
  35 + /**
  36 + * 分页查询
  37 + *
  38 + * @param platTenant 筛选条件
  39 + * @param pageRequest 分页对象
  40 + * @return 查询结果
  41 + */
  42 + @Override
  43 + public Page<PlatTenant> queryByPage(PlatTenant platTenant, PageRequest pageRequest) {
  44 + long total = this.platTenantMapper.count(platTenant);
  45 + return new PageImpl<>(this.platTenantMapper.queryAllByLimit(platTenant, pageRequest), pageRequest, total);
  46 + }
  47 +
  48 + /**
  49 + * 新增数据
  50 + *
  51 + * @param platTenant 实例对象
  52 + * @return 实例对象
  53 + */
  54 + @Override
  55 + public PlatTenant insert(PlatTenant platTenant) {
  56 + try {
  57 + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
  58 + keyPairGenerator.initialize(2048);
  59 + KeyPair keyPair = keyPairGenerator.generateKeyPair();
  60 + PrivateKey privateKey = keyPair.getPrivate();
  61 + PublicKey publicKey = keyPair.getPublic();
  62 + byte[] publicKeyEncoded = publicKey.getEncoded();
  63 + platTenant.setPublicKey(Base64.getEncoder().encodeToString(publicKeyEncoded));
  64 + byte[] privateKeyEncoded = privateKey.getEncoded();
  65 + platTenant.setPrivateKey(Base64.getEncoder().encodeToString(privateKeyEncoded));
  66 + platTenantMapper.insert(platTenant);
  67 + return platTenant;
  68 + } catch (Exception e) {
  69 + return null;
  70 + }
  71 + }
  72 +
  73 + /**
  74 + * 修改数据
  75 + *
  76 + * @param platTenant 实例对象
  77 + * @return 实例对象
  78 + */
  79 + @Override
  80 + public PlatTenant update(PlatTenant platTenant) {
  81 + this.platTenantMapper.update(platTenant);
  82 + return this.queryById(platTenant.getId());
  83 + }
  84 +
  85 + /**
  86 + * 通过主键删除数据
  87 + *
  88 + * @param id 主键
  89 + * @return 是否成功
  90 + */
  91 + @Override
  92 + public boolean deleteById(Integer id) {
  93 + return this.platTenantMapper.deleteById(id) > 0;
  94 + }
  95 +}
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/service/impl/PrintDeviceServiceImpl.java 0 → 100644
  1 +package com.diligrp.mqtt.web.service.impl;
  2 +
  3 +import com.diligrp.mqtt.web.dto.PrintDeviceDto;
  4 +import com.diligrp.mqtt.web.mapper.PrintDeviceMapper;
  5 +import com.diligrp.mqtt.web.service.PrintDeviceService;
  6 +import jakarta.annotation.Resource;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +
  10 +@Service("printDeviceService")
  11 +public class PrintDeviceServiceImpl implements PrintDeviceService {
  12 + @Resource
  13 + private PrintDeviceMapper printDeviceMapper;
  14 +
  15 + @Override
  16 + public PrintDeviceDto queryBySn(String sn) {
  17 + return printDeviceMapper.queryBySn(sn);
  18 + }
  19 +
  20 +}
... ...
mqtt-web/src/main/java/com/diligrp/mqtt/web/service/impl/PrintServiceImpl.java 0 → 100644
  1 +package com.diligrp.mqtt.web.service.impl;
  2 +
  3 +import com.diligrp.mqtt.core.model.CloudMessContent;
  4 +import com.diligrp.mqtt.core.model.CloudRequest;
  5 +import com.diligrp.mqtt.core.model.ReceiveRelyRecord;
  6 +import com.diligrp.mqtt.core.model.SendModel;
  7 +import com.diligrp.mqtt.core.service.MqttMessageService;
  8 +import com.diligrp.mqtt.core.type.CharsetType;
  9 +import com.diligrp.mqtt.core.type.MessStatusEnum;
  10 +import com.diligrp.mqtt.core.type.SendEventType;
  11 +import com.diligrp.mqtt.core.util.BuildCloudPrintCommand;
  12 +import com.diligrp.mqtt.core.util.JsonUtils;
  13 +import com.diligrp.mqtt.web.dto.CloudPrinter;
  14 +import com.diligrp.mqtt.web.dto.PrintDeviceDto;
  15 +import com.diligrp.mqtt.web.mapper.PlatTenantMapper;
  16 +import com.diligrp.mqtt.web.mapper.PrintDeviceMapper;
  17 +import com.diligrp.mqtt.web.message.Message;
  18 +import com.diligrp.mqtt.web.model.PlatTenant;
  19 +import com.diligrp.mqtt.web.service.PrintService;
  20 +import com.fasterxml.jackson.core.type.TypeReference;
  21 +import org.slf4j.Logger;
  22 +import org.slf4j.LoggerFactory;
  23 +import org.springframework.beans.factory.annotation.Autowired;
  24 +import org.springframework.data.mongodb.core.MongoTemplate;
  25 +import org.springframework.stereotype.Service;
  26 +import org.springframework.util.ObjectUtils;
  27 +
  28 +import java.nio.charset.StandardCharsets;
  29 +import java.security.KeyFactory;
  30 +import java.security.Signature;
  31 +import java.security.spec.PKCS8EncodedKeySpec;
  32 +import java.util.*;
  33 +
  34 +/**
  35 + * @author lvqi
  36 + */
  37 +@Service
  38 +public class PrintServiceImpl implements PrintService {
  39 + private static final Logger log = LoggerFactory.getLogger(PrintServiceImpl.class);
  40 + @Autowired
  41 + private PlatTenantMapper platTenantMapper;
  42 + @Autowired
  43 + private PrintDeviceMapper printDeviceMapper;
  44 + @Autowired
  45 + private MongoTemplate mongoTemplate;
  46 + @Autowired
  47 + private MqttMessageService mqttMessageService;
  48 +
  49 + @Override
  50 + public Message<?> cloudPrint(CloudRequest cloudRequest) {
  51 + PlatTenant platTenant = platTenantMapper.queryById(Integer.valueOf(cloudRequest.getFirmId()));
  52 + PrintDeviceDto printDevice = printDeviceMapper.queryBySn(cloudRequest.getSn());
  53 + Integer messStatus = MessStatusEnum.SUCCESS.getCode();
  54 + try {
  55 + if (!ObjectUtils.isEmpty(platTenant)) {
  56 + // 验签
  57 + String sign = cloudRequest.getSign();
  58 + Map<String, Object> paramsMap = new HashMap<>();
  59 + paramsMap.put("firmId", cloudRequest.getFirmId());
  60 + paramsMap.put("productId", cloudRequest.getProductId());
  61 + paramsMap.put("sn", cloudRequest.getSn());
  62 + paramsMap.put("num", cloudRequest.getNum());
  63 + paramsMap.put("mess", cloudRequest.getMess());
  64 + paramsMap.put("messIndex", cloudRequest.getMessIndex());
  65 + paramsMap.put("sign", "");
  66 + String handleStr = handleStr(paramsMap);
  67 + if (verifySign(handleStr, sign, platTenant.getPublicKey())) {
  68 + SendModel sendModel = SendModel.withDefault();
  69 + CloudPrinter cloudPrinter = new CloudPrinter();
  70 + cloudPrinter.setIndex(cloudRequest.getMessIndex());
  71 + cloudPrinter.setPrint_num(Integer.valueOf(cloudRequest.getNum()));
  72 + CloudMessContent mess = cloudRequest.getMess();
  73 + try {
  74 + byte[] bytes = BuildCloudPrintCommand.buildCommand(mess.getPc());
  75 + cloudPrinter.setPrint_esc(Base64.getEncoder().encodeToString(bytes));
  76 + } catch (Exception e) {
  77 + messStatus = MessStatusEnum.COMMAND_FAIL.getCode();
  78 + log.error("构建打印命令失败", e);
  79 + }
  80 + // 语音播报
  81 + cloudPrinter.setTts(mess.getSc());
  82 + cloudPrinter.setRtc(cloudRequest.getFirmId());
  83 + sendModel.setTopic(printDevice.getTopic());
  84 + Map<String, Object> dataMap = JsonUtils.convertValue(cloudPrinter, new TypeReference<>() {
  85 + });
  86 + sendModel.setPayload(dataMap);
  87 + sendModel.setSendEventType(SendEventType.PRINTER.value);
  88 + sendModel.setCharsetType(CharsetType.GBK.code);
  89 + Map<String, Object> requestMap = JsonUtils.convertValue(cloudRequest, new TypeReference<>() {
  90 + });
  91 + sendModel.setParams(requestMap);
  92 + mqttMessageService.sendMessage(sendModel);
  93 + return Message.success("success");
  94 + } else {
  95 + messStatus = MessStatusEnum.SIGN_FAIL.getCode();
  96 + return Message.failure(1001, "验签失败");
  97 + }
  98 + }
  99 + messStatus = MessStatusEnum.FIRM_NOT_EXIST.getCode();
  100 + return Message.failure(1002, "租户不存在");
  101 + } finally {
  102 + ReceiveRelyRecord receiveRelyRecord = new ReceiveRelyRecord();
  103 + receiveRelyRecord.setId(cloudRequest.getMessIndex() + cloudRequest.getSn());
  104 + receiveRelyRecord.setFirm(cloudRequest.getFirmId());
  105 + receiveRelyRecord.setSn(cloudRequest.getSn());
  106 + receiveRelyRecord.setMessIndex(cloudRequest.getMessIndex());
  107 + receiveRelyRecord.setMessage(JsonUtils.toJsonString(cloudRequest));
  108 + receiveRelyRecord.setMessStatus(messStatus);
  109 + mongoTemplate.save(receiveRelyRecord);
  110 + }
  111 + }
  112 +
  113 + public static String handleStr(Map<String, Object> paramsMap) {
  114 + //转成map
  115 + //获取参数名称转成List集合
  116 + Set<String> keySet = paramsMap.keySet();
  117 + List<String> paramNames = new ArrayList<>(keySet);
  118 + //对参数名称进行排序
  119 + Collections.sort(paramNames);
  120 + //把参数转化成url键值对格式并返回
  121 + StringBuilder paramNameValue = new StringBuilder();
  122 + for (String paramName : paramNames) {
  123 + //剔除sign字段和值为空的字段,这些字段不参与签名
  124 + if (!"sign".equals(paramName) || !ObjectUtils.isEmpty(paramsMap.get(paramName))) {
  125 + paramNameValue.append(paramName).append("=").append(paramsMap.get(paramName)).append("&");
  126 + }
  127 + }
  128 + paramNameValue.deleteCharAt(paramNameValue.length() - 1);
  129 + return paramNameValue.toString();
  130 + }
  131 +
  132 + public static boolean verifySign(String content, String signatureValue, String publicKey) {
  133 + try {
  134 + byte[] keyBytes = Base64.getDecoder().decode(publicKey);
  135 + PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(keyBytes);
  136 + KeyFactory keyFactory = KeyFactory.getInstance("RSA");
  137 + java.security.PublicKey pubKey = keyFactory.generatePublic(pkcs8EncodedKeySpec);
  138 +
  139 + // 使用MD5WithRSA的验签方式
  140 + Signature signature = Signature.getInstance("MD5WithRSA");
  141 + signature.initVerify(pubKey);
  142 +
  143 + // 更新待验证的内容
  144 + signature.update(content.getBytes(StandardCharsets.UTF_8));
  145 +
  146 + // 验证签名
  147 + byte[] signatureBytes = Base64.getDecoder().decode(signatureValue);
  148 + return signature.verify(signatureBytes);
  149 + } catch (Exception e) {
  150 + log.error("验签失败", e);
  151 + return false;
  152 + }
  153 + }
  154 +}
... ...
mqtt-web/src/main/resources/mapper/PlatTenantMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="com.diligrp.mqtt.web.mapper.PlatTenantMapper">
  4 +
  5 + <resultMap type="com.diligrp.mqtt.web.model.PlatTenant" id="PlatTenantMap">
  6 + <result property="id" column="id" jdbcType="INTEGER"/>
  7 + <result property="name" column="name" jdbcType="VARCHAR"/>
  8 + <result property="privateKey" column="private_key" jdbcType="VARCHAR"/>
  9 + </resultMap>
  10 +
  11 + <!--查询单个-->
  12 + <select id="queryById" resultMap="PlatTenantMap">
  13 + select id,
  14 + name,
  15 + private_key,
  16 + public_key
  17 + from plat_tenant
  18 + where id = #{id}
  19 + </select>
  20 +
  21 + <!--查询指定行数据-->
  22 + <select id="queryAllByLimit" resultMap="PlatTenantMap">
  23 + select
  24 + id, name, private_key
  25 + from plat_tenant
  26 + <where>
  27 + <if test="id != null">
  28 + and id = #{id}
  29 + </if>
  30 + <if test="name != null and name != ''">
  31 + and name = #{name}
  32 + </if>
  33 + <if test="privateKey != null and privateKey != ''">
  34 + and private_key = #{privateKey}
  35 + </if>
  36 + <if test="publicKey != null and publicKey != ''">
  37 + and public_key = #{publicKey}
  38 + </if>
  39 + </where>
  40 + limit #{pageable.offset}, #{pageable.pageSize}
  41 + </select>
  42 +
  43 + <!--统计总行数-->
  44 + <select id="count" resultType="java.lang.Long">
  45 + select count(1)
  46 + from plat_tenant
  47 + <where>
  48 + <if test="id != null">
  49 + and id = #{id}
  50 + </if>
  51 + <if test="name != null and name != ''">
  52 + and name = #{name}
  53 + </if>
  54 + <if test="privateKey != null and privateKey != ''">
  55 + and private_key = #{privateKey}
  56 + </if>
  57 + <if test="publicKey != null and publicKey != ''">
  58 + and public_key = #{publicKey}
  59 + </if>
  60 + </where>
  61 + </select>
  62 +
  63 + <!--新增所有列-->
  64 + <insert id="insert" keyProperty="id" useGeneratedKeys="true">
  65 + insert into plat_tenant(name, private_key, public_key)
  66 + values (#{name}, #{privateKey}, #{publicKey})
  67 + </insert>
  68 +
  69 + <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
  70 + insert into plat_tenant(name, private_key, public_key)
  71 + values
  72 + <foreach collection="entities" item="entity" separator=",">
  73 + (#{entity.name}, #{entity.privateKey}, #{entity.publicKey})
  74 + </foreach>
  75 + </insert>
  76 +
  77 + <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
  78 + insert into plat_tenant(name, private_key, public_key)
  79 + values
  80 + <foreach collection="entities" item="entity" separator=",">
  81 + (#{entity.name}, #{entity.privateKey}, #{entity.publicKey})
  82 + </foreach>
  83 + on duplicate key update
  84 + name = values(name),
  85 + private_key = values(private_key),
  86 + public_key = values(public_key)
  87 + </insert>
  88 +
  89 + <!--通过主键修改数据-->
  90 + <update id="update">
  91 + update plat_tenant
  92 + <set>
  93 + <if test="name != null and name != ''">
  94 + name = #{name},
  95 + </if>
  96 + <if test="privateKey != null and privateKey != ''">
  97 + private_key = #{privateKey},
  98 + </if>
  99 + <if test="publicKey != null and publicKey != ''">
  100 + public_key = #{publicKey},
  101 + </if>
  102 + </set>
  103 + where id = #{id}
  104 + </update>
  105 +
  106 + <!--通过主键删除-->
  107 + <delete id="deleteById">
  108 + delete from plat_tenant where id = #{id}
  109 + </delete>
  110 +
  111 +</mapper>
  112 +
... ...
mqtt-web/src/main/resources/mapper/PrintDeviceMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="com.diligrp.mqtt.web.mapper.PrintDeviceMapper">
  4 +
  5 +
  6 + <select id="queryBySn" resultType="com.diligrp.mqtt.web.dto.PrintDeviceDto"
  7 + parameterType="java.lang.String">
  8 + select firm_id, product_id, sn, client_id, username, password, CONCAT(firm_id, product_id, sn,'/notify') as topic
  9 + from print_device
  10 + where sn = #{sn}
  11 + </select>
  12 +</mapper>
  13 +
... ...