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.FireCheckRecordPointCheckedFlagEnum;
import com.zcloud.fire.check.persistence.dataobject.FireCheckRecordDeviceDO;
import com.zcloud.fire.check.persistence.mapper.FireCheckRecordDeviceMapper;
import com.zcloud.fire.check.persistence.repository.FireCheckRecordDeviceRepository;
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-12-12 11:10:03
 */
@Service
@RequiredArgsConstructor
public class FireCheckRecordDeviceRepositoryImpl extends BaseRepositoryImpl<FireCheckRecordDeviceMapper, FireCheckRecordDeviceDO> implements FireCheckRecordDeviceRepository {
    private final FireCheckRecordDeviceMapper fireCheckRecordDeviceMapper;

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

    @Override
    public List<FireCheckRecordDeviceDO> getBackChecKRecordPoiList(List<String> idList,Integer checkedFlag) {
        QueryWrapper<FireCheckRecordDeviceDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("fire_record_point_id", idList);
        if(checkedFlag!=null){
            queryWrapper.eq("checked_flag", checkedFlag);

        }
        return fireCheckRecordDeviceMapper.selectList(queryWrapper);
    }

    @Override
    public List<FireCheckRecordDeviceDO> getCheckRecordDeviceList(String fireRecordId) {
        QueryWrapper<FireCheckRecordDeviceDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("fire_record_id", fireRecordId);
        queryWrapper.orderByDesc("create_time");
        return fireCheckRecordDeviceMapper.selectList(queryWrapper);
    }

    @Override
    public void updateNormalNull(Long id) {
        fireCheckRecordDeviceMapper.updateNormalNull(id);
    }

    @Override
    public List<FireCheckRecordDeviceDO> getCheckRecordDeviceListByRecordIdList(List<String> fireRecordIdList) {
        QueryWrapper<FireCheckRecordDeviceDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("fire_record_id", fireRecordIdList);
        queryWrapper.orderByDesc("create_time");
        return fireCheckRecordDeviceMapper.selectList(queryWrapper);
    }
}

