异步注解和日志
This commit is contained in:
parent
bfc250f562
commit
b5c9ef7a5a
@ -0,0 +1,14 @@
|
||||
package com.czlis.common.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 异步任务注解
|
||||
*/
|
||||
@Target({ ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface Async {
|
||||
|
||||
|
||||
}
|
||||
@ -55,4 +55,9 @@ public enum BusinessType {
|
||||
* 清空数据
|
||||
*/
|
||||
CLEAN,
|
||||
|
||||
/**
|
||||
* 接口调用
|
||||
*/
|
||||
INTERFACE_INVOKE,
|
||||
}
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
package com.czlis.interfaceCommon.constants;
|
||||
|
||||
public class SampleStatusConstants {
|
||||
|
||||
public static final String SIGNFOR = "2"; //标本签收
|
||||
}
|
||||
@ -5,7 +5,10 @@ import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.czlis.common.annotation.Async;
|
||||
import com.czlis.common.annotation.Log;
|
||||
import com.czlis.common.config.RuoYiConfig;
|
||||
import com.czlis.common.enums.BusinessType;
|
||||
import com.czlis.interfaceCommon.constants.LisinterfaceNameConstants;
|
||||
import com.czlis.common.core.domain.Result;
|
||||
import com.czlis.interfaceCommon.mapper.LisInterfaceMapper;
|
||||
@ -27,13 +30,15 @@ public class LisInterfaceUtil {
|
||||
CommonUtil commonUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* 接口调用
|
||||
* @param type
|
||||
* @param inValue
|
||||
* @return
|
||||
*/
|
||||
@Log(title = "接口调用",businessType = BusinessType.INTERFACE_INVOKE)
|
||||
public Result invokeLisInterface(String type,String inValue) {
|
||||
String interfaceType = commonUtil.getComOptValue("HISOPT","SP_INTER");
|
||||
log.info("开始调用{}接口,入参:{}",type,interfaceType);
|
||||
switch (interfaceType){
|
||||
case "2": //存储过程
|
||||
return invokeSP(type, inValue);
|
||||
@ -109,7 +114,9 @@ public class LisInterfaceUtil {
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("调用lis的http接口出错:",e);
|
||||
return new Result("-1","调用http接口失败:"+e.getMessage());
|
||||
}
|
||||
log.info("调用http接口成功类型:{},入参:{}/r/n,出参:{}",transCode,jsonStr,retMsg);
|
||||
String message="";
|
||||
String resultCode="";
|
||||
// 检查输入是否为空
|
||||
@ -125,6 +132,11 @@ public class LisInterfaceUtil {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 把json格式转换成xml格式
|
||||
* @param inValue
|
||||
* @return
|
||||
*/
|
||||
public String changeXml(String inValue){
|
||||
JSONObject jsonObj = JSONUtil.parseObj(inValue);
|
||||
Map<String,Object> map = jsonObj.toBean(Map.class);
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
package com.czlis.system.aspectj;
|
||||
|
||||
import com.czlis.common.annotation.Async;
|
||||
import com.czlis.system.manager.AsyncManager;
|
||||
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.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* 异步任务处理
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AsyncAspect {
|
||||
|
||||
|
||||
/**
|
||||
* 环绕通知:拦截被@Async标注的方法,将其异步执行
|
||||
*
|
||||
* @param joinPoint 切点
|
||||
*/
|
||||
@Around("@annotation(async)")
|
||||
public Object doAround(ProceedingJoinPoint joinPoint, Async async) throws Throwable {
|
||||
// 1. 获取目标方法信息
|
||||
Object targetObject = joinPoint.getTarget();
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method targetMethod = signature.getMethod();
|
||||
Object[] methodArgs = joinPoint.getArgs();
|
||||
|
||||
// 2. 将目标方法调用包装成TimerTask
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// 异步执行目标方法
|
||||
targetMethod.invoke(targetObject, methodArgs);
|
||||
} catch (Exception e) {
|
||||
log.error("异步执行方法失败", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 3. 通过AsyncManager提交异步任务(不修改原有AsyncManager)
|
||||
AsyncManager.me().execute(task);
|
||||
|
||||
// 4. 若原方法有返回值,可返回null或自定义结果(异步方法通常建议返回void)
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -6,6 +6,7 @@ import com.czlis.interfaceCommon.constants.LisinterfaceNameConstants;
|
||||
import com.czlis.common.core.domain.Result;
|
||||
import com.czlis.common.core.domain.entity.LabPat;
|
||||
import com.czlis.common.core.domain.entity.LabReqmain;
|
||||
import com.czlis.interfaceCommon.constants.SampleStatusConstants;
|
||||
import com.czlis.interfaceCommon.mapper.LabReqmainMapper;
|
||||
import com.czlis.interfaceCommon.pojo.inter.DayMessage;
|
||||
import com.czlis.interfaceCommon.pojo.inter.GetReqInterface;
|
||||
@ -73,7 +74,7 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
|
||||
setReqStatus.setIp("");
|
||||
setReqStatus.setSqh(sqh);
|
||||
setReqStatus.setUserid(userId.toString());
|
||||
setReqStatus.setStatus("2");
|
||||
setReqStatus.setStatus(SampleStatusConstants.SIGNFOR);
|
||||
String jsonStr = JSONUtil.toJsonStr(setReqStatus);
|
||||
Result result = lisInterfaceUtil.invokeLisInterface(LisinterfaceNameConstants.SETREQSTATUS, jsonStr);
|
||||
if(!result.getCode().equals("0")) return result;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user