package com.tykj.dev.device.repair.service.impl;

import com.tykj.dev.device.repair.repository.RepairBackBillDao;
import com.tykj.dev.device.repair.service.RepairBackBillService;
import com.tykj.dev.device.repair.subject.domin.RepairBackBill;
import com.tykj.dev.misc.exception.ApiException;
import com.tykj.dev.misc.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author zjm
 * @version 1.0.0
 * @ClassName DeviceRepairBackBillServiceImpl.java
 * @Description TODO
 * @createTime 2020年08月25日 10:36:00
 */
@Service
public class RepairBackBillServiceImpl implements RepairBackBillService {
    @Autowired
    RepairBackBillDao deviceRepairBackBillDao;
    @Override
    public RepairBackBill save(RepairBackBill deviceRepairBackBillEntity) {
        return deviceRepairBackBillDao.save(deviceRepairBackBillEntity);
    }

    @Override
    public boolean delete(Integer id) {
        return false;
    }

    @Override
    public List<RepairBackBill> findAll() {
        return deviceRepairBackBillDao.findAll();
    }

    @Override
    public RepairBackBill update(RepairBackBill deviceRepairBackBillEntity) {
        return deviceRepairBackBillDao.save(deviceRepairBackBillEntity);
    }

    @Override
    public RepairBackBill getOne(Integer id) {
        Optional<RepairBackBill> repairBackBill = deviceRepairBackBillDao.findById(id);
        if (repairBackBill.isPresent()){
            return repairBackBill.get();
        }
        else{
            throw new ApiException(ResultUtil.failed("所查询的Id不存在"));
        }
    }
}
