package cn.axzo.workflow.core.service.impl;

import cn.axzo.workflow.core.repository.entity.ExtAxMqLog;
import cn.axzo.workflow.core.repository.mapper.ExtAxMqLogMapper;
import cn.axzo.workflow.core.service.ExtAxMqLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Api Log 表操服务实现
 *
 * @author wangli
 * @since 2024/4/3 10:41
 */
@Service
@Slf4j
public class ExtAxMqLogServiceImpl implements ExtAxMqLogService {
    @Resource
    private ExtAxMqLogMapper mqLogMapper;

    @Override
    public Long insert(ExtAxMqLog apiLog) {
        mqLogMapper.insert(apiLog);
        return apiLog.getId();
    }

    @Override
    public void update(ExtAxMqLog mqLog) {
        UpdateWrapper<ExtAxMqLog> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("unique_id", mqLog.getUniqueId());
        mqLogMapper.update(mqLog, updateWrapper);
    }

    @Override
    public void delete(ExtAxMqLog mqLog) {
        QueryWrapper<ExtAxMqLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("unique_id", mqLog.getUniqueId());
        queryWrapper.eq("trace_id", mqLog.getTraceId());
        mqLogMapper.delete(queryWrapper);
    }
}
