9.29

//20234096 韩坤 信2305-3
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class PlanManagement {
private static List records = new ArrayList<>();
private static Map<String, String[]> processFlow = new HashMap<>();
private static int recordCount = 0;

public static void main(String[] args) {
    initializeProcessFlow();
    PlanManagement ms = new PlanManagement();
    ms.menu();
}

// 初始化工艺流程表
private static void initializeProcessFlow() {
    processFlow.put("10. 射蜡", new String[]{"20. 修蜡", "柳泽羽", "藤艺哲"});
    processFlow.put("20. 修蜡", new String[]{"30. 面层", "藤艺哲", "郝一诺"});
    processFlow.put("30. 面层", new String[]{"40. 封浆", "郝一诺", "杨松铎"});
    processFlow.put("40. 封浆", new String[]{"50. 熔化", "杨松铎", "刘宇恒"});
    processFlow.put("50. 熔化", new String[]{"60. 切割", "刘宇恒", "陶攀印"});
    processFlow.put("60. 切割", new String[]{"70. 精磨", "陶攀印", "阎琪文"});
    processFlow.put("70. 精磨", new String[]{"80. 调型", "阎琪文", "郝正一"});
    processFlow.put("80. 调型", new String[]{"90. 检验", "郝正一", "刘静一"});
    processFlow.put("90. 检验", new String[]{null, "刘静一", null});
}

// 主菜单
public void menu() {
    Scanner scanner = new Scanner(System.in);
    while (true) {
        System.out.println("***********************************************************");
        System.out.println("石家庄铁道大学无限23软件开发有限公司");
        System.out.println("Mes系统2023版");
        System.out.println("***********************************************************");
        System.out.println("1、生成计划");
        System.out.println("2、提交日报");
        System.out.println("3、确认日报");
        System.out.println("4、统计进度");
        System.out.println("**********************************************************");

        int option = scanner.nextInt();
        scanner.nextLine(); // Consume the newline

        switch (option) {
            case 1:
                generatePlan(scanner);
                break;
            case 2:
                submitReport(scanner);
                break;
            case 3:
                confirmReport(scanner);
                break;
            case 4:
                displayProgress(scanner);
                break;
            default:
                System.out.println("该选项不存在,请重新输入。");
        }
    }
}

// 生成计划
private void generatePlan(Scanner scanner) {
    if (recordCount >= 5) {
        System.out.println("记录已满,无法再生成计划。");
        return;
    }

    System.out.println("请输入产品批次(如:2305-003):");
    String planId = scanner.nextLine();
    if (!planId.matches("\\d{4}-\\d{3}")) {
        System.out.println("录入错误,请重新输入正确的产品批次号(如:2305-003)。");
        return;
    }

    System.out.println("请输入产品名称(如:表体):");
    String planName = scanner.nextLine();
    if (planName.isEmpty()) {
        System.out.println("录入错误,请重新输入正确的产品名称(如:表体)。");
        return;
    }

    System.out.println("请输入计划数量:");
    int planNumber;
    try {
        planNumber = scanner.nextInt();
    } catch (Exception e) {
        System.out.println("录入错误,请输入一个正确的数字。");
        scanner.nextLine(); // Consume the invalid input
        return;
    }
    scanner.nextLine(); // Consume the newline

    PlanInformation planInfo = new PlanInformation(recordCount + 1, planId, planName,
            "10. 射蜡", "20. 修蜡", "柳泽羽", "藤艺哲",
            planNumber, 0, 0, 0, 0, 0, 0);

    System.out.println("该产品入库操作已完成,是否提交(Y/N)");
    String submit = scanner.nextLine();

    if (submit.equalsIgnoreCase("Y")) {
        records.add(planInfo);
        recordCount++;
        System.out.println("记录已提交。");
    } else {
        System.out.println("记录已被忽略。");
    }
}

// 提交日报方法
private void submitReport(Scanner scanner) {
    System.out.println("请输入产品批次号:");
    String planId = scanner.nextLine();

    PlanInformation pi = findPlan(planId);
    if (pi == null) {
        System.out.println("库中没有该产品计划。");
        return;
    }

    if (pi.getStatement() == 0) {
        System.out.println("1、产品批次:" + pi.getPlanId());
        System.out.println("2、产品名称:" + pi.getPlanName());
        System.out.println("3、计划数量:" + pi.getPlanNumber());

        System.out.println("请输入当前工序(如:“10. 射蜡”):");
        pi.setProcess(scanner.nextLine());

        String[] details = processFlow.get(pi.getProcess());
        if (details == null) {
            System.out.println("工序信息错误,请重新输入。");
            return;
        }
        pi.setNextProcess(details[0]);
        pi.setOperator(details[1]);
        pi.setRecipient(details[2]);

        if (!pi.getProcess().equals("10. 射蜡")) {
            System.out.println("请输入上一道工序转入数量:");
            pi.setInNumber(scanner.nextInt());
        }

        System.out.println("请输入转出总数:");
        pi.setOutNumber(scanner.nextInt());

        System.out.println("请输入丢失数量:");
        pi.setMissNumber(scanner.nextInt());

        System.out.println("请输入废品数量:");
        pi.setBadNumber(scanner.nextInt());

        pi.setInspectedNumber(pi.getOutNumber() - pi.getMissNumber() - pi.getBadNumber());
        scanner.nextLine(); // Consume the newline

        System.out.println("数据录入完毕,是否提交(Y/N)");
        String submit = scanner.nextLine();

        if (submit.equalsIgnoreCase("Y")) {
            pi.setStatement(1);
            printReport(pi);
        } else {
            System.out.println("数据未保存。");
        }
    } else if (pi.getStatement() == 2) {
        // 已确认过的批次日报显示
        System.out.println("1、产品批次:" + pi.getPlanId());
        System.out.println("2、产品名称:" + pi.getPlanName());
        System.out.println("3、计划数量:" + pi.getPlanNumber());
        System.out.println("4、当前工序:" + pi.getProcess());
        System.out.println("5、下一工序:" + pi.getNextProcess());
        System.out.println("6、操作员:" + pi.getOperator());
        System.out.println("7、接收员:" + pi.getRecipient());
        System.out.println("8、上一道工序转入数量:" + pi.getInNumber());
        System.out.println("9、转出总数:" + pi.getOutNumber());
        System.out.println("10、丢失数量:" + pi.getMissNumber());
        System.out.println("11、废品数量:" + pi.getBadNumber());
        System.out.println("12、待检数量:" + pi.getInspectedNumber());
    }
}

// 确认日报方法
private void confirmReport(Scanner scanner) {
    System.out.println("请输入产品批次号:");
    String planId = scanner.nextLine();

    PlanInformation pi = findPlan(planId);
    if (pi == null || pi.getStatement() != 1) {
        System.out.println("库中没有该产品批次或该批次状态不可确认。");
        return;
    }

    System.out.println("1、产品批次:" + pi.getPlanId());
    System.out.println("2、产品名称:" + pi.getPlanName());
    System.out.println("3、计划数量:" + pi.getPlanNumber());
    System.out.println("4、当前工序:" + pi.getProcess());
    System.out.println("5、下一工序:" + pi.getNextProcess());
    System.out.println("6、操作员:" + pi.getOperator());
    System.out.println("7、接收员:" + pi.getRecipient());
    System.out.println("8、上一道工序转入数量:" + pi.getInNumber());
    System.out.println("9、转出总数:" + pi.getOutNumber());
    System.out.println("10、丢失数量:" + pi.getMissNumber());
    System.out.println("11、废品数量:" + pi.getBadNumber());
    System.out.println("12、待检数量:" + pi.getInspectedNumber());

    System.out.println("确认以上数据是否准确(Y/N)");
    String confirm = scanner.nextLine();

    if (confirm.equalsIgnoreCase("Y")) {
        pi.setStatement(2);
        String[] nextProcessDetails = processFlow.get(pi.getNextProcess());
        pi.setProcess(pi.getNextProcess());
        pi.setNextProcess(nextProcessDetails[0]);
        pi.setOperator(nextProcessDetails[1]);
        pi.setRecipient(nextProcessDetails[2]);
        pi.setInNumber(pi.getOutNumber() - pi.getMissNumber() - pi.getBadNumber() - pi.getInspectedNumber());
        printReport(pi);
    } else {
        System.out.println("数据未确认。");
    }
}

// 显示进度方法
private void displayProgress(Scanner scanner) {
    System.out.println("请输入产品批次号:");
    String planId = scanner.nextLine();

    PlanInformation pi = findPlan(planId);
    if (pi == null) {
        System.out.println("库中没有该产品批次。");
        return;
    }

    int completedQuantity = (pi.getProcess().equals("90. 检验")) ? pi.getOutNumber() : 0;
    int remainingQuantity = pi.getPlanNumber() - completedQuantity;

    System.out.println("1、产品批次:" + pi.getPlanId());
    System.out.println("2、产品名称:" + pi.getPlanName());
    System.out.println("3、计划数量:" + pi.getPlanNumber());
    System.out.println("4、完成数量:" + completedQuantity);
    System.out.println("5、剩余数量:" + remainingQuantity);
}

// 查找计划
private PlanInformation findPlan(String planId) {
    for (PlanInformation pi : records) {
        if (pi.getPlanId().equals(planId)) {
            return pi;
        }
    }
    return null;
}

    private void printReport(PlanInformation pi) {
    System.out.println("1、产品批次:" + pi.getPlanId());
    System.out.println("2、产品名称:" + pi.getPlanName());
    System.out.println("3、计划数量:" + pi.getPlanNumber());
    System.out.println("4、当前工序:" + pi.getProcess());
    System.out.println("5、下一工序:" + pi.getNextProcess());
    System.out.println("6、操作员:" + pi.getOperator());
    System.out.println("7、接收员:" + pi.getRecipient());
    System.out.println("8、上一道工序转入数量:" + pi.getInNumber());
    System.out.println("9、转出总数:" + pi.getOutNumber());
    System.out.println("10、丢失数量:" + pi.getMissNumber());
    System.out.println("11、废品数量:" + pi.getBadNumber());
    System.out.println("12、待检数量:" + pi.getInspectedNumber());
}


class PlanInformation {

//所需私有变量
private int id;
private String planId;
private String planName;
private String process;
private String nextProcess;
private String operator;
private String recipient;
private int planNumber;
private int inNumber;
private int outNumber;
private int missNumber;
private int badNumber;
private int inspectedNumber;
private int statement;
//
public PlanInformation(int id, String planId, String planName,
String process, String nextProcess,
String operator, String recipient,
int planNumber, int inNumber,
int outNumber, int missNumber,
int badNumber, int inspectedNumber,
int statement) {
this.id = id;
this.planId = planId;
this.planName = planName;
this.process = process;
this.nextProcess = nextProcess;
this.operator = operator;
this.recipient = recipient;
this.planNumber = planNumber;
this.inNumber = inNumber;
this.outNumber = outNumber;
this.missNumber = missNumber;
this.badNumber = badNumber;
this.inspectedNumber = inspectedNumber;
this.statement = statement;
}

    // Getter 和 Setter 方法
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getPlanId() {
        return planId;
    }

    public void setPlanId(String planId) {
        this.planId = planId;
    }

    public String getPlanName() {
        return planName;
    }

    public void setPlanName(String planName) {
        this.planName = planName;
    }

    public String getProcess() {
        return process;
    }

    public void setProcess(String process) {
        this.process = process;
    }

    public String getNextProcess() {
        return nextProcess;
    }

    public void setNextProcess(String nextProcess) {
        this.nextProcess = nextProcess;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public String getRecipient() {
        return recipient;
    }

    public void setRecipient(String recipient) {
        this.recipient = recipient;
    }

    public int getPlanNumber() {
        return planNumber;
    }

    public void setPlanNumber(int planNumber) {
        this.planNumber = planNumber;
    }

    public int getInNumber() {
        return inNumber;
    }

    public void setInNumber(int inNumber) {
        this.inNumber = inNumber;
    }

    public int getOutNumber() {
        return outNumber;
    }

    public void setOutNumber(int outNumber) {
        this.outNumber = outNumber;
    }

    public int getMissNumber() {
        return missNumber;
    }

    public void setMissNumber(int missNumber) {
        this.missNumber = missNumber;
    }

    public int getBadNumber() {
        return badNumber;
    }

    public void setBadNumber(int badNumber) {
        this.badNumber = badNumber;
    }

    public int getInspectedNumber() {
        return inspectedNumber;
    }

    public void setInspectedNumber(int inspectedNumber) {
        this.inspectedNumber = inspectedNumber;
    }

    public int getStatement() {
        return statement;
    }

    public void setStatement(int statement) {
        this.statement = statement;
    }
}

}

posted @ 2024-09-29 20:49  HK12345  阅读(11)  评论(0编辑  收藏  举报