package com.zcloud.personnel.positioning.persistence.repository.impl;

import com.zcloud.personnel.positioning.persistence.dataobject.AreaDO;
import com.zcloud.personnel.positioning.persistence.mapper.AreaMapper;
import com.zcloud.personnel.positioning.persistence.repository.AreaRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Query;
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 lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * web-infrastructure
 *
 * @Author fangjiakai
 * @Date 2026-07-07
 */
@Service
@RequiredArgsConstructor
public class AreaRepositoryImpl extends BaseRepositoryImpl<AreaMapper, AreaDO> implements AreaRepository {
    private final AreaMapper areaMapper;

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

    @Override
    public List<AreaDO> listBiPersonPositionAreas(String corpinfoId) {
        return areaMapper.selectBiPersonPositionAreas(corpinfoId);
    }
}
