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.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.persistence.dataobject.MkmjSwipeCardRecordDO;
import com.zcloud.primeport.persistence.mapper.MkmjSwipeCardRecordMapper;
import com.zcloud.primeport.persistence.repository.MkmjSwipeCardRecordRepository;
import jodd.util.Base64;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * web-infrastructure
 *
 * @Author dearLin
 * @Date 2026-04-22 17:04:01
 */
@Service
@RequiredArgsConstructor
public class MkmjSwipeCardRecordRepositoryImpl extends BaseRepositoryImpl<MkmjSwipeCardRecordMapper, MkmjSwipeCardRecordDO> implements MkmjSwipeCardRecordRepository {
    private final MkmjSwipeCardRecordMapper mkmjSwipeCardRecordMapper;

    @Override
    public PageResponse<MkmjSwipeCardRecordDO> listPage(Map<String, Object> params) {
        IPage<MkmjSwipeCardRecordDO> iPage = new Query<MkmjSwipeCardRecordDO>().getPage(params);
        QueryWrapper<MkmjSwipeCardRecordDO> queryWrapper = new QueryWrapper<>();
        if (params.get("likeId") != null) {
            queryWrapper.eq("id", params.get("likeId"));
        }
        if (params.get("cardNo") != null) {
//            queryWrapper.eq("paper_number", Base64.decodeToString(String.valueOf(params.get("cardNo"))));
            queryWrapper.eq("paper_number", params.get("cardNo"));
        }
        if (params.get("likeDeviceName") != null) {
            queryWrapper.like("device_name", params.get("likeDeviceName"));
        }
        if (params.get("swingTimeStart") != null) {
            queryWrapper.ge("swing_time", params.get("swingTimeStart"));
        }
        if (params.get("swingTimeEnd") != null) {
            queryWrapper.le("swing_time", params.get("swingTimeEnd"));
        }
        queryWrapper.orderByDesc("swing_time");
        IPage<MkmjSwipeCardRecordDO> result = mkmjSwipeCardRecordMapper.selectPage(iPage, queryWrapper);
        return PageHelper.pageToResponse(result, result.getRecords());
    }
}

