This commit is contained in:
2026-08-03 14:46:36 +08:00
parent 6be6d5d333
commit 42eae10df6
31 changed files with 170 additions and 440 deletions

2
.gitignore vendored
View File

@@ -8,6 +8,7 @@ target/
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/workspace.xml
.idea/libraries/
*.iws
*.iml
@@ -41,4 +42,5 @@ build/
/logs
.idea/*
*.log

View File

@@ -3,37 +3,20 @@ package com.maibu.web.controller.system;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maibu.annotation.Log;
import com.maibu.core.business.Device;
import com.maibu.core.business.DeviceModel;import com.maibu.core.business.DeviceRunStatistics;
import com.maibu.core.business.DeviceModel;
import com.maibu.core.controller.BaseController;
import com.maibu.core.domain.AjaxResult;
import com.maibu.core.enums.ConnectType;
import com.maibu.core.page.TableDataInfo;
import com.maibu.enums.BusinessType;
import com.maibu.mapper.DeviceRunStatisticsMapper;
import com.maibu.mybatis.LambdaQueryWrapperX;
import com.maibu.service.IDeviceService;
import com.maibu.service.SysDeviceModelService;
import com.maibu.service.impl.SysDeviceModelService;
import com.maibu.utils.ServletUtils;
import com.maibu.utils.StringUtils;
import com.maibu.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

View File

@@ -1,25 +1,19 @@
package com.maibu.web.controller.system;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maibu.core.business.IoTCommonDevice;
import com.maibu.core.business.Product;
import com.maibu.core.business.dto.DeviceConfigDTO;
import com.maibu.core.business.dto.ProductDTO;
import com.maibu.core.controller.BaseController;
import com.maibu.core.domain.AjaxResult;
import com.maibu.core.page.TableDataInfo;
import com.maibu.memory.GlobalMemory;
import com.maibu.service.DeviceProductService;
import com.maibu.service.IotDeviceCommonService;
import com.maibu.service.impl.IotDeviceCommonService;
import com.maibu.utils.ServletUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@@ -84,10 +78,11 @@ public class SysIotCommDeviceController extends BaseController {
/**
* 删除设备
*/
@DeleteMapping("/{id}")
@PostMapping("/delete")
@ApiOperation("删除设备")
public AjaxResult remove(@PathVariable Long id) {
return toAjax(deviceService.removeById(id) ? 1 : 0);
public AjaxResult remove(@RequestBody List<Long> ids) {
deviceService.removeByIds(ids);
return AjaxResult.success();
}
@@ -119,4 +114,5 @@ public class SysIotCommDeviceController extends BaseController {
return AjaxResult.success("缓存更新成功");
}
}

View File

@@ -1,25 +1,16 @@
package com.maibu.web.controller.system;
import cn.hutool.core.convert.Convert;
import com.maibu.core.business.DeviceModel;
import com.maibu.core.business.Product;
import com.maibu.core.business.dto.ProductDTO;
import com.maibu.core.controller.BaseController;
import com.maibu.core.domain.AjaxResult;
import com.maibu.core.page.TableDataInfo;
import com.maibu.service.DeviceProductService;
import com.maibu.service.SysDeviceModelService;
import com.maibu.utils.ServletUtils;
import com.maibu.service.impl.DeviceProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.List;
/**
@@ -39,92 +30,30 @@ public class SysProductController extends BaseController {
@GetMapping("/list")
@ApiOperation("查询产品列表")
public TableDataInfo list(ProductDTO productDTO) {
Integer pageNum = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
Page<Product> page = new Page<>(pageNum, pageSize);
// DTO 转 Entity 用于查询筛选
Product product = new Product();
BeanUtils.copyProperties(productDTO, product);
Page<Product> resultPage = productService.selectProductPage(page, product);
return getDataTable(resultPage.getRecords(), resultPage.getTotal());
List<Product> resultPage = productService.selectProductPage(productDTO);
return getDataTable(resultPage);
}
/**
* 新增产品
* 新增产品/修改
*/
//@PreAuthorize("@ss.hasPermi('iot:product:add')")
@PostMapping("/add")
@PostMapping("/save")
@ApiOperation("新增产品")
public AjaxResult add(@RequestBody ProductDTO productDTO) {
if (productDTO.getName() == null || productDTO.getName().isEmpty()) {
return AjaxResult.error("产品名称不能为空");
}
if (productDTO.getCode() == null || productDTO.getCode().isEmpty()) {
return AjaxResult.error("产品编码不能为空");
public AjaxResult add(@RequestBody Product product) {
return AjaxResult.success(productService.save(product));
}
// 检查编码是否重复
Product existProduct = productService.selectByCode(productDTO.getCode());
if (existProduct != null) {
return AjaxResult.error("产品编码已存在");
}
// DTO 转 Entity
Product product = new Product();
BeanUtils.copyProperties(productDTO, product);
product.setCreateTime(LocalDateTime.now());
product.setDelFlag(false);
boolean success = productService.save(product);
return toAjax(success ? 1 : 0);
}
/**
* 修改产品
*/
@PostMapping("/update")
@ApiOperation("修改产品")
public AjaxResult edit(@RequestBody ProductDTO productDTO) {
if (productDTO.getId() == null) {
return AjaxResult.error("产品 ID 不能为空");
}
Product existProduct = productService.getById(productDTO.getId());
if (existProduct == null) {
return AjaxResult.error("产品不存在");
}
// 如果修改了编码,检查是否重复
if (productDTO.getCode() != null && !productDTO.getCode().equals(existProduct.getCode())) {
Product duplicate = productService.selectByCode(productDTO.getCode());
if (duplicate != null) {
return AjaxResult.error("产品编码已存在");
}
}
// DTO 转 Entity
Product product = new Product();
BeanUtils.copyProperties(productDTO, product);
product.setUpdateTime(LocalDateTime.now());
boolean success = productService.updateById(product);
return toAjax(success ? 1 : 0);
}
/**
* 删除产品
*/
//@PreAuthorize("@ss.hasPermi('iot:product:remove')")
@DeleteMapping("delete/{id}")
@PostMapping("delete")
@ApiOperation("删除产品")
public AjaxResult remove(@PathVariable Long id) {
boolean success = productService.removeById(id);
return toAjax(success ? 1 : 0);
public AjaxResult remove(@RequestBody List<Long> ids) {
return AjaxResult.success(productService.removeByIds(ids));
}
}

View File

@@ -102,6 +102,11 @@ public class DeviceTask {
return builder(FastBeeConstant.TASK.DEVICE_TASK_HANDLER);
}
@Bean(FastBeeConstant.TASK.COMMON_DEVICE_MONITOR)
public Executor commonDeviceMonitor() {
return builder(FastBeeConstant.TASK.COMMON_DEVICE_MONITOR);
}
/*组装线程池*/
private ThreadPoolTaskExecutor builder(String threadNamePrefix) {

View File

@@ -105,6 +105,11 @@ public interface FastBeeConstant {
*/
String DEVICE_TASK_HANDLER = "deviceTaskHandler";
/**
* 其他设备接入 数据状态
*/
String COMMON_DEVICE_MONITOR = "commonDeviceMonitor";
}
interface MQTT {

View File

@@ -3,21 +3,15 @@ package com.maibu.core.business.dto;
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.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.maibu.core.business.ProductInterface;
import com.maibu.core.domain.BaseDO;
import com.maibu.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
import java.util.Map;
@Data
public class ProductDTO extends BaseDO {
public class ProductDTO extends BaseEntity {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.AUTO)
@@ -45,7 +39,4 @@ public class ProductDTO extends BaseDO {
private Map<String, Object> thingsModels;
}

View File

@@ -56,12 +56,36 @@ public class SiteMemory {
deviceMap.put(device.getSerialNumber(), device);
}
public static void removeDevice(String deviceId) {
public void removeDevice(String deviceId) {
if (!StringUtils.isEmpty(deviceId)) {
deviceMap.remove(deviceId);
}
}
public void saveCommonDevice(IoTCommonDevice device) {
commonDeviceMap.put(device.getSn(), device);
}
public IoTCommonDevice getCommonDevice(String sn) {
if (!StringUtils.isEmpty(sn)) {
return commonDeviceMap.get(sn);
}
return null;
}
public List<IoTCommonDevice> getAllCommonDevice() {
if (!CollectionUtils.isEmpty(commonDeviceMap)) {
return (List<IoTCommonDevice>) commonDeviceMap.values();
}
return null;
}
public void removeCommonDevice(String sn) {
if (!StringUtils.isEmpty(sn)) {
commonDeviceMap.remove(sn);
}
}
public void saveDeviceRunParam(DeviceRunParam deviceRunParam) {
deviceRunParamMap.put(deviceRunParam.getDeviceId(), deviceRunParam);
}

View File

@@ -7,6 +7,7 @@ import java.util.concurrent.Executor;
import javax.annotation.Resource;
import com.maibu.service.impl.IotDeviceCommonService;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
@@ -49,6 +50,9 @@ public class InitThread implements ApplicationRunner {
@Resource(name = FastBeeConstant.TASK.DEVICE_ERROR_MONITOR)
private Executor deviceErrorMonitorExecutor;
@Resource(name = FastBeeConstant.TASK.COMMON_DEVICE_MONITOR)
private Executor commonDeviceMonitorExecutor;
@Resource(name = FastBeeConstant.TASK.DEVICE_TASK_HANDLER)
private Executor deviceTaskHandlerExecutor;
@@ -76,6 +80,9 @@ public class InitThread implements ApplicationRunner {
@Autowired
private AlarmOrderConfigMapper alarmOrderConfigMapper;
@Autowired
private IotDeviceCommonService commonService;
@Value("${influxdb.url}")
private String influxDBUrl;
@@ -138,6 +145,9 @@ public class InitThread implements ApplicationRunner {
throw new RuntimeException(e);
}
});
commonDeviceMonitorExecutor.execute(() -> {
commonService.commonDeviceMonitor();
});
}
/**

View File

@@ -1,18 +1,13 @@
package com.maibu.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.maibu.core.business.Product;
import com.maibu.mybatis.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;
/**
* @author jsmbz
* @description 针对表【device_product(产品表)】的数据库操作Mapper
* @createDate 2026-05-08 13:45:57
* @Entity abbc.domain.DeviceProduct
*/
@Mapper
public interface DeviceProductMapper extends BaseMapper<Product> {
public interface DeviceProductMapper extends BaseMapperX<Product> {
}

View File

@@ -1,15 +1,10 @@
package com.maibu.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.maibu.core.business.IoTCommonDevice;
import com.maibu.mybatis.mapper.BaseMapperX;
/**
* @author jsmbz
* @description 针对表【iot_device_common(通用设备表)】的数据库操作Mapper
* @createDate 2026-05-09 14:38:50
* @Entity abbc.domain.IotDeviceCommon
*/
public interface IotDeviceCommonMapper extends BaseMapper<IoTCommonDevice> {
public interface IotDeviceCommonMapper extends BaseMapperX<IoTCommonDevice> {
}

View File

@@ -1,13 +0,0 @@
package com.maibu.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.maibu.core.business.ProductInterface;
/**
* @author jsmbz
* @description 针对表【device_product_interface(产品接口表)】的数据库操作Service
* @createDate 2026-05-08 15:37:53
*/
public interface DeviceProductInterfaceService extends IService<ProductInterface> {
}

View File

@@ -1,37 +0,0 @@
package com.maibu.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.maibu.core.business.Product;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/**
* @author jsmbz
* @description 针对表【device_product(产品表)】的数据库操作Service
* @createDate 2026-05-08 13:45:57
*/
public interface DeviceProductService extends IService<Product> {
/**
* 分页查询产品列表
*/
Page<Product> selectProductPage(Page<Product> page, Product product);
/**
* 根据编码查询产品
*/
Product selectByCode(String code);
/**
* 新增产品(含接口表入库)
*/
boolean insertProduct(Product product);
/**
* 修改产品(含接口表入库)
*/
boolean updateProduct(Product product);
}

View File

@@ -1,63 +0,0 @@
package com.maibu.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.maibu.core.business.IoTCommonDevice;
import com.maibu.core.business.dto.DeviceConfigDTO;
import java.util.List;
/**
* @author jsmbz
* @description 针对表【iot_device_common(通用设备表)】的数据库操作Service
* @createDate 2026-05-09 14:38:50
*/
public interface IotDeviceCommonService extends IService<IoTCommonDevice> {
/**
* 设备录入:连接测试成功后放入未注册缓存
*/
void addDeviceToUnRegisterCache(DeviceConfigDTO deviceDTO) throws Exception;
/**
* 查询未注册设备列表
*/
List<IoTCommonDevice> getUnRegisterDevices();
/**
* 分页查询已注册设备列表
*/
Page<IoTCommonDevice> selectDevicePage(Page<IoTCommonDevice> page, IoTCommonDevice device);
/**
* 根据 SN 查询设备
*/
IoTCommonDevice getBySn(String sn);
/**
* 从未注册缓存注册到组织/场站,并落库
*/
void registerDevice(Long deviceId, Long orgId, Long siteId);
/**
* 编辑设备
* @param deviceDTO
* @return
*/
boolean updateDevice(DeviceConfigDTO deviceDTO);
/**
*
* @param sn
* @return
*/
IoTCommonDevice getFromUnRegisterCache(String sn);
/**
*
* @param cacheDevice
*/
void updateUnRegisterCache(IoTCommonDevice cacheDevice);
}

View File

@@ -1,13 +0,0 @@
package com.maibu.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.maibu.core.business.DeviceAction;
/**
* @author jsmbz
* @description 针对表【iot_device_action(设备动作定义表)】的数据库操作Service
* @createDate 2026-05-07 12:33:48
*/
public interface SysDeviceActionService extends IService<DeviceAction> {
}

View File

@@ -1,52 +0,0 @@
package com.maibu.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maibu.core.business.DeviceModel;
/**
* @author jsmbz
* @description 针对表【iot_device_model(设备模型表)】的数据库操作Service
* @createDate 2026-05-07 11:36:11
*/
public interface SysDeviceModelService {
/**
* 新增设备模型
*
* @param deviceModel
* @return
*/
int insertDeviceModel(DeviceModel deviceModel);
/**
* 分页查询设备模型列表
*
* @param page 分页对象
* @param deviceModel 查询条件
* @return 分页结果
*/
Page<DeviceModel> selectDeviceModelPage(Page<DeviceModel> page, DeviceModel deviceModel);
/**
* selectDeviceModelById
*
* @param id
* @return
*/
DeviceModel selectDeviceModelById(Long id);
/**
* updateDeviceModel
*
* @param deviceModel
* @return
*/
int updateDeviceModel(DeviceModel deviceModel);
/**
* 删除(逻辑删除模型)
*
* @param id
* @return
*/
int deleteDeviceModelById(Long id);
}

View File

@@ -1,21 +0,0 @@
package com.maibu.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.maibu.core.business.DeviceModelProperty;
import java.util.List;
/**
* @author jsmbz
* @description 针对表【iot_device_property(设备属性定义表)】的数据库操作Service
* @createDate 2026-05-07 12:33:48
*/
public interface SysDevicePropertyService extends IService<DeviceModelProperty> {
/**
*
* @param id
* @return
*/
List<DeviceModelProperty> selectByModelId(Long id);
}

View File

@@ -0,0 +1,9 @@
package com.maibu.service.impl;
import org.springframework.stereotype.Service;
@Service
public class DeviceProductInterfaceService {
}

View File

@@ -1,18 +0,0 @@
package com.maibu.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maibu.core.business.ProductInterface;
import com.maibu.mapper.DeviceProductInterfaceMapper;
import com.maibu.service.DeviceProductInterfaceService;
import org.springframework.stereotype.Service;
/**
* @author jsmbz
* @description 针对表【device_product_interface(产品接口表)】的数据库操作Service实现
* @createDate 2026-05-08 15:37:53
*/
@Service
public class DeviceProductInterfaceServiceImpl extends ServiceImpl<DeviceProductInterfaceMapper, ProductInterface>
implements DeviceProductInterfaceService {
}

View File

@@ -2,14 +2,12 @@ package com.maibu.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maibu.core.business.Product;
import com.maibu.core.business.ProductInterface;
import com.maibu.core.business.dto.ProductDTO;
import com.maibu.exception.ServiceException;
import com.maibu.mapper.DeviceProductInterfaceMapper;
import com.maibu.mapper.DeviceProductMapper;
import com.maibu.service.DeviceProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -28,8 +26,7 @@ import java.util.stream.Collectors;
* @createDate 2026-05-08 13:45:57
*/
@Service
public class DeviceProductServiceImpl extends ServiceImpl<DeviceProductMapper, Product>
implements DeviceProductService {
public class DeviceProductService {
@@ -41,8 +38,12 @@ public class DeviceProductServiceImpl extends ServiceImpl<DeviceProductMapper, P
@Autowired
private DeviceProductMapper productMapper;
@Override
public Page<Product> selectProductPage(Page<Product> page, Product product) {
public boolean save(Product product){
return productMapper.saveOrUpdate(product);
}
public List<Product> selectProductPage(ProductDTO product) {
LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
// 精确查询产品编码
@@ -57,7 +58,7 @@ public class DeviceProductServiceImpl extends ServiceImpl<DeviceProductMapper, P
// 精确查询厂商
if (StringUtils.hasText(product.getManufacturer())) {
wrapper.eq(Product::getManufacturer, product.getManufacturer());
wrapper.like(Product::getManufacturer, product.getManufacturer());
}
// 精确查询分类ID
@@ -86,20 +87,20 @@ public class DeviceProductServiceImpl extends ServiceImpl<DeviceProductMapper, P
// 按创建时间倒序
wrapper.orderByDesc(Product::getCreateTime);
return this.page(page, wrapper);
return productMapper.selectList(wrapper);
}
@Override
public Product selectByCode(String code) {
LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Product::getCode, code)
.eq(Product::getDelFlag, 0);
return this.getOne(wrapper);
return productMapper.selectOne(wrapper);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean insertProduct(Product product) {
// 1. 插入产品主表
@@ -108,7 +109,7 @@ public class DeviceProductServiceImpl extends ServiceImpl<DeviceProductMapper, P
product.setDelFlag(false);
product.setStatus(1); // 默认启用
int rows = this.baseMapper.insert(product);
int rows = productMapper.insert(product);
if (rows <= 0) {
throw new ServiceException("产品创建失败");
}
@@ -130,7 +131,7 @@ public class DeviceProductServiceImpl extends ServiceImpl<DeviceProductMapper, P
return true;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateProduct(Product product) {
// 1. 更新产品主表
@@ -198,4 +199,10 @@ public class DeviceProductServiceImpl extends ServiceImpl<DeviceProductMapper, P
return true;
}
public int removeByIds(List<Long> ids) {
if (CollectionUtils.isEmpty(ids)) return 0;
return productMapper.deleteBatchIds(ids);
}
}

View File

@@ -2,16 +2,17 @@ package com.maibu.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maibu.core.business.IoTCommonDevice;
import com.maibu.core.business.dto.DeviceConfigDTO;
import com.maibu.core.enums.ConnectType;
import com.maibu.mapper.IotDeviceCommonMapper;
import com.maibu.memory.GlobalMemory;
import com.maibu.service.IotDeviceCommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
@@ -24,11 +25,12 @@ import java.util.List;
*/
@Slf4j
@Service
public class IotDeviceCommonServiceImpl extends ServiceImpl<IotDeviceCommonMapper, IoTCommonDevice>
implements IotDeviceCommonService {
public class IotDeviceCommonService {
@Override
@Autowired
private IotDeviceCommonMapper iotDeviceCommonMapper;
public void addDeviceToUnRegisterCache(DeviceConfigDTO deviceDTO) throws Exception {
// 1. 检查 SN 是否已存在(缓存 + 数据库)
if (GlobalMemory.unRegisterCommonDeviceMap.containsKey(deviceDTO.getSn())) {
@@ -64,12 +66,12 @@ public class IotDeviceCommonServiceImpl extends ServiceImpl<IotDeviceCommonMappe
log.info("设备 {} 已加入未注册缓存", deviceDTO.getSn());
}
@Override
public List<IoTCommonDevice> getUnRegisterDevices() {
return new ArrayList<>(GlobalMemory.unRegisterCommonDeviceMap.values());
}
@Override
public Page<IoTCommonDevice> selectDevicePage(Page<IoTCommonDevice> page, IoTCommonDevice device) {
LambdaQueryWrapper<IoTCommonDevice> wrapper = new LambdaQueryWrapper<>();
@@ -88,18 +90,18 @@ public class IotDeviceCommonServiceImpl extends ServiceImpl<IotDeviceCommonMappe
wrapper.eq(IoTCommonDevice::getDelFlag, false);
wrapper.orderByDesc(IoTCommonDevice::getCreateTime);
return this.page(page, wrapper);
return iotDeviceCommonMapper.selectPage(page, wrapper);
}
@Override
public IoTCommonDevice getBySn(String sn) {
LambdaQueryWrapper<IoTCommonDevice> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(IoTCommonDevice::getDeviceId, sn)
.eq(IoTCommonDevice::getDelFlag, false);
return this.getOne(wrapper);
return iotDeviceCommonMapper.selectOne(wrapper);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void registerDevice(Long deviceId, Long orgId, Long siteId) {
// TODO: 从未注册缓存取出设备,绑定组织/场站,落库
@@ -107,12 +109,10 @@ public class IotDeviceCommonServiceImpl extends ServiceImpl<IotDeviceCommonMappe
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateDevice(DeviceConfigDTO deviceDTO) {
// 1. 查询设备是否存在
IoTCommonDevice existDevice = this.getById(deviceDTO.getId());
IoTCommonDevice existDevice = iotDeviceCommonMapper.selectById(deviceDTO.getId());
if (existDevice == null) {
throw new RuntimeException("设备不存在");
}
@@ -142,23 +142,10 @@ public class IotDeviceCommonServiceImpl extends ServiceImpl<IotDeviceCommonMappe
BeanUtils.copyProperties(deviceDTO, device);
device.setUpdateTime(LocalDateTime.now());
return this.updateById(device);
return iotDeviceCommonMapper.saveOrUpdate(device);
}
/**
* 设备连接测试(根据协议类型)
*/
@@ -179,13 +166,11 @@ public class IotDeviceCommonServiceImpl extends ServiceImpl<IotDeviceCommonMappe
}
@Override
public IoTCommonDevice getFromUnRegisterCache(String sn) {
return GlobalMemory.unRegisterCommonDeviceMap.get(sn);
}
@Override
public void updateUnRegisterCache(IoTCommonDevice device) {
if (device.getDeviceId() == null) {
throw new RuntimeException("设备 ID (SN) 不能为空");
@@ -196,8 +181,6 @@ public class IotDeviceCommonServiceImpl extends ServiceImpl<IotDeviceCommonMappe
}
/**
* MQTT 连接测试
*/
@@ -240,5 +223,26 @@ public class IotDeviceCommonServiceImpl extends ServiceImpl<IotDeviceCommonMappe
}
public void removeByIds(List<Long> ids) {
if (CollectionUtils.isEmpty(ids)) return;
iotDeviceCommonMapper.deleteBatchIds(ids);
}
public void commonDeviceMonitor() {
//先初始化 外部设备连接
GlobalMemory.getAllSiteMemory().forEach(x -> {
List<IoTCommonDevice> list = x.getAllCommonDevice();
if (!CollectionUtils.isEmpty(list)) {
list.forEach(y -> {
if (ConnectType.MQTT.equals(y.getConnectType())) {
String ip = y.getNetworkIp();
Integer port = y.getPort();
}
});
}
});
}
}

View File

@@ -1,12 +1,10 @@
package com.maibu.service.impl;
import com.maibu.annotation.DataSource;
import com.maibu.constant.CacheConstants;
import com.maibu.constant.UserConstants;
import com.maibu.core.redis.RedisCache;
import com.maibu.core.text.Convert;
import com.maibu.domain.SysConfig;
import com.maibu.enums.DataSourceType;
import com.maibu.exception.ServiceException;
import com.maibu.mapper.SysConfigMapper;
import com.maibu.service.ISysConfigService;

View File

@@ -0,0 +1 @@
package com.maibu.service.impl;

View File

@@ -0,0 +1,13 @@
package com.maibu.service.impl;
import org.springframework.stereotype.Service;
/**
* @author jsmbz
* @description 针对表【iot_device_model_property_mapping(设备模型属性映射表)】的数据库操作Service实现
* @createDate 2026-05-07 12:33:48
*/
@Service
public class SysDeviceModelPropertyMappingService {
}

View File

@@ -1,18 +0,0 @@
package com.maibu.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maibu.core.business.DeviceModelPropertyMapping;
import com.maibu.mapper.SysDeviceModelPropertyMappingMapper;
import com.maibu.service.SysDeviceModelPropertyMappingService;
import org.springframework.stereotype.Service;
/**
* @author jsmbz
* @description 针对表【iot_device_model_property_mapping(设备模型属性映射表)】的数据库操作Service实现
* @createDate 2026-05-07 12:33:48
*/
@Service
public class SysDeviceModelPropertyMappingServiceImpl extends ServiceImpl<SysDeviceModelPropertyMappingMapper, DeviceModelPropertyMapping>
implements SysDeviceModelPropertyMappingService {
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
package com.maibu.service.impl;