mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-05 05:07:46 +08:00
🎨 微信模版消息行业获取的代码优化
This commit is contained in:
parent
6e2babd46b
commit
17aaba2496
@ -193,12 +193,13 @@ public enum WxMpTemplateIndustryEnum {
|
||||
/**
|
||||
* 查找行业
|
||||
*
|
||||
* @param industry 二级行业名称
|
||||
* @param firstClass 主行业名称
|
||||
* @param secondClass 副行业名称
|
||||
* @return .
|
||||
*/
|
||||
public static WxMpTemplateIndustryEnum findBySecondary(String industry) {
|
||||
public static WxMpTemplateIndustryEnum findByClass(String firstClass, String secondClass) {
|
||||
for (WxMpTemplateIndustryEnum industryEnum : WxMpTemplateIndustryEnum.values()) {
|
||||
if (industryEnum.secondClass.contains(industry)) {
|
||||
if (industryEnum.firstClass.equals(firstClass) && industryEnum.secondClass.contains(secondClass)) {
|
||||
return industryEnum;
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,9 @@ public class WxMpIndustryGsonAdapter implements JsonSerializer<WxMpTemplateIndus
|
||||
}
|
||||
|
||||
private WxMpTemplateIndustryEnum convertFromJson(JsonObject json) {
|
||||
String firstClass = GsonHelper.getString(json, "first_class");
|
||||
String secondClass = GsonHelper.getString(json, "second_class");
|
||||
final WxMpTemplateIndustryEnum industryEnum = WxMpTemplateIndustryEnum.findBySecondary(secondClass);
|
||||
final WxMpTemplateIndustryEnum industryEnum = WxMpTemplateIndustryEnum.findByClass(firstClass, secondClass);
|
||||
if (industryEnum != null) {
|
||||
return industryEnum;
|
||||
}
|
||||
@ -38,7 +39,7 @@ public class WxMpIndustryGsonAdapter implements JsonSerializer<WxMpTemplateIndus
|
||||
secondClass = secondClass.split("\\|")[1];
|
||||
}
|
||||
|
||||
return WxMpTemplateIndustryEnum.findBySecondary(secondClass);
|
||||
return WxMpTemplateIndustryEnum.findByClass(firstClass, secondClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user