diff --git a/src/main/java/com/zcloud/aspect/DockingAspect.java b/src/main/java/com/zcloud/aspect/DockingAspect.java index 4b490833..4b48606f 100644 --- a/src/main/java/com/zcloud/aspect/DockingAspect.java +++ b/src/main/java/com/zcloud/aspect/DockingAspect.java @@ -5,6 +5,7 @@ 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.DateUtil; import com.zcloud.util.Jurisdiction; import com.zcloud.util.Tools; import com.zcloud.util.UuidUtil; @@ -14,6 +15,7 @@ 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; @@ -21,6 +23,7 @@ import org.springframework.web.context.request.ServletRequestAttributes; import javax.annotation.PostConstruct; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -29,8 +32,17 @@ import java.util.Map; public class DockingAspect { @Autowired private SendMessageService sendMessageService; - @Autowired - private DockingRelationService dockingRelationService; + + @Value("${mq.csy.data.topic}") + private String csyDataDocking; + + @Value("${mq.cmt.data.topic}") + private String cmtDataDocking; + @Value("${mq.czks.data.topic}") + private String czksDataDocking; + + @Value("${baseimgpath}") + public String baseimgpath; @Pointcut("@annotation(com.zcloud.aspect.DockAnnotation)") public void pointcut() {} @@ -40,94 +52,95 @@ public class DockingAspect { // 增强逻辑:在切点方法执行前打印日志 @Around("pointcut()") public Object beforeApi(ProceedingJoinPoint joinPoint) throws Throwable { - Map proceed = (HashMap)joinPoint.proceed(); + try { + Object proceed = joinPoint.proceed(); + HashMap 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 proceed, ProceedingJoinPoint joinPoint) throws Exception { 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); + 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()); + 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); } - return proceed; + // 路径地址 + sendData.put("url", servletPath); + // 有存自己表里的图片 把自己图片服务器的前缀传过去 + if (annotation.hasAnnex()) { + sendData.put("BASEIMGPATH", baseimgpath); + // 自己表里的图片集合 + sendData.put("sendPicturesList", proceed.get("sendPicturesList")); + proceed.remove("sendPicturesList"); + } + + // 有dockData + TenCorpDto tenCorpDto = new TenCorpDto(); + tenCorpDto.setMessage("秦港企业端数据同步消息"); + tenCorpDto.setData(sendData); + tenCorpDto.setId(UuidUtil.get32UUID()); + tenCorpDto.setProducer_name("qa-prevention-gwj"); + tenCorpDto.setMessageLogId(UuidUtil.get32UUID()); + tenCorpDto.setMark(servletPath); + tenCorpDto.setCREATE_TIME(DateUtil.date2Str(new Date())); + // 有dockData + if (Tools.notEmpty(proceed.get("dockData"))) { + String dockData = proceed.get("dockData"); + PageData dockDataMap = JSON.parseObject(dockData, PageData.class); + sendData.put("dockData",dockData); + // 操作企业 + if ("f8da1790b1034058ae2efefd69af3284".contains(dockDataMap.getString("operatingCorpId")) + || "016d19225e9d4ece863cce8a256a3e72".contains(dockDataMap.getString("operatingCorpId")) + || "1".equals(dockDataMap.getString("sendAllCorp")) + ){ + tenCorpDto.setTopic(czksDataDocking); + sendMessageService.sendMessage(tenCorpDto); + } + // todo先不给其他两家发送消息,上线前打开 +// if ("8854edee3aa94be496cee676b6d4845a".contains(dockDataMap.getString("operatingCorpId")) || "1".equals(dockDataMap.getString("sendAllCorp"))){ +// tenCorpDto.setTopic(csyDataDocking); +// sendMessageService.sendMessage(tenCorpDto); +// } +// if ("6aa255d41602497fa0f934a822820df4".contains(dockDataMap.getString("operatingCorpId")) || "1".equals(dockDataMap.getString("sendAllCorp"))){ +// tenCorpDto.setTopic(cmtDataDocking); +// sendMessageService.sendMessage(tenCorpDto); +// } + proceed.remove("dockData"); + } else { + System.out.println("------------------------无dockData不发消息------------------------"); + } + + System.out.println("------------------------切面方法结束------------------------"); } @PostConstruct private void initDockingRelationship() throws Exception { - dockingRelationMap = dockingRelationService.listAll(null); +// dockingRelationMap = dockingRelationService.listAll(new PageData()); } private PageData getPageData() { @@ -136,6 +149,7 @@ public class DockingAspect { /** * 得到request对象 + * * @return */ private HttpServletRequest getRequest() { diff --git a/src/main/java/com/zcloud/controller/inspection/SafetyEnvironmentalInspectorController.java b/src/main/java/com/zcloud/controller/inspection/SafetyEnvironmentalInspectorController.java index c7bc8356..3502a5cf 100644 --- a/src/main/java/com/zcloud/controller/inspection/SafetyEnvironmentalInspectorController.java +++ b/src/main/java/com/zcloud/controller/inspection/SafetyEnvironmentalInspectorController.java @@ -1,5 +1,7 @@ package com.zcloud.controller.inspection; +import com.alibaba.fastjson.JSON; +import com.zcloud.aspect.DockAnnotation; import com.zcloud.controller.base.BaseController; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; @@ -82,11 +84,13 @@ public class SafetyEnvironmentalInspectorController extends BaseController { @RequestMapping(value="/verify") @RequiresPermissions("safetyenvironmentalinspector:add") @ResponseBody + @DockAnnotation(hasAnnex = true) public Object verify() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); + ArrayList strings = new ArrayList<>(); PageData uBean= safetyenvironmentalinspectorService.findById(pd); uBean.put("INSPECTION_USER_OPINION", pd.getString("INSPECTION_USER_OPINION")); uBean.put("INSPECTION_USER_SIGN_TIME", DateUtil.date2Str(new Date())); @@ -107,10 +111,15 @@ public class SafetyEnvironmentalInspectorController extends BaseController { String ffile = DateUtil.getDays(); String fileName = this.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); Smb.sshSftp(file, fileName, Const.FILEPATHFILE + pd.getString("CORPINFO_ID") + "/" + ffile); - uBean.put("INSPECTION_USER_SIGN_IMG", Const.FILEPATHFILE + pd.getString("CORPINFO_ID") + "/" + ffile + "/" + fileName); + strings.add(uBean.getString("INSPECTION_USER_SIGN_IMG")+"@@"+fileName); } safetyenvironmentalinspectorService.verify(uBean); + if (uBean.get("CORPINFO_ID")!=null){ + uBean.put("operatingCorpId",uBean.get("CORPINFO_ID")); + } + map.put("sendPicturesList", JSON.toJSONString(strings)); + map.put("dockData", JSON.toJSONString(uBean)); map.put("pd", pd); map.put("result", errInfo); return map; diff --git a/src/main/java/com/zcloud/dto/TenCorpDto.java b/src/main/java/com/zcloud/dto/TenCorpDto.java index 011721d9..2e7b3063 100644 --- a/src/main/java/com/zcloud/dto/TenCorpDto.java +++ b/src/main/java/com/zcloud/dto/TenCorpDto.java @@ -2,6 +2,7 @@ package com.zcloud.dto; import com.alibaba.fastjson.JSON; import com.zcloud.entity.PageData; +import com.zcloud.util.Warden; import lombok.Data; @Data @@ -9,7 +10,7 @@ public class TenCorpDto { // 请秋id private String id; // 消息来源名称 - private String producer_name = "qa-prevention-cfd"; + private String producer_name = "qa-prevention-gwj"; private String topic; //印记(方便寻找该条请求) private String mark; @@ -23,6 +24,10 @@ public class TenCorpDto { // 消息体 private PageData data; + private String messageLogId; + + private String CREATE_TIME; + public TenCorpDto() { this.id = Warden.get32UUID(); } @@ -40,6 +45,9 @@ public class TenCorpDto { info.put("MARK_NAME", this.mark_name); info.put("MESSAGE", this.message); info.put("TOPIC",this.topic); + info.put("DATA", JSON.toJSONString(this.data)); + info.put("CREATE_TIME", this.CREATE_TIME); + info.put("MESSAGE_LOG_ID", this.messageLogId); return info; } } diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index c428aa8a..79503c7f 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -71,7 +71,7 @@ smb.basePath=/mnt/qgfile/file/ rocketmq.consumer.group2=edu-admin-edit rocketmq.consumer.group1=edu-admin-add #rocketmq.name-server=10.0.140.141:9876 -rocketmq.name-server=192.168.0.31:9876 +rocketmq.name-server=192.168.151.22:9876 #rocketmq.name-server=172.24.151.16:9876 rocketmq.producer.group=libmiddle rocketmq.producer.send-message-timeout=3000 @@ -103,3 +103,22 @@ gwj-baseimgpath=https://qgqy.qhdsafety.com/file/ gwj-backendaddr=http://192.168.0.31:8991/qa-prevention-gwj/ # ?????? http.file.url=https://qgqy.qhdsafety.com/file/ +perLoc.url=http://192.168.210.32:8084 +perLoc.userName=qaaqadmin +perLoc.pwd=Cfd2023@ +baseimgpath =http://192.168.192.201:8991/file/ + +mq.csy.data.topic=csy_docking +mq.csy.data.group=scheduled_tasks_csy_docking +mq.csy.file.topic=csy_dockingPicture +mq.csy.file.group=scheduled_tasks_csy_dockingPicture + +mq.cmt.data.topic=cmt_docking +mq.cmt.data.group=scheduled_tasks_cmt_docking +mq.cmt.file.topic=cmt_dockingPicture +mq.cmt.file.group=scheduled_tasks_cmt_dockingPicture + +mq.czks.data.topic=czks_docking +mq.czks.data.group=scheduled_tasks_czks_docking +mq.czks.file.topic=czks_dockingPicture +mq.czks.file.group=scheduled_tasks_czks_dockingPicture diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index f34dccb4..eea27b5d 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -104,3 +104,19 @@ czks-backendaddr=http://192.168.0.79:8091/ gwj-useridentity=GWJ gwj-baseimgpath=https://qgqy.qhdsafety.com/file/ gwj-backendaddr=http://192.168.0.31:8991/qa-prevention-gwj/ +baseimgpath =http://192.168.192.201:8991/file/ + +mq.csy.data.topic=csy_docking +mq.csy.data.group=scheduled_tasks_csy_docking +mq.csy.file.topic=csy_dockingPicture +mq.csy.file.group=scheduled_tasks_csy_dockingPicture + +mq.cmt.data.topic=cmt_docking +mq.cmt.data.group=scheduled_tasks_cmt_docking +mq.cmt.file.topic=cmt_dockingPicture +mq.cmt.file.group=scheduled_tasks_cmt_dockingPicture + +mq.czks.data.topic=czks_docking +mq.czks.data.group=scheduled_tasks_czks_docking +mq.czks.file.topic=czks_dockingPicture +mq.czks.file.group=scheduled_tasks_czks_dockingPicture diff --git a/src/main/resources/application-master.properties b/src/main/resources/application-master.properties index 40b507c2..1ac69891 100644 --- a/src/main/resources/application-master.properties +++ b/src/main/resources/application-master.properties @@ -89,3 +89,19 @@ corp.default.pic-path=https://qgqy.qhdsafety.com/file/ corp.default.back-end-path=https://skqhdg.porthebei.com:9004/file/ # ?????? http.file.url=http://192.168.192.201:8991/file/ +baseimgpath =http://192.168.192.201:8991/file/ + +mq.csy.data.topic=csy_docking +mq.csy.data.group=scheduled_tasks_csy_docking +mq.csy.file.topic=csy_dockingPicture +mq.csy.file.group=scheduled_tasks_csy_dockingPicture + +mq.cmt.data.topic=cmt_docking +mq.cmt.data.group=scheduled_tasks_cmt_docking +mq.cmt.file.topic=cmt_dockingPicture +mq.cmt.file.group=scheduled_tasks_cmt_dockingPicture + +mq.czks.data.topic=czks_docking +mq.czks.data.group=scheduled_tasks_czks_docking +mq.czks.file.topic=czks_dockingPicture +mq.czks.file.group=scheduled_tasks_czks_dockingPicture