|
|
|
|
@ -1,18 +1,31 @@
|
|
|
|
|
package com.biutag.lan.job; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.hutool.crypto.digest.MD5; |
|
|
|
|
import cn.hutool.http.HttpResponse; |
|
|
|
|
import cn.hutool.http.HttpUtil; |
|
|
|
|
import com.alibaba.fastjson2.JSON; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
|
import com.biutag.constants.AppConstants; |
|
|
|
|
import com.biutag.enums.MailState; |
|
|
|
|
import com.biutag.lan.domain.DeptMapping; |
|
|
|
|
import com.biutag.lan.domain.Mail; |
|
|
|
|
import com.biutag.lan.domain.MailApproval; |
|
|
|
|
import com.biutag.lan.domain.MailFlow; |
|
|
|
|
import com.biutag.lan.domain.vo.MailDomain; |
|
|
|
|
import com.biutag.lan.mapper.DeptMappingMapper; |
|
|
|
|
import com.biutag.lan.service.MailApprovalService; |
|
|
|
|
import com.biutag.lan.service.MailFlowService; |
|
|
|
|
import com.biutag.lan.service.MailService; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -27,6 +40,17 @@ public class MailboxJob {
|
|
|
|
|
|
|
|
|
|
private final MailService mailService; |
|
|
|
|
|
|
|
|
|
private final MailFlowService mailFlowService; |
|
|
|
|
|
|
|
|
|
private final MailApprovalService mailApprovalService; |
|
|
|
|
|
|
|
|
|
private final DeptMappingMapper deptMappingMapper; |
|
|
|
|
|
|
|
|
|
private final String key = "mailbox"; |
|
|
|
|
|
|
|
|
|
@Value("mailbox.url:''") |
|
|
|
|
private String mailboxUrl; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 每30分钟执行一次 |
|
|
|
|
*/ |
|
|
|
|
@ -35,10 +59,92 @@ public class MailboxJob {
|
|
|
|
|
List<Mail> mails = mailService.list(new LambdaQueryWrapper<Mail>() |
|
|
|
|
.eq(Mail::getFirstDeptId, AppConstants.CHANGSHA_DEPT_ID) |
|
|
|
|
.in(Mail::getMailState, List.of(MailState.processing.getValue(), MailState.delayed.getValue()))); |
|
|
|
|
List<String> mailIds = mails.stream().map(Mail::getId).toList(); |
|
|
|
|
HttpResponse httpResponse = HttpUtil.createGet("") |
|
|
|
|
.execute(); |
|
|
|
|
|
|
|
|
|
long timestamp = new Date().getTime(); |
|
|
|
|
for (Mail mail : mails) { |
|
|
|
|
HttpResponse httpResponse = HttpUtil.createGet(mailboxUrl + "/v1/mail/detail?mailId=" + mail.getId()) |
|
|
|
|
.header("timestamp", String.valueOf(timestamp)) |
|
|
|
|
.auth(MD5.create().digestHex(key + timestamp)) |
|
|
|
|
.execute(); |
|
|
|
|
MailDomain mailDomain = JSON.parseObject(httpResponse.body(), MailDomain.class); |
|
|
|
|
LambdaUpdateWrapper<Mail> updateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
Mail source = mailDomain.getMail(); |
|
|
|
|
updateWrapper.eq(Mail::getId, mail.getId()) |
|
|
|
|
.set(Mail::getUpdateTime, source.getUpdateTime()) |
|
|
|
|
.set(Mail::getSatisfactionSms, source.getSatisfactionSms()) |
|
|
|
|
.set(Mail::getMailState, source.getMailState()) |
|
|
|
|
.set(Mail::getFlowKey, source.getFlowKey()) |
|
|
|
|
.set(Mail::getFlowName, source.getFlowName()) |
|
|
|
|
.set(Mail::getFlowLimitedLastHandlerTime, source.getFlowLimitedLastHandlerTime()) |
|
|
|
|
.set(Mail::getMailCategory, source.getMailCategory()) |
|
|
|
|
.set(Mail::getMailFirstCategory, source.getMailFirstCategory()) |
|
|
|
|
.set(Mail::getMailSecondCategory, source.getMailSecondCategory()) |
|
|
|
|
.set(Mail::getMailThreeCategory, source.getMailThreeCategory()) |
|
|
|
|
.set(Mail::getMailLevel, source.getMailLevel()) |
|
|
|
|
.set(Mail::getContactPoliceName, source.getContactPoliceName()) |
|
|
|
|
.set(Mail::getContactPoliceEmpNo, source.getContactPoliceEmpNo()) |
|
|
|
|
.set(Mail::getContactTime, source.getContactTime()) |
|
|
|
|
.set(Mail::getContactDuration, source.getContactDuration()) |
|
|
|
|
.set(Mail::getContactFlag, source.getContactFlag()) |
|
|
|
|
.set(Mail::getInterviewType, source.getInterviewType()) |
|
|
|
|
.set(Mail::getInterviewIsLeader, source.getInterviewIsLeader()) |
|
|
|
|
.set(Mail::getInterviewPoliceEmpNo, source.getInterviewPoliceEmpNo()) |
|
|
|
|
.set(Mail::getInterviewPoliceName, source.getInterviewPoliceName()) |
|
|
|
|
.set(Mail::getInterviewDetails, source.getInterviewDetails()) |
|
|
|
|
.set(Mail::getInterviewAttachments, source.getInterviewAttachments()) |
|
|
|
|
.set(Mail::getVerifyDetails, source.getVerifyDetails()) |
|
|
|
|
.set(Mail::getVerifyIsTrue, source.getVerifyIsTrue()) |
|
|
|
|
.set(Mail::getVerifyNeedAccountability, source.getVerifyNeedAccountability()) |
|
|
|
|
.set(Mail::getVerifyIsResolved, source.getVerifyIsResolved()) |
|
|
|
|
.set(Mail::getVerifyFeedback, source.getVerifyFeedback()) |
|
|
|
|
.set(Mail::getVerifyFollowupPolice, source.getVerifyFollowupPolice()) |
|
|
|
|
.set(Mail::getVerifyAttachments, source.getVerifyAttachments()) |
|
|
|
|
.set(Mail::getCompleteMethod, source.getCompleteMethod()) |
|
|
|
|
.set(Mail::getQualifiedProcessingStatus, source.getQualifiedProcessingStatus()) |
|
|
|
|
.set(Mail::getProblemSolvingStatus, source.getProblemSolvingStatus()) |
|
|
|
|
.set(Mail::getSatisfactionStatus, source.getSatisfactionStatus()) |
|
|
|
|
.set(Mail::getCompletionComment, source.getCompletionComment()) |
|
|
|
|
.set(Mail::getSimpleFlowFlag, source.getSimpleFlowFlag()) |
|
|
|
|
.set(Mail::getCurrentOperator, source.getCurrentOperator()) |
|
|
|
|
.set(Mail::getExtensionFlag, source.getExtensionFlag()) |
|
|
|
|
.set(Mail::getExtensionDays, source.getExtensionDays()) |
|
|
|
|
.set(Mail::getExtensionReason, source.getExtensionReason()) |
|
|
|
|
.set(Mail::getExtensionState, source.getExtensionState()) |
|
|
|
|
.set(Mail::getMainDeptLevel, source.getMainDeptLevel()) |
|
|
|
|
.set(Mail::getNotSatisfiedReason, source.getNotSatisfiedReason()); |
|
|
|
|
if (StrUtil.isNotBlank(source.getSecondDeptId())) { |
|
|
|
|
List<DeptMapping> deptMappings = deptMappingMapper.selectList(new LambdaQueryWrapper<DeptMapping>().eq(DeptMapping::getExternalId, source.getSecondDeptId())); |
|
|
|
|
if (!deptMappings.isEmpty()) { |
|
|
|
|
updateWrapper.set(Mail::getSecondDeptId, deptMappings.get(0).getInternalId()) |
|
|
|
|
.set(Mail::getSecondDeptName, deptMappings.get(0).getInternalName()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (StrUtil.isNotBlank(source.getThreeDeptId())) { |
|
|
|
|
List<DeptMapping> deptMappings = deptMappingMapper.selectList(new LambdaQueryWrapper<DeptMapping>().eq(DeptMapping::getExternalId, source.getThreeDeptId())); |
|
|
|
|
if (!deptMappings.isEmpty()) { |
|
|
|
|
updateWrapper.set(Mail::getThreeDeptId, deptMappings.get(0).getInternalId()) |
|
|
|
|
.set(Mail::getThreeDeptName, deptMappings.get(0).getInternalName()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
mailService.update(updateWrapper); |
|
|
|
|
if (!mailDomain.getFlows().isEmpty()) { |
|
|
|
|
for (MailFlow flow : mailDomain.getFlows()) { |
|
|
|
|
if (mailFlowService.exists(new LambdaQueryWrapper<MailFlow>().eq(MailFlow::getMailId, mail.getId()).eq(MailFlow::getCreateTime, flow.getCreateTime()))) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
flow.setId(null); |
|
|
|
|
mailFlowService.save(flow); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!mailDomain.getApprovals().isEmpty()) { |
|
|
|
|
for (MailApproval approval : mailDomain.getApprovals()) { |
|
|
|
|
if (mailApprovalService.exists(new LambdaQueryWrapper<MailApproval>().eq(MailApproval::getMailId, mail.getId()).eq(MailApproval::getCreateTime, approval.getCreateTime()))) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
approval.setId(null); |
|
|
|
|
mailApprovalService.save(approval); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|