package cn.iocoder.yudao.module.bpm.service.definition;

import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.copy.TaskCopySaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.TaskCopyDO;
import cn.iocoder.yudao.module.bpm.dal.mysql.definition.TaskCopyMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * @Author: jinyd
 * @CreateTime: 2024/9/25  16:14
 * @Description:
 * @Version: 4.0
 */


@Service
@Validated
public class TaskCopyServiceImpl implements TaskCopyService{

    @Resource
    private TaskCopyMapper taskCopyMapper;

    @Override
    public Long createTaskCopy(TaskCopySaveReqVO createReqVO) {
        // 插入
        TaskCopyDO taskCopy = BeanUtils.toBean(createReqVO, TaskCopyDO.class);
        taskCopyMapper.insert(taskCopy);
        // 返回
        return taskCopy.getId();
    }

    @Override
    public void updateTaskCopy(TaskCopySaveReqVO updateReqVO) {
        // 校验存在
        validateTaskCopyExists(updateReqVO.getId());
        // 更新
        TaskCopyDO updateObj = BeanUtils.toBean(updateReqVO, TaskCopyDO.class);
        taskCopyMapper.updateById(updateObj);
    }

    @Override
    public void deleteTaskCopy(Long id) {
        // 校验存在
        validateTaskCopyExists(id);
        // 删除
        taskCopyMapper.deleteById(id);
    }

    private void validateTaskCopyExists(Long id) {
        if (taskCopyMapper.selectById(id) == null) {
//            throw exception(TASK_COPY_NOT_EXISTS);
        }
    }

    @Override
    public TaskCopyDO getTaskCopy(Long id) {
        return taskCopyMapper.selectById(id);
    }

}
