package com.zcloud.basic.info.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.basic.info.persistence.dataobject.CorpQualificationInfoDO;
import com.zcloud.basic.info.persistence.mapper.CorpQualificationInfoMapper;
import com.zcloud.basic.info.persistence.repository.CorpQualificationInfoRepository;
import com.zcloud.basic.info.utils.Query;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Tools;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2025-10-29 16:02:46
 */
@Service
@RequiredArgsConstructor
public class CorpQualificationInfoRepositoryImpl extends BaseRepositoryImpl<CorpQualificationInfoMapper, CorpQualificationInfoDO> implements CorpQualificationInfoRepository {
    private final CorpQualificationInfoMapper corpQualificationInfoMapper;

    @Override
    public PageResponse<CorpQualificationInfoDO> listPage(Map<String, Object> parmas) {
        Object keyWords = parmas.get("keyWords");
        IPage<CorpQualificationInfoDO> iPage = new Query<CorpQualificationInfoDO>().getPage(parmas);
        QueryWrapper<CorpQualificationInfoDO> queryWrapper = new QueryWrapper<>();
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, parmas);
        if (keyWords != null && !Tools.isEmpty(keyWords.toString())) {
            queryWrapper.and(i -> i.like("qualification_name", keyWords).or().like("certificate_no", keyWords));
        }
        queryWrapper.orderByDesc("create_time");
        IPage<CorpQualificationInfoDO> result = corpQualificationInfoMapper.selectPage(iPage, queryWrapper);
        return PageHelper.pageToResponse(result, result.getRecords());
    }
}

