package com.jojubanking.boot.module.system.service.reserve8;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.text.ParseException;
import java.util.*;
import com.jojubanking.boot.module.system.controller.admin.reserve8.vo.*;
import com.jojubanking.boot.module.system.dal.dataobject.reserve8.Reserve8DO;
import com.jojubanking.boot.framework.common.pojo.PageResult;

import com.jojubanking.boot.module.system.convert.reserve8.Reserve8Convert;
import com.jojubanking.boot.module.system.dal.mysql.reserve8.Reserve8Mapper;

import static com.jojubanking.boot.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.jojubanking.boot.module.system.enums.ErrorCodeConstants.*;

/**
 * 预约挂号 Service 实现类
 *
 * @author admin
 */
@Service
@Validated
public class Reserve8ServiceImpl implements Reserve8Service {

    @Resource
    private Reserve8Mapper reserve8Mapper;

    @Override
    public Integer createReserve8(Reserve8CreateReqVO createReqVO) {
        // 插入
        Reserve8DO reserve8 = Reserve8Convert.INSTANCE.convert(createReqVO);
        reserve8Mapper.insert(reserve8);
        // 返回
        return reserve8.getId();
    }

    @Override
    public void updateReserve8(Reserve8UpdateReqVO updateReqVO) {
        // 校验存在
        this.validateReserve8Exists(updateReqVO.getId());
        // 更新
        Reserve8DO updateObj = Reserve8Convert.INSTANCE.convert(updateReqVO);
        reserve8Mapper.updateById(updateObj);
    }

    @Override
    public void deleteReserve8(Integer id) {
        // 校验存在
        this.validateReserve8Exists(id);
        // 删除
        reserve8Mapper.deleteById(id);
    }

    private void validateReserve8Exists(Integer id) {
        if (reserve8Mapper.selectById(id) == null) {
            throw exception(RESERVE8_NOT_EXISTS);
        }
    }

    @Override
    public Reserve8DO getReserve8(Integer id) {
        return reserve8Mapper.selectById(id);
    }

    @Override
    public List<Reserve8DO> getReserve8List(Collection<Integer> ids) {
        return reserve8Mapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<Reserve8DO> getReserve8Page(Reserve8PageReqVO pageReqVO) throws ParseException {
        return reserve8Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<Reserve8DO> getReserve8List(Reserve8ExportReqVO exportReqVO) {
        return reserve8Mapper.selectList(exportReqVO);
    }

}
