package cn.iocoder.yudao.module.pms.service.iotoperationplandev;

import cn.iocoder.yudao.module.pms.dal.mysql.iotoperationplandev.IotOperationPlanDevMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.pms.controller.admin.iotoperationplandev.vo.*;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotoperationplandev.IotOperationPlanDevDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;



import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_OPERATION_PLAN_DEV_NOT_EXISTS;


/**
 * 运行记录计划设备 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class IotOperationPlanDevServiceImpl implements IotOperationPlanDevService {

    @Resource
    private IotOperationPlanDevMapper iotOperationPlanDevMapper;

    @Override
    public Long createIotOperationPlanDev(IotOperationPlanDevSaveReqVO createReqVO) {
        // 插入
        IotOperationPlanDevDO iotOperationPlanDev = BeanUtils.toBean(createReqVO, IotOperationPlanDevDO.class);
        iotOperationPlanDevMapper.insert(iotOperationPlanDev);
        // 返回
        return iotOperationPlanDev.getId();
    }

    @Override
    public void updateIotOperationPlanDev(IotOperationPlanDevSaveReqVO updateReqVO) {
        // 校验存在
        validateIotOperationPlanDevExists(updateReqVO.getId());
        // 更新
        IotOperationPlanDevDO updateObj = BeanUtils.toBean(updateReqVO, IotOperationPlanDevDO.class);
        iotOperationPlanDevMapper.updateById(updateObj);
    }

    @Override
    public void deleteIotOperationPlanDev(Long id) {
        // 校验存在
        validateIotOperationPlanDevExists(id);
        // 删除
        iotOperationPlanDevMapper.deleteById(id);
    }

    private void validateIotOperationPlanDevExists(Long id) {
        if (iotOperationPlanDevMapper.selectById(id) == null) {
            throw exception(IOT_OPERATION_PLAN_DEV_NOT_EXISTS);
        }
    }

    @Override
    public IotOperationPlanDevDO getIotOperationPlanDev(Long id) {
        return iotOperationPlanDevMapper.selectById(id);
    }

    @Override
    public PageResult<IotOperationPlanDevDO> getIotOperationPlanDevPage(IotOperationPlanDevPageReqVO pageReqVO) {
        return iotOperationPlanDevMapper.selectPage(pageReqVO);
    }

}