设备操作接口

This commit is contained in:
gong
2025-11-24 14:21:01 +08:00
parent ee41fd2253
commit 97b03a8495
9 changed files with 395 additions and 3 deletions

View File

@@ -0,0 +1,63 @@
package com.czg.controller.admin;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.system.dto.SysDevicesDTO;
import com.czg.system.dto.SysDevicesPageDTO;
import com.czg.system.service.SysDevicesService;
import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 设备管理
*
* @author yjjie
* @date 2025/11/24 14:02
*/
@RestController
@RequestMapping("/admin/devices")
public class SysDeviceController {
@Resource
private SysDevicesService sysDevicesService;
/**
* 新增设备
*/
@PostMapping
@SaAdminCheckPermission(value = "devices:add", name = "新增设备")
public CzgResult<Long> addDevice(@RequestBody @Validated(InsertGroup.class) SysDevicesDTO param) {
return CzgResult.success(sysDevicesService.addDevice(param));
}
/**
* 修改设备
*/
@PutMapping
@SaAdminCheckPermission(value = "devices:update", name = "修改设备")
public CzgResult<Long> updateDevice(@RequestBody @Validated(UpdateGroup.class) SysDevicesDTO param) {
return CzgResult.success(sysDevicesService.updateDevice(param));
}
/**
* 删除设备
*/
@DeleteMapping("/{id}")
@SaAdminCheckPermission(value = "devices:delete", name = "删除设备")
public CzgResult<Long> deleteDevice(@PathVariable Long id) {
return CzgResult.success(sysDevicesService.deleteDevice(id));
}
/**
* 查询设备分页
*/
@GetMapping("page")
@SaAdminCheckPermission(value = "devices:page", name = "查询设备分页")
public CzgResult<Page<SysDevicesDTO>> queryDevice(SysDevicesPageDTO param) {
return CzgResult.success(sysDevicesService.queryDevice(param));
}
}

View File

@@ -0,0 +1,82 @@
package com.czg.system.dto;
import java.io.Serializable;
import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField;
import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.experimental.Accessors;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 设备管理 实体类。
*
* @author ww
* @since 2025-11-24
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class SysDevicesDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@NotNull(message = "id不能为空", groups = {UpdateGroup.class})
private Long id;
/**
* 设备 sn收银机用 Mac 地址
*/
@NotBlank(message = "设备sn不能为空", groups = {UpdateGroup.class, InsertGroup.class})
private String deviceSn;
/**
* 设备类型scanBox 扫码盒子cashMachine 收银机printer 打印机
*/
@NotBlank(message = "设备类型不能为空", groups = {UpdateGroup.class, InsertGroup.class})
@Pattern(regexp = "^(scanBox|cashMachine|printer)$", message = "设备类型格式错误")
private String deviceType;
/**
* 连接类型usb4gwifi
*/
@NotBlank(message = "连接类型不能为空", groups = {UpdateGroup.class, InsertGroup.class})
@Pattern(regexp = "^(usb|4g|wifi)$", message = "连接类型格式错误")
private String connType;
/**
* 在线状态0 离线1 在线
*/
private Integer unlineStatus;
/**
* 最后上线时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime lastUnlineTime;
/**
* 离线时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime offlineTime;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,43 @@
package com.czg.system.dto;
import lombok.Data;
/**
* 设备管理 分页参数
*
* @author yjjie
* @date 2025/11/24 14:17
*/
@Data
public class SysDevicesPageDTO {
/**
* 设备 sn
*/
private String deviceSn;
/**
* 设备类型
*/
private String deviceType;
/**
* 连接类型usb4gwifi
*/
private String connType;
/**
* 在线状态0 离线1 在线
*/
private Integer unlineStatus;
/**
* 页码
*/
private Integer page;
/**
* 页大小
*/
private Integer size;
}

View File

@@ -0,0 +1,74 @@
package com.czg.system.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 设备管理 实体类。
*
* @author ww
* @since 2025-11-24
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("sys_devices")
public class SysDevices implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@Id
private Long id;
/**
* 设备 sn收银机用 Mac 地址
*/
private String deviceSn;
/**
* 设备类型scanBox 扫码盒子cashMachine 收银机printer 打印机
*/
private String deviceType;
/**
* 连接类型usb4gwifi
*/
private String connType;
/**
* 在线状态0 离线1 在线
*/
private Integer unlineStatus;
/**
* 最后上线时间
*/
private LocalDateTime lastUnlineTime;
/**
* 离线时间
*/
private LocalDateTime offlineTime;
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,24 @@
package com.czg.system.service;
import com.czg.system.dto.SysDevicesDTO;
import com.czg.system.dto.SysDevicesPageDTO;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import com.czg.system.entity.SysDevices;
/**
* 设备管理 服务层。
*
* @author ww
* @since 2025-11-24
*/
public interface SysDevicesService extends IService<SysDevices> {
Long addDevice(SysDevicesDTO reqDTO);
Long updateDevice(SysDevicesDTO reqDTO);
Long deleteDevice(Long id);
Page<SysDevicesDTO> queryDevice(SysDevicesPageDTO reqDTO);
}

View File

@@ -29,12 +29,12 @@ public class Main {
// orSqlTest();
// String packageName = "system";
String packageName = "system";
// String packageName = "account";
// String packageName = "product";
String packageName = "market";
// String packageName = "market";
// tableName 指定需要生成的表
String tableName = "mk_distribution_withdraw_flow";
String tableName = "sys_devices";
String author = "ww";
//是否生成DTO实体 默认生成
boolean isGenerateDto = true;

View File

@@ -0,0 +1,14 @@
package com.czg.service.system.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.system.entity.SysDevices;
/**
* 设备管理 映射层。
*
* @author ww
* @since 2025-11-24
*/
public interface SysDevicesMapper extends BaseMapper<SysDevices> {
}

View File

@@ -0,0 +1,85 @@
package com.czg.service.system.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.exception.CzgException;
import com.czg.service.system.mapper.SysDevicesMapper;
import com.czg.system.dto.SysDevicesDTO;
import com.czg.system.dto.SysDevicesPageDTO;
import com.czg.system.entity.SysDevices;
import com.czg.system.service.SysDevicesService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* 设备管理 服务层实现。
*
* @author ww
* @since 2025-11-24
*/
@Service
public class SysDevicesServiceImpl extends ServiceImpl<SysDevicesMapper, SysDevices> implements SysDevicesService {
@Override
public Long addDevice(SysDevicesDTO reqDTO) {
// 检查 sn 是否存在
if (exists(query().eq(SysDevices::getDeviceSn, reqDTO.getDeviceSn()))) {
throw new CzgException("设备sn已存在");
}
SysDevices devices = BeanUtil.toBean(reqDTO, SysDevices.class);
save(devices);
return devices.getId();
}
@Override
public Long updateDevice(SysDevicesDTO reqDTO) {
// 检查 sn 存在
if (exists(query().ne(SysDevices::getId, reqDTO.getId()).eq(SysDevices::getDeviceSn, reqDTO.getDeviceSn()))) {
throw new CzgException("设备sn已存在");
}
SysDevices devices = getById(reqDTO.getId());
if (devices == null) {
throw new CzgException("设备不存在");
}
devices.setDeviceSn(reqDTO.getDeviceSn());
devices.setDeviceType(reqDTO.getDeviceType());
devices.setConnType(reqDTO.getConnType());
devices.setUnlineStatus(reqDTO.getUnlineStatus());
updateById(devices);
return devices.getId();
}
@Override
public Long deleteDevice(Long id) {
SysDevices devices = getById(id);
if (devices == null) {
throw new CzgException("设备不存在");
}
removeById(id);
return id;
}
@Override
public Page<SysDevicesDTO> queryDevice(SysDevicesPageDTO reqDTO) {
QueryWrapper wrapper = new QueryWrapper();
if (StrUtil.isNotBlank(reqDTO.getDeviceSn())) {
wrapper.like(SysDevices::getDeviceSn, reqDTO.getDeviceSn());
}
if (StrUtil.isNotBlank(reqDTO.getDeviceType())) {
wrapper.eq(SysDevices::getDeviceType, reqDTO.getDeviceType());
}
if (StrUtil.isNotBlank(reqDTO.getConnType())) {
wrapper.eq(SysDevices::getConnType, reqDTO.getConnType());
}
return page(Page.of(reqDTO.getPage(), reqDTO.getSize()), wrapper).map(devices -> BeanUtil.toBean(devices, SysDevicesDTO.class));
}
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.system.mapper.SysDevicesMapper">
</mapper>