From 5f3929ae16d36349834f95457d1bb26d68428762 Mon Sep 17 00:00:00 2001 From: rqian <1206436827@qq.com> Date: Fri, 7 Aug 2026 09:46:55 +0800 Subject: [PATCH] =?UTF-8?q?#update=20mqtt=20=E4=B8=8A=E4=BD=8D=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 14 +--- .../controller/HostComputerController.java | 67 +++++++++++++++++++ .../service/impl/HostComputerService.java | 25 +++++++ 3 files changed, 94 insertions(+), 12 deletions(-) create mode 100644 maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/HostComputerController.java create mode 100644 maibu-service/maibu-iot-service/src/main/java/com/maibu/service/impl/HostComputerService.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2057c23..2f13d56 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,16 +6,6 @@ - - - - - - - - - - diff --git a/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/HostComputerController.java b/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/HostComputerController.java new file mode 100644 index 0000000..35940b5 --- /dev/null +++ b/maibu-service/maibu-iot-service/src/main/java/com/maibu/controller/HostComputerController.java @@ -0,0 +1,67 @@ +package com.maibu.controller; + +import com.maibu.core.business.WorkRecord; +import com.maibu.core.controller.BaseController; +import com.maibu.core.domain.R; +import com.maibu.service.impl.HostComputerService; +import com.maibu.service.impl.WorkRecordService; +import com.maibu.utils.MinioUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.io.InputStream; + +@RestController +@RequestMapping("/iot/host") +public class HostComputerController extends BaseController { + @Autowired + private MinioUtil minioUtil; + + @Autowired + private WorkRecordService workRecordService; + + @Autowired + private HostComputerService hostComputerService; + + @PostMapping(value = "/add", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public R addWorkRecord( + @RequestPart("file") MultipartFile file, // 接收上传的图片 + @RequestPart("workRecord") WorkRecord workRecord // 接收表单里的 JSON 对象 + ) { + int i = -1; + + WorkRecord workRecord1 = workRecordService.selectWorkRecordByWorkNameAndSiteId(workRecord.getWorkName(), workRecord.getSiteId()); + if (workRecord1 != null) { + return R.fail("该任务已存在"); + } + + try (InputStream inputStream = file.getInputStream()) { + + String fileName = "routePlanImage/rt" + workRecord.getWorkName() + System.currentTimeMillis() + ".png"; + + // 上传到 MinIO + minioUtil.uploadFile(fileName, inputStream, "image/png"); + + // 获取访问 URL + String url = minioUtil.getPublicUrl(fileName); + System.out.println("✅ 图片上传成功,访问地址: " + url); + + // 这里可以把 URL 存到 workRecord 里 + workRecord.setImgUrl(url); + workRecord.setUserId(getUserId()); + workRecord.setOrgId(getLoginUser().getOrgId()); + + i = hostComputerService.saveWorkRecord(workRecord); + } catch (Exception e) { + return R.fail("新增失败: " + e.getMessage()); + } + + return i <= 0 ? R.fail("新增失败") : R.ok("新增成功"); + } + +} diff --git a/maibu-service/maibu-iot-service/src/main/java/com/maibu/service/impl/HostComputerService.java b/maibu-service/maibu-iot-service/src/main/java/com/maibu/service/impl/HostComputerService.java new file mode 100644 index 0000000..f6369d2 --- /dev/null +++ b/maibu-service/maibu-iot-service/src/main/java/com/maibu/service/impl/HostComputerService.java @@ -0,0 +1,25 @@ +package com.maibu.service.impl; + +import com.maibu.core.business.WorkRecord; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class HostComputerService { + + @Autowired + private WorkRecordService workRecordService; + + + public int saveWorkRecord(WorkRecord workRecord) throws Exception { + + // 发送 mqtt 消息到上位机 + + + return workRecordService.addWorkRecord(workRecord); + } + +} + \ No newline at end of file