
package org.tio.sitexxx.service.vo.wx;

import lombok.Data;
import org.tio.sitexxx.service.vo.Const;

/**
 * 系统消息vo
 * 
 * @author xufei 2020年2月10日 下午3:12:31
 */
@Data
public class SysMsgVo {
	public SysMsgVo(String opernick, String msgbody, String tonicks, String key) {
		this.opernick = opernick;
		this.msgbody = msgbody;
		this.tonicks = tonicks;
		this.msgkey = key;
	}

	public SysMsgVo(String operateNick, String toNick, Const.Template template) {
		this.opernick = operateNick;
		this.tonicks = toNick;
		this.msgbody = template.getTemplate();
		this.msgkey = template.getKey();
	}

	/**
	 * 操作码
	 */
	private Short opercode;
	
	/**
	 * 原始消息
	 */
	private String srctext;
	
	/**
	 * 原始消息类型
	 */
	private Short srcmsgtype;
	
	/**
	 * 操作昵称
	 */
	private String opernick;

	/**
	 * 消息体
	 */
	private String msgbody;

	/**
	 * 消息key
	 */
	private String msgkey;

	/**
	 * 操作者转义字符
	 */
	public static String OPERESCAPE = "%%%";

	/**
	 * 接收者转义字符
	 */
	public static String TOESCAPE = "###";

	 /**
	 * 接收者的分割符
	 */
	public static char splitchar = '、';

	/**
	 * 被操作者
	 */
	private String tonicks;

	public String toText() {
		return msgbody.replaceAll(TOESCAPE, "\"" + tonicks + "\"").replaceAll(OPERESCAPE, "\"" + opernick + "\"");
	}

	/**
	 * 是否屏蔽
	 * @return false:屏蔽 true:不屏蔽
	 */
	public boolean isBin(){
		return !(msgkey.equals(Const.MsgTemplateKey.GROUP_BAN) || msgkey.equals(Const.MsgTemplateKey.GROUP_CANCEL_BAN)
				|| msgkey.equals(Const.Template.JOIN.getKey()) || msgkey.equals(Const.Template.LEAVE.getKey())
				|| msgkey.equals(Const.MsgTemplateKey.GROUP_FORBIDDEN) || msgkey.equals(Const.MsgTemplateKey.GROUP_CANCEL_FORBIDDEN));
	}
}
