|
|
|
@ -0,0 +1,61 @@
|
|
|
|
|
package com.example.api.controller;
|
|
|
|
|
|
|
|
|
|
import com.example.api.annotation.Log; // 导入自定义的日志注解
|
|
|
|
|
import com.example.api.model.entity.Distribution; // 导入配送实体类
|
|
|
|
|
import com.example.api.model.enums.BusinessType; // 导入业务类型枚举
|
|
|
|
|
import com.example.api.repository.DriverRepository; // 导入司机数据访问层接口
|
|
|
|
|
import com.example.api.repository.VehicleRepository; // 导入车辆数据访问层接口
|
|
|
|
|
import com.example.api.service.DistributionService; // 导入配送服务类
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; // 导入资源注入注解
|
|
|
|
|
import java.util.HashMap; // 导入HashMap类
|
|
|
|
|
import java.util.List; // 导入List接口
|
|
|
|
|
import java.util.Map; // 导入Map接口
|
|
|
|
|
|
|
|
|
|
// 定义RestController注解,表示该类是一个控制器,用于处理HTTP请求
|
|
|
|
|
@RestController
|
|
|
|
|
// 定义RequestMapping注解,设置该控制器的基础URL路径
|
|
|
|
|
@RequestMapping("/api/distribution")
|
|
|
|
|
public class DistributionController {
|
|
|
|
|
|
|
|
|
|
// 通过@Resource注解自动注入DistributionService
|
|
|
|
|
@Resource
|
|
|
|
|
private DistributionService distributionService;
|
|
|
|
|
|
|
|
|
|
// 通过@Resource注解自动注入DriverRepository
|
|
|
|
|
@Resource
|
|
|
|
|
private DriverRepository driverRepository;
|
|
|
|
|
|
|
|
|
|
// 通过@Resource注解自动注入VehicleRepository
|
|
|
|
|
@Resource
|
|
|
|
|
private VehicleRepository vehicleRepository;
|
|
|
|
|
|
|
|
|
|
// 使用@Log注解记录操作日志,模块为“配送管理”,操作类型为插入(BusinessType.INSERT)
|
|
|
|
|
@Log(module = "配送管理", type = BusinessType.INSERT)
|
|
|
|
|
// 处理POST请求,用于保存配送信息
|
|
|
|
|
@PostMapping("")
|
|
|
|
|
public Distribution save(@RequestBody Distribution distribution) throws Exception {
|
|
|
|
|
return distributionService.save(distribution);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用@Log注解记录操作日志,模块为“配送管理”,操作类型为查询(BusinessType.QUERY)
|
|
|
|
|
@Log(module = "配送管理", type = BusinessType.QUERY)
|
|
|
|
|
// 处理GET请求,用于查询所有配送信息
|
|
|
|
|
@GetMapping("")
|
|
|
|
|
public List<Distribution> findAll() {
|
|
|
|
|
return distributionService.findAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理GET请求,用于获取可用于配送的司机和车辆信息
|
|
|
|
|
@GetMapping("can")
|
|
|
|
|
public Map<String, Object> can() {
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
// 将所有司机信息放入map中
|
|
|
|
|
map.put("drivers", driverRepository.findAll());
|
|
|
|
|
// 将所有车辆信息放入map中
|
|
|
|
|
map.put("vehicles", vehicleRepository.findAll());
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|