134 lines
5.4 KiB
Java
134 lines
5.4 KiB
Java
|
package com.zcloud.aspect;
|
|||
|
|
|||
|
import com.alibaba.fastjson.JSON;
|
|||
|
import com.zcloud.dto.TenCorpDto;
|
|||
|
import com.zcloud.entity.PageData;
|
|||
|
import com.zcloud.entity.system.User;
|
|||
|
import com.zcloud.service.mq.DockSendMessageService;
|
|||
|
import com.zcloud.util.Const;
|
|||
|
import com.zcloud.util.Jurisdiction;
|
|||
|
import com.zcloud.util.Tools;
|
|||
|
import com.zcloud.util.UuidUtil;
|
|||
|
import org.apache.shiro.session.Session;
|
|||
|
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.springframework.beans.factory.annotation.Autowired;
|
|||
|
import org.springframework.beans.factory.annotation.Value;
|
|||
|
import org.springframework.stereotype.Component;
|
|||
|
import org.springframework.web.context.request.RequestContextHolder;
|
|||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|||
|
|
|||
|
import javax.annotation.PostConstruct;
|
|||
|
import javax.servlet.http.HttpServletRequest;
|
|||
|
import java.lang.reflect.Method;
|
|||
|
import java.util.HashMap;
|
|||
|
import java.util.Map;
|
|||
|
|
|||
|
@Component
|
|||
|
@Aspect
|
|||
|
public class DockingAspect {
|
|||
|
@Autowired
|
|||
|
private DockSendMessageService sendMessageService;
|
|||
|
@Value("${baseimgpath}")
|
|||
|
public String baseimgpath;
|
|||
|
@Pointcut("@annotation(com.zcloud.aspect.DockAnnotation)")
|
|||
|
public void pointcut() {
|
|||
|
}
|
|||
|
|
|||
|
public static Map<String, String> dockingRelationMap = new HashMap();
|
|||
|
|
|||
|
// 增强逻辑:在切点方法执行前打印日志
|
|||
|
@Around("pointcut()")
|
|||
|
public Object beforeApi(ProceedingJoinPoint joinPoint) throws Throwable {
|
|||
|
|
|||
|
try {
|
|||
|
Object proceed = joinPoint.proceed();
|
|||
|
HashMap<String, String> parseProceed = JSON.parseObject(JSON.toJSONString(proceed), HashMap.class);
|
|||
|
if (parseProceed == null) {
|
|||
|
return parseProceed;
|
|||
|
}
|
|||
|
// 数据同步
|
|||
|
dataSync(parseProceed, joinPoint);
|
|||
|
return proceed;
|
|||
|
} catch (Exception e) {
|
|||
|
throw e;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void dataSync(HashMap<String, String> proceed, ProceedingJoinPoint joinPoint) throws Exception {
|
|||
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
|||
|
Method method = joinPoint.getTarget().getClass().getDeclaredMethod(signature.getName(), signature.getParameterTypes());
|
|||
|
DockAnnotation annotation = method.getAnnotation(DockAnnotation.class);
|
|||
|
//获取资源映射路径:servlet路径
|
|||
|
String servletPath = getRequest().getServletPath();
|
|||
|
//验证该数据是否需要对接
|
|||
|
System.out.println("------------------------切面方法执行------------------------");
|
|||
|
PageData sendData = this.getPageData();
|
|||
|
// app 方法 不取session
|
|||
|
PageData login_user = new PageData();
|
|||
|
if (!servletPath.contains("/app/")) {
|
|||
|
login_user.put("USER_ID", Jurisdiction.getUSER_ID());
|
|||
|
login_user.put("USERNAME", Jurisdiction.getUsername());
|
|||
|
login_user.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
|
|||
|
login_user.put("DEPARTMENT_ID", Jurisdiction.getDEPARTMENT_ID());
|
|||
|
login_user.put("NAME", Jurisdiction.getName());
|
|||
|
login_user.put("ISSUPERVISE", Jurisdiction.getISSUPERVISE());
|
|||
|
login_user.put("POST_ID", Jurisdiction.getPOST_ID());
|
|||
|
login_user.put("IS_MAIN", Jurisdiction.getIS_MAIN());
|
|||
|
Session session = Jurisdiction.getSession();
|
|||
|
User user = (User)session.getAttribute(Const.SESSION_USER);
|
|||
|
login_user.put("user",JSON.toJSONString(user));
|
|||
|
sendData.put("LOGIN_USER", login_user);
|
|||
|
} else {
|
|||
|
// 手机app 会传递值。
|
|||
|
login_user.put("USER_ID", Tools.notEmpty(sendData.getString("USER_ID")) ? sendData.getString("USER_ID") : "");
|
|||
|
sendData.put("LOGIN_USER", login_user);
|
|||
|
}
|
|||
|
// 路径地址
|
|||
|
sendData.put("url", servletPath);
|
|||
|
// 有存自己表里的图片 把自己图片服务器的前缀传过去
|
|||
|
if (annotation.hasAnnex()) {
|
|||
|
sendData.put("BASEIMGPATH", baseimgpath);
|
|||
|
// 自己表里的图片集合
|
|||
|
sendData.put("sendPicturesList", proceed.get("sendPicturesList"));
|
|||
|
proceed.remove("sendPicturesList");
|
|||
|
}
|
|||
|
TenCorpDto tenCorpDto = new TenCorpDto();
|
|||
|
tenCorpDto.setMessage("港务局数据同步消息");
|
|||
|
tenCorpDto.setData(sendData);
|
|||
|
tenCorpDto.setId(UuidUtil.get32UUID());
|
|||
|
tenCorpDto.setTopic("docking");
|
|||
|
tenCorpDto.setProducer_name("qa-prevention-czks");
|
|||
|
// 有dockData
|
|||
|
if (Tools.notEmpty(proceed.get("dockData"))) {
|
|||
|
sendData.put("dockData", proceed.get("dockData"));
|
|||
|
proceed.remove("dockData");
|
|||
|
sendMessageService.sendMessage(tenCorpDto);
|
|||
|
} else {
|
|||
|
System.out.println("------------------------无dockData不发消息------------------------");
|
|||
|
}
|
|||
|
|
|||
|
System.out.println("------------------------切面方法结束------------------------");
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private PageData getPageData() {
|
|||
|
return new PageData(this.getRequest());
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 得到request对象
|
|||
|
*
|
|||
|
* @return
|
|||
|
*/
|
|||
|
private HttpServletRequest getRequest() {
|
|||
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
|||
|
.getRequest();
|
|||
|
return request;
|
|||
|
}
|
|||
|
}
|