|
|
@ -34,16 +34,31 @@ import com.aspose.words.Document; |
|
|
|
|
|
|
|
|
import com.aspose.cells.Workbook; |
|
|
import com.aspose.cells.Workbook; |
|
|
|
|
|
|
|
|
|
|
|
import com.xujie.sys.modules.ecss.mapper.CoDelMapper; |
|
|
|
|
|
import com.xujie.sys.modules.ecss.data.EcssCoDelNotifyHeaderData; |
|
|
|
|
|
import com.xujie.sys.modules.pms.mapper.QcMapper; |
|
|
|
|
|
import com.xujie.sys.modules.pms.data.MailSendAddressData; |
|
|
|
|
|
import com.xujie.sys.modules.pms.data.SendMailRecord; |
|
|
|
|
|
import com.xujie.sys.modules.sys.entity.SysUserEntity; |
|
|
|
|
|
import com.xujie.sys.common.utils.MailUtil; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service("sysOssService") |
|
|
@Service("sysOssService") |
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
public class SysOssServiceImpl extends ServiceImpl<SysOssDao, SysOssEntity> implements SysOssService { |
|
|
public class SysOssServiceImpl extends ServiceImpl<SysOssDao, SysOssEntity> implements SysOssService { |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private SysOssDao sysOssDao; |
|
|
private SysOssDao sysOssDao; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private CoDelMapper coDelMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private QcMapper qcMapper; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public PageUtils queryPage(Map<String, Object> params) { |
|
|
public PageUtils queryPage(Map<String, Object> params) { |
|
|
String fileName = (String)params.get("fileName"); |
|
|
String fileName = (String)params.get("fileName"); |
|
|
@ -124,6 +139,17 @@ public class SysOssServiceImpl extends ServiceImpl<SysOssDao, SysOssEntity> impl |
|
|
oss.setOrderReftype("询价文档"); |
|
|
oss.setOrderReftype("询价文档"); |
|
|
this.save(oss); |
|
|
this.save(oss); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果是确认页面上传的文档(orderRef6=2),发送邮件给发货通知单创建人 |
|
|
|
|
|
if ("2".equals(oss.getOrderRef6()) && StringUtils.isNotBlank(oss.getOrderRef1()) |
|
|
|
|
|
&& StringUtils.isNotBlank(oss.getOrderRef2())) { |
|
|
|
|
|
try { |
|
|
|
|
|
sendDocumentUploadNotification(oss); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("发送文档上传通知邮件失败: {}", e.getMessage(), e); |
|
|
|
|
|
// 邮件发送失败不影响文件上传,只记录日志 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
@Override |
|
|
@Override |
|
|
@Transactional |
|
|
@Transactional |
|
|
@ -423,4 +449,90 @@ public class SysOssServiceImpl extends ServiceImpl<SysOssDao, SysOssEntity> impl |
|
|
document.save(pdfPath); |
|
|
document.save(pdfPath); |
|
|
System.out.println("Word 文件转换为 PDF 成功,保存路径:" + pdfPath); |
|
|
System.out.println("Word 文件转换为 PDF 成功,保存路径:" + pdfPath); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 发送文档上传通知邮件给发货通知单创建人 |
|
|
|
|
|
* |
|
|
|
|
|
* @param oss 文件信息 |
|
|
|
|
|
*/ |
|
|
|
|
|
private void sendDocumentUploadNotification(SysOssEntity oss) { |
|
|
|
|
|
try { |
|
|
|
|
|
// 查询发货通知单信息,获取创建人 |
|
|
|
|
|
List<EcssCoDelNotifyHeaderData> headerList = coDelMapper.checkEcssCoDelNotifyHeaderByDelNo( |
|
|
|
|
|
oss.getOrderRef1(), oss.getOrderRef2()); |
|
|
|
|
|
|
|
|
|
|
|
if (headerList == null || headerList.isEmpty()) { |
|
|
|
|
|
log.warn("未找到发货通知单,site={}, delNo={}", oss.getOrderRef1(), oss.getOrderRef2()); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
EcssCoDelNotifyHeaderData headerData = headerList.get(0); |
|
|
|
|
|
|
|
|
|
|
|
// 查询创建人邮箱 |
|
|
|
|
|
SysUserEntity creator = coDelMapper.queryByUserName(headerData.getCreateBy()); |
|
|
|
|
|
if (creator == null || StringUtils.isBlank(creator.getEmail())) { |
|
|
|
|
|
log.warn("发货通知单创建人{}不存在或没有配置邮箱地址", headerData.getCreateBy()); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 构建邮件内容 |
|
|
|
|
|
String textHead = String.format("发货通知单 %s【发票:%s】- 仓库确认文档上传通知", |
|
|
|
|
|
headerData.getDelNo(), headerData.getCmcInvoice()); |
|
|
|
|
|
|
|
|
|
|
|
StringBuilder emailContent = new StringBuilder(); |
|
|
|
|
|
emailContent.append("<!DOCTYPE html>"); |
|
|
|
|
|
emailContent.append("<html>"); |
|
|
|
|
|
emailContent.append("<head><meta charset='UTF-8'></head>"); |
|
|
|
|
|
emailContent.append("<body>"); |
|
|
|
|
|
emailContent.append("<h3>发货通知单仓库确认文档上传通知</h3>"); |
|
|
|
|
|
emailContent.append("<p><strong>发货通知单号:</strong>").append(headerData.getDelNo()).append("</p>"); |
|
|
|
|
|
emailContent.append("<p><strong>发票号:</strong>").append(headerData.getCmcInvoice()).append("</p>"); |
|
|
|
|
|
emailContent.append("<p><strong>上传人:</strong>").append(oss.getCreatedBy()).append("</p>"); |
|
|
|
|
|
emailContent.append("<p><strong>上传时间:</strong>").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(oss.getCreateDate())).append("</p>"); |
|
|
|
|
|
emailContent.append("<p><strong>文件名称:</strong>").append(oss.getFileName()).append("</p>"); |
|
|
|
|
|
|
|
|
|
|
|
emailContent.append("<p style='color: #666; margin-top: 20px;'>请登录系统查看详细信息。</p>"); |
|
|
|
|
|
emailContent.append("</body>"); |
|
|
|
|
|
emailContent.append("</html>"); |
|
|
|
|
|
|
|
|
|
|
|
// 发送邮件 |
|
|
|
|
|
String[] mailAddress = new String[]{creator.getEmail()}; |
|
|
|
|
|
sendMailUtil(textHead, emailContent.toString(), mailAddress, headerData); |
|
|
|
|
|
|
|
|
|
|
|
log.info("文档上传通知邮件已发送,收件人: {}, 发货通知单号: {}", creator.getEmail(), headerData.getDelNo()); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("发送文档上传通知邮件失败: {}", e.getMessage(), e); |
|
|
|
|
|
throw e; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 发送邮件工具方法 |
|
|
|
|
|
* |
|
|
|
|
|
* @param textHead 邮件主题 |
|
|
|
|
|
* @param text 邮件内容 |
|
|
|
|
|
* @param mailAddress 收件人邮箱数组 |
|
|
|
|
|
* @param data 发货通知单数据 |
|
|
|
|
|
*/ |
|
|
|
|
|
private void sendMailUtil(String textHead, String text, String[] mailAddress, EcssCoDelNotifyHeaderData data) { |
|
|
|
|
|
try { |
|
|
|
|
|
MailSendAddressData mailSendData = qcMapper.getSendMailFromAddress(); |
|
|
|
|
|
MailUtil.sendMail(textHead, text, mailAddress, mailSendData); |
|
|
|
|
|
|
|
|
|
|
|
// 保存邮件记录 |
|
|
|
|
|
SendMailRecord mailRecord = new SendMailRecord(); |
|
|
|
|
|
mailRecord.setSite(data.getSite()); |
|
|
|
|
|
mailRecord.setBuNo(data.getBuNo()); |
|
|
|
|
|
mailRecord.setDocumentNo(data.getDelNo()); |
|
|
|
|
|
mailRecord.setSender(data.getCreateBy()); |
|
|
|
|
|
mailRecord.setRecipient(Arrays.toString(mailAddress)); |
|
|
|
|
|
mailRecord.setType("关务系统-文档上传"); |
|
|
|
|
|
qcMapper.saveSendMailRecord(mailRecord); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("邮件发送失败: {}", e.getMessage(), e); |
|
|
|
|
|
throw e; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |