package com.zksy.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zksy.base.domain.PipeRepairRecord;
import com.zksy.base.dto.RepairRecordPageInDTO;
import com.zksy.base.mapper.PipeRepairRecordMapper;
import com.zksy.base.service.PipeRepairRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class PipeRepairRecordServiceImpl extends ServiceImpl<PipeRepairRecordMapper, PipeRepairRecord>
        implements PipeRepairRecordService {

    @Override
    public Page<PipeRepairRecord> findByPage(RepairRecordPageInDTO dto) {
        Page<PipeRepairRecord> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        LambdaQueryWrapper<PipeRepairRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(dto.getNetworkId() != null && !dto.getNetworkId().isEmpty(), PipeRepairRecord::getNetworkId, dto.getNetworkId());
        wrapper.eq(dto.getRepairType() != null && !dto.getRepairType().isEmpty(), PipeRepairRecord::getRepairType, dto.getRepairType());
        wrapper.orderByDesc(PipeRepairRecord::getRepairDate);
        return this.page(page, wrapper);
    }

    @Override
    public List<PipeRepairRecord> listByNetworkId(String networkId) {
        LambdaQueryWrapper<PipeRepairRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PipeRepairRecord::getNetworkId, networkId);
        wrapper.orderByDesc(PipeRepairRecord::getRepairDate);
        return this.list(wrapper);
    }
}
