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

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeetingattrs.vo.IotOperationMeetingAttrsPageReqVO;
import cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeetingattrs.vo.IotOperationMeetingAttrsSaveReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotoperationmeetingattrs.IotOperationMeetingAttrsDO;
import cn.iocoder.yudao.module.pms.dal.mysql.iotoperationmeetingattrs.IotOperationMeetingAttrsMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

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

/**
 * 专业公司工作量扩展属性 Service 实现类
 *
 * @author ruiqi
 */
@Service
@Validated
public class IotOperationMeetingAttrsServiceImpl implements IotOperationMeetingAttrsService {

    @Resource
    private IotOperationMeetingAttrsMapper iotOperationMeetingAttrsMapper;

    @Override
    public Long createIotOperationMeetingAttrs(IotOperationMeetingAttrsSaveReqVO createReqVO) {
        // 插入
        IotOperationMeetingAttrsDO iotOperationMeetingAttrs = BeanUtils.toBean(createReqVO, IotOperationMeetingAttrsDO.class);
        iotOperationMeetingAttrsMapper.insert(iotOperationMeetingAttrs);
        // 返回
        return iotOperationMeetingAttrs.getId();
    }

    @Override
    public void updateIotOperationMeetingAttrs(IotOperationMeetingAttrsSaveReqVO updateReqVO) {
        // 校验存在
        validateIotOperationMeetingAttrsExists(updateReqVO.getId());
        // 更新
        IotOperationMeetingAttrsDO updateObj = BeanUtils.toBean(updateReqVO, IotOperationMeetingAttrsDO.class);
        iotOperationMeetingAttrsMapper.updateById(updateObj);
    }

    @Override
    public void deleteIotOperationMeetingAttrs(Long id) {
        // 校验存在
        validateIotOperationMeetingAttrsExists(id);
        // 删除
        iotOperationMeetingAttrsMapper.deleteById(id);
    }

    private void validateIotOperationMeetingAttrsExists(Long id) {
        if (iotOperationMeetingAttrsMapper.selectById(id) == null) {
            throw exception(IOT_OPERATION_MEETING_ATTRS_NOT_EXISTS);
        }
    }

    @Override
    public IotOperationMeetingAttrsDO getIotOperationMeetingAttrs(Long id) {
        return iotOperationMeetingAttrsMapper.selectById(id);
    }

    @Override
    public PageResult<IotOperationMeetingAttrsDO> getIotOperationMeetingAttrsPage(IotOperationMeetingAttrsPageReqVO pageReqVO) {
        return iotOperationMeetingAttrsMapper.selectPage(pageReqVO);
    }

}