package com.qxueyou.scc.base.service.impl;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.qxueyou.scc.base.model.Result;
|
import com.qxueyou.scc.base.service.IONSExceptionLogService;
|
import com.qxueyou.scc.base.util.TraceUtils;
|
import com.qxueyou.scc.sys.model.SysLog;
|
import com.qxueyou.scc.sys.service.ISysLogService;
|
|
/**
|
* ONS严格异常处理,消息处理都捕获Exception,并且不抛出,将异常存入表中
|
* @author ody.yuan
|
*
|
*/
|
@Service(value = "ONSExceptionLogService")
|
public class ONSExceptionLogService implements IONSExceptionLogService {
|
|
@Autowired
|
ISysLogService syslogService;
|
|
@Override
|
@Transactional(propagation=Propagation.REQUIRES_NEW)
|
public Result logSaveExceptionLog(String topic, String msgType,String businessId ,String desp ) {
|
|
// 处理长度
|
String currTopic = null == topic ? "" : topic ;
|
String currDesp = StringUtils.isNotBlank(desp) && desp.length() > 125 ? desp.substring(0,125) : desp ;
|
|
SysLog log = new SysLog();
|
TraceUtils.setCreateTrace(log);
|
|
log.setContent(getContent(currTopic, businessId, msgType));
|
log.setModule("ONS_EXCEPTION_LOG");
|
log.setDesp( currDesp );
|
log.setDeleteFlag(false);
|
log.setType(SysLog.LOG_TYPE_BUSINESS);
|
|
this.syslogService.insertLog(log);
|
|
return new Result(true);
|
|
}
|
|
private String getContent(String currTopic, String businessId ,String msgType){
|
String content = currTopic.concat(" - ");
|
if(StringUtils.isNotBlank(msgType)){
|
content = content.concat(msgType).concat(" - ");
|
}
|
if(StringUtils.isNotBlank(businessId)){
|
content = content.concat(businessId);
|
}
|
return content.length() > 255 ? content.substring(0,255) : content ;
|
}
|
|
}
|