package com.repair.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.repair.mapper.RepairPayRecordMapper;
import com.repair.model.enumModel.ePayStatu;
import com.repair.model.pojo.RepairPayRecord;
import com.repair.model.result.PageUtils;
import com.repair.model.vo.MyRepairRecordVo;
import com.repair.model.vo.ProsperityRepairPayRecordsVo;
import com.repair.model.vo.QueryExportVo;
import com.repair.model.vo.RepairTechnicianVo;
import com.repair.services.RepairPayRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2023-07-20
 */
@Service
public class RepairPayRecordServiceImpl extends ServiceImpl<RepairPayRecordMapper, RepairPayRecord> implements RepairPayRecordService {

    @Autowired
    private RepairPayRecordMapper repairPayRecordMapper;

    @Override
    public int insertRepairPayRecord(RepairPayRecord rpr) {
        int result = repairPayRecordMapper.insert(rpr);
        return result;
    }

    @Override
    public int updateRepairPayRecord(RepairPayRecord rpr) {
        int result = repairPayRecordMapper.updateById(rpr);
        return result;
    }

    @Override
    public PageUtils<RepairPayRecord> queryPageRepairPayRecords(int currentPage, int pageCount) {
        Page<RepairPayRecord> page = new Page<>(currentPage, pageCount);
        QueryWrapper<RepairPayRecord> queryWrapper = new QueryWrapper<>();
        IPage<RepairPayRecord> result = repairPayRecordMapper.selectPage(page, queryWrapper);
        return new PageUtils(result);
    }

    @Override
    public PageUtils<ProsperityRepairPayRecordsVo> queryPayPage(int currentPage, int pageCount, String keyWord, String startTime, String endTime) {
        Page<ProsperityRepairPayRecordsVo> page = new Page<>();
        page.setCurrent(currentPage);
        page.setSize(pageCount);
        IPage<ProsperityRepairPayRecordsVo> result = repairPayRecordMapper.queryPayPage(page, keyWord, startTime, endTime);
        return new PageUtils(result);
    }



    @Override
    public int deleteRepairPayRecordById(int id) {
        int result = repairPayRecordMapper.deleteById(id);
        return result;
    }

    @Override
    public RepairPayRecord getRepairById(int id) {
        RepairPayRecord result = repairPayRecordMapper.selectById(id);
        return result;
    }

    @Override
    public List<RepairPayRecord> getRepairs() {
        List<RepairPayRecord> result = repairPayRecordMapper.selectList(null);
        return result;
    }

    @Override
    public RepairPayRecord getRepairPaySuccessByRecordId(int recordId) {
        QueryWrapper<RepairPayRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_id", recordId);
        queryWrapper.eq("is_success", ePayStatu.Paysuccess.getValue());
        RepairPayRecord result = repairPayRecordMapper.selectOne(queryWrapper);
        return result;
    }

    @Override
    public RepairPayRecord getRepairPayByRecordId(int recordId) {
        QueryWrapper<RepairPayRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_id", recordId);
        RepairPayRecord result = repairPayRecordMapper.selectOne(queryWrapper);
        return result;
    }

    @Override
    public RepairPayRecord queryPaymentData(String recordNo) {
        RepairPayRecord result = repairPayRecordMapper.queryPaymentData(recordNo);
        return result;
    }

    @Override
    public List<QueryExportVo> queryExport(String keyWord, String startTime, String endTime) {

        List<QueryExportVo> vos=repairPayRecordMapper.queryExport(keyWord,startTime,endTime);
        return vos;
    }
}
