package cn.iocoder.yudao.module.system.service.wait;

import cn.iocoder.yudao.module.system.controller.admin.wait.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.wait.MoveToWaitDO;
import cn.iocoder.yudao.module.system.dal.mysql.wait.MoveToWaitMapper;
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.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.system.enums.ErrorCodeConstants.MOVE_TO_WAIT_NOT_EXISTS;

/**
 * 车辆前往等待点记录 Service 实现类
 *
 * @author 陈宾顺
 */
@Service
@Validated
public class MoveToWaitServiceImpl implements MoveToWaitService {

    @Resource
    private MoveToWaitMapper moveToWaitMapper;

    @Override
    public Long createMoveToWait(MoveToWaitSaveReqVO createReqVO) {
        // 插入
        MoveToWaitDO moveToWait = BeanUtils.toBean(createReqVO, MoveToWaitDO.class);
        moveToWaitMapper.insert(moveToWait);
        // 返回
        return moveToWait.getId();
    }

    @Override
    public void updateMoveToWait(MoveToWaitSaveReqVO updateReqVO) {
        // 校验存在
        validateMoveToWaitExists(updateReqVO.getId());
        // 更新
        MoveToWaitDO updateObj = BeanUtils.toBean(updateReqVO, MoveToWaitDO.class);
        moveToWaitMapper.updateById(updateObj);
    }

    @Override
    public void deleteMoveToWait(Long id) {
        // 校验存在
        validateMoveToWaitExists(id);
        // 删除
        moveToWaitMapper.deleteById(id);
    }

    private void validateMoveToWaitExists(Long id) {
        if (moveToWaitMapper.selectById(id) == null) {
            throw exception(MOVE_TO_WAIT_NOT_EXISTS);
        }
    }

    @Override
    public MoveToWaitDO getMoveToWait(Long id) {
        return moveToWaitMapper.selectById(id);
    }

    @Override
    public PageResult<MoveToWaitDO> getMoveToWaitPage(MoveToWaitPageReqVO pageReqVO) {
        return moveToWaitMapper.selectPage(pageReqVO);
    }



}