From eae8b4cff9fb31df7bab8dea5e215bcf2a75a334 Mon Sep 17 00:00:00 2001 From: makejava <1353036300@qq.com> Date: Fri, 16 Jun 2023 10:49:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E9=85=8D=E7=BD=AE=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=8F=8D=E5=BA=8F=E5=88=97=E5=8C=96=E6=97=B6=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E4=BF=A1=E6=81=AF=E4=B8=A2=E5=A4=B1=EF=BC=8C=E6=94=B9?= =?UTF-8?q?=E8=BF=9B=E4=B8=BA=E7=BC=96=E7=A0=81=E5=90=8E=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E3=80=82=E7=AE=80=E5=8C=96=E5=AD=98=E5=82=A8=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E4=B8=A2=E5=A4=B1=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sjhy/plugin/dto/TableInfoSettingsDTO.java | 29 ++++++++++++++----- .../impl/TableInfoSettingsServiceImpl.java | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/sjhy/plugin/dto/TableInfoSettingsDTO.java b/src/main/java/com/sjhy/plugin/dto/TableInfoSettingsDTO.java index 8ea9f48..4e4f94f 100644 --- a/src/main/java/com/sjhy/plugin/dto/TableInfoSettingsDTO.java +++ b/src/main/java/com/sjhy/plugin/dto/TableInfoSettingsDTO.java @@ -7,12 +7,14 @@ import com.intellij.openapi.ui.Messages; import com.intellij.psi.PsiClass; import com.sjhy.plugin.dict.GlobalDict; import com.sjhy.plugin.entity.TableInfo; +import com.sjhy.plugin.tool.JSON; import com.sjhy.plugin.tool.ReflectionUtils; +import com.sjhy.plugin.tool.StringUtils; import lombok.Data; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.HashMap; +import java.util.Base64; import java.util.Map; import java.util.TreeMap; @@ -25,7 +27,7 @@ import java.util.TreeMap; */ @Data public class TableInfoSettingsDTO { - private Map tableInfoMap; + private Map tableInfoMap; public TableInfoSettingsDTO() { this.tableInfoMap = new TreeMap<>(); @@ -71,9 +73,9 @@ public class TableInfoSettingsDTO { @SuppressWarnings("Duplicates") public TableInfo readTableInfo(PsiClass psiClass) { String key = generateKey(psiClass); - TableInfoDTO dto = this.tableInfoMap.get(key); + TableInfoDTO dto = decode(this.tableInfoMap.get(key)); dto = new TableInfoDTO(dto, psiClass); - this.tableInfoMap.put(key, dto); + this.tableInfoMap.put(key, encode(dto)); return dto.toTableInfo(psiClass); } @@ -86,10 +88,10 @@ public class TableInfoSettingsDTO { @SuppressWarnings("Duplicates") public TableInfo readTableInfo(DbTable dbTable) { String key = generateKey(dbTable); - TableInfoDTO dto = this.tableInfoMap.get(key); + TableInfoDTO dto = decode(this.tableInfoMap.get(key)); // 表可能新增了字段,需要重新合并保存 dto = new TableInfoDTO(dto, dbTable); - this.tableInfoMap.put(key, dto); + this.tableInfoMap.put(key, encode(dto)); return dto.toTableInfo(dbTable); } @@ -112,7 +114,7 @@ public class TableInfoSettingsDTO { Messages.showInfoMessage(tableInfo.getName() + "表配置信息保存失败", GlobalDict.TITLE_INFO); return; } - this.tableInfoMap.put(key, TableInfoDTO.valueOf(tableInfo)); + this.tableInfoMap.put(key, encode(TableInfoDTO.valueOf(tableInfo))); } /** @@ -122,7 +124,7 @@ public class TableInfoSettingsDTO { */ public void resetTableInfo(DbTable dbTable) { String key = generateKey(dbTable); - this.tableInfoMap.put(key, new TableInfoDTO(null, dbTable)); + this.tableInfoMap.put(key, encode(new TableInfoDTO(null, dbTable))); } /** @@ -134,4 +136,15 @@ public class TableInfoSettingsDTO { String key = generateKey(dbTable); this.tableInfoMap.remove(key); } + + private static String encode(TableInfoDTO tableInfo) { + return Base64.getEncoder().encodeToString(JSON.toJson(tableInfo).getBytes()); + } + + private static TableInfoDTO decode(String base64) { + if (StringUtils.isEmpty(base64)) { + return null; + } + return JSON.parse(new String(Base64.getDecoder().decode(base64)), TableInfoDTO.class); + } } diff --git a/src/main/java/com/sjhy/plugin/service/impl/TableInfoSettingsServiceImpl.java b/src/main/java/com/sjhy/plugin/service/impl/TableInfoSettingsServiceImpl.java index 61896bc..d2daef5 100644 --- a/src/main/java/com/sjhy/plugin/service/impl/TableInfoSettingsServiceImpl.java +++ b/src/main/java/com/sjhy/plugin/service/impl/TableInfoSettingsServiceImpl.java @@ -17,7 +17,7 @@ import java.util.Objects; * @version 1.0.0 * @date 2021/08/14 15:20 */ -@State(name = "EasyCodeTableSetting", storages = @Storage("easyCodeTableSetting.xml")) +@State(name = "EasyCodeTableSetting", storages = @Storage("easyCodeTableSettingEncode.xml")) public class TableInfoSettingsServiceImpl implements TableInfoSettingsService { private TableInfoSettingsDTO tableInfoSettings = new TableInfoSettingsDTO();