|
|
|
@ -0,0 +1,70 @@
|
|
|
|
|
package com.example.api.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.example.api.model.entity.Driver; // 导入Driver实体类,代表司机信息
|
|
|
|
|
import com.example.api.repository.DriverRepository; // 导入DriverRepository接口,用于访问司机数据
|
|
|
|
|
import com.example.api.service.DriverService; // 导入DriverService接口,定义司机服务
|
|
|
|
|
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 DriverServiceImpl implements DriverService {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private DriverRepository driverRepository; // 使用@Resource注解注入DriverRepository
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存司机信息。
|
|
|
|
|
* @param driver 司机实体对象,包含司机的各个属性
|
|
|
|
|
* @return 保存后的司机实体对象,包含由数据库生成的ID等信息
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Driver save(Driver driver) {
|
|
|
|
|
driver.setCreateAt(DataTimeUtil.getNowTimeString()); // 设置司机的创建时间为当前时间
|
|
|
|
|
return driverRepository.save(driver); // 调用仓库层方法保存司机信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新司机信息。
|
|
|
|
|
* @param driver 要更新的司机实体对象
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void update(Driver driver) {
|
|
|
|
|
driver.setUpdateAt(DataTimeUtil.getNowTimeString()); // 设置司机的更新时间为当前时间
|
|
|
|
|
driverRepository.save(driver); // 调用仓库层方法更新司机信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据ID删除司机信息。
|
|
|
|
|
* @param id 要删除的司机ID
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void delete(String id) {
|
|
|
|
|
driverRepository.deleteById(id); // 调用仓库层方法根据ID删除司机信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据ID查询司机信息。
|
|
|
|
|
* @param id 要查询的司机ID
|
|
|
|
|
* @return 查询到的司机实体对象,如果没有找到则返回null
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Driver findById(String id) {
|
|
|
|
|
return driverRepository.findById(id).orElse(null); // 调用仓库层方法根据ID查询司机信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询所有司机信息。
|
|
|
|
|
* @return 司机实体对象列表,包含所有司机的详细信息
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<Driver> findAll() {
|
|
|
|
|
return driverRepository.findAll(); // 调用仓库层方法查询所有司机信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|