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.gbscommon.utils.Tools;
import com.zcloud.primeport.domain.enums.MenuEnum;
import com.zcloud.primeport.persistence.dataobject.PersonMessageDO;
import com.zcloud.primeport.persistence.dataobject.VehicleAuditDO;
import com.zcloud.primeport.persistence.mapper.VehicleAuditMapper;
import com.zcloud.primeport.persistence.repository.VehicleAuditRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.zcloud.gbscommon.utils.Query;
import com.jjb.saas.framework.repository.common.PageHelper;


import java.util.Map;

/**
 * web-infrastructure
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:25
 */
@Service
@RequiredArgsConstructor
public class VehicleAuditRepositoryImpl extends BaseRepositoryImpl<VehicleAuditMapper, VehicleAuditDO> implements VehicleAuditRepository {
    private final VehicleAuditMapper vehicleAuditMapper;

    @Override
    public PageResponse<VehicleAuditDO> 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());
        }
        if (!Tools.isEmpty(params.get("gateLevelAuthAreaId"))) {
            params.put("gateLevelAuthAreaIdList",params.get("gateLevelAuthAreaId").toString().split(","));
        }
        if (!Tools.isEmpty(params.get("vehicleBelongTypeArr"))) {
            params.put("vehicleBelongTypeArrList",params.get("vehicleBelongTypeArr").toString().split(","));
        }
        page.setOptimizeJoinOfCountSql(false);

        IPage<VehicleAuditDO> result = vehicleAuditMapper.listPage(page, params, menuPerms);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public PageResponse<VehicleAuditDO> carApprovalLogByvehicleApplyIdList(Map<String, Object> params) {
        Page<Map<String, Object>> page = new Page<>(Integer.parseInt(params.get("pageIndex").toString()),
                Integer.parseInt(params.get("pageSize").toString()));
        IPage<VehicleAuditDO> result = vehicleAuditMapper.carApprovalLogByvehicleApplyIdList(page, params);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

}

