package com.zcloud.primeport.persistence.repository.impl;

import com.alibaba.cola.dto.MultiResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcloud.primeport.domain.enums.MenuEnum;
import com.zcloud.primeport.persistence.dataobject.ClosedAreaPersonApplyDO;
import com.zcloud.primeport.persistence.dataobject.ClosedAreaPersonApplyDeptDO;
import com.zcloud.primeport.persistence.dataobject.MkmjApprovalUserDO;
import com.zcloud.primeport.persistence.dataobject.UserDto;
import com.zcloud.primeport.persistence.mapper.ClosedAreaPersonApplyMapper;
import com.zcloud.primeport.persistence.repository.ClosedAreaPersonApplyRepository;
import com.alibaba.cola.dto.PageResponse;
import com.jjb.saas.framework.repository.common.PageHelper;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
import com.zcloud.primeport.plan.mjDevice.TwoPersonUtil;
import com.zcloud.primeport.plan.mjDevice.dto.TwoLevelUser;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * web-infrastructure
 *
 * @Author dearLin
 * @Date 2026-03-19 13:59:16
 */
@Service
@RequiredArgsConstructor
public class ClosedAreaPersonApplyRepositoryImpl extends BaseRepositoryImpl<ClosedAreaPersonApplyMapper, ClosedAreaPersonApplyDO> implements ClosedAreaPersonApplyRepository {
    private final ClosedAreaPersonApplyMapper closedAreaPersonApplyMapper;

    @Override
    public PageResponse<ClosedAreaPersonApplyDO> 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 = "";
        page.setOptimizeJoinOfCountSql(false);

        if (!org.springframework.util.ObjectUtils.isEmpty(params.get("menuPath"))) {
            menuPerms = MenuEnum.getMenuKeyByPath(params.get("menuPath").toString());
        }
        IPage<ClosedAreaPersonApplyDO> result = closedAreaPersonApplyMapper.listPage(page, params,menuPerms);
        return PageHelper.pageToResponse(result, result.getRecords());
    }


    @Override
    public List <ClosedAreaPersonApplyDeptDO> deptList() {

        return closedAreaPersonApplyMapper.deptList();
    }

    @Override
    public PageResponse<UserDto> getCorpUserList(Map<String, Object> params) {
        IPage<ClosedAreaPersonApplyDO> iPage = new Query<ClosedAreaPersonApplyDO>().getPage(params);
        IPage<UserDto> result = closedAreaPersonApplyMapper.getCorpUserList(iPage, params);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public List<TwoLevelUser> getDockAuthInfoById(Long applyId) {
        return closedAreaPersonApplyMapper.getDockAuthInfoById(applyId);
    }

    @Override
    public List<TwoLevelUser> getDockAuthTmpInfoById(Long applyId) {
        return closedAreaPersonApplyMapper.getDockAuthTmpInfoById(applyId);
    }
}

