package com.zcloud.accident.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.auth.utils.AuthContext;
import com.jjb.saas.framework.repository.common.PageHelper;
import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
import com.zcloud.accident.domain.model.AccidentCorpCountStat;
import com.zcloud.accident.domain.model.AccidentCountStat;
import com.zcloud.accident.persistence.dataobject.AccidentDO;
import com.zcloud.accident.persistence.mapper.AccidentMapper;
import com.zcloud.accident.persistence.repository.AccidentRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Query;
import com.zcloud.gbscommon.utils.Tools;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * web-infrastructure
 *
 * @Author fangjiakai
 * @Date 2025-10-29 14:28:49
 */
@Service
@RequiredArgsConstructor
public class AccidentRepositoryImpl extends BaseRepositoryImpl<AccidentMapper, AccidentDO> implements AccidentRepository {
    private final AccidentMapper accidentMapper;

    @Override
    public PageResponse<AccidentDO> listPage(Map<String, Object> params,String menuPerms) {
        if (Tools.isEmpty(params.getOrDefault("eqCorpinfoId",""))) {
            params.put("localCorpId", AuthContext.getTenantId());
        }
        IPage<AccidentDO> iPage = new Query<AccidentDO>().getPage(params);

        IPage<AccidentDO> result = accidentMapper.listPage(iPage, params,menuPerms);
        return PageHelper.pageToResponse(result, result.getRecords());
    }


    @Override
    public List<AccidentDO> listAll(Map<String, Object> params, String menuPerms) {
        return accidentMapper.list(params, menuPerms);
    }

    @Override
    public List<AccidentCorpCountStat> countByCorpinfo(List<String> corpinfoIds) {
        return accidentMapper.countByCorpinfo(corpinfoIds);
    }

    @Override
    public List<AccidentCountStat> countByCorpinfoIdAndIncidentType(List<String> corpinfoIds, Integer eqAccidentType) {
        return accidentMapper.countByCorpinfoIdAndIncidentType(corpinfoIds, eqAccidentType);
    }
}

