package com.ruoyi.interfaces.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.interfaces.domain.MdModelWorkflow;
import com.ruoyi.interfaces.mapper.MdModelWorkflowMapper;
import com.ruoyi.interfaces.service.MdModelWorkflowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author lql
 * @date 2025-7-15
 */
@Slf4j
@Service
@Transactional
public class MdModelWorkflowServiceImpl extends ServiceImpl<MdModelWorkflowMapper, MdModelWorkflow> implements MdModelWorkflowService {

    @Override
    public boolean save(MdModelWorkflow mdModelWorkflow) {
        MdModelWorkflow mdModelWorkflow1 = getByModelId(mdModelWorkflow.getMdid());
        if (mdModelWorkflow1 != null) {
            mdModelWorkflow.setId(mdModelWorkflow1.getId());
            return updateById(mdModelWorkflow);
        }
        return super.save(mdModelWorkflow);
    }

    @Override
    public boolean updateById(MdModelWorkflow mdModelWorkflow) {
        return super.updateById(mdModelWorkflow);
    }

    @Override
    public MdModelWorkflow getByModelId(String modelId) {
        QueryWrapper<MdModelWorkflow> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mdid", modelId);
        return getOne(queryWrapper);
    }
}
