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

import cn.iocoder.yudao.module.pms.controller.admin.vo.IotOpeationModelPageReqVO;
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotOpeationModelSaveReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationmodel.IotOpeationModelDO;
import cn.iocoder.yudao.module.pms.dal.mysql.iotopeationmodel.IotOpeationModelMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import java.util.List;

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

/**
 * 运行记录模板主 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class IotOpeationModelServiceImpl implements IotOpeationModelService {

    @Resource
    private IotOpeationModelMapper iotOpeationModelMapper;

    @Override
    public Long createIotOpeationModel(IotOpeationModelSaveReqVO createReqVO) {
        // 插入
        IotOpeationModelDO iotOpeationModel = BeanUtils.toBean(createReqVO, IotOpeationModelDO.class);
        iotOpeationModelMapper.insert(iotOpeationModel);
        // 返回
        return Long.valueOf(iotOpeationModel.getDeptId());
    }

    @Override
    public void updateIotOpeationModel(IotOpeationModelSaveReqVO updateReqVO) {
        // 校验存在
        validateIotOpeationModelExists(updateReqVO.getId());
        // 更新
        IotOpeationModelDO updateObj = BeanUtils.toBean(updateReqVO, IotOpeationModelDO.class);
        iotOpeationModelMapper.updateById(updateObj);
    }

    @Override
    public void deleteIotOpeationModel(Long id) {
        // 校验存在
        validateIotOpeationModelExists(id);
        // 删除
        iotOpeationModelMapper.deleteById(id);
    }

    private void validateIotOpeationModelExists(Long id) {
        if (iotOpeationModelMapper.selectById(id) == null) {
            throw exception(IOT_OPEATION_MODEL_NOT_EXISTS);
        }
    }

    @Override
    public IotOpeationModelDO getIotOpeationModel(Long id) {
        return iotOpeationModelMapper.selectById(id);
    }

    @Override
    public IotOpeationModelDO getNew() {
        return iotOpeationModelMapper.getNew();
    }

    @Override
    public int insertCom(IotOpeationModelDO modelDO) {
        return iotOpeationModelMapper.insertCom(modelDO);
    }

    @Override
    public int updateCom(IotOpeationModelDO modelDO) {
        return iotOpeationModelMapper.updateCom(modelDO);
    }

    @Override
    public int insertFillInfo(IotOpeationModelDO modelDO) {
        return iotOpeationModelMapper.insertFillInfo(modelDO);
    }

    @Override
    public int updateFillInfo(IotOpeationModelDO modelDO) {
        return iotOpeationModelMapper.updateFillInfo(modelDO);
    }

    @Override
    public PageResult<IotOpeationModelDO> getIotOpeationModelPage(IotOpeationModelPageReqVO pageReqVO) {
        return iotOpeationModelMapper.selectPage(pageReqVO);
    }

}