Compare commits
8 Commits
f9f5569504
...
53356957f3
| Author | SHA1 | Date | |
|---|---|---|---|
| 53356957f3 | |||
| 440aec266b | |||
| 933e74235f | |||
| eac1b2e016 | |||
| 0969a7cd1f | |||
| 20f3edaeec | |||
| 4add59d197 | |||
| b89d962a50 |
@ -144,6 +144,10 @@ public class CaptchaController {
|
||||
Expression exp = parser.parseExpression(StringUtils.remove(code, "="));
|
||||
code = exp.getValue(String.class);
|
||||
}
|
||||
|
||||
log.info("图片验证码:{}", code);
|
||||
log.info("图片验证码uuid:{}", uuid);
|
||||
|
||||
RedisUtils.setCacheObject(verifyKey, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||
CaptchaVo captchaVo = new CaptchaVo();
|
||||
captchaVo.setUuid(uuid);
|
||||
|
||||
@ -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/ #服务器地址
|
||||
|
||||
@ -208,6 +208,8 @@ springdoc:
|
||||
packages-to-scan: com.fuyuanshen.generator
|
||||
- group: 5.工作流模块
|
||||
packages-to-scan: com.fuyuanshen.workflow
|
||||
- group: 设备管理模块
|
||||
packages-to-scan: com.fuyuanshen.equipment
|
||||
|
||||
# 防止XSS攻击
|
||||
xss:
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
package com.fuyuanshen.common.core.constant;
|
||||
|
||||
/**
|
||||
* 响应消息常量类
|
||||
*
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-2117:21
|
||||
*/
|
||||
public class ResponseMessageConstants {
|
||||
|
||||
/**
|
||||
* 删除操作成功提示
|
||||
*/
|
||||
public static final String DELETE_SUCCESS = "删除成功!";
|
||||
|
||||
/**
|
||||
* 新增操作成功提示
|
||||
*/
|
||||
public static final String SAVE_SUCCESS = "新增成功!";
|
||||
|
||||
/**
|
||||
* 更新操作成功提示
|
||||
*/
|
||||
public static final String UPDATE_SUCCESS = "更新成功!";
|
||||
|
||||
// 可根据业务需求继续扩展其他常用提示信息
|
||||
|
||||
}
|
||||
@ -26,6 +26,11 @@
|
||||
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.therapi</groupId>
|
||||
<artifactId>therapi-runtime-javadoc</artifactId>
|
||||
|
||||
@ -0,0 +1,78 @@
|
||||
package com.fuyuanshen.common.encrypt.utils;
|
||||
|
||||
import com.fuyuanshen.common.core.domain.model.PasswordLoginBody;
|
||||
|
||||
/**
|
||||
* 登录测试
|
||||
*
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-3014:29
|
||||
*/
|
||||
public class EncryptUtilsTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// System.out.println(EncryptUtils.encryptByBase64("123456"));
|
||||
|
||||
System.out.println(EncryptUtils.encryptByBase64("1234567890abcdef"));
|
||||
|
||||
String g = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdHnzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ==";
|
||||
String s = "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKNPuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gAkM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWowcSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99EcvDQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthhYhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3UP8iWi1Qw0Y=";
|
||||
|
||||
|
||||
String s1 = EncryptUtils.encryptByRsa("MTIzNDU2Nzg5MGFiY2RlZg==", g);
|
||||
System.out.println(s1);
|
||||
String s2 = EncryptUtils.decryptByRsa("jJPaW7hgFXD/gjdkrfBOEUdXpPZnQg/LZUASoOJAOLU/XRVXO/5666CzyALjw7neK1ujvRuys4MdKCvr9cRARw==", s);
|
||||
System.out.println(s2);
|
||||
|
||||
String s3 = EncryptUtils.decryptByBase64(s2);
|
||||
System.out.println(s3);
|
||||
|
||||
String s4 = EncryptUtils.encryptByAes("123456", s3);
|
||||
System.out.println(s4);
|
||||
|
||||
String s5 = EncryptUtils.decryptByAes(s4, s3);
|
||||
System.out.println(s5);
|
||||
|
||||
|
||||
// 1. 构造 LoginBody 对象
|
||||
PasswordLoginBody loginBody = new PasswordLoginBody();
|
||||
loginBody.setClientId("e5cd7e4891bf95d1d19206ce24a7b32e");
|
||||
loginBody.setGrantType("password");
|
||||
loginBody.setTenantId("894078");
|
||||
loginBody.setCode("21");
|
||||
loginBody.setUuid("39785885a3ef42d59501502848cd1dcb");
|
||||
// loginBody.setUsername("admin");
|
||||
// loginBody.setPassword("admin123");
|
||||
loginBody.setUsername("dyf");
|
||||
loginBody.setPassword("123456");
|
||||
|
||||
// 2. 使用更清晰的方式拼接 JSON 字符串
|
||||
String jsonLoginBody = String.format(
|
||||
"{"
|
||||
+ "\"clientId\":\"%s\","
|
||||
+ "\"grantType\":\"%s\","
|
||||
+ "\"tenantId\":\"%s\","
|
||||
+ "\"code\":\"%s\","
|
||||
+ "\"uuid\":\"%s\","
|
||||
+ "\"username\":\"%s\","
|
||||
+ "\"password\":\"%s\""
|
||||
+ "}",
|
||||
loginBody.getClientId(),
|
||||
loginBody.getGrantType(),
|
||||
loginBody.getTenantId(),
|
||||
loginBody.getCode(),
|
||||
loginBody.getUuid(),
|
||||
loginBody.getUsername(),
|
||||
loginBody.getPassword()
|
||||
);
|
||||
|
||||
|
||||
String S5 = EncryptUtils.encryptByAes(jsonLoginBody, s3);
|
||||
System.out.println(S5);
|
||||
|
||||
String S6 = EncryptUtils.decryptByAes(S5, s3);
|
||||
System.out.println(S6);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -101,8 +101,19 @@
|
||||
<artifactId>fys-common-sse</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>poi-ooxml-schemas</artifactId>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
</project>
|
||||
|
||||
@ -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 = "普通客户";
|
||||
|
||||
}
|
||||
@ -2,16 +2,28 @@ package com.fuyuanshen.equipment.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.common.core.constant.ResponseMessageConstants;
|
||||
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.dto.ImportResult;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.CustomerVo;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -19,7 +31,7 @@ import java.io.IOException;
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Slf4j
|
||||
// @Api(tags = "设备:设备管理")
|
||||
@Tag(name = "设备管理", description = "设备:设备管理")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/device")
|
||||
@ -28,7 +40,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,165 +54,139 @@ 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);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * @param deviceForm
|
||||
// * @return
|
||||
// * @ModelAttribute 主要用于将请求参数绑定到 Java 对象上,它会从 HTTP 请求的查询参数(Query Parameters)
|
||||
// * 或表单数据(Form Data)中提取值,并自动填充到指定的对象属性中。
|
||||
// */
|
||||
// @Log("解绑设备")
|
||||
// @ApiOperation("解绑设备")
|
||||
// @PostMapping(value = "/unbind")
|
||||
// public ResponseVO<Object> unbindDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
|
||||
// deviceService.unbindDevice(deviceForm);
|
||||
// return ResponseVO.success("解绑成功!!!");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Log("修改设备")
|
||||
// @ApiOperation("修改设备")
|
||||
// @PutMapping(value = "/update")
|
||||
// public ResponseVO<Object> updateDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
|
||||
// try {
|
||||
// deviceService.update(deviceForm);
|
||||
// } catch (Exception e) {
|
||||
// log.error("updateDevice error: " + e.getMessage());
|
||||
// return ResponseVO.fail("出错了");
|
||||
// }
|
||||
// return ResponseVO.success(null);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Log("分配客户")
|
||||
// @ApiOperation("分配客户")
|
||||
// @PutMapping(value = "/assignCustomer")
|
||||
// public ResponseVO<Object> assignCustomer(@Validated @RequestBody CustomerVo customerVo) {
|
||||
// deviceService.assignCustomer(customerVo);
|
||||
// return ResponseVO.success(null);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Log("撤回设备")
|
||||
// @ApiOperation("撤回设备")
|
||||
// @PostMapping(value = "/withdraw")
|
||||
// public ResponseVO<Object> withdrawDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
|
||||
// try {
|
||||
// deviceService.withdrawDevice(deviceForm);
|
||||
// } catch (Exception e) {
|
||||
// log.error("updateDevice error: " + e.getMessage());
|
||||
// return ResponseVO.fail("出错了");
|
||||
// }
|
||||
// return ResponseVO.success(null);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @ApiOperation("设备详情")
|
||||
// @GetMapping(value = "/detail/{id}")
|
||||
// public ResponseVO<Object> getDevice(@PathVariable Long id) {
|
||||
// Device device = deviceService.getById(id);
|
||||
// return ResponseVO.success(device);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Log("删除设备")
|
||||
// @ApiOperation("删除设备")
|
||||
// @DeleteMapping(value = "/delete")
|
||||
// public ResponseVO<Object> deleteDevice(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> ids) {
|
||||
// // deviceService.deleteAll(ids);
|
||||
// deviceService.deleteAssign(ids);
|
||||
// return ResponseVO.success(ResponseMessageConstants.DELETE_SUCCESS);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @ApiOperation("导出数据设备")
|
||||
// @GetMapping(value = "/download")
|
||||
// public void exportDevice(HttpServletResponse response, DeviceQueryCriteria criteria) throws IOException {
|
||||
// // deviceService.download(deviceService.queryAll(criteria), response);
|
||||
// User onlineuser = userService.findByName(SecurityUtils.getCurrentUsername());
|
||||
//
|
||||
// // 只能看到自己的创建的设备,以及被分配的设备。
|
||||
// if (onlineuser.getTenantId() != null && !onlineuser.getTenantId().equals(UserConstants.SUPER_ADMIN_ID)) {
|
||||
// // criteria.setTenantId(onlineuser.getTenantId());
|
||||
// criteria.setCurrentOwnerId(onlineuser.getId());
|
||||
// }
|
||||
// exportService.export(deviceService.queryAll(criteria), response);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @ApiOperation("设备定位")
|
||||
// @GetMapping(value = "/locateDevice")
|
||||
// public ResponseVO<Object> locateDevice(DeviceQueryCriteria criteria) throws IOException {
|
||||
// List<Device> devices = deviceService.queryAllDevices(criteria);
|
||||
// return ResponseVO.success(devices);
|
||||
// }
|
||||
//
|
||||
// @ApiOperation("设备数据模板下载")
|
||||
// @GetMapping("/template")
|
||||
// public void download(HttpServletRequest request, HttpServletResponse response) throws IOException, URISyntaxException {
|
||||
// // String filePath = "resources" + File.separator + "template" + File.separator + "device_import.csv";
|
||||
// Path path = Paths.get(ClassLoader.getSystemResource("template/device_import.csv").toURI());
|
||||
// FileUtil.downloadFile(request, response, new File(path.toUri()), true);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @ApiOperation("导入设备数据")
|
||||
// @PostMapping(value = "/import", consumes = "multipart/form-data")
|
||||
// public ResponseVO<ImportResult> importData(@ApiParam(value = "文件", required = true) @RequestPart("file") MultipartFile file) {
|
||||
//
|
||||
// String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
|
||||
// if (!("xlsx".equalsIgnoreCase(suffix))) {
|
||||
// throw new BadRequestException("只能上传Excel——xlsx格式文件");
|
||||
// }
|
||||
//
|
||||
// ImportResult result = new ImportResult();
|
||||
// try {
|
||||
// User currentUser = userMapper.findByUsername(SecurityUtils.getCurrentUsername());
|
||||
// DeviceImportParams params = DeviceImportParams.builder().ip(ip).deviceService(deviceService).tenantId(currentUser.getTenantId()).file(file).filePath(filePath).deviceMapper(deviceMapper).deviceAssignmentsService(deviceAssignmentsService).deviceTypeMapper(deviceTypeMapper).userId(currentUser.getId()).userMapper(userMapper).build();
|
||||
// // 创建监听器
|
||||
// UploadDeviceDataListener listener = new UploadDeviceDataListener(params);
|
||||
// // 读取Excel
|
||||
// EasyExcel.read(file.getInputStream(), DeviceExcelImportDTO.class, listener).sheet().doRead();
|
||||
// // 获取导入结果
|
||||
// result = listener.getImportResult();
|
||||
// // 设置响应消息
|
||||
// String message = String.format("成功导入 %d 条数据,失败 %d 条", result.getSuccessCount(), result.getFailureCount());
|
||||
// // 返回带有正确泛型的响应
|
||||
// return ResponseVO.<ImportResult>success(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);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @ApiOperation("下载导入错误报告")
|
||||
// @GetMapping("/download-import-errors")
|
||||
// public ResponseEntity<byte[]> downloadImportErrors(@RequestParam String errorData) {
|
||||
// try {
|
||||
// // 解码Base64字符串
|
||||
// byte[] data = Base64.getDecoder().decode(errorData);
|
||||
// return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"import_errors.xlsx\"").contentType(MediaType.APPLICATION_OCTET_STREAM).body(data);
|
||||
// } catch (Exception e) {
|
||||
// log.error("下载错误报告失败", e);
|
||||
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||
// }
|
||||
// }
|
||||
|
||||
// @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);
|
||||
}
|
||||
|
||||
|
||||
// @Log("修改设备")
|
||||
@Operation(summary = "修改设备")
|
||||
@PutMapping(value = "/update")
|
||||
public ResponseVO<Object> updateDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
|
||||
try {
|
||||
deviceService.update(deviceForm);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("updateDevice error: " + e.getMessage());
|
||||
return ResponseVO.fail("出错了");
|
||||
}
|
||||
return ResponseVO.success(null);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "设备详情")
|
||||
@GetMapping(value = "/detail/{id}")
|
||||
public ResponseVO<Object> getDevice(@PathVariable Long id) {
|
||||
Device device = deviceService.getById(id);
|
||||
return ResponseVO.success(device);
|
||||
}
|
||||
|
||||
|
||||
// @Log("删除设备")
|
||||
@Operation(summary = "删除设备")
|
||||
@DeleteMapping(value = "/delete")
|
||||
public ResponseVO<Object> deleteDevice(@Parameter(name = "传ID数组[]") @RequestBody List<Long> ids) {
|
||||
deviceService.deleteAll(ids);
|
||||
// deviceService.deleteAssign(ids);
|
||||
return ResponseVO.success(ResponseMessageConstants.DELETE_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "设备定位")
|
||||
@GetMapping(value = "/locateDevice")
|
||||
public ResponseVO<Object> locateDevice(DeviceQueryCriteria criteria) throws IOException {
|
||||
List<Device> devices = deviceService.queryAllDevices(criteria);
|
||||
return ResponseVO.success(devices);
|
||||
}
|
||||
|
||||
|
||||
// @Log("分配客户")
|
||||
@Operation(summary = "分配客户")
|
||||
@PutMapping(value = "/assignCustomer")
|
||||
public ResponseVO<Object> assignCustomer(@Validated @RequestBody CustomerVo customerVo) {
|
||||
deviceService.assignCustomer(customerVo);
|
||||
return ResponseVO.success(null);
|
||||
}
|
||||
|
||||
|
||||
// @Log("撤回设备")
|
||||
@Operation(summary = "撤回设备")
|
||||
@PostMapping(value = "/withdraw")
|
||||
public ResponseVO<Object> withdrawDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
|
||||
try {
|
||||
deviceService.withdrawDevice(deviceForm);
|
||||
} catch (Exception e) {
|
||||
log.error("updateDevice error: " + e.getMessage());
|
||||
return ResponseVO.fail("出错了");
|
||||
}
|
||||
return ResponseVO.success(null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param deviceForm
|
||||
* @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 = "导出数据设备")
|
||||
@GetMapping(value = "/download")
|
||||
public void exportDevice(HttpServletResponse response, DeviceQueryCriteria criteria) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "导入设备数据")
|
||||
@PostMapping(value = "/import", consumes = "multipart/form-data")
|
||||
public ResponseVO<ImportResult> importData(@Parameter(name = "文件", required = true) @RequestPart("file") MultipartFile file) {
|
||||
|
||||
// String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
|
||||
// if (!("xlsx".equalsIgnoreCase(suffix))) {
|
||||
// throw new BadRequestException("只能上传Excel——xlsx格式文件");
|
||||
// }
|
||||
//
|
||||
// ImportResult result = new ImportResult();
|
||||
// try {
|
||||
// User currentUser = userMapper.findByUsername(SecurityUtils.getCurrentUsername());
|
||||
// DeviceImportParams params = DeviceImportParams.builder().ip(ip).deviceService(deviceService).tenantId(currentUser.getTenantId()).file(file).filePath(filePath).deviceMapper(deviceMapper).deviceAssignmentsService(deviceAssignmentsService).deviceTypeMapper(deviceTypeMapper).userId(currentUser.getId()).userMapper(userMapper).build();
|
||||
// // 创建监听器
|
||||
// UploadDeviceDataListener listener = new UploadDeviceDataListener(params);
|
||||
// // 读取Excel
|
||||
// EasyExcel.read(file.getInputStream(), DeviceExcelImportDTO.class, listener).sheet().doRead();
|
||||
// // 获取导入结果
|
||||
// result = listener.getImportResult();
|
||||
// // 设置响应消息
|
||||
// String message = String.format("成功导入 %d 条数据,失败 %d 条", result.getSuccessCount(), result.getFailureCount());
|
||||
// // 返回带有正确泛型的响应
|
||||
// return ResponseVO.<ImportResult>success(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 null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,84 @@
|
||||
package com.fuyuanshen.equipment.controller;
|
||||
|
||||
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.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
import com.fuyuanshen.equipment.service.DeviceTypeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/13
|
||||
**/
|
||||
@Tag(name = "设备类型管理", description = "设备类型管理")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/deviceType")
|
||||
public class DeviceTypeController {
|
||||
|
||||
private final DeviceTypeService deviceTypeService;
|
||||
|
||||
|
||||
@GetMapping
|
||||
@Operation(summary = "分页查询设备类型")
|
||||
public ResponseVO<PageResult<DeviceType>> queryDeviceType(DeviceTypeQueryCriteria criteria) {
|
||||
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
return ResponseVO.success(deviceTypeService.queryAll(criteria, page));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/all")
|
||||
@Operation(summary = "查询所有设备类型")
|
||||
public ResponseVO<Object> queryDeviceTypes() {
|
||||
List<DeviceType> deviceTypes = deviceTypeService.queryDeviceTypes();
|
||||
return ResponseVO.success(deviceTypes);
|
||||
}
|
||||
|
||||
|
||||
// @Log("新增设备类型")
|
||||
@Operation(summary = "新增设备类型")
|
||||
@PostMapping(value = "/add")
|
||||
public ResponseVO<Object> createDeviceType(@Validated @RequestBody DeviceType resources) {
|
||||
deviceTypeService.create(resources);
|
||||
return ResponseVO.success(null);
|
||||
}
|
||||
|
||||
|
||||
// @Log("修改设备类型")
|
||||
@Operation(summary = "修改设备类型")
|
||||
@PutMapping(value = "/update")
|
||||
public ResponseVO<Object> updateDeviceType(@Validated @RequestBody DeviceType resources) {
|
||||
deviceTypeService.update(resources);
|
||||
return ResponseVO.success(null);
|
||||
}
|
||||
|
||||
|
||||
// @Log("删除设备类型")
|
||||
@Operation(summary = "删除设备类型")
|
||||
@DeleteMapping(value = "/delete")
|
||||
public ResponseEntity<Object> deleteDeviceType(@Parameter(name = "传ID数组[]") @RequestBody List<Long> ids) {
|
||||
deviceTypeService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/communicationMode")
|
||||
@Operation(summary = "获取设备类型通讯方式")
|
||||
public ResponseVO<DeviceType> getCommunicationMode(@Parameter(name = "设备类型ID", required = true) Long id) {
|
||||
return ResponseVO.success(deviceTypeService.getById(id));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -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){
|
||||
|
||||
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
@ -19,36 +20,29 @@ import lombok.Data;
|
||||
public class DeviceType extends TenantEntity {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
// @ApiModelProperty(value = "ID", hidden = true)
|
||||
@Schema(name = "ID", hidden = true)
|
||||
private Long id;
|
||||
|
||||
// @ApiModelProperty(value = "客户号")
|
||||
@Schema(name = "客户号")
|
||||
private Long customerId;
|
||||
|
||||
// @ApiModelProperty(value = "创建该类型的客户")
|
||||
@Schema(name = "创建该类型的客户")
|
||||
private Long ownerCustomerId;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
// @TableField(value = "tenant_id")
|
||||
// @ApiModelProperty(hidden = true)
|
||||
// private Long tenantId;
|
||||
|
||||
@NotBlank(message = "设备类型名称不能为空")
|
||||
// @ApiModelProperty(value = "类型名称", required = true)
|
||||
@Schema(name = "类型名称", required = true)
|
||||
private String typeName;
|
||||
|
||||
// @ApiModelProperty(value = "是否支持蓝牙")
|
||||
@Schema(name = "是否支持蓝牙")
|
||||
private Boolean isSupportBle;
|
||||
|
||||
// @ApiModelProperty(value = "定位方式", example = "0:无;1:GPS;2:基站;3:wifi;4:北斗")
|
||||
@Schema(name = "定位方式", example = "0:无;1:GPS;2:基站;3:wifi;4:北斗")
|
||||
private String locateMode;
|
||||
|
||||
// @ApiModelProperty(value = "联网方式", example = "0:无;1:4G;2:WIFI")
|
||||
@Schema(name = "联网方式", example = "0:无;1:4G;2:WIFI")
|
||||
private String networkWay;
|
||||
|
||||
// @ApiModelProperty(value = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
@Schema(name = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
private String communicationMode;
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
package com.fuyuanshen.equipment.domain.dto;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
|
||||
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
|
||||
import com.alibaba.excel.converters.bytearray.ByteArrayImageConverter;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-0710:00
|
||||
*/
|
||||
@Data
|
||||
@HeadRowHeight(20) // 表头行高
|
||||
@ContentRowHeight(100) // 内容行高
|
||||
public class DeviceExcelImportDTO {
|
||||
|
||||
@ExcelProperty("设备类型")
|
||||
private Long deviceType;
|
||||
|
||||
@ExcelProperty("客户号")
|
||||
private Long customerId;
|
||||
|
||||
@ExcelProperty("设备名称")
|
||||
@ColumnWidth(20)
|
||||
private String deviceName;
|
||||
|
||||
|
||||
@ExcelProperty(value = "设备图片", converter = ByteArrayImageConverter.class)
|
||||
@ColumnWidth(15)
|
||||
private byte[] devicePic;
|
||||
|
||||
// 添加图片写入方法
|
||||
public void setDevicePicFromBytes(byte[] bytes) {
|
||||
this.devicePic = bytes;
|
||||
}
|
||||
|
||||
@ExcelProperty("设备MAC")
|
||||
@ColumnWidth(20)
|
||||
private String deviceMac;
|
||||
|
||||
@ExcelProperty("设备IMEI")
|
||||
@ColumnWidth(20)
|
||||
private String deviceImei;
|
||||
|
||||
@ExcelProperty("设备SN")
|
||||
@ColumnWidth(20)
|
||||
private String deviceSn;
|
||||
|
||||
@ExcelProperty("经度")
|
||||
private String longitude;
|
||||
|
||||
@ExcelProperty("纬度")
|
||||
private String latitude;
|
||||
|
||||
@ExcelProperty("备注")
|
||||
@ColumnWidth(30)
|
||||
private String remark;
|
||||
|
||||
@ExcelProperty("设备类型名称")
|
||||
@ColumnWidth(20)
|
||||
private String typeName;
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package com.fuyuanshen.equipment.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-0717:01
|
||||
*/
|
||||
@Data
|
||||
public class ImportResult {
|
||||
private int successCount;
|
||||
private int failureCount;
|
||||
private List<DeviceExcelImportDTO> failedRecords;
|
||||
// private byte[] errorExcelData; // 存储失败数据的Excel字节流
|
||||
|
||||
private String errorExcelUrl; // 改为存储错误报告的URL
|
||||
|
||||
// 添加成功/失败统计信息
|
||||
public String getSummary() {
|
||||
return String.format("成功导入 %d 条数据,失败 %d 条", successCount, failureCount);
|
||||
}
|
||||
|
||||
}
|
||||
@ -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,36 @@
|
||||
package com.fuyuanshen.equipment.domain.query;
|
||||
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/14
|
||||
**/
|
||||
@Data
|
||||
public class DeviceTypeQueryCriteria extends BaseEntity implements Serializable {
|
||||
|
||||
@Schema(name = "型号名称")
|
||||
private String typeName;
|
||||
|
||||
@Schema(name = "所属客户")
|
||||
private Set<Long> customerIds;
|
||||
|
||||
@Schema(name = "所属客户")
|
||||
private Long customerId;
|
||||
|
||||
@Schema(name = "com.fuyuanshen")
|
||||
private Long tenantId;
|
||||
|
||||
@Schema(name = "页码", example = "1")
|
||||
private Integer page = 1;
|
||||
|
||||
@Schema(name = "每页数据量", example = "10")
|
||||
private Integer size = 10;
|
||||
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.fuyuanshen.equipment.domain.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 分配客户的Vo类
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/28
|
||||
**/
|
||||
@Data
|
||||
@Validated
|
||||
public class CustomerVo {
|
||||
|
||||
@Schema(name = "客户ID")
|
||||
@NotNull(message = "客户ID不能为空")
|
||||
private Long customerId;
|
||||
|
||||
@Schema(name = "设备ID")
|
||||
@NotNull(message = "设备ID不能为空")
|
||||
private List<Long> deviceIds;
|
||||
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
package com.fuyuanshen.equipment.mapper;
|
||||
|
||||
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.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/14
|
||||
**/
|
||||
@Mapper
|
||||
public interface DeviceTypeMapper extends BaseMapper<DeviceType> {
|
||||
|
||||
/**
|
||||
* 分页查询设备类型
|
||||
*
|
||||
* @param criteria
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
IPage<DeviceType> findAll(@Param("criteria") DeviceTypeQueryCriteria criteria, Page<Object> page);
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有设备类型
|
||||
*
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
List<DeviceType> findAll(@Param("criteria") DeviceTypeQueryCriteria criteria);
|
||||
|
||||
}
|
||||
@ -4,9 +4,12 @@ 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 com.fuyuanshen.equipment.domain.vo.CustomerVo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -24,85 +27,49 @@ public interface DeviceService extends IService<Device> {
|
||||
*/
|
||||
PageResult<Device> queryAll(DeviceQueryCriteria criteria, Page<Object> page) throws IOException;
|
||||
|
||||
// /**
|
||||
// * 查询所有数据不分页
|
||||
// *
|
||||
// * @param criteria 条件参数
|
||||
// * @return List<DeviceDto>
|
||||
// */
|
||||
// List<Device> queryAll(DeviceQueryCriteria criteria);
|
||||
//
|
||||
// /**
|
||||
// * 查询所有设备信息
|
||||
// *
|
||||
// * @param criteria
|
||||
// * @return
|
||||
// */
|
||||
// List<Device> queryAllDevices(DeviceQueryCriteria criteria);
|
||||
//
|
||||
// /**
|
||||
// * 创建
|
||||
// *
|
||||
// * @param resources /
|
||||
// */
|
||||
// void create(Device resources);
|
||||
//
|
||||
// /**
|
||||
// * 新增设备
|
||||
// *
|
||||
// * @param resources
|
||||
// */
|
||||
// void addDevice(DeviceForm resources) throws Exception;
|
||||
//
|
||||
// /**
|
||||
// * 编辑
|
||||
// *
|
||||
// * @param resources /
|
||||
// */
|
||||
// void update(DeviceForm resources) throws Exception;
|
||||
//
|
||||
// /**
|
||||
// * 分配客户
|
||||
// */
|
||||
// void assignCustomer(CustomerVo customerVo);
|
||||
//
|
||||
// void withdrawDevice(DeviceForm deviceForm);
|
||||
//
|
||||
// /**
|
||||
// * 多选删除
|
||||
// *
|
||||
// * @param ids /
|
||||
// */
|
||||
// void deleteAll(List<Long> ids);
|
||||
//
|
||||
// /**
|
||||
// * 删除设备分配记录
|
||||
// *
|
||||
// * @param ids
|
||||
// */
|
||||
// void deleteAssign(List<Long> ids);
|
||||
//
|
||||
// /**
|
||||
// * 导出数据
|
||||
// *
|
||||
// * @param all 待导出的数据
|
||||
// * @param response /
|
||||
// * @throws IOException /
|
||||
// */
|
||||
// void download(List<Device> all, HttpServletResponse response) throws IOException;
|
||||
//
|
||||
// /**
|
||||
// * 导入设备数据
|
||||
// *
|
||||
// * @param file
|
||||
// */
|
||||
// void importData(MultipartFile file) throws IOException;
|
||||
//
|
||||
// /**
|
||||
// * 解绑设备
|
||||
// *
|
||||
// * @param deviceForm
|
||||
// */
|
||||
// void unbindDevice(DeviceForm deviceForm);
|
||||
/**
|
||||
* 查询所有设备信息
|
||||
*
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
List<Device> queryAllDevices(DeviceQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 新增设备
|
||||
*
|
||||
* @param resources
|
||||
*/
|
||||
void addDevice(DeviceForm resources) throws Exception;
|
||||
|
||||
/**
|
||||
* 修改设备
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void update(DeviceForm resources) throws Exception;
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteAll(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 分配客户
|
||||
*/
|
||||
void assignCustomer(CustomerVo customerVo);
|
||||
|
||||
/**
|
||||
* 撤回设备
|
||||
*/
|
||||
void withdrawDevice(DeviceForm deviceForm);
|
||||
|
||||
/**
|
||||
* 解绑设备
|
||||
*
|
||||
* @param deviceForm
|
||||
*/
|
||||
void unbindDevice(DeviceForm deviceForm);
|
||||
}
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
package com.fuyuanshen.equipment.service;
|
||||
|
||||
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.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/14
|
||||
**/
|
||||
public interface DeviceTypeService extends IService<DeviceType> {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @param page 分页参数
|
||||
* @return PageResult
|
||||
*/
|
||||
PageResult<DeviceType> queryAll(DeviceTypeQueryCriteria criteria, Page<Object> page);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
*
|
||||
* @param criteria 条件参数
|
||||
* @return List<DeviceTypeDto>
|
||||
*/
|
||||
List<DeviceType> queryAll(DeviceTypeQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 查询所有设备类型
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<DeviceType> queryDeviceTypes();
|
||||
|
||||
/**
|
||||
* 新增设备类型
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void create(DeviceType resources);
|
||||
|
||||
/**
|
||||
* 修改设备类型
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void update(DeviceType resources);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteAll(List<Long> ids);
|
||||
|
||||
}
|
||||
@ -1,22 +1,30 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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.constants.DeviceConstants;
|
||||
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.domain.vo.CustomerVo;
|
||||
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.util.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -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,550 +68,150 @@ 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 criteria 筛选条件
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Device> queryAllDevices(DeviceQueryCriteria criteria) {
|
||||
return deviceMapper.findAllDevices(criteria);
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 更新设备信息
|
||||
// *
|
||||
// * @param deviceForm /
|
||||
// * @throws Exception
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void update(DeviceForm deviceForm) throws Exception {
|
||||
// Device device = getById(deviceForm.getId());
|
||||
//
|
||||
// // 处理上传的图片
|
||||
// String imageUrl = saveDeviceImage(deviceForm.getFile(), device.getDeviceMac());
|
||||
// deviceForm.setDevicePic(imageUrl);
|
||||
//
|
||||
// // 更新字段
|
||||
// BeanUtil.copyProperties(deviceForm, device, true);
|
||||
// device.setUpdateTime(new Timestamp(System.currentTimeMillis()));
|
||||
// deviceMapper.updateById(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;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 分配客户 历史记录版本
|
||||
// *
|
||||
// * @param customerVo
|
||||
// */
|
||||
//
|
||||
// public void assignCustomer1(CustomerVo customerVo) {
|
||||
//
|
||||
// // 防止管理员误操作
|
||||
// User currentUser = userService.findById(SecurityUtils.getCurrentUserId());
|
||||
// if (currentUser.getTenantId().equals(UserConstants.SUPER_ADMIN_ID)) {
|
||||
// throw new BadRequestException(ExceptionMessages.ADMIN_OPERATION_NOT_ALLOWED);
|
||||
// }
|
||||
//
|
||||
// List<DeviceAssignments> assignments = new ArrayList<>();
|
||||
// List<DeviceTypeGrants> deviceTypeGrants = new ArrayList<>();
|
||||
// List<Device> devices = new ArrayList<>();
|
||||
// customerVo.getDeviceIds().forEach(deviceId -> {
|
||||
//
|
||||
// // 阻止重复分配
|
||||
// Device device = deviceMapper.selectById(deviceId);
|
||||
// if (device.getCustomerId() != null && device.getCustomerId().equals(customerVo.getCustomerId())) {
|
||||
// throw new BadRequestException("设备 " + device.getDeviceName() + " 已被分配给客户 " + device.getCustomerName());
|
||||
// }
|
||||
//
|
||||
// // 自定义16位id
|
||||
// Long generatedId = NanoId.generate(NanoIdLengthEnum.HIGH_CONCURRENCY.getLength());
|
||||
//
|
||||
// // -- 记录分配历史
|
||||
// DeviceAssignments deviceAssignments = new DeviceAssignments();
|
||||
// deviceAssignments.setId(generatedId);
|
||||
// deviceAssignments.setDeviceId(deviceId);
|
||||
// deviceAssignments.setFromCustomerId(currentUser.getId());
|
||||
// deviceAssignments.setToCustomerId(customerVo.getCustomerId());
|
||||
// deviceAssignments.setAssignedAt(LocalDateTime.now());
|
||||
// deviceAssignments.setDeviceTypeGranted(DeviceAuthorizationStatus.AUTHORIZED.getValue());
|
||||
// assignments.add(deviceAssignments);
|
||||
//
|
||||
// // -- 授权设备类型给客户
|
||||
// // QueryWrapper<DeviceTypeGrants> deviceTypeGrantsQueryWrapper = new QueryWrapper<>();
|
||||
// // Long count = deviceTypeGrantsMapper.selectCount(deviceTypeGrantsQueryWrapper);
|
||||
// DeviceTypeGrants deviceTypeGrant = new DeviceTypeGrants();
|
||||
// deviceTypeGrant.setGrantedAt(new Date());
|
||||
// // 设备类型
|
||||
// deviceTypeGrant.setDeviceTypeId(device.getDeviceType());
|
||||
// deviceTypeGrant.setAssignmentId(generatedId);
|
||||
// // 被授权的客户
|
||||
// deviceTypeGrant.setCustomerId(customerVo.getCustomerId());
|
||||
// // 授权方客户
|
||||
// deviceTypeGrant.setGrantorCustomerId(currentUser.getId());
|
||||
// deviceTypeGrants.add(deviceTypeGrant);
|
||||
//
|
||||
// // -- 更新设备所有者
|
||||
// device.setCurrentOwnerId(customerVo.getCustomerId());
|
||||
// devices.add(device);
|
||||
// });
|
||||
//
|
||||
// deviceAssignmentsService.saveBatch(assignments);
|
||||
// deviceTypeGrantsService.saveBatch(deviceTypeGrants);
|
||||
// this.updateBatchById(devices);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 分配客户
|
||||
// *
|
||||
// * @param customerVo
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void assignCustomer(CustomerVo customerVo) {
|
||||
//
|
||||
// // 获取当前登录用户
|
||||
// User currentUser = userService.findById(SecurityUtils.getCurrentUserId());
|
||||
// // 防止管理员误操作
|
||||
// AdminCheckUtil.checkIfSuperAdmin(currentUser);
|
||||
// // 获取分配用户信息
|
||||
// User assignUser = userService.findById(customerVo.getCustomerId());
|
||||
//
|
||||
// // 获取分配设备信息
|
||||
// List<Device> devices = deviceMapper.selectBatchIds(customerVo.getDeviceIds());
|
||||
//
|
||||
// // 批量更新设备状态
|
||||
// List<DeviceTypeGrants> deviceTypeGrants = new ArrayList<>();
|
||||
// for (Device device : devices) {
|
||||
//
|
||||
// // 如果设备已分配给需要分配的客户,则跳过
|
||||
// LambdaQueryWrapper<DeviceAssignments> wrapper = new LambdaQueryWrapper<>();
|
||||
// wrapper.eq(DeviceAssignments::getDeviceId, device.getId()).eq(DeviceAssignments::getAssigneeId, customerVo.getCustomerId()).ne(DeviceAssignments::getActive, DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
// List<DeviceAssignments> deviceAssignments = deviceAssignmentsMapper.selectList(wrapper);
|
||||
// if (CollectionUtil.isNotEmpty(deviceAssignments)) {
|
||||
// log.info("设备 {} 已分配给客户 {}", device.getDeviceName(), device.getCustomerName());
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// // 更改分配客户
|
||||
// QueryWrapper<DeviceAssignments> q = new QueryWrapper<>();
|
||||
// q.eq("device_id", device.getId());
|
||||
// q.eq("assignee_id", currentUser.getId());
|
||||
// q.ne("active", DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
// DeviceAssignments d = new DeviceAssignments();
|
||||
// d.setAssigneeName(assignUser.getUsername());
|
||||
// deviceAssignmentsMapper.update(d, q);
|
||||
//
|
||||
// // 设备失效
|
||||
// // 获取用户的设备记录
|
||||
// DeviceAssignments assignment = deviceAssignmentsMapper.selectOne(new LambdaQueryWrapper<DeviceAssignments>().eq(DeviceAssignments::getDeviceId, device.getId()).eq(DeviceAssignments::getAssigneeId, currentUser.getId()).eq(DeviceAssignments::getActive, DeviceActiveStatusEnum.ACTIVE.getCode()));
|
||||
//
|
||||
// LambdaQueryWrapper<DeviceAssignments> q1 = new LambdaQueryWrapper<>();
|
||||
// q1.eq(DeviceAssignments::getDeviceId, device.getId()).ne(DeviceAssignments::getAssigneeId, currentUser.getId()).like(DeviceAssignments::getLever, assignment.getLever());
|
||||
//
|
||||
// DeviceAssignments d1 = new DeviceAssignments();
|
||||
// d1.setActive(DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
// deviceAssignmentsMapper.update(d1, q1);
|
||||
//
|
||||
// // device.setCustomerId(assignUser.getId());
|
||||
// // device.setCustomerName(assignUser.getUsername());
|
||||
//
|
||||
// // 新增设备类型记录
|
||||
// DeviceAssignments assignments = new DeviceAssignments();
|
||||
// assignments.setDeviceId(device.getId());
|
||||
// assignments.setAssignedAt(LocalDateTime.now());
|
||||
// // 分配者
|
||||
// assignments.setAssignerId(currentUser.getId());
|
||||
// assignments.setAssignerName(currentUser.getUsername());
|
||||
// // 接收者
|
||||
// assignments.setAssigneeId(assignUser.getId());
|
||||
// // assignments.setAssigneeName(assignUser.getUsername());
|
||||
// assignments.setActive(DeviceActiveStatusEnum.ACTIVE.getCode());
|
||||
// String lever = assignment.getLever() + ":" + assignUser.getId();
|
||||
// assignments.setLever(lever);
|
||||
// deviceAssignmentsService.save(assignments);
|
||||
//
|
||||
// // // 获取当前用户的所有祖先用户
|
||||
// // List<User> ancestorsById = userMapper.findAncestorsById(currentUser.getId());
|
||||
// // Set<Long> excludedTenantIds = new HashSet<>();
|
||||
// // if (CollectionUtil.isNotEmpty(ancestorsById)) {
|
||||
// // // 提取所有需要排除的 tenant_id
|
||||
// // excludedTenantIds = ancestorsById.stream().map(User::getTenantId).distinct().collect(Collectors.toSet());
|
||||
// // }
|
||||
// // excludedTenantIds.add(currentUser.getTenantId());
|
||||
// // // 构建查询条件:device_mac 相同,并且 tenant_id 不在 excludedTenantIds 列表中
|
||||
// // Wrapper<Device> wrapper = new QueryWrapper<Device>().eq("device_mac", device.getDeviceMac()).notIn("tenant_id", excludedTenantIds);
|
||||
// //
|
||||
// // // 构建要更新的数据
|
||||
// // Device updateDevice = new Device();
|
||||
// // updateDevice.setDeviceStatus(0);
|
||||
// // updateDevice.setUpdateTime(new Timestamp(System.currentTimeMillis()));
|
||||
//
|
||||
// // 根据条件批量更新
|
||||
// // deviceMapper.update(updateDevice, wrapper);
|
||||
//
|
||||
// // 创建并保存设备类型授权记录
|
||||
// createAndSaveDeviceTypeGrants(device, currentUser, customerVo, deviceTypeGrants);
|
||||
// }
|
||||
//
|
||||
// this.updateBatchById(devices);
|
||||
//
|
||||
// deviceTypeGrantsService.saveBatch(deviceTypeGrants);
|
||||
//
|
||||
// //
|
||||
// // // 批量分配
|
||||
// // Set<DeviceType> deviceTypes = new HashSet<>();
|
||||
// // for (Device device : devices) {
|
||||
// // device.setId(null);
|
||||
// // device.setCustomerName(null);
|
||||
// // device.setCustomerId(null);
|
||||
// // device.setTenantId(user.getTenantId());
|
||||
// // device.setCreateTime(timestamp);
|
||||
// // device.setCreateBy(currentUser.getUsername());
|
||||
// // device.setUpdateTime(timestamp);
|
||||
// //
|
||||
// // // 查询设备类型
|
||||
// // DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||
// // // SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator();
|
||||
// // Long id = NanoId.generate(NanoIdLengthEnum.HIGH_CONCURRENCY.getLength());
|
||||
// // deviceType.setId(id);
|
||||
// // deviceType.setCreateTime(timestamp);
|
||||
// // deviceType.setCreateBy(currentUser.getUsername());
|
||||
// // deviceType.setCustomerId(customerVo.getCustomerId());
|
||||
// // deviceTypes.add(deviceType);
|
||||
// //
|
||||
// // device.setDeviceType(deviceType.getId());
|
||||
// // }
|
||||
// // this.saveBatch(devices);
|
||||
// // deviceTypeService.saveBatch(deviceTypes);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 撤回设备
|
||||
// *
|
||||
// * @param deviceForm
|
||||
// */
|
||||
// @Override
|
||||
// public void withdrawDevice(DeviceForm deviceForm) {
|
||||
// DeviceAssignments assignment = deviceAssignmentsMapper.selectById(deviceForm.getAssignId());
|
||||
// // 接收者
|
||||
// assignment.setAssigneeName("");
|
||||
// deviceAssignmentsMapper.updateById(assignment);
|
||||
//
|
||||
// LambdaQueryWrapper<DeviceAssignments> q1 = new LambdaQueryWrapper<>();
|
||||
// q1.eq(DeviceAssignments::getAssignerId, assignment.getAssigneeId())
|
||||
// .like(DeviceAssignments::getLever, assignment.getLever())
|
||||
// .ne(DeviceAssignments::getId, assignment.getId());
|
||||
//
|
||||
// DeviceAssignments d1 = new DeviceAssignments();
|
||||
// d1.setActive(DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
// deviceAssignmentsMapper.update(d1, q1);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 创建并保存设备类型授权记录
|
||||
// *
|
||||
// * @param device 当前设备对象
|
||||
// * @param currentUser 当前登录用户
|
||||
// * @param customerVo 客户信息
|
||||
// * @param deviceTypeGrants 授权记录集合
|
||||
// */
|
||||
// private void createAndSaveDeviceTypeGrants(Device device, User currentUser, CustomerVo customerVo, List<DeviceTypeGrants> deviceTypeGrants) {
|
||||
// Long generatedId = NanoId.generate(NanoIdLengthEnum.HIGH_CONCURRENCY.getLength());
|
||||
// DeviceTypeGrants deviceTypeGrant = new DeviceTypeGrants();
|
||||
// deviceTypeGrant.setGrantedAt(new Date());
|
||||
// deviceTypeGrant.setDeviceTypeId(device.getDeviceType());
|
||||
// deviceTypeGrant.setAssignmentId(generatedId);
|
||||
// deviceTypeGrant.setCustomerId(customerVo.getCustomerId());
|
||||
// deviceTypeGrant.setGrantorCustomerId(currentUser.getId());
|
||||
// deviceTypeGrants.add(deviceTypeGrant);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 删除设备
|
||||
// *
|
||||
// * @param ids /
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void deleteAll(List<Long> ids) {
|
||||
//
|
||||
// SecurityUtils.getCurrentUserId();
|
||||
//
|
||||
// // Step 1: 查询所有传入的设备(根据 ID)
|
||||
// List<Device> allDevices = deviceMapper.selectBatchIds(ids);
|
||||
// // Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备
|
||||
// Set<Long> nonNullCustomerIds = allDevices.stream().filter(device -> device.getCustomerId() != null && device.getDeviceStatus() == 1).map(Device::getId).collect(Collectors.toSet());
|
||||
// // Step 3: 从原始 ids 中“去掉”这些非空 customer_id 的设备 ID
|
||||
// List<Long> remainingIds = ids.stream().filter(id -> !nonNullCustomerIds.contains(id)).collect(Collectors.toList());
|
||||
// if (CollectionUtil.isEmpty(remainingIds)) {
|
||||
// throw new BadRequestException("已分配的设备不允许删除!!!");
|
||||
// }
|
||||
// List<Device> devices = deviceMapper.selectBatchIds(remainingIds);
|
||||
// for (Device device : devices) {
|
||||
// String devicePic = device.getDevicePic();
|
||||
// if (StringUtils.isNotBlank(devicePic)) {
|
||||
// File file = new File(devicePic);
|
||||
// if (file.exists()) {
|
||||
// if (file.delete()) {
|
||||
// log.info("设备图片删除成功");
|
||||
// } else {
|
||||
// log.error("设备图片删除失败");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// deviceMapper.deleteBatchIds(ids);
|
||||
// }
|
||||
/**
|
||||
* 新增设备
|
||||
*
|
||||
* @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.getDeviceName());
|
||||
// 设置图片路径
|
||||
deviceForm.setDevicePic(imageUrl);
|
||||
|
||||
// 转换对象并插入数据库
|
||||
Device device = new Device();
|
||||
BeanUtil.copyProperties(deviceForm, device, true);
|
||||
|
||||
deviceMapper.insert(device);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新设备信息
|
||||
*
|
||||
* @param deviceForm /
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(DeviceForm deviceForm) throws Exception {
|
||||
|
||||
Device device = getById(deviceForm.getId());
|
||||
if (device == null) {
|
||||
throw new Exception("设备不存在!!!");
|
||||
}
|
||||
|
||||
// 处理上传的图片
|
||||
String imageUrl = saveDeviceImage(deviceForm.getFile(), device.getDeviceName());
|
||||
deviceForm.setDevicePic(imageUrl);
|
||||
|
||||
// 更新字段
|
||||
BeanUtil.copyProperties(deviceForm, device, true);
|
||||
device.setUpdateTime(new Timestamp(System.currentTimeMillis()));
|
||||
deviceMapper.updateById(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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除设备
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAll(List<Long> ids) {
|
||||
deviceMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分配客户
|
||||
*
|
||||
* @param customerVo
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void assignCustomer(CustomerVo customerVo) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 撤回设备
|
||||
*
|
||||
* @param deviceForm
|
||||
*/
|
||||
@Override
|
||||
public void withdrawDevice(DeviceForm deviceForm) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解绑设备
|
||||
*
|
||||
* @param deviceForm
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void unbindDevice(DeviceForm deviceForm) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 删除设备分配记录(分配记录id)
|
||||
// *
|
||||
// * @param ids
|
||||
// */
|
||||
// public void deleteAssign1(List<Long> ids) {
|
||||
// Long currentUserId = SecurityUtils.getCurrentUserId();
|
||||
// // Step 1: 查询所有传入的设备(根据 ID)
|
||||
// // List<DeviceAssignments> deviceAssignments = deviceAssignmentsMapper.selectBatchIds(ids);
|
||||
// QueryWrapper<DeviceAssignments> wrapper = new QueryWrapper<>();
|
||||
// // wrapper.eq("active", DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
// wrapper.in("device_id", ids);
|
||||
// wrapper.eq("assigner_id", currentUserId);
|
||||
// List<DeviceAssignments> deviceAssignments = deviceAssignmentsMapper.selectList(wrapper);
|
||||
// // Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备
|
||||
// Set<Long> nonNullCustomerIds = deviceAssignments.stream().filter(device -> !StringUtils.isNotEmpty(device.getAssigneeName())).map(DeviceAssignments::getId).collect(Collectors.toSet());
|
||||
// if (CollectionUtil.isEmpty(nonNullCustomerIds)) {
|
||||
// throw new BadRequestException("已分配的设备不允许删除!!!");
|
||||
// }
|
||||
//
|
||||
// // QueryWrapper<DeviceAssignments> de = new QueryWrapper<>();
|
||||
// // wrapper.eq("active", DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
// // wrapper.in("device_id", ids);
|
||||
// // wrapper.eq("assignee_id", currentUserId);
|
||||
// // deviceAssignmentsMapper.delete(de);
|
||||
//
|
||||
// deviceAssignmentsMapper.deleteBatchIds(nonNullCustomerIds);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 删除设备分配记录(分配记录id)
|
||||
// *
|
||||
// * @param ids
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void deleteAssign(List<Long> ids) {
|
||||
// // Step 1: 查询所有传入的设备(根据 ID)
|
||||
// List<DeviceAssignments> deviceAssignments = deviceAssignmentsMapper.selectBatchIds(ids);
|
||||
// // Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备
|
||||
// Set<Long> nonNullCustomerIds = deviceAssignments.stream()
|
||||
// .filter(device -> !StringUtils.isNotEmpty(device.getAssigneeName()))
|
||||
// .map(DeviceAssignments::getId).collect(Collectors.toSet());
|
||||
// if (CollectionUtil.isEmpty(nonNullCustomerIds)) {
|
||||
// throw new BadRequestException("已分配的设备不允许删除!!!");
|
||||
// }
|
||||
//
|
||||
// deviceAssignmentsMapper.deleteBatchIds(nonNullCustomerIds);
|
||||
// deviceTypeGrantsMapper.delete(new QueryWrapper<DeviceTypeGrants>().in("assignment_id", nonNullCustomerIds));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void download(List<Device> all, HttpServletResponse response) throws IOException {
|
||||
// List<Map<String, Object>> list = new ArrayList<>();
|
||||
// for (Device device : all) {
|
||||
// Map<String, Object> map = new LinkedHashMap<>();
|
||||
// map.put("设备类型", device.getTypeName());
|
||||
// map.put("客户号", device.getCustomerId());
|
||||
// // map.put("设备编号", device.getDeviceNo());
|
||||
// map.put("设备名称", device.getDeviceName());
|
||||
// // map.put("设备图片", device.getDevicePic());
|
||||
// map.put("设备MAC", device.getDeviceMac());
|
||||
// map.put("设备SN", device.getDeviceSn());
|
||||
// map.put("创建者", device.getCreateBy());
|
||||
// map.put("更新者", device.getUpdateBy());
|
||||
// map.put("创建时间", device.getCreateTime());
|
||||
// map.put("更新时间", device.getUpdateTime());
|
||||
// list.add(map);
|
||||
// }
|
||||
// FileUtil.downloadExcel(list, response);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void importData(MultipartFile file) throws IOException {
|
||||
// String line = "";
|
||||
// String csvSplitBy = ",";
|
||||
// List<Device> devices = new ArrayList<>();
|
||||
// User currentUser = userService.findByName(SecurityUtils.getCurrentUsername());
|
||||
//
|
||||
// InputStream inputStream = file.getInputStream();
|
||||
// InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "GB2312");
|
||||
// BufferedReader br = new BufferedReader(inputStreamReader);
|
||||
//
|
||||
// // BufferedReader br = new BufferedReader(new FileReader((File) file));
|
||||
// br.readLine(); // 跳过第一行
|
||||
// while ((line = br.readLine()) != null) {
|
||||
// // 使用分隔符分割并存储到List中
|
||||
// String[] values = line.split(csvSplitBy);
|
||||
// Device device = new Device();
|
||||
// device.setDeviceName(values[0]);
|
||||
// device.setDeviceMac(values[1]);
|
||||
// device.setDeviceSn(values[2]);
|
||||
// device.setCreateBy(currentUser.getUsername());
|
||||
// device.setUpdateBy(currentUser.getUsername());
|
||||
// devices.add(device);
|
||||
// }
|
||||
//
|
||||
// this.saveBatch(devices);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 解绑设备
|
||||
// *
|
||||
// * @param deviceForm
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional
|
||||
// public void unbindDevice(DeviceForm deviceForm) {
|
||||
//
|
||||
// QueryWrapper<APPDevice> queryWrapper = new QueryWrapper<>();
|
||||
// if (StringUtils.isNotEmpty(deviceForm.getDeviceMac())) {
|
||||
// queryWrapper.eq("device_mac", deviceForm.getDeviceMac());
|
||||
// }
|
||||
// if (StringUtils.isNotEmpty(deviceForm.getDeviceImei())) {
|
||||
// queryWrapper.eq("device_imei", deviceForm.getDeviceImei());
|
||||
// }
|
||||
// appDeviceMapper.delete(queryWrapper);
|
||||
// Device device = new Device();
|
||||
// device.setId(deviceForm.getId());
|
||||
// device.setBindingStatus(BindingStatusEnum.UNBOUND.getCode());
|
||||
// deviceMapper.updateById(device);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,104 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceTypeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/14
|
||||
**/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceType> implements DeviceTypeService {
|
||||
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
private final DeviceMapper deviceMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询设备类型
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @param page 分页参数
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageResult<DeviceType> queryAll(DeviceTypeQueryCriteria criteria, Page<Object> page) {
|
||||
return PageUtil.toPage(deviceTypeMapper.findAll(criteria, page));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<DeviceType> queryAll(DeviceTypeQueryCriteria criteria) {
|
||||
return deviceTypeMapper.findAll(criteria);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有设备类型
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceType> queryDeviceTypes() {
|
||||
DeviceTypeQueryCriteria criteria = new DeviceTypeQueryCriteria();
|
||||
Long userId = LoginHelper.getUserId();
|
||||
criteria.setCustomerId(userId);
|
||||
return deviceTypeMapper.findAll(criteria);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增设备类型
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(DeviceType resources) {
|
||||
Long userId = LoginHelper.getUserId();
|
||||
resources.setCustomerId(userId);
|
||||
resources.setOwnerCustomerId(userId);
|
||||
deviceTypeMapper.insert(resources);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改设备类型
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(DeviceType resources) {
|
||||
deviceTypeMapper.updateById(resources);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除设备类型
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAll(List<Long> ids) {
|
||||
deviceTypeMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
<?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.fuyuanshen.equipment.mapper.DeviceTypeMapper">
|
||||
<resultMap id="BaseResultMap" type="com.fuyuanshen.equipment.domain.DeviceType">
|
||||
<id column="id" property="id"/>
|
||||
<result column="type_name" property="typeName"/>
|
||||
<result column="is_support_ble" property="isSupportBle"/>
|
||||
<result column="locate_mode" property="locateMode"/>
|
||||
<result column="network_way" property="networkWay"/>
|
||||
<result column="create_by" property="createBy"/>
|
||||
<result column="update_by" property="updateBy"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="communication_mode" property="communicationMode"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
, type_name, is_support_ble, locate_mode, network_way, create_by, update_by, create_time, update_time,communication_mode
|
||||
</sql>
|
||||
|
||||
|
||||
<!-- 查询所有设备类型 -->
|
||||
<select id="findAll" resultMap="BaseResultMap">
|
||||
SELECT DISTINCT dt.*
|
||||
FROM device_type dt
|
||||
<where>
|
||||
<if test="criteria.typeName != null and criteria.typeName.trim() != ''">
|
||||
and dt.type_name like concat('%', TRIM(#{criteria.typeName}), '%')
|
||||
</if>
|
||||
<if test="criteria.tenantId != null">
|
||||
and dt.tenant_id = #{criteria.tenantId}
|
||||
</if>
|
||||
<if test="criteria.createBy != null">
|
||||
and dt.create_by = #{criteria.createBy}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY dt.create_time DESC
|
||||
</select>
|
||||
</mapper>
|
||||
11
pom.xml
11
pom.xml
@ -152,6 +152,17 @@
|
||||
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
|
||||
<version>${springdoc.version}</version>
|
||||
</dependency>
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.springdoc</groupId> -->
|
||||
<!-- <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> -->
|
||||
<!-- <version>${springdoc.version}</version> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui -->
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
<version>2.8.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.therapi</groupId>
|
||||
|
||||
Reference in New Issue
Block a user