1。需求 目前有这么个问题,有两个系统CSP和OMS,这俩系统共用的是同一套日志操作:Log;目前想区分下这俩系统的日志操作,那没办法了,只能重写一份Log的日志操作; 你也可以参照若依框架的日志系统实现。2。新建一张日志表 sysopercsplogNavicatPremiumDataTransferSourceServer:jpcscadminSourceServerType:MySQLSourceServerVersion:50728SourceHost:rmuf6miy84gu8u433x9。mysql。rds。aliyuncs。com:3306SourceSchema:jpomsTargetServerType:MySQLTargetServerVersion:50728FileEncoding:65001Date:0809202209:21:45SETNAMESutf8mb4;SETFOREIGNKEYCHECKS0;TablestructureforsysopercsplogDROPTABLEIFEXISTSsysopercsplog;CREATETABLEsysopercsplog(operidbigint(20)NOTNULLAUTOINCREMENTCOMMENTahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志a主键,titlevarchar(50)CHARACTERSETutf8mb4COLLATEutf8mb4generalciNULLDEFAULTCOMMENT模块标题,businesstypeint(2)NULLDEFAULT0COMMENT业务类型(0其它,1新增,2修改,3删除,4授权,5导出,6导入,7强退,8生成代码,9清空数据),methodvarchar(100)CHARACTERSETutf8mb4COLLATEutf8mb4generalciNULLDEFAULTCOMMENT方法名称,requestmethodvarchar(10)CHARACTERSETutf8mb4COLLATEutf8mb4generalciNULLDEFAULTCOMMENT请求方式,operatortypeint(1)NULLDEFAULT0COMMENT操作类别(0其它1后台用户2手机端用户),opernamevarchar(50)CHARACTERSETutf8mb4COLLATEutf8mb4generalciNULLDEFAULTCOMMENT操作人员,deptnamevarchar(50)CHARACTERSETutf8mb4COLLATEutf8mb4generalciNULLDEFAULTCOMMENT部门名称,operurlvarchar(255)CHARACTERSETutf8mb4COLLATEutf8mb4generalciNULLDEFAULTCOMMENT请求URL,operipvarchar(128)CHARACTERSETutf8mb4COLLATEutf8mb4generalciNULLDEFAULTCOMMENT主机地址,operlocationvarchar(255)CHARACTERSETutf8mb4COLLATEutf8mb4generalciNULLDEFAULTCOMMENT操作地点,operparamvarchar(2000)CHARACTERSETutf8mb4COLLATEutf8mb4generalciNULLDEFAULTCOMMENT请求参数,jsonresulttextCHARACTERSETutf8mb4COLLATEutf8mb4generalciNULLCOMMENT返回参数,statusint(1)NULLDEFAULT0COMMENT操作状态(0正常1异常),errormsgvarchar(2000)CHARACTERSETutf8mb4COLLATEutf8mb4generalciNULLDEFAULTCOMMENT错误消息,opertimedatetimeNULLDEFAULTNULLCOMMENT操作时间,PRIMARYKEY(operid)USINGBTREE,INDEXidxtime(opertime,title,opername)USINGBTREE)ENGINEInnoDCHARACTERSETutf8mb4COLLATEutf8mb4generalciCOMMENTCSP系统操作ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志a记录;3。写相应的Controller层packagecom。juepeiscm。csp。controller。csplog;importcom。juepeiscm。admin。api。domain。SysOperLog;importcom。juepeiscm。common。core。controller。BaseController;importcom。juepeiscm。common。core。domain。AjaxResult;importcom。juepeiscm。common。core。page。TableDataInfo;importcom。juepeiscm。common。enums。BusinessType;importcom。juepeiscm。common。utils。poi。ExcelUtil;importcom。juepeiscm。csp。annotation。CspLog;importcom。juepeiscm。csp。domain。csplog。SysOperCspLog;importcom。juepeiscm。csp。service。csplog。ISysOperCspLogService;importorg。springframework。beans。factory。annotation。Autowired;importorg。springframework。security。access。prepost。PreAuthorize;importorg。springframework。web。bind。annotation。;importjava。util。List;操作CSP系统ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志aAuthor:py。sunDate:20229714:51RestControllerRequestMapping({csplogopercsplog})publicclassSysOperCsplogControllerextendsBaseController{AutowiredprivateISysOperCspLogServiceoperCspLogService;publicSysOperCsplogController(){}查询操作ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志a列表paramsysOperCspLogreturnPreAuthorize(ss。hasPermi(monitor:operlog:list))GetMapping({list})publicTableDataInfolist(SysOperCspLogsysOperCspLog){this。startPage();ListSysOperCspLoglistthis。operCspLogService。selectOperLogList(sysOperCspLog);returnthis。getDataTable(list);}查询系统模块的分类paramreturnGetMapping({listTitle})publicTableDataInfolistTitle(){this。startPage();ListStringlistthis。operCspLogService。selectOperLogListTitle();returnthis。getDataTable(list);}CspLog(title导出CSP系统ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志a,businessTypeBusinessType。EXPORT)PreAuthorize(ss。hasPermi(monitor:operlog:export))GetMapping({export})publicAjaxResultexport(SysOperCspLogoperLog){ListSysOperCspLoglistthis。operCspLogService。selectOperLogList(operLog);ExcelUtilSysOperCspLogutilnewExcelUtil(SysOperLog。class);returnutil。exportExcel(list,操作CSP系统ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志a);}CspLog(title操作CSP系统ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志a,businessTypeBusinessType。DELETE)PreAuthorize(ss。hasPermi(monitor:operlog:remove))DeleteMapping({{operIds}})publicAjaxResultremove(PathVariableLong〔〕operIds){returnthis。toAjax(this。operCspLogService。deleteOperLogByIds(operIds));}CspLog(title清除CSP系统ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志a,businessTypeBusinessType。CLEAN)PreAuthorize(ss。hasPermi(monitor:operlog:remove))DeleteMapping({clean})publicAjaxResultclean(){this。operCspLogService。cleanOperLog();returnAjaxResult。success();}}Service接口层packagecom。juepeiscm。csp。service。csplog;importcom。juepeiscm。admin。api。domain。SysOperLog;importcom。juepeiscm。csp。domain。csplog。SysOperCspLog;importjava。util。List;Author:py。sunDate:20229715:02publicinterfaceISysOperCspLogService{voidinsertOperlog(SysOperCspLogvar1);ListSysOperCspLogselectOperLogList(SysOperCspLogvar1);ListStringselectOperLogListTitle();intdeleteOperLogByIds(Long〔〕var1);SysOperLogselectOperLogById(Longvar1);voidcleanOperLog();}Service实现packagecom。juepeiscm。csp。service。impl。csplog;importcom。juepeiscm。admin。api。domain。SysOperLog;importcom。juepeiscm。common。core。domain。AjaxResult;importcom。juepeiscm。common。core。domain。entity。SysDept;importcom。juepeiscm。common。core。domain。entity。SysUser;importcom。juepeiscm。common。core。domain。model。LoginUser;importcom。juepeiscm。common。exception。CustomException;importcom。juepeiscm。common。utils。SecurityUtils;importcom。juepeiscm。common。utils。ServletUtils;importcom。juepeiscm。common。utils。StringUtils;importcom。juepeiscm。csp。domain。csplog。SysOperCspLog;importcom。juepeiscm。csp。mapper。csplog。SysOperCspLogMapper;importcom。juepeiscm。csp。service。csplog。ISysOperCspLogService;importcom。juepeiscm。framework。web。service。TokenService;importcom。juepeiscm。uam。service。ISysDeptService;importcom。juepeiscm。uam。version。UamVersion;importorg。apache。dubbo。config。annotation。Reference;importorg。springframework。beans。factory。annotation。Autowired;importorg。springframework。stereotype。Service;importjava。util。List;Author:py。sunDate:20229715:03ServicepublicclassSysOperCspLogServiceImplimplementsISysOperCspLogService{AutowiredprivateSysOperCspLogMapperoperLogMapper;AutowiredprivateTokenServicetokenService;Reference(versionUamVersion。idV)publicISysDeptServicedeptService;OverridepublicvoidinsertOperlog(SysOperCspLogsysOperCspLog){try{this。operLogMapper。insertOperlog(sysOperCspLog);}catch(Exceptione){e。printStackTrace();thrownewCustomException(CSP系统ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志a插入失败,请联系管理员!!!);}}OverridepublicListSysOperCspLogselectOperLogList(SysOperCspLogsysOperCspLog){returnthis。operLogMapper。selectOperLogList(sysOperCspLog);}OverridepublicListStringselectOperLogListTitle(){returnthis。operLogMapper。selectOperLogListTitle();}OverridepublicintdeleteOperLogByIds(Long〔〕operIds){returnthis。operLogMapper。deleteOperLogByIds(operIds);}OverridepublicSysOperLogselectOperLogById(LongoperId){returnthis。operLogMapper。selectOperLogById(operId);}OverridepublicvoidcleanOperLog(){this。operLogMapper。cleanOperLog();}}Mapper接口packagecom。juepeiscm。csp。mapper。csplog;importcom。juepeiscm。admin。api。domain。SysOperLog;importcom。juepeiscm。csp。domain。csplog。SysOperCspLog;importjava。util。List;Author:py。sunDate:20229715:06publicinterfaceSysOperCspLogMapper{voidinsertOperlog(SysOperCspLogvar1);ListSysOperCspLogselectOperLogList(SysOperCspLogsysOperCspLog);ListStringselectOperLogListTitle();intdeleteOperLogByIds(Long〔〕var1);SysOperLogselectOperLogById(Longvar1);voidcleanOperLog();}Mapper。xml(我用的是Mybatis)lt;?xmlversion1。0encodingUTF8?!DOCTYPEmapperPUBLICmybatis。orgDTDMapper3。0ENhttp:mybatis。orgdtdmybatis3mapper。dtdmappernamespacecom。juepeiscm。csp。mapper。csplog。SysOperCspLogMapperresultMaptypeSysOperCspLogidSysOperLogResultidpropertyoperIdcolumnoperidresultpropertytitlecolumntitleresultpropertybusinessTypecolumnbusinesstyperesultpropertymethodcolumnmethodresultpropertyrequestMethodcolumnrequestmethodresultpropertyoperatorTypecolumnoperatortyperesultpropertyoperNamecolumnopernameresultpropertydeptNamecolumndeptnameresultpropertyoperUrlcolumnoperurlresultpropertyoperIpcolumnoperipresultpropertyoperLocationcolumnoperlocationresultpropertyoperParamcolumnoperparamresultpropertyjsonResultcolumnjsonresultresultpropertystatuscolumnstatusresultpropertyerrorMsgcolumnerrormsgresultpropertyoperTimecolumnopertimeresultMapsqlidselectOperLogVoselectoperid,title,businesstype,method,requestmethod,operatortype,opername,deptname,operurl,operip,operlocation,operparam,jsonresult,status,errormsg,opertimefromsysopercsplogsqlinsertidinsertOperlogparameterTypeSysOperCspLoginsertintosysopercsplog(title,businesstype,method,requestmethod,operatortype,opername,deptname,operurl,operip,operlocation,operparam,jsonresult,status,errormsg,opertime)values({title},{businessType},{method},{requestMethod},{operatorType},{operName},{deptName},{operUrl},{operIp},{operLocation},{operParam},{jsonResult},{status},{errorMsg},sysdate())insertselectidselectOperLogListparameterTypeSysOperCspLogresultMapSysOperLogResultincluderefidselectOperLogVowhereiftesttitle!nullandtitle!ANDtitlelikeconcat(,{title},)ififtestbusinessType!nullandbusinessType!ANDbusinesstype{businessType}ififtestbusinessTypes!nullandbusinessTypes。length0ANDbusinesstypeinforeachcollectionbusinessTypesitembusinessTypeopen(separator,close){businessType}foreachififteststatus!nullANDstatus{status}ififtestoperName!nullandoperName!ANDopernamelikeconcat(,{operName},)ififtestparams。beginTime!nullandparams。beginTime!!开始时间检索anddateformat(opertime,ymd)dateformat({params。beginTime},ymd)ififtestparams。endTime!nullandparams。endTime!!结束时间检索anddateformat(opertime,ymd)dateformat({params。endTime},ymd)ifwhereorderbyoperiddescselectdeleteiddeleteOperLogByIdsparameterTypeLongdeletefromsysopercsplogwhereoperidinforeachcollectionarrayitemoperIdopen(separator,close){operId}foreachdeleteselectidselectOperLogByIdparameterTypeLongresultMapSysOperLogResultincluderefidselectOperLogVowhereoperid{operId}selectselectidselectOperLogListTitleresultTypejava。lang。Stringselectdistinct(title)fromsysopercsplogselectupdateidcleanOperLogtruncatetablesysopercsplogupdatemapper 定义一个日志管理的名称:CspLogpackagecom。juepeiscm。csp。annotation;importcom。juepeiscm。common。enums。BusinessType;importcom。juepeiscm。common。enums。OperatorType;importjava。lang。annotation。;CSP系统的ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志a管理Author:py。sunDate:20229714:42Target表示注解可以使用到哪些地方,可以是类,方法,或者是属性上,定义在ElementType枚举中:Retention作用是定义被它所注解的注解保留多久,一共有三种策略,定义在RetentionPolicy枚举中:我们的CspLog注解,可以作用在方法和参数上,将由编译器记录在类文件中,并在运行时由VM保留,因此可以反射性地读取。该注解是通过AOP进行解析的Target({ElementType。PARAMETER,ElementType。METHOD})Retention(RetentionPolicy。RUNTIME)DocumentedpublicinterfaceCspLog{模块returnStringtitle()default;功能returnBusinessTypebusinessType()defaultBusinessType。OTHER;操作人类别returnOperatorTypeoperatorType()defaultOperatorType。MANAGE;是否保存请求的参数returnbooleanisSaveRequestData()defaulttrue;}实体类SysOperCspLogpackagecom。juepeiscm。csp。domain。csplog;importcom。fasterxml。jackson。annotation。JsonFormat;importcom。juepeiscm。common。annotation。Excel;importcom。juepeiscm。common。core。domain。BaseEntity;importjava。util。Date;Author:py。sunDate:20229715:04publicclassSysOperCspLogextendsBaseEntity{privatestaticfinallongserialVersionUID1L;Excel(name操作序号,cellTypeExcel。ColumnType。NUMERIC)privateLongoperId;Excel(name操作模块)privateStringtitle;Excel(name业务类型,readConverterExp0其它,1新增,2修改,3删除,4授权,5导出,6导入,7强退,8生成代码,9清空数据)privateIntegerbusinessType;privateInteger〔〕businessTypes;Excel(name请求方法)privateStringmethod;Excel(name请求方式)privateStringrequestMethod;Excel(name操作类别,readConverterExp0其它,1后台用户,2手机端用户)privateIntegeroperatorType;Excel(name操作人员)privateStringoperName;Excel(name部门名称)privateStringdeptName;Excel(name请求地址)privateStringoperUrl;Excel(name操作地址)privateStringoperIp;Excel(name操作地点)privateStringoperLocation;Excel(name请求参数)privateStringoperParam;Excel(name返回参数)privateStringjsonResult;Excel(name状态,readConverterExp0正常,1异常)privateIntegerstatus;Excel(name错误消息)privateStringerrorMsg;JsonFormat(patternyyyyMMddHH:mm:ss)Excel(name操作时间,width30。0D,dateFormatyyyyMMddHH:mm:ss)privateDateoperTime;publicSysOperCspLog(){}publicLonggetOperId(){returnthis。operId;}publicvoidsetOperId(LongoperId){this。operIdoperId;}publicStringgetTitle(){returnthis。title;}publicvoidsetTitle(Stringtitle){this。titletitle;}publicIntegergetBusinessType(){returnthis。businessType;}publicvoidsetBusinessType(IntegerbusinessType){this。businessTypebusinessType;}publicInteger〔〕getBusinessTypes(){returnthis。businessTypes;}publicvoidsetBusinessTypes(Integer〔〕businessTypes){this。businessTypesbusinessTypes;}publicStringgetMethod(){returnthis。method;}publicvoidsetMethod(Stringmethod){this。methodmethod;}publicStringgetRequestMethod(){returnthis。requestMethod;}publicvoidsetRequestMethod(StringrequestMethod){this。requestMethodrequestMethod;}publicIntegergetOperatorType(){returnthis。operatorType;}publicvoidsetOperatorType(IntegeroperatorType){this。operatorTypeoperatorType;}publicStringgetOperName(){returnthis。operName;}publicvoidsetOperName(StringoperName){this。operNameoperName;}publicStringgetDeptName(){returnthis。deptName;}publicvoidsetDeptName(StringdeptName){this。deptNamedeptName;}publicStringgetOperUrl(){returnthis。operUrl;}publicvoidsetOperUrl(StringoperUrl){this。operUrloperUrl;}publicStringgetOperIp(){returnthis。operIp;}publicvoidsetOperIp(StringoperIp){this。operIpoperIp;}publicStringgetOperLocation(){returnthis。operLocation;}publicvoidsetOperLocation(StringoperLocation){this。operLocationoperLocation;}publicStringgetOperParam(){returnthis。operParam;}publicvoidsetOperParam(StringoperParam){this。operParamoperParam;}publicStringgetJsonResult(){returnthis。jsonResult;}publicvoidsetJsonResult(StringjsonResult){this。jsonResultjsonResult;}publicIntegergetStatus(){returnthis。status;}publicvoidsetStatus(Integerstatus){this。statusstatus;}publicStringgetErrorMsg(){returnthis。errorMsg;}publicvoidsetErrorMsg(StringerrorMsg){this。errorMsgerrorMsg;}publicDategetOperTime(){returnthis。operTime;}publicvoidsetOperTime(DateoperTime){this。operTimeoperTime;}}10。定义日志管理的切面 大家一定要记住哈,所有针对实体的SysOperCspLog赋值操作必须在这里main执行。packagecom。juepeiscm。csp。controller。utils;importcom。alibaba。fastjson。JSON;importcom。juepeiscm。common。core。domain。entity。SysDept;importcom。juepeiscm。common。core。domain。model。LoginUser;importcom。juepeiscm。common。enums。BusinessStatus;importcom。juepeiscm。common。enums。HttpMethod;importcom。juepeiscm。common。utils。ServletUtils;importcom。juepeiscm。common。utils。StringUtils;importcom。juepeiscm。common。utils。ip。IpUtils;importcom。juepeiscm。common。utils。spring。SpringUtils;importcom。juepeiscm。csp。annotation。CspLog;importcom。juepeiscm。csp。domain。csplog。SysOperCspLog;importcom。juepeiscm。framework。aspectj。LogAspect;importcom。juepeiscm。framework。manager。AsyncManager;importcom。juepeiscm。framework。web。service。TokenService;importcom。juepeiscm。uam。service。ISysDeptService;importcom。juepeiscm。uam。version。UamVersion;importorg。apache。dubbo。config。annotation。Reference;importorg。aspectj。lang。JoinPoint;importorg。aspectj。lang。Signature;importorg。aspectj。lang。annotation。AfterReturning;importorg。aspectj。lang。annotation。AfterThrowing;importorg。aspectj。lang。annotation。Aspect;importorg。aspectj。lang。annotation。Pointcut;importorg。aspectj。lang。reflect。MethodSignature;importorg。slf4j。Logger;importorg。slf4j。LoggerFactory;importorg。springframework。stereotype。Component;importorg。springframework。validation。BindingResult;importorg。springframework。web。multipart。MultipartFile;importorg。springframework。web。servlet。HandlerMapping;importjavax。servlet。http。HttpServletRequest;importjavax。servlet。http。HttpServletResponse;importjava。lang。reflect。Method;importjava。util。Collection;importjava。util。Iterator;importjava。util。Map;Author:py。sunDate:20229716:31操作ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志a记录处理AspectComponentpublicclassCspLogAspect{privatestaticfinalLoggerlogLoggerFactory。getLogger(CspLog。class);Reference(versionUamVersion。idV)publicISysDeptServicedeptService;publicCspLogAspect(){}把CspLog配置为切入点。配置织入点Pointcut(annotation(com。juepeiscm。csp。annotation。CspLog))publicvoidlogPointCut(){}拦截异常操作处理完请求后执行该方法。也就是用CspLog注解的方法,执行完后,调用handleLog方法,处理返回结果。AfterReturning(pointcutlogPointCut(),returningjsonResult)publicvoiddoAfterReturning(JoinPointjoinPoint,ObjectjsonResult){this。handleLog(joinPoint,(Exception)null,jsonResult);}AfterThrowing(valuelogPointCut(),throwinge)publicvoiddoAfterThrowing(JoinPointjoinPoint,Exceptione){this。handleLog(joinPoint,e,(Object)null);}如果函数抛出了异常,也是执行handleLog方法,不过和正常返回的参数不一样,此处是为了处理异常。protectedvoidhandleLog(JoinPointjoinPoint,Exceptione,ObjectjsonResult){try{获得注解CspLogcontrollerLogthis。getAnnotationLog(joinPoint);if(controllerLognull){return;}获取当前的用户LoginUserloginUser((TokenService)SpringUtils。getBean(TokenService。class))。getLoginUser(ServletUtils。getRequest());数据库ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志aSysOperCspLogoperLognewSysOperCspLog();operLog。setStatus(BusinessStatus。SUCCESS。ordinal());请求的地址StringipIpUtils。getIpAddr(ServletUtils。getRequest());operLog。setOperIp(ip);返回参数operLog。setJsonResult(JSON。toJSONString(jsonResult));operLog。setOperUrl(ServletUtils。getRequest()。getRequestURI());if(loginUser!null){operLog。setOperName(loginUser。getUsername());}获取当前登录用户的部门名称SysDeptsysDeptdeptService。selectDeptIdByUserIdAndAppId(loginUser。getUser()。getUserId(),oms);if(sysDept!nullStringUtils。isNotEmpty(sysDept。getDeptName())){operLog。setDeptName(sysDept。getDeptName());}if(e!null){operLog。setStatus(BusinessStatus。FAIL。ordinal());operLog。setErrorMsg(StringUtils。substring(e。getMessage(),0,2000));}设置方法名称StringclassNamejoinPoint。getTarget()。getClass()。getName();StringmethodNamejoinPoint。getSignature()。getName();operLog。setMethod(className。methodName());设置请求方式operLog。setRequestMethod(ServletUtils。getRequest()。getMethod());处理设置注解上的参数this。getControllerMethodDescription(joinPoint,controllerLog,operLog);保存数据库AsyncManager。me()。execute(AsyncFactoryCsp。recordOper(operLog));}catch(Exceptionvar10){记录本地异常ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志alog。error(前置通知异常);log。error(异常信息:{},var10。getMessage());var10。printStackTrace();}}publicvoidgetControllerMethodDescription(JoinPointjoinPoint,CspLoglog,SysOperCspLogoperLog)throwsException{operLog。setBusinessType(log。businessType()。ordinal());operLog。setTitle(log。title());operLog。setOperatorType(log。operatorType()。ordinal());if(log。isSaveRequestData()){this。setRequestValue(joinPoint,operLog);}}privatevoidsetRequestValue(JoinPointjoinPoint,SysOperCspLogoperLog)throwsException{StringrequestMethodoperLog。getRequestMethod();if(!HttpMethod。PUT。name()。equals(requestMethod)!HttpMethod。POST。name()。equals(requestMethod)){Maplt;?,?paramsMap(Map)ServletUtils。getRequest()。getAttribute(HandlerMapping。URITEMPLATEVARIABLESATTRIBUTE);operLog。setOperParam(StringUtils。substring(paramsMap。toString(),0,2000));}else{Stringparamsthis。argsArrayToString(joinPoint。getArgs());operLog。setOperParam(StringUtils。substring(params,0,2000));}}privateCspLoggetAnnotationLog(JoinPointjoinPoint)throwsException{SignaturesignaturejoinPoint。getSignature();MethodSignaturemethodSignature(MethodSignature)signature;MethodmethodmethodSignature。getMethod();returnmethod!null?(CspLog)method。getAnnotation(CspLog。class):null;}privateStringargsArrayToString(Object〔〕paramsArray){Stringparams;if(paramsArray!nullparamsArray。length0){for(inti0;iparamsArray。length;i){if(StringUtils。isNotNull(paramsArray〔i〕)!this。isFilterObject(paramsArray〔i〕)){ObjectjsonObjJSON。toJSON(paramsArray〔i〕);paramsparamsjsonObj。toString();}}}returnparams。trim();}publicbooleanisFilterObject(Objecto){Classlt;?clazzo。getClass();if(clazz。isArray()){returnclazz。getComponentType()。isAssignableFrom(MultipartFile。class);}else{Iteratoriter;if(Collection。class。isAssignableFrom(clazz)){Collectioncollection(Collection)o;itercollection。iterator();if(iter。hasNext()){returniter。next()instanceofMultipartFile;}}elseif(Map。class。isAssignableFrom(clazz)){Mapmap(Map)o;itermap。entrySet()。iterator();if(iter。hasNext()){Map。Entryentry(Map。Entry)iter。next();returnentry。getValue()instanceofMultipartFile;}}returnoinstanceofMultipartFileoinstanceofHttpServletRequestoinstanceofHttpServletResponseoinstanceofBindingResult;}}}AsyncFactoryCsppackagecom。juepeiscm。csp。controller。utils;importcom。juepeiscm。common。utils。ip。AddressUtils;importcom。juepeiscm。common。utils。spring。SpringUtils;importcom。juepeiscm。csp。domain。csplog。SysOperCspLog;importcom。juepeiscm。csp。service。csplog。ISysOperCspLogService;importorg。slf4j。Logger;importorg。slf4j。LoggerFactory;importjava。util。TimerTask;Author:py。sunDate:20229716:47publicclassAsyncFactoryCsp{privatestaticfinalLoggersysuserloggerLoggerFactory。getLogger(sysuser);publicAsyncFactoryCsp(){}publicstaticTimerTaskrecordOper(finalSysOperCspLogoperLog){returnnewTimerTask(){publicvoidrun(){operLog。setOperLocation(AddressUtils。getRealAddressByIP(operLog。getOperIp()));((ISysOperCspLogService)SpringUtils。getBean(ISysOperCspLogService。class))。insertOperlog(operLog);}};}}12。写一个Controller的Demo来执行一条日志试试在这里插入代码片packagecom。juepeiscm。csp。controller。order;importcom。alibaba。fastjson。JSON;importcom。juepeiscm。admin。api。service。ISysDictDataService;importcom。juepeiscm。common。annotation。RepeatSubmit;importcom。juepeiscm。common。core。controller。BaseController;importcom。juepeiscm。common。core。domain。AjaxResult;importcom。juepeiscm。common。core。domain。entity。SysDictData;importcom。juepeiscm。common。core。page。TableDataInfo;importcom。juepeiscm。common。enums。BusinessType;importcom。juepeiscm。common。exception。BaseException;importcom。juepeiscm。common。utils。StringUtils;importcom。juepeiscm。common。utils。poi。ExcelUtil;importcom。juepeiscm。csp。annotation。CspLog;importcom。juepeiscm。csp。domain。order。CspGodownEntry;importcom。juepeiscm。csp。domain。order。CspGodownEntryDetails;importcom。juepeiscm。csp。service。common。MenuLogService;importcom。juepeiscm。csp。service。data。ICspGoodsdataService;importcom。juepeiscm。csp。service。order。ICspGodownEntryService;importcom。juepeiscm。csp。vo。GodownEntryExcel;importcom。juepeiscm。csp。vo。GoodsDataForGodownEntryDetails;importio。swagger。annotations。Api;importio。swagger。annotations。ApiOperation;importorg。slf4j。Logger;importorg。slf4j。LoggerFactory;importorg。springframework。beans。factory。annotation。Autowired;importorg。springframework。security。access。prepost。PreAuthorize;importorg。springframework。util。CollectionUtils;importorg。springframework。web。bind。annotation。;importorg。springframework。web。multipart。MultipartFile;importjavax。validation。Valid;importjava。math。BigDecimal;importjava。math。RoundingMode;importjava。util。;importjava。util。stream。Collectors;入库订单Controllerauthorjuepeiscmdate20210723Api(tags入库订单接口)RestControllerRequestMapping(ordergodownEntry)publicclassCspGodownEntryControllerextendsBaseController{privatestaticfinalLoggerloggerLoggerFactory。getLogger(CspGodownEntryController。class);AutowiredprivateICspGodownEntryServicecspGodownEntryService;AutowiredprivateICspGoodsdataServicegoodsDataService;AutowiredprivateMenuLogServicemenuLogService;AutowiredprivateISysDictDataServicesysDictDataService;新增入库订单DemoPreAuthorize(ss。hasPermi(order:godownEntry:add))ApiOperation(value新增入库订单)CspLog(title入库订单demo4,businessTypeBusinessType。INSERT)PostMapping(addOrder)RepeatSubmitpublicAjaxResultaddDemo(RequestBodyValidCspGodownEntrygodownEntry){try{returntoAjax(cspGodownEntryService。insertOmsGodownEntry(godownEntry));}catch(Exceptione){e。printStackTrace();returnAjaxResult。error(新增失败,请联系管理员);}}}测试下,看看数据库内容