package com.zcloud.primeport.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.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.jjb.saas.framework.repository.common.PageHelper;
import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Query;
import com.zcloud.gbscommon.utils.Tools;
import com.zcloud.primeport.domain.enums.MenuEnum;
import com.zcloud.primeport.persistence.dataobject.PersonApplyDO;
import com.zcloud.primeport.persistence.dataobject.PersonCountDto;
import com.zcloud.primeport.persistence.dataobject.VehicleApplyDO;
import com.zcloud.primeport.persistence.dataobject.XgfApplyPersonDO;
import com.zcloud.primeport.persistence.mapper.PersonApplyMapper;
import com.zcloud.primeport.persistence.mapper.XgfApplyPersonMapper;
import com.zcloud.primeport.persistence.repository.PersonApplyRepository;
import com.zcloud.primeport.persistence.repository.XgfApplyPersonRepository;
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-03-05 11:33:22
 */
@Service
@RequiredArgsConstructor
public class XgfApplyPersonRepositoryImpl extends BaseRepositoryImpl<XgfApplyPersonMapper, XgfApplyPersonDO> implements XgfApplyPersonRepository {
    private final XgfApplyPersonMapper xgfApplyPersonMapper;

    @Override
    public PageResponse<XgfApplyPersonDO> xgfPersonAuditList(Map<String, Object> params) {
        Page<Map<String, Object>> page = new Page<>(Integer.parseInt(params.get("pageIndex").toString()), Integer.parseInt(params.get("pageSize").toString()));
        page.setOptimizeJoinOfCountSql(false);
        String menuPerms = "";
        if (!org.springframework.util.ObjectUtils.isEmpty(params.get("menuPath"))) {
            menuPerms = MenuEnum.getMenuKeyByPath(params.get("menuPath").toString());
        }
        IPage<XgfApplyPersonDO> result = xgfApplyPersonMapper.xgfPersonAuditList(page, params,menuPerms);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public PageResponse<PersonCountDto> personnelVehicleManagementList(Map<String, Object> params) {
        Page<Map<String, Object>> page = new Page<>(Integer.parseInt(params.get("pageIndex").toString()), Integer.parseInt(params.get("pageSize").toString()));
        String menuPerms = "";
        if (!org.springframework.util.ObjectUtils.isEmpty(params.get("menuPath"))) {
            menuPerms = MenuEnum.getMenuKeyByPath(params.get("menuPath").toString());
        }
        page.setOptimizeJoinOfCountSql(false);
        IPage<PersonCountDto> result = xgfApplyPersonMapper.personnelVehicleManagementList(page, params,menuPerms);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public PageResponse<XgfApplyPersonDO> listPage(Map<String, Object> params) {
        Page<Map<String, Object>> page = new Page<>(Integer.parseInt(params.get("pageIndex").toString()), Integer.parseInt(params.get("pageSize").toString()));
        String menuPerms = "";
        if (!org.springframework.util.ObjectUtils.isEmpty(params.get("menuPath"))) {
            menuPerms = MenuEnum.getMenuKeyByPath(params.get("menuPath").toString());
        }
        page.setOptimizeJoinOfCountSql(false);
        IPage<XgfApplyPersonDO> result = xgfApplyPersonMapper.listPage(page, params,menuPerms);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public List<XgfApplyPersonDO> listTodayHasPort() {
        return xgfApplyPersonMapper.listTodayHasPort();
    }


}

