数据同步aop改造

pull/14/head
dearlin 2023-12-20 11:08:33 +08:00
parent 9843400cb3
commit f0cfa0e9cc
7 changed files with 177 additions and 92 deletions

View File

@ -34,98 +34,163 @@ public class DockingAspect {
private DockingRelationService dockingRelationService;
@Pointcut("@annotation(com.zcloud.aspect.DockAnnotation)")
public void pointcut() {}
public void pointcut() {
}
public static Map<String, String> dockingRelationMap = new HashMap();
// 增强逻辑:在切点方法执行前打印日志
@Around("pointcut()")
public Object beforeApi(ProceedingJoinPoint joinPoint) throws Throwable {
Map<String,String> proceed = (HashMap<String,String>)joinPoint.proceed();
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;
}
//
//
// 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<String, String> dockData = (Map<String, String>) 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();
// 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());
// }
// 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;
}
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());
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<String,String> dockData = (Map<String,String>) 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();
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());
}
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());
login_user.put("ISSUPERVISE", Jurisdiction.getISSUPERVISE());
login_user.put("POST_ID", Jurisdiction.getPOST_ID());
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", "czks-baseimgpath");
// 自己表里的图片集合
sendData.put("sendPicturesList", proceed.get("sendPicturesList"));
proceed.remove("sendPicturesList");
}
// 有dockData
if (Tools.notEmpty(proceed.get("dockData"))) {
sendData.put("dockData", proceed.get("dockData"));
proceed.remove("dockData");
} else {
sendData.put("dockData", "手动添加的dockData");
}
TenCorpDto tenCorpDto = new TenCorpDto();
tenCorpDto.setMessage("沧州矿石数据同步消息");
tenCorpDto.setData(sendData);
tenCorpDto.setId(UuidUtil.get32UUID());
tenCorpDto.setTopic("docking");
tenCorpDto.setProducer_name("qa-prevention-czks");
sendMessageService.sendMessage(tenCorpDto);
}
@PostConstruct
@ -139,6 +204,7 @@ public class DockingAspect {
/**
* request
*
* @return
*/
private HttpServletRequest getRequest() {

View File

@ -155,7 +155,7 @@ public class CorpRoleController extends BaseController {
*/
@RequestMapping(value="/delete")
@ResponseBody
@DockAnnotation
@DockAnnotation(isAdd = true)
public Object deleteRole(@RequestParam String ROLE_ID)throws Exception{
Map<String,String> map = new HashMap<String,String>();
PageData pd = new PageData();
@ -177,7 +177,7 @@ public class CorpRoleController extends BaseController {
errInfo = "success";
FHLOG.save(Jurisdiction.getUsername(), "删除角色ID为:"+ROLE_ID); //记录日志
}
map.put("dockData", JSON.toJSONString(pd));
map.put("dockData", JSON.toJSONString(this.getPageData()));
}
map.put("result", errInfo);
return map;

View File

@ -82,6 +82,7 @@ public class OutSourcedController extends BaseController {
//pd.put("INVOLVING_CORPS", Jurisdiction.getCORPINFO_ID()); //理单位名称
pd.put("IS_CORP_TYPE", "1"); //是否企业重点工程0监管重点工程;1企业重点工程
ArrayList<String> strings = new ArrayList<>();
if (null != file && !file.isEmpty()) {
String suffixName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase();
@ -95,6 +96,7 @@ public class OutSourcedController extends BaseController {
String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
Smb.sshSftp(file, fileName, Const.FILEPATHFILE + ffile);
pd.put("UNITS_APTITUDE", Const.FILEPATHFILE + ffile + "/" + fileName);
strings.add(Const.FILEPATHFILE + ffile + "/" + fileName);
}
if (null != file1 && !file1.isEmpty()) {
String suffixName = file1.getOriginalFilename().substring(file1.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase();
@ -217,14 +219,15 @@ public class OutSourcedController extends BaseController {
String ffile = DateUtil.getDays();
String fileName = this.get32UUID() + file9One.getOriginalFilename().
substring(file9One.getOriginalFilename().lastIndexOf("."));
Smb.sshSftp(file9One, fileName, Const.FILEPATHYHTP + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
PageData pdImg = new PageData();
String fileUpdateName = file9One.getOriginalFilename();
pdImg.put("IMGFILES_ID", this.get32UUID());
String IMGFILES_ID = this.get32UUID();
pdImg.put("IMGFILES_ID", IMGFILES_ID);
pdImg.put("FILE_NAME", fileUpdateName);
pdImg.put("FILEPATH", Const.FILEPATHYHTP + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
pdImg.put("TYPE", "300");
pdImg.put("FOREIGN_KEY", pd.getString("OUTSOURCED_ID"));
Smb.sshSftp(file9One, fileName, Const.FILEPATHYHTP + Jurisdiction.getCORPINFO_ID() + "/" + ffile,IMGFILES_ID, pd.getString("OUTSOURCED_ID"),"300");
imgfilesService.save(pdImg);
}
}
@ -237,6 +240,7 @@ public class OutSourcedController extends BaseController {
pd.put("INVOLVING_CORPS", Jurisdiction.getCORPINFO_ID());
outsourcedService.save(pd);
map.put("result", errInfo);
map.put("sendPicturesList", strings);
return map;
}

View File

@ -5,7 +5,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.zcloud.aspect.DockAnnotation;
import com.zcloud.entity.system.DepartmentMenu;
import com.zcloud.util.ReturnMap;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@ -153,6 +156,7 @@ public class DictionariesController extends BaseController {
*/
@RequestMapping(value="/add")
@ResponseBody
@DockAnnotation(isAdd = true)
public Object add() throws Exception{
Map<String,String> map = new HashMap<String,String>();
String errInfo = "success";
@ -160,6 +164,7 @@ public class DictionariesController extends BaseController {
pd = this.getPageData();
pd.put("DICTIONARIES_ID", this.get32UUID()); //主键
dictionariesService.save(pd);
map.put("dockData", JSON.toJSONString(pd));
map.put("result", errInfo);
return map;
}
@ -226,13 +231,14 @@ public class DictionariesController extends BaseController {
*/
@RequestMapping(value="/edit")
@ResponseBody
@DockAnnotation(isAdd = true)
public Object edit() throws Exception{
Map<String,Object> map = new HashMap<String,Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
PageData pd = this.getPageData();
dictionariesService.edit(pd);
map.put("result", errInfo); //返回结果
map.put("dockData", JSON.toJSONString(pd));
return map;
}
@ -244,6 +250,7 @@ public class DictionariesController extends BaseController {
*/
@RequestMapping(value="/delete")
@ResponseBody
@DockAnnotation(isAdd = true)
public Object delete(@RequestParam String DICTIONARIES_ID) throws Exception{
Map<String,String> map = new HashMap<String,String>();
PageData pd = new PageData();
@ -253,7 +260,8 @@ public class DictionariesController extends BaseController {
errInfo = "fail";
}else{
pd = dictionariesService.findById(pd); //根据ID读取
if("yes".equals(pd.getString("YNDEL")))return null; //当禁止删除字段值为yes, 则禁止删除,只能从手动从数据库删除
if("yes".equals(pd.getString("YNDEL"))) return null;
//当禁止删除字段值为yes, 则禁止删除,只能从手动从数据库删除
if(null != pd.get("TBSNAME") && !"".equals(pd.getString("TBSNAME"))){
String TBFIELD = pd.getString("TBFIELD");
if(Tools.isEmpty(TBFIELD))TBFIELD = "BIANMA"; //如果关联字段没有设置,就默认字段为 BIANMA
@ -275,6 +283,7 @@ public class DictionariesController extends BaseController {
}
if("success".equals(errInfo)){
dictionariesService.delete(pd); //执行删除
map.put("dockData", JSON.toJSONString(this.getPageData()));
}
map.put("result", errInfo);
return map;

View File

@ -49,7 +49,8 @@ smb.port=22
smb.user=root
smb.password=Zcloud@zcloud88888
smb.basePath=/mnt/qgfile/file/
#????????????
baseimgpath = https://qgqy.qhdsafety.com/file/
#????????
czks-useridentity=CZKS
czks-baseimgpath=https://qgqy.qhdsafety.com/file/

View File

@ -62,6 +62,10 @@ spring.main.banner-mode=off
preventionxgf.api.url=http://192.168.0.79:8088/
qa-regulatory-gwj.api.url=http://192.168.0.79:8092/
#????????????
baseimgpath = https://qgqy.qhdsafety.com/
#?????
smb.host=39.103.224.166
smb.port=22

View File

@ -30,7 +30,8 @@ spring.datasource.testOnBorrow: false
spring.datasource.testOnReturn: false
#?????????filters????????sql?????,'wall'?????
filters: stat, wall, log4j
#????????????
baseimgpath = https://qgqy.qhdsafety.com/
#????????
spring.cache.ehcache.cofnig=ehcache.xml