From 3c607f075990d6d3238daa7db1c68eaae8126424 Mon Sep 17 00:00:00 2001
From: zhongrj <123456>
Date: Mon, 22 Aug 2022 15:05:47 +0800
Subject: [PATCH] 新增数据同步方式及配置,当选择为sql时则为数据库直连同步,全局替换所有的同步方法,用户修改,离职,注销修改调整,文件上传去除同步推送上传
---
src/main/java/org/springblade/modules/workreport/controller/WorkReportController.java | 136 ++++++++++++++++++++++++++++-----------------
1 files changed, 85 insertions(+), 51 deletions(-)
diff --git a/src/main/java/org/springblade/modules/workreport/controller/WorkReportController.java b/src/main/java/org/springblade/modules/workreport/controller/WorkReportController.java
index 528e0ca..40106f8 100644
--- a/src/main/java/org/springblade/modules/workreport/controller/WorkReportController.java
+++ b/src/main/java/org/springblade/modules/workreport/controller/WorkReportController.java
@@ -14,6 +14,7 @@
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IDeptService;
import org.springblade.modules.system.service.IUserService;
+import org.springblade.modules.system.service.MyAsyncService;
import org.springblade.modules.workreport.entity.WorkReport;
import org.springblade.modules.workreport.service.WorkReportService;
import org.springblade.modules.workreport.vo.WorkReportVo;
@@ -42,10 +43,12 @@
private final IUserService userService;
private final IDeptService deptService;
+ private final MyAsyncService myAsyncService;
/**
* 自定义分页
- * @param query page,size
+ *
+ * @param query page,size
* @param workReport 工作汇报信息对象
*/
@GetMapping("/page")
@@ -62,7 +65,8 @@
/**
* 自定义分页--接收到的汇报信息page
- * @param query page,size
+ *
+ * @param query page,size
* @param workReport 工作汇报信息对象
*/
@GetMapping("/pageReply")
@@ -73,6 +77,7 @@
/**
* 新增
+ *
* @param workReport 工作汇报信息对象
*/
@PostMapping("/save")
@@ -83,6 +88,7 @@
/**
* 修改
+ *
* @param workReport 工作汇报信息对象
*/
@PostMapping("/update")
@@ -92,76 +98,84 @@
/**
* 新增或修改
+ *
* @param workReport 工作汇报信息对象
*/
@PostMapping("/submit")
- public R submit(@RequestBody WorkReport workReport){
+ public R submit(@RequestBody WorkReport workReport) {
boolean status = false;
- if (null==workReport.getId()){
+ if (null == workReport.getId()) {
workReport.setReportTime(new Date());
workReport.setReplyDeptIds(getReplyDeptIds(workReport.getReceivedIds()));
//新增
status = workReportService.save(workReport);
-
- //数据同步
- String s1 =
- "insert into sys_work_report(id,type,content,work_desc,report_time,received_ids,dept_id,reply_dept_ids,category,user_id) " +
- "values(" + "'" + workReport.getId() + "'" + "," +
- "'" + workReport.getType() + "'" + "," +
- "'" + workReport.getContent() + "'" + "," +
- "'" + workReport.getWorkDesc() + "'" + "," +
- "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(workReport.getReportTime()) + "'" + "," +
- "'" + workReport.getReceivedIds() + "'" + "," +
- "'" + workReport.getDeptId() + "'" + "," +
- "'" + workReport.getReplyDeptIds() + "'" + "," +
- "'" + workReport.getCategory() + "'" + "," +
- "'" +workReport.getUserId() + "'" + ")";
- FtpUtil.sqlFileUpload(s1);
- }else {
+ if (status) {
+ //数据同步
+ String s1 =
+ "insert into sys_work_report(id,type,content,work_desc,report_time,received_ids,dept_id,reply_dept_ids,category,user_id) " +
+ "values(" + "'" + workReport.getId() + "'" + "," +
+ "'" + workReport.getType() + "'" + "," +
+ "'" + workReport.getContent() + "'" + "," +
+ "'" + workReport.getWorkDesc() + "'" + "," +
+ "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(workReport.getReportTime()) + "'" + "," +
+ "'" + workReport.getReceivedIds() + "'" + "," +
+ "'" + workReport.getDeptId() + "'" + "," +
+ "'" + workReport.getReplyDeptIds() + "'" + "," +
+ "'" + workReport.getCategory() + "'" + "," +
+ "'" + workReport.getUserId() + "'" + ")";
+ //FtpUtil.sqlFileUpload(s1);
+ myAsyncService.dataSync(s1);
+ }
+ } else {
workReport.setReplyDeptIds(getReplyDeptIds(workReport.getReceivedIds()));
- if (null==workReport.getReplyTime()){
+ if (null == workReport.getReplyTime()) {
workReport.setReplyTime(new Date());
}
//修改
status = workReportService.updateById(workReport);
-
- //内网同步
- String s1 =
- "update sys_work_report set type = " + "'" + workReport.getType() + "'" +
- ",content = " + "'" + workReport.getContent() + "'" +
- ",work_desc = " + "'" + workReport.getWorkDesc() + "'" +
- ",received_ids = " + "'" + workReport.getReceivedIds() + "'" +
- ",reply_content = " + "'" + workReport.getReplyContent() + "'" +
- ",reply_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(workReport.getReplyTime()) + "'" +
- ",dept_id = " + "'" + workReport.getDeptId() + "'" +
- ",reply_dept_ids = " + "'" + workReport.getReplyDeptIds() + "'" +
- ",category = " + "'" + workReport.getCategory() + "'" +
- ",user_id = " + "'" + workReport.getUserId() + "'" +
- " " +"where id = " + "'" + workReport.getId() + "'";
- FtpUtil.sqlFileUpload(s1);
+ if (status) {
+ //内网同步
+ String s1 =
+ "update sys_work_report set type = " + "'" + workReport.getType() + "'" +
+ ",content = " + "'" + workReport.getContent() + "'" +
+ ",work_desc = " + "'" + workReport.getWorkDesc() + "'" +
+ ",received_ids = " + "'" + workReport.getReceivedIds() + "'" +
+ ",reply_content = " + "'" + workReport.getReplyContent() + "'" +
+ ",reply_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(workReport.getReplyTime()) + "'" +
+ ",dept_id = " + "'" + workReport.getDeptId() + "'" +
+ ",reply_dept_ids = " + "'" + workReport.getReplyDeptIds() + "'" +
+ ",category = " + "'" + workReport.getCategory() + "'" +
+ ",user_id = " + "'" + workReport.getUserId() + "'" +
+ " " + "where id = " + "'" + workReport.getId() + "'";
+ //FtpUtil.sqlFileUpload(s1);
+ myAsyncService.dataSync(s1);
+ }
}
return R.status(status);
}
/**
* 删除
+ *
* @param ids 工作汇报信息ids 数组
*/
@PostMapping("/remove")
public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
//内网删除
List<Long> list = Func.toLongList(ids);
- list.forEach(id ->{
+ list.forEach(id -> {
//内网同步
String s1 = "delete from sys_work_report where id = " + "'" + id + "'";
- FtpUtil.sqlFileUpload(s1);
+ //FtpUtil.sqlFileUpload(s1);
+ myAsyncService.dataSync(s1);
});
return R.status(workReportService.removeByIds(Func.toLongList(ids)));
}
/**
* 详情
+ *
* @param workReport 工作汇报信息对象
*/
@GetMapping("/detail")
@@ -177,23 +191,35 @@
/**
* 获取接收人的单位信息
+ *
* @param detail 汇报详情
* @return
*/
private String getReplyDeptName(WorkReportVo detail) {
- List<String> replyDeptIds = Arrays.asList(detail.getReplyDeptIds().split(","));
- StringBuilder replyDeptNameInfo = new StringBuilder();
- for (String deptId : replyDeptIds) {
- //查询接收人单位信息
- Dept deptDetail = deptService.getById(Long.parseLong(deptId));
- replyDeptNameInfo = replyDeptNameInfo.append(deptDetail.getDeptName()).append(",");
+
+ if (null != detail.getReplyDeptIds() && detail.getReplyDeptIds() != "" && !detail.getReplyDeptIds().isEmpty()) {
+ List<String> replyDeptIds = Arrays.asList(detail.getReplyDeptIds().split(","));
+ StringBuilder replyDeptNameInfo = new StringBuilder();
+ if (replyDeptIds.size() > 0) {
+ for (String deptId : replyDeptIds) {
+ //查询接收人单位信息
+ Dept deptDetail = deptService.getById(Long.parseLong(deptId));
+ if (null != deptDetail) {
+ replyDeptNameInfo = replyDeptNameInfo.append(deptDetail.getDeptName()).append(",");
+ }
+ }
+ if (replyDeptNameInfo.length() > 0) {
+ //截取
+ return replyDeptNameInfo.substring(0, replyDeptNameInfo.length() - 1);
+ }
+ }
}
- //截取
- return replyDeptNameInfo.substring(0, replyDeptNameInfo.length() - 1);
+ return null;
}
/**
* 获取接收人的单位id(dept)信息
+ *
* @param
* @return
*/
@@ -203,12 +229,14 @@
for (String userId : userIds) {
//查询接收人单位信息
User userDetail = userService.getById(userId);
- list.add(userDetail.getDeptId());
+ if (null != userDetail) {
+ list.add(userDetail.getDeptId());
+ }
}
//去重
List<String> collect = list.stream().distinct().collect(Collectors.toList());
//截取
- return String.join(",",collect);
+ return String.join(",", collect);
}
/**
@@ -217,7 +245,7 @@
* @param detail 汇报详情
* @return
*/
- private String getReplyRealName(WorkReportVo detail){
+ private String getReplyRealName(WorkReportVo detail) {
List<String> userIds = Arrays.asList(detail.getReceivedIds().split(","));
StringBuilder replyRealNameInfo = new StringBuilder();
for (String userId : userIds) {
@@ -226,10 +254,16 @@
// user.setCardid(idCardNo);
// User userDetail = userService.getOne(Condition.getQueryWrapper(user));
User userDetail = userService.getById(userId);
- replyRealNameInfo = replyRealNameInfo.append(userDetail.getRealName()).append(",");
+ if (null != userDetail) {
+ replyRealNameInfo = replyRealNameInfo.append(userDetail.getRealName()).append(",");
+ }
+
}
//截取
- return replyRealNameInfo.substring(0, replyRealNameInfo.length() - 1);
+ if (replyRealNameInfo.toString().length() > 0) {
+ return replyRealNameInfo.substring(0, replyRealNameInfo.length() - 1);
+ }
+ return null;
}
}
--
Gitblit v1.9.3