笔记模块拆分,mq切换为rocketmq

This commit is contained in:
weizhiqiang 2022-08-01 15:30:19 +08:00
parent f75894d742
commit 2d06f4da85
30 changed files with 54 additions and 1743 deletions

View file

@ -27,7 +27,6 @@
<module>skyeye-knowlg</module>
<module>skyeye-forum</module>
<module>skyeye-disk-cloud</module>
<module>skyeye-note</module>
<module>skyeye-light-app</module>
<module>skyeye-code-doc</module>
<module>skyeye-jobdiary</module>

View file

@ -1,128 +0,0 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.common.constans;
/**
* @ClassName: MqConstants
* @Description: MQ消息队列常量类
* @author: skyeye云系列--卫志强
* @date: 2021/7/4 21:56
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
public class MqConstants {
/**
* 等待处理
*/
public static final String JOB_TYPE_IS_WAIT = "1";
/**
* 处理中
*/
public static final String JOB_TYPE_IS_PROCESSING = "2";
/**
* 执行失败
*/
public static final String JOB_TYPE_IS_FAIL = "3";
/**
* 执行成功
*/
public static final String JOB_TYPE_IS_SUCCESS = "4";
/**
* 部分成功
*/
public static final String JOB_TYPE_IS_PARTIAL_SUCCESS = "5";
public static enum JobMateMationJobType {
ORDINARY_MAIL_DELIVERY(2, 1, false, "邮件通知", "ordinaryMailDeliveryService"),
MAIL_ACCESS_INBOX(3, 2, true, "收件箱邮件获取", "mailAccessInboxService"),
MAIL_ACCESS_SENDED(3, 3, true, "已发送邮件获取", "mailAccessSendedService"),
MAIL_ACCESS_DELETE(3, 4, true, "已删除邮件获取", "mailAccessDeleteService"),
MAIL_ACCESS_DRAFTS(3, 5, true, "草稿箱邮件获取", "mailAccessDraftsService"),
COMPLEX_MAIL_DELIVERY(2, 6, false, "邮件发送", "complexMailDeliveryService"),
MAIL_DRAFTS_SAVE(2, 7, false, "保存草稿同步", "mailDraftsSaveService"),
MAIL_DRAFTS_EDIT(2, 8, false, "草稿编辑同步", "mailDraftsEditService"),
MAIL_DRAFTS_SEND(2, 9, false, "草稿箱邮件发送", "mailDraftsSendService"),
NOTICE_SEND(2, 10, false, "消息通知", "noticeSendService"),
WATI_WORKER_SEND(2, 11, false, "派工通知", "watiWorkerSendService"),
OUTPUT_NOTES_IS_ZIP(1, 100, true, "笔记输出压缩包", "outputNotesIsZipService");
// 所属大类 1.我的输出 2.我的发送 3.我的获取
private int bigType;
private int jobType;
private boolean sendMsgToPage;
private String typeName;
private String serviceName;
JobMateMationJobType(int bigType, int jobType, boolean sendMsgToPage, String typeName, String serviceName) {
this.bigType = bigType;
this.jobType = jobType;
this.sendMsgToPage = sendMsgToPage;
this.typeName = typeName;
this.serviceName = serviceName;
}
public static String getTypeNameByJobType(String jobType) {
for (JobMateMationJobType bean : JobMateMationJobType.values()) {
if (bean.getJobType() == Integer.parseInt(jobType)) {
return bean.getTypeName();
}
}
return "";
}
public static String getServiceNameByJobType(String jobType) {
for (JobMateMationJobType bean : JobMateMationJobType.values()) {
if (bean.getJobType() == Integer.parseInt(jobType)) {
return bean.getServiceName();
}
}
return "";
}
public static int getBigTypeByJobType(String jobType) {
for (JobMateMationJobType bean : JobMateMationJobType.values()) {
if (bean.getJobType() == Integer.parseInt(jobType)) {
return bean.getBigType();
}
}
return 0;
}
public static boolean getSendMsgToPageByJobType(String jobType) {
for (JobMateMationJobType bean : JobMateMationJobType.values()) {
if (bean.getJobType() == Integer.parseInt(jobType)) {
return bean.isSendMsgToPage();
}
}
return false;
}
public int getBigType() {
return bigType;
}
public int getJobType() {
return jobType;
}
public String getTypeName() {
return typeName;
}
public String getServiceName() {
return serviceName;
}
public boolean isSendMsgToPage() {
return sendMsgToPage;
}
}
}

View file

@ -1,56 +0,0 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.common.constans;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @ClassName: NoteConstants
* @Description: 笔记系统相关的常量类
* @author: skyeye云系列--卫志强
* @date: 2021/6/14 11:55
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
public class NoteConstants {
// 笔记管理---目录logo图片
public static final String SYS_FILE_CONSOLE_IS_FOLDER_LOGO_PATH = "../../assets/images/folder-show.png";
// 笔记文件夹目录集合
public static final String SYS_FILE_MYNOTE_LIST_MATION = "sys_file_mynote_list_mation_";
public static String getSysFileMyNoteListMation(String folderId, String userId) {
return SYS_FILE_MYNOTE_LIST_MATION + folderId + "_" + userId;
}
/**
* 获取我的笔记默认的文件夹
*
* @return
*/
public static final List<Map<String, Object>> getFileMyNoteDefaultFolder() {
List<Map<String, Object>> beans = new ArrayList<>();
Map<String, Object> newnotes = new HashMap<>();
newnotes.put("id", "1");
newnotes.put("name", "最新笔记");
newnotes.put("pId", "0");
newnotes.put("isParent", 0);// 是否是文件夹 0否1是
newnotes.put("icon", "../../assets/images/note-folder.png");// 图标
beans.add(newnotes);
Map<String, Object> myfiles = new HashMap<>();
myfiles.put("id", "2");
myfiles.put("name", "我的文件夹");
myfiles.put("pId", "0");
myfiles.put("isParent", 1);// 是否是文件夹 0否1是
myfiles.put("icon", "../../assets/images/my-folder-icon.png");// 图标
beans.add(myfiles);
return beans;
}
}

View file

@ -22,20 +22,6 @@
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- mq消息通知 -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
</dependency>
</dependencies>
</project>

View file

@ -11,6 +11,8 @@ import com.skyeye.annotation.api.ApiOperation;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
import com.skyeye.eve.entity.mq.JobMateQueryDO;
import com.skyeye.eve.rest.mq.JobMateMation;
import com.skyeye.eve.rest.mq.JobMateUpdateMation;
import com.skyeye.service.JobMateMationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
@ -43,13 +45,23 @@ public class JobMateMationController {
* @param outputObject 出参以及提示信息的返回值对象
*/
@ApiOperation(id = "sendMQProducer", value = "其他模块同步生产消息", method = "POST", allUse = "2")
@ApiImplicitParams({
@ApiImplicitParam(id = "jsonStr", name = "jsonStr", value = "消费者消费的json字符串", required = "required"),
@ApiImplicitParam(id = "userId", name = "userId", value = "用户id", required = "required")})
@ApiImplicitParams(classBean = JobMateMation.class)
@RequestMapping("/post/JobMateMationController/sendMQProducer")
public void sendMQProducer(InputObject inputObject, OutputObject outputObject) {
jobMateMationService.sendMQProducer(inputObject, outputObject);
}
/**
* 修改任务信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@ApiOperation(id = "comMQJobMation", value = "修改任务信息", method = "POST", allUse = "0")
@ApiImplicitParams(classBean = JobMateUpdateMation.class)
@RequestMapping("/post/JobMateMationController/comMQJobMation")
public void comMQJobMation(InputObject inputObject, OutputObject outputObject) {
jobMateMationService.comMQJobMation(inputObject, outputObject);
}
}

View file

@ -1,30 +0,0 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.mq.config;
import javax.jms.Queue;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author 卫志强
* @ClassName: QueueConfig
* @Description: 创建一个队列
* @date 2019年3月3日
*/
@Configuration
public class QueueConfig {
@Value("${queue}")
// 值就是skyeye
private String queueName;
@Bean
public Queue queue() {// 消息队列的名字就是skyeye
return new ActiveMQQueue(queueName);
}
}

View file

@ -1,44 +0,0 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.mq.consumer;
import cn.hutool.json.JSONUtil;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.common.util.SpringUtils;
import com.skyeye.exception.CustomException;
import com.skyeye.mq.job.JobMateService;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author 卫志强
* @ClassName: Consumer
* @Description: 消费者
* @date 2019年3月3日
*/
@Component
public class Consumer {
/**
* activeMq监听监听接收消息队列
*
* @param data 从消息队列获得到的参数
*/
@JmsListener(destination = "${queue}")
public void receive(String data) {
Map<String, Object> map = JSONUtil.toBean(data, null);
String type = map.get("type").toString();
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
throw new CustomException(ex);
}
JobMateService jobMateService = SpringUtils.getBean(MqConstants.JobMateMationJobType.getServiceNameByJobType(type));
jobMateService.call(data);
}
}

View file

@ -4,11 +4,11 @@
package com.skyeye.mq.job.impl;
import cn.hutool.json.JSONUtil;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.common.util.MailUtil;
import com.skyeye.common.util.ToolUtil;
import com.skyeye.dao.MQUserEmailDao;
import com.skyeye.eve.service.SystemFoundationSettingsService;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.mq.job.JobMateService;
import com.skyeye.service.JobMateMationService;
import org.slf4j.Logger;

View file

@ -4,11 +4,11 @@
package com.skyeye.mq.job.impl;
import cn.hutool.json.JSONUtil;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.common.util.MailUtil;
import com.skyeye.common.util.ToolUtil;
import com.skyeye.dao.MQUserEmailDao;
import com.skyeye.eve.service.SystemFoundationSettingsService;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.mq.job.JobMateService;
import com.skyeye.service.JobMateMationService;
import org.slf4j.Logger;

View file

@ -4,11 +4,11 @@
package com.skyeye.mq.job.impl;
import cn.hutool.json.JSONUtil;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.common.util.MailUtil;
import com.skyeye.common.util.ToolUtil;
import com.skyeye.dao.MQUserEmailDao;
import com.skyeye.eve.service.SystemFoundationSettingsService;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.mq.job.JobMateService;
import com.skyeye.service.JobMateMationService;
import org.slf4j.Logger;

View file

@ -4,8 +4,8 @@
package com.skyeye.mq.job.impl;
import cn.hutool.json.JSONUtil;
import com.skyeye.common.util.MailUtil;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.common.util.MailUtil;
import com.skyeye.mq.job.JobMateService;
import com.skyeye.service.JobMateMationService;
import org.slf4j.Logger;

View file

@ -4,8 +4,8 @@
package com.skyeye.mq.job.impl;
import cn.hutool.json.JSONUtil;
import com.skyeye.common.util.MailUtil;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.common.util.MailUtil;
import com.skyeye.mq.job.JobMateService;
import com.skyeye.service.JobMateMationService;
import org.slf4j.Logger;

View file

@ -8,7 +8,6 @@ import cn.hutool.json.JSONUtil;
import com.skyeye.common.constans.Constants;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.common.util.DataCommonUtil;
import com.skyeye.common.util.DateUtil;
import com.skyeye.common.util.MailUtil;
import com.skyeye.common.util.ToolUtil;
import com.skyeye.dao.MQUserEmailDao;

View file

@ -13,6 +13,8 @@ public interface JobMateMationService {
void sendMQProducer(String jsonStr, String userId);
void comMQJobMation(InputObject inputObject, OutputObject outputObject);
void comMQJobMation(String jobId, String status, String responseBody);
void sendMQProducer(InputObject inputObject, OutputObject outputObject);

View file

@ -14,18 +14,21 @@ import com.skyeye.common.object.OutputObject;
import com.skyeye.common.util.DateUtil;
import com.skyeye.dao.JobMateMationDao;
import com.skyeye.eve.entity.mq.JobMateQueryDO;
import com.skyeye.eve.rest.mq.JobMateMation;
import com.skyeye.eve.rest.mq.JobMateUpdateMation;
import com.skyeye.exception.CustomException;
import com.skyeye.service.JobMateMationService;
import com.skyeye.websocket.TalkWebSocket;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.jms.Queue;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
@ -49,13 +52,13 @@ public class JobMateMationServiceImpl implements JobMateMationService {
private JobMateMationDao jobMateMationDao;
@Autowired
private JmsMessagingTemplate jmsMessagingTemplate;
private RocketMQTemplate rocketMQTemplate;
@Autowired
private TalkWebSocket talkWebSocket;
@Autowired
private Queue queue;
@Value("${spring.profiles.active}")
private String tag;
/**
* 根据大类获取任务信息
@ -82,10 +85,8 @@ public class JobMateMationServiceImpl implements JobMateMationService {
*/
@Override
public void sendMQProducer(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
String jsonStr = map.get("jsonStr").toString();
String userId = map.get("userId").toString();
this.sendMQProducer(jsonStr, userId);
JobMateMation jobMateMation = inputObject.getParams(JobMateMation.class);
this.sendMQProducer(jobMateMation.getJsonStr(), jobMateMation.getUserId());
}
/**
@ -109,8 +110,13 @@ public class JobMateMationServiceImpl implements JobMateMationService {
map.put("jobMateId", parentJob.get("jobId"));
parentJob.put("requestBody", JSONUtil.toJsonStr(map));
jobMateMationDao.editJobRequestBodyMation(parentJob);
String jobType = parentJob.get("jobType").toString();
// 发起消息
jmsMessagingTemplate.convertAndSend(queue, parentJob.get("requestBody").toString());
String topic = MqConstants.JobMateMationJobType.getTopicByJobType(jobType);
// 同步发送
SendResult sendResult = rocketMQTemplate.syncSend(topic + ":" + tag,
MessageBuilder.withPayload(parentJob.get("requestBody").toString()).build());
LOGGER.info("mq send topic is [{}], send result: [{}]", topic, sendResult);
}
/**
@ -141,6 +147,19 @@ public class JobMateMationServiceImpl implements JobMateMationService {
return job;
}
/**
* 修改任务信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
public void comMQJobMation(InputObject inputObject, OutputObject outputObject) {
JobMateUpdateMation jobMateUpdateMation = inputObject.getParams(JobMateUpdateMation.class);
LOGGER.info("update job [{}], status is {}", jobMateUpdateMation.getJobId(), jobMateUpdateMation.getStatus());
this.comMQJobMation(jobMateUpdateMation.getJobId(), jobMateUpdateMation.getStatus(), jobMateUpdateMation.getResponseBody());
}
/**
* 任务状态修改
*

View file

@ -63,7 +63,7 @@
a.type,
a.request_body requestBody,
a.response_body responseBody,
a.parent_id parentId
a.parent_id parentId,
a.`status`
FROM
job_mate_mation a
@ -80,7 +80,7 @@
a.type,
a.request_body requestBody,
a.response_body responseBody,
a.parent_id parentId
a.parent_id parentId,
a.`status`
FROM
job_mate_mation a

View file

@ -1 +0,0 @@
/target/

View file

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>skyeye-note</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -1,32 +0,0 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.skyeye</groupId>
<artifactId>skyeye-promote</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>skyeye-note</artifactId>
<name>skyeye-note</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 引入任务的依赖 -->
<dependency>
<groupId>com.skyeye</groupId>
<artifactId>skyeye-mq</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View file

@ -1,177 +0,0 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.eve.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
import com.skyeye.eve.service.MyNoteService;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyNoteController {
@Autowired
private MyNoteService myNoteService;
/**
* 根据当前用户获取笔记文件夹
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/queryFileMyNoteByUserId")
public void queryFileMyNoteByUserId(InputObject inputObject, OutputObject outputObject) {
myNoteService.queryFileMyNoteByUserId(inputObject, outputObject);
}
/**
* 添加文件夹
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/insertFileMyNoteByUserId")
public void insertFileMyNoteByUserId(InputObject inputObject, OutputObject outputObject) {
myNoteService.insertFileMyNoteByUserId(inputObject, outputObject);
}
/**
* 删除文件夹以及文件夹下的所有文件
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/deleteFileFolderById")
public void deleteFileFolderById(InputObject inputObject, OutputObject outputObject) {
myNoteService.deleteFileFolderById(inputObject, outputObject);
}
/**
* 编辑文件夹名称
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/editFileFolderById")
public void editFileFolderById(InputObject inputObject, OutputObject outputObject) {
myNoteService.editFileFolderById(inputObject, outputObject);
}
/**
* 根据当前用户获取最新的笔记列表
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/queryMyNoteListNewByUserId")
public void queryMyNoteListNewByUserId(InputObject inputObject, OutputObject outputObject) {
myNoteService.queryMyNoteListNewByUserId(inputObject, outputObject);
}
/**
* 添加笔记
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/insertMyNoteContentByUserId")
public void insertMyNoteContentByUserId(InputObject inputObject, OutputObject outputObject) {
myNoteService.insertMyNoteContentByUserId(inputObject, outputObject);
}
/**
* 根据文件夹id获取文件夹下的文件夹和笔记列表
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/queryFileAndContentListByFolderId")
public void queryFileAndContentListByFolderId(InputObject inputObject, OutputObject outputObject) {
myNoteService.queryFileAndContentListByFolderId(inputObject, outputObject);
}
/**
* 编辑笔记时回显信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/queryMyNoteContentMationById")
public void queryMyNoteContentMationById(InputObject inputObject, OutputObject outputObject) {
myNoteService.queryMyNoteContentMationById(inputObject, outputObject);
}
/**
* 编辑笔记信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/editMyNoteContentById")
public void editMyNoteContentById(InputObject inputObject, OutputObject outputObject) {
myNoteService.editMyNoteContentById(inputObject, outputObject);
}
/**
* 保存文件夹拖拽后的信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/editFileToDragById")
public void editFileToDragById(InputObject inputObject, OutputObject outputObject) {
myNoteService.editFileToDragById(inputObject, outputObject);
}
/**
* 保存笔记移动后的信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/editNoteToMoveById")
public void editNoteToMoveById(InputObject inputObject, OutputObject outputObject) {
myNoteService.editNoteToMoveById(inputObject, outputObject);
}
/**
* 获取文件夹或笔记移动时的选择树
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/queryTreeToMoveByUserId")
public void queryTreeToMoveByUserId(InputObject inputObject, OutputObject outputObject) {
myNoteService.queryTreeToMoveByUserId(inputObject, outputObject);
}
/**
* 根据id获取分享笔记的内容
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/queryShareNoteById")
public void queryShareNoteById(InputObject inputObject, OutputObject outputObject) {
myNoteService.queryShareNoteById(inputObject, outputObject);
}
/**
* 根据id(文件夹或者笔记id)将笔记输出为压缩包
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@RequestMapping("/post/MyNoteController/outputNoteIsZipJob")
public void outputNoteIsZipJob(InputObject inputObject, OutputObject outputObject) {
myNoteService.outputNoteIsZipJob(inputObject, outputObject);
}
}

View file

@ -1,64 +0,0 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.eve.dao;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface MyNoteDao {
int insertFileFolderByUserId(Map<String, Object> map);
List<Map<String, Object>> queryFileFolderByUserIdAndParentId(Map<String, Object> map);
Map<String, Object> queryFolderMationById(@Param("folderId") String folderId);
int deleteFileFolderById(Map<String, Object> map);
int deleteFilesByFolderId(Map<String, Object> map);
int deleteFolderChildByFolderId(Map<String, Object> map);
int deleteNoteContentById(Map<String, Object> map);
int editFileFolderById(Map<String, Object> map);
int editNoteContentNameById(Map<String, Object> map);
List<Map<String, Object>> queryMyNoteListNewByUserId(Map<String, Object> map);
int insertMyNoteContentByUserId(Map<String, Object> map);
List<Map<String, Object>> queryFileAndContentListByFolderId(Map<String, Object> map);
Map<String, Object> queryMyNoteContentMationById(Map<String, Object> map);
int editMyNoteContentById(Map<String, Object> map);
List<Map<String, Object>> queryFileFolderListByList(List<Map<String, Object>> folderBeans);
int deleteFileFolderListByList(List<Map<String, Object>> folderBeans);
List<Map<String, Object>> queryFileListByList(List<Map<String, Object>> folderNew);
int deleteFileListByList(List<Map<String, Object>> folderNew);
int insertFileFolderListByList(List<Map<String, Object>> folderNew);
int insertFileListByList(List<Map<String, Object>> fileNew);
List<Map<String, Object>> queryTreeToMoveByUserId(Map<String, Object> map);
Map<String, Object> queryShareNoteById(@Param("fileId") String fileId);
List<Map<String, Object>> queryAllFolderListByFolderId(@Param("folderId") String folderId);
List<Map<String, Object>> queryAllFileListByFolderList(List<Map<String, Object>> beans);
int editNoteToMoveById(@Param("fileId") String fileId, @Param("parentId") String parentId, @Param("userId") String userId);
}

View file

@ -1,40 +0,0 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.eve.service;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
public interface MyNoteService {
void queryFileMyNoteByUserId(InputObject inputObject, OutputObject outputObject);
void insertFileMyNoteByUserId(InputObject inputObject, OutputObject outputObject);
void deleteFileFolderById(InputObject inputObject, OutputObject outputObject);
void editFileFolderById(InputObject inputObject, OutputObject outputObject);
void queryMyNoteListNewByUserId(InputObject inputObject, OutputObject outputObject);
void insertMyNoteContentByUserId(InputObject inputObject, OutputObject outputObject);
void queryFileAndContentListByFolderId(InputObject inputObject, OutputObject outputObject);
void queryMyNoteContentMationById(InputObject inputObject, OutputObject outputObject);
void editMyNoteContentById(InputObject inputObject, OutputObject outputObject);
void editFileToDragById(InputObject inputObject, OutputObject outputObject);
void editNoteToMoveById(InputObject inputObject, OutputObject outputObject);
void queryTreeToMoveByUserId(InputObject inputObject, OutputObject outputObject);
void queryShareNoteById(InputObject inputObject, OutputObject outputObject);
void outputNoteIsZipJob(InputObject inputObject, OutputObject outputObject);
}

View file

@ -1,477 +0,0 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.eve.service.impl;
import cn.hutool.json.JSONUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.common.constans.NoteConstants;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
import com.skyeye.common.util.DataCommonUtil;
import com.skyeye.common.util.DateUtil;
import com.skyeye.common.util.ToolUtil;
import com.skyeye.eve.dao.MyNoteDao;
import com.skyeye.eve.service.MyNoteService;
import com.skyeye.jedis.JedisClientService;
import com.skyeye.service.JobMateMationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.*;
/**
* @ClassName: MyNoteServiceImpl
* @Description: 笔记管理服务类
* @author: skyeye云系列--卫志强
* @date: 2021/7/6 22:56
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
@Service
public class MyNoteServiceImpl implements MyNoteService {
@Autowired
private MyNoteDao myNoteDao;
@Autowired
public JedisClientService jedisClient;
@Autowired
private JobMateMationService jobMateMationService;
/**
* 根据当前用户获取笔记文件夹
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
public void queryFileMyNoteByUserId(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
if (ToolUtil.isBlank(map.get("parentId").toString()) || "0".equals(map.get("parentId").toString())) {
// 加载一级文件夹
List<Map<String, Object>> beans = new ArrayList<>();
if (ToolUtil.isBlank(jedisClient.get(NoteConstants.SYS_FILE_MYNOTE_LIST_MATION))) {
beans = NoteConstants.getFileMyNoteDefaultFolder();
jedisClient.set(NoteConstants.SYS_FILE_MYNOTE_LIST_MATION, JSONUtil.toJsonStr(beans));
} else {
beans = JSONUtil.toList(jedisClient.get(NoteConstants.SYS_FILE_MYNOTE_LIST_MATION), null);
}
outputObject.setBeans(beans);
} else {//加载子文件夹
Map<String, Object> user = inputObject.getLogParams();
map.put("userId", user.get("id"));
List<Map<String, Object>> beans = new ArrayList<>();
String key = NoteConstants.getSysFileMyNoteListMation(map.get("parentId").toString(), map.get("userId").toString());
if (ToolUtil.isBlank(jedisClient.get(key))) {
beans = myNoteDao.queryFileFolderByUserIdAndParentId(map);
jedisClient.set(key, JSONUtil.toJsonStr(beans));
} else {
beans = JSONUtil.toList(jedisClient.get(key), null);
}
outputObject.setBeans(beans);
}
}
/**
* 添加文件夹
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void insertFileMyNoteByUserId(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
String userId = inputObject.getLogParams().get("id").toString();
String key = NoteConstants.getSysFileMyNoteListMation(map.get("parentId").toString(), userId);
jedisClient.delKeys(key);//删除父文件夹的redis的key
String parentId = setParentId(map.get("parentId").toString());
if ("0".equals(parentId)) {
outputObject.setreturnMessage("错误的文件夹编码!");
return;
}
map.put("parentId", parentId);
map.put("state", 1);
DataCommonUtil.setCommonData(map, userId);
myNoteDao.insertFileFolderByUserId(map);
map.put("logoPath", NoteConstants.SYS_FILE_CONSOLE_IS_FOLDER_LOGO_PATH);
outputObject.setBean(map);
}
/**
* 删除文件夹以及文件夹下的所有文件
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void deleteFileFolderById(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
Map<String, Object> user = inputObject.getLogParams();
map.put("userId", user.get("id"));
String id = map.get("id").toString();
if ("folder".equals(map.get("fileType").toString())) {//操作文件夹表
Map<String, Object> folder = myNoteDao.queryFolderMationById(id);
String[] str = folder.get("parentId").toString().split(",");
String key = NoteConstants.getSysFileMyNoteListMation(str[str.length - 1], user.get("id").toString());
myNoteDao.deleteFileFolderById(map);//删除自身文件夹
myNoteDao.deleteFolderChildByFolderId(map);//删除子文件夹
myNoteDao.deleteFilesByFolderId(map);//删除子文件
jedisClient.delKeys(key);//删除父文件夹的redis的key
} else {//操作笔记内容表
myNoteDao.deleteNoteContentById(map);//删除自身文件
}
}
/**
* 编辑文件夹名称
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void editFileFolderById(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
Map<String, Object> user = inputObject.getLogParams();
map.put("userId", user.get("id"));
String id = map.get("id").toString();
if ("folder".equals(map.get("fileType").toString())) {//操作文件夹表
Map<String, Object> folder = myNoteDao.queryFolderMationById(id);
String[] str = folder.get("parentId").toString().split(",");
String key = NoteConstants.getSysFileMyNoteListMation(str[str.length - 1], user.get("id").toString());
jedisClient.delKeys(key);//删除父文件夹的redis的key
myNoteDao.editFileFolderById(map);
} else {//操作笔记内容表
myNoteDao.editNoteContentNameById(map);
}
}
/**
* 根据当前用户获取最新的笔记列表
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
public void queryMyNoteListNewByUserId(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
Map<String, Object> user = inputObject.getLogParams();
map.put("userId", user.get("id"));
Page pages = PageHelper.startPage(Integer.parseInt(map.get("page").toString()), Integer.parseInt(map.get("limit").toString()));
List<Map<String, Object>> beans = myNoteDao.queryMyNoteListNewByUserId(map);
outputObject.setBeans(beans);
outputObject.settotal(pages.getTotal());
}
/**
* 添加笔记
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void insertMyNoteContentByUserId(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
String parentId = setParentId(map.get("parentId").toString());
if ("0".equals(parentId)) {
outputObject.setreturnMessage("错误的文件夹编码!");
return;
}
map.put("parentId", parentId);
map.put("state", 1);
map.put("iconLogo", getIconLogoPathByType(map.get("type").toString()));
DataCommonUtil.setCommonData(map, inputObject.getLogParams().get("id").toString());
myNoteDao.insertMyNoteContentByUserId(map);
outputObject.setBean(map);
}
/**
* 根据笔记类型设置展示图标
*
* @param type
* @return
*/
private String getIconLogoPathByType(String type) {
String iconLogo = "../../assets/images/%s";
switch (type) {
case "1":
// 富文本编辑器
iconLogo = String.format(Locale.ROOT, iconLogo, "note-1.png");
break;
case "2":
// markdown笔记
iconLogo = String.format(Locale.ROOT, iconLogo, "note-2.png");
break;
case "3":
// word笔记
iconLogo = String.format(Locale.ROOT, iconLogo, "note-3.png");
break;
case "4":
// ecxel笔记
iconLogo = String.format(Locale.ROOT, iconLogo, "note-4.png");
break;
default:
break;
}
return iconLogo;
}
/**
* 根据文件夹id获取文件夹下的文件夹和笔记列表
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
public void queryFileAndContentListByFolderId(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
Map<String, Object> user = inputObject.getLogParams();
map.put("userId", user.get("id"));
List<Map<String, Object>> beans = myNoteDao.queryFileAndContentListByFolderId(map);
outputObject.setBeans(beans);
outputObject.settotal(beans.size());
}
/**
* 编辑笔记时回显信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
public void queryMyNoteContentMationById(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
Map<String, Object> bean = myNoteDao.queryMyNoteContentMationById(map);
outputObject.setBean(bean);
}
/**
* 编辑笔记信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void editMyNoteContentById(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
String desc = map.get("desc").toString();
if (desc.length() > 100) {
desc = desc.substring(0, 99);
}
map.put("desc", desc);
Map<String, Object> user = inputObject.getLogParams();
map.put("userId", user.get("id"));
myNoteDao.editMyNoteContentById(map);
}
/**
* 保存文件夹拖拽后的信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void editFileToDragById(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
Map<String, Object> user = inputObject.getLogParams();
String newParentId = "";
String targetId = map.get("targetId").toString();
String key = NoteConstants.getSysFileMyNoteListMation(targetId, user.get("id").toString());
jedisClient.delKeys(key);//删除父文件夹的redis的key
if (targetId.equals("2")) {
newParentId = "2" + ",";
} else {
Map<String, Object> folder = myNoteDao.queryFolderMationById(targetId);//获取目标文件夹的父id
newParentId = folder.get("parentId").toString() + targetId + ",";//拖拽文件夹新的父id
}
String arrId = map.get("arrId").toString();
String[] arr = arrId.split(",");//拖拽文件夹的id数组
List<Map<String, Object>> folderBeans = new ArrayList<>();
for (int i = 0; i < arr.length; i++) {
Map<String, Object> bean = new HashMap<>();
bean.put("id", arr[i]);
folderBeans.add(bean);
}
if (!folderBeans.isEmpty()) {
// 选择保存的文件夹不为空
List<Map<String, Object>> folderNew = myNoteDao.queryFileFolderListByList(folderBeans);
if (!folderNew.isEmpty()) {//删除之前的信息
myNoteDao.deleteFileFolderListByList(folderNew);
}
List<Map<String, Object>> fileNew = myNoteDao.queryFileListByList(folderNew);
if (!fileNew.isEmpty()) {//删除之前的信息
myNoteDao.deleteFileListByList(fileNew);
}
for (Map<String, Object> folder : folderNew) {//重置父id
String[] str = folder.get("parentId").toString().split(",");
String thiskey = NoteConstants.getSysFileMyNoteListMation(str[str.length - 1], user.get("id").toString());
jedisClient.delKeys(thiskey);//删除父文件夹的redis的key
folder.put("directParentId", str[str.length - 1]);
folder.put("newId", ToolUtil.getSurFaceId());
}
//将数据转化为树的形式方便进行父id重新赋值
folderNew = ToolUtil.listToTree(folderNew, "id", "directParentId", "children");
ToolUtil.FileListParentISEdit(folderNew, newParentId);//替换父id
folderNew = ToolUtil.FileTreeTransList(folderNew);//将树转为list
for (Map<String, Object> folder : folderNew) {
folder.put("createId", user.get("id"));
folder.put("createTime", DateUtil.getTimeAndToString());
folder.put("state", 1);
}
//为文件重置新parentId参数
for (Map<String, Object> folder : folderNew) {
String parentId = folder.get("parentId").toString() + folder.get("id").toString() + ",";
String nParentId = folder.get("newParentId").toString() + folder.get("newId").toString() + ",";
// 重置文件的参数
for (Map<String, Object> file : fileNew) {
if (file.get("parentId").toString().equals(parentId)) {
file.put("newParentId", nParentId);
file.put("newId", ToolUtil.getSurFaceId());
file.put("createId", user.get("id"));
file.put("createTime", DateUtil.getTimeAndToString());
file.put("state", 1);
}
}
}
if (!folderNew.isEmpty()) {
myNoteDao.insertFileFolderListByList(folderNew);
}
if (!fileNew.isEmpty()) {
myNoteDao.insertFileListByList(fileNew);
}
}
}
/**
* 根据节点id设置ParentId
*
* @param id
* @return
*/
private String setParentId(String id) {
if ("2".equals(id)) {
return id + ",";
} else {
Map<String, Object> folder = myNoteDao.queryFolderMationById(id);
if (!CollectionUtils.isEmpty(folder)) {
return folder.get("parentId").toString() + id + ",";
} else {
return "0";
}
}
}
/**
* 保存笔记移动后的信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void editNoteToMoveById(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
// 要移动的笔记id
String rowId = map.get("moveId").toString();
// 移动后的目录id
String toId = map.get("toId").toString();
String parentId = setParentId(toId);
if ("0".equals(parentId)) {
outputObject.setreturnMessage("错误的文件夹编码!");
return;
}
myNoteDao.editNoteToMoveById(rowId, parentId, inputObject.getLogParams().get("id").toString());
}
/**
* 获取文件夹或笔记移动时的选择树
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
public void queryTreeToMoveByUserId(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
if (ToolUtil.isBlank(map.get("parentId").toString()) || "0".equals(map.get("parentId").toString())) {//加载一级文件夹
List<Map<String, Object>> beans = new ArrayList<>();
if (ToolUtil.isBlank(jedisClient.get(NoteConstants.SYS_FILE_MYNOTE_LIST_MATION))) {
beans = NoteConstants.getFileMyNoteDefaultFolder();
jedisClient.set(NoteConstants.SYS_FILE_MYNOTE_LIST_MATION, JSONUtil.toJsonStr(beans));
} else {
beans = JSONUtil.toList(jedisClient.get(NoteConstants.SYS_FILE_MYNOTE_LIST_MATION), null);
}
outputObject.setBeans(beans);
} else {//加载子文件夹
Map<String, Object> user = inputObject.getLogParams();
map.put("userId", user.get("id"));
List<Map<String, Object>> beans = new ArrayList<>();
beans = myNoteDao.queryTreeToMoveByUserId(map);
outputObject.setBeans(beans);
}
}
/**
* 根据id获取分享笔记的内容
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
public void queryShareNoteById(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
Map<String, Object> bean = myNoteDao.queryShareNoteById(map.get("id").toString());
if (bean == null) {
outputObject.setreturnMessage("该信息已被删除或不存在.");
return;
}
outputObject.setBean(bean);
}
/**
* 根据id(文件夹或者笔记id)将笔记输出为压缩包
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@Override
public void outputNoteIsZipJob(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> map = inputObject.getParams();
String rowId = map.get("id").toString();
// 类型1.文件夹2.笔记
int type = Integer.parseInt(map.get("type").toString());
Map<String, Object> mation;
if (type == 1) {
// 获取文件夹信息
mation = myNoteDao.queryFolderMationById(rowId);
} else {
// 获取文件信息
mation = myNoteDao.queryShareNoteById(rowId);
}
if (CollectionUtils.isEmpty(mation)) {
outputObject.setreturnMessage("该信息不存在.");
return;
}
String userId = inputObject.getLogParams().get("id").toString();
Map<String, Object> json = new HashMap<>();
json.put("title", mation.get("title").toString());
json.put("noteType", type);
json.put("rowId", rowId);
json.put("userId", userId);
json.put("type", MqConstants.JobMateMationJobType.OUTPUT_NOTES_IS_ZIP.getJobType());
// 启动任务
jobMateMationService.sendMQProducer(JSONUtil.toJsonStr(json), userId);
}
}

View file

@ -1,193 +0,0 @@
/*******************************************************************************
* Copyright 卫志强 QQ598748873@qq.com Inc. All rights reserved. 开源地址https://gitee.com/doc_wei01/skyeye
******************************************************************************/
package com.skyeye.mq.job.impl;
import cn.hutool.json.JSONUtil;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.common.util.FileUtil;
import com.skyeye.common.util.ToolUtil;
import com.skyeye.eve.dao.MyNoteDao;
import com.skyeye.exception.CustomException;
import com.skyeye.mq.job.JobMateService;
import com.skyeye.service.JobMateMationService;
import com.youbenzi.md2.export.FileFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipOutputStream;
/**
* @author 卫志强
* @ClassName: OutputNotesIsZipServiceImpl
* @Description: 笔记输出为压缩包
* @date 2020年8月23日
*/
@Service("outputNotesIsZipService")
public class OutputNotesIsZipServiceImpl implements JobMateService {
private static Logger LOGGER = LoggerFactory.getLogger(OutputNotesIsZipServiceImpl.class);
@Autowired
private JobMateMationService jobMateMationService;
@Value("${IMAGES_PATH}")
private String tPath;
/**
* 系统水印
*/
@Value("${system.sysWaterMark}")
private String sysWaterMark;
/**
* 系统地址
*/
@Value("${webroot.ndc}")
private String webRootNdc;
@Autowired
private MyNoteDao myNoteDao;
@Override
public void call(String data) {
Map<String, Object> map = JSONUtil.toBean(data, null);
String jobId = map.get("jobMateId").toString();
Map<String, Object> mation = new HashMap<>();
try {
LOGGER.info("start output job, jobId is {}", jobId);
// 任务开始
jobMateMationService.comMQJobMation(jobId, MqConstants.JOB_TYPE_IS_PROCESSING, "");
String rowId = map.get("rowId").toString();
// 类型1.文件夹2.笔记
int type = Integer.parseInt(map.get("noteType").toString());
if (type == 1) {
String zipFile = outputFolder(rowId, map.get("userId").toString());
mation.put("filePath", zipFile);
} else {
String zipFile = outPutFileContent(rowId, map.get("userId").toString());
mation.put("filePath", zipFile);
}
// 任务完成
jobMateMationService.comMQJobMation(jobId, MqConstants.JOB_TYPE_IS_SUCCESS, JSONUtil.toJsonStr(mation));
} catch (Exception e) {
LOGGER.info("job is fail, this message is {}", e);
// 任务失败
mation.put("message", e);
jobMateMationService.comMQJobMation(jobId, MqConstants.JOB_TYPE_IS_FAIL, JSONUtil.toJsonStr(mation));
}
}
/**
* 文件夹(包含文件)输出为压缩包
*
* @param parentId
* @param userId
* @return
*/
private String outputFolder(String parentId, String userId) {
// 1.获取该目录下的所有目录
List<Map<String, Object>> beans = myNoteDao.queryAllFolderListByFolderId(parentId);
// 2.获取所有目录下的所有文件
List<Map<String, Object>> files = myNoteDao.queryAllFileListByFolderList(beans);
// 文件存储基础路径
String basePath = String.format("%s%s%s%s", tPath, "\\upload\\notes\\filezip\\", userId, "\\");
ToolUtil.createFolder(basePath);
for (Map<String, Object> bean : files) {
String content = bean.containsKey("content") ? bean.get("content").toString() : "";
bean.put("fileAddress", outPutFileContent(basePath, content, Integer.parseInt(bean.get("fileType").toString()), userId));
bean.put("content", "");
bean.put("fileName", bean.get("fileName").toString() + ".pdf");
}
beans.addAll(files);
// 重置父id
for (Map<String, Object> folder : beans) {
String[] str = folder.get("parentId").toString().split(",");
folder.put("directParentId", str[str.length - 1]);
}
// 将数据转化为树的形式方便进行父id重新赋值
beans = ToolUtil.listToTree(beans, "id", "directParentId", "children");
// 打包--压缩包文件名
String fileName = String.valueOf(System.currentTimeMillis());
String strZipPath = basePath + fileName + ".zip";
ZipOutputStream out = null;
try {
out = new ZipOutputStream(new FileOutputStream(strZipPath));
ToolUtil.recursionZip(out, beans, "", tPath.replace("images", ""), 2);
} catch (Exception ee) {
throw new CustomException(ee);
} finally {
// 删除临时文件
for (Map<String, Object> bean : files) {
FileUtil.deleteFile(tPath.replace("images", "") + bean.get("fileAddress").toString());
}
FileUtil.close(out);
}
return "/images/upload/notes/filezip/" + userId + "/" + fileName + ".zip";
}
/**
* 单个文件输出
*
* @param basePath 基础路径
* @param content 内容
* @param type 类型
* @param userId 用户id
* @return
*/
private String outPutFileContent(String basePath, String content, int type, String userId) {
String fileName = String.valueOf(System.currentTimeMillis());
if (ToolUtil.isBlank(content)) {
content = "暂无内容";
}
switch (type) {
case 1:
// 富文本编辑器
break;
case 2:
// markdown笔记
FileFactory.produce(content, basePath + "/" + fileName + ".pdf", webRootNdc, sysWaterMark);
break;
case 3:
// word笔记
break;
case 4:
// ecxel笔记
break;
default:
break;
}
return "/images/upload/notes/filezip/" + userId + "/" + fileName + ".pdf";
}
/**
* 单个文件输出
*
* @param fileId 文件id
* @param userId 用户id
* @return
*/
private String outPutFileContent(String fileId, String userId) {
Map<String, Object> mation = myNoteDao.queryShareNoteById(fileId);
mation.put("fileName", mation.get("title"));
mation.put("fileType", mation.get("type"));
// 文件存储基础路径
String basePath = String.format("%s%s%s%s", tPath, "/upload/notes/filezip/", userId, "/");
ToolUtil.createFolder(basePath);
return outPutFileContent(basePath, mation.get("content").toString(), Integer.parseInt(mation.get("fileType").toString()), userId);
}
}

View file

@ -1,363 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.skyeye.eve.dao.MyNoteDao">
<insert id="insertFileFolderByUserId" parameterType="java.util.Map">
INSERT INTO note_folder
(id, name, state, parent_id, create_id, create_time, last_update_id, last_update_time)
VALUES
(#{id}, #{catalogName}, #{state}, #{parentId}, #{createId}, #{createTime}, #{createId}, #{createTime})
</insert>
<select id="queryFileFolderByUserIdAndParentId" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
a.id,
a.name `name`,
#{parentId} pId,
'../../assets/images/my-folder-icon.png' icon,
1 isParent
FROM
note_folder a
WHERE a.parent_id = CONCAT(IFNULL((SELECT t.parent_id FROM note_folder t WHERE t.id = #{parentId}), ''), #{parentId}, ',')
AND a.create_id = #{userId}
AND a.state = 1
ORDER BY a.name ASC
</select>
<select id="queryTreeToMoveByUserId" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
a.id,
a.name `name`,
#{parentId} pId,
'../../assets/images/my-folder-icon.png' icon,
1 isParent
FROM
note_folder a
WHERE a.parent_id = CONCAT(IFNULL((SELECT t.parent_id FROM note_folder t WHERE t.id = #{parentId}), ''), #{parentId}, ',')
AND a.create_id = #{userId}
AND a.state = 1
AND a.id != #{moveId}
ORDER BY a.name ASC
</select>
<select id="queryFolderMationById" resultType="java.util.Map">
SELECT
a.id,
a.`name` title,
a.parent_id parentId
FROM
note_folder a
WHERE a.id = #{folderId}
AND a.state = '1'
</select>
<update id="deleteFileFolderById" parameterType="java.util.Map">
UPDATE note_folder
<set>
state = 2,
last_update_id = #{userId},
last_update_time = NOW(),
</set>
WHERE id = #{id}
</update>
<update id="deleteFolderChildByFolderId" parameterType="java.util.Map">
UPDATE note_folder
<set>
state = 2,
last_update_id = #{userId},
last_update_time = NOW(),
</set>
WHERE
INSTR(CONCAT(',', parent_id, ','), CONCAT(',', #{id}, ','))
</update>
<update id="deleteFilesByFolderId" parameterType="java.util.Map">
UPDATE note_content
<set>
state = 2,
last_update_id = #{userId},
last_update_time = NOW(),
</set>
WHERE
INSTR(CONCAT(',', parent_id, ','), CONCAT(',', #{id}, ','))
</update>
<update id="deleteNoteContentById" parameterType="java.util.Map">
UPDATE note_content
<set>
state = 2,
last_update_id = #{userId},
last_update_time = NOW(),
</set>
WHERE id = #{id}
</update>
<update id="editFileFolderById" parameterType="java.util.Map">
UPDATE note_folder
<set>
<if test="catalogName != '' and catalogName != null">
name = #{catalogName},
</if>
last_update_id = #{userId},
last_update_time = NOW(),
</set>
WHERE id = #{id}
AND create_id = #{userId}
</update>
<update id="editNoteContentNameById" parameterType="java.util.Map">
UPDATE note_content
<set>
<if test="catalogName != '' and catalogName != null">
title = #{catalogName},
</if>
last_update_id = #{userId},
last_update_time = NOW(),
</set>
WHERE id = #{id}
AND create_id = #{userId}
</update>
<select id="queryMyNoteListNewByUserId" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
a.id,
a.title name,
a.icon_logo icon,
a.type fileType,
a.desc `desc`,
a.content,
CONVERT(a.last_update_time, char) createTime
FROM
note_content a
WHERE a.state = 1
<if test="search != '' and search != null">
AND (a.title LIKE '%${search}%' OR a.desc LIKE '%${search}%')
</if>
AND a.create_id = #{userId}
ORDER BY a.last_update_time DESC
</select>
<insert id="insertMyNoteContentByUserId" parameterType="java.util.Map">
INSERT INTO note_content
(id, title, state, parent_id, icon_logo, `desc`, content, type, create_id, create_time, last_update_id, last_update_time)
VALUES
(#{id}, #{title}, #{state}, #{parentId}, #{iconLogo}, #{desc}, #{content}, #{type}, #{createId}, #{createTime}, #{createId}, #{createTime})
</insert>
<select id="queryFileAndContentListByFolderId" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
*
FROM (
SELECT
a.id,
a.name `name`,
#{parentId} pId,
'../../assets/images/my-folder-icon.png' icon,
1 isParent,
'folder' fileType,
'' `desc`,
CONVERT(a.create_time, char) createTime
FROM
note_folder a
WHERE
a.parent_id = CONCAT(IFNULL((SELECT t.parent_id FROM note_folder t WHERE t.id = #{parentId}), ''), #{parentId}, ',')
AND a.state = 1
<if test="search != '' and search != null">
AND a.name LIKE '%${search}%'
</if>
AND a.create_id = #{userId}
ORDER BY a.`name` DESC
) k
UNION ALL
SELECT
*
FROM (
SELECT
a.id,
a.title `name`,
#{parentId} pId,
a.icon_logo icon,
0 isParent,
a.type fileType,
a.desc `desc`,
CONVERT(a.create_time, char) createTime
FROM
note_content a
WHERE
a.parent_id = CONCAT(IFNULL((SELECT t.parent_id FROM note_folder t WHERE t.id = #{parentId}), ''), #{parentId}, ',')
AND a.state = 1
<if test="search != '' and search != null">
AND (a.title LIKE '%${search}%' OR a.desc LIKE '%${search}%')
</if>
AND a.create_id = #{userId}
ORDER BY a.title DESC
) j
</select>
<select id="queryMyNoteContentMationById" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
id,
title,
`type`,
icon_logo,
`desc`,
content
FROM
note_content
WHERE id = #{id}
</select>
<update id="editMyNoteContentById" parameterType="java.util.Map">
UPDATE note_content
<set>
<if test="title != '' and title != null">
title = #{title},
</if>
content = #{content},
`desc` = #{desc},
last_update_id = #{userId},
last_update_time = NOW(),
</set>
WHERE id = #{id}
AND create_id = #{userId}
</update>
<select id="queryFileFolderListByList" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
a.id,
a.name `name`,
a.parent_id parentId,
'folder' fileType
FROM
note_folder a
WHERE a.state = '1'
AND (
<foreach collection="list" item="item" index="index" >
INSTR(CONCAT(',', a.parent_id, ','), CONCAT(',', #{item.id}, ',')) OR a.id = #{item.id} OR
</foreach>
1=0)
ORDER BY LENGTH(a.parent_id) ASC
</select>
<delete id="deleteFileFolderListByList" parameterType="java.util.Map">
DELETE
FROM
note_folder
WHERE
(
<foreach collection="list" item="item" index="index" >
id = #{item.id} OR
</foreach>
1 = 0)
</delete>
<select id="queryFileListByList" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
a.id,
a.title fileName,
a.icon_logo iconLogo,
a.desc `desc`,
a.content,
a.type,
a.parent_id parentId
FROM
note_content a
WHERE a.state = '1'
AND (
<foreach collection="list" item="item" index="index" >
a.parent_id = CONCAT(#{item.parentId}, #{item.id}, ',') OR
</foreach>
1=0)
ORDER BY LENGTH(a.parent_id) ASC
</select>
<delete id="deleteFileListByList" parameterType="java.util.Map">
DELETE
FROM
note_content
WHERE
(
<foreach collection="list" item="item" index="index" >
id = #{item.id} OR
</foreach>
1 = 0)
</delete>
<insert id="insertFileFolderListByList" parameterType="java.util.Map">
insert into note_folder
(id, name, parent_id, state, create_id, create_time, last_update_id, last_update_time)
values
<foreach collection="list" item="item" index="index" separator="," >
(#{item.newId}, #{item.name}, #{item.newParentId}, #{item.state}, #{item.createId}, #{item.createTime}, #{item.createId}, #{item.createTime})
</foreach>
</insert>
<insert id="insertFileListByList" parameterType="java.util.Map">
insert into note_content
(id, title, icon_logo, `desc`, content, type, parent_id, state, create_id, create_time, last_update_id, last_update_time)
values
<foreach collection="list" item="item" index="index" separator="," >
(#{item.newId}, #{item.fileName}, #{item.iconLogo}, #{item.desc}, #{item.content}, #{item.type},
#{item.newParentId}, #{item.state}, #{item.createId}, #{item.createTime}, #{item.createId}, #{item.createTime})
</foreach>
</insert>
<select id="queryShareNoteById" resultType="java.util.Map">
SELECT
a.id,
a.title,
a.type,
a.content,
CONVERT(a.create_time, char) createTime,
b.user_name createName
FROM
note_content a
LEFT JOIN sys_eve_user_staff b ON a.create_id = b.user_id
WHERE a.id = #{fileId}
AND a.state = '1'
</select>
<select id="queryAllFolderListByFolderId" resultType="java.util.Map">
SELECT
a.id,
a.`name` fileName,
'' content,
'folder' fileType,
a.parent_id parentId
FROM
note_folder a
WHERE a.state = '1'
AND (INSTR(CONCAT(',', a.parent_id, ','), CONCAT(',', #{folderId}, ',')) OR a.id = #{folderId})
ORDER BY LENGTH(a.parent_id) ASC
</select>
<select id="queryAllFileListByFolderList" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
a.id,
a.title fileName,
a.content,
a.type fileType,
a.parent_id parentId
FROM
note_content a
WHERE a.state = '1'
AND (
<foreach collection="list" item="item" index="index" >
a.parent_id = CONCAT(#{item.parentId}, #{item.id}, ',') OR
</foreach>
1=0)
ORDER BY LENGTH(a.parent_id) ASC
</select>
<update id="editNoteToMoveById">
UPDATE note_content
<set>
parent_id = #{parentId},
last_update_id = #{userId},
last_update_time = NOW(),
</set>
WHERE id = #{fileId}
</update>
</mapper>

View file

@ -1,68 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<controller modelName="笔记">
<!--
- allUse 是否需要登录才能使用 1是 0否 2需要登陆才能访问但无需授权 默认为否
-->
<!-- 笔记开始 -->
<url id="mynote001" path="/post/MyNoteController/queryFileMyNoteByUserId" val="根据当前用户获取笔记文件夹" allUse="2" method="GET" groupName="笔记模块">
<property id="parentId" name="parentId" ref="required" var="父文件夹id默认为0" />
</url>
<url id="mynote002" path="/post/MyNoteController/insertFileMyNoteByUserId" val="添加文件夹" allUse="2">
<property id="parentId" name="parentId" ref="required" var="父文件夹id默认为0" />
<property id="catalogName" name="catalogName" ref="required" var="文件夹名称" />
</url>
<url id="mynote003" path="/post/MyNoteController/deleteFileFolderById" val="删除文件夹以及文件夹下的所有文件" allUse="2">
<property id="rowId" name="id" ref="required" var="文件夹id" />
<property id="fileType" name="fileType" ref="required" var="文件或者文件夹类型" />
</url>
<url id="mynote004" path="/post/MyNoteController/editFileFolderById" val="编辑文件夹名称" allUse="2">
<property id="rowId" name="id" ref="required" var="文件夹id" />
<property id="catalogName" name="catalogName" ref="required" var="文件夹名称" />
<property id="fileType" name="fileType" ref="required" var="文件或者文件夹类型" />
</url>
<url id="mynote005" path="/post/MyNoteController/queryMyNoteListNewByUserId" val="根据当前用户获取最新的笔记列表" allUse="2">
<property id="limit" name="limit" ref="required,num" var="分页参数,每页多少条数据" />
<property id="page" name="page" ref="required,num" var="分页参数,第几页"/>
<property id="search" name="search" ref="" var="搜索框的值"/>
</url>
<url id="mynote006" path="/post/MyNoteController/queryFileAndContentListByFolderId" val="根据文件夹id获取文件夹下的文件夹和笔记列表" allUse="2">
<property id="parentId" name="parentId" ref="required" var="文件夹id" />
<property id="search" name="search" ref="" var="搜索框的值"/>
</url>
<url id="mynote007" path="/post/MyNoteController/insertMyNoteContentByUserId" val="添加笔记" allUse="2">
<property id="parentId" name="parentId" ref="required" var="父文件夹id默认为0" />
<property id="title" name="title" ref="required" var="笔记标题" />
<property id="type" name="type" ref="required" var="笔记类型" />
</url>
<url id="mynote008" path="/post/MyNoteController/queryMyNoteContentMationById" val="编辑笔记时回显信息" allUse="2">
<property id="rowId" name="id" ref="required" var="笔记ID" />
</url>
<url id="mynote009" path="/post/MyNoteController/editMyNoteContentById" val="编辑笔记信息" allUse="2">
<property id="rowId" name="id" ref="required" var="笔记ID" />
<property id="title" name="title" ref="required" var="笔记标题" />
<property id="content" name="content" ref="" var="笔记内容" />
<property id="desc" name="desc" ref="" var="笔记简介" />
</url>
<url id="mynote010" path="/post/MyNoteController/editFileToDragById" val="保存文件夹拖拽后的信息" allUse="2">
<property id="targetId" name="targetId" ref="required" var="拖拽目标节点id" />
<property id="arrId" name="arrId" ref="required" var="拖拽节点id数组" />
</url>
<url id="mynote011" path="/post/MyNoteController/editNoteToMoveById" val="保存笔记移动后的信息" allUse="2">
<property id="toId" name="toId" ref="required" var="移动目标节点id" />
<property id="moveId" name="moveId" ref="required" var="移动笔记id" />
</url>
<url id="mynote012" path="/post/MyNoteController/queryTreeToMoveByUserId" val="获取文件夹或笔记移动时的选择树" allUse="2" method="GET" groupName="文件夹树模块">
<property id="parentId" name="parentId" ref="required" var="父文件夹id默认为0" />
<property id="moveId" name="moveId" ref="required" var="移动节点id" />
</url>
<url id="mynote013" path="/post/MyNoteController/queryShareNoteById" val="根据id获取分享笔记的内容" allUse="2">
<property id="rowId" name="id" ref="required" var="笔记ID" />
</url>
<url id="mynote014" path="/post/MyNoteController/outputNoteIsZipJob" val="根据id(文件夹或者笔记id)将笔记输出为压缩包" allUse="2">
<property id="rowId" name="id" ref="required" var="笔记ID" />
<property id="type" name="type" ref="required,num" var="类型1.文件夹2.笔记"/>
</url>
<!-- 笔记结束 -->
</controller>

View file

@ -7,7 +7,6 @@ package com.skyeye.quartz.consumer.impl;
import cn.hutool.json.JSONUtil;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.common.util.DataCommonUtil;
import com.skyeye.common.util.DateUtil;
import com.skyeye.common.util.ToolUtil;
import com.skyeye.eve.dao.SysQuartzDao;
import com.skyeye.quartz.consumer.TaskMateService;

View file

@ -6,7 +6,6 @@ package com.skyeye.quartz.consumer.impl;
import cn.hutool.json.JSONUtil;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.common.util.DataCommonUtil;
import com.skyeye.common.util.DateUtil;
import com.skyeye.common.util.ToolUtil;
import com.skyeye.eve.dao.SysQuartzDao;
import com.skyeye.quartz.consumer.TaskMateService;

View file

@ -6,7 +6,6 @@ package com.skyeye.quartz.consumer.impl;
import cn.hutool.json.JSONUtil;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.common.util.DataCommonUtil;
import com.skyeye.common.util.DateUtil;
import com.skyeye.common.util.ToolUtil;
import com.skyeye.eve.dao.SysQuartzDao;
import com.skyeye.quartz.consumer.TaskMateService;

View file

@ -99,13 +99,6 @@
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- 引入笔记模块的依赖 -->
<dependency>
<groupId>com.skyeye</groupId>
<artifactId>skyeye-note</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- 引入开发文档和代码生成器模块的依赖 -->
<dependency>
<groupId>com.skyeye</groupId>