diff --git a/src/main/java/com/zcloud/aspect/DockAnnotation.java b/src/main/java/com/zcloud/aspect/DockAnnotation.java new file mode 100644 index 00000000..920b2b78 --- /dev/null +++ b/src/main/java/com/zcloud/aspect/DockAnnotation.java @@ -0,0 +1,18 @@ +package com.zcloud.aspect; + +import java.lang.annotation.*; + +/** + * @Description: 对接切面注解 + * @Author: dearLin + * @Date: 2023/3/8 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface DockAnnotation { + // 是否有额外数据 + boolean isAdd() default false; + //是否有附件 + boolean hasAnnex() default false; +} diff --git a/src/main/java/com/zcloud/aspect/DockingAspect.java b/src/main/java/com/zcloud/aspect/DockingAspect.java new file mode 100644 index 00000000..4b490833 --- /dev/null +++ b/src/main/java/com/zcloud/aspect/DockingAspect.java @@ -0,0 +1,146 @@ +package com.zcloud.aspect; + +import com.alibaba.fastjson.JSON; +import com.zcloud.dto.TenCorpDto; +import com.zcloud.entity.PageData; +import com.zcloud.service.docking.DockingRelationService; +import com.zcloud.service.mq.SendMessageService; +import com.zcloud.util.Jurisdiction; +import com.zcloud.util.Tools; +import com.zcloud.util.UuidUtil; +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.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 SendMessageService sendMessageService; + @Autowired + private DockingRelationService dockingRelationService; + + @Pointcut("@annotation(com.zcloud.aspect.DockAnnotation)") + public void pointcut() {} + + public static Map dockingRelationMap = new HashMap(); + + // 增强逻辑:在切点方法执行前打印日志 + @Around("pointcut()") + public Object beforeApi(ProceedingJoinPoint joinPoint) throws Throwable { + Map proceed = (HashMap)joinPoint.proceed(); + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = joinPoint.getTarget().getClass().getDeclaredMethod(signature.getName(), signature.getParameterTypes()); + try { + HttpServletRequest request = getRequest(); + //获取资源映射路径:servlet路径 + String servletPath = request.getServletPath(); + //验证该数据是否需要对接 + System.out.println("------------------------切面方法执行------------------------"); + //将路径换为对应的访问路径 + /*servletPath=dockingRelationMap.get(servletPath); + //完整访问路径(访问港务局的路径,不是被访问的路径) + String fullPath = gwjUrl+servletPath; + System.out.println("完整路径:"+fullPath);*/ + //获取所有访问参数 + PageData pageData = getPageData(); + DockAnnotation annotation = method.getAnnotation(DockAnnotation.class); + if (annotation != null) { + if (annotation.isAdd()){ + if (Tools.notEmpty(proceed.get("dockData"))){ + pageData.put("dockData",proceed.get("dockData")); + } + }else if (annotation.hasAnnex()) { + //查找附件 + String dockDataJson = pageData.getString("dockData"); + if (Tools.notEmpty(dockDataJson)){ + Map dockData = (Map) JSON.parse(dockDataJson); + String img = dockData.get("img"); + for (String imgurl : img.split(",")) { + //获取附件名称 + String[] split = imgurl.split("/"); + String filename = split[split.length - 1]; + PageData imgpd = new PageData(); + imgpd.put("imgUrl",imgurl); + imgpd.put("filename",filename); + imgpd.put("url","/file/saveImg"); + imgpd.put("TARGETURL","https://qgqy.qhdsafety.com/file/"); + imgpd.put("ORIGINURL","https://qgqy.qhdsafety.com/file/"); + TenCorpDto tenCorpDto = new TenCorpDto(); + tenCorpDto.setMessage("一条新增消息"); + tenCorpDto.setData(imgpd); + tenCorpDto.setId(UuidUtil.get32UUID()); + tenCorpDto.setTopic("docking"); + tenCorpDto.setProducer_name("qa-prevention-czks"); + sendMessageService.sendMessage(tenCorpDto); + } + } + } + } + PageData login_user = new PageData(); + 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()); + pageData.put("LOGIN_USER",login_user); + pageData.put("url",servletPath); + /*//连接redis + Jedis jedis = new Jedis(host,port); + //测试是否连接成功 + String ping = jedis.ping(); + System.out.println(ping); + //切换数据库 + String select = jedis.select(0); + System.out.println(select); + //存储数据至redis + String rq = JSON.toJSONString(map); + jedis.zadd("request",0,rq); + System.out.println(rq);*/ + TenCorpDto tenCorpDto = new TenCorpDto(); + tenCorpDto.setMessage("一条新增消息"); + tenCorpDto.setData(pageData); + tenCorpDto.setId(UuidUtil.get32UUID()); + tenCorpDto.setTopic("docking"); + tenCorpDto.setProducer_name("qa-prevention-czks"); + sendMessageService.sendMessage(tenCorpDto); + System.out.println("------------------------方法执行完毕------------------------"); + } catch (Exception e) { + throw new RuntimeException(e); + } + return proceed; + } + + @PostConstruct + private void initDockingRelationship() throws Exception { + dockingRelationMap = dockingRelationService.listAll(null); + } + + private PageData getPageData() { + return new PageData(this.getRequest()); + } + + /** + * 得到request对象 + * @return + */ + private HttpServletRequest getRequest() { + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) + .getRequest(); + return request; + } +} diff --git a/src/main/java/com/zcloud/mapper/datasource/docking/DockingRelationMapper.java b/src/main/java/com/zcloud/mapper/datasource/docking/DockingRelationMapper.java new file mode 100644 index 00000000..b964e038 --- /dev/null +++ b/src/main/java/com/zcloud/mapper/datasource/docking/DockingRelationMapper.java @@ -0,0 +1,16 @@ +package com.zcloud.mapper.datasource.docking; + +import com.zcloud.entity.PageData; + +import java.util.List; + +public interface DockingRelationMapper { + + /**列表(全部) + * @param pd + * @throws Exception + */ + List listAll(PageData pd); + +} + diff --git a/src/main/java/com/zcloud/service/docking/DockingRelationService.java b/src/main/java/com/zcloud/service/docking/DockingRelationService.java new file mode 100644 index 00000000..a6d7eb54 --- /dev/null +++ b/src/main/java/com/zcloud/service/docking/DockingRelationService.java @@ -0,0 +1,22 @@ +package com.zcloud.service.docking; + +import com.zcloud.entity.PageData; + +import java.util.Map; + +/** + * 说明:图片管理 + * 作者:luoxiaobao + * 时间:2020-12-24 + * 官网:www.zcloudchina.com + */ +public interface DockingRelationService { + + /**列表(全部) + * @param pd + * @throws Exception + */ + public Map listAll(PageData pd)throws Exception; + +} + diff --git a/src/main/java/com/zcloud/service/docking/impl/DockingRelationServiceImpl.java b/src/main/java/com/zcloud/service/docking/impl/DockingRelationServiceImpl.java new file mode 100644 index 00000000..5b20e73d --- /dev/null +++ b/src/main/java/com/zcloud/service/docking/impl/DockingRelationServiceImpl.java @@ -0,0 +1,43 @@ +package com.zcloud.service.docking.impl; + +import com.zcloud.entity.PageData; +import com.zcloud.mapper.datasource.docking.DockingRelationMapper; +import com.zcloud.service.docking.DockingRelationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 说明:图片管理 + * 作者:luoxiaobao + * 时间:2020-12-24 + * 官网:www.zcloudchina.com + */ +@Service +@Transactional //开启事物 +public class DockingRelationServiceImpl implements DockingRelationService { + + @Autowired + private DockingRelationMapper dockingRelationMapper; + + /**列表(全部) + * @param pd + * @throws Exception + */ + public Map listAll(PageData pd)throws Exception{ + HashMap relationMap = new HashMap<>(); + List relationList = dockingRelationMapper.listAll(pd); + for (PageData pageData : relationList) { + String originurl = pageData.getString("ORIGINURL"); + String targeturl = pageData.getString("TARGETURL"); + relationMap.put(originurl,targeturl); + } + return relationMap; + } + +} + diff --git a/src/main/resources/mybatis/datasource/docking/DockingRelationMapper.xml b/src/main/resources/mybatis/datasource/docking/DockingRelationMapper.xml new file mode 100644 index 00000000..e3cc6745 --- /dev/null +++ b/src/main/resources/mybatis/datasource/docking/DockingRelationMapper.xml @@ -0,0 +1,33 @@ + + + + + + + + SYS_DOCKING_RELATION + + + + f.DOCKING_RRELATION_ID, + f.ORIGINURL, + f.TARGETURL + + + + + #{DOCKING_RRELATION_ID}, + #{ORIGINURL}, + #{TARGETURL} + + + + + +