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.RescueTeamDO;
import com.zcloud.zcGbsServicer.persistence.dataobject.ResourcePersonDO;
import com.zcloud.zcGbsServicer.persistence.mapper.ResourcePersonMapper;
import com.zcloud.zcGbsServicer.persistence.repository.ResourcePersonRepository;
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:34
*/
@Service
@RequiredArgsConstructor
public class ResourcePersonRepositoryImpl extends BaseRepositoryImpl<ResourcePersonMapper, ResourcePersonDO> implements ResourcePersonRepository {
    private final ResourcePersonMapper resourcePersonMapper;

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


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

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

