You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
962 B

1 month ago
  1. package com.gaotao.common.utils;
  2. import com.gaotao.modules.api.dao.SysErrorLogMapper;
  3. import com.gaotao.modules.api.entity.SysErrorLog;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6. import org.springframework.transaction.annotation.Propagation;
  7. import org.springframework.transaction.annotation.Transactional;
  8. /**
  9. * 错误日志保存服务
  10. * 使用独立事务保存日志避免被外层事务回滚
  11. *
  12. * @author rqrq
  13. * @date 2026/01/26
  14. */
  15. @Service
  16. public class ErrorLogService {
  17. @Autowired
  18. private SysErrorLogMapper sysErrorLogMapper;
  19. /**
  20. * 在独立事务中保存错误日志
  21. * REQUIRES_NEW开启新事务不受外层事务影响
  22. *
  23. * @param log 错误日志实体
  24. */
  25. @Transactional(propagation = Propagation.REQUIRES_NEW)
  26. public void saveInNewTransaction(SysErrorLog log) {
  27. sysErrorLogMapper.insert(log);
  28. }
  29. }