package com.zcloud.personnel.positioning.persistence.repository.impl;

import com.zcloud.personnel.positioning.persistence.dataobject.AlarmTypeStatDO;
import com.zcloud.personnel.positioning.persistence.dataobject.AlarmRecordDO;
import com.zcloud.personnel.positioning.persistence.mapper.AlarmRecordMapper;
import com.zcloud.personnel.positioning.persistence.repository.AlarmRecordRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Query;
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 lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * web-infrastructure
 *
 * @Author fangjiakai
 * @Date 2026-07-07
 */
@Service
@RequiredArgsConstructor
public class AlarmRecordRepositoryImpl extends BaseRepositoryImpl<AlarmRecordMapper, AlarmRecordDO> implements AlarmRecordRepository {
    private final AlarmRecordMapper alarmRecordMapper;

    @Override
    public PageResponse<AlarmRecordDO> listPage(Map<String, Object> params) {
        IPage<AlarmRecordDO> iPage = new Query<AlarmRecordDO>().getPage(params);
        QueryWrapper<AlarmRecordDO> queryWrapper = new QueryWrapper<>();
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
        queryWrapper.orderByDesc("start_time", "create_time");
        IPage<AlarmRecordDO> result = alarmRecordMapper.selectPage(iPage, queryWrapper);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public List<AlarmRecordDO> listBiAlarm(String corpinfoId, Integer portArea) {
        return alarmRecordMapper.selectBiAlarmList(corpinfoId, portArea);
    }

    @Override
    public List<AlarmTypeStatDO> listBiAlarmType(String corpinfoId) {
        return alarmRecordMapper.selectBiAlarmTypeList(corpinfoId);
    }
}
