Skip to content

Commit 71e62b8

Browse files
committed
修复module路径选择针对部分版本不生效问题。添加新的默认类型映射text
1 parent ad9671d commit 71e62b8

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/main/java/com/sjhy/plugin/tool/ConfigInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,13 @@ private void initDefault() {
114114
TypeMapperGroup typeMapperGroup = new TypeMapperGroup();
115115
List<TypeMapper> typeMapperList = new ArrayList<>();
116116
typeMapperList.add(new TypeMapper("varchar(\\(\\d+\\))?", "java.lang.String"));
117+
typeMapperList.add(new TypeMapper("text", "java.lang.String"));
117118
typeMapperList.add(new TypeMapper("decimal(\\(\\d+\\))?", "java.lang.Double"));
118119
typeMapperList.add(new TypeMapper("integer", "java.lang.Integer"));
119120
typeMapperList.add(new TypeMapper("int(\\(\\d+\\))?", "java.lang.Integer"));
120121
typeMapperList.add(new TypeMapper("int4", "java.lang.Integer"));
121122
typeMapperList.add(new TypeMapper("int8", "java.lang.Long"));
122-
typeMapperList.add(new TypeMapper("bigint", "java.lang.Long"));
123+
typeMapperList.add(new TypeMapper("bigint(\\(\\d+\\))?", "java.lang.Long"));
123124
typeMapperList.add(new TypeMapper("datetime", "java.util.Date"));
124125
typeMapperList.add(new TypeMapper("timestamp", "java.util.Date"));
125126
typeMapperList.add(new TypeMapper("boolean", "java.lang.Boolean"));

src/main/java/com/sjhy/plugin/tool/VelocityUtils.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ private Map<String, Object> handlerMap() {
119119
map.put("packageName", cacheDataUtils.getPackageName());
120120
if (selectModule != null) {
121121
//module绝对路径
122-
if (selectModule.getModuleFile()!=null) {
123-
map.put("modulePath", selectModule.getModuleFile().getParent().getPath());
124-
}
122+
map.put("modulePath", new File(selectModule.getModuleFilePath()).getParent());
125123
map.put("moduleName", selectModule.getName());
126124
}
127125
// 项目路径

src/main/java/com/sjhy/plugin/ui/SelectSavePath.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
66
import com.intellij.openapi.module.Module;
77
import com.intellij.openapi.vfs.VirtualFile;
8+
import com.intellij.openapi.vfs.VirtualFileManager;
89
import com.intellij.psi.PsiPackage;
910
import com.sjhy.plugin.entity.TableInfo;
1011
import com.sjhy.plugin.entity.Template;
@@ -48,7 +49,7 @@ public class SelectSavePath extends JDialog {
4849
/**
4950
* 模型下拉框
5051
*/
51-
private JComboBox moduleComboBox;
52+
private JComboBox<String> moduleComboBox;
5253
/**
5354
* 包字段
5455
*/
@@ -128,16 +129,18 @@ public void windowClosing(WindowEvent e) {
128129
* @return 模板对象集合
129130
*/
130131
private List<Template> getSelectTemplate() {
132+
// 获取到已选择的复选框
131133
List<String> selectTemplateNameList = new ArrayList<>();
132134
checkBoxList.forEach(jCheckBox -> {
133135
if (jCheckBox.isSelected()) {
134136
selectTemplateNameList.add(jCheckBox.getText());
135137
}
136138
});
137-
List<Template> selectTemplateList = new ArrayList<>();
139+
List<Template> selectTemplateList = new ArrayList<>(selectTemplateNameList.size());
138140
if (selectTemplateNameList.isEmpty()) {
139141
return selectTemplateList;
140142
}
143+
// 将复选框转换成对应的模板对象
141144
templateGroup.getElementList().forEach(template -> {
142145
if (selectTemplateNameList.contains(template.getName())) {
143146
selectTemplateList.add(template);
@@ -151,12 +154,13 @@ private List<Template> getSelectTemplate() {
151154
*/
152155
private void onOK() {
153156
List<Template> selectTemplateList = getSelectTemplate();
157+
// 如果选择的模板是空的
154158
if (selectTemplateList.isEmpty()) {
155159
JOptionPane.showMessageDialog(null, "Can't Select Template!");
156160
return;
157161
}
158162
String savePath = pathField.getText();
159-
if (savePath.isEmpty()) {
163+
if (StringUtils.isEmpty(savePath)) {
160164
JOptionPane.showMessageDialog(null, "Can't Select Save Path!");
161165
return;
162166
}
@@ -168,6 +172,7 @@ private void onOK() {
168172
cacheDataUtils.setUnifiedConfig(unifiedConfig.isSelected());
169173
// 生成代码
170174
VelocityUtils.getInstance().handler();
175+
// 关闭窗口
171176
dispose();
172177
}
173178

@@ -195,10 +200,15 @@ private void init() {
195200

196201
//初始化Module选择
197202
for (Module module : cacheDataUtils.getModules()) {
198-
//noinspection unchecked
199203
moduleComboBox.addItem(module.getName());
200204
}
201205

206+
//监听module选择事件
207+
moduleComboBox.addActionListener(e -> {
208+
// 刷新路径
209+
refreshPath();
210+
});
211+
202212
//添加包选择事件
203213
packageChooseButton.addActionListener(e -> {
204214
PackageChooserDialog dialog = new PackageChooserDialog("Package Chooser", cacheDataUtils.getProject());
@@ -219,8 +229,8 @@ private void init() {
219229
//将当前选中的model设置为基础路径
220230
VirtualFile path = cacheDataUtils.getProject().getBaseDir();
221231
Module module = getSelectModule();
222-
if (module!=null && module.getModuleFile()!=null) {
223-
path = module.getModuleFile().getParent();
232+
if (module!=null) {
233+
path = VirtualFileManager.getInstance().findFileByUrl("file://" + new File(module.getModuleFilePath()).getParent());
224234
}
225235
VirtualFile virtualFile = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), cacheDataUtils.getProject(), path);
226236
if (virtualFile != null) {
@@ -264,8 +274,8 @@ private Module getSelectModule() {
264274
private String getBasePath() {
265275
Module module = getSelectModule();
266276
String baseDir = cacheDataUtils.getProject().getBasePath();
267-
if (module!=null && module.getModuleFile()!=null) {
268-
baseDir = module.getModuleFile().getParent().getPath();
277+
if (module!=null) {
278+
baseDir = new File(module.getModuleFilePath()).getParent();
269279
}
270280
// 针对Maven项目
271281
File file = new File(baseDir + "/src/main/java");

0 commit comments

Comments
 (0)