派生自 projectDept/qhighschool

EricsHu
2023-11-24 0e62c15e4b010ffa2d5cff9474f3fd389e369338
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 ;
    }
 
}