package cn.iocoder.yudao.module.configure.service.tracelink;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.configure.controller.admin.tracelink.vo.TraceLinkPageReqVO;
import cn.iocoder.yudao.module.configure.dal.dataobject.tracelink.TraceLinkDO;
import cn.iocoder.yudao.module.configure.dal.mysql.tracelink.TraceLinkMapper;
import cn.iocoder.yudao.module.configure.enums.ErrorCodeConstants;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;

/**
 * 溯源模板-环节 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class TraceLinkServiceImpl implements TraceLinkService {

    @Resource
    private TraceLinkMapper traceLinkMapper;

    @Override
    public void deleteTraceLink(Long id) {
        // 校验存在
        validateTraceLinkExists(id);
        // 删除
        traceLinkMapper.deleteById(id);
    }

    private void validateTraceLinkExists(Long id) {
        if (traceLinkMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.TRACE_LINK_NOT_EXISTS);
        }
    }

    @Override
    public TraceLinkDO getTraceLink(Long id) {
        return traceLinkMapper.selectById(id);
    }

    @Override
    public PageResult<TraceLinkDO> getTraceLinkPage(TraceLinkPageReqVO pageReqVO) {
        return traceLinkMapper.selectPage(pageReqVO);
    }

}
