You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
227 lines
7.6 KiB
227 lines
7.6 KiB
package com.automobile.service;
|
|
|
|
import com.automobile.model.Car;
|
|
import com.automobile.parts.Engine;
|
|
import com.automobile.parts.Piston;
|
|
import com.automobile.parts.SteeringWheel;
|
|
import com.automobile.parts.Seat;
|
|
import com.automobile.parts.Transmission;
|
|
import com.automobile.parts.Wheel;
|
|
import com.automobile.system.ElectronicSystem;
|
|
import com.automobile.system.ElectronicControlUnit;
|
|
import com.automobile.configuration.ConfigurationSystem;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
/**
|
|
* 汽车制造系统类
|
|
* 实现完整的汽车制造流程,包含多个层级的组合关系
|
|
*/
|
|
public class ManufacturingSystem {
|
|
private String factoryName;
|
|
private List<ManufacturingLine> assemblyLines;
|
|
private List<Car> completedCars;
|
|
|
|
/**
|
|
* 构造方法
|
|
* @param factoryName 工厂名称
|
|
*/
|
|
public ManufacturingSystem(String factoryName) {
|
|
this.factoryName = factoryName;
|
|
this.assemblyLines = new ArrayList<>();
|
|
this.completedCars = new ArrayList<>();
|
|
|
|
// 创建多条装配线
|
|
for (int i = 1; i <= 3; i++) {
|
|
assemblyLines.add(new ManufacturingLine("装配线-" + i));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 开始制造汽车
|
|
* @param config 汽车配置系统
|
|
* @return 制造的汽车实例
|
|
*/
|
|
public Car manufactureCar(ConfigurationSystem config) {
|
|
System.out.println("\n===== " + factoryName + " 汽车制造开始 =====");
|
|
|
|
// 分配装配线
|
|
ManufacturingLine line = getAvailableAssemblyLine();
|
|
System.out.println("分配装配线: " + line.getName());
|
|
|
|
// 1. 底盘组装
|
|
System.out.println("阶段1: 底盘组装");
|
|
line.workOnChassis();
|
|
|
|
// 2. 引擎安装
|
|
System.out.println("阶段2: 引擎安装");
|
|
Engine engine = line.assembleEngine();
|
|
|
|
// 3. 变速箱安装
|
|
System.out.println("阶段3: 变速箱安装");
|
|
Transmission transmission = line.assembleTransmission();
|
|
|
|
// 4. 车轮安装
|
|
System.out.println("阶段4: 车轮安装");
|
|
List<Wheel> wheels = line.assembleWheels();
|
|
|
|
// 5. 车身安装
|
|
System.out.println("阶段5: 车身安装");
|
|
line.attachBody();
|
|
|
|
// 6. 内饰安装
|
|
System.out.println("阶段6: 内饰安装");
|
|
SteeringWheel steeringWheel = line.installSteeringWheel();
|
|
List<Seat> seats = line.installSeats();
|
|
|
|
// 7. 电子系统安装
|
|
System.out.println("阶段7: 电子系统安装");
|
|
ElectronicSystem electronicSystem = line.installElectronicSystem();
|
|
|
|
// 8. 完成装配并确认配置
|
|
System.out.println("阶段8: 最终装配");
|
|
Car car = config.confirmConfiguration();
|
|
|
|
// 9. 质量检测
|
|
System.out.println("阶段9: 质量检测");
|
|
boolean passed = performQualityCheck(car);
|
|
|
|
if (passed) {
|
|
completedCars.add(car);
|
|
System.out.println("汽车制造完成!车辆识别号: " + car.getVin());
|
|
System.out.println("===== " + factoryName + " 汽车制造结束 =====\n");
|
|
} else {
|
|
System.out.println("质量检测失败,汽车需要返工");
|
|
}
|
|
|
|
return car;
|
|
}
|
|
|
|
/**
|
|
* 获取可用的装配线
|
|
* @return 装配线
|
|
*/
|
|
private ManufacturingLine getAvailableAssemblyLine() {
|
|
// 简单实现:返回第一条可用的装配线
|
|
return assemblyLines.get(0);
|
|
}
|
|
|
|
/**
|
|
* 执行质量检测
|
|
* @param car 待检测的汽车
|
|
* @return 是否通过检测
|
|
*/
|
|
private boolean performQualityCheck(Car car) {
|
|
System.out.println("进行安全检测...");
|
|
System.out.println("进行性能测试...");
|
|
System.out.println("进行外观检查...");
|
|
|
|
// 启动汽车测试
|
|
car.start();
|
|
car.accelerate(50);
|
|
car.stop();
|
|
|
|
System.out.println("质量检测通过!");
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 显示制造统计
|
|
*/
|
|
public void showManufacturingStats() {
|
|
System.out.println("\n===== " + factoryName + " 制造统计 =====");
|
|
System.out.println("装配线数量: " + assemblyLines.size());
|
|
System.out.println("已完成汽车数量: " + completedCars.size());
|
|
|
|
if (!completedCars.isEmpty()) {
|
|
System.out.println("最近制造的汽车:");
|
|
Car lastCar = completedCars.get(completedCars.size() - 1);
|
|
lastCar.displayInfo();
|
|
}
|
|
|
|
System.out.println("=============================\n");
|
|
}
|
|
|
|
/**
|
|
* 内部类:制造装配线
|
|
*/
|
|
private static class ManufacturingLine {
|
|
private String name;
|
|
private boolean isBusy;
|
|
|
|
public ManufacturingLine(String name) {
|
|
this.name = name;
|
|
this.isBusy = false;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
// 各个制造阶段的方法
|
|
public void workOnChassis() {
|
|
System.out.println(" - 底盘框架焊接");
|
|
System.out.println(" - 悬挂系统安装");
|
|
System.out.println(" - 制动系统安装");
|
|
}
|
|
|
|
public Engine assembleEngine() {
|
|
System.out.println(" - 引擎缸体加工");
|
|
System.out.println(" - 安装4个活塞");
|
|
System.out.println(" - 安装曲轴和凸轮轴");
|
|
System.out.println(" - 安装燃油喷射系统");
|
|
return new Engine();
|
|
}
|
|
|
|
public Transmission assembleTransmission() {
|
|
System.out.println(" - 变速箱壳体加工");
|
|
System.out.println(" - 安装齿轮组");
|
|
System.out.println(" - 安装换挡机构");
|
|
return new Transmission();
|
|
}
|
|
|
|
public List<Wheel> assembleWheels() {
|
|
List<Wheel> wheels = new ArrayList<>();
|
|
System.out.println(" - 安装4个车轮");
|
|
for (int i = 0; i < 4; i++) {
|
|
wheels.add(new Wheel());
|
|
}
|
|
return wheels;
|
|
}
|
|
|
|
public void attachBody() {
|
|
System.out.println(" - 车身喷漆");
|
|
System.out.println(" - 车身与底盘结合");
|
|
System.out.println(" - 安装车门和车窗");
|
|
}
|
|
|
|
public SteeringWheel installSteeringWheel() {
|
|
System.out.println(" - 安装方向盘");
|
|
System.out.println(" - 连接转向柱");
|
|
return new SteeringWheel();
|
|
}
|
|
|
|
public List<Seat> installSeats() {
|
|
List<Seat> seats = new ArrayList<>();
|
|
System.out.println(" - 安装驾驶员座椅");
|
|
seats.add(new Seat(Seat.SeatType.DRIVER));
|
|
System.out.println(" - 安装乘客座椅");
|
|
seats.add(new Seat(Seat.SeatType.PASSENGER));
|
|
System.out.println(" - 安装后排座椅");
|
|
seats.add(new Seat(Seat.SeatType.REAR));
|
|
seats.add(new Seat(Seat.SeatType.REAR));
|
|
return seats;
|
|
}
|
|
|
|
public ElectronicSystem installElectronicSystem() {
|
|
System.out.println(" - 安装发动机控制单元");
|
|
System.out.println(" - 安装变速箱控制单元");
|
|
System.out.println(" - 安装车身控制单元");
|
|
System.out.println(" - 安装防抱死制动系统");
|
|
System.out.println(" - 安装安全气囊控制单元");
|
|
return new ElectronicSystem();
|
|
}
|
|
}
|
|
} |