【其他】日期调整为工具类

This commit is contained in:
weizhiqiang 2022-06-21 17:10:59 +08:00
parent ebb5aad829
commit 8963b7f57d
3 changed files with 134 additions and 133 deletions

View file

@ -6,6 +6,7 @@ package com.skyeye.mq.job.impl;
import cn.hutool.json.JSONUtil;
import com.skyeye.common.constans.MqConstants;
import com.skyeye.common.util.DateUtil;
import com.skyeye.common.util.EmailUtil;
import com.skyeye.common.util.ShowMail;
import com.skyeye.common.util.ToolUtil;
@ -28,109 +29,108 @@ import java.util.List;
import java.util.Map;
/**
*
* @ClassName: MailAccessDeleteServiceImpl
* @Description: 已删除邮件获取
* @author: skyeye云系列--卫志强
* @date: 2021/7/4 21:58
*
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
@Service("mailAccessDeleteService")
public class MailAccessDeleteServiceImpl implements JobMateService{
private static final Logger LOGGER = LoggerFactory.getLogger(MailAccessDeleteServiceImpl.class);
@Value("${IMAGES_PATH}")
private String tPath;
@Autowired
private MQUserEmailDao mqUserEmailDao;
@Autowired
private JobMateMationService jobMateMationService;
public class MailAccessDeleteServiceImpl implements JobMateService {
@Autowired
private SystemFoundationSettingsService systemFoundationSettingsService;
private static final Logger LOGGER = LoggerFactory.getLogger(MailAccessDeleteServiceImpl.class);
@SuppressWarnings("unchecked")
@Override
public void call(String data) throws Exception {
Map<String, Object> map = JSONUtil.toBean(data, null);
String jobId = map.get("jobMateId").toString();
try {
// 任务开始
jobMateMationService.comMQJobMation(jobId, MqConstants.JOB_TYPE_IS_PROCESSING, "");
try{
//获取服务器信息
Map<String, Object> emailServer = systemFoundationSettingsService.getSystemFoundationSettings();
String storeType = emailServer.get("emailType").toString();//邮箱类型
String host = emailServer.get("emailReceiptServer").toString();//邮箱收件服务器
String username = map.get("userAddress").toString();//登录邮箱账号
String password = map.get("userPassword").toString();//密码
String basePath = tPath + "upload/emailenclosure/";//附件存储路径
@Value("${IMAGES_PATH}")
private String tPath;
Folder folder = ToolUtil.getFolderByServer(host, username, password, storeType, "Deleted Messages");
if (!folder.exists()) {//如果文件夹不存在则创建
folder.create(Folder.HOLDS_MESSAGES);
}
folder.open(Folder.READ_ONLY);
Message[] message = folder.getMessages();//获取邮件信息
ShowMail re = null;
//邮件集合
List<Map<String, Object>> beans = new ArrayList<>();
Map<String, Object> bean = null;
//附件集合
List<Map<String, Object>> enclosureBeans = new ArrayList<>();
//获取当前邮箱已有的邮件
List<Map<String, Object>> emailHasMail = mqUserEmailDao.queryDeleteEmailListByEmailFromAddress(map);
//创建目录
ToolUtil.createFolder(basePath);
//遍历邮件数据
for (int i = 0; i < message.length; i++) {
if(!message[i].getFolder().isOpen()) //判断是否open
message[i].getFolder().open(Folder.READ_ONLY); //如果close就重新open
re = new ShowMail((MimeMessage) message[i]);
//如果该邮件在本地数据库中不存在并且messageId不为空
//收件人或者抄送人或者暗送人是当前账号
if(!ToolUtil.judgeInListByMessage(emailHasMail, re.getMessageId()) && !ToolUtil.isBlank(re.getMessageId())
&& (re.getMailAddress("to").indexOf(username) > -1 || re.getMailAddress("cc").indexOf(username) > -1 || re.getMailAddress("bcc").indexOf(username) > -1)){
bean = EmailUtil.getEmailMationByUtil(re, message[i]);
String rowId = ToolUtil.getSurFaceId();
re.setDateFormat("yyyy-MM-dd HH:mm:ss");
bean.put("id", rowId);//id
bean.put("emailState", "2");//邮件状态 0.草稿 1.正常 2.已删除
re.setAttachPath(basePath);//设置附件保存基础路径
enclosureBeans.addAll(re.saveAttachMent((Part) message[i], rowId));//保存附件
beans.add(bean);
}
if(beans.size() >= 20){//每20条数据保存一次
if(!beans.isEmpty())
mqUserEmailDao.insertEmailListToServer(beans);
if(!enclosureBeans.isEmpty())
mqUserEmailDao.insertEmailEnclosureListToServer(enclosureBeans);
beans.clear();
enclosureBeans.clear();
emailHasMail = mqUserEmailDao.queryDeleteEmailListByEmailFromAddress(map);
}
}
if(!beans.isEmpty())
mqUserEmailDao.insertEmailListToServer(beans);
if(!enclosureBeans.isEmpty())
mqUserEmailDao.insertEmailEnclosureListToServer(enclosureBeans);
}finally{
}
// 任务完成
jobMateMationService.comMQJobMation(jobId, MqConstants.JOB_TYPE_IS_SUCCESS, "");
} catch (Exception e) {
LOGGER.warn("get Trash acquisition failed, reason is {}.", e);
// 任务失败
jobMateMationService.comMQJobMation(jobId, MqConstants.JOB_TYPE_IS_FAIL, "");
}
}
@Autowired
private MQUserEmailDao mqUserEmailDao;
@Autowired
private JobMateMationService jobMateMationService;
@Autowired
private SystemFoundationSettingsService systemFoundationSettingsService;
@SuppressWarnings("unchecked")
@Override
public void call(String data) throws Exception {
Map<String, Object> map = JSONUtil.toBean(data, null);
String jobId = map.get("jobMateId").toString();
try {
// 任务开始
jobMateMationService.comMQJobMation(jobId, MqConstants.JOB_TYPE_IS_PROCESSING, "");
//获取服务器信息
Map<String, Object> emailServer = systemFoundationSettingsService.getSystemFoundationSettings();
String storeType = emailServer.get("emailType").toString();//邮箱类型
String host = emailServer.get("emailReceiptServer").toString();//邮箱收件服务器
String username = map.get("userAddress").toString();//登录邮箱账号
String password = map.get("userPassword").toString();//密码
String basePath = tPath + "upload/emailenclosure/";//附件存储路径
Folder folder = ToolUtil.getFolderByServer(host, username, password, storeType, "Deleted Messages");
if (!folder.exists()) {//如果文件夹不存在则创建
folder.create(Folder.HOLDS_MESSAGES);
}
folder.open(Folder.READ_ONLY);
Message[] message = folder.getMessages();//获取邮件信息
ShowMail re = null;
//邮件集合
List<Map<String, Object>> beans = new ArrayList<>();
Map<String, Object> bean = null;
//附件集合
List<Map<String, Object>> enclosureBeans = new ArrayList<>();
//获取当前邮箱已有的邮件
List<Map<String, Object>> emailHasMail = mqUserEmailDao.queryDeleteEmailListByEmailFromAddress(map);
//创建目录
ToolUtil.createFolder(basePath);
//遍历邮件数据
for (int i = 0; i < message.length; i++) {
if (!message[i].getFolder().isOpen()) //判断是否open
message[i].getFolder().open(Folder.READ_ONLY); //如果close就重新open
re = new ShowMail((MimeMessage) message[i]);
//如果该邮件在本地数据库中不存在并且messageId不为空
//收件人或者抄送人或者暗送人是当前账号
if (!ToolUtil.judgeInListByMessage(emailHasMail, re.getMessageId()) && !ToolUtil.isBlank(re.getMessageId())
&& (re.getMailAddress("to").indexOf(username) > -1 || re.getMailAddress("cc").indexOf(username) > -1 || re.getMailAddress("bcc").indexOf(username) > -1)) {
bean = EmailUtil.getEmailMationByUtil(re, message[i]);
String rowId = ToolUtil.getSurFaceId();
re.setDateFormat(DateUtil.YYYY_MM_DD_HH_MM_SS);
bean.put("id", rowId);//id
bean.put("emailState", "2");//邮件状态 0.草稿 1.正常 2.已删除
re.setAttachPath(basePath);//设置附件保存基础路径
enclosureBeans.addAll(re.saveAttachMent((Part) message[i], rowId));//保存附件
beans.add(bean);
}
if (beans.size() >= 20) {//每20条数据保存一次
if (!beans.isEmpty()) {
mqUserEmailDao.insertEmailListToServer(beans);
}
if (!enclosureBeans.isEmpty()) {
mqUserEmailDao.insertEmailEnclosureListToServer(enclosureBeans);
}
beans.clear();
enclosureBeans.clear();
emailHasMail = mqUserEmailDao.queryDeleteEmailListByEmailFromAddress(map);
}
}
if (!beans.isEmpty()) {
mqUserEmailDao.insertEmailListToServer(beans);
}
if (!enclosureBeans.isEmpty()) {
mqUserEmailDao.insertEmailEnclosureListToServer(enclosureBeans);
}
// 任务完成
jobMateMationService.comMQJobMation(jobId, MqConstants.JOB_TYPE_IS_SUCCESS, "");
} catch (Exception e) {
LOGGER.warn("get Trash acquisition failed, reason is {}.", e);
// 任务失败
jobMateMationService.comMQJobMation(jobId, MqConstants.JOB_TYPE_IS_FAIL, "");
}
}
}

View file

@ -1,6 +1,7 @@
/*******************************************************************************
* 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;
@ -8,56 +9,56 @@ import com.skyeye.common.object.OutputObject;
public interface ScheduleDayService {
public void insertScheduleDayMation(InputObject inputObject, OutputObject outputObject) throws Exception;
public void insertScheduleDayMation(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryScheduleDayMationByUserId(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryScheduleDayMationByUserId(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryScheduleDayMationTodayByUserId(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryScheduleDayMationTodayByUserId(InputObject inputObject, OutputObject outputObject) throws Exception;
public void editScheduleDayMationById(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryScheduleDayMationById(InputObject inputObject, OutputObject outputObject) throws Exception;
public void deleteScheduleDayMationById(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryHolidayScheduleList(InputObject inputObject, OutputObject outputObject) throws Exception;
public void downloadScheduleTemplate(InputObject inputObject, OutputObject outputObject) throws Exception;
public void editScheduleDayMationById(InputObject inputObject, OutputObject outputObject) throws Exception;
public void exploreScheduleTemplate(InputObject inputObject, OutputObject outputObject) throws Exception;
public void deleteHolidayScheduleById(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryScheduleDayMationById(InputObject inputObject, OutputObject outputObject) throws Exception;
public void deleteHolidayScheduleByThisYear(InputObject inputObject, OutputObject outputObject) throws Exception;
public void deleteScheduleDayMationById(InputObject inputObject, OutputObject outputObject) throws Exception;
public void addHolidayScheduleRemind(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryHolidayScheduleList(InputObject inputObject, OutputObject outputObject) throws Exception;
public void deleteHolidayScheduleRemind(InputObject inputObject, OutputObject outputObject) throws Exception;
public void downloadScheduleTemplate(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryScheduleByIdToEdit(InputObject inputObject, OutputObject outputObject) throws Exception;
public void exploreScheduleTemplate(InputObject inputObject, OutputObject outputObject) throws Exception;
public void editScheduleById(InputObject inputObject, OutputObject outputObject) throws Exception;
public void deleteHolidayScheduleById(InputObject inputObject, OutputObject outputObject) throws Exception;
public void addSchedule(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryHolidayScheduleListBySys(InputObject inputObject, OutputObject outputObject) throws Exception;
public void deleteHolidayScheduleByThisYear(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryMyScheduleList(InputObject inputObject, OutputObject outputObject) throws Exception;
public void addHolidayScheduleRemind(InputObject inputObject, OutputObject outputObject) throws Exception;
void insertScheduleMationByOtherModule(InputObject inputObject, OutputObject outputObject) throws Exception;
public void deleteHolidayScheduleRemind(InputObject inputObject, OutputObject outputObject) throws Exception;
/**
* 将其他模块同步到日程
* 不启动日程定时任务如需启动在该接口外面自行启动
*
* @param title 标题
* @param content 日程内容
* @param startTime 开始时间,格式为yyyy-MM-dd HH:mm:ss
* @param endTime 结束时间,格式为yyyy-MM-dd HH:mm:ss
* @param userId 执行人
* @param objectId 关联id
* @param objectType object类型1.任务计划id2.项目任务id
* @throws Exception
*/
public String synchronizationSchedule(String title, String content, String startTime, String endTime, String userId, String objectId, int objectType) throws Exception;
public void queryScheduleByIdToEdit(InputObject inputObject, OutputObject outputObject) throws Exception;
public void editScheduleById(InputObject inputObject, OutputObject outputObject) throws Exception;
public void addSchedule(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryHolidayScheduleListBySys(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryMyScheduleList(InputObject inputObject, OutputObject outputObject) throws Exception;
void insertScheduleMationByOtherModule(InputObject inputObject, OutputObject outputObject) throws Exception;
/**
* 将其他模块同步到日程
* 不启动日程定时任务如需启动在该接口外面自行启动
*
* @param title 标题
* @param content 日程内容
* @param startTime 开始时间,格式为yyyy-MM-dd HH:mm:ss
* @param endTime 结束时间,格式为yyyy-MM-dd HH:mm:ss
* @param userId 执行人
* @param objectId 关联id
* @param objectType object类型1.任务计划id2.项目任务id
* @throws Exception
*/
public String synchronizationSchedule(String title, String content, String startTime, String endTime, String userId, String objectId, int objectType) throws Exception;
}

View file

@ -149,7 +149,7 @@ public class HotForumQuartz {
*/
public static ArrayList<String> pastDay(String time) throws ParseException {
ArrayList<String> pastDaysList = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.YYYY_MM_DD);
Date date = sdf.parse(time);
for (int i = 6; i >= 0; i--) {
Calendar calendar = Calendar.getInstance();