package com.hfkj.service.agent.impl;

import com.hfkj.dao.BsAgentApiLogMapper;
import com.hfkj.entity.BsAgentApiLog;
import com.hfkj.entity.BsAgentApiLogExample;
import com.hfkj.entity.BsAgentApiLogWithBLOBs;
import com.hfkj.service.agent.BsAgentApiLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @className: BsAgentApiLogServiceImpl
 * @author: HuRui
 * @date: 2024/9/3
 **/
@Service("agentApiLogService")
public class BsAgentApiLogServiceImpl implements BsAgentApiLogService {
    @Resource
    private BsAgentApiLogMapper agentApiLogMapper;
    @Override
    public void edit(BsAgentApiLogWithBLOBs data) {
        if (data.getId() == null) {
            data.setCreateTime(new Date());
            agentApiLogMapper.insertSelective(data);
        } else {
            agentApiLogMapper.updateByPrimaryKeyWithBLOBs(data);
        }
    }

    @Override
    public boolean isExist(String appId, String reqId) {
        return agentApiLogMapper.isExist(appId, reqId) > 0;
    }

    @Override
    public BsAgentApiLogWithBLOBs getDetail(String appId, String reqId) {
        BsAgentApiLogExample example = new BsAgentApiLogExample();
        example.createCriteria().andAppIdEqualTo(appId).andRequestIdEqualTo(reqId);
        List<BsAgentApiLogWithBLOBs> list = agentApiLogMapper.selectByExampleWithBLOBs(example);
        if (!list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }
}
