package com.zksy.WaterSupply.WaterSourceInfo.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zksy.WaterSupply.WaterSourceInfo.domain.WaterSourceInfo;
import com.zksy.WaterSupply.WaterSourceInfo.mapper.WaterSourceInfoMapper;
import com.zksy.WaterSupply.WaterSourceInfo.service.IWaterSourceInfoService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class WaterSourceInfoServiceImpl extends ServiceImpl<WaterSourceInfoMapper, WaterSourceInfo>
        implements IWaterSourceInfoService {

    @Override
    public IPage<WaterSourceInfo> queryPage(Page<WaterSourceInfo> page,
                                            String sourceId,
                                            String sourceName,
                                            String status,
                                            String unit,
                                            LocalDateTime startTime,
                                            LocalDateTime endTime) {
        List<WaterSourceInfo> list = baseMapper.selectSourceList(sourceId, sourceName, status, unit, startTime, endTime);
        page.setRecords(list);
        page.setTotal(list.size());
        return page;
    }

    @Override
    public IPage<WaterSourceInfo> queryDeletedPage(Page<WaterSourceInfo> page,
                                                   String sourceId,
                                                   String sourceName,
                                                   String status,
                                                   LocalDateTime startTime,
                                                   LocalDateTime endTime) {
        List<WaterSourceInfo> list = baseMapper.selectDeletedList(sourceId, sourceName, status, startTime, endTime);
        page.setRecords(list);
        page.setTotal(list.size());
        return page;
    }

    @Override
    public boolean restoreByIds(List<Long> ids, String updateBy) {
        if (ids == null || ids.isEmpty()) return false;
        return baseMapper.restoreByIds(ids, updateBy) > 0;
    }

    @Override
    public boolean deleteByIdsPhysically(List<Long> ids) {
        if (ids == null || ids.isEmpty()) return false;
        return baseMapper.deleteByIdsPhysically(ids) > 0;
    }
}