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

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2025-11-10 14:13:46
 */
@Service
@RequiredArgsConstructor
public class DepartmentSuperviseRepositoryImpl extends BaseRepositoryImpl<DepartmentSuperviseMapper, DepartmentSuperviseDO> implements DepartmentSuperviseRepository {
    private final DepartmentSuperviseMapper departmentSuperviseMapper;

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

    @Override
    public List<Long> listBySuperviseDepartmentId(Map<String, Object> params) {
        QueryWrapper<DepartmentSuperviseDO> queryWrapper = new QueryWrapper<>();
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
        List<DepartmentSuperviseDO> departmentSuperviseDOS = departmentSuperviseMapper.selectList(queryWrapper);

        return departmentSuperviseDOS.stream().map(DepartmentSuperviseDO::getDepartmentId).collect(Collectors.toList());
    }

}

