package com.zksy.WaterSupply.WaterPlantInfo.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.WaterPlantInfo.domain.WaterPlantInfo;
import com.zksy.WaterSupply.WaterPlantInfo.mapper.WaterPlantInfoMapper;
import com.zksy.WaterSupply.WaterPlantInfo.service.IWaterPlantInfoService;
import org.springframework.stereotype.Service;

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

@Service
public class WaterPlantInfoServiceImpl extends ServiceImpl<WaterPlantInfoMapper, WaterPlantInfo>
        implements IWaterPlantInfoService {

    @Override
    public IPage<WaterPlantInfo> queryPage(Page<WaterPlantInfo> page,
                                           String plantCode,
                                           String plantName,
                                           String status,
                                           String principal,
                                           LocalDateTime startTime,
                                           LocalDateTime endTime) {
        List<WaterPlantInfo> list = baseMapper.selectPlantList(plantCode, plantName, status, principal, startTime, endTime);
        page.setRecords(list);
        page.setTotal(list.size());
        return page;
    }

    @Override
    public IPage<WaterPlantInfo> queryDeletedPage(Page<WaterPlantInfo> page,
                                                  String plantCode,
                                                  String plantName,
                                                  String status,
                                                  LocalDateTime startTime,
                                                  LocalDateTime endTime) {
        List<WaterPlantInfo> list = baseMapper.selectDeletedList(plantCode, plantName, 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;
    }
}