From 0eb673e59446a09ca045596875991cb4dbd3bfc2 Mon Sep 17 00:00:00 2001 From: grimm <1769111741@qq.com> Date: Fri, 29 Dec 2023 18:39:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A1=A8=E5=86=85?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8=E8=BF=94=E5=9B=9E=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ljsd/jieling/exception/ErrorCode.java | 4 ++ .../jieling/exception/ErrorCodeException.java | 4 +- .../exception/ErrorTableException.java | 72 +++++++++++++++++++ .../java/config/SErrorCodeEerverConfig.java | 15 ++-- 4 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorTableException.java diff --git a/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCode.java b/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCode.java index d71c13ead..c586086cb 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCode.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCode.java @@ -226,6 +226,10 @@ public enum ErrorCode implements IErrorCode { this.errMsg = errMsg; } + public void setCodeId(int codeId) { + this.codeId = codeId; + } + @Override public int code() { return codeId; diff --git a/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCodeException.java b/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCodeException.java index 7c2576314..e7d32eab6 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCodeException.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCodeException.java @@ -67,7 +67,7 @@ public class ErrorCodeException extends Exception { } public String toString() { - return "[CODE: " + this.errorCode.code() + "][" + this.errorCode.message() + "][" +((super.getMessage()==null)?"":super.getMessage())+ "][" +((params!=null&¶ms.size()!=0)?params.toString():"")+"] "; + return "[CODE: " + this.errorCode.code() + "][" + this.errorCode.message() + "][" +((super.getMessage()==null)?"":super.getMessage())+ "][" +((params!=null&& !params.isEmpty())?params.toString():"")+"] "; } public List getParams() { @@ -75,6 +75,6 @@ public class ErrorCodeException extends Exception { } public String getMessage() { - return "" + super.getMessage(); + return super.getMessage(); } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorTableException.java b/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorTableException.java new file mode 100644 index 000000000..ee3a8d793 --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorTableException.java @@ -0,0 +1,72 @@ +package com.ljsd.jieling.exception; + +import config.SErrorCodeEerverConfig; +import util.StringUtil; + +import java.util.ArrayList; +import java.util.List; + +/** + * Description: 逻辑异常包装类 + * Author: zsx + * CreateDate: 2019/10/21 11:44 + */ +public class ErrorTableException extends Exception { + private int id; + private String msg; + private List params; + + public ErrorTableException(int id, String msg) { + this.id = id; + this.msg = msg; + } + + public ErrorTableException(int id, String msg, List params) { + this.id = id; + this.msg = msg; + this.params = params; + } + + public ErrorTableException(int id) { + String message = SErrorCodeEerverConfig.errorTableMap.get(id); + if (StringUtil.isEmpty(message)){ + this.id = -1; + this.msg = "操作失败,并未找到错误码:{"+id+"},请联系管理员"; + }else { + this.id = id; + this.msg = message; + } + } + + public void setId(int id) { + this.id = id; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public void setParams(List params) { + this.params = params; + } + + public int getCode() { + return this.id; + } + + public String getMsg() { + return msg; + } + + public String getMessage() { + return super.getMessage(); + } + + public List getParams() { + return null == params ? new ArrayList<>() : params; + } + + public String toString() { + return "[CODE: " + this.getCode() + "][" + this.getMsg() + "][" +((super.getMessage()==null)?"":super.getMessage())+ "][" +((params!=null&& !params.isEmpty())?params.toString():"")+"] "; + } +} diff --git a/tablemanager/src/main/java/config/SErrorCodeEerverConfig.java b/tablemanager/src/main/java/config/SErrorCodeEerverConfig.java index e22321e01..70ca694bf 100644 --- a/tablemanager/src/main/java/config/SErrorCodeEerverConfig.java +++ b/tablemanager/src/main/java/config/SErrorCodeEerverConfig.java @@ -4,13 +4,16 @@ import manager.STableManager; import manager.Table; import java.text.MessageFormat; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @Table(name ="ErrorCodeEerverConfig") public class SErrorCodeEerverConfig implements BaseConfig { - private static Map errorCodeMap; + private static Map errorCodeMap; public static Map errorMap; + public static Map errorTableMap = new HashMap<>(); + private int id; private String key; @@ -26,13 +29,15 @@ public class SErrorCodeEerverConfig implements BaseConfig { Map config = STableManager.getConfig(SErrorCodeEerverConfig.class); Map errorCodeEerverConfigMap = new ConcurrentHashMap<>(); Map tempErrorMap = new ConcurrentHashMap<>(); - for (Map.Entry entry :config.entrySet()){ - SErrorCodeEerverConfig sErrorCodeEerverConfig = entry.getValue(); - errorCodeEerverConfigMap.put(sErrorCodeEerverConfig.getkey(),sErrorCodeEerverConfig); - tempErrorMap.put(sErrorCodeEerverConfig.getid(),sErrorCodeEerverConfig); + Map tableErrorMap = new HashMap<>(); + for (SErrorCodeEerverConfig errorConfig : config.values()) { + errorCodeEerverConfigMap.put(errorConfig.getkey(),errorConfig); + tempErrorMap.put(errorConfig.getid(),errorConfig); + tableErrorMap.put(errorConfig.getid(), errorConfig.getvalue()); } errorCodeMap = errorCodeEerverConfigMap; errorMap = tempErrorMap; + errorTableMap = tableErrorMap; } From ea310891c52bf426259c9ca90dc59d3a71e4f931 Mon Sep 17 00:00:00 2001 From: grimm <1769111741@qq.com> Date: Sun, 31 Dec 2023 15:36:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B3=95=E5=AE=9D=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=8A=A9=E6=88=98=E5=85=8B=E9=9A=86?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=85=A5=E5=BA=93=E6=95=B0=E6=8D=AE=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ljsd/jieling/logic/dao/Baubles.java | 7 +++++ .../ljsd/jieling/logic/dao/PropertyItem.java | 9 +++++++ .../com/ljsd/jieling/util/CBean2Proto.java | 26 ++++++++++--------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/Baubles.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/Baubles.java index 343ce2993..82ba3f161 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/Baubles.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/Baubles.java @@ -15,6 +15,13 @@ public class Baubles extends PropertyItem{ public Baubles() { } + // 克隆 + public Baubles(Baubles baubles) { + super(baubles); + this.masterId = baubles.getMasterId(); + this.blessList = new HashSet<>(baubles.getBlessList()); + } + public Baubles(int uid, int equipId) { super(uid, equipId); } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/PropertyItem.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/PropertyItem.java index 70e3691a8..6fd98b2f8 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/PropertyItem.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/PropertyItem.java @@ -25,6 +25,15 @@ public class PropertyItem extends MongoBase { this.equipId = equipId; } + // 克隆 + public PropertyItem(PropertyItem item) { + this.id = item.getId(); + this.equipId = item.getEquipId(); + this.level = item.getLevel(); + this.buildLevel = item.getBuildLevel(); + this.heroId = item.getHeroId(); + } + public String getId() { return id; } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/util/CBean2Proto.java b/serverlogic/src/main/java/com/ljsd/jieling/util/CBean2Proto.java index f1adf8b73..ad1c6b524 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/util/CBean2Proto.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/util/CBean2Proto.java @@ -287,22 +287,23 @@ public class CBean2Proto { HelpTypeEnum type = HelpTypeEnum.getType(hero.getPropertyId()); // 英雄镜像 EquipManager equipManager = user.getEquipManager(); + Hero clone = hero.clone(); // 魂宝灵宝镜像 - List jewels = buildPropertyItemList(equipManager, hero.getJewelInfo()); + List jewels = buildPropertyItemList(equipManager, clone.getJewelInfo()); // 法相 - List faxiangs = buildPropertyItemList(equipManager, hero.getFaxiangList()); + List faxiangs = buildPropertyItemList(equipManager, clone.getFaxiangList()); // 结果返回,援助类型不在这里写 HelpHero helpHero = new HelpHero(); helpHero.setUid(user.getId()); helpHero.setFunctionType(type); helpHero.setCreatTime(TimeUtils.now()); - helpHero.setHero(hero); + helpHero.setHero(clone); helpHero.setState(0); helpHero.setJewels(jewels); helpHero.setFaxiangs(faxiangs); helpHero.setFourTotalTier(user.getPlayerInfoManager().getFourChallengeTotal()); - helpHero.setBaubles(equipManager.getBaubles(hero.getBauBlesId())); - helpHero.setBaublesList(buildBaublesList(equipManager, hero.getBauBlesId())); + helpHero.setBaubles(equipManager.getBaubles(clone.getBauBlesId())); + helpHero.setBaublesList(buildBaublesList(equipManager, clone.getBauBlesId())); return helpHero; } @@ -310,17 +311,18 @@ public class CBean2Proto { * 克隆装备信息 */ public static List buildPropertyItemList(EquipManager equipManager, Set infoList){ - List List = new ArrayList<>(); + List items = new ArrayList<>(); if (infoList == null || infoList.isEmpty()){ - return List; + return items; } for (String id: infoList){ PropertyItem item = equipManager.getEquip(id); if (item != null){ - List.add(item); + PropertyItem clone = new PropertyItem(item); + items.add(clone); } } - return List; + return items; } /** @@ -338,10 +340,10 @@ public class CBean2Proto { if (blessList != null && !blessList.isEmpty()){ for (String id: blessList){ Baubles item = equipManager.getBaubles(id); - if (item == null){ - continue; + if (item != null){ + Baubles clone = new Baubles(item); + list.add(clone); } - list.add(item); } } return list;