package com.zcloud.fire.check.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.fire.check.domain.enums.MenuEnum;
import com.zcloud.fire.check.domain.model.FireCheckStandardE;
import com.zcloud.fire.check.persistence.dataobject.FireCheckStandardDO;
import com.zcloud.fire.check.persistence.dataobject.FireCheckStandardStatisticDO;
import com.zcloud.fire.check.persistence.mapper.FireCheckStandardMapper;
import com.zcloud.fire.check.persistence.repository.FireCheckStandardRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Query;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2025-11-26 10:12:15
 */
@Service
@RequiredArgsConstructor
public class FireCheckStandardRepositoryImpl extends BaseRepositoryImpl<FireCheckStandardMapper, FireCheckStandardDO> implements FireCheckStandardRepository {
    private final FireCheckStandardMapper fireCheckStandardMapper;

    @Override
    public PageResponse<FireCheckStandardDO> listPage(Map<String, Object> params) {
        IPage<FireCheckStandardDO> iPage = new Query<FireCheckStandardDO>().getPage(params);
        String menuPerms = "";
        if (!org.springframework.util.ObjectUtils.isEmpty(params.get("menuPath"))){
            menuPerms = MenuEnum.getMenuKeyByPath(params.get("menuPath").toString());
        }
        IPage<FireCheckStandardDO> result = fireCheckStandardMapper.listPage(iPage, params,menuPerms);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public List<FireCheckStandardDO> listAll(Map<String, Object> params) {
        QueryWrapper<FireCheckStandardDO> queryWrapper = new QueryWrapper<>();
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
        queryWrapper.orderByDesc("create_time");
        return fireCheckStandardMapper.selectList(queryWrapper);
    }
    @Override
    public boolean addBatch(List<FireCheckStandardDO> fireCheckStandardDOList) {
        saveBatch(fireCheckStandardDOList);
        return true;
    }

    @Override
    public List<FireCheckStandardDO> getCheckStandardList(List<String> fireDeviceTypeList) {
        QueryWrapper<FireCheckStandardDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("fire_device_type", fireDeviceTypeList);
        return fireCheckStandardMapper.selectList(queryWrapper);
    }

    @Override
    public List<FireCheckStandardStatisticDO> getDeviceStandardList(String fireCheckId) {
        return fireCheckStandardMapper.getDeviceStandardList(fireCheckId);
    }
}

