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

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;