liurunyu
7 天以前 fcc1cf275578bd3aa08ef50c6a611fb206b7aac9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package com.dy.pipIrrParamSet.console;
 
import com.dy.pipIrrParamSet.ServerProperties;
import com.dy.pipIrrParamSet.paramSet.ParamSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
 
import java.io.PrintWriter;
 
/**
 * @Author: liurunyu
 * @Date: 2025/5/28 15:36
 * @Description
 */
@Component
@Scope("prototype")
public class Command {
    
    private static String[] commands ;
    static{
        commands = new String[]{
                "config 查看配置信息",    
                "mw 121 [tag] 命令含义:通信中间件在云服务器(121.199.41.121)上的[tag](元谋ym,沙盘sp测试test,梅江mj,民勤mq,延庆yq,黑龙江hlj,甘州gz,凉州lz,金川jc)系统配置",
                "mw 233 [tag] 命令含义:通信中间件在云服务器(8.130.130.233)上的[tag](元谋ym,沙盘sp测试test,梅江mj,民勤mq,延庆yq,黑龙江hlj,甘州gz,凉州lz,金川jc)系统配置",
                "web 121 命令含义:web模块在云服务器(121.199.41.121)上的配置",
                "web 233 命令含义:web模块在云服务器(8.130.130.233)上的配置",
                "exit 退出",
        };
    }
    private PrintWriter prtWrt ;
 
    private String[] nowCom ;
 
    private ParamSet paramSet ;
 
    @Autowired
    public void setBean(ParamSet paramSet){
        this.paramSet = paramSet;
    }
 
    public boolean dealCommand(String comLine, PrintWriter prtWrt) throws Exception{
        this.prtWrt = prtWrt ;
        boolean exit = false ;
        comLine = comLine.trim() ;
        if (comLine.equals("help")) {
            outHelp();
        }else if (comLine.equals("config")) {
            outConfig();
        }else if(comLine.equals("exit")){
            exit = true ;
        }else if(isParamSetCom(comLine)){
            paramSet.dealCom(nowCom, this);
        }else {
            outNoIdentify();
        }
        return exit ;
    }
    public boolean isParamSetCom(String command){
        nowCom = null ;
        String[] inputs = command.split(" ");
        int count = 0 ;
        for (String in : inputs){
            if(!in.equals("")){
                count++ ;
            }
        }
        if(count > 0){
            nowCom = new String[count] ;
        }
        int index = 0 ;
        for (String in : inputs){
            if(!in.equals("")){
                nowCom[index++] = in ;
            }
        }
        return nowCom == null? false : (nowCom.length > 0 ? true : false) ;
    }
 
    public void out(String str){
        prtWrt.println(str==null?"":str);
        prtWrt.println("");
    }
    public void out1(String str){
        prtWrt.println(str==null?"":str);
    }
    private void outHelp(){
        prtWrt.println("命令");
        for(String s : commands){
            prtWrt.println("  " + s);
        }
        prtWrt.println("");
    }
    public void outConfig(){
        prtWrt.println("预先设置");
        prtWrt.println("  软件空间根目录:" + ServerProperties.WorkspaceRoot);
        prtWrt.println("");
    }
    public void outNoIdentify(){
        prtWrt.println("命令不可识别!");
        prtWrt.println("");
    }
    public void outNoParams(){
        prtWrt.println("请输入命令参数!");
        prtWrt.println("");
    }
 
 
    public static void main(String[] args) {
        String com = "   02 123       345          789";
        com = com.trim() ;
        String[] coms = com.split(" ");
        for(String s : coms){
            System.out.println(s);
        }
    }
 
}