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.FireCheckPointListDO;
import com.zcloud.fire.check.persistence.dataobject.FireCheckRecordDO;
import com.zcloud.fire.check.persistence.dataobject.FireCheckRecordPointDO;
import com.zcloud.fire.check.persistence.mapper.FireCheckRecordPointMapper;
import com.zcloud.fire.check.persistence.repository.FireCheckRecordPointRepository;
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:20
 */
@Service
@RequiredArgsConstructor
public class FireCheckRecordPointRepositoryImpl extends BaseRepositoryImpl<FireCheckRecordPointMapper, FireCheckRecordPointDO> implements FireCheckRecordPointRepository {
    private final FireCheckRecordPointMapper fireCheckRecordPointMapper;

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

    @Override
    public List<FireCheckRecordPointDO> getInfoByFireCheckRecordId(String fireCheckId) {
        QueryWrapper<FireCheckRecordPointDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("fire_record_id", fireCheckId);
        queryWrapper.eq("checked_flag", FireCheckRecordPointCheckedFlagEnum.CHECKED.getCode());

        queryWrapper.orderByDesc("create_time");
        List<FireCheckRecordPointDO> fireCheckRecordPointDOS = fireCheckRecordPointMapper.selectList(queryWrapper);
        return fireCheckRecordPointDOS;
    }
    @Override
    public List<FireCheckRecordPointDO> getCheckRecordPointList(Map<String, Object> params) {
        List<FireCheckRecordPointDO> result = fireCheckRecordPointMapper.getCheckRecordPointList(params);
        return result;
    }

    @Override
    public void updateCheckFlag(FireCheckRecordPointDO pointInfo) {
        QueryWrapper<FireCheckRecordPointDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("fire_record_point_id", pointInfo.getFireRecordPointId());

        fireCheckRecordPointMapper.update(pointInfo, queryWrapper);
    }

    @Override
    public List<String> getLastThreeRecord(String firePointId) {
        return fireCheckRecordPointMapper.getLastThreeRecord(firePointId);
    }

    @Override
    public List<FireCheckRecordPointDO> getCheckRecordPointListByCheckRecordIds(List<String> fireCheckRecordIdList) {
        return fireCheckRecordPointMapper.getCheckRecordPointListByCheckRecordIds(fireCheckRecordIdList);
    }
}

