art: 新增系统第三方集成调用日志表,切面服务实现
| | |
| | | "name": "åææ°ç«ç¬MESæ°æ®åºè®¾è®¡", |
| | | "describe": "æè¿°åèªæ°ç«ç¬MESæ°æ®åºè®¾è®¡è¯¦æ
", |
| | | "avatar": "", |
| | | "version": "4.9.4", |
| | | "version": "4.9.2", |
| | | "createdTime": "2025-3-10 16:38:19", |
| | | "updatedTime": "2025-7-28 20:46:22", |
| | | "updatedTime": "2025-7-30 14:19:17", |
| | | "dbConns": [], |
| | | "profile": { |
| | | "default": { |
| | |
| | | "correlations": [], |
| | | "indexes": [], |
| | | "type": "P" |
| | | }, |
| | | { |
| | | "id": "8C08DDB8-C3E9-4FBF-B4CE-EAB9BCFE1E38", |
| | | "env": { |
| | | "base": { |
| | | "nameSpace": "", |
| | | "codeRoot": "" |
| | | } |
| | | }, |
| | | "defKey": "sys_api_log", |
| | | "defName": "ç³»ç»ç¬¬ä¸æ¹éææ¥å£æ¥å¿", |
| | | "comment": "", |
| | | "properties": { |
| | | "partitioned by": "(date string)", |
| | | "row format delimited": "", |
| | | "fields terminated by ','": "", |
| | | "collection items terminated by '-'": "", |
| | | "map keys terminated by ':'": "", |
| | | "store as textfile;": "" |
| | | }, |
| | | "sysProps": { |
| | | "nameTemplate": "{defKey}[{defName}]" |
| | | }, |
| | | "notes": {}, |
| | | "headers": [ |
| | | { |
| | | "refKey": "hideInGraph", |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "defKey", |
| | | "freeze": false, |
| | | "hideInGraph": false |
| | | }, |
| | | { |
| | | "refKey": "defName", |
| | | "freeze": false, |
| | | "hideInGraph": false |
| | | }, |
| | | { |
| | | "refKey": "primaryKey", |
| | | "freeze": false, |
| | | "hideInGraph": false |
| | | }, |
| | | { |
| | | "refKey": "notNull", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "autoIncrement", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "domain", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "type", |
| | | "freeze": false, |
| | | "hideInGraph": false |
| | | }, |
| | | { |
| | | "refKey": "len", |
| | | "freeze": false, |
| | | "hideInGraph": false |
| | | }, |
| | | { |
| | | "refKey": "scale", |
| | | "freeze": false, |
| | | "hideInGraph": false |
| | | }, |
| | | { |
| | | "refKey": "comment", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "refDict", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "defaultValue", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "isStandard", |
| | | "freeze": false, |
| | | "hideInGraph": false |
| | | }, |
| | | { |
| | | "refKey": "uiHint", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "extProps", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "attr1", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "attr2", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "attr3", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "attr4", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "attr5", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "attr6", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "attr7", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "attr8", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | }, |
| | | { |
| | | "refKey": "attr9", |
| | | "freeze": false, |
| | | "hideInGraph": true |
| | | } |
| | | ], |
| | | "fields": [ |
| | | { |
| | | "defKey": "id", |
| | | "defName": "主é®", |
| | | "comment": "", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": true, |
| | | "notNull": true, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "FC9790A7-36B8-4A48-8F9A-BC1042BCFE64", |
| | | "extProps": {}, |
| | | "domain": "16120F75-6AA7-4483-868D-F07F511BB081", |
| | | "id": "493A6ADA-F893-45D2-AC93-D3090DC02B0D" |
| | | }, |
| | | { |
| | | "defKey": "create_by", |
| | | "defName": "å建人", |
| | | "comment": "", |
| | | "domain": "54611CCC-CA4B-42E1-9F32-4944C85B85A6", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": true, |
| | | "refDict": "", |
| | | "uiHint": "", |
| | | "id": "C9EFA288-7FAB-408E-87FB-91A4C08BDF73", |
| | | "baseType": "FC9790A7-36B8-4A48-8F9A-BC1042BCFE64" |
| | | }, |
| | | { |
| | | "defKey": "create_time", |
| | | "defName": "å建æ¶é´", |
| | | "comment": "", |
| | | "domain": "7CFFA0D3-6A93-4DDC-BC10-DF21211064DC", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": true, |
| | | "refDict": "", |
| | | "uiHint": "", |
| | | "id": "E239E79C-CBF1-42DA-907E-2FCADECD2C67", |
| | | "baseType": "89D69E81-EA34-42EE-9FA2-93B8BD27E098" |
| | | }, |
| | | { |
| | | "defKey": "api_category", |
| | | "defName": "APIåç±»", |
| | | "comment": "", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "FC9790A7-36B8-4A48-8F9A-BC1042BCFE64", |
| | | "extProps": {}, |
| | | "domain": "73FD2BAD-2358-4336-B96D-45DC897BD792", |
| | | "id": "F49D357B-7349-4B9D-9907-191F2F94DA3B" |
| | | }, |
| | | { |
| | | "defKey": "api_name", |
| | | "defName": "æ¥å£åç§°", |
| | | "comment": "", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "FC9790A7-36B8-4A48-8F9A-BC1042BCFE64", |
| | | "extProps": {}, |
| | | "domain": "9092C4E0-1A54-4859-ABBB-5B62DBC27573", |
| | | "id": "66F55A69-EE62-442E-926D-97695E82BE19" |
| | | }, |
| | | { |
| | | "defKey": "request_time", |
| | | "defName": "è¯·æ±æ¶é´", |
| | | "comment": "", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "89D69E81-EA34-42EE-9FA2-93B8BD27E098", |
| | | "extProps": {}, |
| | | "domain": "7CFFA0D3-6A93-4DDC-BC10-DF21211064DC", |
| | | "id": "42B46C10-65A4-410E-A238-3A3F86018945" |
| | | }, |
| | | { |
| | | "defKey": "response_time", |
| | | "defName": "ååºæ¶é´", |
| | | "comment": "", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "89D69E81-EA34-42EE-9FA2-93B8BD27E098", |
| | | "extProps": {}, |
| | | "domain": "7CFFA0D3-6A93-4DDC-BC10-DF21211064DC", |
| | | "id": "628E5760-93A0-4779-85A9-C0231AD79EBC" |
| | | }, |
| | | { |
| | | "defKey": "request_method", |
| | | "defName": "è¯·æ±æ¹å¼", |
| | | "comment": "", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "FC9790A7-36B8-4A48-8F9A-BC1042BCFE64", |
| | | "extProps": {}, |
| | | "domain": "73FD2BAD-2358-4336-B96D-45DC897BD792", |
| | | "id": "AF639452-207A-474B-9C76-266BDD0F6BA5" |
| | | }, |
| | | { |
| | | "defKey": "request_url", |
| | | "defName": "请æ±URL", |
| | | "comment": "", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "B17BDED3-085F-40E1-9019-3B79CF2BF075", |
| | | "extProps": {}, |
| | | "domain": "13DE7063-440C-426F-B1DF-25EC824C6DB8", |
| | | "id": "A3AD6177-3EAE-4ADC-BC22-1B29AC035DD1" |
| | | }, |
| | | { |
| | | "defKey": "request_headers", |
| | | "defName": "请æ±å¤´", |
| | | "comment": "", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "B17BDED3-085F-40E1-9019-3B79CF2BF075", |
| | | "extProps": {}, |
| | | "domain": "13DE7063-440C-426F-B1DF-25EC824C6DB8", |
| | | "id": "2BA704F8-36C4-4B4D-BF63-C721376D4B7E" |
| | | }, |
| | | { |
| | | "defKey": "request_body", |
| | | "defName": "请æ±ä½", |
| | | "comment": "", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "B17BDED3-085F-40E1-9019-3B79CF2BF075", |
| | | "extProps": {}, |
| | | "domain": "13DE7063-440C-426F-B1DF-25EC824C6DB8", |
| | | "id": "4DBE1100-12B3-4CFD-B0B1-4AFE5A9033AB" |
| | | }, |
| | | { |
| | | "defKey": "response_code", |
| | | "defName": "ååºç¼ç ", |
| | | "comment": "", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "FC9790A7-36B8-4A48-8F9A-BC1042BCFE64", |
| | | "extProps": {}, |
| | | "domain": "54611CCC-CA4B-42E1-9F32-4944C85B85A6", |
| | | "id": "4CD23738-EE0F-4029-9465-9CDF3E7CD461" |
| | | }, |
| | | { |
| | | "defKey": "response_message", |
| | | "defName": "ååºæ¶æ¯", |
| | | "comment": "", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "FC9790A7-36B8-4A48-8F9A-BC1042BCFE64", |
| | | "extProps": {}, |
| | | "domain": "9092C4E0-1A54-4859-ABBB-5B62DBC27573", |
| | | "id": "E872F6CA-7D7A-40F1-959D-FD35447BB5A1" |
| | | }, |
| | | { |
| | | "defKey": "response_body", |
| | | "defName": "ååºä½", |
| | | "comment": "", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "B17BDED3-085F-40E1-9019-3B79CF2BF075", |
| | | "extProps": {}, |
| | | "domain": "13DE7063-440C-426F-B1DF-25EC824C6DB8", |
| | | "id": "AC48A8A8-E320-4E79-AFA7-4FDB1059961F" |
| | | }, |
| | | { |
| | | "defKey": "request_status", |
| | | "defName": "ç¶æ", |
| | | "comment": "æåã失败", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "1D764C4A-6F9F-421E-B11A-6F3E23B51811", |
| | | "extProps": {}, |
| | | "domain": "6BC8F04B-6CFA-4995-98D3-318F5CDD774E", |
| | | "id": "4CCFBCCD-0681-4B6F-BAE8-624063397C72" |
| | | }, |
| | | { |
| | | "defKey": "method", |
| | | "defName": "è°ç¨æ¹æ³", |
| | | "comment": "", |
| | | "type": "", |
| | | "len": "", |
| | | "scale": "", |
| | | "primaryKey": false, |
| | | "notNull": false, |
| | | "autoIncrement": false, |
| | | "defaultValue": "", |
| | | "hideInGraph": false, |
| | | "refDict": "", |
| | | "baseType": "FC9790A7-36B8-4A48-8F9A-BC1042BCFE64", |
| | | "extProps": {}, |
| | | "domain": "9092C4E0-1A54-4859-ABBB-5B62DBC27573", |
| | | "id": "112770C9-963A-40F4-BCDF-289177A84824" |
| | | } |
| | | ], |
| | | "correlations": [], |
| | | "indexes": [], |
| | | "type": "P" |
| | | } |
| | | ], |
| | | "views": [], |
| | |
| | | "ED18EDD7-96F9-4CCA-93F0-633567955063", |
| | | "ADF40C7F-5C97-4196-BCA7-E780FCC8E2FB", |
| | | "27A01955-9C87-4E63-9A2A-8B489835879F", |
| | | "D36AAD93-CF06-45C1-8058-430304D98601" |
| | | "D36AAD93-CF06-45C1-8058-430304D98601", |
| | | "8C08DDB8-C3E9-4FBF-B4CE-EAB9BCFE1E38" |
| | | ], |
| | | "refViews": [], |
| | | "refDiagrams": [], |
| | |
| | | public class JeecgOneUtil { |
| | | public static void main(String[] args) throws Exception { |
| | | TableVo tableVo = new TableVo(); |
| | | tableVo.setTableName("lsw_material"); |
| | | tableVo.setEntityName("LswMaterial"); |
| | | tableVo.setEntityPackage("lsw"); |
| | | tableVo.setFtlDescription("线边åºç©æä¿¡æ¯"); |
| | | tableVo.setTableName("sys_api_log"); |
| | | tableVo.setEntityName("SysApiLog"); |
| | | tableVo.setEntityPackage("system"); |
| | | tableVo.setFtlDescription("ç³»ç»ç¬¬ä¸æ¹éææ¥å£æ¥å¿"); |
| | | new CodeGenerateOne(tableVo).generateCodeFile(null); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.common.aspect; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.parser.Feature; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.sap.conn.jco.*; |
| | | import org.aspectj.lang.ProceedingJoinPoint; |
| | | import org.aspectj.lang.annotation.Around; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | | import org.aspectj.lang.annotation.Pointcut; |
| | | import org.aspectj.lang.reflect.MethodSignature; |
| | | import org.jeecg.common.aspect.annotation.ApiLog; |
| | | import org.jeecg.common.constant.ApiLogCategoryEnum; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.modules.mdc.util.ThrowableUtil; |
| | | import org.jeecg.modules.system.entity.SysApiLog; |
| | | import org.jeecg.modules.system.service.ISysApiLogService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Aspect |
| | | @Component |
| | | public class ApiLogAspect { |
| | | @Autowired |
| | | private ISysApiLogService apiLogService; |
| | | @Autowired |
| | | private ObjectMapper objectMapper; |
| | | |
| | | @Pointcut("@annotation(org.jeecg.common.aspect.annotation.ApiLog)") |
| | | public void logPointCut() { |
| | | |
| | | } |
| | | |
| | | @Around("logPointCut()") |
| | | public Object around(ProceedingJoinPoint point) { |
| | | SysApiLog dto = new SysApiLog(); |
| | | dto.setRequestTime(new Date()); |
| | | //æ§è¡æ¹æ³ |
| | | Object result = null; |
| | | try { |
| | | result = point.proceed(); |
| | | //æ§è¡æ¶é¿(毫ç§) |
| | | dto.setResponseTime(new Date()); |
| | | //ä¿åæ¥å¿ |
| | | saveApiLog(dto, point, result); |
| | | } catch (Throwable e) { |
| | | //æ§è¡æ¶é¿(毫ç§) |
| | | dto.setResponseTime(new Date()); |
| | | //ä¿åæ¥å¿ |
| | | saveErrorLog(dto, point, e); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private void saveApiLog(SysApiLog dto, ProceedingJoinPoint joinPoint, Object result) { |
| | | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
| | | Method method = signature.getMethod(); |
| | | |
| | | ApiLog syslog = method.getAnnotation(ApiLog.class); |
| | | if (syslog != null) { |
| | | String apiName = syslog.apiName(); |
| | | ApiLogCategoryEnum apiCategory = syslog.apiCategory(); |
| | | //注解ä¸çæè¿°,æä½æ¥å¿å
容 |
| | | dto.setApiName(apiName); |
| | | dto.setApiCategory(apiCategory.name()); |
| | | switch (apiCategory) { |
| | | case SAP: |
| | | dto.setRequestMethod("RFC"); |
| | | if (result instanceof Map) { |
| | | Map<String, Object> map = (Map<String, Object>) result; |
| | | dto.setResponseCode(map.get("ztype").toString()); |
| | | dto.setResponseMessage(map.get("zmess").toString()); |
| | | dto.setRequestBody(map.get("importParameters").toString()); |
| | | dto.setResponseBody(parseSAPResponseResult(map.get("result"))); |
| | | } |
| | | break; |
| | | case WMS: |
| | | dto.setRequestMethod("Webservice"); |
| | | break; |
| | | case FEI_SHU: |
| | | dto.setRequestMethod("Http"); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | //请æ±çæ¹æ³å |
| | | String className = joinPoint.getTarget().getClass().getName(); |
| | | String methodName = signature.getName(); |
| | | dto.setMethod(className + "." + methodName + "()"); |
| | | dto.setRequestStatus(0); |
| | | apiLogService.save(dto); |
| | | } |
| | | |
| | | private void saveErrorLog(SysApiLog dto, ProceedingJoinPoint joinPoint, Throwable e) { |
| | | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
| | | Method method = signature.getMethod(); |
| | | |
| | | ApiLog syslog = method.getAnnotation(ApiLog.class); |
| | | if (syslog != null) { |
| | | String apiName = syslog.apiName(); |
| | | ApiLogCategoryEnum apiCategory = syslog.apiCategory(); |
| | | //注解ä¸çæè¿°,æä½æ¥å¿å
容 |
| | | dto.setApiName(apiName); |
| | | dto.setApiCategory(apiCategory.name()); |
| | | switch (apiCategory) { |
| | | case SAP: |
| | | dto.setRequestMethod("RFC"); |
| | | break; |
| | | case WMS: |
| | | dto.setRequestMethod("Webservice"); |
| | | break; |
| | | case FEI_SHU: |
| | | dto.setRequestMethod("Http"); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | //请æ±çæ¹æ³å |
| | | String className = joinPoint.getTarget().getClass().getName(); |
| | | String methodName = signature.getName(); |
| | | dto.setMethod(className + "." + methodName + "()"); |
| | | dto.setRequestStatus(-1); |
| | | dto.setResponseCode("-1"); |
| | | dto.setResponseMessage("请æ±å¼å¸¸ï¼è¯·æ¥çååºä½ï¼"); |
| | | dto.setResponseBody(ThrowableUtil.getStackTrace(e)); |
| | | apiLogService.save(dto); |
| | | } |
| | | |
| | | private String parseSAPResponseResult(Object result) { |
| | | List<JSONObject> items = new ArrayList<>(); |
| | | if (result instanceof List) { |
| | | List<Object> list = (List<Object>) result; |
| | | try { |
| | | for (Object obj : list) { |
| | | String json = objectMapper.writeValueAsString(obj); |
| | | JSONObject item = JSONObject.parseObject(json, Feature.OrderedField); |
| | | items.add(item); |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | throw new JeecgBootException(e); |
| | | } |
| | | } |
| | | return items.toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.common.aspect.annotation; |
| | | |
| | | import org.jeecg.common.constant.ApiLogCategoryEnum; |
| | | |
| | | import java.lang.annotation.*; |
| | | |
| | | @Target(ElementType.METHOD) |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Documented |
| | | public @interface ApiLog { |
| | | /** |
| | | * APIåç§° |
| | | * @return |
| | | */ |
| | | String apiName() default ""; |
| | | |
| | | /** |
| | | * APIåç±» |
| | | * @return |
| | | */ |
| | | ApiLogCategoryEnum apiCategory() default ApiLogCategoryEnum.SAP; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.common.constant; |
| | | |
| | | /** |
| | | * ç¬¬ä¸æ¹éææ¥å£å¯¹æ¥ç±»å |
| | | */ |
| | | public enum ApiLogCategoryEnum { |
| | | SAP, //SAPæ¥å£å¯¹æ¥ |
| | | WMS, //WMSæ¥å£å¯¹æ¥ |
| | | FEI_SHU, //é£ä¹¦æ¥å£å¯¹æ¥ |
| | | ; |
| | | |
| | | public static ApiLogCategoryEnum getInstance(String code) { |
| | | ApiLogCategoryEnum[] values = ApiLogCategoryEnum.values(); |
| | | for (ApiLogCategoryEnum value : values) { |
| | | if (value.name().equals(code)) { |
| | | return value; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.Map; |
| | | |
| | | @Api(tags = "SAPéææµè¯") |
| | | @RestController |
| | | @RequestMapping("/sap/client") |
| | |
| | | return Result.ok(test); |
| | | } |
| | | |
| | | @ApiOperation(value = "SAPéææµè¯-æµè¯æ¥å£", notes = "SAPéææµè¯-æµè¯æ¥å£") |
| | | @ApiOperation(value = "SAPéææµè¯-ç产订å忥æ¥å£", notes = "SAPéææµè¯-ç产订å忥æ¥å£") |
| | | @GetMapping("/syncProductionOrder") |
| | | public Result<?> syncProductionOrder() { |
| | | productionOrderSync.syncProductionOrder(); |
| | | return Result.ok(); |
| | | public Result<?> syncProductionOrder() throws Exception { |
| | | Map<String, Object> resultMap = productionOrderSync.syncProductionOrder(); |
| | | return Result.ok(resultMap); |
| | | } |
| | | } |
| | |
| | | package org.jeecg.modules.sap.service; |
| | | |
| | | import java.util.Map; |
| | | |
| | | public interface ProductionOrderSync { |
| | | /** |
| | | * 忥çæè®¢å |
| | | */ |
| | | void syncProductionOrder(); |
| | | Map<String, Object> syncProductionOrder() throws Exception; |
| | | } |
| | |
| | | package org.jeecg.modules.sap.service.impl; |
| | | |
| | | import com.sap.conn.jco.*; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.sap.conn.jco.JCoDestination; |
| | | import com.sap.conn.jco.JCoFunction; |
| | | import com.sap.conn.jco.JCoRepository; |
| | | import com.sap.conn.jco.JCoTable; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.aspect.annotation.ApiLog; |
| | | import org.jeecg.common.constant.ApiLogCategoryEnum; |
| | | import org.jeecg.config.sap.SapRfcConnectionManager; |
| | | import org.jeecg.modules.sap.FunctionConst; |
| | | import org.jeecg.modules.sap.dto.ProductionOrderDTO; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * çæè®¢å忥æå¡ |
| | |
| | | |
| | | |
| | | @Override |
| | | public void syncProductionOrder() { |
| | | @ApiLog(apiName = "ç产订å忥æ¥å£(ZPPF_033_1)", apiCategory = ApiLogCategoryEnum.SAP) |
| | | public Map<String, Object> syncProductionOrder() throws Exception { |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | JCoDestination destination = connectionManager.getDestination(); |
| | | try { |
| | | JCoRepository repository = destination.getRepository(); |
| | | JCoFunction function = repository.getFunction(FunctionConst.ZPPF_033_1); |
| | | if (function == null) { |
| | |
| | | // 设置è¾å
¥åæ° |
| | | //订åå·æ¥è¯¢æ¡ä»¶ |
| | | // JCoTable AUFNRTable = function.getTableParameterList().getTable("ZTAB_AUFNR"); |
| | | List<JSONObject> items = new ArrayList<>(); |
| | | //订åç±»å æ åç产订å |
| | | JCoTable AUARTTable = function.getTableParameterList().getTable("ZTAB_AUART"); |
| | | AUARTTable.appendRow(); |
| | | AUARTTable.setValue("AUART", orderTypeCode1); |
| | | //ç»è£
请æ±åæ° |
| | | JSONObject item1 = new JSONObject(); |
| | | item1.put("AUART", orderTypeCode1); |
| | | items.add(item1); |
| | | //å
«ååè°åº¦ |
| | | JCoTable FEVORTable = function.getTableParameterList().getTable("ZTAB_FEVOR"); |
| | | FEVORTable.appendRow(); |
| | | FEVORTable.setValue("FEVOR", productionManager); |
| | | //ç»è£
请æ±åæ° |
| | | JSONObject item2 = new JSONObject(); |
| | | item2.put("FEVOR", productionManager); |
| | | items.add(item2); |
| | | //æ°ç«ç¬ |
| | | JCoTable WERKSTable = function.getTableParameterList().getTable("ZTAB_WERKS"); |
| | | WERKSTable.appendRow(); |
| | | WERKSTable.setValue("WERKS", factoryCode); |
| | | //ç»è£
请æ±åæ° |
| | | JSONObject item3 = new JSONObject(); |
| | | item3.put("WERKS", factoryCode); |
| | | items.add(item3); |
| | | //订åç¶æ |
| | | JCoTable TXT04Table = function.getTableParameterList().getTable("ZTAB_TXT04"); |
| | | TXT04Table.appendRow(); |
| | | TXT04Table.setValue("TXT04", orderStatus); |
| | | //ç»è£
请æ±åæ° |
| | | JSONObject item4 = new JSONObject(); |
| | | item4.put("TXT04", orderStatus); |
| | | items.add(item4); |
| | | // æ§è¡è°ç¨ |
| | | function.execute(destination); |
| | | //è·åè¿åç»æ |
| | | String zmess = function.getExportParameterList().getValue("ZMESS").toString(); |
| | | String ztype = function.getExportParameterList().getValue("ZTYPE").toString();//S æ è¯ æå |
| | | if(!"S".equals(ztype)){ |
| | | log.error("è·å订åä¿¡æ¯å¤±è´¥ï¼ZTYPE={}, ZMESS={}", ztype, zmess); |
| | | return; |
| | | } |
| | | // è·åè¾åºåæ° |
| | | JCoTable outputTable = function.getTableParameterList().getTable("ZTAB_OUT"); |
| | | int numRows = outputTable.getNumRows(); |
| | |
| | | resultList.add(dto); |
| | | log.info(dto.toString()); |
| | | } |
| | | } catch (JCoException e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | resultMap.put("zmess", zmess); |
| | | resultMap.put("ztype", ztype); |
| | | resultMap.put("importParameters", items); |
| | | resultMap.put("result", resultList); |
| | | return resultMap; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.system.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.aspect.annotation.AutoLog; |
| | | import org.jeecg.common.system.base.controller.JeecgController; |
| | | import org.jeecg.common.system.query.QueryGenerator; |
| | | import org.jeecg.modules.system.entity.SysApiLog; |
| | | import org.jeecg.modules.system.service.ISysApiLogService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | /** |
| | | * @Description: ç³»ç»ç¬¬ä¸æ¹éææ¥å£æ¥å¿ |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-07-30 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Slf4j |
| | | @Api(tags="ç³»ç»ç¬¬ä¸æ¹éææ¥å£æ¥å¿") |
| | | @RestController |
| | | @RequestMapping("/system/sysApiLog") |
| | | public class SysApiLogController extends JeecgController<SysApiLog, ISysApiLogService> { |
| | | @Autowired |
| | | private ISysApiLogService sysApiLogService; |
| | | |
| | | /** |
| | | * å页å表æ¥è¯¢ |
| | | * |
| | | * @param sysApiLog |
| | | * @param pageNo |
| | | * @param pageSize |
| | | * @param req |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "ç³»ç»ç¬¬ä¸æ¹éææ¥å£æ¥å¿-å页å表æ¥è¯¢") |
| | | @ApiOperation(value="ç³»ç»ç¬¬ä¸æ¹éææ¥å£æ¥å¿-å页å表æ¥è¯¢", notes="ç³»ç»ç¬¬ä¸æ¹éææ¥å£æ¥å¿-å页å表æ¥è¯¢") |
| | | @GetMapping(value = "/list") |
| | | public Result<?> queryPageList(SysApiLog sysApiLog, |
| | | @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, |
| | | @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, |
| | | HttpServletRequest req) { |
| | | QueryWrapper<SysApiLog> queryWrapper = QueryGenerator.initQueryWrapper(sysApiLog, req.getParameterMap()); |
| | | Page<SysApiLog> page = new Page<SysApiLog>(pageNo, pageSize); |
| | | IPage<SysApiLog> pageList = sysApiLogService.page(page, queryWrapper); |
| | | return Result.OK(pageList); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.system.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.experimental.Accessors; |
| | | import org.jeecg.common.aspect.annotation.Dict; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | /** |
| | | * @Description: ç³»ç»ç¬¬ä¸æ¹éææ¥å£æ¥å¿ |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-07-30 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Data |
| | | @TableName("sys_api_log") |
| | | @EqualsAndHashCode(callSuper = false) |
| | | @Accessors(chain = true) |
| | | @ApiModel(value="sys_api_log对象", description="ç³»ç»ç¬¬ä¸æ¹éææ¥å£æ¥å¿") |
| | | public class SysApiLog implements Serializable { |
| | | |
| | | /**主é®*/ |
| | | @TableId(type = IdType.ASSIGN_ID) |
| | | @ApiModelProperty(value = "主é®") |
| | | private String id; |
| | | /**å建人*/ |
| | | @ApiModelProperty(value = "å建人") |
| | | private String createBy; |
| | | /**å建æ¶é´*/ |
| | | @ApiModelProperty(value = "å建æ¶é´") |
| | | @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date createTime; |
| | | /**APIåç±»*/ |
| | | @ApiModelProperty(value = "APIåç±»") |
| | | @Dict(dicCode = "api_log_category") |
| | | private String apiCategory; |
| | | /**æ¥å£åç§°*/ |
| | | @ApiModelProperty(value = "æ¥å£åç§°") |
| | | private String apiName; |
| | | /**è¯·æ±æ¶é´*/ |
| | | @ApiModelProperty(value = "è¯·æ±æ¶é´") |
| | | @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date requestTime; |
| | | /**ååºæ¶é´*/ |
| | | @ApiModelProperty(value = "ååºæ¶é´") |
| | | @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date responseTime; |
| | | /**è¯·æ±æ¹å¼*/ |
| | | @ApiModelProperty(value = "è¯·æ±æ¹å¼") |
| | | private String requestMethod; |
| | | /**请æ±å®æURL*/ |
| | | @ApiModelProperty(value = "请æ±URL") |
| | | private String requestUrl; |
| | | /**请æ±å¤´*/ |
| | | @ApiModelProperty(value = "请æ±å¤´") |
| | | private String requestHeaders; |
| | | /**请æ±ä½*/ |
| | | @ApiModelProperty(value = "请æ±ä½") |
| | | private String requestBody; |
| | | /**ååºç¼ç */ |
| | | @ApiModelProperty(value = "ååºç¼ç ") |
| | | private String responseCode; |
| | | /**ååºæ¶æ¯*/ |
| | | @ApiModelProperty(value = "ååºæ¶æ¯") |
| | | private String responseMessage; |
| | | /**ååºä½*/ |
| | | @ApiModelProperty(value = "ååºä½") |
| | | private String responseBody; |
| | | /**ç¶æ;æåã失败*/ |
| | | @ApiModelProperty(value = "ç¶æ;æåã失败") |
| | | private Integer requestStatus; |
| | | /**è°ç¨æ¹æ³*/ |
| | | @ApiModelProperty(value = "è°ç¨æ¹æ³") |
| | | private String method; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.system.mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.jeecg.modules.system.entity.SysApiLog; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | | /** |
| | | * @Description: ç³»ç»ç¬¬ä¸æ¹éææ¥å£æ¥å¿ |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-07-30 |
| | | * @Version: V1.0 |
| | | */ |
| | | public interface SysApiLogMapper extends BaseMapper<SysApiLog> { |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="org.jeecg.modules.system.mapper.SysApiLogMapper"> |
| | | |
| | | </mapper> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.system.service; |
| | | |
| | | import org.jeecg.modules.system.entity.SysApiLog; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | |
| | | /** |
| | | * @Description: ç³»ç»ç¬¬ä¸æ¹éææ¥å£æ¥å¿ |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-07-30 |
| | | * @Version: V1.0 |
| | | */ |
| | | public interface ISysApiLogService extends IService<SysApiLog> { |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.system.service.impl; |
| | | |
| | | import org.jeecg.modules.system.entity.SysApiLog; |
| | | import org.jeecg.modules.system.mapper.SysApiLogMapper; |
| | | import org.jeecg.modules.system.service.ISysApiLogService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | |
| | | /** |
| | | * @Description: ç³»ç»ç¬¬ä¸æ¹éææ¥å£æ¥å¿ |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-07-30 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service |
| | | public class SysApiLogServiceImpl extends ServiceImpl<SysApiLogMapper, SysApiLog> implements ISysApiLogService { |
| | | |
| | | } |