| | |
| | | package com.whyc.util; |
| | | |
| | | import com.whyc.pojo.UserInf; |
| | | import com.whyc.service.UserLogService; |
| | | import com.whyc.constant.YamlProperties; |
| | | import com.whyc.pojo.DocUser; |
| | | import com.whyc.service.DocLogService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.system.ApplicationHome; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | @Component |
| | | public class CommonUtil { |
| | | |
| | | private static UserLogService userLogService; |
| | | private static DocLogService docLogService; |
| | | |
| | | @Autowired |
| | | public void setUserLogService(UserLogService userLogService) { |
| | | CommonUtil.userLogService = userLogService; |
| | | public void setUserLogService(DocLogService docLogService) { |
| | | CommonUtil.docLogService = docLogService; |
| | | } |
| | | |
| | | /**获取当前Session中的属性user*/ |
| | | public static UserInf getUser(HttpServletRequest request) { |
| | | return (UserInf) request.getSession().getAttribute("user"); |
| | | public static DocUser getUser(HttpServletRequest request) { |
| | | return (DocUser) request.getSession().getAttribute("user"); |
| | | } |
| | | |
| | | public static String classesPath(){ |
| | |
| | | return jarFile.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 获取存放文件的根路径 |
| | | * @return 返回存放文件的根路径 |
| | | */ |
| | | public static File getRootFile(){ |
| | | ApplicationHome applicationHome = new ApplicationHome(CommonUtil.class); |
| | | File jarFile = applicationHome.getDir(); |
| | | String baseDirPath; |
| | | if(YamlProperties.runModel == 1) { |
| | | //开发路径 |
| | | baseDirPath = jarFile.getParentFile().toString()+File.separator+"doc_file"+File.separator; |
| | | }else { |
| | | //打包路径 |
| | | baseDirPath = jarFile.toString()+File.separator+"doc_file"+File.separator; |
| | | } |
| | | return new File(baseDirPath); |
| | | } |
| | | |
| | | /**手动记录特定日志*/ |
| | | public static void record(long uId, int operationType, String msg){ |
| | | userLogService.record(uId,operationType,msg); |
| | | docLogService.record(uId,operationType,msg); |
| | | } |
| | | |
| | | /**手动记录特定日志*/ |
| | | public static void record(long uId, int operationType, String msg,String msgDetail){ |
| | | userLogService.record(uId,operationType,msg,msgDetail); |
| | | docLogService.record(uId,operationType,msg,msgDetail); |
| | | } |
| | | /**手动记录特定日志*/ |
| | | public static void record2(HttpServletRequest request,long uId, int operationType, String msg,String msgDetail){ |
| | | userLogService.record2(request,uId,operationType,msg,msgDetail); |
| | | docLogService.record2(request,uId,operationType,msg,msgDetail); |
| | | } |
| | | } |