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.MkmjApprovalUserDO;
import com.zcloud.primeport.persistence.dataobject.MkmjGateDO;
import com.zcloud.primeport.persistence.mapper.MkmjApprovalUserMapper;
import com.zcloud.primeport.persistence.repository.MkmjApprovalUserRepository;
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;

@Service
@RequiredArgsConstructor
public class MkmjApprovalUserRepositoryImpl extends BaseRepositoryImpl<MkmjApprovalUserMapper, MkmjApprovalUserDO> implements MkmjApprovalUserRepository {
    private final MkmjApprovalUserMapper mkmjApprovalUserMapper;

    @Override
    public PageResponse<MkmjApprovalUserDO> 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<MkmjApprovalUserDO> result = mkmjApprovalUserMapper.listPage(page, params,menuPerms);

        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public Integer countByMkmjId(Long mkmjId) {
        QueryWrapper<MkmjApprovalUserDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mkmj_id", mkmjId);
        queryWrapper.eq("delete_enum", "false");
        return Math.toIntExact(mkmjApprovalUserMapper.selectCount(queryWrapper));
    }
}

