26 changed files with 2504 additions and 478 deletions
File diff suppressed because it is too large
@ -1,14 +0,0 @@ |
|||||
package org.nl.acs.common.aspect; |
|
||||
|
|
||||
import java.lang.annotation.*; |
|
||||
|
|
||||
/** |
|
||||
* @author geng by |
|
||||
*/ |
|
||||
@Target({ElementType.TYPE,ElementType.METHOD}) |
|
||||
@Retention(RetentionPolicy.RUNTIME) |
|
||||
@Documented |
|
||||
public @interface TaskAnnotation { |
|
||||
String module() default ""; |
|
||||
String operator() default ""; |
|
||||
} |
|
@ -1,203 +0,0 @@ |
|||||
package org.nl.acs.common.aspect; |
|
||||
|
|
||||
import cn.hutool.core.date.DateUtil; |
|
||||
import cn.hutool.core.util.IdUtil; |
|
||||
import cn.hutool.core.util.ObjectUtil; |
|
||||
import cn.hutool.core.util.StrUtil; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
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.nl.acs.task.service.TaskService; |
|
||||
import org.nl.acs.task.service.dto.TaskDto; |
|
||||
import org.nl.modules.system.util.CodeUtil; |
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
|
|
||||
import java.lang.reflect.Field; |
|
||||
import java.lang.reflect.Method; |
|
||||
import java.util.Date; |
|
||||
|
|
||||
/** |
|
||||
* @author geng by |
|
||||
*/ |
|
||||
@Component |
|
||||
@Aspect |
|
||||
@Slf4j |
|
||||
public class TaskAspect { |
|
||||
|
|
||||
@Autowired |
|
||||
TaskService taskserver; |
|
||||
|
|
||||
@Pointcut("@annotation(org.nl.acs.common.aspect.TaskAnnotation)") |
|
||||
public void pt() { |
|
||||
} |
|
||||
|
|
||||
//使用环绕通知.proceedingJoinPoint接口表示连接点,目标方法的对象
|
|
||||
@Around("pt()") |
|
||||
public synchronized Object around(ProceedingJoinPoint pjp) { |
|
||||
|
|
||||
MethodSignature signature = (MethodSignature) pjp.getSignature(); |
|
||||
|
|
||||
/*Method method = signature.getMethod(); |
|
||||
Class<?> targetDriverClass = method.getDeclaringClass();*/ |
|
||||
String res = null; |
|
||||
Object[] args = pjp.getArgs(); |
|
||||
Object arg = args[0]; |
|
||||
Class<?> targetDriverClass = arg.getClass(); |
|
||||
Field instruction_apply_time = null; |
|
||||
try { |
|
||||
instruction_apply_time = targetDriverClass.getDeclaredField("instruction_apply_time"); |
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
} |
|
||||
String instruction_apply_timeName = null; |
|
||||
if (ObjectUtil.isNotEmpty(instruction_apply_time)) { |
|
||||
instruction_apply_time.setAccessible(true); |
|
||||
instruction_apply_timeName = instruction_apply_time.getName(); |
|
||||
} |
|
||||
Date nowDate = null; |
|
||||
if (ObjectUtil.isNotEmpty(instruction_apply_timeName)) { |
|
||||
try { |
|
||||
nowDate = (Date) instruction_apply_time.get(instruction_apply_timeName); |
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
} |
|
||||
} |
|
||||
Field instruction_require_time_out = null; |
|
||||
try { |
|
||||
instruction_require_time_out = targetDriverClass.getDeclaredField("instruction_require_time_out"); |
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
} |
|
||||
String instruction_require_time_outName = ""; |
|
||||
if (ObjectUtil.isNotEmpty(instruction_require_time_out)) { |
|
||||
instruction_require_time_out.setAccessible(true); |
|
||||
instruction_require_time_outName = instruction_require_time_out.getName(); |
|
||||
} |
|
||||
long minTime = 0L; |
|
||||
try { |
|
||||
minTime = (long) instruction_require_time_out.get(instruction_require_time_outName); |
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
} |
|
||||
if (minTime != 0L) { |
|
||||
Date date = new Date(); |
|
||||
if (date.getTime() - nowDate.getTime() < minTime) { |
|
||||
log.trace("触发时间因为小于{}毫秒,而被无视", minTime); |
|
||||
return false; |
|
||||
} else { |
|
||||
Boolean flag = false; |
|
||||
try { |
|
||||
res = (String) pjp.proceed(); |
|
||||
} catch (Throwable throwable) { |
|
||||
throwable.printStackTrace(); |
|
||||
} |
|
||||
if (StrUtil.isNotEmpty(res)) { |
|
||||
String start_device_code = ""; |
|
||||
String next_device_code = ""; |
|
||||
String reqsucess = ""; |
|
||||
if (StrUtil.isNotEmpty(res)) { |
|
||||
String[] ress = res.split("\\,"); |
|
||||
if (ress.length == 3) { |
|
||||
start_device_code = ress[0]; |
|
||||
next_device_code = ress[1]; |
|
||||
reqsucess = ress[2]; |
|
||||
} |
|
||||
TaskDto onedto = new TaskDto(); |
|
||||
String now = DateUtil.now(); |
|
||||
onedto.setTask_id(IdUtil.simpleUUID()); |
|
||||
//onedto.setQuantity(String.valueOf(full_number));
|
|
||||
onedto.setCreate_by("auto"); |
|
||||
onedto.setUpdate_by("auto"); |
|
||||
onedto.setRoute_plan_code("normal"); |
|
||||
String taskcode = CodeUtil.getNewCode("TASK_NO"); |
|
||||
onedto.setTask_code("-" + taskcode); |
|
||||
onedto.setTask_type("7"); |
|
||||
onedto.setTask_status("0"); |
|
||||
onedto.setPriority("1"); |
|
||||
onedto.setStart_device_code(start_device_code); |
|
||||
onedto.setStart_point_code(start_device_code); |
|
||||
onedto.setNext_device_code(next_device_code); |
|
||||
onedto.setNext_point_code(next_device_code); |
|
||||
onedto.setUpdate_time(now); |
|
||||
onedto.setCreate_time(now); |
|
||||
try { |
|
||||
taskserver.create(onedto); |
|
||||
flag = true; |
|
||||
} catch (Exception e) { |
|
||||
//logServer.deviceLogToacs(this.device_code, "", "", device_code + ":创建任务失败," + String.valueOf(e.getMessage()));
|
|
||||
} |
|
||||
/* if (ress.length == 4){ |
|
||||
String start_device_code = ress[0]; |
|
||||
String next_device_code = ress[1]; |
|
||||
String reqsucess = ress[2]; |
|
||||
}*/ |
|
||||
} |
|
||||
//生成任务成功
|
|
||||
if (flag) { |
|
||||
Method reqMethod = null; |
|
||||
//logServer.deviceLogToacs(this.device_code, "", "", device_code + ":缺料请求任务生成成功");
|
|
||||
try { |
|
||||
reqMethod = targetDriverClass.getMethod("set" + initialUpperCase(reqsucess), boolean.class); |
|
||||
} catch (NoSuchMethodException e) { |
|
||||
e.printStackTrace(); |
|
||||
} |
|
||||
if (ObjectUtil.isNotEmpty(reqMethod)) { |
|
||||
try { |
|
||||
reqMethod.invoke(arg, true); |
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
} |
|
||||
} |
|
||||
} else { |
|
||||
//logServer.deviceLogToacs(this.device_code, "", "", device_code + ":分配任务缓存线");
|
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
return res; |
|
||||
} |
|
||||
|
|
||||
//首字母转大写
|
|
||||
public String initialUpperCase(String str) { |
|
||||
return str.substring(0, 1).toUpperCase() + str.substring(1, str.length()); |
|
||||
} |
|
||||
|
|
||||
private void recordLog(ProceedingJoinPoint pjp, long time) { |
|
||||
MethodSignature signature = (MethodSignature) pjp.getSignature(); |
|
||||
Method method = signature.getMethod(); |
|
||||
//注解
|
|
||||
TaskAnnotation annotation = method.getAnnotation(TaskAnnotation.class); |
|
||||
Class<?> targetClass = method.getDeclaringClass(); |
|
||||
//方法
|
|
||||
String target = targetClass.getName() + "#" + method.getName(); |
|
||||
|
|
||||
//参数名
|
|
||||
String[] strings = signature.getParameterNames(); |
|
||||
//参数值
|
|
||||
Object[] method_args = pjp.getArgs(); |
|
||||
|
|
||||
String params = ""; |
|
||||
if (strings != null && strings.length > 0) { |
|
||||
for (int i = 0; i < strings.length; i++) { |
|
||||
params += strings[i] + "=" + method_args[i] + ","; |
|
||||
} |
|
||||
//拼接参数和参数值
|
|
||||
params = params.substring(0, params.length() - 1); |
|
||||
} |
|
||||
|
|
||||
String module = annotation.module(); |
|
||||
String operator = annotation.operator(); |
|
||||
log.info("==============================log start==============================="); |
|
||||
log.info("module:{}", module); |
|
||||
log.info("operator:{}", operator); |
|
||||
log.info("执行的方法{}:", target); |
|
||||
log.info("请求的参数{}:", params); |
|
||||
log.info("===============================log end================================"); |
|
||||
|
|
||||
} |
|
||||
} |
|
@ -0,0 +1,16 @@ |
|||||
|
import java.net.Inet4Address; |
||||
|
import java.net.InetAddress; |
||||
|
import java.net.UnknownHostException; |
||||
|
|
||||
|
/** |
||||
|
* @author: geng by |
||||
|
* @createDate: 2022/8/1 |
||||
|
*/ |
||||
|
public class Test { |
||||
|
|
||||
|
@org.junit.Test |
||||
|
public void test() throws UnknownHostException { |
||||
|
InetAddress localHost = Inet4Address.getLocalHost(); |
||||
|
System.out.println(localHost.getHostAddress()); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue