设备操作接口

This commit is contained in:
gong
2025-11-24 14:21:01 +08:00
parent ee41fd2253
commit 97b03a8495
9 changed files with 395 additions and 3 deletions

View File

@@ -0,0 +1,14 @@
package com.czg.service.system.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.system.entity.SysDevices;
/**
* 设备管理 映射层。
*
* @author ww
* @since 2025-11-24
*/
public interface SysDevicesMapper extends BaseMapper<SysDevices> {
}

View File

@@ -0,0 +1,85 @@
package com.czg.service.system.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.exception.CzgException;
import com.czg.service.system.mapper.SysDevicesMapper;
import com.czg.system.dto.SysDevicesDTO;
import com.czg.system.dto.SysDevicesPageDTO;
import com.czg.system.entity.SysDevices;
import com.czg.system.service.SysDevicesService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* 设备管理 服务层实现。
*
* @author ww
* @since 2025-11-24
*/
@Service
public class SysDevicesServiceImpl extends ServiceImpl<SysDevicesMapper, SysDevices> implements SysDevicesService {
@Override
public Long addDevice(SysDevicesDTO reqDTO) {
// 检查 sn 是否存在
if (exists(query().eq(SysDevices::getDeviceSn, reqDTO.getDeviceSn()))) {
throw new CzgException("设备sn已存在");
}
SysDevices devices = BeanUtil.toBean(reqDTO, SysDevices.class);
save(devices);
return devices.getId();
}
@Override
public Long updateDevice(SysDevicesDTO reqDTO) {
// 检查 sn 存在
if (exists(query().ne(SysDevices::getId, reqDTO.getId()).eq(SysDevices::getDeviceSn, reqDTO.getDeviceSn()))) {
throw new CzgException("设备sn已存在");
}
SysDevices devices = getById(reqDTO.getId());
if (devices == null) {
throw new CzgException("设备不存在");
}
devices.setDeviceSn(reqDTO.getDeviceSn());
devices.setDeviceType(reqDTO.getDeviceType());
devices.setConnType(reqDTO.getConnType());
devices.setUnlineStatus(reqDTO.getUnlineStatus());
updateById(devices);
return devices.getId();
}
@Override
public Long deleteDevice(Long id) {
SysDevices devices = getById(id);
if (devices == null) {
throw new CzgException("设备不存在");
}
removeById(id);
return id;
}
@Override
public Page<SysDevicesDTO> queryDevice(SysDevicesPageDTO reqDTO) {
QueryWrapper wrapper = new QueryWrapper();
if (StrUtil.isNotBlank(reqDTO.getDeviceSn())) {
wrapper.like(SysDevices::getDeviceSn, reqDTO.getDeviceSn());
}
if (StrUtil.isNotBlank(reqDTO.getDeviceType())) {
wrapper.eq(SysDevices::getDeviceType, reqDTO.getDeviceType());
}
if (StrUtil.isNotBlank(reqDTO.getConnType())) {
wrapper.eq(SysDevices::getConnType, reqDTO.getConnType());
}
return page(Page.of(reqDTO.getPage(), reqDTO.getSize()), wrapper).map(devices -> BeanUtil.toBean(devices, SysDevicesDTO.class));
}
}

View File

@@ -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.czg.service.system.mapper.SysDevicesMapper">
</mapper>