From 1576a9417b8f20d84af99bc142208bd9fbe2d404 Mon Sep 17 00:00:00 2001 From: tangzh Date: Mon, 26 May 2025 22:39:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eladmin-web/package.json | 2 +- .../src/api/bus/busDevice/busDevice.js | 48 ++++ .../bus/busDeviceCommand/busDeviceCommand.js | 27 ++ eladmin-web/src/api/bus/busUser/busUser.js | 42 +++ .../src/components/Crud/UD.operation.vue | 4 +- .../src/components/Echarts/PieChart.vue | 2 +- eladmin-web/src/views/bus/busDevice/index.vue | 178 +++++++++++++ .../src/views/bus/busDeviceCommand/index.vue | 133 ++++++++++ eladmin-web/src/views/bus/busUser/index.vue | 244 ++++++++++++++++++ .../src/views/dashboard/PanelGroup.vue | 2 +- eladmin/eladmin-common/pom.xml | 17 ++ .../java/me/zhengjie/utils/CRC32Utils.java | 28 ++ .../main/java/me/zhengjie/utils/CacheKey.java | 5 + .../main/java/me/zhengjie/utils/FileUtil.java | 10 +- .../java/me/zhengjie/utils/QrCodeUtil.java | 82 ++++++ .../modules/front/rest/DeviceController.java | 43 +++ .../modules/front/service/WeChatService.java | 2 + .../front/service/impl/WeChatServiceImpl.java | 21 +- .../security/config/WebSocketConfig.java | 46 ++++ .../handler/DeviceWebSocketHandler.java | 77 ++++++ .../handler/ThirdPartyWebSocketClient.java | 148 +++++++++++ .../modules/system/domain/BusDevice.java | 95 +++++++ .../system/domain/BusDeviceCommand.java | 77 ++++++ .../modules/system/domain/BusUser.java | 8 + .../modules/system/domain/BusUserCommand.java | 71 +++++ .../modules/system/domain/BusUserDevice.java | 75 ++++++ .../domain/dto/BusCommandQueryCriteria.java | 33 +++ .../domain/dto/BusDeviceQueryCriteria.java | 34 +++ .../modules/system/domain/dto/BusTreeVo.java | 58 +++++ .../domain/dto/BusUserQueryCriteria.java | 4 +- .../modules/system/domain/enums/MsgType.java | 31 +++ .../system/mapper/BusCommandMapper.java | 42 +++ .../system/mapper/BusDeviceMapper.java | 41 +++ .../system/mapper/BusUserCommandMapper.java | 35 +++ .../system/mapper/BusUserDeviceMapper.java | 35 +++ .../modules/system/mapper/BusUserMapper.java | 2 + .../system/rest/BusCommandController.java | 82 ++++++ .../system/rest/BusDeviceController.java | 132 ++++++++++ .../rest/BusDeviceSocketController.java | 31 +++ .../system/rest/BusUserController.java | 49 ++-- .../system/service/BusCommandService.java | 65 +++++ .../system/service/BusDeviceService.java | 73 ++++++ .../system/service/BusUserDeviceService.java | 31 +++ .../system/service/BusUserService.java | 9 +- .../service/impl/BusCommandServiceImpl.java | 73 ++++++ .../service/impl/BusDeviceServiceImpl.java | 112 ++++++++ .../impl/BusUserDeviceServiceImpl.java | 73 ++++++ .../service/impl/BusUserServiceImpl.java | 8 + .../system/service/socket/DeviceService.java | 37 +++ .../main/resources/config/application-dev.yml | 9 +- .../mapper/system/BusCommandMapper.xml | 34 +++ .../mapper/system/BusDeviceMapper.xml | 45 ++++ .../mapper/system/BusUserCommandMapper.xml | 35 +++ .../mapper/system/BusUserDeviceMapper.xml | 35 +++ .../resources/mapper/system/BusUserMapper.xml | 9 + .../mapper/system/DashboardMapper.xml | 16 +- eladmin/pom.xml | 2 +- 57 files changed, 2710 insertions(+), 52 deletions(-) create mode 100644 eladmin-web/src/api/bus/busDevice/busDevice.js create mode 100644 eladmin-web/src/api/bus/busDeviceCommand/busDeviceCommand.js create mode 100644 eladmin-web/src/api/bus/busUser/busUser.js create mode 100644 eladmin-web/src/views/bus/busDevice/index.vue create mode 100644 eladmin-web/src/views/bus/busDeviceCommand/index.vue create mode 100644 eladmin-web/src/views/bus/busUser/index.vue create mode 100644 eladmin/eladmin-common/src/main/java/me/zhengjie/utils/CRC32Utils.java create mode 100644 eladmin/eladmin-common/src/main/java/me/zhengjie/utils/QrCodeUtil.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/front/rest/DeviceController.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/WebSocketConfig.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/handler/DeviceWebSocketHandler.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/handler/ThirdPartyWebSocketClient.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusDevice.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusDeviceCommand.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusUserCommand.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusUserDevice.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusCommandQueryCriteria.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusDeviceQueryCriteria.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusTreeVo.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/enums/MsgType.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusCommandMapper.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusDeviceMapper.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusUserCommandMapper.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusUserDeviceMapper.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusCommandController.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusDeviceController.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusDeviceSocketController.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusCommandService.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusDeviceService.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusUserDeviceService.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusCommandServiceImpl.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusDeviceServiceImpl.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusUserDeviceServiceImpl.java create mode 100644 eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/socket/DeviceService.java create mode 100644 eladmin/eladmin-system/src/main/resources/mapper/system/BusCommandMapper.xml create mode 100644 eladmin/eladmin-system/src/main/resources/mapper/system/BusDeviceMapper.xml create mode 100644 eladmin/eladmin-system/src/main/resources/mapper/system/BusUserCommandMapper.xml create mode 100644 eladmin/eladmin-system/src/main/resources/mapper/system/BusUserDeviceMapper.xml diff --git a/eladmin-web/package.json b/eladmin-web/package.json index 91a56b6..b603f94 100644 --- a/eladmin-web/package.json +++ b/eladmin-web/package.json @@ -5,7 +5,7 @@ "author": "Zheng Jie", "license": "Apache-2.0", "scripts": { - "dev": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve", + "dev": "vue-cli-service serve", "build:prod": "vue-cli-service build", "build:stage": "vue-cli-service build --mode staging", "preview": "node build/index.js --preview", diff --git a/eladmin-web/src/api/bus/busDevice/busDevice.js b/eladmin-web/src/api/bus/busDevice/busDevice.js new file mode 100644 index 0000000..6e03560 --- /dev/null +++ b/eladmin-web/src/api/bus/busDevice/busDevice.js @@ -0,0 +1,48 @@ +import request from '@/utils/request' + +export function add(data) { + return request({ + url: 'api/busDevice', + method: 'post', + data + }) +} + +export function del(ids) { + return request({ + url: 'api/busDevice/', + method: 'delete', + data: ids + }) +} + +export function edit(data) { + return request({ + url: 'api/busDevice', + method: 'put', + data + }) +} + +export function getQrCode(id) { + return request({ + url: 'api/busDevice/getQrCode?id=' + id, + method: 'get' + }) +} + +export function getDeviceTree(pid) { + return request({ + url: 'api/busDevice/getDeviceTree?pid=' + pid, + method: 'get' + }) +} + +export function getChild(id) { + return request({ + url: 'api/busDevice/child?id=' + id, + method: 'get' + }) +} + +export default { add, edit, del, getDeviceTree } diff --git a/eladmin-web/src/api/bus/busDeviceCommand/busDeviceCommand.js b/eladmin-web/src/api/bus/busDeviceCommand/busDeviceCommand.js new file mode 100644 index 0000000..b716e4f --- /dev/null +++ b/eladmin-web/src/api/bus/busDeviceCommand/busDeviceCommand.js @@ -0,0 +1,27 @@ +import request from '@/utils/request' + +export function add(data) { + return request({ + url: 'api/busDeviceCommand', + method: 'post', + data + }) +} + +export function del(ids) { + return request({ + url: 'api/busDeviceCommand/', + method: 'delete', + data: ids + }) +} + +export function edit(data) { + return request({ + url: 'api/busDeviceCommand', + method: 'put', + data + }) +} + +export default { add, edit, del } diff --git a/eladmin-web/src/api/bus/busUser/busUser.js b/eladmin-web/src/api/bus/busUser/busUser.js new file mode 100644 index 0000000..1a01a60 --- /dev/null +++ b/eladmin-web/src/api/bus/busUser/busUser.js @@ -0,0 +1,42 @@ +import request from '@/utils/request' + +export function add(data) { + return request({ + url: 'api/busUser', + method: 'post', + data + }) +} + +export function del(ids) { + return request({ + url: 'api/busUser/', + method: 'delete', + data: ids + }) +} + +export function edit(data) { + return request({ + url: 'api/busUser', + method: 'put', + data + }) +} + +export function updUserCommands(data) { + return request({ + url: 'api/busUser/updUserCommands', + method: 'put', + data + }) +} + +export function get(id) { + return request({ + url: 'api/busUser/' + id, + method: 'get' + }) +} + +export default { add, edit, del, get } diff --git a/eladmin-web/src/components/Crud/UD.operation.vue b/eladmin-web/src/components/Crud/UD.operation.vue index 87623e7..eeba427 100644 --- a/eladmin-web/src/components/Crud/UD.operation.vue +++ b/eladmin-web/src/components/Crud/UD.operation.vue @@ -1,13 +1,13 @@ diff --git a/eladmin-web/src/components/Echarts/PieChart.vue b/eladmin-web/src/components/Echarts/PieChart.vue index 8c92337..644f658 100644 --- a/eladmin-web/src/components/Echarts/PieChart.vue +++ b/eladmin-web/src/components/Echarts/PieChart.vue @@ -77,7 +77,7 @@ export default { calculable: true, series: [ { - name: '案件类型统计', + name: '设备指令统计', type: 'pie', roseType: 'radius', radius: [15, 95], diff --git a/eladmin-web/src/views/bus/busDevice/index.vue b/eladmin-web/src/views/bus/busDevice/index.vue new file mode 100644 index 0000000..9bbbdfb --- /dev/null +++ b/eladmin-web/src/views/bus/busDevice/index.vue @@ -0,0 +1,178 @@ + + + + + diff --git a/eladmin-web/src/views/bus/busDeviceCommand/index.vue b/eladmin-web/src/views/bus/busDeviceCommand/index.vue new file mode 100644 index 0000000..a2cb1a5 --- /dev/null +++ b/eladmin-web/src/views/bus/busDeviceCommand/index.vue @@ -0,0 +1,133 @@ + + + + + diff --git a/eladmin-web/src/views/bus/busUser/index.vue b/eladmin-web/src/views/bus/busUser/index.vue new file mode 100644 index 0000000..9b57515 --- /dev/null +++ b/eladmin-web/src/views/bus/busUser/index.vue @@ -0,0 +1,244 @@ + + + + + diff --git a/eladmin-web/src/views/dashboard/PanelGroup.vue b/eladmin-web/src/views/dashboard/PanelGroup.vue index 1e955e3..a68670c 100644 --- a/eladmin-web/src/views/dashboard/PanelGroup.vue +++ b/eladmin-web/src/views/dashboard/PanelGroup.vue @@ -46,7 +46,7 @@
- 执法数据 + 指令数据
diff --git a/eladmin/eladmin-common/pom.xml b/eladmin/eladmin-common/pom.xml index c97dde2..e66aba9 100644 --- a/eladmin/eladmin-common/pom.xml +++ b/eladmin/eladmin-common/pom.xml @@ -20,5 +20,22 @@ hutool-all ${hutool.version} + + + + org.springframework + spring-test + + + com.google.zxing + core + 3.4.1 + + + com.google.zxing + javase + 3.4.1 + + \ No newline at end of file diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/CRC32Utils.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/CRC32Utils.java new file mode 100644 index 0000000..39f0770 --- /dev/null +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/CRC32Utils.java @@ -0,0 +1,28 @@ +package me.zhengjie.utils; + +import java.util.zip.CRC32; + +public class CRC32Utils { + + public static String getUnsignedCRC32(String input) { + CRC32 crc32 = new CRC32(); + crc32.update(input.getBytes()); + int value = (int) crc32.getValue(); + // 将int转换为long以避免潜在的符号扩展问题 + int unsignedValue = value & 0xFFFFFFFF; + String hexString = formatCrcToHex(unsignedValue); + return "0x" + hexString; // 0x8abd91cc + } + + private static String formatCrcToHex(int crc) { + // 方法一:采用String.format + String format = String.format("%08x", crc); + return format.toUpperCase(); + } + + public static void main(String[] args) { + String text = "{\"Name\":\"4KL200URH300.4K\",\"MachineName\":\"3DPLUS\",\"MachineType\":\"Spade\",\"MainboardID\":\"12345678\",\"ProtocolVersion\":\"V3.0.0\",\"FirmwareVersion\":\"V1.0.0\"}"; + String crc32Value = getUnsignedCRC32(text); + System.out.println("CRC-32 (unsigned): " + crc32Value); + } +} diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java index e8fb086..0a17a5d 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java @@ -63,4 +63,9 @@ public interface CacheKey { * 数据字典 */ String DICT_NAME = "dict::name:"; + + /** + * 二维码 + */ + String QR_CODE = "qrCode:"; } diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java index 77500d6..d4fa138 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java @@ -75,11 +75,11 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { */ private static final DecimalFormat DF = new DecimalFormat("0.00"); - public static final String IMAGE = "图片"; - public static final String TXT = "文档"; - public static final String MUSIC = "音乐"; - public static final String VIDEO = "视频"; - public static final String OTHER = "其他"; + public static final String IMAGE = "image"; + public static final String TXT = "txt"; + public static final String MUSIC = "music"; + public static final String VIDEO = "video"; + public static final String OTHER = "others"; /** diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/QrCodeUtil.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/QrCodeUtil.java new file mode 100644 index 0000000..09a1b3c --- /dev/null +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/QrCodeUtil.java @@ -0,0 +1,82 @@ +package me.zhengjie.utils; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.stereotype.Component; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.WriterException; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; +import org.springframework.web.multipart.MultipartFile; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.util.HashMap; +import java.util.Map; + +@Slf4j +@Component +public class QrCodeUtil { + + //CODE_WIDTH:二维码宽度,单位像素 + private static final int CODE_WIDTH = 400; + //CODE_HEIGHT:二维码高度,单位像素 + private static final int CODE_HEIGHT = 400; + //FRONT_COLOR:二维码前景色,0x000000 表示黑色 + private static final int FRONT_COLOR = 0x000000; + //BACKGROUND_COLOR:二维码背景色,0xFFFFFF 表示白色 + //演示用 16 进制表示,和前端页面 CSS 的取色是一样的,注意前后景颜色应该对比明显,如常见的黑白 + private static final int BACKGROUND_COLOR = 0xFFFFFF; + //文件类型 + private static final String FILE_FORMAT = "png"; + + public MultipartFile getQrCode(String content, String orderCode) { + try { + if (StringUtils.isBlank(content)) { return null; } + content = content.trim(); + // 核心代码-生成二维码 + BufferedImage image = getBufferedImage(content); + MultipartFile multipartFile = toMultipartFile(image, orderCode); + return multipartFile; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private static MultipartFile toMultipartFile(BufferedImage image, String orderCode) throws Exception { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ImageIO.write(image, FILE_FORMAT, byteArrayOutputStream); + byte[] byteArray = byteArrayOutputStream.toByteArray(); + // 使用MockMultipartFile来创建MultipartFile + return new MockMultipartFile(orderCode, orderCode + "." + FILE_FORMAT , "image/png", byteArray); + } + + //核心代码-生成二维码 + private static BufferedImage getBufferedImage(String content) throws WriterException { + //com.google.zxing.EncodeHintType:编码提示类型,枚举类型 + Map hints = new HashMap<>(); + //EncodeHintType.CHARACTER_SET:设置字符编码类型 + hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); + //EncodeHintType.ERROR_CORRECTION:设置误差校正 + //ErrorCorrectionLevel:误差校正等级,L = ~7% correction、M = ~15% correction、Q = ~25% correction、H = ~30% correction + //不设置时,默认为 L 等级,等级不一样,生成的图案不同,但扫描的结果是一样的 + hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); + //EncodeHintType.MARGIN:设置二维码边距,单位像素,值越小,二维码离四周越近 + hints.put(EncodeHintType.MARGIN, 1); + MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); + BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, CODE_WIDTH, CODE_HEIGHT, hints); + BufferedImage bufferedImage = new BufferedImage(CODE_WIDTH, CODE_HEIGHT, BufferedImage.TYPE_INT_BGR); + for (int x = 0; x < CODE_WIDTH; x++) { + for (int y = 0; y < CODE_HEIGHT; y++) { + bufferedImage.setRGB(x, y, bitMatrix.get(x, y) ? FRONT_COLOR : BACKGROUND_COLOR); + } + } + return bufferedImage; + } + +} diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/front/rest/DeviceController.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/front/rest/DeviceController.java new file mode 100644 index 0000000..f8178ed --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/front/rest/DeviceController.java @@ -0,0 +1,43 @@ +package me.zhengjie.modules.front.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import me.zhengjie.annotation.Log; +import me.zhengjie.annotation.rest.AnonymousPostMapping; +import me.zhengjie.modules.front.domain.dto.LoginVo; +import me.zhengjie.modules.front.service.WeChatService; +import me.zhengjie.modules.security.service.dto.JwtUserDto; +import me.zhengjie.modules.system.service.BusDeviceService; +import me.zhengjie.utils.SecurityUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + + +@Slf4j +@RestController("DeviceController") +@RequestMapping("api/front/device") +@Api(tags = "微信:设备管理") +public class DeviceController { + + @Autowired private BusDeviceService busDeviceService; + + @Log("绑定设备") + @ApiOperation(value = "绑定设备") + @GetMapping(value = "/binding") + public ResponseEntity binding(@RequestParam String code) { + busDeviceService.binding(code); + return new ResponseEntity<>("绑定成功", HttpStatus.OK); + } + +} + + + diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/front/service/WeChatService.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/front/service/WeChatService.java index 78e89c0..06300c3 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/front/service/WeChatService.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/front/service/WeChatService.java @@ -6,6 +6,8 @@ import javax.servlet.http.HttpServletRequest; public interface WeChatService { + String getQrCode(Long deviceId, String code); + LoginVo authorizeLogin(String code, HttpServletRequest request); } diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/front/service/impl/WeChatServiceImpl.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/front/service/impl/WeChatServiceImpl.java index 8d2b6cc..a0d1188 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/front/service/impl/WeChatServiceImpl.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/front/service/impl/WeChatServiceImpl.java @@ -6,7 +6,6 @@ import com.alibaba.fastjson2.JSONObject; import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.front.domain.dto.LoginVo; import me.zhengjie.modules.front.domain.dto.WeChatMiniAuthorizeVo; -import me.zhengjie.modules.front.service.CusUserService; import me.zhengjie.modules.front.service.WeChatService; import me.zhengjie.modules.security.config.SecurityProperties; import me.zhengjie.modules.security.security.TokenProvider; @@ -14,13 +13,15 @@ import me.zhengjie.modules.security.service.OnlineUserService; import me.zhengjie.modules.security.service.dto.JwtUserDto; import me.zhengjie.modules.system.domain.BusUser; import me.zhengjie.modules.system.mapper.BusUserMapper; -import me.zhengjie.utils.DateUtil; -import me.zhengjie.utils.RestTemplateUtils; +import me.zhengjie.modules.system.service.BusUserService; +import me.zhengjie.service.LocalStorageService; +import me.zhengjie.utils.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import java.time.LocalDateTime; @@ -38,14 +39,22 @@ public class WeChatServiceImpl implements WeChatService { @Value("${weChat.secret}") private String secret; + @Autowired private QrCodeUtil qrCodeUtil; @Autowired private BusUserMapper BusUserMapper; @Autowired private RestTemplateUtils restTemplateUtil; @Autowired private TokenProvider tokenProvider; @Autowired private SecurityProperties properties; @Autowired private OnlineUserService onlineUserService; - @Autowired private CusUserService BusUserService; - private static final String WECHAT_MINI_SNS_AUTH_CODE2SESSION_URL = "https://api.weixin.qq.com/sns/jscode2session?appid={}&secret={}&js_code={}&grant_type=authorization_code"; + @Autowired private BusUserService busUserService; + @Autowired private LocalStorageService localStorageService; private static final String DEFAULT_AVATAR = "/avatar/avatar.png"; + private static final String WECHAT_MINI_SNS_AUTH_CODE2SESSION_URL = "https://api.weixin.qq.com/sns/jscode2session?appid={}&secret={}&js_code={}&grant_type=authorization_code"; + + @Override + public String getQrCode(Long deviceId, String code) { + MultipartFile mFile = qrCodeUtil.getQrCode(code, code); + return localStorageService.createFile(code, mFile); + } @Override public LoginVo authorizeLogin(String code, HttpServletRequest request) { @@ -74,7 +83,7 @@ public class WeChatServiceImpl implements WeChatService { loginVo.setPhone(BusUser.getPhone()); loginVo.setAvatar(BusUser.getAvatar()); // 生成令牌 - JwtUserDto jwtUserDto = BusUserService.addUserCache(BusUser); + JwtUserDto jwtUserDto = busUserService.addUserCache(BusUser); String token = tokenProvider.createToken(jwtUserDto); loginVo.setToken(properties.getTokenStartWith() + token); // 保存在线信息 diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/WebSocketConfig.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/WebSocketConfig.java new file mode 100644 index 0000000..5d21fdd --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/WebSocketConfig.java @@ -0,0 +1,46 @@ +package me.zhengjie.modules.security.config; + +import me.zhengjie.modules.security.config.handler.DeviceWebSocketHandler; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.config.annotation.EnableWebSocket; +import org.springframework.web.socket.config.annotation.WebSocketConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; +import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean; + + +/** + * WebSocket配置类,启用WebSocket功能并注册处理器 + */ +@Configuration +@EnableWebSocket +public class WebSocketConfig implements WebSocketConfigurer { + + private final DeviceWebSocketHandler deviceWebSocketHandler; + + public WebSocketConfig(DeviceWebSocketHandler deviceWebSocketHandler) { + this.deviceWebSocketHandler = deviceWebSocketHandler; + } + + /** + * 注册WebSocket处理器,配置端点和允许的源 + * @param registry WebSocket处理器注册器 + */ + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + registry.addHandler(deviceWebSocketHandler, "/ws/device") + .setAllowedOrigins("*"); + } + + /** + * 配置WebSocket容器参数,设置消息缓冲区大小 + * @return WebSocket容器工厂Bean + */ + @Bean + public ServletServerContainerFactoryBean createWebSocketContainer() { + ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean(); + container.setMaxTextMessageBufferSize(8192); + container.setMaxBinaryMessageBufferSize(8192); + return container; + } +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/handler/DeviceWebSocketHandler.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/handler/DeviceWebSocketHandler.java new file mode 100644 index 0000000..530ebeb --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/handler/DeviceWebSocketHandler.java @@ -0,0 +1,77 @@ +package me.zhengjie.modules.security.config.handler; + +import org.springframework.stereotype.Component; +import org.springframework.web.socket.CloseStatus; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +import java.io.IOException; +import java.util.concurrent.ConcurrentHashMap; + +/** + * 处理客户端WebSocket连接的处理器 + * 管理客户端会话并转发设备状态变化 + */ +@Component +public class DeviceWebSocketHandler extends TextWebSocketHandler { + + // 存储所有活跃的WebSocket会话,键为会话ID + private final ConcurrentHashMap sessions = new ConcurrentHashMap<>(); + private final ThirdPartyWebSocketClient thirdPartyClient; + + public DeviceWebSocketHandler(ThirdPartyWebSocketClient thirdPartyClient) { + this.thirdPartyClient = thirdPartyClient; + } + + /** + * 处理来自客户端的文本消息 + * @param session 客户端会话 + * @param message 收到的消息 + * @throws IOException 发送消息失败时抛出 + */ + @Override + protected void handleTextMessage(WebSocketSession session, TextMessage message) throws IOException { + String payload = message.getPayload(); + // 将客户端指令转发给第三方WebSocket服务 + thirdPartyClient.sendCommand(payload); + } + + /** + * 客户端连接建立后的回调方法 + * @param session 新建立的会话 + */ + @Override + public void afterConnectionEstablished(WebSocketSession session) { + sessions.put(session.getId(), session); + // 可在此处添加连接初始化逻辑 + } + + /** + * 客户端连接关闭后的回调方法 + * @param session 关闭的会话 + * @param status 关闭状态 + */ + @Override + public void afterConnectionClosed(WebSocketSession session, CloseStatus status) { + sessions.remove(session.getId()); + } + + /** + * 通知所有客户端设备状态变化 + * @param deviceId 设备ID + * @param status 设备状态 + */ + public void notifyDeviceChange(String deviceId, String status) { + sessions.forEach((id, session) -> { + try { + // 向客户端发送JSON格式的设备状态消息 + session.sendMessage(new TextMessage( + String.format("{\"deviceId\": \"%s\", \"status\": \"%s\"}", deviceId, status) + )); + } catch (IOException e) { + e.printStackTrace(); + } + }); + } +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/handler/ThirdPartyWebSocketClient.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/handler/ThirdPartyWebSocketClient.java new file mode 100644 index 0000000..5b7f32d --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/handler/ThirdPartyWebSocketClient.java @@ -0,0 +1,148 @@ +package me.zhengjie.modules.security.config.handler; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.socket.client.WebSocketClient; +import org.springframework.web.socket.client.standard.StandardWebSocketClient; +import org.springframework.web.socket.handler.TextWebSocketHandler; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.TextMessage; + +import javax.annotation.PostConstruct; +import java.io.IOException; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +/** + * 与第三方WebSocket服务通信的客户端 + * 负责建立连接、订阅设备和处理消息 + */ +@Component +public class ThirdPartyWebSocketClient extends TextWebSocketHandler { + + @Value("${thirdparty.ws.url}") + private String thirdPartyWsUrl; + + private WebSocketSession session; + // 存储已订阅的设备,键为设备ID,值为订阅状态 + private final ConcurrentHashMap subscribedDevices = new ConcurrentHashMap<>(); + private final DeviceWebSocketHandler deviceHandler; + private final ScheduledExecutorService reconnectExecutor = Executors.newSingleThreadScheduledExecutor(); + + public ThirdPartyWebSocketClient(DeviceWebSocketHandler deviceHandler) { + this.deviceHandler = deviceHandler; + } + + /** + * Bean初始化后连接到第三方WebSocket服务 + */ + @PostConstruct + public void init() { + connect(); + } + + /** + * 建立与第三方WebSocket服务的连接 + */ + private void connect() { + WebSocketClient client = new StandardWebSocketClient(); + try { + session = client.doHandshake(this, thirdPartyWsUrl).get(); + System.out.println("Connected to third-party WebSocket server"); + } catch (Exception e) { + e.printStackTrace(); + // 连接失败,安排重连 + scheduleReconnect(); + } + } + + /** + * 安排重连任务 + */ + private void scheduleReconnect() { + reconnectExecutor.schedule(this::connect, 5, TimeUnit.SECONDS); + } + + /** + * 订阅指定设备的状态变化 + * @param deviceId 设备ID + */ + public void subscribeDevice(String deviceId) { + if (session != null && session.isOpen()) { + try { + // 发送订阅消息到第三方服务 + session.sendMessage(new TextMessage( + String.format("{\"action\": \"subscribe\", \"deviceId\": \"%s\"}", deviceId) + )); + subscribedDevices.put(deviceId, "subscribed"); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * 向第三方服务发送指令 + * @param command 指令内容 + */ + public void sendCommand(String command) { + if (session != null && session.isOpen()) { + try { + session.sendMessage(new TextMessage(command)); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * 处理从第三方服务接收到的文本消息 + * @param session 会话 + * @param message 收到的消息 + */ + @Override + protected void handleTextMessage(WebSocketSession session, TextMessage message) { + String payload = message.getPayload(); + // 处理设备状态变化消息 + processDeviceStatusChange(payload); + } + + /** + * 解析设备状态变化消息并通知客户端 + * @param payload 消息内容 + */ + private void processDeviceStatusChange(String payload) { + // 解析消息并提取设备ID和状态 + String deviceId = extractDeviceId(payload); + String status = extractStatus(payload); + + if (deviceId != null && status != null) { + // 通知所有连接的客户端设备状态变化 + deviceHandler.notifyDeviceChange(deviceId, status); + } + } + + /** + * 从消息中提取设备ID + * 需要根据第三方服务的消息格式实现具体解析逻辑 + * @param payload 消息内容 + * @return 设备ID + */ + private String extractDeviceId(String payload) { + // TODO: 实现JSON解析逻辑 + return null; + } + + /** + * 从消息中提取设备状态 + * 需要根据第三方服务的消息格式实现具体解析逻辑 + * @param payload 消息内容 + * @return 设备状态 + */ + private String extractStatus(String payload) { + // TODO: 实现JSON解析逻辑 + return null; + } +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusDevice.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusDevice.java new file mode 100644 index 0000000..93dd87c --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusDevice.java @@ -0,0 +1,95 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.domain; + +import com.baomidou.mybatisplus.annotation.TableField; +import lombok.Data; +import cn.hutool.core.bean.BeanUtil; +import io.swagger.annotations.ApiModelProperty; +import cn.hutool.core.bean.copier.CopyOptions; +import java.sql.Timestamp; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Set; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import me.zhengjie.modules.system.domain.dto.BusTreeVo; + +/** +* @description / +* @author tz +* @date 2025-05-20 +**/ +@Data +@TableName("bus_device") +public class BusDevice implements Serializable { + + @TableId(value = "id", type = IdType.AUTO) + @ApiModelProperty(value = "设备唯一标识") + private Long id; + + @ApiModelProperty(value = "设备序列号(唯一)") + private String deviceSn; + + @ApiModelProperty(value = "型号") + private String model; + + @ApiModelProperty(value = "品牌") + private String brand; + + @ApiModelProperty(value = "固件版本") + private String firmwareVersion; + + @ApiModelProperty(value = "放置位置") + private String location; + + @ApiModelProperty(value = "设备状态(1=在线,2=离线,3=故障)") + private Integer status; + + @ApiModelProperty(value = "最近上线时间") + private Timestamp onlineTime; + + @ApiModelProperty(value = "最近下线时间") + private Timestamp offlineTime; + + @ApiModelProperty(value = "累计时长(分钟)") + private Integer totalPrintTime; + + @ApiModelProperty(value = "备注") + private String remark; + + @ApiModelProperty(value = "类型:1打印机,2摄像头") + private Integer type; + + @ApiModelProperty(value = "创建者") + private String createBy; + + @ApiModelProperty(value = "更新者") + private String updateBy; + + @ApiModelProperty(value = "创建时间") + private Timestamp createTime; + + @ApiModelProperty(value = "更新时间") + private Timestamp updateTime; + + public void copy(BusDevice source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusDeviceCommand.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusDeviceCommand.java new file mode 100644 index 0000000..b80ca56 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusDeviceCommand.java @@ -0,0 +1,77 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.domain; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.bean.copier.CopyOptions; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.sql.Timestamp; + +/** +* @description / +* @author tz +* @date 2025-05-21 +**/ +@Data +@TableName("bus_device_command") +public class BusDeviceCommand implements Serializable { + + @TableId(value = "id", type = IdType.AUTO) + @ApiModelProperty(value = "指令唯一标识") + private Long id; + + @ApiModelProperty(value = "指令代码(唯一)") + private Long deviceId; + + @ApiModelProperty(value = "指令名称") + private String commandName; + + @ApiModelProperty(value = "指令类型(1=控制,2=查询,3=校准)") + private Integer commandType; + + @ApiModelProperty(value = "指令描述") + private String description; + + @ApiModelProperty(value = "是否为系统指令(1=是,2=否)") + private Integer isSystem; + + @ApiModelProperty(value = "指令参数(JSON格式)") + private String commandParams; + + @ApiModelProperty(value = "创建者") + private String createBy; + + @ApiModelProperty(value = "更新者") + private String updateBy; + + @ApiModelProperty(value = "创建时间") + private Timestamp createTime; + + @ApiModelProperty(value = "更新时间") + private Timestamp updateTime; + + public void copy(BusDeviceCommand source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusUser.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusUser.java index ae0a250..4cf454b 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusUser.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusUser.java @@ -18,15 +18,19 @@ package me.zhengjie.modules.system.domain; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.copier.CopyOptions; import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; import me.zhengjie.base.BaseEntity; +import me.zhengjie.modules.system.domain.dto.BusTreeVo; import java.io.Serializable; import java.sql.Timestamp; +import java.util.List; +import java.util.Set; @Getter @Setter @@ -61,6 +65,10 @@ public class BusUser extends BaseEntity implements Serializable { @ApiModelProperty(value = "创建时间") private Timestamp createTime; + @TableField(exist = false) + @ApiModelProperty(value = "指令", hidden = true) + private List commands; + public void copy(BusUser source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusUserCommand.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusUserCommand.java new file mode 100644 index 0000000..71628da --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusUserCommand.java @@ -0,0 +1,71 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.domain; + +import lombok.Data; +import cn.hutool.core.bean.BeanUtil; +import io.swagger.annotations.ApiModelProperty; +import cn.hutool.core.bean.copier.CopyOptions; +import java.sql.Timestamp; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; + +/** +* @description / +* @author tz +* @date 2025-05-23 +**/ +@Data +@TableName("bus_user_device_command") +public class BusUserCommand implements Serializable { + + @TableId(value = "id", type = IdType.AUTO) + @ApiModelProperty(value = "操作记录唯一标识") + private Long id; + + @NotNull + @ApiModelProperty(value = "用户ID(外键)") + private Long userId; + + @NotNull + @ApiModelProperty(value = "设备ID(外键)") + private Long deviceId; + + @NotNull + @ApiModelProperty(value = "指令ID(外键)") + private Long commandId; + + @ApiModelProperty(value = "创建者") + private String createBy; + + @ApiModelProperty(value = "更新者") + private String updateBy; + + @NotNull + @ApiModelProperty(value = "创建时间") + private Timestamp createTime; + + @NotNull + @ApiModelProperty(value = "更新时间") + private Timestamp updateTime; + + public void copy(BusUserCommand source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusUserDevice.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusUserDevice.java new file mode 100644 index 0000000..79dac50 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/BusUserDevice.java @@ -0,0 +1,75 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.domain; + +import lombok.Data; +import cn.hutool.core.bean.BeanUtil; +import io.swagger.annotations.ApiModelProperty; +import cn.hutool.core.bean.copier.CopyOptions; +import java.sql.Timestamp; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; + +/** +* @description / +* @author tz +* @date 2025-05-23 +**/ +@Data +@TableName("bus_user_device") +public class BusUserDevice implements Serializable { + + @TableId(value = "id", type = IdType.AUTO) + @ApiModelProperty(value = "绑定记录唯一标识") + private Long id; + + @NotNull + @ApiModelProperty(value = "用户ID(外键)") + private Long userId; + + @NotNull + @ApiModelProperty(value = "设备ID(外键)") + private Long deviceId; + + @NotNull + @ApiModelProperty(value = "是否为主用户(1=是,2=否)") + private Integer isPrimary; + + @NotNull + @ApiModelProperty(value = "绑定状态(1=有效,2=失效)") + private Integer status; + + @ApiModelProperty(value = "创建者") + private String createBy; + + @ApiModelProperty(value = "更新者") + private String updateBy; + + @NotNull + @ApiModelProperty(value = "创建时间") + private Timestamp createTime; + + @NotNull + @ApiModelProperty(value = "更新时间") + private Timestamp updateTime; + + public void copy(BusUserDevice source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusCommandQueryCriteria.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusCommandQueryCriteria.java new file mode 100644 index 0000000..4b6bb18 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusCommandQueryCriteria.java @@ -0,0 +1,33 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.domain.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** +* @author tz +* @date 2025-05-21 +**/ +@Data +public class BusCommandQueryCriteria { + + @ApiModelProperty(value = "页码", example = "1") + private Integer page = 1; + + @ApiModelProperty(value = "每页数据量", example = "10") + private Integer size = 10; +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusDeviceQueryCriteria.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusDeviceQueryCriteria.java new file mode 100644 index 0000000..8f0c972 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusDeviceQueryCriteria.java @@ -0,0 +1,34 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.domain.dto; + +import lombok.Data; +import io.swagger.annotations.ApiModelProperty; +import me.zhengjie.modules.system.domain.BusDevice; + +/** +* @author tz +* @date 2025-05-20 +**/ +@Data +public class BusDeviceQueryCriteria extends BusDevice { + + @ApiModelProperty(value = "页码", example = "1") + private Integer page = 1; + + @ApiModelProperty(value = "每页数据量", example = "10") + private Integer size = 10; +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusTreeVo.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusTreeVo.java new file mode 100644 index 0000000..ba0d299 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusTreeVo.java @@ -0,0 +1,58 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.domain.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** +* @author tz +* @date 2025-05-21 +**/ +@Data +public class BusTreeVo { + + @ApiModelProperty(value = "标识") + private String id; + + @ApiModelProperty(value = "上级") + private String pid; + + @ApiModelProperty(value = "名称") + private String name; + + @ApiModelProperty(value = "备注") + private String remark; + + @ApiModelProperty(value = "子节点数目", hidden = true) + private Integer subCount = 0; + + @ApiModelProperty(value = "标签名称") + public String getLabel() { + return name; + } + + @ApiModelProperty(value = "是否有子节点") + public Boolean getHasChildren() { + return subCount > 0; + } + + @ApiModelProperty(value = "是否为叶子") + public Boolean getLeaf() { + return subCount <= 0; + } + +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusUserQueryCriteria.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusUserQueryCriteria.java index f29ef04..8b85eb6 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusUserQueryCriteria.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/dto/BusUserQueryCriteria.java @@ -17,17 +17,19 @@ package me.zhengjie.modules.system.domain.dto; import lombok.Data; import io.swagger.annotations.ApiModelProperty; +import me.zhengjie.modules.system.domain.BusUser; /** * @author tz * @date 2025-05-19 **/ @Data -public class BusUserQueryCriteria{ +public class BusUserQueryCriteria extends BusUser { @ApiModelProperty(value = "页码", example = "1") private Integer page = 1; @ApiModelProperty(value = "每页数据量", example = "10") private Integer size = 10; + } \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/enums/MsgType.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/enums/MsgType.java new file mode 100644 index 0000000..ca43e38 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/enums/MsgType.java @@ -0,0 +1,31 @@ +///* +// * Copyright 2019-2025 Tz +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, software +// * distributed under the License is distributed on an "AS IS" BASIS, +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// */ +//package me.zhengjie.modules.system.domain.enums; +// +///** +// * @author ZhangHouYing +// * @date 2019-08-10 9:56 +// */ +//public enum MsgType { +// /** 连接 */ +// CONNECT, +// /** 关闭 */ +// CLOSE, +// /** 信息 */ +// INFO, +// /** 错误 */ +// ERROR +//} diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusCommandMapper.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusCommandMapper.java new file mode 100644 index 0000000..e58c2f8 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusCommandMapper.java @@ -0,0 +1,42 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.mapper; + +import java.util.List; + +import me.zhengjie.modules.system.domain.BusDevice; +import me.zhengjie.modules.system.domain.BusDeviceCommand; +import me.zhengjie.modules.system.domain.dto.BusCommandQueryCriteria; +import me.zhengjie.modules.system.domain.dto.BusTreeVo; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Mapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + +/** +* @author tz +* @date 2025-05-21 +**/ +@Mapper +public interface BusCommandMapper extends BaseMapper { + + IPage findAll(@Param("criteria") BusCommandQueryCriteria criteria, Page page); + + List findAll(@Param("criteria") BusCommandQueryCriteria criteria); + + List getCommandByDeviceId(@Param("pid") Long pid); +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusDeviceMapper.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusDeviceMapper.java new file mode 100644 index 0000000..71b5db2 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusDeviceMapper.java @@ -0,0 +1,41 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.mapper; + +import java.util.List; + +import me.zhengjie.modules.system.domain.BusDevice; +import me.zhengjie.modules.system.domain.dto.BusDeviceQueryCriteria; +import me.zhengjie.modules.system.domain.dto.BusTreeVo; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Mapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + +/** +* @author tz +* @date 2025-05-20 +**/ +@Mapper +public interface BusDeviceMapper extends BaseMapper { + + IPage findAll(@Param("criteria") BusDeviceQueryCriteria criteria, Page page); + + List findAll(@Param("criteria") BusDeviceQueryCriteria criteria); + + List getDevice(); +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusUserCommandMapper.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusUserCommandMapper.java new file mode 100644 index 0000000..c9a3f12 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusUserCommandMapper.java @@ -0,0 +1,35 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.mapper; + + +import me.zhengjie.modules.system.domain.BusUserCommand; +import org.apache.ibatis.annotations.Mapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** +* @author tz +* @date 2025-05-23 +**/ +@Mapper +public interface BusUserCommandMapper extends BaseMapper { + + void bindingCommand(@Param("userId") Long id, @Param("commandIds") List commandIds); + +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusUserDeviceMapper.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusUserDeviceMapper.java new file mode 100644 index 0000000..68031ba --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusUserDeviceMapper.java @@ -0,0 +1,35 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.mapper; + + +import me.zhengjie.modules.system.domain.BusUserDevice; +import org.apache.ibatis.annotations.Mapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** +* @author tz +* @date 2025-05-23 +**/ +@Mapper +public interface BusUserDeviceMapper extends BaseMapper { + + void bindingDevice(@Param("userId") Long id, @Param("deviceIds") List deviceIds); + +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusUserMapper.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusUserMapper.java index 3ef0d2c..1db0175 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusUserMapper.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/mapper/BusUserMapper.java @@ -18,6 +18,7 @@ package me.zhengjie.modules.system.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import me.zhengjie.modules.system.domain.BusUser; +import me.zhengjie.modules.system.domain.dto.BusTreeVo; import me.zhengjie.modules.system.domain.dto.BusUserQueryCriteria; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -38,4 +39,5 @@ public interface BusUserMapper extends BaseMapper { List findAll(@Param("criteria") BusUserQueryCriteria criteria); + List getUserCommands(@Param("userId") Long id); } \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusCommandController.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusCommandController.java new file mode 100644 index 0000000..87c6643 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusCommandController.java @@ -0,0 +1,82 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.rest; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.RequiredArgsConstructor; +import me.zhengjie.annotation.Log; +import me.zhengjie.modules.system.domain.BusDeviceCommand; +import me.zhengjie.modules.system.domain.dto.BusCommandQueryCriteria; +import me.zhengjie.modules.system.service.BusCommandService; +import me.zhengjie.utils.PageResult; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** +* @author tz +* @date 2025-05-21 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "系统:设备指令") +@RequestMapping("/api/busDeviceCommand") +public class BusCommandController { + + private final BusCommandService busDeviceCommandService; + + @GetMapping + @ApiOperation("查询busCommand") + @PreAuthorize("@el.check('busDeviceCommand:list')") + public ResponseEntity> queryBusDeviceCommand(BusCommandQueryCriteria criteria){ + Page page = new Page<>(criteria.getPage(), criteria.getSize()); + return new ResponseEntity<>(busDeviceCommandService.queryAll(criteria,page),HttpStatus.OK); + } + + @PostMapping + @Log("新增busCommand") + @ApiOperation("新增busCommand") + @PreAuthorize("@el.check('busDeviceCommand:add')") + public ResponseEntity createBusDeviceCommand(@Validated @RequestBody BusDeviceCommand resources){ + busDeviceCommandService.create(resources); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @PutMapping + @Log("修改busCommand") + @ApiOperation("修改busCommand") + @PreAuthorize("@el.check('busDeviceCommand:edit')") + public ResponseEntity updateBusDeviceCommand(@Validated @RequestBody BusDeviceCommand resources){ + busDeviceCommandService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping + @Log("删除busCommand") + @ApiOperation("删除busCommand") + @PreAuthorize("@el.check('busDeviceCommand:del')") + public ResponseEntity deleteBusDeviceCommand(@ApiParam(value = "传ID数组[]") @RequestBody List ids) { + busDeviceCommandService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusDeviceController.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusDeviceController.java new file mode 100644 index 0000000..8a4c459 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusDeviceController.java @@ -0,0 +1,132 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.rest; + +import cn.hutool.core.collection.CollUtil; +import me.zhengjie.annotation.Log; +import me.zhengjie.modules.system.domain.BusDevice; +import me.zhengjie.modules.system.domain.BusDeviceCommand; +import me.zhengjie.modules.system.domain.Menu; +import me.zhengjie.modules.system.domain.dto.BusDeviceQueryCriteria; +import me.zhengjie.modules.system.domain.dto.BusTreeVo; +import me.zhengjie.modules.system.service.BusCommandService; +import me.zhengjie.modules.system.service.BusDeviceService; +import lombok.RequiredArgsConstructor; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import me.zhengjie.utils.PageResult; + +/** +* @author tz +* @date 2025-05-20 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "系统:设备管理") +@RequestMapping("/api/busDevice") +public class BusDeviceController { + + private final BusDeviceService busDeviceService; + private final BusCommandService busCommandService; + + @ApiOperation("根据ID返回所有子节点ID,包含自身ID") + @GetMapping(value = "/child") + public ResponseEntity child(@RequestParam String id) { + Long newId = Long.parseLong(id.replace("d", "").replace("c", "")); + Set menuSet = new HashSet<>(); + BusTreeVo set = new BusTreeVo(); + if (id.contains("d")) { + BusDevice entity = busDeviceService.getById(newId); + List list = busDeviceService.getDeviceTree(newId); + set.setId("d" + newId); + set.setPid("0"); + set.setName("品牌:" + entity.getBrand() + " | " + "型号:" + entity.getModel()); + set.setRemark(entity.getLocation() + "[" + (entity.getType().equals(1) ? "3D打印机" : "摄像头") + "]"); + menuSet.add(set); + menuSet.addAll(list); + } else { + BusDeviceCommand entity = busCommandService.getById(newId); + set.setId("c" + newId); + set.setPid("d" + entity.getDeviceId()); + set.setName(entity.getCommandName()); + set.setRemark(entity.getDescription()); + menuSet.add(set); + } + Set ids = menuSet.stream().map(BusTreeVo::getId).collect(Collectors.toSet()); + return new ResponseEntity<>(ids,HttpStatus.OK); + } + + @ApiOperation("查询设备指令Tree") + @GetMapping(value = "/getDeviceTree") + public ResponseEntity> getDeviceTree(@RequestParam String pid) { + pid = pid.replace("d", "").replace("c", ""); + return new ResponseEntity<>(busDeviceService.getDeviceTree(Long.parseLong(pid)), HttpStatus.OK); + } + + @GetMapping("getQrCode") + @ApiOperation("查询busDevice") + @PreAuthorize("@el.check('busDevice:qrCode')") + public ResponseEntity getQrCode(BusDeviceQueryCriteria criteria) { + String qrCodeUrl = busDeviceService.getQrCode(criteria.getId()); + return new ResponseEntity<>(qrCodeUrl, HttpStatus.OK); + } + + @GetMapping + @ApiOperation("查询busDevice") + @PreAuthorize("@el.check('busDevice:list')") + public ResponseEntity> queryBusDevice(BusDeviceQueryCriteria criteria){ + Page page = new Page<>(criteria.getPage(), criteria.getSize()); + return new ResponseEntity<>(busDeviceService.queryAll(criteria, page), HttpStatus.OK); + } + + @PostMapping + @Log("新增busDevice") + @ApiOperation("新增busDevice") + @PreAuthorize("@el.check('busDevice:add')") + public ResponseEntity createBusDevice(@Validated @RequestBody BusDevice resources){ + busDeviceService.create(resources); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @PutMapping + @Log("修改busDevice") + @ApiOperation("修改busDevice") + @PreAuthorize("@el.check('busDevice:edit')") + public ResponseEntity updateBusDevice(@Validated @RequestBody BusDevice resources){ + busDeviceService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping + @Log("删除busDevice") + @ApiOperation("删除busDevice") + @PreAuthorize("@el.check('busDevice:del')") + public ResponseEntity deleteBusDevice(@ApiParam(value = "传ID数组[]") @RequestBody List ids) { + busDeviceService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusDeviceSocketController.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusDeviceSocketController.java new file mode 100644 index 0000000..907f0f9 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusDeviceSocketController.java @@ -0,0 +1,31 @@ +package me.zhengjie.modules.system.rest; + +import me.zhengjie.modules.system.service.socket.DeviceService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/api/printer") +public class BusDeviceSocketController { + + @Autowired DeviceService deviceService; + + /** + * 订阅设备状态变化的HTTP接口 + * @param deviceId 设备ID + */ + @PostMapping("/{deviceId}/subscribe") + public void subscribe(@PathVariable String deviceId) { + deviceService.subscribeToDevice(deviceId); + } + + /** + * 向设备发送指令的HTTP接口 + * @param deviceId 设备ID + * @param command 指令内容 + */ + @PostMapping("/{deviceId}/command") + public void sendCommand(@PathVariable String deviceId, @RequestBody String command) { + deviceService.sendDeviceCommand(deviceId, command); + } +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusUserController.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusUserController.java index 700c924..ee8f5bc 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusUserController.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/BusUserController.java @@ -17,7 +17,9 @@ package me.zhengjie.modules.system.rest; import me.zhengjie.annotation.Log; import me.zhengjie.modules.system.domain.BusUser; +import me.zhengjie.modules.system.domain.dto.BusTreeVo; import me.zhengjie.modules.system.domain.dto.BusUserQueryCriteria; +import me.zhengjie.modules.system.service.BusUserDeviceService; import me.zhengjie.modules.system.service.BusUserService; import lombok.RequiredArgsConstructor; import java.util.List; @@ -36,27 +38,44 @@ import me.zhengjie.utils.PageResult; **/ @RestController @RequiredArgsConstructor -@Api(tags = "busUser") +@Api(tags = "系统:系统用户") @RequestMapping("/api/busUser") public class BusUserController { private final BusUserService busUserService; + private final BusUserDeviceService busUserDeviceService; + + @Log("修改用户设备指令") + @ApiOperation("修改用户设备指令") + @PutMapping(value = "/updUserCommands") + @PreAuthorize("@el.check('roles:edit')") + public ResponseEntity updUserCommands(@RequestBody BusUser busUser) { + busUserDeviceService.updUserCommands(busUser); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @ApiOperation("查询用户信息") + @GetMapping(value = "/{id}") + @PreAuthorize("@el.check('busUser:list')") + public ResponseEntity findUserById(@PathVariable Long id) { + BusUser busUser = busUserService.getById(id); + List userCommands = busUserService.getUserCommands(busUser.getId()); + busUser.setCommands(userCommands); + return new ResponseEntity<>(busUser, HttpStatus.OK); + } @GetMapping @ApiOperation("查询busUser") @PreAuthorize("@el.check('busUser:list')") public ResponseEntity> queryBusUser(BusUserQueryCriteria criteria){ Page page = new Page<>(criteria.getPage(), criteria.getSize()); - return new ResponseEntity<>(busUserService.queryAll(criteria,page),HttpStatus.OK); - } - - @PostMapping - @Log("新增busUser") - @ApiOperation("新增busUser") - @PreAuthorize("@el.check('busUser:add')") - public ResponseEntity createBusUser(@Validated @RequestBody BusUser resources){ - busUserService.create(resources); - return new ResponseEntity<>(HttpStatus.CREATED); + PageResult result = busUserService.queryAll(criteria, page); + List content = result.getContent(); + for (BusUser busUser : content) { + List userCommands = busUserService.getUserCommands(busUser.getId()); + busUser.setCommands(userCommands); + } + return new ResponseEntity<>(result, HttpStatus.OK); } @PutMapping @@ -68,12 +87,4 @@ public class BusUserController { return new ResponseEntity<>(HttpStatus.NO_CONTENT); } - @DeleteMapping - @Log("删除busUser") - @ApiOperation("删除busUser") - @PreAuthorize("@el.check('busUser:del')") - public ResponseEntity deleteBusUser(@ApiParam(value = "传ID数组[]") @RequestBody List ids) { - busUserService.deleteAll(ids); - return new ResponseEntity<>(HttpStatus.OK); - } } \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusCommandService.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusCommandService.java new file mode 100644 index 0000000..7123676 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusCommandService.java @@ -0,0 +1,65 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.service; + +import java.util.List; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import me.zhengjie.modules.system.domain.BusDeviceCommand; +import me.zhengjie.modules.system.domain.dto.BusCommandQueryCriteria; +import me.zhengjie.utils.PageResult; + +/** +* @description 服务接口 +* @author tz +* @date 2025-05-21 +**/ +public interface BusCommandService extends IService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param page 分页参数 + * @return PageResult + */ + PageResult queryAll(BusCommandQueryCriteria criteria, Page page); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(BusCommandQueryCriteria criteria); + + /** + * 创建 + * @param resources / + */ + void create(BusDeviceCommand resources); + + /** + * 编辑 + * @param resources / + */ + void update(BusDeviceCommand resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(List ids); + +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusDeviceService.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusDeviceService.java new file mode 100644 index 0000000..50c9c4d --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusDeviceService.java @@ -0,0 +1,73 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.service; + +import java.util.List; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import me.zhengjie.modules.system.domain.BusDevice; +import me.zhengjie.modules.system.domain.Menu; +import me.zhengjie.modules.system.domain.dto.BusDeviceQueryCriteria; +import me.zhengjie.modules.system.domain.dto.BusTreeVo; +import me.zhengjie.utils.PageResult; + +/** +* @description 服务接口 +* @author tz +* @date 2025-05-20 +**/ +public interface BusDeviceService extends IService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param page 分页参数 + * @return PageResult + */ + PageResult queryAll(BusDeviceQueryCriteria criteria, Page page); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(BusDeviceQueryCriteria criteria); + + /** + * 创建 + * @param resources / + */ + void create(BusDevice resources); + + /** + * 编辑 + * @param resources / + */ + void update(BusDevice resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(List ids); + + String getQrCode(Long id); + + void binding(String code); + + List getDeviceTree(Long pid); + +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusUserDeviceService.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusUserDeviceService.java new file mode 100644 index 0000000..03b0716 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusUserDeviceService.java @@ -0,0 +1,31 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import me.zhengjie.modules.system.domain.BusUser; +import me.zhengjie.modules.system.domain.BusUserDevice; + +/** +* @description 服务接口 +* @author tz +* @date 2025-05-23 +**/ +public interface BusUserDeviceService extends IService { + + void updUserCommands(BusUser busUser); + +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusUserService.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusUserService.java index 0444dd1..405c2e8 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusUserService.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/BusUserService.java @@ -15,16 +15,12 @@ */ package me.zhengjie.modules.system.service; -import me.zhengjie.domain.BusUser; -import me.zhengjie.domain.dto.BusUserQueryCriteria; -import java.util.Map; import java.util.List; -import java.io.IOException; -import javax.servlet.http.HttpServletResponse; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import me.zhengjie.modules.security.service.dto.JwtUserDto; import me.zhengjie.modules.system.domain.BusUser; +import me.zhengjie.modules.system.domain.dto.BusTreeVo; import me.zhengjie.modules.system.domain.dto.BusUserQueryCriteria; import me.zhengjie.utils.PageResult; @@ -69,4 +65,7 @@ public interface BusUserService extends IService { * @param ids / */ void deleteAll(List ids); + + List getUserCommands(Long id); + } \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusCommandServiceImpl.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusCommandServiceImpl.java new file mode 100644 index 0000000..94a0ced --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusCommandServiceImpl.java @@ -0,0 +1,73 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.service.impl; + +import me.zhengjie.modules.system.domain.BusDeviceCommand; +import me.zhengjie.modules.system.domain.dto.BusCommandQueryCriteria; +import me.zhengjie.modules.system.mapper.BusCommandMapper; +import me.zhengjie.modules.system.service.BusCommandService; +import me.zhengjie.utils.FileUtil; +import lombok.RequiredArgsConstructor; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import me.zhengjie.utils.PageUtil; +import java.util.List; +import me.zhengjie.utils.PageResult; + +/** +* @description 服务实现 +* @author tz +* @date 2025-05-21 +**/ +@Service +@RequiredArgsConstructor +public class BusCommandServiceImpl extends ServiceImpl implements BusCommandService { + + private final BusCommandMapper busDeviceCommandMapper; + + @Override + public PageResult queryAll(BusCommandQueryCriteria criteria, Page page){ + return PageUtil.toPage(busDeviceCommandMapper.findAll(criteria, page)); + } + + @Override + public List queryAll(BusCommandQueryCriteria criteria){ + return busDeviceCommandMapper.findAll(criteria); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void create(BusDeviceCommand resources) { + busDeviceCommandMapper.insert(resources); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(BusDeviceCommand resources) { + BusDeviceCommand busDeviceCommand = getById(resources.getId()); + busDeviceCommand.copy(resources); + busDeviceCommandMapper.updateById(busDeviceCommand); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteAll(List ids) { + busDeviceCommandMapper.deleteBatchIds(ids); + } + +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusDeviceServiceImpl.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusDeviceServiceImpl.java new file mode 100644 index 0000000..7503f05 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusDeviceServiceImpl.java @@ -0,0 +1,112 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.service.impl; + +import me.zhengjie.exception.BadRequestException; +import me.zhengjie.modules.front.service.WeChatService; +import me.zhengjie.modules.system.domain.BusDevice; +import me.zhengjie.modules.system.domain.Menu; +import me.zhengjie.modules.system.domain.dto.BusDeviceQueryCriteria; +import me.zhengjie.modules.system.domain.dto.BusTreeVo; +import me.zhengjie.modules.system.mapper.BusCommandMapper; +import me.zhengjie.modules.system.mapper.BusDeviceMapper; +import me.zhengjie.modules.system.service.BusDeviceService; +import lombok.RequiredArgsConstructor; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import me.zhengjie.utils.CacheKey; +import me.zhengjie.utils.RedisUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import me.zhengjie.utils.PageUtil; + +import java.util.List; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +import me.zhengjie.utils.PageResult; + +/** +* @description 服务实现 +* @author tz +* @date 2025-05-20 +**/ +@Service +@RequiredArgsConstructor +public class BusDeviceServiceImpl extends ServiceImpl implements BusDeviceService { + + private final BusDeviceMapper busDeviceMapper; + private final BusCommandMapper busCommandMapper; + private final WeChatService weChatService; + private final RedisUtils redisUtils; + + @Override + public PageResult queryAll(BusDeviceQueryCriteria criteria, Page page){ + return PageUtil.toPage(busDeviceMapper.findAll(criteria, page)); + } + + @Override + public List queryAll(BusDeviceQueryCriteria criteria){ + return busDeviceMapper.findAll(criteria); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void create(BusDevice resources) { + busDeviceMapper.insert(resources); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(BusDevice resources) { + BusDevice busDevice = getById(resources.getId()); + busDevice.copy(resources); + busDeviceMapper.updateById(busDevice); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteAll(List ids) { + busDeviceMapper.deleteBatchIds(ids); + } + + @Override + public String getQrCode(Long id) { + String code = (new Random().nextInt(900000) + 100000) + ""; + String qrCode = weChatService.getQrCode(id, code); + redisUtils.set(CacheKey.QR_CODE + code, id, 1, TimeUnit.DAYS); + return qrCode; + } + + @Override + public void binding(String code) { + if (null == redisUtils.get(CacheKey.QR_CODE + code)) { + throw new BadRequestException("二维码已过期,请联系管理员"); + } + Long deviceId = Long.parseLong(redisUtils.get(CacheKey.QR_CODE + code).toString()); + } + + @Override + public List getDeviceTree(Long pid) { + List result; + if(pid != null && !pid.equals(0L)){ + result = busCommandMapper.getCommandByDeviceId(pid); + } else { + result = busDeviceMapper.getDevice(); + } + return result; + } +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusUserDeviceServiceImpl.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusUserDeviceServiceImpl.java new file mode 100644 index 0000000..634e507 --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusUserDeviceServiceImpl.java @@ -0,0 +1,73 @@ +/* +* Copyright 2019-2025 Tz +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.system.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import me.zhengjie.modules.system.domain.BusUser; +import me.zhengjie.modules.system.domain.BusUserCommand; +import me.zhengjie.modules.system.domain.BusUserDevice; +import me.zhengjie.modules.system.domain.dto.BusTreeVo; +import me.zhengjie.modules.system.mapper.BusUserCommandMapper; +import me.zhengjie.modules.system.mapper.BusUserDeviceMapper; +import me.zhengjie.modules.system.service.BusUserDeviceService; +import lombok.RequiredArgsConstructor; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +/** +* @description 服务实现 +* @author tz +* @date 2025-05-23 +**/ +@Service +@RequiredArgsConstructor +public class BusUserDeviceServiceImpl extends ServiceImpl implements BusUserDeviceService { + + private final BusUserDeviceMapper busUserDeviceMapper; + private final BusUserCommandMapper busUserCommandMapper; + + @Override + @Transactional(rollbackFor = Exception.class) + public void updUserCommands(BusUser busUser) { + List commands = busUser.getCommands(); + if (null == commands || commands.isEmpty()) { return; } + List userDevices = commands.stream().filter(i -> i.getId().contains("d")).collect(Collectors.toList()); + List userCommands = commands.stream().filter(i -> i.getId().contains("c")).collect(Collectors.toList()); + List oldUserDevices = busUserDeviceMapper.selectList(new LambdaQueryWrapper().eq(BusUserDevice::getUserId, busUser.getId())); + List oldUserCommands = busUserCommandMapper.selectList(new LambdaQueryWrapper().eq(BusUserCommand::getUserId, busUser.getId())); + if (!oldUserDevices.isEmpty()) { + List delIds = oldUserDevices.stream().map(i -> i.getId()).collect(Collectors.toList()); + busUserDeviceMapper.deleteBatchIds(delIds); + } + if (!oldUserCommands.isEmpty()) { + List delIds = oldUserCommands.stream().map(i -> i.getId()).collect(Collectors.toList()); + busUserCommandMapper.deleteBatchIds(delIds); + } + if (!userDevices.isEmpty()) { + List deviceIds = userDevices.stream().map(i -> Long.parseLong(i.getId().replace("d", ""))).collect(Collectors.toList()); + busUserDeviceMapper.bindingDevice(busUser.getId(), deviceIds); + } + if (!userCommands.isEmpty()) { + List commandIds = userCommands.stream().map(i -> Long.parseLong(i.getId().replace("c", ""))).collect(Collectors.toList()); + busUserCommandMapper.bindingCommand(busUser.getId(), commandIds); + } + } +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusUserServiceImpl.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusUserServiceImpl.java index f8f5655..ed18b81 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusUserServiceImpl.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/BusUserServiceImpl.java @@ -19,6 +19,7 @@ import me.zhengjie.modules.security.service.UserCacheManager; import me.zhengjie.modules.security.service.dto.JwtUserDto; import me.zhengjie.modules.system.domain.BusUser; import me.zhengjie.modules.system.domain.User; +import me.zhengjie.modules.system.domain.dto.BusTreeVo; import me.zhengjie.modules.system.domain.dto.BusUserQueryCriteria; import me.zhengjie.modules.system.mapper.BusUserMapper; import me.zhengjie.modules.system.service.BusUserService; @@ -29,6 +30,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import me.zhengjie.utils.PageUtil; + +import java.util.Collections; import java.util.List; import java.util.ArrayList; import me.zhengjie.utils.PageResult; @@ -75,6 +78,11 @@ public class BusUserServiceImpl extends ServiceImpl impl busUserMapper.deleteBatchIds(ids); } + @Override + public List getUserCommands(Long id) { + return busUserMapper.getUserCommands(id); + } + @Override public JwtUserDto addUserCache(BusUser BusUser) { String openId = BusUser.getToken(); diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/socket/DeviceService.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/socket/DeviceService.java new file mode 100644 index 0000000..6c808ca --- /dev/null +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/system/service/socket/DeviceService.java @@ -0,0 +1,37 @@ +package me.zhengjie.modules.system.service.socket; + +import me.zhengjie.modules.security.config.handler.ThirdPartyWebSocketClient; +import org.springframework.stereotype.Service; + +/** + * 设备管理服务,提供与设备相关的业务逻辑 + */ +@Service +public class DeviceService { + + private final ThirdPartyWebSocketClient webSocketClient; + + public DeviceService(ThirdPartyWebSocketClient webSocketClient) { + this.webSocketClient = webSocketClient; + } + + /** + * 订阅设备状态变化 + * @param deviceId 设备ID + */ + public void subscribeToDevice(String deviceId) { + webSocketClient.subscribeDevice(deviceId); + } + + /** + * 向设备发送指令 + * @param deviceId 设备ID + * @param command 指令内容 + */ + public void sendDeviceCommand(String deviceId, String command) { + // 构建符合第三方服务格式的指令 + String formattedCommand = String.format("{\"deviceId\": \"%s\", \"command\": \"%s\"}", + deviceId, command); + webSocketClient.sendCommand(formattedCommand); + } +} \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/resources/config/application-dev.yml b/eladmin/eladmin-system/src/main/resources/config/application-dev.yml index c814188..51b6575 100644 --- a/eladmin/eladmin-system/src/main/resources/config/application-dev.yml +++ b/eladmin/eladmin-system/src/main/resources/config/application-dev.yml @@ -104,8 +104,13 @@ swagger: # 微信信息配置 weChat: - appId: 1231321 - secret: 123123 + appId: wx583d0c321ef43dfe + secret: 1b5eca11a1058361b0f14c5933ef6bd6 + +# socket地址 +thirdparty: + ws: + url: ws://127.0.0.1:3030/websocket # 文件存储路径 file: diff --git a/eladmin/eladmin-system/src/main/resources/mapper/system/BusCommandMapper.xml b/eladmin/eladmin-system/src/main/resources/mapper/system/BusCommandMapper.xml new file mode 100644 index 0000000..342f27a --- /dev/null +++ b/eladmin/eladmin-system/src/main/resources/mapper/system/BusCommandMapper.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + id, device_id, command_name, command_type, description, is_system, command_params, create_by, update_by, create_time, update_time + + + + \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/resources/mapper/system/BusDeviceMapper.xml b/eladmin/eladmin-system/src/main/resources/mapper/system/BusDeviceMapper.xml new file mode 100644 index 0000000..6990756 --- /dev/null +++ b/eladmin/eladmin-system/src/main/resources/mapper/system/BusDeviceMapper.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + id, device_sn, model, brand, firmware_version, location, status, online_time, offline_time, total_print_time, remark, type, create_by, update_by, create_time, update_time + + + + \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/resources/mapper/system/BusUserCommandMapper.xml b/eladmin/eladmin-system/src/main/resources/mapper/system/BusUserCommandMapper.xml new file mode 100644 index 0000000..52536b6 --- /dev/null +++ b/eladmin/eladmin-system/src/main/resources/mapper/system/BusUserCommandMapper.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + insert into bus_user_device_command (user_id, device_id, command_id) + select #{userId}, device_id, id from bus_device_command where id in + + #{id} + + + + + id, user_id, device_id, command_id, create_by, update_by, create_time, update_time + + + + \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/resources/mapper/system/BusUserDeviceMapper.xml b/eladmin/eladmin-system/src/main/resources/mapper/system/BusUserDeviceMapper.xml new file mode 100644 index 0000000..68461a9 --- /dev/null +++ b/eladmin/eladmin-system/src/main/resources/mapper/system/BusUserDeviceMapper.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + insert into bus_user_device (user_id, device_id) values + + (#{userId}, #{id}) + + + + + id, user_id, device_id, is_primary, status, create_by, update_by, create_time, update_time + + + + \ No newline at end of file diff --git a/eladmin/eladmin-system/src/main/resources/mapper/system/BusUserMapper.xml b/eladmin/eladmin-system/src/main/resources/mapper/system/BusUserMapper.xml index 1455cd4..aec987d 100644 --- a/eladmin/eladmin-system/src/main/resources/mapper/system/BusUserMapper.xml +++ b/eladmin/eladmin-system/src/main/resources/mapper/system/BusUserMapper.xml @@ -16,6 +16,12 @@ + + id, real_name, nickname, avatar, phone, status, token, sex, create_by, update_by, create_time, update_time @@ -25,6 +31,9 @@ from bus_user + and nickname like concat('%', #{criteria.nickname}, '%') + and phone like concat('%', #{criteria.phone}, '%') + and status = #{criteria.status} order by id desc diff --git a/eladmin/eladmin-system/src/main/resources/mapper/system/DashboardMapper.xml b/eladmin/eladmin-system/src/main/resources/mapper/system/DashboardMapper.xml index bba1f3c..7bfb883 100644 --- a/eladmin/eladmin-system/src/main/resources/mapper/system/DashboardMapper.xml +++ b/eladmin/eladmin-system/src/main/resources/mapper/system/DashboardMapper.xml @@ -4,7 +4,7 @@ @@ -47,13 +47,13 @@ select '前七天' text, count(1) value from sys_role where DATE(create_time) = CURDATE() - INTERVAL 7 DAY - select '前一天' text, count(1) value from bus_law_enforcement where DATE(create_time) = CURDATE() - INTERVAL 1 DAY UNION ALL - select '前两天' text, count(1) value from bus_law_enforcement where DATE(create_time) = CURDATE() - INTERVAL 2 DAY UNION ALL - select '前三天' text, count(1) value from bus_law_enforcement where DATE(create_time) = CURDATE() - INTERVAL 3 DAY UNION ALL - select '前四天' text, count(1) value from bus_law_enforcement where DATE(create_time) = CURDATE() - INTERVAL 4 DAY UNION ALL - select '前五天' text, count(1) value from bus_law_enforcement where DATE(create_time) = CURDATE() - INTERVAL 5 DAY UNION ALL - select '前六天' text, count(1) value from bus_law_enforcement where DATE(create_time) = CURDATE() - INTERVAL 6 DAY UNION ALL - select '前七天' text, count(1) value from bus_law_enforcement where DATE(create_time) = CURDATE() - INTERVAL 7 DAY + select '前一天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 1 DAY UNION ALL + select '前两天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 2 DAY UNION ALL + select '前三天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 3 DAY UNION ALL + select '前四天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 4 DAY UNION ALL + select '前五天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 5 DAY UNION ALL + select '前六天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 6 DAY UNION ALL + select '前七天' text, count(1) value from bus_command_log where DATE(create_time) = CURDATE() - INTERVAL 7 DAY diff --git a/eladmin/pom.xml b/eladmin/pom.xml index 07ff11d..fd8ed6f 100644 --- a/eladmin/pom.xml +++ b/eladmin/pom.xml @@ -10,8 +10,8 @@ eladmin-common eladmin-logging - eladmin-tools eladmin-system + eladmin-tools eladmin-generator