com.kuangkie.carbon.common.IntegrationMsg Maven / Gradle / Ivy
The newest version!
package com.kuangkie.carbon.common;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import com.kuangkie.carbon.enun.MessageState;
public class IntegrationMsg {
private String code;
private MessageState state;
public IntegrationMsg(MessageState state, String code) {
this.state = state;
this.code = code;
}
private Collection debug, info, warn, refuse, error;
private Map extendMsgMap;
public void setExtendMsg(Map extendMsgMap) {
// if(extendMsgMap!=null) {
// this.extendMsgMap.clear();
// this.extendMsgMap.putAll(extendMsgMap);
// }
this.extendMsgMap=extendMsgMap;
}
public Map getExtendMsgMap(){
return extendMsgMap;
}
public Object getExtendMsg(String key){
return extendMsgMap==null?null:extendMsgMap.get(key);
}
public String getExtendMsgString(String key){
if(extendMsgMap==null) {
return null;
}else if(extendMsgMap.containsKey(key)) {
return extendMsgMap.get(key).toString();
}else {
return null;
}
}
public String getRecordCode() {
return code;
}
public void setRecordCode(String code) {
this.code = code;
}
public MessageState getState() {
return state;
}
public void setState(MessageState state) {
this.state = state;
}
public Collection getInfo() {
return info;
}
public void setInfo(Collection info) {
this.info = info;
}
public Collection getWarn() {
return warn;
}
public void setWarn(Collection warn) {
this.warn = warn;
}
public Collection getRefuse() {
return refuse;
}
public void setRefuse(Collection refuse) {
this.refuse = refuse;
}
public Collection getDebug() {
return debug;
}
public void setDebug(Collection debug) {
this.debug = debug;
}
public Collection getError() {
return error;
}
public void setError(Collection syserror) {
this.error = syserror;
}
public boolean success() {
return MessageState.SUCCESS == getState();
}
public String getWarnMsgContentStr() {
Collection allMsgs = new ArrayList<>();
Collection msgs = this.getError();
if (msgs != null) {
allMsgs.addAll(msgs);
}
msgs = this.getRefuse();
if (msgs != null) {
allMsgs.addAll(msgs);
}
msgs = this.getWarn();
if (msgs != null) {
allMsgs.addAll(msgs);
}
if (allMsgs.isEmpty()) {
return null;
} else {
return toContentString(allMsgs);
}
}
public String getWarnMsgStr() {
Collection allMsgs = new ArrayList<>();
Collection msgs = this.getError();
if (msgs != null) {
allMsgs.addAll(msgs);
}
msgs = this.getRefuse();
if (msgs != null) {
allMsgs.addAll(msgs);
}
msgs = this.getWarn();
if (msgs != null) {
allMsgs.addAll(msgs);
}
if (allMsgs.isEmpty()) {
return null;
} else {
return toString(allMsgs);
}
}
public String getRefuseMsgContentStr() {
Collection allMsgs = new ArrayList<>();
Collection msgs = this.getError();
if (msgs != null) {
allMsgs.addAll(msgs);
}
msgs = this.getRefuse();
if (msgs != null) {
allMsgs.addAll(msgs);
}
if (allMsgs.isEmpty()) {
return null;
} else {
return toContentString(allMsgs);
}
}
public String getRefuseMsgStr() {
Collection allMsgs = new ArrayList<>();
Collection msgs = this.getError();
if (msgs != null) {
allMsgs.addAll(msgs);
}
msgs = this.getRefuse();
if (msgs != null) {
allMsgs.addAll(msgs);
}
if (allMsgs.isEmpty()) {
return null;
} else {
return toString(allMsgs);
}
}
private String toString(Collection msgs) {
if (msgs != null && !msgs.isEmpty()) {
StringBuilder sb = new StringBuilder();
msgs.forEach(m -> {
sb.append(m.toString());
sb.append("; ");
});
return sb.toString();
} else {
return "";
}
}
private String toContentString(Collection msgs) {
if (msgs != null && !msgs.isEmpty()) {
StringBuilder sb = new StringBuilder(" ");
msgs.forEach(m -> {
sb.append(m.getContent());
sb.append("; ");
});
return sb.toString();
} else {
return "";
}
}
}