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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
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 ;
    }
}