EventServiceImpl.java 1.51 KB
package vion.service.impl.monitor;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.lang.Assert;
import org.springframework.stereotype.Service;
import vion.dto.monitor.EventDTO;
import vion.mapper.monitor.EventMapper;
import vion.model.monitor.Event;
import vion.model.monitor.RAgentEvent;
import vion.service.monitor.IEventService;
import vion.vo.monitor.EventVO;

/**
 * @author vion
 * @date 2024/10/31
 */
@Service
@RequiredArgsConstructor
public class EventServiceImpl extends MPJBaseServiceImpl<EventMapper, Event> implements IEventService {

    private final Converter converter;

    @Override
    public Page<EventVO> list(EventDTO dto) {
        Assert.notNull(dto.getAgentUid(), "agentUid 不能为空");
        Assert.notNull(dto.getMallUid(), "mallUid 不能为空");
        var wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Event.class))
                .selectAs(Event::getName, EventVO::getName)
                .selectAs(Event::getUid, EventVO::getUid)
                .selectAsClass(RAgentEvent.class, EventVO.class)
                .leftJoin(RAgentEvent.class, RAgentEvent::getEventUid, Event::getUid)
                .orderByDesc(RAgentEvent::getUpdateTime);
        return this.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), EventVO.class, wrapper);
    }
}