|
@@ -0,0 +1,99 @@
|
|
|
|
|
+package com.skyversation.xjcy.controller;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.skyversation.xjcy.dms.DMSColumn;
|
|
|
|
|
+import com.skyversation.xjcy.dms.DMSService;
|
|
|
|
|
+import com.skyversation.xjcy.dms.FileType;
|
|
|
|
|
+import com.skyversation.xjcy.enums.WechatSource;
|
|
|
|
|
+import com.skyversation.xjcy.oauth.AuthService;
|
|
|
|
|
+import com.skyversation.xjcy.util.FileUtil;
|
|
|
|
|
+import com.skyversation.xjcy.util.MessageManage;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
|
+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 java.io.IOException;
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Validated
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping()
|
|
|
|
|
+public class UploadController {
|
|
|
|
|
+ private final DMSService dMSService;
|
|
|
|
|
+ private final AuthService authService;
|
|
|
|
|
+
|
|
|
|
|
+ public UploadController(DMSService dMSService, AuthService authService) {
|
|
|
|
|
+ this.dMSService = dMSService;
|
|
|
|
|
+ this.authService = authService;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @RequestMapping("/uploadWeChatArticle")
|
|
|
|
|
+ public String uploadWeChatArticle(@RequestParam("pdf") MultipartFile pdf,
|
|
|
|
|
+ @RequestParam("picture") MultipartFile picture,
|
|
|
|
|
+ @RequestParam("title") String title,
|
|
|
|
|
+ @RequestParam("time") String time,
|
|
|
|
|
+ @RequestParam("source") String source,
|
|
|
|
|
+ @RequestParam("url") String url) {
|
|
|
|
|
+ WechatSource sourceEnum;
|
|
|
|
|
+ try {
|
|
|
|
|
+ sourceEnum = WechatSource.valueOf(source.toUpperCase());
|
|
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
|
|
+ return MessageManage.getInstance().getResultContent(-1,
|
|
|
|
|
+ "source的取值范围为" +
|
|
|
|
|
+ Arrays.stream(WechatSource.values())
|
|
|
|
|
+ .map(Objects::toString)
|
|
|
|
|
+ .map(String::toLowerCase)
|
|
|
|
|
+ .collect(Collectors.joining(",")),
|
|
|
|
|
+ "传入的source不可用"
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String pdfPath;
|
|
|
|
|
+ try {
|
|
|
|
|
+ pdfPath = dMSService.uploadFile(
|
|
|
|
|
+ FileUtil.getResource(pdf),
|
|
|
|
|
+ authService.getToken(),
|
|
|
|
|
+ DMSColumn.WECHAT_ARTICLE,
|
|
|
|
|
+ "c_article_content",
|
|
|
|
|
+ FileType.FILE);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ return MessageManage.getInstance().getResultContent(-1, "将pdf上传至服务器失败", "将pdf上传至服务器失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ String picturePath;
|
|
|
|
|
+ try {
|
|
|
|
|
+ picturePath = dMSService.uploadFile(
|
|
|
|
|
+ FileUtil.getResource(picture),
|
|
|
|
|
+ authService.getToken(),
|
|
|
|
|
+ DMSColumn.WECHAT_ARTICLE,
|
|
|
|
|
+ "c_article_picture",
|
|
|
|
|
+ FileType.PICTURE);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ return MessageManage.getInstance().getResultContent(-1, "将pdf上传至服务器失败", "将picture上传至服务器失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
|
|
+ obj.put("c_wechat_source_type", sourceEnum.getCode());
|
|
|
|
|
+ obj.put("c_article_title", title.replaceAll("'", "''"));
|
|
|
|
|
+ obj.put("c_article_content", pdfPath);
|
|
|
|
|
+ obj.put("c_article_picture", picturePath);
|
|
|
|
|
+ obj.put("c_publish_time", time);
|
|
|
|
|
+ obj.put("c_original_url", url.replaceAll("'", "''"));
|
|
|
|
|
+ obj.put("c_status", "2");
|
|
|
|
|
+
|
|
|
|
|
+ obj.put("title", title.replaceAll("'", "''"));
|
|
|
|
|
+ obj.put("content", title.replaceAll("'", "''"));
|
|
|
|
|
+ boolean success = dMSService.insertToDms(obj, authService.getToken(), DMSColumn.WECHAT_ARTICLE);
|
|
|
|
|
+ if (success) {
|
|
|
|
|
+ return MessageManage.getInstance().getResultContent(200, "完成", "完成");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return MessageManage.getInstance().getResultContent(-1, "未知错误", "未知错误");
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|