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

import com.zcloud.personnel.positioning.persistence.dataobject.AlarmRuleDO;
import com.zcloud.personnel.positioning.persistence.dataobject.AlarmRuleCompanyStatDO;
import com.zcloud.personnel.positioning.persistence.dataobject.CompanyOptionDO;
import com.zcloud.personnel.positioning.persistence.mapper.AlarmRuleMapper;
import com.zcloud.personnel.positioning.persistence.repository.AlarmRuleRepository;
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.Map;
import java.util.List;

/**
 * web-infrastructure
 *
 * @Author fangjiakai
 * @Date 2026-07-07
 */
@Service
@RequiredArgsConstructor
public class AlarmRuleRepositoryImpl extends BaseRepositoryImpl<AlarmRuleMapper, AlarmRuleDO> implements AlarmRuleRepository {
    private final AlarmRuleMapper alarmRuleMapper;

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

    @Override
    public PageResponse<AlarmRuleCompanyStatDO> listCompanyStats(Map<String, Object> params) {
        IPage<AlarmRuleCompanyStatDO> page = new Query<AlarmRuleCompanyStatDO>().getPage(params);
        IPage<AlarmRuleCompanyStatDO> result = alarmRuleMapper.listCompanyStats(page, params);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public List<CompanyOptionDO> listCompanyOptions(Map<String, Object> params) {
        return alarmRuleMapper.listCompanyOptions(params);
    }
}
