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.repository.repo.impl.BaseRepositoryImpl;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.primeport.domain.enums.MenuEnum;
import com.zcloud.primeport.persistence.dataobject.MkmjDO;
import com.zcloud.primeport.persistence.dataobject.PersonApplyDO;
import com.zcloud.primeport.persistence.mapper.PersonApplyMapper;
import com.zcloud.primeport.persistence.repository.PersonApplyRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.zcloud.gbscommon.utils.Query;
import com.jjb.saas.framework.repository.common.PageHelper;

/**
 * web-infrastructure
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:22
 */
@Service
@RequiredArgsConstructor
public class PersonApplyRepositoryImpl extends BaseRepositoryImpl<PersonApplyMapper, PersonApplyDO> implements PersonApplyRepository {
    private final PersonApplyMapper personApplyMapper;

    @Override
    public PageResponse<PersonApplyDO> 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<PersonApplyDO> iPage = personApplyMapper.listPage(page, params, menuPerms);
        return PageHelper.pageToResponse(iPage, iPage.getRecords());
    }

    @Override
    public PageResponse<PersonApplyDO> xgfPersonPermissionsList(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());
        }
        IPage<PersonApplyDO> result = personApplyMapper.xgfPersonPermissionsList(page, params, menuPerms);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public PageResponse<PersonApplyDO> xgfPersonnelVehicleManagementList(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());
        }
        IPage<PersonApplyDO> result = personApplyMapper.xgfPersonnelVehicleManagementList(page, params, menuPerms);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public PersonApplyDO xgfPersonPermissionsInfo(Long id) {
        return personApplyMapper.xgfPersonPermissionsInfo(id);
    }

    @Override
    public PersonApplyDO getInfoByUserId(Long userId) {
        return personApplyMapper.getInfoByUserId(userId);
    }


}

