|
|
|
@ -0,0 +1,69 @@
|
|
|
|
|
package com.example.api.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.example.api.model.entity.Vehicle; // 导入Vehicle实体类,代表车辆信息
|
|
|
|
|
import com.example.api.repository.VehicleRepository; // 导入VehicleRepository接口,用于访问车辆数据
|
|
|
|
|
import com.example.api.service.VehicleService; // 导入VehicleService接口,定义车辆服务
|
|
|
|
|
import com.example.api.utils.DataTimeUtil; // 导入DataTimeUtil工具类,用于处理日期和时间
|
|
|
|
|
import org.springframework.stereotype.Service; // 导入Service注解,标识服务组件
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; // 注解,用于注入Spring管理的Bean
|
|
|
|
|
import java.util.List; // 导入List类,用于处理列表数据
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 车辆服务实现类,提供车辆相关的业务逻辑。
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class VehicleServiceImpl implements VehicleService {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private VehicleRepository vehicleRepository; // 使用@Resource注解注入VehicleRepository
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存车辆信息。
|
|
|
|
|
* @param vehicle 车辆实体对象,包含车辆的各个属性
|
|
|
|
|
* @return 保存后的车辆实体对象,包含由数据库生成的ID等信息
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Vehicle save(Vehicle vehicle) {
|
|
|
|
|
vehicle.setCreateAt(DataTimeUtil.getNowTimeString()); // 设置车辆的创建时间为当前时间
|
|
|
|
|
return vehicleRepository.save(vehicle); // 调用仓库层方法保存车辆信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新车辆信息。
|
|
|
|
|
* @param vehicle 要更新的车辆实体对象
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void update(Vehicle vehicle) {
|
|
|
|
|
vehicleRepository.save(vehicle); // 调用仓库层方法更新车辆信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据ID删除车辆信息。
|
|
|
|
|
* @param id 要删除的车辆ID
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void delete(String id) {
|
|
|
|
|
vehicleRepository.deleteById(id); // 调用仓库层方法根据ID删除车辆信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据ID查询车辆信息。
|
|
|
|
|
* @param id 要查询的车辆ID
|
|
|
|
|
* @return 查询到的车辆实体对象,如果没有找到则返回null
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Vehicle findById(String id) {
|
|
|
|
|
return vehicleRepository.findById(id).orElse(null); // 调用仓库层方法根据ID查询车辆信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询所有车辆信息。
|
|
|
|
|
* @return 车辆实体对象列表,包含所有车辆的详细信息
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<Vehicle> findAll() {
|
|
|
|
|
return vehicleRepository.findAll(); // 调用仓库层方法查询所有车辆信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|