Merge branch 'master' into group5-dictTag

pull/3/head
liuhanqing 2021-01-17 16:53:08 +08:00
commit 52bd2049ec
18 changed files with 64 additions and 49 deletions

View File

@ -19,6 +19,7 @@
<module>sms-api</module> <module>sms-api</module>
<module>sms-sdk-aliyun</module> <module>sms-sdk-aliyun</module>
<module>sms-sdk-tencent</module> <module>sms-sdk-tencent</module>
<module>sms-business-validation</module>
<module>sms-spring-boot-starter</module> <module>sms-spring-boot-starter</module>
</modules> </modules>

View File

@ -6,12 +6,12 @@
<parent> <parent>
<groupId>cn.stylefeng.roses</groupId> <groupId>cn.stylefeng.roses</groupId>
<artifactId>kernel-s-system</artifactId> <artifactId>kernel-d-sms</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<artifactId>system-business-sms</artifactId> <artifactId>sms-business-validation</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -18,23 +18,29 @@ import java.lang.reflect.Type;
/** /**
* jackson * jackson
* <p> * <p>
* 使@JsonSerialize(using=DictValueSerializer.class) * 使
* <p>
* 1.pojo @JsonSerialize(using=DictValueSerializer.class)
* 2.pojo"字典类型编码|字典的编码"
* *
* @author liuhanqing * @author liuhanqing
* @date 2021/1/16 22:21 * @date 2021/1/16 22:21
*/ */
@JacksonStdImpl @JacksonStdImpl
public final class DictValueSerializer public final class DictValueSerializer extends StdScalarSerializer<Object> {
extends StdScalarSerializer<Object> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* *
*/ */
private static final String SEPARATOR = "|"; private static final String SEPARATOR = "|";
/** /**
* *
*/ */
private static final String NULL_STR = "null"; private static final String NULL_STR = "null";
/** /**
* *
*/ */
@ -58,43 +64,55 @@ public final class DictValueSerializer
return; return;
} }
String strVal = value.toString(); // 被序列化字段的值
// 判断需要翻译字典值是否为不空且含有字典标识 String fieldValue = value.toString();
if (StrUtil.isNotBlank(strVal) && strVal.indexOf(SEPARATOR) > 0) {
// 如果为空或者没有分隔符返回空串
if (StrUtil.isBlank(fieldValue) || !fieldValue.contains(SEPARATOR)) {
fieldValue = StrUtil.EMPTY;
gen.writeString(fieldValue);
return;
}
// 分隔需要序列化的值 // 分隔需要序列化的值
String[] dictArr = strVal.split("\\|"); String[] dictTypeCodeAndDictCode = fieldValue.split("\\|");
if (dictArr.length == 2) {
// 获取字典编码值 // 如果分割出来不是2则格式不正确
String dictCode = dictArr[1]; if (dictTypeCodeAndDictCode.length != 2) {
if (StrUtil.isBlank(dictCode) || NULL_STR.equals(dictArr[1])) { fieldValue = StrUtil.EMPTY;
strVal = StrUtil.EMPTY; gen.writeString(fieldValue);
} else { return;
// 获取字典名称逻辑,多个名称用逗号分隔 }
String[] codeArr = dictCode.split(VALUE_SEPARATOR);
if (codeArr.length > 0) { // 获取字典类型编码和字典编码
if (codeArr.length == 1) { String dictTypeCode = dictTypeCodeAndDictCode[0];
strVal = DictContext.me().getDictName(dictArr[0], codeArr[0]); String dictCode = dictTypeCodeAndDictCode[1];
} else {
StringBuffer sb = new StringBuffer(); // 字典code为空返回空串
for (String dic : codeArr) { if (StrUtil.isBlank(dictCode) || NULL_STR.equals(dictCode)) {
String dicVal = DictContext.me().getDictName(dictArr[0], dic); fieldValue = StrUtil.EMPTY;
if (StrUtil.isNotBlank(dicVal)) { gen.writeString(fieldValue);
sb.append(dicVal).append(","); return;
}
// 字典编码是多个,存在逗号分隔符
if (dictCode.contains(VALUE_SEPARATOR)) {
String[] dictCodeArray = dictCode.split(VALUE_SEPARATOR);
StringBuilder dictNames = new StringBuilder();
for (String singleDictCode : dictCodeArray) {
String dictName = DictContext.me().getDictName(dictTypeCode, singleDictCode);
if (StrUtil.isNotBlank(dictName)) {
dictNames.append(dictName).append(VALUE_SEPARATOR);
} }
} }
if (StrUtil.isNotEmpty(sb)) { fieldValue = StrUtil.removeSuffix(dictNames.toString(), VALUE_SEPARATOR);
strVal = StrUtil.removeSuffix(sb.toString(), ","); gen.writeString(fieldValue);
} else { return;
strVal = dictArr[1];
} }
}
} // 字典编码是一个
} fieldValue = DictContext.me().getDictName(dictTypeCode, dictCode);
} else { gen.writeString(fieldValue);
strVal = StrUtil.EMPTY;
}
}
gen.writeString(strVal);
} }
@Override @Override
@ -113,4 +131,5 @@ public final class DictValueSerializer
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException {
visitStringFormat(visitor, typeHint); visitStringFormat(visitor, typeHint);
} }
} }

View File

@ -25,7 +25,6 @@
<module>system-business-menu</module> <module>system-business-menu</module>
<module>system-business-notice</module> <module>system-business-notice</module>
<module>system-business-login-log</module> <module>system-business-login-log</module>
<module>system-business-sms</module>
<module>system-spring-boot-starter</module> <module>system-spring-boot-starter</module>
</modules> </modules>

View File

@ -78,13 +78,9 @@ public class SysNotice extends BaseEntity {
@TableField(value = "del_flag", fill = FieldFill.INSERT) @TableField(value = "del_flag", fill = FieldFill.INSERT)
private String delFlag; private String delFlag;
/*public String getPriorityLevelValue(){ /**
AtomicReference<String> value = new AtomicReference<>(""); *
Optional.ofNullable(this.priorityLevel).ifPresent(val ->{ */
value.set(MessagePriorityLevelEnum.getName(this.priorityLevel));
});
return value.get();
}*/
@JsonSerialize(using = DictValueSerializer.class) @JsonSerialize(using = DictValueSerializer.class)
public String getPriorityLevelValue() { public String getPriorityLevelValue() {
return "priority_level|" + this.priorityLevel; return "priority_level|" + this.priorityLevel;