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

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.iotoperationmeetingdetail.vo.IotOperationMeetingDetailPageReqVO;
import cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeetingdetail.vo.IotOperationMeetingDetailSaveReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotoperationmeetingdetail.IotOperationMeetingDetailDO;
import cn.iocoder.yudao.module.pms.dal.mysql.iotoperationmeetingdetail.IotOperationMeetingDetailMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
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_OPERATION_MEETING_DETAIL_NOT_EXISTS;

/**
 * 生产运营会明细 Service 实现类
 *
 * @author ruiqi
 */
@Service
@Validated
public class IotOperationMeetingDetailServiceImpl implements IotOperationMeetingDetailService {

    @Resource
    private IotOperationMeetingDetailMapper iotOperationMeetingDetailMapper;

    @Override
    public Long createIotOperationMeetingDetail(IotOperationMeetingDetailSaveReqVO createReqVO) {
        // 插入
        IotOperationMeetingDetailDO iotOperationMeetingDetail = BeanUtils.toBean(createReqVO, IotOperationMeetingDetailDO.class);
        iotOperationMeetingDetailMapper.insert(iotOperationMeetingDetail);
        // 返回
        return iotOperationMeetingDetail.getId();
    }

    @Override
    public void updateIotOperationMeetingDetail(IotOperationMeetingDetailSaveReqVO updateReqVO) {
        // 校验存在
        validateIotOperationMeetingDetailExists(updateReqVO.getId());
        // 更新
        IotOperationMeetingDetailDO updateObj = BeanUtils.toBean(updateReqVO, IotOperationMeetingDetailDO.class);
        iotOperationMeetingDetailMapper.updateById(updateObj);
    }

    @Override
    public void deleteIotOperationMeetingDetail(Long id) {
        // 校验存在
        validateIotOperationMeetingDetailExists(id);
        // 删除
        iotOperationMeetingDetailMapper.deleteById(id);
    }

    private void validateIotOperationMeetingDetailExists(Long id) {
        if (iotOperationMeetingDetailMapper.selectById(id) == null) {
            throw exception(IOT_OPERATION_MEETING_DETAIL_NOT_EXISTS);
        }
    }

    @Override
    public IotOperationMeetingDetailDO getIotOperationMeetingDetail(Long id) {
        return iotOperationMeetingDetailMapper.selectById(id);
    }

    @Override
    public PageResult<IotOperationMeetingDetailDO> getIotOperationMeetingDetailPage(IotOperationMeetingDetailPageReqVO pageReqVO) {
        return iotOperationMeetingDetailMapper.selectPage(pageReqVO);
    }

    @Override
    public List<IotOperationMeetingDetailDO> summarizedProjectDetails(IotOperationMeetingDetailPageReqVO reqVO) {
        return iotOperationMeetingDetailMapper.summarizedProjectDetails(reqVO);
    }

}