1。需求 目前有这么个问题,有两个系统CSP和OMS,这俩系统共用的是同一套日志操作:L目前想区分下这俩系统的日志操作,那没办法了,只能重写一份Log的日志操作; 你也可以参照若依框架的日志系统实现。2。新建一张日志表 sysopercsplogNavicatPremiumDataTransferSourceServer:jpcscadminSourceServerType:MySQLSourceServerVersion:50728SourceHost:rmuf6miy84gu8u433x9。mysql。rds。aliyuncs。com:3306SourceSchema:jpomsTargetServerType:MySQLTargetServerVersion:50728FileEncoding:65001Date:0809202209:21:45SETNAMESutf8mb4;SETFOREIGNKEYCHECKS0;TablestructureforsysopercsplogDROPTABLEIFEXISTSCREATETABLEsysopercsplog(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。importcom。juepeiscm。admin。api。domain。SysOperLimportcom。juepeiscm。common。core。controller。BaseCimportcom。juepeiscm。common。core。domain。AjaxRimportcom。juepeiscm。common。core。page。TableDataIimportcom。juepeiscm。common。enums。BusinessTimportcom。juepeiscm。common。utils。poi。ExcelUimportcom。juepeiscm。csp。annotation。CspLimportcom。juepeiscm。csp。domain。csplog。SysOperCspLimportcom。juepeiscm。csp。service。csplog。ISysOperCspLogSimportorg。springframework。beans。factory。annotation。Aimportorg。springframework。security。access。prepost。PreAimportorg。springframework。web。bind。annotation。;importjava。util。L操作CSP系统ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志aAuthor:py。sunDate:20229714:51RestControllerRequestMapping({csplogopercsplog})publicclassSysOperCsplogControllerextendsBaseController{AutowiredprivateISysOperCspLogServiceoperCspLogSpublicSysOperCsplogController(){}查询操作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。importcom。juepeiscm。admin。api。domain。SysOperLimportcom。juepeiscm。csp。domain。csplog。SysOperCspLimportjava。util。LAuthor:py。sunDate:20229715:02publicinterfaceISysOperCspLogService{voidinsertOperlog(SysOperCspLogvar1);ListSysOperCspLogselectOperLogList(SysOperCspLogvar1);ListStringselectOperLogListTitle();intdeleteOperLogByIds(Long〔〕var1);SysOperLogselectOperLogById(Longvar1);voidcleanOperLog();}Service实现packagecom。juepeiscm。csp。service。impl。importcom。juepeiscm。admin。api。domain。SysOperLimportcom。juepeiscm。common。core。domain。AjaxRimportcom。juepeiscm。common。core。domain。entity。SysDimportcom。juepeiscm。common。core。domain。entity。SysUimportcom。juepeiscm。common。core。domain。model。LoginUimportcom。juepeiscm。common。exception。CustomEimportcom。juepeiscm。common。utils。SecurityUimportcom。juepeiscm。common。utils。ServletUimportcom。juepeiscm。common。utils。StringUimportcom。juepeiscm。csp。domain。csplog。SysOperCspLimportcom。juepeiscm。csp。mapper。csplog。SysOperCspLogMimportcom。juepeiscm。csp。service。csplog。ISysOperCspLogSimportcom。juepeiscm。framework。web。service。TokenSimportcom。juepeiscm。uam。service。ISysDeptSimportcom。juepeiscm。uam。version。UamVimportorg。apache。dubbo。config。annotation。Rimportorg。springframework。beans。factory。annotation。Aimportorg。springframework。stereotype。Simportjava。util。LAuthor:py。sunDate:20229715:03ServicepublicclassSysOperCspLogServiceImplimplementsISysOperCspLogService{AutowiredprivateSysOperCspLogMapperoperLogMAutowiredprivateTokenServicetokenSReference(versionUamVersion。idV)publicISysDeptServicedeptSOverridepublicvoidinsertOperlog(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。importcom。juepeiscm。admin。api。domain。SysOperLimportcom。juepeiscm。csp。domain。csplog。SysOperCspLimportjava。util。LAuthor:py。sunDate:20229715:06publicinterfaceSysOperCspLogMapper{voidinsertOperlog(SysOperCspLogvar1);ListSysOperCspLogselectOperLogList(SysOperCspLogsysOperCspLog);ListStringselectOperLogListTitle();intdeleteOperLogByIds(Long〔〕var1);SysOperLogselectOperLogById(Longvar1);voidcleanOperLog();}Mapper。xml(我用的是Mybatis)?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。importcom。juepeiscm。common。enums。BusinessTimportcom。juepeiscm。common。enums。OperatorTimportjava。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()功能returnBusinessTypebusinessType()defaultBusinessType。OTHER;操作人类别returnOperatorTypeoperatorType()defaultOperatorType。MANAGE;是否保存请求的参数returnbooleanisSaveRequestData()}实体类SysOperCspLogpackagecom。juepeiscm。csp。domain。importcom。fasterxml。jackson。annotation。JsonFimportcom。juepeiscm。common。annotation。Eimportcom。juepeiscm。common。core。domain。BaseEimportjava。util。DAuthor:py。sunDate:20229715:04publicclassSysOperCspLogextendsBaseEntity{privatestaticfinallongserialVersionUID1L;Excel(name操作序号,cellTypeExcel。ColumnType。NUMERIC)privateLongoperId;Excel(name操作模块)privateSExcel(name业务类型,readConverterExp0其它,1新增,2修改,3删除,4授权,5导出,6导入,7强退,8生成代码,9清空数据)privateIntegerbusinessTprivateInteger〔〕businessTExcel(name请求方法)privateSExcel(name请求方式)privateStringrequestMExcel(name操作类别,readConverterExp0其它,1后台用户,2手机端用户)privateIntegeroperatorTExcel(name操作人员)privateStringoperNExcel(name部门名称)privateStringdeptNExcel(name请求地址)privateStringoperUExcel(name操作地址)privateStringoperIp;Excel(name操作地点)privateStringoperLExcel(name请求参数)privateStringoperPExcel(name返回参数)privateStringjsonRExcel(name状态,readConverterExp0正常,1异常)privateIExcel(name错误消息)privateStringerrorMJsonFormat(patternyyyyMMddHH:mm:ss)Excel(name操作时间,width30。0D,dateFormatyyyyMMddHH:mm:ss)privateDateoperTpublicSysOperCspLog(){}publicLonggetOperId(){returnthis。operId;}publicvoidsetOperId(LongoperId){this。operIdoperId;}publicStringgetTitle(){returnthis。}publicvoidsetTitle(Stringtitle){this。}publicIntegergetBusinessType(){returnthis。businessT}publicvoidsetBusinessType(IntegerbusinessType){this。businessTypebusinessT}publicInteger〔〕getBusinessTypes(){returnthis。businessT}publicvoidsetBusinessTypes(Integer〔〕businessTypes){this。businessTypesbusinessT}publicStringgetMethod(){returnthis。}publicvoidsetMethod(Stringmethod){this。}publicStringgetRequestMethod(){returnthis。requestM}publicvoidsetRequestMethod(StringrequestMethod){this。requestMethodrequestM}publicIntegergetOperatorType(){returnthis。operatorT}publicvoidsetOperatorType(IntegeroperatorType){this。operatorTypeoperatorT}publicStringgetOperName(){returnthis。operN}publicvoidsetOperName(StringoperName){this。operNameoperN}publicStringgetDeptName(){returnthis。deptN}publicvoidsetDeptName(StringdeptName){this。deptNamedeptN}publicStringgetOperUrl(){returnthis。operU}publicvoidsetOperUrl(StringoperUrl){this。operUrloperU}publicStringgetOperIp(){returnthis。operIp;}publicvoidsetOperIp(StringoperIp){this。operIpoperIp;}publicStringgetOperLocation(){returnthis。operL}publicvoidsetOperLocation(StringoperLocation){this。operLocationoperL}publicStringgetOperParam(){returnthis。operP}publicvoidsetOperParam(StringoperParam){this。operParamoperP}publicStringgetJsonResult(){returnthis。jsonR}publicvoidsetJsonResult(StringjsonResult){this。jsonResultjsonR}publicIntegergetStatus(){returnthis。}publicvoidsetStatus(Integerstatus){this。}publicStringgetErrorMsg(){returnthis。errorM}publicvoidsetErrorMsg(StringerrorMsg){this。errorMsgerrorM}publicDategetOperTime(){returnthis。operT}publicvoidsetOperTime(DateoperTime){this。operTimeoperT}}10。定义日志管理的切面 大家一定要记住哈,所有针对实体的SysOperCspLog赋值操作必须在这里main执行。packagecom。juepeiscm。csp。controller。importcom。alibaba。fastjson。JSON;importcom。juepeiscm。common。core。domain。entity。SysDimportcom。juepeiscm。common。core。domain。model。LoginUimportcom。juepeiscm。common。enums。BusinessSimportcom。juepeiscm。common。enums。HttpMimportcom。juepeiscm。common。utils。ServletUimportcom。juepeiscm。common。utils。StringUimportcom。juepeiscm。common。utils。ip。IpUimportcom。juepeiscm。common。utils。spring。SpringUimportcom。juepeiscm。csp。annotation。CspLimportcom。juepeiscm。csp。domain。csplog。SysOperCspLimportcom。juepeiscm。framework。aspectj。LogAimportcom。juepeiscm。framework。manager。AsyncMimportcom。juepeiscm。framework。web。service。TokenSimportcom。juepeiscm。uam。service。ISysDeptSimportcom。juepeiscm。uam。version。UamVimportorg。apache。dubbo。config。annotation。Rimportorg。aspectj。lang。JoinPimportorg。aspectj。lang。Simportorg。aspectj。lang。annotation。AfterRimportorg。aspectj。lang。annotation。AfterTimportorg。aspectj。lang。annotation。Aimportorg。aspectj。lang。annotation。Pimportorg。aspectj。lang。reflect。MethodSimportorg。slf4j。Limportorg。slf4j。LoggerFimportorg。springframework。stereotype。Cimportorg。springframework。validation。BindingRimportorg。springframework。web。multipart。MultipartFimportorg。springframework。web。servlet。HandlerMimportjavax。servlet。http。HttpServletRimportjavax。servlet。http。HttpServletRimportjava。lang。reflect。Mimportjava。util。Cimportjava。util。Iimportjava。util。MAuthor:py。sunDate:20229716:31操作ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志a记录处理AspectComponentpublicclassCspLogAspect{privatestaticfinalLoggerlogLoggerFactory。getLogger(CspLog。class);Reference(versionUamVersion。idV)publicISysDeptServicedeptSpublicCspLogAspect(){}把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){}获取当前的用户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)){M?,?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)MethodmethodmethodSignature。getMethod();returnmethod!null?(CspLog)method。getAnnotation(CspLog。class):}privateStringargsArrayToString(Object〔〕paramsArray){Sif(paramsArray!nullparamsArray。length0){for(inti0;iparamsArray。i){if(StringUtils。isNotNull(paramsArray〔i〕)!this。isFilterObject(paramsArray〔i〕)){ObjectjsonObjJSON。toJSON(paramsArray〔i〕);paramsparamsjsonObj。toString();}}}returnparams。trim();}publicbooleanisFilterObject(Objecto){C?clazzo。getClass();if(clazz。isArray()){returnclazz。getComponentType()。isAssignableFrom(MultipartFile。class);}else{Iif(Collection。class。isAssignableFrom(clazz)){Collectioncollection(Collection)o;itercollection。iterator();if(iter。hasNext()){returniter。next()instanceofMultipartF}}elseif(Map。class。isAssignableFrom(clazz)){Mapmap(Map)o;itermap。entrySet()。iterator();if(iter。hasNext()){Map。Entryentry(Map。Entry)iter。next();returnentry。getValue()instanceofMultipartF}}returnoinstanceofMultipartFileoinstanceofHttpServletRequestoinstanceofHttpServletResponseoinstanceofBindingR}}}AsyncFactoryCsppackagecom。juepeiscm。csp。controller。importcom。juepeiscm。common。utils。ip。AddressUimportcom。juepeiscm。common。utils。spring。SpringUimportcom。juepeiscm。csp。domain。csplog。SysOperCspLimportcom。juepeiscm。csp。service。csplog。ISysOperCspLogSimportorg。slf4j。Limportorg。slf4j。LoggerFimportjava。util。TimerTAuthor: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。importcom。alibaba。fastjson。JSON;importcom。juepeiscm。admin。api。service。ISysDictDataSimportcom。juepeiscm。common。annotation。RepeatSimportcom。juepeiscm。common。core。controller。BaseCimportcom。juepeiscm。common。core。domain。AjaxRimportcom。juepeiscm。common。core。domain。entity。SysDictDimportcom。juepeiscm。common。core。page。TableDataIimportcom。juepeiscm。common。enums。BusinessTimportcom。juepeiscm。common。exception。BaseEimportcom。juepeiscm。common。utils。StringUimportcom。juepeiscm。common。utils。poi。ExcelUimportcom。juepeiscm。csp。annotation。CspLimportcom。juepeiscm。csp。domain。order。CspGodownEimportcom。juepeiscm。csp。domain。order。CspGodownEntryDimportcom。juepeiscm。csp。service。common。MenuLogSimportcom。juepeiscm。csp。service。data。ICspGoodsdataSimportcom。juepeiscm。csp。service。order。ICspGodownEntrySimportcom。juepeiscm。csp。vo。GodownEntryEimportcom。juepeiscm。csp。vo。GoodsDataForGodownEntryDimportio。swagger。annotations。Aimportio。swagger。annotations。ApiOimportorg。slf4j。Limportorg。slf4j。LoggerFimportorg。springframework。beans。factory。annotation。Aimportorg。springframework。security。access。prepost。PreAimportorg。springframework。util。CollectionUimportorg。springframework。web。bind。annotation。;importorg。springframework。web。multipart。MultipartFimportjavax。validation。Vimportjava。math。BigDimportjava。math。RoundingMimportjava。util。;importjava。util。stream。C入库订单Controllerauthorjuepeiscmdate20210723Api(tags入库订单接口)RestControllerRequestMapping(ordergodownEntry)publicclassCspGodownEntryControllerextendsBaseController{privatestaticfinalLoggerloggerLoggerFactory。getLogger(CspGodownEntryController。class);AutowiredprivateICspGodownEntryServicecspGodownEntrySAutowiredprivateICspGoodsdataServicegoodsDataSAutowiredprivateMenuLogServicemenuLogSAutowiredprivateISysDictDataServicesysDictDataS新增入库订单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(新增失败,请联系管理员);}}}测试下,看看数据库内容