package com.pqs9300.serviceimpl.transaction;

import com.njcn.utils.PubUtils;
import com.pqs9300.mapper.transaction.OverRunLogMapper;
import com.pqs9300.mapper.transaction.SuperviseMapper;
import com.pqs9300.pojo.transaction.OverRunLogDetail;
import com.pqs9300.pojo.transaction.Supervise;
import com.pqs9300.pojo.transaction.TransactionData;
import com.pqs9300.service.transaction.OverRunLogService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

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

/**
 * @author hongawen
 * @date: 2020/7/1 11:41
 */
@Service
public class OverRunLogServiceImpl implements OverRunLogService {

    @Resource
    private SuperviseMapper superviseMapper;

    @Resource
    private OverRunLogMapper overRunLogMapper;

    /**
     *
     * @param supIndex 事务索引
     *
     * 首先查询出当前事务，显示url的内容。
     *
     */
    @Override
    public TransactionData getMonitorDetailData(String supIndex) throws Exception {
        TransactionData transactionData=new TransactionData();
        Supervise supervise = new Supervise();
        supervise.setSupIndex(supIndex);
        supervise=superviseMapper.selectOne(supervise);
        if(null==supervise){
            return null;
        }
        transactionData.setName(supervise.getName());
        transactionData.setCreateTime(PubUtils.date2String(supervise.getCreateTime(),"yyyy年MM月dd日"));
        //获取详细信息
        List<OverRunLogDetail> overRunLogList=overRunLogMapper.getMonitorDetailData(supIndex);
        if(!CollectionUtils.isEmpty(overRunLogList)){
            transactionData.setOverRunLogList(overRunLogList);
        }
        return transactionData;
    }
}
