|
@@ -0,0 +1,126 @@
|
|
|
|
|
+package com.storlead.mail.controller.mkt;
|
|
|
|
|
+
|
|
|
|
|
+import com.storlead.framework.common.result.Result;
|
|
|
|
|
+import com.storlead.mail.webclient.client.MktMailRemoteClient;
|
|
|
|
|
+import com.storlead.mail.webclient.dto.MktMailQueryRemoteDTO;
|
|
|
|
|
+import com.storlead.mail.webclient.dto.MktSendMailRemoteDTO;
|
|
|
|
|
+import com.storlead.mail.webclient.support.MailRemoteResponseWriter;
|
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 营销邮件主流程(路径对齐邮件服务 {@code MktMailApiController},转发独立邮件服务 /mkt/**)。
|
|
|
|
|
+ */
|
|
|
|
|
+@Log4j2
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/mkt")
|
|
|
|
|
+@Api(tags = "营销邮件: 邮件主流程")
|
|
|
|
|
+public class MktMailApiController {
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private MktMailRemoteClient mktMailRemoteClient;
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/file/cache_mail_file")
|
|
|
|
|
+ @ApiOperation("缓存营销邮件临时附件(scene=MKT)")
|
|
|
|
|
+ public Result<?> cacheMailFile(@RequestParam("files") List<MultipartFile> files,
|
|
|
|
|
+ @RequestParam("accountId") Long accountId) {
|
|
|
|
|
+ return mktMailRemoteClient.cacheMailFile(files, accountId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/file/list")
|
|
|
|
|
+ @ApiOperation("按邮件查询正式附件(mkt_mail_attachment)")
|
|
|
|
|
+ public Result<?> listAttachments(@RequestParam Long mailId) {
|
|
|
|
|
+ return mktMailRemoteClient.listAttachments(mailId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/file/download")
|
|
|
|
|
+ @ApiOperation("下载营销正式附件")
|
|
|
|
|
+ public void downloadFormalFile(@RequestParam Long fileId, HttpServletResponse response) {
|
|
|
|
|
+ MailRemoteResponseWriter.write(response, mktMailRemoteClient.downloadFormalFile(fileId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/file/download_temp")
|
|
|
|
|
+ @ApiOperation("下载营销临时附件")
|
|
|
|
|
+ public void downloadTempFile(@RequestParam Long fileId, HttpServletResponse response) {
|
|
|
|
|
+ MailRemoteResponseWriter.write(response, mktMailRemoteClient.downloadTempFile(fileId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/receive_mail")
|
|
|
|
|
+ @ApiOperation("接收营销邮件(异步:INBOX+Sent Items,落 mkt_mail_message 并用 reply_msg_id 绑定原信)")
|
|
|
|
|
+ public Result<?> receiveMail(@RequestParam("accountId") Long accountId) {
|
|
|
|
|
+ return mktMailRemoteClient.receiveMail(accountId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/save_draft")
|
|
|
|
|
+ @ApiOperation("保存营销邮件草稿")
|
|
|
|
|
+ public Result<?> saveDraft(@RequestBody MktSendMailRemoteDTO dto) {
|
|
|
|
|
+ return mktMailRemoteClient.saveDraft(dto);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/send")
|
|
|
|
|
+ @ApiOperation("发送营销邮件(单封;默认同步等待投递结果;async=true 异步投递+回调)")
|
|
|
|
|
+ public Result<?> send(@RequestBody MktSendMailRemoteDTO dto) {
|
|
|
|
|
+ return mktMailRemoteClient.send(dto);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/page_list")
|
|
|
|
|
+ @ApiOperation("营销邮件投递分页")
|
|
|
|
|
+ public Result<?> pageList(@RequestBody MktMailQueryRemoteDTO query) {
|
|
|
|
|
+ return mktMailRemoteClient.pageList(query);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/detail")
|
|
|
|
|
+ @ApiOperation("营销邮件详情(含附件)")
|
|
|
|
|
+ public Result<?> detail(@RequestParam Long id) {
|
|
|
|
|
+ return mktMailRemoteClient.detail(id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/get_mail_detial")
|
|
|
|
|
+ @ApiOperation("获取详情接口")
|
|
|
|
|
+ public Result<?> getMailDetial(@RequestParam Long mailId) {
|
|
|
|
|
+ return mktMailRemoteClient.getMailDetail(mailId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/open_stats")
|
|
|
|
|
+ @ApiOperation("按业务单号汇总打开追踪(opened / open_count)")
|
|
|
|
|
+ public Result<?> openStats(@RequestParam("bizRef") String bizRef) {
|
|
|
|
|
+ return mktMailRemoteClient.openStats(bizRef);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/track/{token}")
|
|
|
|
|
+ @ApiOperation("打开追踪像素(免登录;始终返回 1x1 GIF)")
|
|
|
|
|
+ public void track(@PathVariable("token") String token, HttpServletResponse response) {
|
|
|
|
|
+ byte[] gif = mktMailRemoteClient.track(token);
|
|
|
|
|
+ if (gif == null || gif.length == 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ response.resetBuffer();
|
|
|
|
|
+ response.setStatus(HttpServletResponse.SC_OK);
|
|
|
|
|
+ response.setContentType(MediaType.IMAGE_GIF_VALUE);
|
|
|
|
|
+ response.setHeader(HttpHeaders.CACHE_CONTROL, "no-store, no-cache, must-revalidate");
|
|
|
|
|
+ response.setHeader(HttpHeaders.PRAGMA, "no-cache");
|
|
|
|
|
+ response.setHeader("Expires", "0");
|
|
|
|
|
+ response.setContentLength(gif.length);
|
|
|
|
|
+ response.getOutputStream().write(gif);
|
|
|
|
|
+ response.getOutputStream().flush();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("mkt track write gif error, token={}", token, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|