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