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.CorpFormDO;
import com.zcloud.basic.info.persistence.mapper.CorpFormMapper;
import com.zcloud.basic.info.persistence.repository.CorpFormRepository;
import com.zcloud.basic.info.utils.Query;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2025-10-29 16:02:27
 */
@Service
@RequiredArgsConstructor
public class CorpFormRepositoryImpl extends BaseRepositoryImpl<CorpFormMapper, CorpFormDO> implements CorpFormRepository {
    private final CorpFormMapper corpFormMapper;

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

    @Override
    public List<CorpFormDO> getInfoByType(Long id, Integer type) {
        QueryWrapper<CorpFormDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("info_id", id);
        queryWrapper.eq("type", type);
        queryWrapper.orderByAsc("item_order");
        List<CorpFormDO> corpFormDOS = corpFormMapper.selectList(queryWrapper);
        return corpFormDOS;
    }

    @Override
    public List<CorpFormDO> getInfoByTypeList(Long corpInfoId, List<Integer> typeList) {
        List<CorpFormDO> corpFormDOList = corpFormMapper.selectListByType(corpInfoId,typeList);
        return corpFormDOList;
    }

    @Override
    public List<CorpFormDO> getCorpListByTypeList(List<Long> corpInfoIdList, List<Integer> typeList) {
        List<CorpFormDO> corpFormDOList = corpFormMapper.getCorpListByTypeList(corpInfoIdList,typeList);
        return corpFormDOList;
    }

    @Override
    public void addBatch(List<CorpFormDO> filteredList) {
        this.saveBatch(filteredList);
    }
}

