今天,系统的对代码进行了修改优化,对原有代码进行全面修改,并实现了工序对接功能。
点击查看代码
//信2305-2 -- 20234023 -- 张一衡
import java.awt.*;
import java.sql.SQLOutput;
import java.util.Scanner;
import java.util.Random;
public class Moontest {
public static void main(String[] args) {
PlanManagement planManagement = new PlanManagement();
planManagement.runMenu();
}
}
class PlanInformation{
private int id=-1;//日报流水号,依次加一
private String planid="";//表示产品生产批次号(例如:2312-110,有8 位字符组成,前四位表示年月,后三位表示序号)。
private String planname="";//产品名称
private String process="";//当前工序名称
private String nextprocess="";//表示下一接收工序名称。(例如:“11.00 .修蜡”含义同上)。
private String operator="";//当前工序的操作者。
private String recipient="";//下一道工序的接受者。
private int plannumber=0;//该产品定要要求的产品数量。
private int innumber=0; //从上一道工序的接收的合格产品总数。
private int outnumber=0;//当前工序的产品转出总数。
private int missnumber=0;//表示当前工序的产品丢失数量。
private int badnumber=0;//表示当前工序的产品废品数量。
private int inspectednumber=0;//表示当前工序的产品待检验数量。
private int statement=0;//初始状态
//构造函数
public PlanInformation(){}
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;
}
//GetAndSet
public int getId() {
return id;
}
public String getPlanid() {
return planid;
}
public String getPlanname() {
return planname;
}
public String getProcess() {
return process;
}
public String getNextprocess() {
return nextprocess;
}
public String getOperator() {
return operator;
}
public String getRecipient() {
return recipient;
}
public int getPlannumber() {
return plannumber;
}
public int getInnumber() {
return innumber;
}
public int getOutnumber() {
return outnumber;
}
public int getMissnumber() {
return missnumber;
}
public int getBadnumber() {
return badnumber;
}
public int getInspectednumber() {
return inspectednumber;
}
public int getStatement() {
return statement;
}
public void setId(int id) {
this.id = id;
}
public void setPlanid(String planid) {
this.planid = planid;
}
public void setPlanname(String planname) {
this.planname = planname;
}
public void setProcess(String process) {
this.process = process;
}
public void setNextprocess(String nextprocess) {
this.nextprocess = nextprocess;
}
public void setOperator(String operator) {
this.operator = operator;
}
public void setRecipient(String recipient) {
this.recipient = recipient;
}
public void setPlannumber(int plumber) {
this.plannumber = plumber;
}
public void setInnumber(int innumber) {
this.innumber = innumber;
}
public void setOutnumber(int outnumber) {
this.outnumber = outnumber;
}
public void setMissnumber(int missnumber) {
this.missnumber = missnumber;
}
public void setBadnumber(int badnumber) {
this.badnumber = badnumber;
}
public void setInspectednumber(int inspectednumber) {
this.inspectednumber = inspectednumber;
}
public void setStatement(int statement) {
this.statement = statement;
}
}
class PlanManagement{
String []processnames ={"","射蜡","修蜡","面层","封浆","熔化","切割","精磨","调型","检验",""};
String []operators ={"","柳泽羽","藤艺哲","郝一诺","杨松铎","刘宇恒","陶攀印","阎琪文","郝正一","刘静一"};
String []recipients ={"","藤艺哲","郝一诺","杨松铎","刘宇恒","陶攀印","阎琪文","郝正一","刘静一",""};
PlanInformation[] plans = new PlanInformation[100];//存储数组
Scanner sc=new Scanner(System.in);
private int count=0;//当前记录数量
private int nextId = 0;//下一个ID
//验证产品批次号格式
boolean FormatOrNot(String pid){
return pid.matches("\\d{4}-\\d{3}$");
}
//查找产品计划
private PlanInformation findPlanByPlanId(String planId) {
for (PlanInformation plan : plans) {
if (plan != null && plan.getPlanid().equals(planId)) {
return plan;
}
}
return null;
}
//生成计划信息
void GeneratePlanInformation() {
if (count >= plans.length) {
System.out.println("计划数量已满,无法生成新的计划。");
return;
}
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学无限23软件开发有限公司 ");
System.out.println(" Mes系统2023版 ");
System.out.println("***********************************************************");
String pid;
do {
System.out.print(" 产品批次号(格式:YYYY-XXX):");
pid = sc.nextLine();
if (!FormatOrNot(pid)) {
System.out.println("录入错误,请重新输入!");
}
}while (!FormatOrNot(pid)) ;
System.out.print(" 产品名称:");
String pname = sc.nextLine();
System.out.print(" 计划数量:");
int pnumber = sc.nextInt();
sc.nextLine();
System.out.println("生成计划成功,是否提交(Y/N):");
String choice = sc.nextLine();
if (choice.equalsIgnoreCase("Y")) {
//创建新的计划信息
PlanInformation plan = new PlanInformation(nextId++, pid, pname, "", "", "", "", pnumber, 0, 0, 0, 0, 0, 0);
if(count==0){
plan.setProcess(processnames[1]);
plan.setOperator(operators[1]);
}else{
plan.setProcess(processnames[count+1]);
plan.setOperator(operators[count+1]);
}
if (count + 2 < processnames.length) {
plan.setNextprocess(processnames[count + 2]);
} else {
plan.setNextprocess("");
}
plan.setRecipient(recipients[count+1]);
plans[count++] = plan;
plan.setStatement(0);//设置为初始状态
System.out.println("计划已提交。");
} else {
System.out.println("计划未提交,已取消。");
}
}
void SubmitDailyReport(){
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学无限23软件开发有限公司 ");
System.out.println(" Mes系统2023版 ");
System.out.println("***********************************************************");
System.out.print(" 请输入产品批次号:");
String pid=sc.nextLine();
System.out.println("***********************************************************");
PlanInformation plan = findPlanByPlanId(pid);
if(plan==null){
System.out.println("库中没用该产品计划!");
return;
}
if(plan.getStatement()!=0){
System.out.println("该计划已提交或确认,无法再次提交日报。");
return;
}
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学无限23软件开发有限公司 ");
System.out.println(" Mes系统2023版 ");
System.out.println("***********************************************************");
System.out.println(" 1、产品批次:"+plan.getPlanid()+" ");
System.out.println(" 2、产品名称:"+plan.getPlanname()+" ");
System.out.println(" 3、计划数量:"+plan.getPlannumber()+" ");
System.out.println(" 4、当前工序:"+plan.getProcess()+" ");
System.out.println(" 5、下一工序:"+plan.getNextprocess()+" ");
System.out.println(" 6、操作员:"+plan.getOperator()+"(自动生成,根据工序号) ");
System.out.println(" 7、接收员:"+plan.getRecipient()+"(自动生成根据工序号) ");
System.out.print (" 8、上一道工序转入数量(第一道工序为0):");
plan.setInnumber(sc.nextInt());
sc.nextLine();
System.out.print(" 9、转出总数:");
plan.setOutnumber(sc.nextInt());
sc.nextLine();
System.out.print(" 10、丢失数量:");
plan.setMissnumber(sc.nextInt());
sc.nextLine();
System.out.print(" 11、废品数量:");
plan.setBadnumber(sc.nextInt());
sc.nextLine();
System.out.print(" 12、待检验数量:");
plan.setInspectednumber(sc.nextInt());
sc.nextLine();
//验证押平规则
if(!"射蜡".equals(plan.getProcess())){
while(plan.getInnumber()!=plan.getOutnumber()+plan.getMissnumber()+plan.getBadnumber()
+plan.getInspectednumber()){
System.out.println("录入错误:上一道工序的转入数量不符合规则,请检查并重新输入!");
System.out.println();
System.out.print(" 8、上一道工序转入数量(第一道工序为0):");
int tempInnumber=sc.nextInt();
sc.nextLine();
System.out.print(" 9、转出总数:");
int tempOutnumber=sc.nextInt();
sc.nextLine();
System.out.print(" 10、丢失数量:");
int tempMissnumber=sc.nextInt();
sc.nextLine();
System.out.print(" 11、废品数量:");
int tempBadnumber=sc.nextInt();
sc.nextLine();
System.out.print(" 12、待检验数量:");
int tempInspectednumber=sc.nextInt();
sc.nextLine();
String choice = sc.nextLine();
if (choice.equalsIgnoreCase("Y")) {
plan.setInnumber(tempInnumber);
plan.setOutnumber(tempOutnumber);
plan.setMissnumber(tempMissnumber);
plan.setBadnumber(tempBadnumber);
plan.setInspectednumber(tempInspectednumber);
} else {
System.out.println("未保存修改,已取消。");
return;
}
}
}
plan.setStatement(1);//设置为初始状态
System.out.println("日报信息保存提交成功!");
//向下一工序推进
int currentIndex = -1;
for (int i = 0; i < processnames.length; i++) {
if (processnames[i].equals(plan.getProcess())) {
currentIndex = i;
break;
}
}
if (currentIndex + 1 < processnames.length) {
plan.setProcess(processnames[currentIndex + 1]);
if (currentIndex + 2 < processnames.length) {
plan.setNextprocess(processnames[currentIndex + 2]);
} else {
plan.setNextprocess("");
}
plan.setOperator(operators[currentIndex + 1]);
plan.setRecipient(recipients[currentIndex + 1]);
} else {
System.out.println("已到达最后一个工序,无法继续推进。");
}
}
void ConfirmDailyReport(){
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学无限23软件开发有限公司 ");
System.out.println(" Mes系统2023版 ");
System.out.println("***********************************************************");
System.out.print(" 请输入产品批次号:");
String pid=sc.nextLine();
PlanInformation plan=findPlanByPlanId(pid);
System.out.println("***********************************************************");
if(plan==null){
System.out.println("库中没用该产品计划!");
return;
}
if(plan.getStatement()!=1){
System.out.println("该计划未提交,无法确认日报。");
return;
}
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学无限23软件开发有限公司 ");
System.out.println(" Mes系统2023版 ");
System.out.println("***********************************************************");
System.out.println(" 1、产品批次:" + plan.getPlanid());
System.out.println(" 2、产品名称:" + plan.getPlanname());
System.out.println(" 3、计划数量:" + plan.getPlannumber());
System.out.println(" 4、当前工序:"+plan.getProcess()+" ");
System.out.println(" 5、下一工序:"+plan.getNextprocess()+" ");
System.out.println(" 6、操作员:"+plan.getOperator()+"(自动生成,根据工序号) ");
System.out.println(" 7、接收员:"+plan.getRecipient()+"(自动生成根据工序号) ");
System.out.println(" 8、上一道工序转入数量:"+plan.getInnumber()+"(小于等于计划数量,第一道工序不用录入该数字) ");
System.out.println(" 9、转出总数:"+plan.getOutnumber()+" ");
System.out.println(" 10、丢失数量:"+plan.getMissnumber()+" ");
System.out.println(" 11、废品数量:"+plan.getBadnumber()+" ");
System.out.println(" 12、待检验数量:"+plan.getInspectednumber()+" ");
System.out.println("***********************************************************");
// 确认
System.out.println("是否确认日报(Y/N):");
String choice = sc.nextLine();
if (choice.equalsIgnoreCase("Y")) {
plan.setStatement(2); // 设置为已确认
// 生成新的生产任务记录
if (plan.getNextprocess()!= null &&!plan.getNextprocess().isEmpty()) {
PlanInformation newPlan = new PlanInformation();
newPlan.setId(nextId++);
newPlan.setPlanid(plan.getPlanid());
newPlan.setPlanname(plan.getPlanname());
newPlan.setProcess(plan.getNextprocess());
newPlan.setNextprocess(getNextProcessName(plan.getNextprocess()));
newPlan.setOperator(getOperatorForProcess(plan.getNextprocess()));
newPlan.setRecipient(getRecipientForProcess(plan.getNextprocess()));
plans[count++] = newPlan;
} else {
System.out.println("已完成所有工序,无需生成新任务记录。");
}
System.out.println("日报确认成功,已生成新任务记录!");
} else {
System.out.println("确认已取消。");
}
}
//下一工序
private String getNextProcessName(String currentProcess) {
int currentIndex = -1;
for (int i = 0; i < processnames.length; i++) {
if (processnames[i].equals(currentProcess)) {
currentIndex = i;
break;
}
}
if (currentIndex + 1 < processnames.length) {
return processnames[currentIndex + 1];
} else {
return "";
}
}
//操作员
private String getOperatorForProcess(String process) {
int index = -1;
for (int i = 0; i < processnames.length; i++) {
if (processnames[i].equals(process)) {
index = i;
break;
}
}
if (index >= 0 && index < operators.length) {
return operators[index];
} else {
return "";
}
}
//接收员
private String getRecipientForProcess(String process) {
int index = -1;
for (int i = 0; i < processnames.length; i++) {
if (processnames[i].equals(process)) {
index = i;
break;
}
}
if (index >= 0 && index < recipients.length) {
return recipients[index];
} else {
return "";
}
}
// 显示进度
void NowProgress(){
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学无限23软件开发有限公司 ");
System.out.println(" Mes系统2023版 ");
System.out.println("***********************************************************");
for (int i= 0;i< count;i++) {
if (plans[i] != null&&plans[i].getPlannumber()!=0) {
System.out.println("产品批次:" + plans[i].getPlanid());
System.out.println("产品名称:" + plans[i].getPlanname());
System.out.println("计划数量:" + plans[i].getPlannumber());
System.out.println("完成数量:" + plans[i].getOutnumber());
System.out.println("剩余数量:" + (plans[i].getPlannumber() - plans[i].getOutnumber()));
System.out.println("***********************************************************");
}
}
}
void Menu(){
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("***********************************************************");
System.out.print("请输入操作选项:");
}
void runMenu(){
do{
Menu();
int choice=sc.nextInt();
sc.nextLine();// Consume newline
switch(choice){
case 1: GeneratePlanInformation() ;break;
case 2: SubmitDailyReport();break;
case 3: ConfirmDailyReport();break;
case 4: NowProgress();break;
default: System.out.println("该选项不存在,请你重新输入!");
}
}while(true);
}
}