| | |
| | | package com.ruoyi.web.controller.common; |
| | | |
| | | import java.io.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Base64; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import javax.lang.model.util.Elements; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.enums.PhotoEnum; |
| | | import com.ruoyi.common.enums.RadioEnum; |
| | | import com.ruoyi.common.enums.VadioEnum; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.file.FileUploadUtils; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | | import com.ruoyi.framework.config.ServerConfig; |
| | | import com.smartor.domain.HtmlContentVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.hwpf.HWPFDocument; |
| | | import org.apache.poi.hwpf.converter.PicturesManager; |
| | | import org.apache.poi.hwpf.converter.WordToHtmlConverter; |
| | | import org.apache.poi.hwpf.usermodel.PictureType; |
| | | 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.http.MediaType; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.xml.parsers.DocumentBuilderFactory; |
| | |
| | | import javax.xml.transform.TransformerFactory; |
| | | import javax.xml.transform.dom.DOMSource; |
| | | import javax.xml.transform.stream.StreamResult; |
| | | |
| | | import com.ruoyi.common.enums.PhotoEnum; |
| | | import com.ruoyi.common.enums.RadioEnum; |
| | | import com.ruoyi.common.enums.VadioEnum; |
| | | import org.apache.poi.hwpf.HWPFDocument; |
| | | import org.apache.poi.hwpf.converter.PicturesManager; |
| | | import org.apache.poi.hwpf.converter.WordToHtmlConverter; |
| | | import org.apache.poi.hwpf.usermodel.Picture; |
| | | import org.apache.poi.hwpf.usermodel.PictureType; |
| | | import org.jsoup.Jsoup; |
| | | import org.jsoup.nodes.Element; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.file.FileUploadUtils; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | | import com.ruoyi.framework.config.ServerConfig; |
| | | import org.springframework.web.multipart.commons.CommonsMultipartFile; |
| | | import org.w3c.dom.Document; |
| | | import java.io.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Base64; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 通用请求处理 |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @RestController |
| | | @Api(description = "通过请求处理") |
| | | @RequestMapping("/common") |
| | | public class CommonController { |
| | | private static final Logger log = LoggerFactory.getLogger(CommonController.class); |
| | |
| | | private ServerConfig serverConfig; |
| | | |
| | | private static final String FILE_DELIMETER = ","; |
| | | |
| | | @Value("${uploadSwitch}") |
| | | private Integer uploadSwitch; |
| | | |
| | | /** |
| | | * 通用下载请求 |
| | |
| | | /** |
| | | * 分类上传请求 |
| | | */ |
| | | @ApiOperation("分类上传请求") |
| | | @PostMapping("/uploadSort") |
| | | public AjaxResult uploadFileSort(MultipartFile file) { |
| | | try { |
| | |
| | | } |
| | | // 上传并返回新文件名称 |
| | | String fileName = FileUploadUtils.uploadSort(filePath, file); |
| | | String url = serverConfig.getUrl() + fileName; |
| | | String url = null; |
| | | //新华医院特殊,这个视频的访问得转 |
| | | String xhPath = "http://218.108.11.22:8093/profile-api"; |
| | | if (uploadSwitch == 1) { |
| | | String fn = fileName.replaceAll("/profile", ""); |
| | | url = xhPath + fn; |
| | | } else { |
| | | url = serverConfig.getUrl() + fileName; |
| | | } |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("url", url); |
| | | ajax.put("fileName", fileName); |
| | |
| | | /** |
| | | * 上传并转成html请求 |
| | | */ |
| | | @ApiOperation("word文件上传并转成html") |
| | | @PostMapping("/uploadShow") |
| | | public AjaxResult uploadFileShow(MultipartFile file) { |
| | | try { |
| | |
| | | //将word转成html |
| | | convertDocToHtml(filePath + "\\" + file.getOriginalFilename(), filePath + "\\" + file.getOriginalFilename().split("\\.", 2)[0] + ".html"); |
| | | |
| | | String url = serverConfig.getUrl() + fileName.replaceAll("\\.[^.]*$", ".html"); |
| | | String url = null; |
| | | String xhPath = "http://218.108.11.22:8093/profile-api"; |
| | | if (uploadSwitch == 1) { |
| | | String fn = fileName.replaceAll("\\.[^.]*$", ".html").replaceAll("/profile", ""); |
| | | url = xhPath + fn; |
| | | |
| | | } else { |
| | | url = serverConfig.getUrl() + fileName.replaceAll("\\.[^.]*$", ".html"); |
| | | } |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("url", url); |
| | | ajax.put("fileName", fileName); |
| | |
| | | /** |
| | | * 通用上传请求(单个) |
| | | */ |
| | | @ApiOperation("通用上传请求") |
| | | @PostMapping("/upload") |
| | | public AjaxResult uploadFile(MultipartFile file) { |
| | | try { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @param |
| | | * @return |
| | | */ |
| | | @ApiOperation("富文本转html") |
| | | @PostMapping("/htmlContent") |
| | | public AjaxResult htmlContent(@RequestBody HtmlContentVO htmlContentVO) { |
| | | log.error("htmlContentVO入参为:{}", htmlContentVO); |
| | | // 获取文件的原始名称 |
| | | String fileName = htmlContentVO.getFileName(); |
| | | if (!fileName.endsWith(".html")) { |
| | | // 去掉之前的扩展名 |
| | | int lastIndex = fileName.lastIndexOf('.'); |
| | | if (lastIndex != -1) { |
| | | fileName = fileName.substring(0, lastIndex); // 去掉扩展名 |
| | | } |
| | | // 添加.html后缀 |
| | | fileName += ".html"; |
| | | } |
| | | FileUtils.createFile(RuoYiConfig.getUploadPath() + "/show/" + fileName.split("\\.", 2)[0]); |
| | | // 将文件保存到指定目录 |
| | | File outputFile = new File(RuoYiConfig.getUploadPath() + "/show/" + fileName.split("\\.", 2)[0] + "/" + fileName); |
| | | try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"))) { |
| | | if (StringUtils.isNotEmpty(htmlContentVO.getContent())) |
| | | writer.write(htmlContentVO.getContent()); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String url = null; |
| | | String xhPath = "http://218.108.11.22:8093/profile-api"; |
| | | if (uploadSwitch == 1) { |
| | | url = xhPath + "/upload/show/" + fileName.split("\\.", 2)[0] + "/" + fileName; |
| | | } else { |
| | | url = serverConfig.getUrl() + "/profile/upload/show/" + fileName.split("\\.", 2)[0] + "/" + fileName; |
| | | } |
| | | return AjaxResult.success(url); |
| | | } |
| | | |
| | | |
| | | public static void convertDocToHtml(String docFilePath, String outputHtmlFilePath) throws TransformerException, IOException, ParserConfigurationException { |
| | | |
| | | InputStream inputStream = new FileInputStream(docFilePath); |