package com.sz.admin.monitor.service.impl;

import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.sz.admin.monitor.mapper.ComputeRoomMapper;
import com.sz.admin.monitor.mapper.NvrMapper;
import com.sz.admin.monitor.pojo.po.ComputerRoom;
import com.sz.admin.monitor.pojo.po.ModelContentDO;
import com.sz.admin.monitor.pojo.po.Nvr;
import com.sz.admin.monitor.pojo.po.table.ComputerRoomTableDef;
import com.sz.admin.monitor.pojo.po.table.ModelContentDOTableDef;
import com.sz.admin.monitor.pojo.po.table.NvrTableDef;
import com.sz.admin.monitor.service.ComputerRoomService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: ComputerRoomServiceImpl
 * Package: com.sz.admin.monitor.service.impl
 * Description:
 */
@Service
public class ComputerRoomServiceImpl extends ServiceImpl<ComputeRoomMapper, ComputerRoom> implements ComputerRoomService {
    @Resource
    private ComputeRoomMapper computerRoomMapper;
    @Override
    public List<ComputerRoom> getComputerRoomList(Long substationId) {
        // 构建 EXISTS 子查询
        QueryWrapper queryWrapper = QueryWrapper.create()
            .select(
                ComputerRoomTableDef.COMPUTER_ROOM.ID,
                ComputerRoomTableDef.COMPUTER_ROOM.SUBSTATION_ID,
                ComputerRoomTableDef.COMPUTER_ROOM.NAME,
                ComputerRoomTableDef.COMPUTER_ROOM.DESCRIPTION
            )
            .from(ComputerRoomTableDef.COMPUTER_ROOM)
            .where(ComputerRoomTableDef.COMPUTER_ROOM.SUBSTATION_ID.eq(substationId))
            .and(ComputerRoomTableDef.COMPUTER_ROOM.ID.in(
                QueryWrapper.create()
                    .select(ModelContentDOTableDef.MODEL_CONTENT_DO.ROOM_ID)
                    .from(ModelContentDOTableDef.MODEL_CONTENT_DO)
            ));
        return computerRoomMapper.selectListByQuery(queryWrapper);
    }
}
