#update mqtt 上位机
This commit is contained in:
@@ -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("新增成功");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user