| | |
| | | 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.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; |
| | |
| | | * @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 = serverConfig.getUrl() + "/profile/upload/show/" + fileName.split("\\.", 2)[0] + "/" + fileName; |
| | | 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); |
| | | } |
| | | |