package com.unis.module.coding.service.spqyxx;

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 com.unis.module.coding.controller.admin.spqyxx.vo.*;
import com.unis.module.coding.dal.dataobject.spqyxx.SpqyxxDO;
import com.unis.framework.common.pojo.PageResult;
import com.unis.framework.common.pojo.PageParam;
import com.unis.framework.common.util.object.BeanUtils;

import com.unis.module.coding.dal.mysql.spqyxx.SpqyxxMapper;

import static com.unis.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.unis.module.core.enums.ErrorCodeConstants.SPQYXX_NOT_EXISTS;

/**
 * 视频区域信息 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class SpqyxxServiceImpl implements SpqyxxService {

    @Resource
    private SpqyxxMapper spqyxxMapper;

    @Override
    public Long createSpqyxx(SpqyxxSaveReqVO createReqVO) {
        // 插入
        SpqyxxDO spqyxx = BeanUtils.toBean(createReqVO, SpqyxxDO.class);
        spqyxxMapper.insert(spqyxx);
        // 返回
        return spqyxx.getId();
    }

    @Override
    public void updateSpqyxx(SpqyxxSaveReqVO updateReqVO) {
        // 校验存在
        validateSpqyxxExists(updateReqVO.getId());
        // 更新
        SpqyxxDO updateObj = BeanUtils.toBean(updateReqVO, SpqyxxDO.class);
        spqyxxMapper.updateById(updateObj);
    }

    @Override
    public void deleteSpqyxx(Long id) {
        // 校验存在
        validateSpqyxxExists(id);
        // 删除
        spqyxxMapper.deleteById(id);
    }

    private void validateSpqyxxExists(Long id) {
        if (spqyxxMapper.selectById(id) == null) {
            throw exception(SPQYXX_NOT_EXISTS);
        }
    }

    @Override
    public SpqyxxDO getSpqyxx(Long id) {
        return spqyxxMapper.selectById(id);
    }

    @Override
    public PageResult<SpqyxxDO> getSpqyxxPage(SpqyxxPageReqVO pageReqVO) {
        return spqyxxMapper.selectPage(pageReqVO);
    }

}