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.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.MkmjDO;
import com.zcloud.primeport.persistence.dataobject.VehicleViolationsDO;
import com.zcloud.primeport.persistence.mapper.VehicleViolationsMapper;
import com.zcloud.primeport.persistence.repository.VehicleViolationsRepository;
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:29
 */
@Service
@RequiredArgsConstructor
public class VehicleViolationsRepositoryImpl extends BaseRepositoryImpl<VehicleViolationsMapper, VehicleViolationsDO> implements VehicleViolationsRepository {
    private final VehicleViolationsMapper vehicleViolationsMapper;

    @Override
    public PageResponse<VehicleViolationsDO> listPage(Map<String, Object> params) {
        IPage<VehicleViolationsDO> iPage = new Query<VehicleViolationsDO>().getPage(params);
        QueryWrapper<VehicleViolationsDO> queryWrapper = new QueryWrapper<>();
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
        queryWrapper.eq(!Tools.isEmpty(params.get("violationType")),"violation_type",params.get("violationType"));
        queryWrapper.eq("licence_no",params.get("licenceNo"));
        queryWrapper.orderByDesc("create_time");
        IPage<VehicleViolationsDO> result = vehicleViolationsMapper.selectPage(iPage, queryWrapper);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public PageResponse<VehicleViolationsDO> violationRecordslistPage(Map<String, Object> params) {
        Page<Map<String, Object>> page = new Page<>(Integer.parseInt(params.get("pageIndex").toString()), Integer.parseInt(params.get("pageSize").toString()));

        IPage<VehicleViolationsDO> iPage = vehicleViolationsMapper.violationRecordslistPage(page, params);
        return PageHelper.pageToResponse(iPage, iPage.getRecords());
    }

    @Override
    public List<VehicleViolationsDO> listVehicleViolationByLicenceNo(String licenceNo) {
        return vehicleViolationsMapper.listVehicleViolationByLicenceNo(licenceNo);
    }
}

