Browse Source

修改gitignore

suntg 8 years ago
parent
commit
0f19a58bbf

+ 0 - 1
.gitignore

@@ -46,7 +46,6 @@ hs_err_pid*
 
 # Maven
 target/
-log/
 
 ## Maven release plugin
 pom.xml.tag

+ 0 - 1
pom.xml

@@ -9,7 +9,6 @@
 		<groupId>com.uas.platform</groupId>
 		<artifactId>platform</artifactId>
 		<version>0.0.1-SNAPSHOT</version>
-		<relativePath>../platform</relativePath>
 	</parent>
 	<profiles>
 		<profile>

+ 38 - 0
src/main/java/com/uas/platform/b2c/core/support/log/ControllerUsageLog.java

@@ -0,0 +1,38 @@
+package com.uas.platform.b2c.core.support.log;
+
+import java.lang.annotation.*;
+
+/**
+ * Controller层用户操作日志记录注解
+ * Created by suntg on 2017/7/31.
+ */
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface ControllerUsageLog {
+
+    /**
+     * 模块
+     * @return
+     */
+    String module() default "";
+
+    /**
+     * 详细内容
+     * @return
+     */
+    String detail() default "";
+
+    /**
+     * 关联单据编号
+     * @return
+     */
+    String code() default "";
+
+    /**
+     * 关联单据ID
+     * @return
+     */
+    String key() default "";
+
+}

+ 62 - 0
src/main/java/com/uas/platform/b2c/core/support/log/ErpB2cBufferedLogger.java

@@ -0,0 +1,62 @@
+package com.uas.platform.b2c.core.support.log;
+
+import com.uas.platform.b2c.common.account.model.ErpB2cLog;
+import com.uas.platform.b2c.common.account.service.ErpB2cLogService;
+import com.uas.platform.b2c.core.utils.ContextUtils;
+import com.uas.platform.b2c.core.utils.PathUtils;
+import com.uas.platform.core.logging.BufferedLogger;
+
+/**
+ * 平台的异步日志记录的工具
+ * 
+ * @author suntg
+ * @date 2016年8月16日16:01:18
+ * 
+ */
+public class ErpB2cBufferedLogger extends BufferedLogger<ErpB2cLog> {
+
+	public ErpB2cBufferedLogger() {
+		super(PathUtils.getFilePath(), ErpB2cLog.class, ContextUtils.getBean(ErpB2cLogService.class));
+	}
+
+	/**
+	 * 记录平台使用日志
+	 * 
+	 * @param title
+	 *            消息标题
+	 * @param message
+	 *            消息
+	 */
+	public void log(String title, String message) {
+		log(new ErpB2cLog(title, message, null, null));
+	}
+
+	/**
+	 * 记录平台密码找回日志
+	 * 
+	 * @param title
+	 *            消息标题
+	 * @param message
+	 *            消息
+	 */
+	public void log(String title, String message, Long userUU, String ip) {
+		log(new ErpB2cLog(title, message, userUU, ip, null, null));
+	}
+
+	/**
+	 * 记录平台使用日志
+	 * 
+	 * @param title
+	 *            消息标题
+	 * @param message
+	 *            消息
+	 * @param relativeCode
+	 *            相关单据号
+	 * @param relativeKey
+	 *            相关单据主键
+	 */
+	public void log(String title, String message, String relativeCode, Long relativeKey) {
+		log(new ErpB2cLog(title, message, relativeCode, relativeKey));
+	}
+
+}

+ 13 - 0
src/main/java/com/uas/platform/b2c/core/support/log/ServiceUsageLog.java

@@ -0,0 +1,13 @@
+package com.uas.platform.b2c.core.support.log;
+
+import java.lang.annotation.*;
+
+/**
+ * Service层用户操作日志注解
+ * Created by suntg on 2017/7/31.
+ */
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface ServiceUsageLog {
+}

+ 94 - 0
src/main/java/com/uas/platform/b2c/core/support/log/TradeBufferedLogger.java

@@ -0,0 +1,94 @@
+package com.uas.platform.b2c.core.support.log;
+
+import com.uas.platform.b2c.common.account.model.TradeLog;
+import com.uas.platform.b2c.common.account.service.TradeLogService;
+import com.uas.platform.b2c.core.utils.ContextUtils;
+import com.uas.platform.b2c.core.utils.PathUtils;
+import com.uas.platform.b2c.logistics.model.InvoiceFOrder;
+import com.uas.platform.b2c.logistics.model.InvoiceFPurchase;
+import com.uas.platform.b2c.trade.order.model.Order;
+import com.uas.platform.b2c.trade.order.model.Purchase;
+import com.uas.platform.core.exception.IllegalOperatorException;
+import com.uas.platform.core.logging.BufferedLogger;
+
+/**
+ * 交易流程日志记录
+ *
+ * @author huxz
+ */
+public class TradeBufferedLogger extends BufferedLogger<TradeLog> {
+
+	public TradeBufferedLogger() {
+		super(PathUtils.getFilePath(), TradeLog.class, ContextUtils.getBean(TradeLogService.class));
+	}
+
+	/**
+	 * 记录交易流程操作日志
+	 *
+	 * @param entityName			操作单据实体类名称
+	 * @param voucherId				操作单据编号ID
+	 * @param voucherOperation		单据操作
+	 * @param changeLog				操作具体日志记录
+	 */
+	public void log(String entityName, String voucherId, TradeLog.VoucherOperation voucherOperation,
+			String changeLog) {
+		log(new TradeLog(entityName, voucherId, voucherOperation, changeLog));
+	}
+
+	/**
+	 * 记录交易流程订单操作日志
+	 *
+	 * @param order					状态变更的订单的实例
+	 * @param voucherOperation		单据操作
+	 * @param changeLog				操作具体日志记录
+	 */
+	public void log(Order order, TradeLog.VoucherOperation voucherOperation, String changeLog) {
+		if (order == null) {
+			throw new IllegalOperatorException("订单数据已失效");
+		}
+		log(order.getClass().getSimpleName(), order.getOrderid(), voucherOperation, changeLog);
+	}
+
+	/**
+	 * 记录交易流程采购单操作日志
+	 *
+	 * @param purchase				状态变更的采购单的实例
+	 * @param voucherOperation		单据操作
+	 * @param changeLog				操作具体日志记录
+	 */
+	public void log(Purchase purchase, TradeLog.VoucherOperation voucherOperation, String changeLog) {
+		if (purchase == null) {
+			throw new IllegalOperatorException("采购单数据已失效");
+		}
+		log(purchase.getClass().getSimpleName(), purchase.getPurchaseid(), voucherOperation, changeLog);
+	}
+
+	/**
+	 * 记录交易流程卖家出货单操作日志
+	 *
+	 * @param invoice				状态变更的卖家出货单的实例
+	 * @param voucherOperation		单据操作
+	 * @param changeLog				操作具体日志记录
+	 */
+	public void log(InvoiceFPurchase invoice, TradeLog.VoucherOperation voucherOperation, String changeLog) {
+		if (invoice == null) {
+			throw new IllegalOperatorException("卖家出货单数据已失效");
+		}
+		log(invoice.getClass().getSimpleName(), invoice.getInvoiceid(), voucherOperation, changeLog);
+	}
+
+	/**
+	 * 记录交易流程平台出货单操作日志
+	 *
+	 * @param invoice				状态变更的平台出货单的实例
+	 * @param voucherOperation		单据操作
+	 * @param changeLog				操作具体日志记录
+	 */
+	public void log(InvoiceFOrder invoice, TradeLog.VoucherOperation voucherOperation, String changeLog) {
+		if (invoice == null) {
+			throw new IllegalOperatorException("平台出货单数据已失效");
+		}
+		log(invoice.getClass().getSimpleName(), invoice.getInvoiceid(), voucherOperation, changeLog);
+	}
+
+}

+ 25 - 0
src/main/java/com/uas/platform/b2c/core/support/log/TradeLogTask.java

@@ -0,0 +1,25 @@
+package com.uas.platform.b2c.core.support.log;
+
+import com.uas.platform.core.logging.BufferedLoggerManager;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+@Component
+@EnableAsync
+@EnableScheduling
+public class TradeLogTask {
+
+	private final static TradeBufferedLogger logger = BufferedLoggerManager
+			.getLogger(TradeBufferedLogger.class);
+
+	@Scheduled(fixedRate = 60 * 1000)
+	@Async
+	public void execute() {
+		assert logger != null;
+		logger.switchOver();
+	}
+
+}

+ 234 - 0
src/main/java/com/uas/platform/b2c/core/support/log/UsageAopLog.java

@@ -0,0 +1,234 @@
+package com.uas.platform.b2c.core.support.log;
+
+import com.uas.platform.b2c.core.support.SystemSession;
+import com.uas.platform.core.logging.BufferedLogable;
+import org.springframework.util.StringUtils;
+
+/**
+ * 用户操作日志
+ * @author
+ * @version 2017年8月3日15:04:38 suntg 创建
+ */
+public class UsageAopLog  extends BufferedLogable {
+
+    /**
+     * id
+     */
+    private Long id;
+    /**
+     * 客户端IP地址
+     */
+    private String ip;
+    /**
+     * 发起时间
+     */
+    private Long date;
+    /**
+     * 操作请求uri
+     */
+    private String uri;
+    /**
+     * 操作请求对应的实现方法
+     */
+    private String method;
+    /**
+     * 请求参数
+     */
+    private String params;
+    /**
+     * 从开始到完成所用时间,毫秒
+     */
+    private long time;
+    /**
+     * 个人UU号,可以为空
+     */
+    private Long userUu;
+    /**
+     * 个人名字,可以为空
+     */
+    private String userName;
+    /**
+     * 企业UU号,可以为空
+     */
+    private Long enUu;
+    /**
+     * 企业名称,可以为空
+     */
+    private String enName;
+    /**
+     * 模块名称
+     */
+    private String module;
+    /**
+     * 操作详情
+     */
+    private String detail;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+
+    public String getIp() {
+        return ip;
+    }
+
+    public void setIp(String ip) {
+        this.ip = ip;
+    }
+
+    public Long getDate() {
+        return date;
+    }
+
+    public void setDate(Long date) {
+        this.date = date;
+    }
+
+    public String getUri() {
+        return uri;
+    }
+
+    public void setUri(String uri) {
+        this.uri = uri;
+    }
+
+    public String getMethod() {
+        return method;
+    }
+
+    public void setMethod(String method) {
+        this.method = method;
+    }
+
+    public String getParams() {
+        return params;
+    }
+
+    public void setParams(String params) {
+        this.params = params;
+    }
+
+    public long getTime() {
+        return time;
+    }
+
+    public void setTime(long time) {
+        this.time = time;
+    }
+
+    public Long getUserUu() {
+        return userUu;
+    }
+
+    public void setUserUu(Long userUu) {
+        this.userUu = userUu;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public Long getEnUu() {
+        return enUu;
+    }
+
+    public void setEnUu(Long enUu) {
+        this.enUu = enUu;
+    }
+
+    public String getEnName() {
+        return enName;
+    }
+
+    public void setEnName(String enName) {
+        this.enName = enName;
+    }
+
+    public String getModule() {
+        return module;
+    }
+
+    public void setModule(String module) {
+        this.module = module;
+    }
+
+    public String getDetail() {
+        return detail;
+    }
+
+    public void setDetail(String detail) {
+        this.detail = detail;
+    }
+
+    @Override
+    public String bufferedMessage() {
+        StringBuffer sb = new StringBuffer();
+        sb.append(this.ip).append(separator);
+        sb.append(this.date).append(separator);
+        sb.append(this.uri).append(separator);
+        sb.append(this.method).append(separator);
+        sb.append(this.params).append(separator);
+        sb.append(this.time).append(separator);
+        sb.append(this.userUu == null ? " " : this.userUu).append(separator);
+        sb.append(this.userName == null ? " " : this.userName).append(separator);
+        sb.append(this.enUu == null ? " " : this.enUu).append(separator);
+        sb.append(this.enName == null ? " " : this.enName).append(separator);
+        sb.append(this.module == null ? " " : this.module).append(separator);
+        sb.append(this.detail == null ? " " : this.detail);
+        return sb.toString();
+    }
+
+    @Override
+    public void bufferedLog(String bufferedMessage) {
+        String[] strArray = bufferedMessage.split(separator);
+        if (strArray.length == 12) {
+            this.ip = strArray[0];
+            if (!strArray[1].equals("null"))
+                this.date = Long.parseLong(strArray[1]);
+            this.uri = strArray[2];
+            this.method = strArray[3];
+            this.params = strArray[4];
+            if (!strArray[5].equals("null"))
+                this.time = Long.parseLong(strArray[5]);
+            if (!strArray[6].equals(" "))
+                this.userUu = Long.parseLong(strArray[6]);
+            this.userName = StringUtils.hasText(strArray[7]) ? strArray[7] : null;
+            if (!strArray[8].equals(" "))
+                this.enUu = Long.parseLong(strArray[8]);
+            this.enName = StringUtils.hasText(strArray[9]) ? strArray[9] : null;
+            this.module = StringUtils.hasText(strArray[10]) ? strArray[10] : null;
+            this.detail = StringUtils.hasText(strArray[11]) ? strArray[11] : null;
+        }
+    }
+
+    public UsageAopLog() {
+    }
+
+    public UsageAopLog(String ip, Long date, String uri, String method, String params, long time, String module, String detail) {
+        this.ip = ip;
+        this.uri = uri;
+        this.method = method;
+        this.date = date;
+        this.params = params;
+        this.time = time;
+        this.module = module;
+        this.detail = detail;
+        if(SystemSession.getUser() != null) {
+            this.userUu = SystemSession.getUser().getUserUU();
+            this.userName = SystemSession.getUser().getUserName();
+            if(SystemSession.getUser().getEnterprise() != null) {
+                this.enName = SystemSession.getUser().getEnterprise().getEnName();
+                this.enUu = SystemSession.getUser().getEnterprise().getUu();
+            }
+        }
+    }
+}

+ 31 - 0
src/main/java/com/uas/platform/b2c/core/support/log/UsageAopLogTask.java

@@ -0,0 +1,31 @@
+package com.uas.platform.b2c.core.support.log;
+
+import com.uas.platform.core.logging.BufferedLoggerManager;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * 定时任务<br>
+ * 将平台使用记录的日志文件的内容每隔60秒持久化一次
+ * 
+ * @author suntg
+ * @date 2016年8月16日16:01:41
+ *
+ */
+@Component
+@EnableAsync
+@EnableScheduling
+public class UsageAopLogTask {
+
+	private final static UsageAopLogger logger = BufferedLoggerManager.getLogger(UsageAopLogger.class);
+
+	@Scheduled(fixedRate = 60 * 1000)
+	@Async
+	public void execute() {
+		logger.switchOver();
+	}
+
+}

+ 29 - 0
src/main/java/com/uas/platform/b2c/core/support/log/UsageAopLogger.java

@@ -0,0 +1,29 @@
+package com.uas.platform.b2c.core.support.log;
+
+import com.uas.platform.b2c.common.account.service.UsageAopLogService;
+import com.uas.platform.b2c.core.utils.ContextUtils;
+import com.uas.platform.b2c.core.utils.PathUtils;
+import com.uas.platform.core.logging.BufferedLogger;
+
+/**
+ * 平台的异步日志记录的工具
+ * 
+ * @author suntg
+ * @date 2016年8月16日16:01:18
+ * 
+ */
+public class UsageAopLogger extends BufferedLogger<UsageAopLog> {
+
+	public UsageAopLogger() {
+		super(PathUtils.getFilePath(), UsageAopLog.class, ContextUtils.getBean(UsageAopLogService.class));
+	}
+
+	/**
+	 * 记录平台使用日志
+	 * 
+	 */
+	public void log(String ip, Long date, String uri, String method, String params, long time, String module, String detail) {
+		log(new UsageAopLog(ip, date, uri, method, params, time, module, detail));
+	}
+
+}

+ 78 - 0
src/main/java/com/uas/platform/b2c/core/support/log/UsageBufferedLogger.java

@@ -0,0 +1,78 @@
+package com.uas.platform.b2c.core.support.log;
+
+import com.uas.platform.b2c.common.account.model.UsageLog;
+import com.uas.platform.b2c.common.account.service.UsageLogService;
+import com.uas.platform.b2c.core.utils.ContextUtils;
+import com.uas.platform.b2c.core.utils.PathUtils;
+import com.uas.platform.core.logging.BufferedLogger;
+
+/**
+ * 平台的异步日志记录的工具
+ * 
+ * @author suntg
+ * @date 2016年8月16日16:01:18
+ * 
+ */
+public class UsageBufferedLogger extends BufferedLogger<UsageLog> {
+
+	public UsageBufferedLogger() {
+		super(PathUtils.getFilePath(), UsageLog.class, ContextUtils.getBean(UsageLogService.class));
+	}
+
+	/**
+	 * 记录平台使用日志
+	 * 
+	 * @param title
+	 *            消息标题
+	 * @param message
+	 *            消息
+	 */
+	public void log(String title, String message) {
+		log(new UsageLog(title, message, null, null, null));
+	}
+
+	/**
+	 * 记录平台密码找回日志
+	 * 
+	 * @param title
+	 *            消息标题
+	 * @param message
+	 *            消息
+	 */
+	public void log(String title, String message, Long userUU, String ip) {
+		log(new UsageLog(title, message, userUU, ip, null, null));
+	}
+
+	/**
+	 * 记录平台使用日志
+	 * 
+	 * @param title
+	 *            消息标题
+	 * @param message
+	 *            消息
+	 * @param description
+	 *            消息详细描述
+	 */
+	public void log(String title, String message, String description) {
+		log(new UsageLog(title, message, description, null, null));
+	}
+
+	/**
+	 * 记录平台使用日志
+	 * 
+	 * @param title
+	 *            消息标题
+	 * @param message
+	 *            消息
+	 * @param description
+	 *            消息详细描述
+	 * @param relativeCode
+	 *            相关单据号
+	 * @param relativeKey
+	 *            相关单据主键
+	 */
+	public void log(String title, String message, String description, String relativeCode, Long relativeKey) {
+		log(new UsageLog(title, message, description, relativeCode, relativeKey));
+	}
+
+}

+ 108 - 0
src/main/java/com/uas/platform/b2c/core/support/log/UsageLogAspect.java

@@ -0,0 +1,108 @@
+package com.uas.platform.b2c.core.support.log;
+
+import com.uas.platform.b2c.core.utils.FastjsonUtils;
+import com.uas.platform.core.logging.BufferedLoggerManager;
+import com.wordnik.swagger.annotations.ApiOperation;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.lang.reflect.Method;
+import java.util.Date;
+
+/**
+ * Controller用户操作日志
+ * Created by suntg on 2017/7/31.
+ */
+@Aspect
+@Component
+public class UsageLogAspect {
+
+    private static final UsageAopLogger logger = BufferedLoggerManager.getLogger(UsageAopLogger.class);
+
+    /**
+     * controller层切点
+     */
+    @Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
+    public void controllerAspect() {
+
+    }
+
+    /**
+     * service层切点
+     */
+    @Pointcut("@annotation(com.uas.platform.b2c.core.support.log.ServiceUsageLog)")
+    public void serviceAspect() {
+
+    }
+
+    // TODO 暂时不做日志记录
+    // @Around("controllerAspect()")
+    public Object doBefore(ProceedingJoinPoint joinPoint) throws Throwable {
+        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+        HttpSession session = request.getSession();
+        //请求的IP
+        String ip = request.getRemoteAddr();
+        String uri = request.getRequestURI();
+        String methodName = joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()";
+        String params = FastjsonUtils.toJson(request.getParameterMap());
+        Date date = new Date();
+        String module = null;
+        String detail = null;
+        Method method = getMethod(joinPoint);
+
+        try {
+            ApiOperation apiOperation = method.getAnnotation(ApiOperation.class);
+            if(apiOperation != null) {
+                detail = apiOperation.value();
+            }
+        } catch (Exception e) {
+            detail = null;
+        }
+
+        // 执行
+        Object object = joinPoint.proceed();
+
+        Date doneDate = new Date();
+        long time = doneDate.getTime() - date.getTime();
+
+        assert logger != null;
+        // TODO 暂时不记录操作日志
+        // logger.log(ip, date.getTime(), uri, methodName, params, time, module, detail);
+
+        return object;
+    }
+
+    /**
+     * 根据切点获取对应的方法对象
+     * @param joinPoint
+     * @return
+     * @throws Exception
+     */
+    public static Method getMethod(JoinPoint joinPoint)  throws Exception {
+        String targetName = joinPoint.getTarget().getClass().getName();
+        String methodName = joinPoint.getSignature().getName();
+        Object[] arguments = joinPoint.getArgs();
+        Class targetClass = Class.forName(targetName);
+        Method[] methods = targetClass.getMethods();
+        Method _method = null;
+        for (Method method : methods) {
+            if (method.getName().equals(methodName)) {
+                Class[] params = method.getParameterTypes();
+                if (params.length == arguments.length) {
+                    _method = method;
+                    break;
+                }
+            }
+        }
+        return _method;
+    }
+
+
+}

+ 33 - 0
src/main/java/com/uas/platform/b2c/core/support/log/UsageLogTask.java

@@ -0,0 +1,33 @@
+package com.uas.platform.b2c.core.support.log;
+
+import com.uas.platform.core.logging.BufferedLoggerManager;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * 定时任务<br>
+ * 将平台使用记录的日志文件的内容每隔60秒持久化一次
+ * 
+ * @author suntg
+ * @date 2016年8月16日16:01:41
+ *
+ */
+@Component
+@EnableAsync
+@EnableScheduling
+public class UsageLogTask {
+
+	private final static UsageBufferedLogger logger = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
+	private final static ErpB2cBufferedLogger erpB2cLogger = BufferedLoggerManager.getLogger(ErpB2cBufferedLogger.class);
+
+	@Scheduled(fixedRate = 60 * 1000)
+	@Async
+	public void execute() {
+		logger.switchOver();
+		erpB2cLogger.switchOver();
+	}
+
+}