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

import cn.iocoder.yudao.module.system.controller.admin.remote.vo.ControllerTaskTransferLogPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.remote.vo.ControllerTaskTransferLogSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.remote.ControllerTaskTransferLogDO;
import cn.iocoder.yudao.module.system.dal.mysql.remote.ControllerTaskTransferLogMapper;
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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.CONTROLLER_TASK_TRANSFER_LOG_NOT_EXISTS;

/**
 * 远遥任务转移记录 Service 实现类
 *
 * @author 陈宾顺
 */
@Service
@Validated
public class ControllerTaskTransferLogServiceImpl extends ServiceImpl<ControllerTaskTransferLogMapper, ControllerTaskTransferLogDO> implements ControllerTaskTransferLogService {

    @Resource
    private ControllerTaskTransferLogMapper controllerTaskTransferLogMapper;

    @Override
    public Long createControllerTaskTransferLog(ControllerTaskTransferLogSaveReqVO createReqVO) {
        // 插入
        ControllerTaskTransferLogDO controllerTaskTransferLog = BeanUtils.toBean(createReqVO, ControllerTaskTransferLogDO.class);
        controllerTaskTransferLogMapper.insert(controllerTaskTransferLog);
        // 返回
        return controllerTaskTransferLog.getId();
    }

    @Override
    public void updateControllerTaskTransferLog(ControllerTaskTransferLogSaveReqVO updateReqVO) {
        // 校验存在
        validateControllerTaskTransferLogExists(updateReqVO.getId());
        // 更新
        ControllerTaskTransferLogDO updateObj = BeanUtils.toBean(updateReqVO, ControllerTaskTransferLogDO.class);
        controllerTaskTransferLogMapper.updateById(updateObj);
    }

    @Override
    public void deleteControllerTaskTransferLog(Long id) {
        // 校验存在
        validateControllerTaskTransferLogExists(id);
        // 删除
        controllerTaskTransferLogMapper.deleteById(id);
    }

    private void validateControllerTaskTransferLogExists(Long id) {
        if (controllerTaskTransferLogMapper.selectById(id) == null) {
            throw exception(CONTROLLER_TASK_TRANSFER_LOG_NOT_EXISTS);
        }
    }

    @Override
    public ControllerTaskTransferLogDO getControllerTaskTransferLog(Long id) {
        return controllerTaskTransferLogMapper.selectById(id);
    }

    @Override
    public PageResult<ControllerTaskTransferLogDO> getControllerTaskTransferLogPage(ControllerTaskTransferLogPageReqVO pageReqVO) {
        return controllerTaskTransferLogMapper.selectPage(pageReqVO);
    }

}
