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

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jjb.saas.framework.repository.common.PageHelper;
import com.zcloud.zcGbsServicer.persistence.dataobject.ResourceDeviceDO;
import com.zcloud.zcGbsServicer.persistence.mapper.ResourceDeviceMapper;
import com.zcloud.zcGbsServicer.persistence.repository.ResourceDeviceRepository;
import com.alibaba.cola.dto.PageResponse;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
* web-infrastructure
* @Author makejava
* @Date 2026-01-21 17:23:16
*/
@Service
@RequiredArgsConstructor
public class ResourceDeviceRepositoryImpl extends BaseRepositoryImpl<ResourceDeviceMapper, ResourceDeviceDO> implements ResourceDeviceRepository {
    private final ResourceDeviceMapper resourceDeviceMapper;

    @Override
    public  PageResponse<ResourceDeviceDO> listPage(Map<String,Object> params) {
    IPage<ResourceDeviceDO> iPage = new Query<ResourceDeviceDO>().getPage(params);
        QueryWrapper<ResourceDeviceDO> queryWrapper = new QueryWrapper<>();
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
        queryWrapper.orderByDesc("create_time");
        IPage<ResourceDeviceDO> result = resourceDeviceMapper.selectPage(iPage, queryWrapper);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public List<ResourceDeviceDO> listByBizId(List<String> bizIds) {
        if (CollUtil.isEmpty(bizIds)) return null;
        return this.list(new LambdaQueryWrapper<ResourceDeviceDO>()
                .in(ResourceDeviceDO::getBizId, bizIds));
    }

    @Override
    public List<ResourceDeviceDO> listByBizIdAndBizType(List<String> bizIds, Integer bizType) {
        if (CollUtil.isEmpty(bizIds)) return null;
        return this.list(new LambdaQueryWrapper<ResourceDeviceDO>()
                .in(ResourceDeviceDO::getBizId, bizIds)
                .eq(ResourceDeviceDO::getBizType, bizType));
    }
}

