gasWellWatch/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java

114 lines
3.8 KiB
Java
Raw Normal View History

2024-11-25 01:04:53 +08:00
package com.isu.gaswellwatch.service.impl;
import cn.hutool.core.collection.CollectionUtil;
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.isu.gaswellwatch.config.SnowflakeConfig;
import com.isu.gaswellwatch.dao.DepartmentDao;
import com.isu.gaswellwatch.dao.DeviceDao;
import com.isu.gaswellwatch.dto.DepartmentDTO;
import com.isu.gaswellwatch.dto.DepartmentEditDTO;
import com.isu.gaswellwatch.dto.DeviceCreateDTO;
import com.isu.gaswellwatch.dto.DeviceEditDTO;
import com.isu.gaswellwatch.entity.BlockDepartment;
import com.isu.gaswellwatch.entity.Department;
import com.isu.gaswellwatch.entity.Device;
2024-11-25 16:29:26 +08:00
import com.isu.gaswellwatch.entity.GasWell;
2024-11-25 01:04:53 +08:00
import com.isu.gaswellwatch.exception.BusinessException;
import com.isu.gaswellwatch.service.BlockDepartmentService;
import com.isu.gaswellwatch.service.DepartmentService;
import com.isu.gaswellwatch.service.DeviceService;
import com.isu.gaswellwatch.service.GasWellService;
import com.isu.gaswellwatch.utils.ConverterUtil;
import com.isu.gaswellwatch.vo.DepartmentVO;
2024-11-25 15:48:00 +08:00
import com.isu.gaswellwatch.vo.DeviceVO;
2024-11-25 01:04:53 +08:00
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service("deviceService")
@Transactional(rollbackFor = Exception.class)
public class DeviceServiceImpl extends ServiceImpl<DeviceDao, Device> implements DeviceService {
@Resource
private SnowflakeConfig snowflakeConfig;
@Resource
private DeviceDao deviceDao;
@Resource
private GasWellService gasWellService;
@Override
2024-11-25 15:48:00 +08:00
public Page<DeviceVO> page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName,Long deviceTypeId){
Page<DeviceVO> page = deviceDao.page(new Page<>(currentPage, pageSize),gasWellName,gasStationName,deviceTypeId);
2024-11-25 01:04:53 +08:00
//TODO 从Redis获取设备数据
2024-11-25 15:48:00 +08:00
return ConverterUtil.convertPage(page, DeviceVO.class);
2024-11-25 01:04:53 +08:00
}
@Override
public void add(DeviceCreateDTO deviceCreateDTO){
//查重
List<Device> list = list(new LambdaQueryWrapper<Device>().eq(Device::getId, deviceCreateDTO.getCode()));
if(CollectionUtil.isNotEmpty(list)) {
throw new BusinessException("已有相同设备编码,请重新输入");
}
2024-11-25 16:29:26 +08:00
GasWell gasWell = gasWellService.getOne(new LambdaQueryWrapper<GasWell>().eq(GasWell::getId, deviceCreateDTO.getGasWell()));
if(gasWell==null) {
throw new BusinessException("该气井不存在");
}
if(gasWell.getDeviceId()!=null) {
throw new BusinessException("该气井已存在绑定设备,无法添加新设备");
}
2024-11-25 01:04:53 +08:00
Device device = ConverterUtil.convert(deviceCreateDTO, Device.class);
//code必须为整形用于在缓存中查询设备的上报数据
device.setId(Long.valueOf(deviceCreateDTO.getCode()));
save(device);
//在气井中绑定设备
gasWellService.bindDevice(deviceCreateDTO.getGasWell(),device.getId());
}
@Override
public void edit(DeviceEditDTO deviceEditDTO){
updateById(ConverterUtil.convert(deviceEditDTO, Device.class));
}
@Override
public void delete(Long id){
//删除设备
removeById(id);
//解绑气井
gasWellService.unbindDevice(id);
}
@Override
2024-11-25 15:48:00 +08:00
public DeviceVO getDevice(Long id) {
return deviceDao.getDeviceById(id);
2024-11-25 01:04:53 +08:00
}
@Override
public void getDeviceControlData(Long id) {
}
@Override
public void getDeviceHistoryData(Long id) {
}
@Override
public void getDeviceLogData(Long id) {
}
}