初始化提交
This commit is contained in:
136
fys-modules/fys-equipment/pom.xml
Normal file
136
fys-modules/fys-equipment/pom.xml
Normal file
@ -0,0 +1,136 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-modules</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>fys-equipment</artifactId>
|
||||
|
||||
<description>
|
||||
富源晟设备管理
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>com.fuyuanshen</groupId> -->
|
||||
<!-- <artifactId>fys-app</artifactId> -->
|
||||
<!-- </dependency> -->
|
||||
|
||||
<!-- 通用工具-->
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-doc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-mybatis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-translation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-system</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- OSS功能模块 -->
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-oss</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- excel-->
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-excel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SMS功能模块 -->
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-sms</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-tenant</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-idempotent</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-sensitive</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-encrypt</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-websocket</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-common-sse</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 客户管理模块 -->
|
||||
<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-customer</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
<version>3.3.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- fastjson2 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.54</version>
|
||||
</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 = "普通客户";
|
||||
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package com.fuyuanshen.equipment.controller;
|
||||
|
||||
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
|
||||
import com.fuyuanshen.common.log.annotation.Log;
|
||||
import com.fuyuanshen.common.log.enums.BusinessType;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.bo.UserAppBo;
|
||||
import com.fuyuanshen.equipment.service.AppUserService;
|
||||
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.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Slf4j
|
||||
@Tag(name = "设备管理", description = "设备:设备管理")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/app/device")
|
||||
public class DeviceAPPController extends BaseController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// @GetMapping
|
||||
// @Operation(summary = "WEB端查看APP客户设备绑定")
|
||||
// public TableDataInfo<APPDevice> queryAPPDevice(APPDeviceQueryCriteria criteria) {
|
||||
// Page<APPDevice> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
// TableDataInfo<APPDevice> devices = null;
|
||||
// devices = appDeviceService.queryAll(page, criteria);
|
||||
// return devices;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,204 @@
|
||||
package com.fuyuanshen.equipment.controller;
|
||||
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.common.core.constant.ResponseMessageConstants;
|
||||
import com.fuyuanshen.common.core.domain.ResponseVO;
|
||||
import com.fuyuanshen.common.core.domain.model.LoginUser;
|
||||
import com.fuyuanshen.common.core.utils.file.FileUtil;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.customer.mapper.CustomerMapper;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.DeviceExcelImportDTO;
|
||||
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.excel.DeviceImportParams;
|
||||
import com.fuyuanshen.equipment.excel.UploadDeviceDataListener;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import com.fuyuanshen.equipment.service.impl.DeviceExportService;
|
||||
import com.fuyuanshen.system.service.ISysOssService;
|
||||
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 io.undertow.util.BadRequestException;
|
||||
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:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Slf4j
|
||||
@Tag(name = "web:设备管理", description = "web:设备管理")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/device")
|
||||
public class DeviceController {
|
||||
|
||||
private final ISysOssService ossService;
|
||||
private final DeviceService deviceService;
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final CustomerMapper customerMapper;
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
|
||||
private final DeviceExportService exportService;
|
||||
|
||||
|
||||
@Operation(summary = "分页查询设备列表", security = {@SecurityRequirement(name = "bearer-key")})
|
||||
@GetMapping
|
||||
public TableDataInfo<Device> queryDevice(DeviceQueryCriteria criteria) throws IOException {
|
||||
Page<Device> page = new Page<>(criteria.getPageNum(), criteria.getPageSize());
|
||||
return deviceService.queryAll(criteria, page);
|
||||
}
|
||||
|
||||
|
||||
// @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);
|
||||
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(@RequestBody List<Long> ids) {
|
||||
try {
|
||||
deviceService.withdrawDevice(ids);
|
||||
} 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 {
|
||||
List<Device> devices = deviceService.queryAll(criteria);
|
||||
exportService.export(devices, response);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "导入设备数据")
|
||||
@PostMapping(value = "/import", consumes = "multipart/form-data")
|
||||
public ResponseVO<ImportResult> importData(@Parameter(name = "文件", required = true) @RequestPart("file") MultipartFile file) throws BadRequestException {
|
||||
|
||||
String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
|
||||
if (!("xlsx".equalsIgnoreCase(suffix))) {
|
||||
throw new BadRequestException("只能上传Excel——xlsx格式文件");
|
||||
}
|
||||
|
||||
ImportResult result = new ImportResult();
|
||||
try {
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
DeviceImportParams params = DeviceImportParams.builder().ossService(ossService).deviceService(deviceService).tenantId(loginUser.getTenantId()).file(file).filePath("").deviceMapper(deviceMapper).deviceTypeMapper(deviceTypeMapper).userId(loginUser.getUserId()).customerMapper(customerMapper).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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,82 @@
|
||||
package com.fuyuanshen.equipment.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.common.core.domain.ResponseVO;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceTypeForm;
|
||||
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.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 TableDataInfo<DeviceType> queryDeviceType(DeviceTypeQueryCriteria criteria) {
|
||||
Page<DeviceType> page = new Page<>(criteria.getPageNum(), criteria.getPageSize());
|
||||
return 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 DeviceTypeForm resources) {
|
||||
deviceTypeService.update(resources);
|
||||
return ResponseVO.success(null);
|
||||
}
|
||||
|
||||
|
||||
// @Log("删除设备类型")
|
||||
@Operation(summary = "删除设备类型")
|
||||
@DeleteMapping(value = "/delete")
|
||||
public ResponseVO<Object> deleteDeviceType(@Parameter(name = "传ID数组[]") @RequestBody List<Long> ids) {
|
||||
deviceTypeService.deleteAll(ids);
|
||||
return ResponseVO.success("删除成功!!!");
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/communicationMode")
|
||||
@Operation(summary = "获取设备类型通讯方式")
|
||||
public ResponseVO<DeviceType> getCommunicationMode(@Parameter(name = "设备类型ID", required = true) Long id) {
|
||||
return ResponseVO.success(deviceTypeService.getCommunicationMode(id));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
package com.fuyuanshen.equipment.converter;
|
||||
|
||||
import com.alibaba.excel.converters.Converter;
|
||||
import com.alibaba.excel.metadata.GlobalConfiguration;
|
||||
import com.alibaba.excel.metadata.data.WriteCellData;
|
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-0618:56
|
||||
*/
|
||||
|
||||
public class IgnoreFailedImageConverter implements Converter<URL> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(IgnoreFailedImageConverter.class);
|
||||
|
||||
@Override
|
||||
public Class<?> supportJavaTypeKey() {
|
||||
return URL.class;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public CellDataTypeEnum supportExcelTypeKey() {
|
||||
// return CellDataTypeEnum.STRING;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public WriteCellData<?> convertToExcelData(URL value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
URLConnection conn = value.openConnection();
|
||||
conn.setConnectTimeout(2000); // 2秒超时
|
||||
conn.setReadTimeout(3000); // 3秒超时
|
||||
|
||||
try (InputStream inputStream = conn.getInputStream()) {
|
||||
// byte[] bytes = FileUtils.readInputStream(inputStream, value.toString());
|
||||
// 替代 FileUtils.readInputStream 的自定义方法
|
||||
byte[] bytes = readInputStream(inputStream);
|
||||
return new WriteCellData<>(bytes);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 静默忽略错误,只记录日志
|
||||
logger.debug("忽略图片加载失败: {}, 原因: {}", value, e.getMessage());
|
||||
// return null; // 返回null表示不写入图片
|
||||
return new WriteCellData<>(new byte[0]); // 返回空数组而不是 null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 替代 FileUtils.readInputStream 的自定义方法
|
||||
*
|
||||
* @param inputStream 输入流
|
||||
* @return 字节数组
|
||||
* @throws Exception 读取异常
|
||||
*/
|
||||
private byte[] readInputStream(InputStream inputStream) throws Exception {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[8192];
|
||||
int bytesRead;
|
||||
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package com.fuyuanshen.equipment.converter;// package com.fuyuanshen.modules.system.converter;
|
||||
//
|
||||
// import com.alibaba.excel.converters.Converter;
|
||||
// import com.alibaba.excel.enums.CellDataTypeEnum;
|
||||
// import com.alibaba.excel.metadata.GlobalConfiguration;
|
||||
// import com.alibaba.excel.metadata.data.ReadCellData;
|
||||
// import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||
//
|
||||
// import java.io.ByteArrayOutputStream;
|
||||
// import java.io.IOException;
|
||||
//
|
||||
// /**
|
||||
// * @author: 默苍璃
|
||||
// * @date: 2025-06-0710:01
|
||||
// */
|
||||
//
|
||||
// public class ImageReadConverter implements Converter<byte[]> {
|
||||
//
|
||||
// @Override
|
||||
// public Class<?> supportJavaTypeKey() {
|
||||
// return byte[].class;
|
||||
// }
|
||||
//
|
||||
// // @Override
|
||||
// // public CellDataTypeEnum supportExcelTypeKey() {
|
||||
// // return CellDataTypeEnum.IMAGE;
|
||||
// // }
|
||||
//
|
||||
// @Override
|
||||
// public byte[] convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws IOException {
|
||||
// if (cellData.getType() == CellDataTypeEnum.IMAGE) {
|
||||
// ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
// cellData.getImageValueList().forEach(image -> {
|
||||
// try {
|
||||
// outputStream.write(image.getImageBytes());
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// });
|
||||
// return outputStream.toByteArray();
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
@ -0,0 +1,106 @@
|
||||
package com.fuyuanshen.equipment.domain;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
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 lombok.Data;
|
||||
|
||||
/**
|
||||
* @Description: 设备表
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Data
|
||||
@TableName("app_device")
|
||||
public class APPDevice1 extends TenantEntity {
|
||||
|
||||
@TableId(value = "app_device_id", type = IdType.AUTO)
|
||||
@Schema(name = "ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(name = "设备类型")
|
||||
private Long deviceType;
|
||||
|
||||
@Schema(name = "设备类型名称")
|
||||
private String deviceTypeName;
|
||||
|
||||
@Schema(name = "客户号")
|
||||
private Long customerId;
|
||||
|
||||
@Schema(name = "所属客户")
|
||||
private String customerName;
|
||||
|
||||
/*@Schema(name = "设备编号")
|
||||
private String deviceNo;*/
|
||||
|
||||
@Schema(name = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
@Schema(name = "设备图片")
|
||||
private String devicePic;
|
||||
|
||||
@Schema(name = "设备MAC")
|
||||
private String deviceMac;
|
||||
|
||||
@Schema(name = "设备IMEI")
|
||||
private String deviceImei;
|
||||
|
||||
@Schema(name = "设备SN")
|
||||
private String deviceSn;
|
||||
|
||||
@Schema(name = "经度")
|
||||
private String longitude;
|
||||
|
||||
@Schema(name = "纬度")
|
||||
private String latitude;
|
||||
|
||||
@Schema(name = "备注")
|
||||
private String remark;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(name = "设备类型名称")
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
@TableField(value = "tenant_id")
|
||||
@Schema(hidden = true)
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 设备状态
|
||||
* 0 失效
|
||||
* 1 正常
|
||||
*/
|
||||
@Schema(name = "设备状态")
|
||||
private Integer deviceStatus;
|
||||
|
||||
/**
|
||||
* 绑定状态
|
||||
* 0 未绑定
|
||||
* 1 已绑定
|
||||
*/
|
||||
@Schema(name = "绑定状态")
|
||||
private Integer bindingStatus;
|
||||
|
||||
/**
|
||||
* 绑定类型
|
||||
* 0 APP
|
||||
* 1 小程序
|
||||
*/
|
||||
@Schema(name = "绑定类型")
|
||||
private Integer bindingType;
|
||||
|
||||
|
||||
public void copy(APPDevice1 source) {
|
||||
BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package com.fuyuanshen.equipment.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.Update;
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-1308:57
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("customer_device")
|
||||
public class CustomerDevice extends TenantEntity {
|
||||
|
||||
@NotNull(groups = Update.class)
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField(value = "customer_id")
|
||||
private Long customerId;
|
||||
|
||||
@TableField(value = "device_id")
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 设备状态
|
||||
* 0 失效
|
||||
* 1 正常
|
||||
*/
|
||||
@TableField(value = "assign_status")
|
||||
private Byte assignStatus;
|
||||
|
||||
}
|
||||
@ -0,0 +1,114 @@
|
||||
package com.fuyuanshen.equipment.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Description: 设备表
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Data
|
||||
@TableName("device")
|
||||
@JsonInclude(JsonInclude.Include.ALWAYS) // 关键注解
|
||||
public class Device extends TenantEntity {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
@Schema(name = "ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(name = "设备记录ID")
|
||||
@TableField(exist = false)
|
||||
private Long assignId;
|
||||
|
||||
@Schema(name = "设备类型")
|
||||
private Long deviceType;
|
||||
|
||||
@Schema(name = "设备类型名称")
|
||||
private String typeName;
|
||||
|
||||
@Schema(name = "客户号")
|
||||
private Long customerId;
|
||||
|
||||
@Schema(name = "所属客户")
|
||||
private String customerName;
|
||||
|
||||
/**
|
||||
* 当前所有者
|
||||
* current_owner_id
|
||||
*/
|
||||
@Schema(name = "当前所有者")
|
||||
private Long currentOwnerId;
|
||||
|
||||
/**
|
||||
* 原始所有者(创建者)
|
||||
* original_owner_id
|
||||
*/
|
||||
@Schema(name = "原始所有者(创建者)")
|
||||
private Long originalOwnerId;
|
||||
|
||||
/**
|
||||
* 原始设备
|
||||
*/
|
||||
@Schema(name = "原始设备")
|
||||
private Long originalDeviceId;
|
||||
|
||||
@Schema(name = "设备编号")
|
||||
private String deviceNo;
|
||||
|
||||
@Schema(name = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
@Schema(name = "设备图片")
|
||||
private String devicePic;
|
||||
|
||||
@Schema(name = "设备MAC")
|
||||
private String deviceMac;
|
||||
|
||||
@Schema(name = "蓝牙名称")
|
||||
private String bluetoothName;
|
||||
|
||||
@Schema(name = "设备IMEI")
|
||||
private String deviceImei;
|
||||
|
||||
@Schema(name = "设备SN")
|
||||
private String deviceSn;
|
||||
|
||||
@Schema(name = "经度")
|
||||
private String longitude;
|
||||
|
||||
@Schema(name = "纬度")
|
||||
private String latitude;
|
||||
|
||||
@Schema(name = "备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 设备状态
|
||||
* 0 失效
|
||||
* 1 正常
|
||||
*/
|
||||
@Schema(name = "设备状态")
|
||||
private Integer deviceStatus;
|
||||
|
||||
/**
|
||||
* 绑定状态
|
||||
* 0 未绑定
|
||||
* 1 已绑定
|
||||
*/
|
||||
@Schema(name = "绑定状态")
|
||||
private Integer bindingStatus;
|
||||
|
||||
/**
|
||||
* 创建人名称
|
||||
*/
|
||||
private String createByName;
|
||||
|
||||
private Long bindingUserId;
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
package com.fuyuanshen.equipment.domain;
|
||||
|
||||
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 lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 设备分配记录表
|
||||
*
|
||||
* @TableName device_assignments
|
||||
*/
|
||||
@TableName(value = "device_assignments")
|
||||
@Data
|
||||
public class DeviceAssignments extends TenantEntity {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备id
|
||||
*/
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 分配方
|
||||
*/
|
||||
private Long fromCustomerId;
|
||||
|
||||
/**
|
||||
* 接收方
|
||||
*/
|
||||
private Long toCustomerId;
|
||||
|
||||
/**
|
||||
* 分配者
|
||||
* assigner_name
|
||||
*/
|
||||
private Long assignerId;
|
||||
private String assignerName;
|
||||
|
||||
/**
|
||||
* 接收者
|
||||
* assignee_name
|
||||
*/
|
||||
private Long assigneeId;
|
||||
private String assigneeName;
|
||||
|
||||
/**
|
||||
* 分配时间
|
||||
*/
|
||||
private LocalDateTime assignedAt;
|
||||
|
||||
/**
|
||||
* 0 未授权
|
||||
* 1 已授权
|
||||
* 是否同步授权了设备类型
|
||||
*/
|
||||
private Integer deviceTypeGranted;
|
||||
|
||||
/**
|
||||
* 0 否
|
||||
* 1 是
|
||||
* 是否直接分配(用于父级显示)
|
||||
*/
|
||||
private Integer direct;
|
||||
|
||||
/**
|
||||
* 0 否
|
||||
* 1 是
|
||||
* 设备是否有效
|
||||
*/
|
||||
private Integer active;
|
||||
|
||||
/**
|
||||
* 分配等级(用于失效)
|
||||
*/
|
||||
private String lever;
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.fuyuanshen.equipment.domain;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
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 lombok.Data;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/24
|
||||
**/
|
||||
@Data
|
||||
@TableName("device_log")
|
||||
public class DeviceLog extends TenantEntity {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
// @Schema(value = "ID")
|
||||
private Long id;
|
||||
|
||||
// @Schema(value = "设备行为")
|
||||
private String deviceAction;
|
||||
|
||||
// @Schema(value = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
// @Schema(value = "数据来源")
|
||||
private String dataSource;
|
||||
|
||||
// @Schema(value = "内容")
|
||||
private String content;
|
||||
|
||||
public void copy(DeviceLog source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
package com.fuyuanshen.equipment.domain;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Description: 设备类型
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/14
|
||||
**/
|
||||
@Data
|
||||
@TableName("device_type")
|
||||
public class DeviceType extends TenantEntity {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
@Schema(name = "ID", hidden = true)
|
||||
private Long id;
|
||||
|
||||
@Schema(name = "客户号")
|
||||
private Long customerId;
|
||||
|
||||
@Schema(name = "创建该类型的客户")
|
||||
private Long ownerCustomerId;
|
||||
|
||||
/**
|
||||
* 原始所有者(创建者)
|
||||
* original_owner_id
|
||||
*/
|
||||
@Schema(name = "原始所有者(创建者)")
|
||||
private Long originalOwnerId;
|
||||
|
||||
/**
|
||||
* 原始设备
|
||||
*/
|
||||
@Schema(name = "原始设备类型")
|
||||
private Long originalDeviceId;
|
||||
|
||||
@NotBlank(message = "设备类型名称不能为空")
|
||||
@Schema(name = "类型名称", required = true)
|
||||
private String typeName;
|
||||
|
||||
@Schema(name = "是否支持蓝牙")
|
||||
private Boolean isSupportBle;
|
||||
|
||||
@Schema(name = "定位方式", example = "0:无;1:GPS;2:基站;3:wifi;4:北斗")
|
||||
private String locateMode;
|
||||
|
||||
@Schema(name = "联网方式", example = "0:无;1:4G;2:WIFI")
|
||||
private String networkWay;
|
||||
|
||||
@Schema(name = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
private String communicationMode;
|
||||
|
||||
/**
|
||||
* 创建人名称
|
||||
*/
|
||||
private String createByName;
|
||||
|
||||
public void copy(DeviceType source) {
|
||||
BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,95 @@
|
||||
package com.fuyuanshen.equipment.domain;
|
||||
|
||||
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 lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 设备分配权限表 (解决跨客户共享)
|
||||
*
|
||||
* @TableName device_type_grants
|
||||
*/
|
||||
@TableName(value = "device_type_grants")
|
||||
@Data
|
||||
public class DeviceTypeGrants extends TenantEntity {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private Long deviceTypeId;
|
||||
|
||||
/**
|
||||
* 被授权的客户
|
||||
*/
|
||||
private Long customerId;
|
||||
|
||||
/**
|
||||
* 授权方客户
|
||||
*/
|
||||
private Long grantorCustomerId;
|
||||
|
||||
/**
|
||||
* 生成日期
|
||||
*/
|
||||
private Date grantedAt;
|
||||
|
||||
/**
|
||||
* 关联分配记录
|
||||
*/
|
||||
private Long assignmentId;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (this == that) {
|
||||
return true;
|
||||
}
|
||||
if (that == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != that.getClass()) {
|
||||
return false;
|
||||
}
|
||||
DeviceTypeGrants other = (DeviceTypeGrants) that;
|
||||
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) && (this.getDeviceTypeId() == null ? other.getDeviceTypeId() == null : this.getDeviceTypeId().equals(other.getDeviceTypeId())) && (this.getCustomerId() == null ? other.getCustomerId() == null : this.getCustomerId().equals(other.getCustomerId())) && (this.getGrantorCustomerId() == null ? other.getGrantorCustomerId() == null : this.getGrantorCustomerId().equals(other.getGrantorCustomerId())) && (this.getGrantedAt() == null ? other.getGrantedAt() == null : this.getGrantedAt().equals(other.getGrantedAt())) && (this.getAssignmentId() == null ? other.getAssignmentId() == null : this.getAssignmentId().equals(other.getAssignmentId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
||||
result = prime * result + ((getDeviceTypeId() == null) ? 0 : getDeviceTypeId().hashCode());
|
||||
result = prime * result + ((getCustomerId() == null) ? 0 : getCustomerId().hashCode());
|
||||
result = prime * result + ((getGrantorCustomerId() == null) ? 0 : getGrantorCustomerId().hashCode());
|
||||
result = prime * result + ((getGrantedAt() == null) ? 0 : getGrantedAt().hashCode());
|
||||
result = prime * result + ((getAssignmentId() == null) ? 0 : getAssignmentId().hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(" [");
|
||||
sb.append("Hash = ").append(hashCode());
|
||||
sb.append(", id=").append(id);
|
||||
sb.append(", deviceTypeId=").append(deviceTypeId);
|
||||
sb.append(", customerId=").append(customerId);
|
||||
sb.append(", grantorCustomerId=").append(grantorCustomerId);
|
||||
sb.append(", grantedAt=").append(grantedAt);
|
||||
sb.append(", assignmentId=").append(assignmentId);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
package com.fuyuanshen.equipment.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* APP用户信息对象 app_user
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-06-27
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("app_user")
|
||||
public class UserApp extends TenantEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@TableId(value = "user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 用户类型(app_user系统用户)
|
||||
*/
|
||||
private String userType;
|
||||
|
||||
/**
|
||||
* 用户邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
private String phonenumber;
|
||||
|
||||
/**
|
||||
* 用户性别(0男 1女 2未知)
|
||||
*/
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 头像地址
|
||||
*/
|
||||
private Long avatar;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 删除标志(0代表存在 1代表删除)
|
||||
*/
|
||||
@TableLogic
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 最后登录IP
|
||||
*/
|
||||
private String loginIp;
|
||||
|
||||
/**
|
||||
* 最后登录时间
|
||||
*/
|
||||
private Date loginDate;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@ -0,0 +1,95 @@
|
||||
package com.fuyuanshen.equipment.domain.bo;
|
||||
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import com.fuyuanshen.equipment.domain.UserApp;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* APP用户信息业务对象 app_user
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-06-27
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = UserApp.class, reverseConvertGenerate = false)
|
||||
public class UserAppBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@NotNull(message = "用户ID不能为空", groups = { EditGroup.class })
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
@NotBlank(message = "用户账号不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
// @NotBlank(message = "用户昵称不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 用户类型(app_user系统用户)
|
||||
*/
|
||||
private String userType;
|
||||
|
||||
/**
|
||||
* 用户邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
private String phonenumber;
|
||||
|
||||
/**
|
||||
* 用户性别(0男 1女 2未知)
|
||||
*/
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 头像地址
|
||||
*/
|
||||
private Long avatar;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 最后登录IP
|
||||
*/
|
||||
private String loginIp;
|
||||
|
||||
/**
|
||||
* 最后登录时间
|
||||
*/
|
||||
private Date loginDate;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package com.fuyuanshen.equipment.domain.dto;
|
||||
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 绑定设备参数
|
||||
*/
|
||||
@Data
|
||||
public class AppDeviceBo {
|
||||
/**
|
||||
* 设备IMEI
|
||||
*/
|
||||
private String deviceImei;
|
||||
|
||||
/**
|
||||
* 设备MAC
|
||||
*/
|
||||
private String deviceMac;
|
||||
|
||||
/**
|
||||
* 通讯方式 0:4G; 1:蓝牙
|
||||
*/
|
||||
@NotNull(message = "通讯方式不能为空", groups = { EditGroup.class })
|
||||
private Integer communicationMode;
|
||||
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
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.fuyuanshen.equipment.converter.IgnoreFailedImageConverter;
|
||||
import lombok.Data;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-0618:16
|
||||
*/
|
||||
@Data
|
||||
@HeadRowHeight(20) // 表头行高
|
||||
@ContentRowHeight(100) // 内容行高
|
||||
public class DeviceExcelExportDTO {
|
||||
|
||||
@ExcelProperty("ID")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("设备类型")
|
||||
private Long deviceType;
|
||||
|
||||
// @ExcelProperty("客户号")
|
||||
// private Long customerId;
|
||||
|
||||
@ExcelProperty("所属客户")
|
||||
private String customerName;
|
||||
|
||||
@ExcelProperty("设备名称")
|
||||
@ColumnWidth(20)
|
||||
private String deviceName;
|
||||
|
||||
@ExcelProperty(value = "设备图片", converter = IgnoreFailedImageConverter.class)
|
||||
@ColumnWidth(15) // 设置图片列宽度
|
||||
private URL devicePic; // 使用URL类型
|
||||
|
||||
@ExcelProperty("设备MAC")
|
||||
@ColumnWidth(20)
|
||||
private String deviceMac;
|
||||
|
||||
@ExcelProperty("设备IMEI")
|
||||
@ColumnWidth(20)
|
||||
private String deviceImei;
|
||||
|
||||
@ExcelProperty("经度")
|
||||
private String longitude;
|
||||
|
||||
@ExcelProperty("纬度")
|
||||
private String latitude;
|
||||
|
||||
@ExcelProperty("备注")
|
||||
@ColumnWidth(30)
|
||||
private String remark;
|
||||
|
||||
@ExcelProperty("设备类型名称")
|
||||
@ColumnWidth(20)
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 设备状态
|
||||
* 0 失效
|
||||
* 1 正常
|
||||
*/
|
||||
@ExcelProperty("设备状态")
|
||||
@ColumnWidth(20)
|
||||
private String deviceStatus;
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
@ColumnWidth(20)
|
||||
private String createTime;
|
||||
|
||||
@ExcelProperty("创建人")
|
||||
@ColumnWidth(20)
|
||||
private String createBy;
|
||||
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
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;
|
||||
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.fuyuanshen.equipment.domain.form;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Description: 设备类型
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/14
|
||||
**/
|
||||
@Data
|
||||
public class DeviceTypeForm {
|
||||
|
||||
@Schema(name = "ID", hidden = true)
|
||||
private Long id;
|
||||
|
||||
@Schema(name = "类型名称", required = true)
|
||||
private String typeName;
|
||||
|
||||
@Schema(name = "是否支持蓝牙")
|
||||
private Boolean isSupportBle;
|
||||
|
||||
@Schema(name = "定位方式", example = "0:无;1:GPS;2:基站;3:wifi;4:北斗")
|
||||
private String locateMode;
|
||||
|
||||
@Schema(name = "联网方式", example = "0:无;1:4G;2:WIFI")
|
||||
private String networkWay;
|
||||
|
||||
@Schema(name = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
private String communicationMode;
|
||||
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
package com.fuyuanshen.equipment.domain.query;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Data
|
||||
public class APPDeviceQueryCriteria1 {
|
||||
|
||||
@Schema(name = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
@Schema(name = "设备类型")
|
||||
private Long deviceType;
|
||||
|
||||
@Schema(name = "设备MAC")
|
||||
private String deviceMac;
|
||||
|
||||
@Schema(name = "设备IMEI")
|
||||
private String deviceImei;
|
||||
|
||||
@Schema(name = "设备SN")
|
||||
private String deviceSn;
|
||||
|
||||
/**
|
||||
* 设备状态
|
||||
* 0 失效
|
||||
* 1 正常
|
||||
*/
|
||||
@Schema(name = "设备状态 0 失效 1 正常 ")
|
||||
private Integer deviceStatus;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
|
||||
@Schema(name = "创建时间")
|
||||
private List<Timestamp> createTime;
|
||||
|
||||
@Schema(name = "页码", example = "1")
|
||||
private Integer page = 1;
|
||||
|
||||
@Schema(name = "每页数据量", example = "10")
|
||||
private Integer size = 10;
|
||||
|
||||
@Schema(name = "客户id")
|
||||
private Long customerId;
|
||||
private Set<Long> customerIds;
|
||||
|
||||
@Schema(name = "当前所有者")
|
||||
private Long currentOwnerId;
|
||||
|
||||
@Schema(name = "租户ID")
|
||||
private Long tenantId;
|
||||
|
||||
@Schema(name = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
private Integer communicationMode;
|
||||
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package com.fuyuanshen.equipment.domain.query;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-07-0910:27
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DeviceAssignmentQuery implements Serializable {
|
||||
|
||||
/**
|
||||
* 表示这个 serialVersionUID 字段是专门为 Java 序列化机制服务的。
|
||||
*/
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 分配者
|
||||
*/
|
||||
private Long assignerId;
|
||||
|
||||
/**
|
||||
* 接收者
|
||||
*/
|
||||
private Long assigneeId;
|
||||
|
||||
/**
|
||||
* 0 否
|
||||
* 1 是
|
||||
* 设备是否有效
|
||||
*/
|
||||
private Integer active;
|
||||
|
||||
/**
|
||||
* 分配等级(用于失效)
|
||||
*/
|
||||
private String lever;
|
||||
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
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.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 设备查询参数
|
||||
*
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Data
|
||||
public class DeviceQueryCriteria extends BaseEntity {
|
||||
|
||||
@Schema(name = "设备id")
|
||||
private Long deviceId;
|
||||
|
||||
@Schema(name = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
@Schema(name = "设备类型")
|
||||
private Long deviceType;
|
||||
|
||||
@Schema(name = "设备MAC")
|
||||
private String deviceMac;
|
||||
|
||||
@Schema(name = "设备IMEI")
|
||||
private String deviceImei;
|
||||
|
||||
@Schema(name = "设备SN")
|
||||
private String deviceSn;
|
||||
|
||||
/**
|
||||
* 设备状态
|
||||
* 0 失效
|
||||
* 1 正常
|
||||
*/
|
||||
@Schema(name = "设备状态 0 失效 1 正常 ")
|
||||
private Integer deviceStatus;
|
||||
|
||||
@Schema(name = "页码", example = "1")
|
||||
private Integer pageNum = 1;
|
||||
|
||||
@Schema(name = "每页数据量", example = "10")
|
||||
private Integer pageSize = 10;
|
||||
|
||||
@Schema(name = "客户id")
|
||||
private Long customerId;
|
||||
private Set<Long> customerIds;
|
||||
|
||||
@Schema(name = "当前所有者")
|
||||
private Long currentOwnerId;
|
||||
|
||||
@Schema(name = "租户ID")
|
||||
private String tenantId;
|
||||
|
||||
@Schema(name = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
private Integer communicationMode;
|
||||
|
||||
/* app绑定用户id */
|
||||
private Long bindingUserId;
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
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 = "设备类型id")
|
||||
private Long deviceTypeId;
|
||||
|
||||
@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 pageNum = 1;
|
||||
|
||||
@Schema(name = "每页数据量", example = "10")
|
||||
private Integer pageSize = 10;
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.fuyuanshen.equipment.domain.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AppDeviceVo {
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 设备IMEI
|
||||
*/
|
||||
private String deviceImei;
|
||||
|
||||
/**
|
||||
* 设备MAC
|
||||
*/
|
||||
private String deviceMac;
|
||||
|
||||
/**
|
||||
* 通讯方式 0:4G;1:蓝牙
|
||||
*/
|
||||
private Integer communicationMode;
|
||||
|
||||
/**
|
||||
* 设备图片
|
||||
*/
|
||||
private String devicePic;
|
||||
|
||||
/**
|
||||
* 蓝牙名称
|
||||
*/
|
||||
private String bluetoothName;
|
||||
}
|
||||
@ -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,120 @@
|
||||
package com.fuyuanshen.equipment.domain.vo;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import com.fuyuanshen.common.excel.annotation.ExcelDictFormat;
|
||||
import com.fuyuanshen.common.excel.convert.ExcelDictConvert;
|
||||
import com.fuyuanshen.equipment.domain.UserApp;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* APP用户信息视图对象 app_user
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-06-27
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@AutoMapper(target = UserApp.class)
|
||||
public class UserAppVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@ExcelProperty(value = "用户ID")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
@ExcelProperty(value = "用户账号")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
@ExcelProperty(value = "用户昵称")
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 用户类型(app_user系统用户)
|
||||
*/
|
||||
@ExcelProperty(value = "用户类型", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(readConverterExp = "a=pp_user系统用户")
|
||||
private String userType;
|
||||
|
||||
/**
|
||||
* 用户邮箱
|
||||
*/
|
||||
@ExcelProperty(value = "用户邮箱")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
@ExcelProperty(value = "手机号码")
|
||||
private String phonenumber;
|
||||
|
||||
/**
|
||||
* 用户性别(0男 1女 2未知)
|
||||
*/
|
||||
@ExcelProperty(value = "用户性别", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(readConverterExp = "0=男,1=女,2=未知")
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 头像地址
|
||||
*/
|
||||
@ExcelProperty(value = "头像地址")
|
||||
private Long avatar;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@ExcelProperty(value = "密码")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
*/
|
||||
@ExcelProperty(value = "帐号状态", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 最后登录IP
|
||||
*/
|
||||
@ExcelProperty(value = "最后登录IP")
|
||||
private String loginIp;
|
||||
|
||||
/**
|
||||
* 最后登录时间
|
||||
*/
|
||||
@ExcelProperty(value = "最后登录时间")
|
||||
private Date loginDate;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ExcelProperty(value = "备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 租户编号
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
private Long deptId;
|
||||
}
|
||||
@ -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,34 @@
|
||||
package com.fuyuanshen.equipment.excel;
|
||||
|
||||
import com.fuyuanshen.customer.mapper.CustomerMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import com.fuyuanshen.system.service.ISysOssService;
|
||||
import lombok.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-1414:56
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor(force = true)
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class DeviceImportParams {
|
||||
|
||||
private DeviceService deviceService;
|
||||
private DeviceMapper deviceMapper;
|
||||
private CustomerMapper customerMapper;
|
||||
private DeviceTypeMapper deviceTypeMapper;
|
||||
private ISysOssService ossService;
|
||||
private MultipartFile file;
|
||||
private String filePath;
|
||||
private String ip;
|
||||
private String username;
|
||||
private Long userId;
|
||||
private String tenantId;
|
||||
|
||||
}
|
||||
@ -0,0 +1,263 @@
|
||||
package com.fuyuanshen.equipment.excel;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.read.listener.ReadListener;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.fuyuanshen.common.core.domain.model.LoginUser;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.equipment.constants.DeviceConstants;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.dto.DeviceExcelImportDTO;
|
||||
import com.fuyuanshen.equipment.domain.dto.ImportResult;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.handler.ImageWriteHandler;
|
||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||
import org.apache.poi.openxml4j.util.ZipSecureFile;
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class UploadDeviceDataListener implements ReadListener<DeviceExcelImportDTO> {
|
||||
|
||||
// 存储图片数据的映射
|
||||
private final Map<Integer, byte[]> rowImageMap = new HashMap<>();
|
||||
|
||||
private final DeviceImportParams params;
|
||||
|
||||
private final Map<Integer, Device> rowDeviceMap = new HashMap<>();
|
||||
private final Map<Integer, DeviceExcelImportDTO> rowDtoMap = new HashMap<>();
|
||||
private final List<Integer> rowIndexList = new ArrayList<>();
|
||||
|
||||
private int successCount = 0;
|
||||
private int failureCount = 0;
|
||||
private final List<DeviceExcelImportDTO> failedRecords = new ArrayList<>();
|
||||
|
||||
|
||||
public UploadDeviceDataListener(DeviceImportParams params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
|
||||
public ImportResult getImportResult() {
|
||||
ImportResult result = new ImportResult();
|
||||
result.setSuccessCount(successCount);
|
||||
result.setFailureCount(failureCount);
|
||||
|
||||
// 准备失败记录(包含图片数据)
|
||||
List<DeviceExcelImportDTO> failedRecordsWithImages = new ArrayList<>();
|
||||
|
||||
for (DeviceExcelImportDTO failedRecord : failedRecords) {
|
||||
// 获取原始行号
|
||||
Integer rowIndex = null;
|
||||
for (Map.Entry<Integer, DeviceExcelImportDTO> entry : rowDtoMap.entrySet()) {
|
||||
if (entry.getValue() == failedRecord) {
|
||||
rowIndex = entry.getKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (rowIndex != null) {
|
||||
// 创建副本,避免修改原始数据
|
||||
DeviceExcelImportDTO recordWithImage = new DeviceExcelImportDTO();
|
||||
BeanUtil.copyProperties(failedRecord, recordWithImage);
|
||||
|
||||
// 设置图片数据
|
||||
byte[] imageData = rowImageMap.get(rowIndex);
|
||||
if (imageData != null) {
|
||||
recordWithImage.setDevicePicFromBytes(imageData);
|
||||
}
|
||||
|
||||
failedRecordsWithImages.add(recordWithImage);
|
||||
} else {
|
||||
failedRecordsWithImages.add(failedRecord);
|
||||
}
|
||||
}
|
||||
|
||||
result.setFailedRecords(failedRecordsWithImages);
|
||||
|
||||
// 生成错误报告
|
||||
if (!failedRecordsWithImages.isEmpty()) {
|
||||
try {
|
||||
// 生成唯一的文件名
|
||||
String fileName = "import_errors_" + System.currentTimeMillis() + ".xlsx";
|
||||
|
||||
// 创建错误报告目录
|
||||
String errorDirPath = params.getFilePath() + DeviceConstants.ERROR_REPORT_DIR;
|
||||
File errorDir = new File(errorDirPath);
|
||||
if (!errorDir.exists() && !errorDir.mkdirs()) {
|
||||
log.error("无法创建错误报告目录: {}", errorDirPath);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 保存错误报告到文件(包含图片)
|
||||
File errorFile = new File(errorDir, fileName);
|
||||
EasyExcel.write(errorFile, DeviceExcelImportDTO.class).registerWriteHandler(new ImageWriteHandler()) // 添加图片处理
|
||||
.sheet("失败数据").doWrite(failedRecordsWithImages);
|
||||
|
||||
// 生成访问URL
|
||||
// String errorExcelUrl = params.getIp() + DeviceConstants.FILE_ACCESS_PREFIX + "/" + DeviceConstants.ERROR_REPORT_DIR + "/" + fileName;
|
||||
SysOssVo upload = params.getOssService().upload(errorFile);
|
||||
result.setErrorExcelUrl(upload.getUrl());
|
||||
log.info("错误报告已保存: {}", errorFile.getAbsolutePath());
|
||||
} catch (Exception e) {
|
||||
log.error("生成错误报告失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void invoke(DeviceExcelImportDTO data, AnalysisContext context) {
|
||||
log.info("解析到一条数据: {}", JSON.toJSONString(data));
|
||||
int rowIndex = context.readRowHolder().getRowIndex();
|
||||
|
||||
Device device = new Device();
|
||||
BeanUtil.copyProperties(data, device, true);
|
||||
rowDeviceMap.put(rowIndex, device);
|
||||
rowDtoMap.put(rowIndex, data);
|
||||
rowIndexList.add(rowIndex);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext context) {
|
||||
try {
|
||||
processImages();
|
||||
processDataRowByRow();
|
||||
log.info("数据处理完成!成功:{}条,失败:{}条", successCount, failureCount);
|
||||
} catch (Exception e) {
|
||||
log.error("数据处理失败:{}", e.getMessage(), e);
|
||||
throw new RuntimeException("导入失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void processDataRowByRow() {
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
for (Integer rowIndex : rowIndexList) {
|
||||
Device device = rowDeviceMap.get(rowIndex);
|
||||
DeviceExcelImportDTO originalDto = rowDtoMap.get(rowIndex);
|
||||
try {
|
||||
// DeviceQueryCriteria criteria = new DeviceQueryCriteria();
|
||||
// criteria.setDeviceMac(device.getDeviceMac());
|
||||
// criteria.setTenantId(params.getTenantId());
|
||||
// List<Device> deviceList = params.getDeviceMapper().findAll(criteria);
|
||||
// if (!deviceList.isEmpty()) {
|
||||
// throw new RuntimeException("设备MAC重复");
|
||||
// }
|
||||
// device.setTenantId(params.getTenantId());
|
||||
|
||||
// 设备类型
|
||||
QueryWrapper<DeviceType> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("type_name", device.getTypeName());
|
||||
// wrapper.eq("customer_id", params.getUserId());
|
||||
List<DeviceType> deviceTypes = params.getDeviceTypeMapper().selectList(wrapper);
|
||||
if (CollectionUtil.isNotEmpty(deviceTypes)) {
|
||||
device.setDeviceType(deviceTypes.get(0).getId());
|
||||
}
|
||||
device.setCurrentOwnerId(loginUser.getUserId());
|
||||
device.setOriginalOwnerId(loginUser.getUserId());
|
||||
device.setCreateByName(loginUser.getNickname());
|
||||
params.getDeviceService().save(device);
|
||||
successCount++;
|
||||
log.info("行 {} 数据插入成功", rowIndex);
|
||||
} catch (Exception e) {
|
||||
failureCount++;
|
||||
failedRecords.add(originalDto);
|
||||
log.error("行 {} 数据插入失败: {}", rowIndex, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processImages() {
|
||||
try (OPCPackage opcPackage = OPCPackage.open(params.getFile().getInputStream())) {
|
||||
ZipSecureFile.setMinInflateRatio(-1.0d);
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(opcPackage);
|
||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||
|
||||
XSSFDrawing drawing = sheet.getDrawingPatriarch();
|
||||
if (drawing == null) return;
|
||||
|
||||
for (XSSFShape shape : drawing.getShapes()) {
|
||||
if (shape instanceof XSSFPicture) {
|
||||
XSSFPicture picture = (XSSFPicture) shape;
|
||||
XSSFClientAnchor anchor = picture.getPreferredSize();
|
||||
int rowIndex = anchor.getRow1();
|
||||
int colIndex = anchor.getCol1();
|
||||
|
||||
if (colIndex == 2) {
|
||||
Device device = rowDeviceMap.get(rowIndex);
|
||||
if (device != null) {
|
||||
try {
|
||||
byte[] imageData = picture.getPictureData().getData();
|
||||
String extraValue = getCellValue(sheet, rowIndex, 4);
|
||||
String imageUrl = uploadAndGenerateUrl(imageData, extraValue);
|
||||
device.setDevicePic(imageUrl);
|
||||
|
||||
// 2. 保存图片数据到DTO,用于错误报告
|
||||
rowImageMap.put(rowIndex, imageData);
|
||||
} catch (Exception e) {
|
||||
log.error("行 {} 图片处理失败: {}", rowIndex, e.getMessage());
|
||||
device.setDevicePic(null); // 设置为空,让插入继续
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("图片处理失败:{}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private String getCellValue(XSSFSheet sheet, int rowIndex, int colIndex) {
|
||||
XSSFRow row = sheet.getRow(rowIndex);
|
||||
if (row == null) return null;
|
||||
|
||||
XSSFCell cell = row.getCell(colIndex);
|
||||
if (cell == null) return null;
|
||||
|
||||
return cell.toString();
|
||||
}
|
||||
|
||||
private String uploadAndGenerateUrl(byte[] imageData, String deviceMac) {
|
||||
if (imageData == null || imageData.length == 0) {
|
||||
log.warn("图片数据为空");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
String fileExtension = "jpg";
|
||||
String newFileName = "PS_" + new Random(8) + "." + fileExtension;
|
||||
// String targetDirPath = params.getFilePath() + DeviceConstants.FILE_ACCESS_ISOLATION;
|
||||
// File targetDir = new File(targetDirPath);
|
||||
//
|
||||
// if (!targetDir.exists() && !targetDir.mkdirs()) {
|
||||
// log.error("无法创建目录: {}", targetDirPath);
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// File newFile = new File(targetDir, newFileName);
|
||||
// Files.write(newFile.toPath(), imageData);
|
||||
//
|
||||
// return params.getIp() + DeviceConstants.FILE_ACCESS_PREFIX + "/" + DeviceConstants.FILE_ACCESS_ISOLATION + "/" + newFileName;
|
||||
SysOssVo upload = params.getOssService().upload(imageData, newFileName);
|
||||
return upload.getUrl();
|
||||
} catch (Exception e) {
|
||||
log.error("保存图片失败", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
package com.fuyuanshen.equipment.handler;
|
||||
|
||||
import com.alibaba.excel.write.handler.SheetWriteHandler;
|
||||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
|
||||
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
||||
import org.apache.poi.xssf.usermodel.XSSFDrawing;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-0718:05
|
||||
*/
|
||||
public class ImageWriteHandler implements SheetWriteHandler {
|
||||
|
||||
@Override
|
||||
public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
|
||||
// 不需要实现
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
|
||||
Workbook workbook = writeWorkbookHolder.getWorkbook();
|
||||
Sheet sheet = writeSheetHolder.getSheet();
|
||||
|
||||
// 获取设备图片列索引(假设是第4列,索引3)
|
||||
int imageColIndex = 3;
|
||||
|
||||
// 遍历所有行
|
||||
for (int rowIndex = 1; rowIndex <= sheet.getLastRowNum(); rowIndex++) { // 从第2行开始(跳过标题)
|
||||
Row row = sheet.getRow(rowIndex);
|
||||
if (row == null) continue;
|
||||
|
||||
Cell imageCell = row.getCell(imageColIndex);
|
||||
if (imageCell == null) continue;
|
||||
|
||||
// 获取图片数据
|
||||
byte[] imageData = null;
|
||||
if (imageCell.getCellType() == CellType.STRING) {
|
||||
// 处理Base64编码的图片(如果需要)
|
||||
}
|
||||
|
||||
if (imageData != null && imageData.length > 0) {
|
||||
try {
|
||||
// 添加图片到工作表
|
||||
int pictureIdx = workbook.addPicture(imageData, Workbook.PICTURE_TYPE_JPEG);
|
||||
|
||||
// 创建绘图对象
|
||||
if (sheet instanceof XSSFSheet) {
|
||||
XSSFSheet xssfSheet = (XSSFSheet) sheet;
|
||||
XSSFDrawing drawing = xssfSheet.createDrawingPatriarch();
|
||||
|
||||
// 设置图片位置
|
||||
XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, imageColIndex, rowIndex, imageColIndex + 1, rowIndex + 1);
|
||||
|
||||
// 创建图片
|
||||
drawing.createPicture(anchor, pictureIdx);
|
||||
}
|
||||
|
||||
// 清除单元格内容
|
||||
imageCell.setBlank();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.fuyuanshen.equipment.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.fuyuanshen.equipment.domain.DeviceAssignments;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceAssignmentQuery;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 97433
|
||||
* @description 针对表【device_assignments】的数据库操作Mapper
|
||||
* @createDate 2025-06-19 18:19:13
|
||||
* @Entity system.domain.DeviceAssignments
|
||||
*/
|
||||
@Mapper
|
||||
public interface DeviceAssignmentsMapper extends BaseMapper<DeviceAssignments> {
|
||||
|
||||
/**
|
||||
* 查询设备分配信息
|
||||
*
|
||||
* @param deviceAssignmentQuery
|
||||
* @return
|
||||
*/
|
||||
List<DeviceAssignments> deviceAssignmentsMapper(@Param("query") DeviceAssignmentQuery deviceAssignmentQuery);
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
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.Device;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Mapper
|
||||
public interface DeviceMapper extends BaseMapper<Device> {
|
||||
|
||||
/**
|
||||
* 分页查询设备
|
||||
*
|
||||
* @param criteria
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
IPage<Device> findAll(@Param("criteria") DeviceQueryCriteria criteria, Page<Device> page);
|
||||
|
||||
List<Device> findAll(@Param("criteria") DeviceQueryCriteria criteria);
|
||||
|
||||
List<Device> findAllDevices(@Param("criteria") DeviceQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据条件查询
|
||||
*
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
List<Device> findDevices(@Param("criteria") DeviceQueryCriteria criteria);
|
||||
|
||||
Page<AppDeviceVo> queryAppDeviceList(Page<AppDeviceVo> page, @Param("criteria") DeviceQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 获取分配设备的客户
|
||||
*
|
||||
* @param customerId
|
||||
* @return
|
||||
*/
|
||||
Device getAssignCustomer(Long customerId);
|
||||
|
||||
/**
|
||||
* 获取设备链
|
||||
*
|
||||
* @param originalDeviceId
|
||||
* @return
|
||||
*/
|
||||
List<Device> findByOriginalDeviceId(Long originalDeviceId);
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.fuyuanshen.equipment.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.fuyuanshen.equipment.domain.DeviceTypeGrants;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author 97433
|
||||
* @description 针对表【device_type_grants】的数据库操作Mapper
|
||||
* @createDate 2025-06-19 13:49:33
|
||||
* @Entity generator.domain.DeviceTypeGrants
|
||||
*/
|
||||
@Mapper
|
||||
public interface DeviceTypeGrantsMapper extends BaseMapper<DeviceTypeGrants> {
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
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<DeviceType> page);
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有设备类型
|
||||
*
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
List<DeviceType> findAll(@Param("criteria") DeviceTypeQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 获取已经分配的设备类型
|
||||
*
|
||||
* @param customerId
|
||||
* @return
|
||||
*/
|
||||
DeviceType getAssignType(@Param("deviceType") Long deviceType, @Param("customerId") Long customerId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.fuyuanshen.equipment.mapper;
|
||||
|
||||
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import com.fuyuanshen.equipment.domain.UserApp;
|
||||
import com.fuyuanshen.equipment.domain.vo.UserAppVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* APP用户信息Mapper接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-06-27
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserAppMapper extends BaseMapperPlus<UserApp, UserAppVo> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.fuyuanshen.equipment.service;
|
||||
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.equipment.domain.bo.UserAppBo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* APP用户信息Service接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-06-27
|
||||
*/
|
||||
public interface AppUserService {
|
||||
|
||||
/**
|
||||
* 修改APP用户信息
|
||||
*
|
||||
* @param bo APP用户信息
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
Boolean updateByBo(UserAppBo bo);
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package com.fuyuanshen.equipment.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fuyuanshen.equipment.domain.DeviceAssignments;
|
||||
|
||||
/**
|
||||
* @author 97433
|
||||
* @description 针对表【device_assignments】的数据库操作Service
|
||||
* @createDate 2025-06-19 18:19:13
|
||||
*/
|
||||
public interface DeviceAssignmentsService extends IService<DeviceAssignments> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,94 @@
|
||||
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.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.CustomerVo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
public interface DeviceService extends IService<Device> {
|
||||
|
||||
/**
|
||||
* 查询设备数据分页
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @param page 分页参数
|
||||
* @return PageResult
|
||||
*/
|
||||
TableDataInfo<Device> queryAll(DeviceQueryCriteria criteria, Page<Device> page) throws IOException;
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
*
|
||||
* @param criteria 条件参数
|
||||
* @return List<DeviceDto>
|
||||
*/
|
||||
List<Device> queryAll(DeviceQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 查询所有设备信息
|
||||
*
|
||||
* @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(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 解绑设备
|
||||
*
|
||||
* @param deviceForm
|
||||
*/
|
||||
void unbindDevice(DeviceForm deviceForm);
|
||||
|
||||
TableDataInfo<AppDeviceVo> queryAppDeviceList(DeviceQueryCriteria bo, PageQuery pageQuery);
|
||||
|
||||
int bindDevice(AppDeviceBo bo);
|
||||
|
||||
int unBindDevice(Long id);
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.fuyuanshen.equipment.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fuyuanshen.equipment.domain.DeviceTypeGrants;
|
||||
|
||||
/**
|
||||
* @author 97433
|
||||
* @description 针对表【device_type_grants】的数据库操作Service
|
||||
* @createDate 2025-06-19 13:49:33
|
||||
*/
|
||||
public interface DeviceTypeGrantsService extends IService<DeviceTypeGrants> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
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.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceTypeForm;
|
||||
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
|
||||
*/
|
||||
TableDataInfo<DeviceType> queryAll(DeviceTypeQueryCriteria criteria, Page<DeviceType> 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(DeviceTypeForm resources);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteAll(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获取设备类型通讯方式
|
||||
*
|
||||
* @param id /
|
||||
* @return DeviceTypeDto
|
||||
*/
|
||||
DeviceType getCommunicationMode(Long id);
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fuyuanshen.equipment.domain.DeviceAssignments;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceAssignmentsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author 97433
|
||||
* @description 针对表【device_assignments】的数据库操作Service实现
|
||||
* @createDate 2025-06-19 18:19:13
|
||||
*/
|
||||
@Service
|
||||
public class DeviceAssignmentsServiceImpl extends ServiceImpl<DeviceAssignmentsMapper, DeviceAssignments> implements DeviceAssignmentsService {
|
||||
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.util.DateUtils;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.DeviceExcelExportDTO;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-06-0618:22
|
||||
*/
|
||||
@Service
|
||||
public class DeviceExportService {
|
||||
|
||||
public void export(List<Device> devices, HttpServletResponse response) {
|
||||
try {
|
||||
String fileName = "设备列表_" + System.currentTimeMillis() + ".xlsx";
|
||||
// 使用URLEncoder进行RFC 5987编码
|
||||
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()).replaceAll("\\+", "%20");
|
||||
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
// 使用RFC 5987标准编码文件名
|
||||
response.setHeader("Content-disposition", "attachment;filename*=UTF-8''" + encodedFileName);
|
||||
|
||||
// 转换为DTO列表
|
||||
List<DeviceExcelExportDTO> dtoList = devices.stream().map(device -> {
|
||||
DeviceExcelExportDTO dto = new DeviceExcelExportDTO();
|
||||
dto.setId(device.getId());
|
||||
dto.setDeviceType(device.getDeviceType());
|
||||
dto.setCustomerName(device.getCustomerName());
|
||||
dto.setDeviceName(device.getDeviceName());
|
||||
dto.setDeviceMac(device.getDeviceMac());
|
||||
// 设备IMEI
|
||||
dto.setDeviceImei(device.getDeviceImei());
|
||||
dto.setLongitude(device.getLongitude());
|
||||
dto.setLatitude(device.getLatitude());
|
||||
dto.setRemark(device.getRemark());
|
||||
dto.setTypeName(device.getTypeName());
|
||||
dto.setCreateBy(device.getCreateByName());
|
||||
Integer deviceStatus = device.getDeviceStatus();
|
||||
dto.setDeviceStatus(deviceStatus == 1 ? "正常" : "失效");
|
||||
// 时间戳转换
|
||||
dto.setCreateTime(DateUtils.format(device.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
// 处理图片URL转换
|
||||
handleDevicePic(device, dto);
|
||||
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 写入Excel
|
||||
EasyExcel.write(response.getOutputStream(), DeviceExcelExportDTO.class).sheet("设备数据").doWrite(dtoList);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("导出Excel失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void handleDevicePic(Device device, DeviceExcelExportDTO dto) {
|
||||
String picUrl = device.getDevicePic();
|
||||
if (picUrl != null && !picUrl.trim().isEmpty()) {
|
||||
try {
|
||||
// 尝试创建URL对象(会自动验证格式)
|
||||
dto.setDevicePic(new URL(picUrl));
|
||||
} catch (MalformedURLException e) {
|
||||
// 不是有效URL时设置为null
|
||||
dto.setDevicePic(null);
|
||||
}
|
||||
} else {
|
||||
dto.setDevicePic(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,565 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
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.model.LoginUser;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.customer.domain.Customer;
|
||||
import com.fuyuanshen.customer.mapper.CustomerMapper;
|
||||
import com.fuyuanshen.equipment.constants.DeviceConstants;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceAssignments;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.DeviceTypeGrants;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceAssignmentQuery;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.CustomerVo;
|
||||
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
|
||||
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
|
||||
import com.fuyuanshen.equipment.enums.DeviceActiveStatusEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeGrantsMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceAssignmentsService;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import com.fuyuanshen.equipment.service.DeviceTypeGrantsService;
|
||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||
import com.fuyuanshen.system.service.ISysOssService;
|
||||
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.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
|
||||
|
||||
public static final String USER_ID_SEPARATOR = ":";
|
||||
|
||||
@Value("${file.device.pic}")
|
||||
private String filePath;
|
||||
@Value("${file.device.ip}")
|
||||
private String ip;
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
private final CustomerMapper customerMapper;
|
||||
|
||||
private final ISysOssService ossService;
|
||||
|
||||
private final DeviceAssignmentsService deviceAssignmentsService;
|
||||
private final DeviceAssignmentsMapper deviceAssignmentsMapper;
|
||||
|
||||
private final DeviceTypeGrantsService deviceTypeGrantsService;
|
||||
private final DeviceTypeGrantsMapper deviceTypeGrantsMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询设备
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @param page 分页参数
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<Device> queryAll(DeviceQueryCriteria criteria, Page<Device> page) throws IOException {
|
||||
|
||||
criteria.setCurrentOwnerId(LoginHelper.getUserId());
|
||||
IPage<Device> devices = deviceMapper.findAll(criteria, page);
|
||||
|
||||
List<Device> records = devices.getRecords();
|
||||
for (Device record : records) {
|
||||
if (record.getDevicePic() == null) {
|
||||
record.setDevicePic("");
|
||||
}
|
||||
}
|
||||
|
||||
return new TableDataInfo<Device>(records, devices.getTotal());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Device> queryAll(DeviceQueryCriteria criteria) {
|
||||
return deviceMapper.findAll(criteria);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有设备
|
||||
*
|
||||
* @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 addDevice(DeviceForm deviceForm) throws Exception {
|
||||
DeviceTypeQueryCriteria queryCriteria = new DeviceTypeQueryCriteria();
|
||||
queryCriteria.setDeviceTypeId(deviceForm.getDeviceType());
|
||||
queryCriteria.setCustomerId(LoginHelper.getUserId());
|
||||
DeviceTypeGrants typeGrants = deviceTypeGrantsMapper.selectById(queryCriteria.getDeviceTypeId());
|
||||
DeviceType deviceTypes = deviceTypeMapper.selectById(typeGrants.getDeviceTypeId());
|
||||
if (deviceTypes == null) {
|
||||
throw new Exception("设备类型不存在!!!");
|
||||
}
|
||||
|
||||
// 保存图片并获取URL
|
||||
if (deviceForm.getFile() != null) {
|
||||
SysOssVo upload = ossService.upload(deviceForm.getFile());
|
||||
// 设置图片路径
|
||||
deviceForm.setDevicePic(upload.getUrl());
|
||||
}
|
||||
|
||||
// 转换对象并插入数据库
|
||||
Device device = new Device();
|
||||
BeanUtil.copyProperties(deviceForm, device, true);
|
||||
device.setDeviceNo(createDeviceNo());
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
device.setCurrentOwnerId(loginUser.getUserId());
|
||||
device.setOriginalOwnerId(loginUser.getUserId());
|
||||
device.setCreateByName(loginUser.getNickname());
|
||||
device.setTypeName(deviceTypes.getTypeName());
|
||||
device.setDeviceType(deviceTypes.getId());
|
||||
|
||||
deviceMapper.insert(device);
|
||||
|
||||
// 新增设备类型记录
|
||||
DeviceAssignments assignments = new DeviceAssignments();
|
||||
assignments.setDeviceId(device.getId());
|
||||
assignments.setAssignedAt(LocalDateTime.now());
|
||||
// 分配者
|
||||
assignments.setAssignerId(loginUser.getUserId());
|
||||
assignments.setAssignerName(loginUser.getUsername());
|
||||
// 接收者
|
||||
assignments.setAssigneeId(loginUser.getUserId());
|
||||
assignments.setActive(DeviceActiveStatusEnum.ACTIVE.getCode());
|
||||
String lever = USER_ID_SEPARATOR + loginUser.getUserId();
|
||||
assignments.setLever(lever);
|
||||
deviceAssignmentsService.save(assignments);
|
||||
|
||||
}
|
||||
|
||||
private String createDeviceNo() {
|
||||
String uuidStr = UUID.fastUUID().toString(); // 获取带 - 的标准格式字符串
|
||||
return uuidStr.replaceAll("-", "");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新设备信息
|
||||
*
|
||||
* @param deviceForm /
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(DeviceForm deviceForm) throws Exception {
|
||||
DeviceAssignments deviceAssignments = deviceAssignmentsMapper.selectById(deviceForm.getId());
|
||||
|
||||
DeviceTypeQueryCriteria deviceTypeQueryCriteria = new DeviceTypeQueryCriteria();
|
||||
deviceTypeQueryCriteria.setDeviceTypeId(deviceAssignments.getDeviceId());
|
||||
deviceTypeQueryCriteria.setCustomerId(LoginHelper.getUserId());
|
||||
List<DeviceType> deviceTypes = deviceTypeMapper.findAll(deviceTypeQueryCriteria);
|
||||
if (deviceTypes.isEmpty()) {
|
||||
throw new Exception("设备类型不存在!!!");
|
||||
}
|
||||
Device device = deviceMapper.selectById(deviceAssignments.getDeviceId());
|
||||
if (device == null) {
|
||||
throw new Exception("设备不存在!!!");
|
||||
}
|
||||
// 设备类型
|
||||
Long deviceType = device.getDeviceType();
|
||||
|
||||
// 处理上传的图片
|
||||
if (deviceForm.getFile() != null) {
|
||||
SysOssVo upload = ossService.upload(deviceForm.getFile());
|
||||
// 设置图片路径
|
||||
deviceForm.setDevicePic(upload.getUrl());
|
||||
}
|
||||
|
||||
// 更新字段
|
||||
BeanUtil.copyProperties(deviceForm, device, true);
|
||||
device.setId(deviceAssignments.getDeviceId());
|
||||
device.setDeviceType(deviceType);
|
||||
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) {
|
||||
List<Long> invalidIds = new ArrayList<>();
|
||||
|
||||
deviceAssignmentsMapper.deleteByIds(ids);
|
||||
//
|
||||
// for (Long id : ids) {
|
||||
//
|
||||
// Device deviceType = deviceMapper.selectById(id);
|
||||
// if (deviceType == null || !Objects.equals(deviceType.getCurrentOwnerId(), LoginHelper.getUserId())) {
|
||||
// invalidIds.add(id);
|
||||
// }
|
||||
// }
|
||||
// if (!invalidIds.isEmpty()) {
|
||||
// throw new RuntimeException("以下设备无法删除(ID 不存在或无权限): " + invalidIds);
|
||||
// }
|
||||
//
|
||||
// deviceMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分配客户
|
||||
*
|
||||
* @param customerVo
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void assignCustomer(CustomerVo customerVo) {
|
||||
|
||||
if (customerVo.getDeviceIds().isEmpty() || customerVo.getCustomerId() == null) {
|
||||
throw new RuntimeException("请选择设备或客户");
|
||||
}
|
||||
|
||||
// 获取当前登录用户
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
// 获取分配用户信息
|
||||
Customer assignUser = customerMapper.selectById(customerVo.getCustomerId());
|
||||
// 获取分配设备信息
|
||||
List<DeviceAssignments> assignments = deviceAssignmentsMapper.selectByIds(customerVo.getDeviceIds());
|
||||
|
||||
// 批量更新设备状态
|
||||
List<DeviceTypeGrants> deviceTypeGrants = new ArrayList<>();
|
||||
for (DeviceAssignments assignment : assignments) {
|
||||
|
||||
if (assignment.getToCustomerId() != null) {
|
||||
log.info("设备已经分配客户!!!");
|
||||
continue;
|
||||
}
|
||||
|
||||
Device device = deviceMapper.selectById(assignment.getDeviceId());
|
||||
|
||||
// 如果设备已分配给需要分配的客户,则跳过
|
||||
DeviceAssignmentQuery dq = DeviceAssignmentQuery.builder().deviceId(device.getId()).assigneeId(customerVo.getCustomerId())
|
||||
.active(DeviceActiveStatusEnum.ACTIVE.getCode()).lever(assignment.getLever() + USER_ID_SEPARATOR).build();
|
||||
// 查询分配
|
||||
List<DeviceAssignments> assignmentsList = deviceAssignmentsMapper.deviceAssignmentsMapper(dq);
|
||||
if (CollectionUtil.isNotEmpty(assignmentsList)) {
|
||||
log.info("设备 {} 已分配给客户 {}", device.getDeviceName(), device.getCustomerName());
|
||||
continue;
|
||||
}
|
||||
|
||||
// 更改分配客户
|
||||
assignment.setAssigneeName(assignUser.getNickName());
|
||||
assignment.setToCustomerId(customerVo.getCustomerId());
|
||||
deviceAssignmentsMapper.updateById(assignment);
|
||||
|
||||
// 设备失效
|
||||
// 获取用户的设备记录
|
||||
DeviceAssignmentQuery dq1 = DeviceAssignmentQuery.builder().deviceId(device.getId()).assignerId(loginUser.getUserId())
|
||||
.active(DeviceActiveStatusEnum.ACTIVE.getCode()).lever(assignment.getLever() + USER_ID_SEPARATOR).build();
|
||||
List<DeviceAssignments> ag = deviceAssignmentsMapper.deviceAssignmentsMapper(dq1);
|
||||
if (CollectionUtil.isNotEmpty(ag)) {
|
||||
for (DeviceAssignments d : ag) {
|
||||
d.setActive(DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
deviceAssignmentsMapper.updateById(d);
|
||||
}
|
||||
}
|
||||
|
||||
// 新增设备类型记录
|
||||
DeviceAssignments dam = new DeviceAssignments();
|
||||
dam.setDeviceId(device.getId());
|
||||
dam.setAssignedAt(LocalDateTime.now());
|
||||
// 分配者
|
||||
dam.setAssignerId(loginUser.getUserId());
|
||||
dam.setAssignerName(loginUser.getUsername());
|
||||
// 接收者
|
||||
dam.setAssigneeId(assignUser.getCustomerId());
|
||||
// assignments.setAssigneeName(assignUser.getUsername());
|
||||
dam.setActive(DeviceActiveStatusEnum.ACTIVE.getCode());
|
||||
String lever = assignment.getLever() + USER_ID_SEPARATOR + assignUser.getCustomerId();
|
||||
dam.setLever(lever);
|
||||
deviceAssignmentsService.save(dam);
|
||||
|
||||
// 判断设备类型是否存在
|
||||
DeviceTypeGrants dtg = deviceTypeGrantsMapper.selectOne(new LambdaQueryWrapper<DeviceTypeGrants>()
|
||||
.eq(DeviceTypeGrants::getDeviceTypeId, device.getDeviceType())
|
||||
.eq(DeviceTypeGrants::getCustomerId, assignUser.getCustomerId()));
|
||||
if (dtg != null) {
|
||||
continue;
|
||||
}
|
||||
// 创建并保存设备类型授权记录
|
||||
DeviceTypeGrants deviceTypeGrant = new DeviceTypeGrants();
|
||||
deviceTypeGrant.setGrantedAt(new Date());
|
||||
deviceTypeGrant.setDeviceTypeId(device.getDeviceType());
|
||||
// 关联分配记录
|
||||
deviceTypeGrant.setAssignmentId(dam.getId());
|
||||
// 被授权的客户
|
||||
deviceTypeGrant.setCustomerId(customerVo.getCustomerId());
|
||||
// 授权方客户
|
||||
deviceTypeGrant.setGrantorCustomerId(loginUser.getUserId());
|
||||
deviceTypeGrants.add(deviceTypeGrant);
|
||||
}
|
||||
|
||||
deviceTypeGrantsService.saveBatch(deviceTypeGrants);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建并保存设备类型授权记录
|
||||
*
|
||||
* @param device 当前设备对象
|
||||
* @param currentUser 当前登录用户
|
||||
* @param customerVo 客户信息
|
||||
* @param deviceTypeGrants 授权记录集合
|
||||
*/
|
||||
private void createAndSaveDeviceTypeGrants(Device device, LoginUser 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.getUserId());
|
||||
deviceTypeGrants.add(deviceTypeGrant);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 撤回设备
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
// @Override
|
||||
// public void withdrawDevice(List<Long> ids) {
|
||||
// ids.forEach((id) -> {
|
||||
// List<Device> deviceChain = getDeviceChain(id);
|
||||
// deviceChain.forEach((device) -> {
|
||||
// device.setDeviceStatus(DeviceStatusEnum.INVALID.getCode());
|
||||
// deviceMapper.updateById(device);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// ids.forEach((id) -> {
|
||||
// Device device = new Device();
|
||||
// device.setId(id);
|
||||
// device.setCustomerId(null);
|
||||
// device.setCustomerName("");
|
||||
// deviceMapper.updateById(device);
|
||||
// });
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public List<Device> getDeviceChain(Long originalDeviceId) {
|
||||
// List<Device> chain = new ArrayList<>();
|
||||
// Set<Long> visited = new HashSet<>(); // 防止循环引用
|
||||
// findNext(chain, visited, originalDeviceId);
|
||||
// return chain;
|
||||
// }
|
||||
//
|
||||
// private void findNext(List<Device> chain, Set<Long> visited, Long currentOriginalDeviceId) {
|
||||
// if (visited.contains(currentOriginalDeviceId)) {
|
||||
// log.info("检测到循环引用,终止递归");
|
||||
// return;
|
||||
// }
|
||||
// visited.add(currentOriginalDeviceId);
|
||||
//
|
||||
// List<Device> devices = deviceMapper.findByOriginalDeviceId(currentOriginalDeviceId);
|
||||
// for (Device device : devices) {
|
||||
// chain.add(device);
|
||||
// findNext(chain, visited, device.getId());
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 撤回设备
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void withdrawDevice(List<Long> ids) {
|
||||
|
||||
for (Long id : ids) {
|
||||
DeviceAssignments assignment = deviceAssignmentsMapper.selectById(id);
|
||||
Device device = deviceMapper.selectById(assignment.getDeviceId());
|
||||
// 接收者
|
||||
assignment.setAssigneeName("");
|
||||
assignment.setToCustomerId(null);
|
||||
deviceAssignmentsMapper.updateById(assignment);
|
||||
|
||||
// 获取所有已分配的设备
|
||||
DeviceAssignmentQuery dq = DeviceAssignmentQuery.builder().deviceId(device.getId())
|
||||
.active(DeviceActiveStatusEnum.ACTIVE.getCode()).lever(assignment.getLever() + USER_ID_SEPARATOR).build();
|
||||
// 查询分配
|
||||
List<DeviceAssignments> assignmentsList = deviceAssignmentsMapper.deviceAssignmentsMapper(dq);
|
||||
for (DeviceAssignments assignments : assignmentsList) {
|
||||
assignments.setActive(DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||
deviceAssignmentsMapper.updateById(assignments);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解绑设备
|
||||
*
|
||||
* @param deviceForm
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void unbindDevice(DeviceForm deviceForm) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TableDataInfo<AppDeviceVo> queryAppDeviceList(DeviceQueryCriteria bo, PageQuery pageQuery) {
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
bo.setBindingUserId(userId);
|
||||
Page<AppDeviceVo> result = baseMapper.queryAppDeviceList(pageQuery.build(), bo);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bindDevice(AppDeviceBo bo) {
|
||||
Integer mode = bo.getCommunicationMode();
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
if (mode == CommunicationModeEnum.FOUR_G.getValue()) {
|
||||
|
||||
String deviceImei = bo.getDeviceImei();
|
||||
QueryWrapper<Device> qw = new QueryWrapper<Device>()
|
||||
.eq("device_imei", deviceImei);
|
||||
List<Device> devices = baseMapper.selectList(qw);
|
||||
if (devices.isEmpty()) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
Device device = devices.get(0);
|
||||
if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) {
|
||||
throw new RuntimeException("设备已绑定");
|
||||
}
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", device.getId())
|
||||
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
||||
.set("binding_user_id", userId);
|
||||
;
|
||||
|
||||
return baseMapper.update(null, deviceUpdateWrapper);
|
||||
} else if (mode == CommunicationModeEnum.BLUETOOTH.getValue()) {
|
||||
String deviceMac = bo.getDeviceMac();
|
||||
QueryWrapper<Device> qw = new QueryWrapper<Device>()
|
||||
.eq("device_mac", deviceMac);
|
||||
List<Device> devices = baseMapper.selectList(qw);
|
||||
if (devices.isEmpty()) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
Device device = devices.get(0);
|
||||
if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) {
|
||||
throw new RuntimeException("设备已绑定");
|
||||
}
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", device.getId())
|
||||
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
||||
.set("binding_user_id", userId);
|
||||
return baseMapper.update(null, qw);
|
||||
} else {
|
||||
throw new RuntimeException("通讯方式错误");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int unBindDevice(Long id) {
|
||||
Device device = baseMapper.selectById(id);
|
||||
if (device == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
// DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||
// String mode = deviceType.getCommunicationMode();
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", device.getId())
|
||||
.set("binding_status", BindingStatusEnum.UNBOUND.getCode());
|
||||
return baseMapper.update(null, deviceUpdateWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fuyuanshen.equipment.domain.DeviceTypeGrants;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeGrantsMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceTypeGrantsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author 97433
|
||||
* @description 针对表【device_type_grants】的数据库操作Service实现
|
||||
* @createDate 2025-06-19 13:49:33
|
||||
*/
|
||||
@Service
|
||||
public class DeviceTypeGrantsServiceImpl extends ServiceImpl<DeviceTypeGrantsMapper, DeviceTypeGrants>
|
||||
implements DeviceTypeGrantsService {
|
||||
|
||||
}
|
||||
@ -0,0 +1,196 @@
|
||||
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;
|
||||
import com.fuyuanshen.common.core.domain.PageResult;
|
||||
import com.fuyuanshen.common.core.domain.model.LoginUser;
|
||||
import com.fuyuanshen.common.core.utils.PageUtil;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.DeviceTypeGrants;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceTypeForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeGrantsMapper;
|
||||
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.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
private final DeviceTypeGrantsMapper deviceTypeGrantsMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询设备类型
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @param page 分页参数
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<DeviceType> queryAll(DeviceTypeQueryCriteria criteria, Page<DeviceType> page) {
|
||||
criteria.setCustomerId(LoginHelper.getUserId());
|
||||
// return
|
||||
IPage<DeviceType> deviceTypeIPage = deviceTypeMapper.findAll(criteria, page);
|
||||
return new TableDataInfo<DeviceType>(deviceTypeIPage.getRecords(), deviceTypeIPage.getTotal());
|
||||
}
|
||||
|
||||
|
||||
@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) {
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
resources.setCustomerId(loginUser.getUserId());
|
||||
resources.setOwnerCustomerId(loginUser.getUserId());
|
||||
resources.setOriginalOwnerId(loginUser.getUserId());
|
||||
resources.setCreateByName(loginUser.getNickname());
|
||||
deviceTypeMapper.insert(resources);
|
||||
|
||||
// 自动授权给自己
|
||||
DeviceTypeGrants deviceTypeGrants = new DeviceTypeGrants();
|
||||
deviceTypeGrants.setDeviceTypeId(resources.getId());
|
||||
deviceTypeGrants.setCustomerId(loginUser.getUserId());
|
||||
deviceTypeGrants.setGrantorCustomerId(loginUser.getUserId());
|
||||
deviceTypeGrants.setGrantedAt(new Date());
|
||||
deviceTypeGrantsMapper.insert(deviceTypeGrants);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改设备类型
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(DeviceTypeForm resources) {
|
||||
DeviceTypeGrants deviceTypeGrants = deviceTypeGrantsMapper.selectById(resources.getId());
|
||||
if (deviceTypeGrants == null) {
|
||||
throw new RuntimeException("设备类型不存在");
|
||||
}
|
||||
resources.setId(deviceTypeGrants.getDeviceTypeId());
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(resources.getId());
|
||||
if (deviceType == null) {
|
||||
throw new RuntimeException("设备类型不存在");
|
||||
}
|
||||
if (!Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
|
||||
throw new RuntimeException("无权修改该设备类型");
|
||||
}
|
||||
// if (deviceMapper.countByTypeId(resources.getId()) > 0)
|
||||
// throw new RuntimeException("该设备类型已被使用,无法删除");
|
||||
BeanUtil.copyProperties(resources, deviceType);
|
||||
deviceTypeMapper.updateById(deviceType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除设备类型
|
||||
*
|
||||
* @param ids /
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAll(List<Long> ids) {
|
||||
|
||||
deviceTypeGrantsMapper.deleteByIds(ids);
|
||||
//
|
||||
// List<Long> invalidIds = new ArrayList<>();
|
||||
// List<Long> invalidId2 = new ArrayList<>();
|
||||
// for (Long id : ids) {
|
||||
// DeviceType deviceType = deviceTypeMapper.selectById(id);
|
||||
// if (deviceType == null || !Objects.equals(deviceType.getOwnerCustomerId(), LoginHelper.getUserId())) {
|
||||
// invalidIds.add(id);
|
||||
// }
|
||||
// DeviceQueryCriteria deviceQueryCriteria = new DeviceQueryCriteria();
|
||||
// deviceQueryCriteria.setDeviceType(id);
|
||||
// List<Device> devices = deviceMapper.findAll(deviceQueryCriteria);
|
||||
// if (!devices.isEmpty()) {
|
||||
// invalidId2.add(id);
|
||||
// }
|
||||
// }
|
||||
// if (!invalidIds.isEmpty()) {
|
||||
// throw new RuntimeException("以下设备类型无法删除(ID 不存在或无权限): " + invalidIds);
|
||||
// }
|
||||
// if (!invalidId2.isEmpty()) {
|
||||
// throw new RuntimeException("以下设备类型无法删除(已绑定设备): " + invalidId2);
|
||||
// }
|
||||
//
|
||||
// deviceTypeMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备类型通讯方式
|
||||
*
|
||||
* @param id /
|
||||
* @return DeviceTypeDto
|
||||
*/
|
||||
@Override
|
||||
public DeviceType getCommunicationMode(Long id) {
|
||||
|
||||
DeviceTypeGrants deviceTypeGrants = deviceTypeGrantsMapper.selectById(id);
|
||||
if (deviceTypeGrants == null) {
|
||||
throw new RuntimeException("设备类型不存在");
|
||||
}
|
||||
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(deviceTypeGrants.getDeviceTypeId());
|
||||
if (deviceType == null) {
|
||||
throw new RuntimeException("设备类型不存在");
|
||||
}
|
||||
//
|
||||
// if (!Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
|
||||
// throw new RuntimeException("无权获取该设备类型通讯方式");
|
||||
// }
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
import com.fuyuanshen.equipment.domain.UserApp;
|
||||
import com.fuyuanshen.equipment.domain.bo.UserAppBo;
|
||||
import com.fuyuanshen.equipment.mapper.UserAppMapper;
|
||||
import com.fuyuanshen.equipment.service.AppUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Service业务层处理
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-06-27
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class UserAppServiceImpl implements AppUserService {
|
||||
|
||||
private final UserAppMapper baseMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 修改APP用户信息
|
||||
*
|
||||
* @param bo APP用户信息
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(UserAppBo bo) {
|
||||
UserApp update = MapstructUtils.convert(bo, UserApp.class);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.fuyuanshen.equipment.mapper.UserAppMapper">
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,45 @@
|
||||
<?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.DeviceAssignmentsMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.fuyuanshen.equipment.domain.DeviceAssignments">
|
||||
<id property="id" column="id"/>
|
||||
<result property="deviceId" column="device_id"/>
|
||||
<result property="fromCustomerId" column="from_customer_id"/>
|
||||
<result property="toCustomerId" column="to_customer_id"/>
|
||||
<result property="assignedAt" column="assigned_at"/>
|
||||
<result property="deviceTypeGranted" column="device_type_granted"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
,device_id,from_customer_id,to_customer_id,assigned_at,device_type_granted
|
||||
</sql>
|
||||
|
||||
|
||||
<!-- 查询设备分配信息 -->
|
||||
<select id="deviceAssignmentsMapper" resultType="com.fuyuanshen.equipment.domain.DeviceAssignments"
|
||||
parameterType="com.fuyuanshen.equipment.domain.query.DeviceAssignmentQuery">
|
||||
SELECT *
|
||||
FROM device_assignments
|
||||
<where>
|
||||
<if test="query.deviceId != null">
|
||||
AND device_id = #{query.deviceId}
|
||||
</if>
|
||||
<if test="query.assigneeId != null">
|
||||
AND assignee_id = #{query.assigneeId}
|
||||
</if>
|
||||
<if test="query.active != null">
|
||||
AND active = #{query.active}
|
||||
</if>
|
||||
<if test="query.assignerId != null">
|
||||
AND assigner_id = #{query.assignerId}
|
||||
</if>
|
||||
<if test="query.lever != null">
|
||||
AND lever LIKE CONCAT('%', #{query.lever}, '%')
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
@ -0,0 +1,201 @@
|
||||
<?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.DeviceMapper">
|
||||
<resultMap id="BaseResultMap" type="com.fuyuanshen.equipment.domain.Device">
|
||||
<id column="id" property="id"/>
|
||||
<result column="device_type" property="deviceType"/>
|
||||
<result column="customer_id" property="customerId"/>
|
||||
<result column="device_no" property="deviceNo"/>
|
||||
<result column="device_name" property="deviceName"/>
|
||||
<result column="device_pic" property="devicePic"/>
|
||||
<result column="device_mac" property="deviceMac"/>
|
||||
<result column="device_sn" property="deviceSn"/>
|
||||
<result column="device_status" property="deviceStatus"/>
|
||||
<result column="remark" property="remark"/>
|
||||
<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="binding_status" property="bindingStatus"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
, device_type, customer_id, device_name, device_pic, device_mac, device_sn,
|
||||
remark, create_by, update_by, create_time, update_time
|
||||
</sql>
|
||||
|
||||
<sql id="device_Column_List">
|
||||
d
|
||||
.
|
||||
id
|
||||
,d.device_type,
|
||||
d.customer_id, d.device_name, d.device_pic, d.device_mac,
|
||||
d.device_sn, d.remark, d.create_by, d.update_by, d.create_time, d.update_time,
|
||||
d.binding_status, d.device_status, d.current_owner_id, d.original_owner_id, d.customer_name,
|
||||
d.device_imei, d.longitude, d.latitude, d.tenant_id
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询设备 -->
|
||||
<select id="findAll1" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||
select d.* , t.type_name
|
||||
FROM device d
|
||||
LEFT JOIN device_type t ON d.device_type = t.id
|
||||
<where>
|
||||
<!-- 时间范围等其他条件保持原样 -->
|
||||
<if test="criteria.deviceName != null and criteria.deviceName.trim() != ''">
|
||||
and d.device_name like concat('%', TRIM(#{criteria.deviceName}), '%')
|
||||
</if>
|
||||
<if test="criteria.deviceMac != null">
|
||||
and d.device_mac = #{criteria.deviceMac}
|
||||
</if>
|
||||
<if test="criteria.deviceImei != null">
|
||||
and d.device_imei = #{criteria.deviceImei}
|
||||
</if>
|
||||
<if test="criteria.deviceType != null">
|
||||
and d.device_type = #{criteria.deviceType}
|
||||
</if>
|
||||
<if test="criteria.deviceStatus != null">
|
||||
and d.device_status = #{criteria.deviceStatus}
|
||||
</if>
|
||||
<if test="criteria.currentOwnerId != null">
|
||||
and d.current_owner_id = #{criteria.currentOwnerId}
|
||||
</if>
|
||||
<if test="criteria.params.beginTime != null and criteria.params.endTime != null">
|
||||
and d.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}
|
||||
</if>
|
||||
<if test="criteria.tenantId != null">
|
||||
AND tenant_id = #{criteria.tenantId}
|
||||
</if>
|
||||
</where>
|
||||
order by d.create_time desc
|
||||
</select>
|
||||
|
||||
|
||||
<!-- 分页查询设备 -->
|
||||
<select id="findAll" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||
select
|
||||
da.id AS id,d.device_name,
|
||||
d.device_pic, d.device_mac, d.device_sn, d.update_by,d.device_imei,
|
||||
d.update_time, dg.id AS device_type, d.remark, d.binding_status,d.type_name AS typeName,
|
||||
da.assignee_id AS customerId, da.assignee_name AS customerName, da.active AS deviceStatus,
|
||||
da.create_time AS create_time , da.assigner_name AS createByName , da.id AS assignId
|
||||
from device d
|
||||
LEFT JOIN device_type t ON d.device_type = t.id
|
||||
LEFT JOIN device_type_grants dg ON dg.device_type_id = t.id
|
||||
LEFT JOIN device_assignments da ON da.device_id = d.id
|
||||
<where>
|
||||
<!-- 时间范围等其他条件保持原样 -->
|
||||
<if test="criteria.deviceName != null and criteria.deviceName.trim() != ''">
|
||||
and d.device_name like concat('%', TRIM(#{criteria.deviceName}), '%')
|
||||
</if>
|
||||
<if test="criteria.deviceMac != null">
|
||||
and d.device_mac = #{criteria.deviceMac}
|
||||
</if>
|
||||
<if test="criteria.deviceImei != null">
|
||||
and d.device_imei = #{criteria.deviceImei}
|
||||
</if>
|
||||
<if test="criteria.deviceType != null">
|
||||
and d.device_type = #{criteria.deviceType}
|
||||
</if>
|
||||
<if test="criteria.deviceStatus != null">
|
||||
and da.active = #{criteria.deviceStatus}
|
||||
</if>
|
||||
<if test="criteria.params.beginTime != null and criteria.params.endTime != null">
|
||||
and da.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}
|
||||
</if>
|
||||
AND da.assignee_id = #{criteria.currentOwnerId}
|
||||
AND dg.customer_id = #{criteria.currentOwnerId}
|
||||
</where>
|
||||
ORDER BY da.create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="findAllDevices" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||
select
|
||||
d.id, d.customer_id, d.device_name,
|
||||
d.device_pic, d.device_mac, d.device_sn, d.create_by, d.update_by,
|
||||
d.create_time, d.update_time, d.longitude, d.latitude, d.remark
|
||||
from device d
|
||||
<where>
|
||||
<if test="criteria.deviceName != null and criteria.deviceName.trim() != ''">
|
||||
and d.device_name like concat('%', TRIM(#{criteria.deviceName}), '%')
|
||||
</if>
|
||||
<if test="criteria.deviceMac != null">
|
||||
and d.device_mac = #{criteria.deviceMac}
|
||||
</if>
|
||||
<if test="criteria.deviceTypeId != null">
|
||||
and d.device_type = #{criteria.deviceTypeId}
|
||||
</if>
|
||||
<if test="criteria.createTime != null and criteria.createTime.size() != 0">
|
||||
and d.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
|
||||
</if>
|
||||
</where>
|
||||
order by d.id desc
|
||||
</select>
|
||||
|
||||
<!-- 根据条件查询 -->
|
||||
<select id="findDevices" resultType="com.fuyuanshen.equipment.domain.Device"
|
||||
parameterType="com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria">
|
||||
SELECT d.*
|
||||
FROM device d
|
||||
<where>
|
||||
<!-- 时间范围等其他条件保持原样 -->
|
||||
<if test="criteria.deviceName != null and criteria.deviceName.trim() != ''">
|
||||
and d.device_name like concat('%', TRIM(#{criteria.deviceName}), '%')
|
||||
</if>
|
||||
<if test="criteria.deviceMac != null">
|
||||
and d.device_mac = #{criteria.deviceMac}
|
||||
</if>
|
||||
<if test="criteria.deviceImei != null">
|
||||
and d.device_imei = #{criteria.deviceImei}
|
||||
</if>
|
||||
<if test="criteria.deviceType != null">
|
||||
and d.device_type = #{criteria.deviceType}
|
||||
</if>
|
||||
<if test="criteria.deviceStatus != null">
|
||||
and d.device_status = #{criteria.deviceStatus}
|
||||
</if>
|
||||
<if test="criteria.currentOwnerId != null">
|
||||
and d.current_owner_id = #{criteria.currentOwnerId}
|
||||
</if>
|
||||
<if test="criteria.params.beginTime != null and criteria.params.endTime != null">
|
||||
and d.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="queryAppDeviceList" resultType="com.fuyuanshen.equipment.domain.vo.AppDeviceVo">
|
||||
select d.id,
|
||||
d.device_name,
|
||||
d.device_mac,
|
||||
d.device_sn,
|
||||
d.device_imei,
|
||||
d.device_mac,
|
||||
dt.communication_mode,
|
||||
d.bluetooth_name
|
||||
from device d
|
||||
inner join device_type dt on d.device_type = dt.id
|
||||
where d.binding_user_id = #{criteria.bindingUserId}
|
||||
<if test="criteria.deviceType != null">
|
||||
and d.device_type = #{criteria.deviceType}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 获取分配设备的客户 -->
|
||||
<select id="getAssignCustomer" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||
SELECT *
|
||||
FROM device
|
||||
WHERE original_device_id = #{customerId}
|
||||
AND device_status = 1
|
||||
</select>
|
||||
|
||||
<!-- 获取设备链 -->
|
||||
<select id="findByOriginalDeviceId" resultType="com.fuyuanshen.equipment.domain.Device"
|
||||
parameterType="java.lang.Long">
|
||||
SELECT id, original_device_id
|
||||
FROM device
|
||||
WHERE original_device_id = #{originalDeviceId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,19 @@
|
||||
<?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.DeviceTypeGrantsMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.fuyuanshen.equipment.domain.DeviceTypeGrants">
|
||||
<id property="id" column="id" />
|
||||
<result property="deviceTypeId" column="device_type_id" />
|
||||
<result property="customerId" column="customer_id" />
|
||||
<result property="grantorCustomerId" column="grantor_customer_id" />
|
||||
<result property="grantedAt" column="granted_at" />
|
||||
<result property="assignmentId" column="assignment_id" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,device_type_id,customer_id,grantor_customer_id,granted_at,assignment_id
|
||||
</sql>
|
||||
</mapper>
|
||||
@ -0,0 +1,45 @@
|
||||
<?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="grant_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.* ,dg.id AS grant_id ,dg.create_time AS Dcreate_time
|
||||
FROM device_type dt
|
||||
JOIN device_type_grants dg ON dt.id = dg.device_type_id
|
||||
<where>
|
||||
<if test="criteria.typeName != null and criteria.typeName.trim() != ''">
|
||||
and dt.type_name like concat('%', TRIM(#{criteria.typeName}), '%')
|
||||
</if>
|
||||
<if test="criteria.customerId != null">
|
||||
and dg.customer_id = #{criteria.customerId}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY Dcreate_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 获取已经分配的设备类型 -->
|
||||
<select id="getAssignType" resultType="com.fuyuanshen.equipment.domain.DeviceType">
|
||||
SELECT *
|
||||
FROM device_type
|
||||
WHERE owner_customer_id = #{customerId}
|
||||
AND original_device_id = #{deviceType}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user