package com.zcloud.zcGbsServicer.persistence.repository.impl;

import com.alibaba.cola.dto.PageResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jjb.saas.framework.repository.common.PageHelper;
import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Query;
import com.zcloud.zcGbsServicer.persistence.dataobject.ControlRoomDO;
import com.zcloud.zcGbsServicer.persistence.mapper.ControlRoomMapper;
import com.zcloud.zcGbsServicer.persistence.repository.ControlRoomRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
* web-infrastructure
* @Author makejava
* @Date 2026-01-21 17:21:50
*/
@Service
@RequiredArgsConstructor
public class ControlRoomRepositoryImpl extends BaseRepositoryImpl<ControlRoomMapper, ControlRoomDO> implements ControlRoomRepository {
    private final ControlRoomMapper controlRoomMapper;

    @Override
    public PageResponse<ControlRoomDO> listPage(Map<String, Object> params) {
        IPage<ControlRoomDO> iPage = new Query<ControlRoomDO>().getPage(params);
        QueryWrapper<ControlRoomDO> queryWrapper = new QueryWrapper<>();
        Object corpId = params == null ? null : params.remove("eqCorpId");
        String menuPerms = params == null ? null : (String) params.remove("menuPerms");
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
        if (corpId != null) {
            queryWrapper.eq("tenant_id", corpId);
        }
        IPage<ControlRoomDO> result = controlRoomMapper.selectPageSql(iPage, queryWrapper, menuPerms);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public PageResponse<ControlRoomDO> listScreen(IPage<ControlRoomDO> page, Map<String, Object> params) {
        IPage<ControlRoomDO> result = controlRoomMapper.selectScreenList(page, params);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public ControlRoomDO getById(Long id) {
        return controlRoomMapper.selectById(id);
    }
}
