|
@@ -4,15 +4,24 @@ import com.github.junrar.unpack.decode.LitDecode;
|
|
|
import com.simuwang.base.common.enums.Frequency;
|
|
|
import com.simuwang.base.common.enums.TaskType;
|
|
|
import com.simuwang.base.common.util.DateUtils;
|
|
|
+import com.simuwang.base.common.util.EmailUtil;
|
|
|
+import com.simuwang.base.common.util.ExcelUtil;
|
|
|
+import com.simuwang.base.common.util.StringUtil;
|
|
|
import com.simuwang.base.mapper.daq.*;
|
|
|
+import com.simuwang.base.mapper.daq.system.SysConfigMapper;
|
|
|
import com.simuwang.base.pojo.dos.*;
|
|
|
+import com.simuwang.base.pojo.dto.MailboxInfoDTO;
|
|
|
import com.simuwang.shiro.utils.UserUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
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.Component;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* FileName: NavFrequencyComputeTask
|
|
@@ -29,7 +38,13 @@ public class ParseEmailFailTask {
|
|
|
private EmailParseInfoMapper emailParseInfoMapper;
|
|
|
@Autowired
|
|
|
private ChannelMapper channelMapper;
|
|
|
+ @Autowired
|
|
|
+ private ChannelResponbilityMapper channelResponbilityMapper;
|
|
|
|
|
|
+ @Value("${email.file.path}")
|
|
|
+ private String path;
|
|
|
+ @Autowired
|
|
|
+ private SysConfigMapper sysConfigMapper;
|
|
|
/**
|
|
|
* 取近一月(35天)净值数量判断
|
|
|
* 净值数 >= 8, 设置为“日频”
|
|
@@ -44,11 +59,86 @@ public class ParseEmailFailTask {
|
|
|
String parseDate = DateUtils.getAroundToday(-1);
|
|
|
for (ChannelInfoDO channelInfoDO : channelInfoDOList) {
|
|
|
String email = emailTaskInfoDO.getEmail();
|
|
|
+ Integer channelId = channelInfoDO.getId();
|
|
|
List<EmailParseInfoDO> emailParseInfoDOList = emailParseInfoMapper.selectListByParseDate(email,parseDate);
|
|
|
+ if(!emailParseInfoDOList.isEmpty()){
|
|
|
+ ChannelResponsibilityInfoDO param = new ChannelResponsibilityInfoDO();
|
|
|
+ param.setChannelId(channelId);
|
|
|
+ ChannelResponsibilityInfoDO channelResponsibilityInfoDO = channelResponbilityMapper.select(param);
|
|
|
+ if(channelResponsibilityInfoDO==null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ sendEmail(emailParseInfoDOList,channelResponsibilityInfoDO.getEmail());
|
|
|
+ }
|
|
|
}
|
|
|
endEmailTask(emailTaskInfoDO.getId(),2);
|
|
|
}
|
|
|
|
|
|
+ private void sendEmail(List<EmailParseInfoDO> emailParseInfoDOList, String email) {
|
|
|
+ File fundBaseInfoFile = writeExcelFile(emailParseInfoDOList);
|
|
|
+ fundBaseInfoFile.setWritable(true);
|
|
|
+ fundBaseInfoFile.setReadable(true);
|
|
|
+ fundBaseInfoFile.setExecutable(true);
|
|
|
+ MailboxInfoDTO dto = getFromEmailInfo();
|
|
|
+ String htmlText = sysConfigMapper.selectConfigByKey("parse_fail_email_body");
|
|
|
+ String emailTitle = sysConfigMapper.selectConfigByKey("parse_fail_email_title");
|
|
|
+ List<File> fileList = new ArrayList<>();
|
|
|
+ fileList.add(fundBaseInfoFile);
|
|
|
+ try {
|
|
|
+ EmailUtil.senEmail(dto,email,fileList,htmlText,sysConfigMapper.selectConfigByKey("email.host")==null?"":sysConfigMapper.selectConfigByKey("email.host"),emailTitle);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(),e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ private MailboxInfoDTO getFromEmailInfo(){
|
|
|
+ MailboxInfoDTO dto = new MailboxInfoDTO();
|
|
|
+ dto.setAccount(sysConfigMapper.selectConfigByKey("sender.email"));
|
|
|
+ dto.setProtocol(sysConfigMapper.selectConfigByKey("sender.protocol"));
|
|
|
+ dto.setPassword(sysConfigMapper.selectConfigByKey("sender.password"));
|
|
|
+ dto.setPort(sysConfigMapper.selectConfigByKey("sender.port"));
|
|
|
+ dto.setHost(sysConfigMapper.selectConfigByKey("sender.host"));
|
|
|
+ dto.setSsl(sysConfigMapper.selectConfigByKey("sender.ssl"));
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+ private File writeExcelFile(List<EmailParseInfoDO> emailParseInfoDOList) {
|
|
|
+ Map<String,List<List<String>>> values = new HashMap<>();
|
|
|
+ List<String> head = new ArrayList<>();
|
|
|
+ head.add("邮件ID");
|
|
|
+ head.add("发件邮箱");
|
|
|
+ head.add("接收邮箱");
|
|
|
+ head.add("邮件标题");
|
|
|
+ head.add("失败原因");
|
|
|
+ String sheetName = "缺失产品清单";
|
|
|
+ List<List<String>> dataList = new ArrayList<>();
|
|
|
+ for(EmailParseInfoDO dto : emailParseInfoDOList){
|
|
|
+ List<String> data = new ArrayList<>();
|
|
|
+ data.add(String.valueOf(dto.getId()));
|
|
|
+ data.add(dto.getSenderEmail());
|
|
|
+ data.add(dto.getEmail());
|
|
|
+ data.add(dto.getEmailTitle());
|
|
|
+ data.add(dto.getEmailTitle());
|
|
|
+ dataList.add(data);
|
|
|
+ }
|
|
|
+ values.put(sheetName,dataList);
|
|
|
+ HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook(sheetName,head,values,null);
|
|
|
+ File file = new File(path+"/"+DateUtils.format(new Date(),DateUtils.YYYYMMDDHHMMSS)+"缺失产品清单.xls");
|
|
|
+ if(!file.exists()){
|
|
|
+ try {
|
|
|
+ file.createNewFile();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ wb.write(file);
|
|
|
+ wb.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return file;
|
|
|
+ }
|
|
|
+
|
|
|
private EmailTaskInfoDO startEmailTask(String email,Integer taskStatus) {
|
|
|
EmailTaskInfoDO emailTaskInfoDO = new EmailTaskInfoDO();
|
|
|
try{
|