package cn.lihu.jh.module.ecg.service.devmanage;
|
|
import cn.lihu.jh.module.ecg.dal.dataobject.devmanage.DeviceStatisticDO;
|
import org.springframework.stereotype.Service;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.*;
|
import cn.lihu.jh.module.ecg.controller.admin.devmanage.vo.*;
|
import cn.lihu.jh.module.ecg.dal.dataobject.devmanage.DeviceDO;
|
import cn.lihu.jh.framework.common.pojo.PageResult;
|
import cn.lihu.jh.framework.common.pojo.PageParam;
|
import cn.lihu.jh.framework.common.util.object.BeanUtils;
|
|
import cn.lihu.jh.module.ecg.dal.mysql.devmanage.DeviceMapper;
|
|
import javax.annotation.Resource;
|
|
import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*;
|
|
/**
|
* 设备 Service 实现类
|
*
|
* @author majianbo
|
*/
|
@Service
|
@Validated
|
public class DeviceServiceImpl implements DeviceService {
|
|
@Resource
|
private DeviceMapper deviceMapper;
|
|
@Override
|
public Integer createDevice(DeviceSaveReqVO createReqVO) {
|
// 插入
|
DeviceDO device = BeanUtils.toBean(createReqVO, DeviceDO.class);
|
deviceMapper.insert(device);
|
// 返回
|
return device.getId();
|
}
|
|
@Override
|
public void updateDevice(DeviceSaveReqVO updateReqVO) {
|
// 校验存在
|
validateDeviceExists(updateReqVO.getId());
|
// 更新
|
DeviceDO updateObj = BeanUtils.toBean(updateReqVO, DeviceDO.class);
|
deviceMapper.updateById(updateObj);
|
}
|
|
@Override
|
public Integer updateDeviceState(DeviceSaveReqVO updateReqVO) {
|
// 校验存在
|
validateDeviceExists(updateReqVO.getId());
|
// 更新
|
DeviceDO updateObj = BeanUtils.toBean(updateReqVO, DeviceDO.class);
|
return deviceMapper.updateDevState(updateObj.getDevId(), updateObj.getState(), updateObj.getStateDate());
|
}
|
|
@Override
|
public void deleteDevice(Integer id) {
|
// 校验存在
|
validateDeviceExists(id);
|
// 删除
|
deviceMapper.deleteById(id);
|
}
|
|
private void validateDeviceExists(Integer id) {
|
if (deviceMapper.selectById(id) == null) {
|
throw exception(DEVICE_NOT_EXISTS);
|
}
|
}
|
|
@Override
|
public DeviceDO getDevice(Integer id) {
|
return deviceMapper.selectById(id);
|
}
|
|
@Override
|
public DeviceDO getDevice(String devId) {
|
return deviceMapper.getDeviceByDevId(devId);
|
}
|
|
@Override
|
public PageResult<DeviceDO> getDevicePage(DevicePageReqVO pageReqVO) {
|
return deviceMapper.selectPage(pageReqVO);
|
}
|
|
@Override
|
public List<DeviceStatisticDO> getDeviceStatistic(DevicePageReqVO pageReqVO) {
|
return deviceMapper.getDevStatistic(pageReqVO);
|
}
|
|
}
|