|
@@ -24,6 +24,7 @@ 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.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
@@ -152,6 +153,7 @@ public class CompanyEmailConfigServiceImpl implements CompanyEmailConfigService
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Async
|
|
|
public void sendCompanyEmail(List<Integer> idList) {
|
|
|
List<ContactInformationDO> configDOList = contactInformationService.selectByIdList(idList);
|
|
|
Map<String,List<ContactInformationDO>> companyListMap = configDOList.stream().collect(Collectors.groupingBy(e -> e.getCompanyId()));
|
|
@@ -162,9 +164,229 @@ public class CompanyEmailConfigServiceImpl implements CompanyEmailConfigService
|
|
|
emails.append(configDO.getContactEmail()).append(";");
|
|
|
}
|
|
|
//把缺失数据的邮件发送到该公司名下的邮箱地址
|
|
|
- sendEmail(companyId,emails.toString());
|
|
|
+ sendNavAssetEmail(companyId,emails.toString());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void sendNavAssetEmail(String companyId, String emails) {
|
|
|
+ List<String> fundIdList = fundInfoMapper.getFundIdByCompanyId(companyId);
|
|
|
+ List<EmailDeletionInfoDO> emailDeletionInfoDOS = new ArrayList<>();
|
|
|
+ for (String fundId : fundIdList) {
|
|
|
+ getNavNotRemarkDeletion(fundId,emailDeletionInfoDOS);
|
|
|
+ getAssetNotRemarkDeletion(fundId,emailDeletionInfoDOS);
|
|
|
+ }
|
|
|
+ if(emailDeletionInfoDOS.size() > 0){
|
|
|
+ EmailTemplateDO emailTemplateDO = emailTemplateMapper.selectByCode(DELETION_TEMPLATE_CODE);
|
|
|
+ if(emailTemplateDO == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String emailTitle = emailTemplateDO.getEmailTitle();
|
|
|
+ String emailBody = emailTemplateDO.getEmailBody().replaceAll("\r\n", "<br/>").replaceAll("\n", "<br/>");
|
|
|
+ try {
|
|
|
+ //将数据写入excel文件
|
|
|
+ File file = writeExcelFile(emailDeletionInfoDOS);
|
|
|
+ file.setWritable(true);
|
|
|
+ file.setReadable(true);
|
|
|
+ file.setExecutable(true);
|
|
|
+ MailboxInfoDTO dto = getFromEmailInfo();
|
|
|
+ try{
|
|
|
+ EmailUtil.senEmail(dto,emails,List.of(file),emailBody,sysConfigMapper.selectConfigByKey("email.host")==null?"":sysConfigMapper.selectConfigByKey("email.host"),emailTitle);
|
|
|
+ }catch (Exception e){
|
|
|
+ //有些是因为被识别为垃圾邮件导致的报错,需要在发送一次
|
|
|
+ logger.error(e.getMessage(),e);
|
|
|
+ EmailUtil.senEmail(dto,emails,List.of(file),emailBody,sysConfigMapper.selectConfigByKey("email.host")==null?"":sysConfigMapper.selectConfigByKey("email.host"),emailTitle);
|
|
|
+ }
|
|
|
+ //发送成功之后修改数据为已发送
|
|
|
+ deletionInfoMapper.updateSendStatusByFundId(fundIdList);
|
|
|
+ //写入发送历史
|
|
|
+ String[] emailList = emails.split(";");
|
|
|
+ for(String email : emailList){
|
|
|
+ saveCompanyEmailSendHistory(companyId,email,emailTitle,1,ResultCode.SEND_SUCCESS.getMsg());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ String[] emailList = emails.split(";");
|
|
|
+ for(String email : emailList){
|
|
|
+ saveCompanyEmailSendHistory(companyId,email,emailTitle,0,e.getMessage());
|
|
|
+ }
|
|
|
+ logger.error(e.getMessage(),e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getAssetNotRemarkDeletion(String fundId, List<EmailDeletionInfoDO> emailDeletionInfoDOS) {
|
|
|
+ List<EmailDeletionInfoDO> fundEmailDeletionInfoDOList = deletionInfoMapper.selectAssetNotRemarkDeletionInfoByFundId(fundId);
|
|
|
+ if(fundEmailDeletionInfoDOList.isEmpty()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ fundEmailDeletionInfoDOList = fundEmailDeletionInfoDOList.stream().filter(e -> e.getChannelId() != null).collect(Collectors.toList());
|
|
|
+ Map<Integer, List<EmailDeletionInfoDO>> channelDeletionMap = fundEmailDeletionInfoDOList.stream().collect(Collectors.groupingBy(EmailDeletionInfoDO::getChannelId));
|
|
|
+ FundReportFrequencyDO fundReportFrequencyDO = fundReportFrequencyMapper.getFrequencyByFundId(fundId);
|
|
|
+ if(fundReportFrequencyDO == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (Integer channelId : channelDeletionMap.keySet()) {
|
|
|
+ List<EmailDeletionInfoDO> channelEmailDeletionInfoDOList = channelDeletionMap.get(channelId);
|
|
|
+ if(channelEmailDeletionInfoDOList.isEmpty()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //根据渠道ID和基金ID去查最新的净值日期
|
|
|
+ Date priceDate = assetMapper.selectMaxPriceDate(channelId,fundId);
|
|
|
+ if(priceDate == null){
|
|
|
+ FundInfoDO fundInformationDO = fundInfoMapper.searchFundDetail(fundId);
|
|
|
+ if(fundInformationDO != null && fundInformationDO.getInceptionDate() == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ priceDate = DateUtils.parse(fundInformationDO.getInceptionDate(),"yyyy-MM-dd");
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.error(e.getMessage(),e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(Frequency.DAY.getCode().equals(fundReportFrequencyDO.getAssetFrequency())){
|
|
|
+ List<DeletionTaskLogInfoDO> deletionTaskLogInfoDOList = deletionTaskLogInfoMapper.selectDeletionTaskLogInfoDO(fundId,channelId,fundReportFrequencyDO.getNavFrequency(),DateUtils.format(priceDate,"yyyy-MM-dd"),DeletionType.NAV_DELETION.getCode());
|
|
|
+ //最新净值不再更新,超过五次就不再发送
|
|
|
+ if(deletionTaskLogInfoDOList.size() >= 5){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ DeletionTaskLogInfoDO deletionTaskLogInfoDO = new DeletionTaskLogInfoDO();
|
|
|
+ deletionTaskLogInfoDO.setChannelId(channelId);
|
|
|
+ deletionTaskLogInfoDO.setFundId(fundId);
|
|
|
+ deletionTaskLogInfoDO.setIsvalid(1);
|
|
|
+ deletionTaskLogInfoDO.setCreateTime(new Date());
|
|
|
+ deletionTaskLogInfoDO.setUpdateTime(new Date());
|
|
|
+ deletionTaskLogInfoDO.setPriceDate(DateUtils.format(priceDate,"yyyy-MM-dd"));
|
|
|
+ deletionTaskLogInfoDO.setFrequency(fundReportFrequencyDO.getNavFrequency());
|
|
|
+ deletionTaskLogInfoDO.setDeletionType(DeletionType.ASSET_DELETION.getCode());
|
|
|
+ deletionTaskLogInfoMapper.saveDeletionTaskLogInfoDO(deletionTaskLogInfoDO);
|
|
|
+ }
|
|
|
+ if(Frequency.WEEK.getCode().equals(fundReportFrequencyDO.getAssetFrequency())){
|
|
|
+ List<DeletionTaskLogInfoDO> deletionTaskLogInfoDOList = deletionTaskLogInfoMapper.selectDeletionTaskLogInfoDO(fundId,channelId,fundReportFrequencyDO.getNavFrequency(),DateUtils.format(priceDate,"yyyy-MM-dd"),DeletionType.NAV_DELETION.getCode());
|
|
|
+ //最新净值不再更新,超过3次就不再发送
|
|
|
+ if(deletionTaskLogInfoDOList.size() >= 3){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ DeletionTaskLogInfoDO deletionTaskLogInfoDO = new DeletionTaskLogInfoDO();
|
|
|
+ deletionTaskLogInfoDO.setChannelId(channelId);
|
|
|
+ deletionTaskLogInfoDO.setFundId(fundId);
|
|
|
+ deletionTaskLogInfoDO.setIsvalid(1);
|
|
|
+ deletionTaskLogInfoDO.setCreateTime(new Date());
|
|
|
+ deletionTaskLogInfoDO.setUpdateTime(new Date());
|
|
|
+ deletionTaskLogInfoDO.setPriceDate(DateUtils.format(priceDate,"yyyy-MM-dd"));
|
|
|
+ deletionTaskLogInfoDO.setFrequency(fundReportFrequencyDO.getNavFrequency());
|
|
|
+ deletionTaskLogInfoDO.setDeletionType(DeletionType.ASSET_DELETION.getCode());
|
|
|
+ deletionTaskLogInfoMapper.saveDeletionTaskLogInfoDO(deletionTaskLogInfoDO);
|
|
|
+ }
|
|
|
+ if(Frequency.MONTH.getCode().equals(fundReportFrequencyDO.getAssetFrequency())){
|
|
|
+ List<DeletionTaskLogInfoDO> deletionTaskLogInfoDOList = deletionTaskLogInfoMapper.selectDeletionTaskLogInfoDO(fundId,channelId,fundReportFrequencyDO.getNavFrequency(),DateUtils.format(priceDate,"yyyy-MM-dd"),DeletionType.NAV_DELETION.getCode());
|
|
|
+ //最新净值不再更新,超过1次就不再发送
|
|
|
+ if(deletionTaskLogInfoDOList.size() >= 1){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ DeletionTaskLogInfoDO deletionTaskLogInfoDO = new DeletionTaskLogInfoDO();
|
|
|
+ deletionTaskLogInfoDO.setChannelId(channelId);
|
|
|
+ deletionTaskLogInfoDO.setFundId(fundId);
|
|
|
+ deletionTaskLogInfoDO.setIsvalid(1);
|
|
|
+ deletionTaskLogInfoDO.setCreateTime(new Date());
|
|
|
+ deletionTaskLogInfoDO.setUpdateTime(new Date());
|
|
|
+ deletionTaskLogInfoDO.setPriceDate(DateUtils.format(priceDate,"yyyy-MM-dd"));
|
|
|
+ deletionTaskLogInfoDO.setFrequency(fundReportFrequencyDO.getNavFrequency());
|
|
|
+ deletionTaskLogInfoDO.setDeletionType(DeletionType.ASSET_DELETION.getCode());
|
|
|
+ deletionTaskLogInfoMapper.saveDeletionTaskLogInfoDO(deletionTaskLogInfoDO);
|
|
|
+ }
|
|
|
+ for(EmailDeletionInfoDO infoDO : channelEmailDeletionInfoDOList){
|
|
|
+ infoDO.setDeletionType(DeletionType.getDeletionTypeByCode(Integer.valueOf(infoDO.getDeletionType())).getInfo());
|
|
|
+ }
|
|
|
+ emailDeletionInfoDOS.addAll(channelEmailDeletionInfoDOList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getNavNotRemarkDeletion(String fundId, List<EmailDeletionInfoDO> emailDeletionInfoDOS) {
|
|
|
+ List<EmailDeletionInfoDO> fundEmailDeletionInfoDOList = deletionInfoMapper.selectNavNotRemarkDeletionInfoByFundId(fundId);
|
|
|
+ if(fundEmailDeletionInfoDOList.isEmpty()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ fundEmailDeletionInfoDOList = fundEmailDeletionInfoDOList.stream().filter(e -> e.getChannelId() != null).collect(Collectors.toList());
|
|
|
+ Map<Integer, List<EmailDeletionInfoDO>> channelDeletionMap = fundEmailDeletionInfoDOList.stream().collect(Collectors.groupingBy(EmailDeletionInfoDO::getChannelId));
|
|
|
+ FundReportFrequencyDO fundReportFrequencyDO = fundReportFrequencyMapper.getFrequencyByFundId(fundId);
|
|
|
+ if(fundReportFrequencyDO == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (Integer channelId : channelDeletionMap.keySet()) {
|
|
|
+ List<EmailDeletionInfoDO> channelEmailDeletionInfoDOList = channelDeletionMap.get(channelId);
|
|
|
+ if(channelEmailDeletionInfoDOList.isEmpty()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //根据渠道ID和基金ID去查最新的净值日期
|
|
|
+ Date priceDate = navMapper.selectMaxPriceDate(channelId,fundId);
|
|
|
+ if(priceDate == null){
|
|
|
+ FundInfoDO fundInformationDO = fundInfoMapper.searchFundDetail(fundId);
|
|
|
+ if(fundInformationDO != null && fundInformationDO.getInceptionDate() == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ priceDate = DateUtils.parse(fundInformationDO.getInceptionDate(),"yyyy-MM-dd");
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.error(e.getMessage(),e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(Frequency.DAY.getCode().equals(fundReportFrequencyDO.getNavFrequency())){
|
|
|
+ List<DeletionTaskLogInfoDO> deletionTaskLogInfoDOList = deletionTaskLogInfoMapper.selectDeletionTaskLogInfoDO(fundId,channelId,fundReportFrequencyDO.getNavFrequency(),DateUtils.format(priceDate,"yyyy-MM-dd"),DeletionType.NAV_DELETION.getCode());
|
|
|
+ //最新净值不再更新,超过五次就不再发送
|
|
|
+ if(deletionTaskLogInfoDOList.size() >= 5){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ DeletionTaskLogInfoDO deletionTaskLogInfoDO = new DeletionTaskLogInfoDO();
|
|
|
+ deletionTaskLogInfoDO.setChannelId(channelId);
|
|
|
+ deletionTaskLogInfoDO.setFundId(fundId);
|
|
|
+ deletionTaskLogInfoDO.setIsvalid(1);
|
|
|
+ deletionTaskLogInfoDO.setCreateTime(new Date());
|
|
|
+ deletionTaskLogInfoDO.setUpdateTime(new Date());
|
|
|
+ deletionTaskLogInfoDO.setPriceDate(DateUtils.format(priceDate,"yyyy-MM-dd"));
|
|
|
+ deletionTaskLogInfoDO.setFrequency(fundReportFrequencyDO.getNavFrequency());
|
|
|
+ deletionTaskLogInfoDO.setDeletionType(DeletionType.NAV_DELETION.getCode());
|
|
|
+ deletionTaskLogInfoMapper.saveDeletionTaskLogInfoDO(deletionTaskLogInfoDO);
|
|
|
+ }
|
|
|
+ if(Frequency.WEEK.getCode().equals(fundReportFrequencyDO.getNavFrequency())){
|
|
|
+ List<DeletionTaskLogInfoDO> deletionTaskLogInfoDOList = deletionTaskLogInfoMapper.selectDeletionTaskLogInfoDO(fundId,channelId,fundReportFrequencyDO.getNavFrequency(),DateUtils.format(priceDate,"yyyy-MM-dd"),DeletionType.NAV_DELETION.getCode());
|
|
|
+ //最新净值不再更新,超过3次就不再发送
|
|
|
+ if(deletionTaskLogInfoDOList.size() >= 3){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ DeletionTaskLogInfoDO deletionTaskLogInfoDO = new DeletionTaskLogInfoDO();
|
|
|
+ deletionTaskLogInfoDO.setChannelId(channelId);
|
|
|
+ deletionTaskLogInfoDO.setFundId(fundId);
|
|
|
+ deletionTaskLogInfoDO.setIsvalid(1);
|
|
|
+ deletionTaskLogInfoDO.setCreateTime(new Date());
|
|
|
+ deletionTaskLogInfoDO.setUpdateTime(new Date());
|
|
|
+ deletionTaskLogInfoDO.setPriceDate(DateUtils.format(priceDate,"yyyy-MM-dd"));
|
|
|
+ deletionTaskLogInfoDO.setFrequency(fundReportFrequencyDO.getNavFrequency());
|
|
|
+ deletionTaskLogInfoDO.setDeletionType(DeletionType.NAV_DELETION.getCode());
|
|
|
+ deletionTaskLogInfoMapper.saveDeletionTaskLogInfoDO(deletionTaskLogInfoDO);
|
|
|
+ }
|
|
|
+ if(Frequency.MONTH.getCode().equals(fundReportFrequencyDO.getNavFrequency())){
|
|
|
+ List<DeletionTaskLogInfoDO> deletionTaskLogInfoDOList = deletionTaskLogInfoMapper.selectDeletionTaskLogInfoDO(fundId,channelId,fundReportFrequencyDO.getNavFrequency(),DateUtils.format(priceDate,"yyyy-MM-dd"),DeletionType.NAV_DELETION.getCode());
|
|
|
+ //最新净值不再更新,超过1次就不再发送
|
|
|
+ if(deletionTaskLogInfoDOList.size() >= 1){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ DeletionTaskLogInfoDO deletionTaskLogInfoDO = new DeletionTaskLogInfoDO();
|
|
|
+ deletionTaskLogInfoDO.setChannelId(channelId);
|
|
|
+ deletionTaskLogInfoDO.setFundId(fundId);
|
|
|
+ deletionTaskLogInfoDO.setIsvalid(1);
|
|
|
+ deletionTaskLogInfoDO.setCreateTime(new Date());
|
|
|
+ deletionTaskLogInfoDO.setUpdateTime(new Date());
|
|
|
+ deletionTaskLogInfoDO.setPriceDate(DateUtils.format(priceDate,"yyyy-MM-dd"));
|
|
|
+ deletionTaskLogInfoDO.setFrequency(fundReportFrequencyDO.getNavFrequency());
|
|
|
+ deletionTaskLogInfoDO.setDeletionType(DeletionType.NAV_DELETION.getCode());
|
|
|
+ deletionTaskLogInfoMapper.saveDeletionTaskLogInfoDO(deletionTaskLogInfoDO);
|
|
|
+ }
|
|
|
+ for(EmailDeletionInfoDO infoDO : channelEmailDeletionInfoDOList){
|
|
|
+ infoDO.setDeletionType(DeletionType.getDeletionTypeByCode(Integer.valueOf(infoDO.getDeletionType())).getInfo());
|
|
|
+ }
|
|
|
+ emailDeletionInfoDOS.addAll(channelEmailDeletionInfoDOList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
//邮件校验处理
|
|
|
public void sendEmail(String companyId, String emails) {
|
|
@@ -466,7 +688,57 @@ public class CompanyEmailConfigServiceImpl implements CompanyEmailConfigService
|
|
|
emails.append(configDO.getContactEmail()).append(";");
|
|
|
}
|
|
|
//把缺失数据的邮件发送到该公司名下的邮箱地址
|
|
|
- sendDistributeEmail(companyId,emails.toString());
|
|
|
+ sendDistributeNotRemarkEmail(companyId,emails.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendDistributeNotRemarkEmail(String companyId, String emails) {
|
|
|
+ List<String> fundIdList = fundInfoMapper.getFundIdByCompanyId(companyId);
|
|
|
+ List<EmailDeletionInfoDO> emailDeletionInfoDOS = new ArrayList<>();
|
|
|
+ for (String fundId : fundIdList) {
|
|
|
+ List<EmailDeletionInfoDO> distributeDeletionList = deletionInfoMapper.selectDistributeDeletionInfoByFundId(fundId);
|
|
|
+ if(distributeDeletionList.isEmpty()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for(EmailDeletionInfoDO infoDO : distributeDeletionList){
|
|
|
+ infoDO.setDeletionType(DeletionType.getDeletionTypeByCode(Integer.valueOf(infoDO.getDeletionType())).getInfo());
|
|
|
+ }
|
|
|
+ emailDeletionInfoDOS.addAll(distributeDeletionList);
|
|
|
+ }
|
|
|
+ if(emailDeletionInfoDOS.size() > 0){
|
|
|
+ EmailTemplateDO emailTemplateDO = emailTemplateMapper.selectByCode(DISTRIBUTION_DELETION_TEMPLATE_CODE);
|
|
|
+ if(emailTemplateDO == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String emailTitle = emailTemplateDO.getEmailTitle();
|
|
|
+ String emailBody = emailTemplateDO.getEmailBody().replaceAll("\r\n", "<br/>").replaceAll("\n", "<br/>");
|
|
|
+ try {
|
|
|
+ //将数据写入excel文件
|
|
|
+ File file = writeExcelFile(emailDeletionInfoDOS);
|
|
|
+ file.setWritable(true);
|
|
|
+ file.setReadable(true);
|
|
|
+ file.setExecutable(true);
|
|
|
+ MailboxInfoDTO dto = getFromEmailInfo();
|
|
|
+ try{
|
|
|
+ EmailUtil.senEmail(dto,emails,List.of(file),emailBody,sysConfigMapper.selectConfigByKey("email.host")==null?"":sysConfigMapper.selectConfigByKey("email.host"),emailTitle);
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.error(e.getMessage(),e);
|
|
|
+ EmailUtil.senEmail(dto,emails,List.of(file),emailBody,sysConfigMapper.selectConfigByKey("email.host")==null?"":sysConfigMapper.selectConfigByKey("email.host"),emailTitle);
|
|
|
+ }
|
|
|
+ //发送成功之后修改数据为已发送
|
|
|
+ deletionInfoMapper.updateSendStatusByFundId(fundIdList);
|
|
|
+ //写入发送历史
|
|
|
+ String[] emailList = emails.split(";");
|
|
|
+ for(String email : emailList){
|
|
|
+ saveCompanyEmailSendHistory(companyId,email,emailTitle,1,ResultCode.SEND_SUCCESS.getMsg());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ String[] emailList = emails.split(";");
|
|
|
+ for(String email : emailList){
|
|
|
+ saveCompanyEmailSendHistory(companyId,email,emailTitle,0,e.getMessage());
|
|
|
+ }
|
|
|
+ logger.error(e.getMessage(),e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|