10 Commits

Author SHA1 Message Date
7d91426414 Merge branch 'dyf-device' 2025-07-18 15:17:18 +08:00
ad06811747 撤回设备 2025-07-18 15:06:39 +08:00
dyf
aeaa906bc9 Merge pull request 'feat(fys-demo): 添加视频上传和处理功能' (#5) from liwenlong/fys-Multi-tenant:jingquan into main
Reviewed-on: #5
2025-07-18 14:03:18 +08:00
36092932bf feat(fys-demo): 添加视频上传和处理功能
- 新增 VideoUploadController 控制器处理视频上传
- 添加视频帧提取和转换为 RGB565 格式功能
- 实现视频文件大小和格式校验
- 优化临时文件创建和清理逻辑
- 引入 javacv-platform依赖进行视频处理
2025-07-18 13:27:26 +08:00
34188f20dd 帐号状态(0正常 1停用) 2025-07-18 11:18:30 +08:00
0fa0e4ab1b 帐号状态(0正常 1停用) 2025-07-18 10:36:02 +08:00
e321dcd652 修改客户状态 2025-07-18 10:23:04 +08:00
78e2538f71 Merge branch 'dyf-device' 2025-07-17 16:41:08 +08:00
faef79e56d return R.ok(); 2025-07-17 16:29:25 +08:00
7b1615ce4d WEB端解绑设备 2025-07-17 16:20:22 +08:00
14 changed files with 363 additions and 107 deletions

View File

@ -17,8 +17,8 @@ public class TestSMSController {
public void testSend() {
// 在创建完SmsBlend实例后再未手动调用注销的情况下框架会持有该实例可以直接通过指定configId来获取想要的配置如果你想使用
// 负载均衡形式获取实例只要使用getSmsBlend的无参重载方法即可如果你仅有一个配置也可以使用该方法
SmsBlend smsBlend = SmsFactory.getSmsBlend("alibaba");
SmsResponse smsResponse = smsBlend.sendMessage("18656573389", "123");
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
SmsResponse smsResponse = smsBlend.sendMessage("18656573389", "1234");
}
}

View File

@ -3,6 +3,7 @@ package com.fuyuanshen.customer.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.crypto.digest.BCrypt;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.domain.ResponseVO;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
@ -51,43 +52,43 @@ public class CustomerController {
@GetMapping(value = "/allCustomer")
@Operation(summary = "查询所有客户")
public ResponseVO<List<Customer>> queryAllCustomer(UserQueryCriteria criteria) {
public R<List<Customer>> queryAllCustomer(UserQueryCriteria criteria) {
List<Customer> customers = customerService.queryAllCustomers(criteria);
return ResponseVO.success(customers);
return R.ok(customers);
}
// @Log("新增客户")
@Operation(summary = "新增客户")
@PostMapping(value = "/addCustomer")
public ResponseVO<Object> addCustomer(@Validated @RequestBody Customer customer) throws BadRequestException {
public R<Void> addCustomer(@Validated @RequestBody Customer customer) throws BadRequestException {
if (StringUtils.isBlank(customer.getPassword())) {
throw new BadRequestException("账号密码不能为空");
}
customer.setPassword(BCrypt.hashpw(customer.getPassword()));
customerService.addCustomer(customer);
return ResponseVO.success("新增客户成功!!!");
return R.ok();
}
// @Log("修改客户")
@Operation(summary = "修改客户")
@PutMapping(value = "updateCustomer")
public ResponseVO<Object> updateCustomer(@RequestBody Customer resources) throws Exception {
public R<Void> updateCustomer(@RequestBody Customer resources) throws Exception {
customerService.updateCustomer(resources);
return ResponseVO.success(null);
return R.ok();
}
// @Log("删除客户")
@Operation(summary = "删除客户")
@DeleteMapping(value = "/deleteCustomer")
public ResponseVO<Object> deleteCustomer(@RequestBody Set<Long> ids) throws BadRequestException {
public R<Void> deleteCustomer(@RequestBody Set<Long> ids) throws BadRequestException {
if (CollectionUtil.isEmpty(ids)) {
throw new BadRequestException("请选择要删除的客户");
}
customerService.delete(ids);
return ResponseVO.success(null);
return R.ok();
}

View File

@ -50,6 +50,12 @@ public class UserQueryCriteria extends BaseEntity {
@Schema(name = "是否启用")
private Boolean enabled;
/**
* 帐号状态0正常 1停用
*/
@Schema(name = "帐号状态0正常 1停用")
private String status;
@Schema(name = "部门ID")
private Long deptId;

View File

@ -58,6 +58,12 @@ public class ConsumerVo extends TenantEntity {
@Schema(name = "是否启用")
private Boolean enabled;
/**
* 帐号状态0正常 1停用
*/
@Schema(name = "帐号状态0正常 1停用")
private String status;
@Schema(name = "是否为admin账号", hidden = true)
private Boolean isAdmin = false;

View File

@ -112,6 +112,11 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
@Override
@Transactional(rollbackFor = Exception.class)
public void updateCustomer(Customer resources) throws Exception {
if (resources.getEnabled()) {
resources.setStatus("0");
} else {
resources.setStatus("1");
}
saveOrUpdate(resources);
}

View File

@ -68,8 +68,8 @@
<if test="criteria.id != null">
and u1.user_id = #{criteria.id}
</if>
<if test="criteria.enabled != null">
and u1.enabled = #{criteria.enabled}
<if test="criteria.status != null">
and u.status = #{criteria.status}
</if>
<if test="criteria.deptIds != null and criteria.deptIds.size() != 0">
and u1.dept_id in
@ -94,7 +94,7 @@
<!-- 分页查询客户 -->
<select id="findCustomers" resultType="com.fuyuanshen.customer.domain.Customer">
select
u.user_id as customerId, u.nick_name , u.user_name, u.enabled, u.create_time
u.user_id as customerId, u.nick_name , u.user_name, u.enabled, u.create_time,u.status
from sys_user u
<where>
<if test="criteria.ids != null and !criteria.ids.isEmpty()">
@ -109,8 +109,8 @@
<if test="criteria.blurry != null and criteria.blurry.trim() != ''">
and u.nick_name like concat('%', TRIM(#{criteria.blurry}), '%')
</if>
<if test="criteria.enabled != null">
and u.enabled = #{criteria.enabled}
<if test="criteria.status != null">
and u.status = #{criteria.status}
</if>
<if test="criteria.params.beginTime != null and criteria.params.endTime != null">
and u.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}
@ -139,8 +139,8 @@
<if test="criteria.blurry != null and criteria.blurry.trim() != ''">
and u.nick_name like concat('%', TRIM(#{criteria.blurry}), '%')
</if>
<if test="criteria.enabled != null">
and u.enabled = #{criteria.enabled}
<if test="criteria.status != null">
and u.status = #{criteria.status}
</if>
<if test="criteria.params.beginTime != null and criteria.params.endTime != null">
and u.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}

View File

@ -103,6 +103,11 @@
<artifactId>fys-common-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,244 @@
package com.fuyuanshen.demo.controller;
import cn.dev33.satoken.annotation.SaIgnore;
import com.fuyuanshen.common.core.domain.R;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.file.Files;
import java.util.Base64;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.Java2DFrameUtils;
import org.springframework.http.ResponseEntity;
@RestController
@RequestMapping("/video")
public class VideoUploadController {
// 可配置项:建议从 application.yml 中读取
private static final int MAX_VIDEO_SIZE = 10 * 1024 * 1024; // 10 MB
private static final int FRAME_RATE = 15; // 每秒抽15帧
private static final int DURATION = 2; // 抽2秒
private static final int TOTAL_FRAMES = FRAME_RATE * DURATION;
private static final int WIDTH = 160;
private static final int HEIGHT = 80;
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@SaIgnore
public R<List<String>> upload(@RequestParam("file") MultipartFile file) {
if (file == null || file.isEmpty()) {
return R.fail("上传文件不能为空");
}
if (!isVideo(file.getOriginalFilename())) {
return R.fail("只允许上传视频文件");
}
if (file.getSize() > MAX_VIDEO_SIZE) {
return R.fail("视频大小不能超过10MB");
}
File tempFile = null;
try {
// 创建临时文件保存上传的视频
tempFile = createTempVideoFile(file);
List<BufferedImage> frames = extractFramesFromVideo(tempFile);
if (frames.isEmpty()) {
return R.fail("无法提取任何帧");
}
// ✅ 新增:保存帧为图片
//saveFramesToLocal(frames, "extracted_frame");
byte[] binaryData = convertFramesToRGB565(frames);
// String base64Data = Base64.getEncoder().encodeToString(binaryData);
//
// return R.ok(base64Data);
// 构造响应头
// 将二进制数据转为 Hex 字符串
// 转换为 Hex 字符串列表
List<String> hexList = bytesToHexList(binaryData);
return R.ok(hexList);
} catch (Exception e) {
return R.fail("视频处理失败:" + e.getMessage());
} finally {
deleteTempFile(tempFile);
}
}
/**
* rgb565 转 hex
*/
private List<String> bytesToHexList(byte[] bytes) {
List<String> hexList = new ArrayList<>();
for (byte b : bytes) {
int value = b & 0xFF;
char high = HEX_ARRAY[value >>> 4];
char low = HEX_ARRAY[value & 0x0F];
hexList.add(String.valueOf(high) + low);
}
return hexList;
}
/**
* 创建临时文件并保存上传的视频
*/
private File createTempVideoFile(MultipartFile file) throws Exception {
File tempFile = Files.createTempFile("upload-", ".mp4").toFile();
file.transferTo(tempFile);
return tempFile;
}
/**
* 从视频中按时间均匀提取指定数量的帧
*/
private List<BufferedImage> extractFramesFromVideo(File videoFile) throws Exception {
List<BufferedImage> frames = new ArrayList<>();
try (FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(videoFile)) {
grabber.start();
// 获取视频总帧数和帧率
long totalFramesInVideo = grabber.getLengthInFrames();
int fps = (int) Math.round(grabber.getFrameRate());
if (fps <= 0) fps = 30;
double durationSeconds = (double) totalFramesInVideo / fps;
if (durationSeconds < DURATION) {
throw new IllegalArgumentException("视频太短,至少需要 " + DURATION + "");
}
// 计算每帧之间的间隔(浮点以实现更精确跳转)
double frameInterval = (double) totalFramesInVideo / TOTAL_FRAMES;
for (int i = 0; i < TOTAL_FRAMES; i++) {
int targetFrameNumber = (int) Math.round(i * frameInterval);
// 避免设置无效帧号
if (targetFrameNumber >= totalFramesInVideo) {
throw new IllegalArgumentException("目标帧超出范围: " + targetFrameNumber + " ");
}
grabber.setFrameNumber(targetFrameNumber);
Frame frame = grabber.grab();
if (frame != null && frame.image != null) {
BufferedImage bufferedImage = Java2DFrameUtils.toBufferedImage(frame);
frames.add(cropImage(bufferedImage, WIDTH, HEIGHT));
} else {
throw new IllegalArgumentException("无法获取第 " + targetFrameNumber + "");
}
}
grabber.stop();
}
return frames;
}
/**
* 将抽取的帧保存到本地,用于调试
*/
private void saveFramesToLocal(List<BufferedImage> frames, String prefix) {
// 指定输出目录
File outputDir = new File("output_frames");
if (!outputDir.exists()) {
outputDir.mkdirs();
}
int index = 0;
for (BufferedImage frame : frames) {
try {
File outputImage = new File(outputDir, prefix + "_" + (index++) + ".png");
ImageIO.write(frame, "png", outputImage);
System.out.println("保存帧图片成功: " + outputImage.getAbsolutePath());
} catch (Exception e) {
throw new IllegalArgumentException("保存帧图片失败 " + e);
}
}
}
/**
* 将所有帧转换为 RGB565 格式字节数组
*/
private byte[] convertFramesToRGB565(List<BufferedImage> frames) throws Exception {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
for (BufferedImage image : frames) {
byte[] rgb565Bytes = convertToRGB565(image);
byteArrayOutputStream.write(rgb565Bytes);
}
return byteArrayOutputStream.toByteArray();
}
/**
* 判断是否是支持的视频格式
*/
private boolean isVideo(String filename) {
String ext = filename.substring(filename.lastIndexOf('.')).toLowerCase();
return Arrays.asList(".mp4", ".avi", ".mov", ".mkv").contains(ext);
}
/**
* 裁剪图像到目标尺寸
*/
private BufferedImage cropImage(BufferedImage img, int targetWidth, int targetHeight) {
int w = Math.min(img.getWidth(), targetWidth);
int h = Math.min(img.getHeight(), targetHeight);
return img.getSubimage(0, 0, w, h);
}
/**
* 将 BufferedImage 转换为 RGB565 格式的字节数组
*/
private byte[] convertToRGB565(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
byte[] result = new byte[width * height * 2]; // RGB565: 2 bytes per pixel
int index = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int rgb = image.getRGB(x, y);
int r = ((rgb >> 16) & 0xFF) >> 3;
int g = ((rgb >> 8) & 0xFF) >> 2;
int b = (rgb & 0xFF) >> 3;
short pixel = (short) ((r << 11) | (g << 5) | b);
result[index++] = (byte) (pixel >> 8); // High byte first
result[index++] = (byte) pixel;
}
}
return result;
}
/**
* 删除临时文件
*/
private void deleteTempFile(File file) {
if (file != null && file.exists()) {
if (!file.delete()) {
throw new IllegalArgumentException("无法删除临时文件: " + file.getAbsolutePath());
}
}
}
}

View File

@ -4,11 +4,13 @@ package com.fuyuanshen.equipment.controller;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.common.core.constant.ResponseMessageConstants;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.domain.ResponseVO;
import com.fuyuanshen.common.core.domain.model.LoginUser;
import com.fuyuanshen.common.core.utils.file.FileUtil;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.customer.mapper.CustomerMapper;
import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.dto.DeviceExcelImportDTO;
@ -49,7 +51,7 @@ import java.util.List;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/device")
public class DeviceController {
public class DeviceController extends BaseController {
private final ISysOssService ossService;
private final DeviceService deviceService;
@ -72,106 +74,106 @@ public class DeviceController {
// @Log("新增设备")
@Operation(summary = "新增设备")
@PostMapping(value = "/add")
public ResponseVO<Object> addDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
public R<Void> addDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
try {
deviceService.addDevice(deviceForm);
} catch (Exception e) {
log.error("addDevice error: " + e.getMessage());
return ResponseVO.fail(e.getMessage());
return R.fail(e.getMessage());
}
return ResponseVO.success(null);
return R.ok();
}
// @Log("修改设备")
@Operation(summary = "修改设备")
@PutMapping(value = "/update")
public ResponseVO<Object> updateDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
public R<Void> updateDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
try {
deviceService.update(deviceForm);
} catch (Exception e) {
e.printStackTrace();
log.error("updateDevice error: " + e.getMessage());
return ResponseVO.fail("出错了");
return R.fail(e.getMessage());
}
return ResponseVO.success(null);
return R.ok();
}
@Operation(summary = "设备详情")
@GetMapping(value = "/detail/{id}")
public ResponseVO<Object> getDevice(@PathVariable Long id) {
public R<Device> getDevice(@PathVariable Long id) {
Device device = deviceService.getById(id);
return ResponseVO.success(device);
return R.ok(device);
}
// @Log("删除设备")
@Operation(summary = "删除设备")
@DeleteMapping(value = "/delete")
public ResponseVO<Object> deleteDevice(@Parameter(name = "传ID数组[]") @RequestBody List<Long> ids) {
public R<Void> deleteDevice(@Parameter(name = "传ID数组[]") @RequestBody List<Long> ids) {
deviceService.deleteAll(ids);
return ResponseVO.success(ResponseMessageConstants.DELETE_SUCCESS);
return R.ok();
}
@Operation(summary = "设备定位")
@GetMapping(value = "/locateDevice")
public ResponseVO<Object> locateDevice(DeviceQueryCriteria criteria) throws IOException {
public R<List<Device>> locateDevice(DeviceQueryCriteria criteria) throws IOException {
List<Device> devices = deviceService.queryAllDevices(criteria);
return ResponseVO.success(devices);
return R.ok(devices);
}
// @Log("分配客户")
@Operation(summary = "分配客户")
@PutMapping(value = "/assignCustomer")
public ResponseVO<Object> assignCustomer(@Validated @RequestBody CustomerVo customerVo) {
public R<Void> assignCustomer(@Validated @RequestBody CustomerVo customerVo) {
deviceService.assignCustomer(customerVo);
return ResponseVO.success(null);
return R.ok();
}
// @Log("撤回设备")
@Operation(summary = "撤回分配设备")
@PostMapping(value = "/withdraw")
public ResponseVO<Object> withdrawDevice(@RequestBody List<Long> ids) {
public R<Void> withdrawDevice(@RequestBody List<Long> ids) {
try {
deviceService.withdrawDevice(ids);
} catch (Exception e) {
log.error("updateDevice error: " + e.getMessage());
return ResponseVO.fail("出错了");
return R.fail(e.getMessage());
}
return ResponseVO.success(null);
return R.ok();
}
/**
* @param deviceForm
* @param id
* @return
* @ModelAttribute 主要用于将请求参数绑定到 Java 对象上,它会从 HTTP 请求的查询参数Query Parameters
* 或表单数据Form Data中提取值并自动填充到指定的对象属性中。
*/
// @Log("解绑设备")
@Operation(summary = "解绑设备")
@PostMapping(value = "/unbind")
public ResponseVO<Object> unbindDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
deviceService.unbindDevice(deviceForm);
return ResponseVO.success("解绑成功!!!");
@Operation(summary = "WEB端解绑设备")
@GetMapping(value = "/unbind")
public R<Void> unbindDevice(@Validated Long id) {
return toAjax(deviceService.webUnBindDevice(id));
}
@Operation(summary = "导出数据设备")
@GetMapping(value = "/download")
public void exportDevice(HttpServletResponse response, DeviceQueryCriteria criteria) throws IOException {
public R<Void> exportDevice(HttpServletResponse response, DeviceQueryCriteria criteria) throws IOException {
List<Device> devices = deviceService.queryAll(criteria);
exportService.export(devices, response);
return R.ok();
}
@Operation(summary = "导入设备数据")
@PostMapping(value = "/import", consumes = "multipart/form-data")
public ResponseVO<ImportResult> importData(@Parameter(name = "文件", required = true) @RequestPart("file") MultipartFile file) throws BadRequestException {
public R<ImportResult> importData(@Parameter(name = "文件", required = true) @RequestPart("file") MultipartFile file) throws BadRequestException {
String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
if (!("xlsx".equalsIgnoreCase(suffix))) {
@ -195,13 +197,13 @@ public class DeviceController {
// 设置响应消息
String message = String.format("成功导入 %d 条数据,失败 %d 条", result.getSuccessCount(), result.getFailureCount());
// 返回带有正确泛型的响应
return ResponseVO.<ImportResult>success(message, result);
return R.ok(message, result);
} catch (Exception e) {
log.error("导入设备数据出错: {}", e.getMessage(), e);
// 在异常情况下,设置默认结果
String errorMessage = String.format("导入失败: %s。成功 %d 条,失败 %d 条", e.getMessage(), result.getSuccessCount(), result.getFailureCount());
// 使用新方法确保类型正确
return ResponseVO.<ImportResult>fail(errorMessage, result);
return R.fail(errorMessage, result);
}
}

View File

@ -1,6 +1,7 @@
package com.fuyuanshen.equipment.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.domain.ResponseVO;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.equipment.domain.DeviceType;
@ -40,43 +41,45 @@ public class DeviceTypeController {
@GetMapping(value = "/all")
@Operation(summary = "查询所有设备类型")
public ResponseVO<Object> queryDeviceTypes() {
public R<List<DeviceType>> queryDeviceTypes() {
List<DeviceType> deviceTypes = deviceTypeService.queryDeviceTypes();
return ResponseVO.success(deviceTypes);
return R.ok(deviceTypes);
}
// @Log("新增设备类型")
@Operation(summary = "新增设备类型")
@PostMapping(value = "/add")
public ResponseVO<Object> createDeviceType(@Validated @RequestBody DeviceType resources) {
public R<Void> createDeviceType(@Validated @RequestBody DeviceType resources) {
deviceTypeService.create(resources);
return ResponseVO.success(null);
return R.ok();
}
// @Log("修改设备类型")
@Operation(summary = "修改设备类型")
@PutMapping(value = "/update")
public ResponseVO<Object> updateDeviceType(@Validated @RequestBody DeviceTypeForm resources) {
public R<Void> updateDeviceType(@Validated @RequestBody DeviceTypeForm resources) {
deviceTypeService.update(resources);
return ResponseVO.success(null);
return R.ok();
}
// @Log("删除设备类型")
@Operation(summary = "删除设备类型")
@DeleteMapping(value = "/delete")
public ResponseVO<Object> deleteDeviceType(@Parameter(name = "传ID数组[]") @RequestBody List<Long> ids) {
public R<Void> deleteDeviceType(@Parameter(name = "传ID数组[]") @RequestBody List<Long> ids) {
deviceTypeService.deleteAll(ids);
return ResponseVO.success("删除成功!!!");
return R.ok();
}
@GetMapping(value = "/communicationMode")
@Operation(summary = "获取设备类型通讯方式")
public ResponseVO<DeviceType> getCommunicationMode(@Parameter(name = "设备类型ID", required = true) Long id) {
return ResponseVO.success(deviceTypeService.getCommunicationMode(id));
public R<DeviceType> getCommunicationMode(@Parameter(name = "设备类型ID", required = true) Long id) {
DeviceType communicationMode = deviceTypeService.getCommunicationMode(id);
return R.ok(communicationMode);
}
}

View File

@ -34,7 +34,7 @@ public class DeviceAssignments extends TenantEntity {
private Long fromCustomerId;
/**
* 接收方
* 接收方(当前设备所处位置)
*/
private Long toCustomerId;

View File

@ -98,4 +98,12 @@ public interface DeviceService extends IService<Device> {
* @return
*/
Boolean queryDevice(String mac);
/**
* WEB端解绑设备
*
* @param id
* @return
*/
int webUnBindDevice(Long id);
}

View File

@ -320,9 +320,9 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
List<DeviceTypeGrants> deviceTypeGrants = new ArrayList<>();
for (DeviceAssignments assignment : assignments) {
if (assignment.getToCustomerId() != null) {
if (assignment.getToCustomerId() != null && assignment.getToCustomerId() != 0L) {
log.info("设备已经分配客户!!!");
continue;
throw new RuntimeException("设备已经分配客户!!!");
}
Device device = deviceMapper.selectById(assignment.getDeviceId());
@ -413,54 +413,6 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
}
/**
* 撤回设备
*
* @param ids
*/
// @Override
// public void withdrawDevice(List<Long> ids) {
// ids.forEach((id) -> {
// List<Device> deviceChain = getDeviceChain(id);
// deviceChain.forEach((device) -> {
// device.setDeviceStatus(DeviceStatusEnum.INVALID.getCode());
// deviceMapper.updateById(device);
// });
// });
//
// ids.forEach((id) -> {
// Device device = new Device();
// device.setId(id);
// device.setCustomerId(null);
// device.setCustomerName("");
// deviceMapper.updateById(device);
// });
//
// }
//
//
// public List<Device> getDeviceChain(Long originalDeviceId) {
// List<Device> chain = new ArrayList<>();
// Set<Long> visited = new HashSet<>(); // 防止循环引用
// findNext(chain, visited, originalDeviceId);
// return chain;
// }
//
// private void findNext(List<Device> chain, Set<Long> visited, Long currentOriginalDeviceId) {
// if (visited.contains(currentOriginalDeviceId)) {
// log.info("检测到循环引用,终止递归");
// return;
// }
// visited.add(currentOriginalDeviceId);
//
// List<Device> devices = deviceMapper.findByOriginalDeviceId(currentOriginalDeviceId);
// for (Device device : devices) {
// chain.add(device);
// findNext(chain, visited, device.getId());
// }
// }
/**
* 撤回设备
*
@ -475,7 +427,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
Device device = deviceMapper.selectById(assignment.getDeviceId());
// 接收者
assignment.setAssigneeName("");
assignment.setToCustomerId(null);
assignment.setToCustomerId(0L);
deviceAssignmentsMapper.updateById(assignment);
// 获取所有已分配的设备
@ -580,6 +532,22 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
}
/**
* WEB端解绑设备
*
* @param id
* @return
*/
@Override
public int webUnBindDevice(Long id) {
DeviceAssignments deviceAssignment = deviceAssignmentsMapper.selectById(id);
if (deviceAssignment == null) {
throw new RuntimeException("请先将设备入库!!!");
}
return unBindDevice(deviceAssignment.getDeviceId());
}
/**
* 查询设备MAC号
*

View File

@ -37,6 +37,8 @@
<lombok.version>1.18.36</lombok.version>
<bouncycastle.version>1.80</bouncycastle.version>
<justauth.version>1.16.7</justauth.version>
<javacv-platform.version>1.5.7</javacv-platform.version>
<!-- 离线IP地址定位库 -->
<ip2region.version>2.7.0</ip2region.version>
@ -142,6 +144,12 @@
<version>${justauth.version}</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>${javacv-platform.version}</version> <!-- 使用合适的版本号 -->
</dependency>
<!-- common 的依赖配置-->
<dependency>
<groupId>com.fuyuanshen</groupId>