package com.dy.pipIrrParamSet.paramSet; 
 | 
  
 | 
import com.dy.pipIrrParamSet.ServerProperties; 
 | 
import com.dy.pipIrrParamSet.console.Command; 
 | 
import com.dy.pipIrrParamSet.util.FileUtil; 
 | 
import org.springframework.context.annotation.Scope; 
 | 
import org.springframework.stereotype.Component; 
 | 
  
 | 
import java.io.File; 
 | 
import java.nio.file.Path; 
 | 
import java.util.ArrayList; 
 | 
import java.util.List; 
 | 
  
 | 
/** 
 | 
 * @Author: liurunyu 
 | 
 * @Date: 2025/5/29 13:44 
 | 
 * @Description 
 | 
 */ 
 | 
@Component 
 | 
@Scope("prototype") 
 | 
public class ParamSetWeb { 
 | 
  
 | 
    protected void set(String[] comIn, Command command){ 
 | 
        boolean flag = setApplicationCommonWebYml(comIn, command) ; 
 | 
        if(flag){ 
 | 
            flag = setInitConfig(comIn, command) ; 
 | 
            if(flag){ 
 | 
                List<File> webModules = this.getWebModules(comIn, command); 
 | 
                if(webModules == null || webModules.size() == 0){ 
 | 
                    command.out("未得到任何web模块"); 
 | 
                }else{ 
 | 
                    /* 
 | 
                    command.out1("发现web模块:"); 
 | 
                    for(File webModule : webModules){ 
 | 
                        command.out1("  " + webModule.getName()); 
 | 
                        command.out1("  " + webModule.getPath()); 
 | 
                    } 
 | 
                    command.out1(""); 
 | 
                    */ 
 | 
                    Boolean banner = null ; 
 | 
                    int countCancel = 0 ; 
 | 
                    int countSuccess = 0 ; 
 | 
                    int countFailure = 0 ; 
 | 
                    for(File webModule : webModules){ 
 | 
                        banner = setWebModuleApplicationYml(comIn, command, webModule.getPath() + "\\") ; 
 | 
                        if(banner == null){ 
 | 
                            countCancel ++ ; 
 | 
                        }else if(banner.booleanValue()){ 
 | 
                            countSuccess ++ ; 
 | 
                        }else if(!banner.booleanValue()){ 
 | 
                            countFailure ++ ; 
 | 
                        } 
 | 
                    } 
 | 
                    command.out("参数设置完成,其中" + countSuccess + "个模块成功," + countFailure + "个模块失败," + countCancel + "个模块忽略"); 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
  
 | 
    } 
 | 
  
 | 
    private boolean setApplicationCommonWebYml(String[] comIn, Command command){ 
 | 
        String filePath = ServerProperties.WorkspaceRoot 
 | 
                + ParamKey.AbstractPathOfMGlobal 
 | 
                + ParamKey.AbstractPathOfResources 
 | 
                + ParamKey.FileOfApplicationCommonWebYml_MainName 
 | 
                + "." 
 | 
                + ParamKey.FileOfApplicationCommonWebYml_ExeName ; 
 | 
        String modelFilePath = ServerProperties.WorkspaceRoot 
 | 
                + ParamKey.AbstractPathOfMGlobal 
 | 
                + ParamKey.AbstractPathOfResources 
 | 
                + ParamKey.FileOfApplicationCommonWebYml_MainName 
 | 
                + ParamKey.FileOfModelNamePre 
 | 
                + comIn[1] 
 | 
                + ParamKey.FileOfModelNameTail 
 | 
                + "." 
 | 
                + ParamKey.FileOfApplicationCommonWebYml_ExeName ; 
 | 
        Path appFilePath = FileUtil.getFilePath(filePath) ; 
 | 
        if(appFilePath == null){ 
 | 
            command.out("未找到配置文件" + filePath); 
 | 
            return false ; 
 | 
        } 
 | 
        Path appModelFilePath = FileUtil.getFilePath(modelFilePath) ; 
 | 
        if(appModelFilePath == null){ 
 | 
            command.out("未找到配置文件" + modelFilePath); 
 | 
            return false ; 
 | 
        } 
 | 
        List<String> modelLines; 
 | 
        try{ 
 | 
            modelLines = FileUtil.readFile(appModelFilePath); 
 | 
        }catch (Exception e){ 
 | 
            command.out("读取文件" + modelFilePath + "发生异常:" + e.getMessage()); 
 | 
            return false ; 
 | 
        } 
 | 
        if(modelLines == null || modelLines.size() == 0){ 
 | 
            command.out("文件" + modelFilePath + "是空文件"); 
 | 
            return false ; 
 | 
        }else{ 
 | 
            try { 
 | 
                FileUtil.writeFile(appFilePath, modelLines); 
 | 
            }catch (Exception e){ 
 | 
                command.out("写入文件" + filePath + "发生异常:" + e.getMessage()); 
 | 
                return false ; 
 | 
            } 
 | 
        } 
 | 
        return true ; 
 | 
    } 
 | 
  
 | 
    private boolean setInitConfig(String[] comIn, Command command){ 
 | 
        String filePath = ServerProperties.WorkspaceRoot 
 | 
                + ParamKey.AbstractPathOfMGlobal 
 | 
                + ParamKey.AbstractPathOfResources 
 | 
                + ParamKey.FileOfInitConfigXml_MainName 
 | 
                + "." 
 | 
                + ParamKey.FileOfInitConfigXml_ExeName ; 
 | 
        String modelFilePath = ServerProperties.WorkspaceRoot 
 | 
                + ParamKey.AbstractPathOfMGlobal 
 | 
                + ParamKey.AbstractPathOfResources 
 | 
                + ParamKey.FileOfInitConfigXml_MainName 
 | 
                + ParamKey.FileOfModelNamePre 
 | 
                + comIn[1] 
 | 
                + ParamKey.FileOfModelNameTail 
 | 
                + "." 
 | 
                + ParamKey.FileOfInitConfigXml_ExeName ; 
 | 
        Path appFilePath = FileUtil.getFilePath(filePath) ; 
 | 
        if(appFilePath == null){ 
 | 
            command.out("未找到配置文件" + filePath); 
 | 
            return false ; 
 | 
        } 
 | 
        Path appModelFilePath = FileUtil.getFilePath(modelFilePath) ; 
 | 
        if(appModelFilePath == null){ 
 | 
            command.out("未找到配置文件" + modelFilePath); 
 | 
            return false ; 
 | 
        } 
 | 
        List<String> modelLines; 
 | 
        try{ 
 | 
            modelLines = FileUtil.readFile(appModelFilePath); 
 | 
        }catch (Exception e){ 
 | 
            command.out("读取文件" + modelFilePath + "发生异常:" + e.getMessage()); 
 | 
            return false ; 
 | 
        } 
 | 
        if(modelLines == null || modelLines.size() == 0){ 
 | 
            command.out("文件" + modelFilePath + "是空文件"); 
 | 
            return false ; 
 | 
        }else{ 
 | 
            try { 
 | 
                FileUtil.writeFile(appFilePath, modelLines); 
 | 
            }catch (Exception e){ 
 | 
                command.out("写入文件" + filePath + "发生异常:" + e.getMessage()); 
 | 
                return false ; 
 | 
            } 
 | 
        } 
 | 
        return true ; 
 | 
    } 
 | 
  
 | 
  
 | 
    private Boolean setWebModuleApplicationYml(String[] comIn, Command command, String absolutePath){ 
 | 
        String modelFilePath = absolutePath 
 | 
                + ParamKey.AbstractPathOfResources 
 | 
                + ParamKey.FileOfApplication_MainName 
 | 
                + ParamKey.FileOfModelNamePre 
 | 
                + comIn[1] 
 | 
                + ParamKey.FileOfModelNameTail 
 | 
                + "." 
 | 
                + ParamKey.FileOfApplication_ExeName ; 
 | 
        File f = new File(modelFilePath) ; 
 | 
        if(!f.exists()){ 
 | 
            return null ; 
 | 
        } 
 | 
  
 | 
        Path appModelFilePath = FileUtil.getFilePath(modelFilePath) ; 
 | 
        if(appModelFilePath == null){ 
 | 
            return false ; 
 | 
        } 
 | 
        String filePath = absolutePath 
 | 
                + ParamKey.AbstractPathOfResources 
 | 
                + ParamKey.FileOfApplication_MainName 
 | 
                + "." 
 | 
                + ParamKey.FileOfApplication_ExeName ; 
 | 
        Path appFilePath = FileUtil.getFilePath(filePath) ; 
 | 
        if(appFilePath == null){ 
 | 
            command.out("未找到配置文件" + filePath); 
 | 
            return false ; 
 | 
        } 
 | 
  
 | 
        List<String> modelLines; 
 | 
        try{ 
 | 
            modelLines = FileUtil.readFile(appModelFilePath); 
 | 
        }catch (Exception e){ 
 | 
            command.out("读取文件" + modelFilePath + "发生异常"); 
 | 
            return false ; 
 | 
        } 
 | 
        if(modelLines == null || modelLines.size() == 0){ 
 | 
            command.out("文件" + modelFilePath + "是空文件"); 
 | 
            return false ; 
 | 
        }else{ 
 | 
            try { 
 | 
                FileUtil.writeFile(appFilePath, modelLines); 
 | 
            }catch (Exception e){ 
 | 
                command.out("写入文件" + filePath + "发生异常:" + e.getMessage()); 
 | 
                return false ; 
 | 
            } 
 | 
        } 
 | 
        return true ; 
 | 
    } 
 | 
  
 | 
    private List<File> getWebModules(String[] comIn, Command command){ 
 | 
        List<File> webModules = new ArrayList<>(); 
 | 
        String dirPath = ServerProperties.WorkspaceRoot 
 | 
                + ParamKey.AbstractPathOfWeb ; 
 | 
        File dir = new File(dirPath) ; 
 | 
        if(dir.exists() && dir.isDirectory()){ 
 | 
            File[] subFiles = dir.listFiles() ; 
 | 
            if(subFiles != null && subFiles.length > 0){ 
 | 
                for(File subFile : subFiles){ 
 | 
                    if(subFile.isDirectory()){ 
 | 
                        webModules.add(subFile); 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
        return webModules ; 
 | 
    } 
 | 
} 
 |