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](民勤mq,延庆yq,黑龙江hlj,甘州gz,凉州lz,金川jc,嘉峪关jyg)系统配置", 
 | 
                "mw 233 [tag] 命令含义:通信中间件在云服务器(8.130.130.233)上的[tag](元谋ym,沙盘sp,测试test,梅江mj)系统配置", 
 | 
                "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); 
 | 
        } 
 | 
    } 
 | 
  
 | 
} 
 |