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.persistence.dataobject.FireCheckListItemDO;
import com.zcloud.fire.check.persistence.dataobject.FireCheckListItemStatisticDO;
import com.zcloud.fire.check.persistence.mapper.FireCheckListItemMapper;
import com.zcloud.fire.check.persistence.repository.FireCheckListItemRepository;
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-28 10:32:29
 */
@Service
@RequiredArgsConstructor
public class FireCheckListItemRepositoryImpl extends BaseRepositoryImpl<FireCheckListItemMapper, FireCheckListItemDO> implements FireCheckListItemRepository {
    private final FireCheckListItemMapper fireCheckListItemMapper;

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

    @Override
    public List<FireCheckListItemDO> listByFireCheckId(String fireCheckId) {
        QueryWrapper<FireCheckListItemDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("fire_check_id", fireCheckId);
        return fireCheckListItemMapper.selectList(queryWrapper);
    }
    @Override
    public void deleteByFireCheckId(String fireCheckId) {
        QueryWrapper<FireCheckListItemDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("fire_check_id", fireCheckId);
        fireCheckListItemMapper.delete(queryWrapper);
    }

    @Override
    public List<FireCheckListItemStatisticDO> statisticListByFireCheckIdList(List<String> fireCheckIdList) {
        return fireCheckListItemMapper.statisticListByFireCheckIdList(fireCheckIdList);
    }

    @Override
    public Long countByDeviceId(String fireDeviceId) {
        QueryWrapper<FireCheckListItemDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("fire_device_id", fireDeviceId);
        return fireCheckListItemMapper.selectCount(queryWrapper);
    }
}

