forked from dyf/fys-Multi-tenant
添加设备
This commit is contained in:
@ -270,3 +270,26 @@ justauth:
|
||||
client-id: 10**********6
|
||||
client-secret: 1f7d08**********5b7**********29e
|
||||
redirect-uri: ${justauth.address}/social-callback?source=gitea
|
||||
|
||||
|
||||
# 文件存储路径
|
||||
file:
|
||||
mac:
|
||||
path: ~/file/
|
||||
avatar: ~/avatar/
|
||||
linux:
|
||||
path: /home/eladmin/file/
|
||||
avatar: /home/eladmin/avatar/
|
||||
windows:
|
||||
path: C:\eladmin\file\
|
||||
avatar: C:\eladmin\avatar\
|
||||
# 文件大小 /M
|
||||
maxSize: 100
|
||||
avatarMaxSize: 5
|
||||
device:
|
||||
pic: C:\eladmin\file\ #设备图片存储路径
|
||||
ip: http://fuyuanshen.com:81/ #服务器地址
|
||||
app_avatar:
|
||||
pic: C:\eladmin\file\ #设备图片存储路径
|
||||
#ip: http://fuyuanshen.com:81/ #服务器地址
|
||||
ip: https://fuyuanshen.com/ #服务器地址
|
||||
|
@ -39,11 +39,13 @@ public class EncryptUtilsTest {
|
||||
PasswordLoginBody loginBody = new PasswordLoginBody();
|
||||
loginBody.setClientId("e5cd7e4891bf95d1d19206ce24a7b32e");
|
||||
loginBody.setGrantType("password");
|
||||
loginBody.setTenantId("000000");
|
||||
loginBody.setTenantId("894078");
|
||||
loginBody.setCode("9");
|
||||
loginBody.setUuid("04ab60c877ae4bb19e3c09ff5cb2a638");
|
||||
loginBody.setUsername("admin");
|
||||
loginBody.setPassword("admin123");
|
||||
loginBody.setUuid("54b415e4c4574e029aa522b5070538b0");
|
||||
// loginBody.setUsername("admin");
|
||||
// loginBody.setPassword("admin123");
|
||||
loginBody.setUsername("dyf");
|
||||
loginBody.setPassword("123456");
|
||||
|
||||
// 2. 使用更清晰的方式拼接 JSON 字符串
|
||||
String jsonLoginBody = String.format(
|
||||
|
@ -0,0 +1,30 @@
|
||||
package com.fuyuanshen.equipment.constants;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-0609:42
|
||||
*/
|
||||
public class DeviceConstants {
|
||||
|
||||
/**
|
||||
* 文件访问路径前缀
|
||||
*/
|
||||
public static final String FILE_ACCESS_PREFIX = "images";
|
||||
|
||||
/**
|
||||
* 文件访问路径前缀
|
||||
*/
|
||||
public static final String FILE_ACCESS_ISOLATION = "device";
|
||||
|
||||
/**
|
||||
* 错误报告目录
|
||||
*/
|
||||
public static final String ERROR_REPORT_DIR = "error_reports";
|
||||
|
||||
/**
|
||||
* 文件访问IP地址
|
||||
*/
|
||||
// public static final String FILE_ACCESS_IP = "http://fuyuanshen.com:81/";
|
||||
public static final String FILE_ACCESS_IP = "https://fuyuanshen.com/";
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.fuyuanshen.equipment.constants;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-1109:26
|
||||
*/
|
||||
public class ExceptionMessages {
|
||||
|
||||
/**
|
||||
* 禁止管理员操作客户数据的提示
|
||||
*/
|
||||
public static final String ADMIN_OPERATION_NOT_ALLOWED = "警告:请不要随意操作客户数据!";
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.fuyuanshen.equipment.constants;
|
||||
|
||||
public class RedisConstants {
|
||||
|
||||
public static final String APP_FORGOT_PASSWORD_SMS_TOKEN = "app_sms_forgotPassword:";
|
||||
|
||||
public static final String APP_REGISTER_SMS_TOKEN = "app_sms_register:";
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.fuyuanshen.equipment.constants;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-0609:42
|
||||
*/
|
||||
public class RoleConstants {
|
||||
|
||||
/**
|
||||
* 添加客户默认绑定角色
|
||||
*/
|
||||
public static final String ROLE_CUSTOMER = "普通客户";
|
||||
|
||||
}
|
@ -5,10 +5,15 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.common.core.domain.PageResult;
|
||||
import com.fuyuanshen.common.core.domain.ResponseVO;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -19,7 +24,7 @@ import java.io.IOException;
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Slf4j
|
||||
// @Api(tags = "设备:设备管理")
|
||||
@Tag(name = "设备管理", description = "设备:设备管理")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/device")
|
||||
@ -28,7 +33,7 @@ public class DeviceController {
|
||||
private final DeviceService deviceService;
|
||||
|
||||
|
||||
|
||||
@Operation(summary = "分页查询设备列表", security = {@SecurityRequirement(name = "bearer-key")})
|
||||
@GetMapping
|
||||
public ResponseVO<PageResult<Device>> queryDevice(DeviceQueryCriteria criteria) {
|
||||
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
@ -42,19 +47,19 @@ public class DeviceController {
|
||||
return ResponseVO.success(devices);
|
||||
}
|
||||
|
||||
//
|
||||
// @Log("新增设备")
|
||||
// @ApiOperation("新增设备")
|
||||
// @PostMapping(value = "/add")
|
||||
// public ResponseVO<Object> addDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
|
||||
// try {
|
||||
// deviceService.addDevice(deviceForm);
|
||||
// } catch (Exception e) {
|
||||
// log.error("addDevice error: " + e.getMessage());
|
||||
// return ResponseVO.fail(e.getMessage());
|
||||
// }
|
||||
// return ResponseVO.success(null);
|
||||
// }
|
||||
|
||||
// @Log("新增设备")
|
||||
@Operation(summary = "新增设备")
|
||||
@PostMapping(value = "/add")
|
||||
public ResponseVO<Object> addDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
|
||||
try {
|
||||
deviceService.addDevice(deviceForm);
|
||||
} catch (Exception e) {
|
||||
log.error("addDevice error: " + e.getMessage());
|
||||
return ResponseVO.fail(e.getMessage());
|
||||
}
|
||||
return ResponseVO.success(null);
|
||||
}
|
||||
//
|
||||
//
|
||||
// /**
|
||||
|
@ -21,71 +21,71 @@ import lombok.Data;
|
||||
public class Device extends TenantEntity {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
// @ApiModelProperty(value = "ID")
|
||||
// @Schema(value = "ID")
|
||||
private Long id;
|
||||
|
||||
// @ApiModelProperty(value = "设备记录ID")
|
||||
// @Schema(value = "设备记录ID")
|
||||
@TableField(exist = false)
|
||||
private Long assignId;
|
||||
|
||||
// @ApiModelProperty(value = "设备类型")
|
||||
// @Schema(value = "设备类型")
|
||||
private Long deviceType;
|
||||
|
||||
// @ApiModelProperty(value = "设备类型名称")
|
||||
// @Schema(value = "设备类型名称")
|
||||
private String typeName;
|
||||
|
||||
// @ApiModelProperty(value = "客户号")
|
||||
// @Schema(value = "客户号")
|
||||
private Long customerId;
|
||||
|
||||
/**
|
||||
* 当前所有者
|
||||
* current_owner_id
|
||||
*/
|
||||
// @ApiModelProperty(value = "当前所有者")
|
||||
// @Schema(value = "当前所有者")
|
||||
private Long currentOwnerId;
|
||||
|
||||
/**
|
||||
* 原始所有者(创建者)
|
||||
* original_owner_id
|
||||
*/
|
||||
// @ApiModelProperty(value = "原始所有者(创建者)")
|
||||
// @Schema(value = "原始所有者(创建者)")
|
||||
private Long originalOwnerId;
|
||||
|
||||
// @ApiModelProperty(value = "所属客户")
|
||||
// @Schema(value = "所属客户")
|
||||
private String customerName;
|
||||
|
||||
/*@ApiModelProperty(value = "设备编号")
|
||||
/*@Schema(value = "设备编号")
|
||||
private String deviceNo;*/
|
||||
|
||||
// @ApiModelProperty(value = "设备名称")
|
||||
// @Schema(value = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
// @ApiModelProperty(value = "设备图片")
|
||||
// @Schema(value = "设备图片")
|
||||
private String devicePic;
|
||||
|
||||
// @ApiModelProperty(value = "设备MAC")
|
||||
// @Schema(value = "设备MAC")
|
||||
private String deviceMac;
|
||||
|
||||
// @ApiModelProperty(value = "设备IMEI")
|
||||
// @Schema(value = "设备IMEI")
|
||||
private String deviceImei;
|
||||
|
||||
// @ApiModelProperty(value = "设备SN")
|
||||
// @Schema(value = "设备SN")
|
||||
private String deviceSn;
|
||||
|
||||
// @ApiModelProperty(value = "经度")
|
||||
// @Schema(value = "经度")
|
||||
private String longitude;
|
||||
|
||||
// @ApiModelProperty(value = "纬度")
|
||||
// @Schema(value = "纬度")
|
||||
private String latitude;
|
||||
|
||||
// @ApiModelProperty(value = "备注")
|
||||
// @Schema(value = "备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
// @TableField(value = "tenant_id")
|
||||
// // @ApiModelProperty(hidden = true)
|
||||
// // @Schema(hidden = true)
|
||||
// private Long tenantId;
|
||||
|
||||
/**
|
||||
@ -93,7 +93,7 @@ public class Device extends TenantEntity {
|
||||
* 0 失效
|
||||
* 1 正常
|
||||
*/
|
||||
// @ApiModelProperty(value = "设备状态")
|
||||
// @Schema(value = "设备状态")
|
||||
private Integer deviceStatus;
|
||||
|
||||
/**
|
||||
@ -101,7 +101,7 @@ public class Device extends TenantEntity {
|
||||
* 0 未绑定
|
||||
* 1 已绑定
|
||||
*/
|
||||
// @ApiModelProperty(value = "绑定状态")
|
||||
// @Schema(value = "绑定状态")
|
||||
private Integer bindingStatus;
|
||||
|
||||
|
||||
|
@ -18,19 +18,19 @@ import lombok.Data;
|
||||
public class DeviceLog extends TenantEntity {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
// @ApiModelProperty(value = "ID")
|
||||
// @Schema(value = "ID")
|
||||
private Long id;
|
||||
|
||||
// @ApiModelProperty(value = "设备行为")
|
||||
// @Schema(value = "设备行为")
|
||||
private String deviceAction;
|
||||
|
||||
// @ApiModelProperty(value = "设备名称")
|
||||
// @Schema(value = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
// @ApiModelProperty(value = "数据来源")
|
||||
// @Schema(value = "数据来源")
|
||||
private String dataSource;
|
||||
|
||||
// @ApiModelProperty(value = "内容")
|
||||
// @Schema(value = "内容")
|
||||
private String content;
|
||||
|
||||
public void copy(DeviceLog source){
|
||||
|
@ -19,36 +19,36 @@ import lombok.Data;
|
||||
public class DeviceType extends TenantEntity {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
// @ApiModelProperty(value = "ID", hidden = true)
|
||||
// @Schema(value = "ID", hidden = true)
|
||||
private Long id;
|
||||
|
||||
// @ApiModelProperty(value = "客户号")
|
||||
// @Schema(value = "客户号")
|
||||
private Long customerId;
|
||||
|
||||
// @ApiModelProperty(value = "创建该类型的客户")
|
||||
// @Schema(value = "创建该类型的客户")
|
||||
private Long ownerCustomerId;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
// @TableField(value = "tenant_id")
|
||||
// @ApiModelProperty(hidden = true)
|
||||
// @Schema(hidden = true)
|
||||
// private Long tenantId;
|
||||
|
||||
@NotBlank(message = "设备类型名称不能为空")
|
||||
// @ApiModelProperty(value = "类型名称", required = true)
|
||||
// @Schema(value = "类型名称", required = true)
|
||||
private String typeName;
|
||||
|
||||
// @ApiModelProperty(value = "是否支持蓝牙")
|
||||
// @Schema(value = "是否支持蓝牙")
|
||||
private Boolean isSupportBle;
|
||||
|
||||
// @ApiModelProperty(value = "定位方式", example = "0:无;1:GPS;2:基站;3:wifi;4:北斗")
|
||||
// @Schema(value = "定位方式", example = "0:无;1:GPS;2:基站;3:wifi;4:北斗")
|
||||
private String locateMode;
|
||||
|
||||
// @ApiModelProperty(value = "联网方式", example = "0:无;1:4G;2:WIFI")
|
||||
// @Schema(value = "联网方式", example = "0:无;1:4G;2:WIFI")
|
||||
private String networkWay;
|
||||
|
||||
// @ApiModelProperty(value = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
// @Schema(value = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
private String communicationMode;
|
||||
|
||||
|
||||
|
@ -0,0 +1,56 @@
|
||||
package com.fuyuanshen.equipment.domain.form;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 设备表单
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/17
|
||||
**/
|
||||
@Data
|
||||
public class DeviceForm {
|
||||
|
||||
@Schema(title = "ID", hidden = true)
|
||||
private Long id;
|
||||
|
||||
@Schema(title = "设备记录ID")
|
||||
private Long assignId;
|
||||
|
||||
@Schema(title = "设备类型")
|
||||
private Long deviceType;
|
||||
|
||||
@Schema(title = "客户号")
|
||||
private Long customerId;
|
||||
|
||||
/*@Schema(value = "设备编号")
|
||||
private String deviceNo;*/
|
||||
|
||||
@NotBlank(message = "设备名称不能为空")
|
||||
@Schema(title = "设备名称", required = true)
|
||||
private String deviceName;
|
||||
|
||||
@Schema(title = "设备图片存储路径", hidden = true)
|
||||
private String devicePic;
|
||||
|
||||
// @NotBlank(message = "设备MAC不能为空")
|
||||
@Schema(title = "设备MAC")
|
||||
private String deviceMac;
|
||||
|
||||
@Schema(title = "设备IMEI")
|
||||
private String deviceImei;
|
||||
|
||||
// @NotBlank(message = "设备SN不能为空")
|
||||
@Schema(title = "设备SN", required = true)
|
||||
private String deviceSn;
|
||||
|
||||
@Schema(title = "设备图片")
|
||||
private MultipartFile file;
|
||||
|
||||
@Schema(title = "备注")
|
||||
private String remark;
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.fuyuanshen.equipment.domain.dto;
|
||||
package com.fuyuanshen.equipment.domain.query;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@ -16,19 +16,19 @@ import java.util.Set;
|
||||
@Data
|
||||
public class DeviceQueryCriteria {
|
||||
|
||||
// @ApiModelProperty(value = "设备名称")
|
||||
// @Schema(value = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
// @ApiModelProperty(value = "设备类型")
|
||||
// @Schema(value = "设备类型")
|
||||
private Long deviceType;
|
||||
|
||||
// @ApiModelProperty(value = "设备MAC")
|
||||
// @Schema(value = "设备MAC")
|
||||
private String deviceMac;
|
||||
|
||||
// @ApiModelProperty(value = "设备IMEI")
|
||||
// @Schema(value = "设备IMEI")
|
||||
private String deviceImei;
|
||||
|
||||
// @ApiModelProperty(value = "设备SN")
|
||||
// @Schema(value = "设备SN")
|
||||
private String deviceSn;
|
||||
|
||||
/**
|
||||
@ -36,29 +36,29 @@ public class DeviceQueryCriteria {
|
||||
* 0 失效
|
||||
* 1 正常
|
||||
*/
|
||||
// @ApiModelProperty(value = "设备状态 0 失效 1 正常 ")
|
||||
// @Schema(value = "设备状态 0 失效 1 正常 ")
|
||||
private Integer deviceStatus;
|
||||
|
||||
// @ApiModelProperty(value = "创建时间")
|
||||
// @Schema(value = "创建时间")
|
||||
private List<Timestamp> createTime;
|
||||
|
||||
// @ApiModelProperty(value = "页码", example = "1")
|
||||
// @Schema(value = "页码", example = "1")
|
||||
private Integer page = 1;
|
||||
|
||||
// @ApiModelProperty(value = "每页数据量", example = "10")
|
||||
// @Schema(value = "每页数据量", example = "10")
|
||||
private Integer size = 10;
|
||||
|
||||
// @ApiModelProperty(value = "客户id")
|
||||
// @Schema(value = "客户id")
|
||||
private Long customerId;
|
||||
private Set<Long> customerIds;
|
||||
|
||||
// @ApiModelProperty(value = "当前所有者")
|
||||
// @Schema(value = "当前所有者")
|
||||
private Long currentOwnerId;
|
||||
|
||||
// @ApiModelProperty(value = "租户ID")
|
||||
// @Schema(value = "租户ID")
|
||||
private Long tenantId;
|
||||
|
||||
// @ApiModelProperty(value = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
// @Schema(value = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
private Integer communicationMode;
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.fuyuanshen.equipment.enums;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-1818:17
|
||||
*/
|
||||
public enum BindingStatusEnum {
|
||||
UNBOUND(0, "未绑定"), BOUND(1, "已绑定");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
BindingStatusEnum(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static BindingStatusEnum fromCode(int code) {
|
||||
for (BindingStatusEnum status : values()) {
|
||||
if (status.getCode() == code) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid binding status code: " + code);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.fuyuanshen.equipment.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
/**
|
||||
* 通讯方式枚举
|
||||
*
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-2414:11
|
||||
*/
|
||||
public enum CommunicationModeEnum {
|
||||
|
||||
FOUR_G(0, "4G"),
|
||||
BLUETOOTH(1, "蓝牙");
|
||||
|
||||
private final int value;
|
||||
private final String label;
|
||||
|
||||
CommunicationModeEnum(int value, String label) {
|
||||
this.value = value;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据值获取标签
|
||||
*/
|
||||
public static String getLabelByValue(int value) {
|
||||
for (CommunicationModeEnum mode : values()) {
|
||||
if (mode.getValue() == value) {
|
||||
return mode.getLabel();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.fuyuanshen.equipment.enums;
|
||||
|
||||
/**
|
||||
* 设备有效性状态枚举
|
||||
*
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-2113:26
|
||||
*/
|
||||
public enum DeviceActiveStatusEnum {
|
||||
|
||||
INACTIVE(0, "无效"), ACTIVE(1, "有效");
|
||||
|
||||
private final Integer code;
|
||||
private final String description;
|
||||
|
||||
DeviceActiveStatusEnum(Integer code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 code 获取描述
|
||||
*
|
||||
* @param code 状态码
|
||||
* @return 描述信息
|
||||
*/
|
||||
public static String getDescriptionByCode(Integer code) {
|
||||
for (DeviceActiveStatusEnum status : values()) {
|
||||
if (status.getCode().equals(code)) {
|
||||
return status.getDescription();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,45 @@
|
||||
package com.fuyuanshen.equipment.enums;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-1918:50
|
||||
*/
|
||||
public enum DeviceAuthorizationStatus {
|
||||
/**
|
||||
* 未授权
|
||||
*/
|
||||
UNAUTHORIZED(0),
|
||||
|
||||
/**
|
||||
* 已授权
|
||||
*/
|
||||
AUTHORIZED(1);
|
||||
|
||||
private final int value;
|
||||
|
||||
DeviceAuthorizationStatus(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据整数值获取对应的枚举值
|
||||
*
|
||||
* @param value 整数值(0 或 1)
|
||||
* @return 对应的 DeviceAuthorizationStatus 枚举
|
||||
* @throws IllegalArgumentException 如果值不是 0 或 1
|
||||
*/
|
||||
public static DeviceAuthorizationStatus fromValue(int value) {
|
||||
for (DeviceAuthorizationStatus status : values()) {
|
||||
if (status.getValue() == value) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid device authorization status value: " + value);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
package com.fuyuanshen.equipment.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 设备状态枚举
|
||||
*
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-1916:02
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DeviceStatusEnum {
|
||||
|
||||
/**
|
||||
* 失效
|
||||
*/
|
||||
INVALID(0, "失效"),
|
||||
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
NORMAL(1, "正常");
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
private final Integer code;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private final String description;
|
||||
|
||||
/**
|
||||
* 根据状态码获取描述
|
||||
*
|
||||
* @param code 状态码
|
||||
* @return 描述
|
||||
*/
|
||||
public static String getDescriptionByCode(Integer code) {
|
||||
for (DeviceStatusEnum status : DeviceStatusEnum.values()) {
|
||||
if (status.getCode().equals(code)) {
|
||||
return status.getDescription();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.fuyuanshen.equipment.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
/**
|
||||
* 用户类型枚举
|
||||
*
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-1811:14
|
||||
*/
|
||||
public enum UserType {
|
||||
|
||||
APP(0, "APP"), MINI_PROGRAM(1, "小程序");
|
||||
|
||||
private final int value;
|
||||
private final String description;
|
||||
|
||||
UserType(int value, String description) {
|
||||
this.value = value;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据值获取对应的枚举
|
||||
*
|
||||
* @param value 枚举值
|
||||
* @return 对应的枚举对象
|
||||
*/
|
||||
public static UserType fromValue(int value) {
|
||||
for (UserType userType : values()) {
|
||||
if (userType.getValue() == value) {
|
||||
return userType;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid user type value: " + value);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
@ -4,7 +4,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fuyuanshen.common.core.domain.PageResult;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -24,6 +25,13 @@ public interface DeviceService extends IService<Device> {
|
||||
*/
|
||||
PageResult<Device> queryAll(DeviceQueryCriteria criteria, Page<Object> page) throws IOException;
|
||||
|
||||
/**
|
||||
* 新增设备
|
||||
*
|
||||
* @param resources
|
||||
*/
|
||||
void addDevice(DeviceForm resources) throws Exception;
|
||||
|
||||
// /**
|
||||
// * 查询所有数据不分页
|
||||
// *
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@ -7,15 +8,22 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fuyuanshen.common.core.domain.PageResult;
|
||||
import com.fuyuanshen.common.core.utils.PageUtil;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.constants.DeviceConstants;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.enums.DeviceStatusEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -28,6 +36,12 @@ import java.util.*;
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
|
||||
|
||||
@Value("${file.device.pic}")
|
||||
private String filePath;
|
||||
@Value("${file.device.ip}")
|
||||
private String ip;
|
||||
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
|
||||
|
||||
@ -54,97 +68,60 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
return PageUtil.toPage(devices);
|
||||
}
|
||||
|
||||
//
|
||||
// @Override
|
||||
// public List<Device> queryAll(DeviceQueryCriteria criteria) {
|
||||
// return deviceMapper.findAll(criteria);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<Device> queryAllDevices(DeviceQueryCriteria criteria) {
|
||||
// return deviceMapper.findAllDevices(criteria);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void create(Device resources) {
|
||||
// deviceMapper.insert(resources);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 新增设备
|
||||
// *
|
||||
// * @param deviceForm
|
||||
// * @throws Exception
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void addDevice(DeviceForm deviceForm) throws Exception {
|
||||
//
|
||||
// // 获取当前登录用户信息
|
||||
// // Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
// // String username1 = authentication.getName();
|
||||
// // 从缓存获取
|
||||
// // UserDetails currentUser = SecurityUtils.getCurrentUser();
|
||||
// // String username = currentUser.getUsername();
|
||||
// // JwtUserDto jwtUserDto = userCacheManager.getUserCache(username);
|
||||
// User currentUser = userMapper.findByUsername(SecurityUtils.getCurrentUsername());
|
||||
//
|
||||
// if (StringUtils.isNotEmpty(deviceForm.getDeviceMac())) {
|
||||
// QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.eq("device_mac", deviceForm.getDeviceMac());
|
||||
// // queryWrapper.eq("tenant_id", currentUser.getTenantId());
|
||||
// if ((deviceMapper.selectOne(queryWrapper)) != null) {
|
||||
// throw new BadRequestException("设备 mac地址 有误,请仔细核对!!!");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// QueryWrapper<DeviceTypeGrants> deviceTypeGrantsQueryWrapper = new QueryWrapper<>();
|
||||
// deviceTypeGrantsQueryWrapper.eq("customer_id", currentUser.getId());
|
||||
// deviceTypeGrantsQueryWrapper.eq("device_type_id", deviceForm.getDeviceType());
|
||||
// Long count = deviceTypeGrantsMapper.selectCount(deviceTypeGrantsQueryWrapper);
|
||||
// if (count <= 0) {
|
||||
// throw new BadRequestException("请先授权设备类型!!!");
|
||||
// }
|
||||
//
|
||||
// // 保存图片并获取URL
|
||||
// String imageUrl = saveDeviceImage(deviceForm.getFile(), deviceForm.getDeviceMac());
|
||||
// // 设置图片路径
|
||||
// deviceForm.setDevicePic(imageUrl);
|
||||
//
|
||||
// // 转换对象并插入数据库
|
||||
// Device device = new Device();
|
||||
// BeanUtil.copyProperties(deviceForm, device, true);
|
||||
//
|
||||
// // 添加租户ID
|
||||
// device.setTenantId(currentUser.getTenantId());
|
||||
// // 默认状态正常
|
||||
// device.setDeviceStatus(DeviceStatusEnum.NORMAL.getCode());
|
||||
// // SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator();
|
||||
// // device.setId(snowflakeGenerator.next());
|
||||
// device.setCurrentOwnerId(currentUser.getId());
|
||||
// device.setOriginalOwnerId(currentUser.getId());
|
||||
// DeviceType deviceType = deviceTypeMapper.selectById(deviceForm.getDeviceType());
|
||||
// device.setTypeName(deviceType.getTypeName());
|
||||
//
|
||||
// deviceMapper.insert(device);
|
||||
//
|
||||
// // 新增设备类型记录
|
||||
// DeviceAssignments assignments = new DeviceAssignments();
|
||||
// assignments.setDeviceId(device.getId());
|
||||
// assignments.setAssignedAt(LocalDateTime.now());
|
||||
// // 分配者
|
||||
// assignments.setAssignerId(currentUser.getId());
|
||||
// assignments.setAssignerName(currentUser.getUsername());
|
||||
// // 接收者
|
||||
// assignments.setAssigneeId(currentUser.getId());
|
||||
// assignments.setActive(DeviceActiveStatusEnum.ACTIVE.getCode());
|
||||
// String lever = currentUser.getId() + ":";
|
||||
// assignments.setLever(lever);
|
||||
// deviceAssignmentsService.save(assignments);
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* 新增设备
|
||||
*
|
||||
* @param deviceForm
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addDevice(DeviceForm deviceForm) throws Exception {
|
||||
|
||||
// 获取当前登录用户信息
|
||||
// LoginUser user = LoginHelper.getLoginUser();
|
||||
|
||||
// 保存图片并获取URL
|
||||
String imageUrl = saveDeviceImage(deviceForm.getFile(), deviceForm.getDeviceMac());
|
||||
// 设置图片路径
|
||||
deviceForm.setDevicePic(imageUrl);
|
||||
|
||||
// 转换对象并插入数据库
|
||||
Device device = new Device();
|
||||
BeanUtil.copyProperties(deviceForm, device, true);
|
||||
|
||||
deviceMapper.insert(device);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存设备图片并返回访问路径
|
||||
*
|
||||
* @param file MultipartFile
|
||||
* @param deviceMac 设备MAC用于生成唯一文件名
|
||||
* @return 文件存储路径 URL 形式
|
||||
*/
|
||||
private String saveDeviceImage(MultipartFile file, String deviceMac) throws IOException {
|
||||
if (file == null || file.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String originalFileName = file.getOriginalFilename();
|
||||
String fileExtension = originalFileName.substring(originalFileName.lastIndexOf(".") + 1);
|
||||
String newFileName = "PS_" + deviceMac + "." + fileExtension;
|
||||
|
||||
File newFile = new File(filePath + DeviceConstants.FILE_ACCESS_ISOLATION + File.separator + newFileName);
|
||||
|
||||
if (!newFile.getParentFile().exists()) {
|
||||
newFile.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
log.info("图片保存路径: {}", newFile.getAbsolutePath());
|
||||
file.transferTo(newFile);
|
||||
|
||||
return ip + DeviceConstants.FILE_ACCESS_PREFIX + "/" + DeviceConstants.FILE_ACCESS_ISOLATION + "/" + newFileName;
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
|
Reference in New Issue
Block a user