修改 表头背景
parent
1ea24fdccb
commit
6ebbe21fec
|
|
@ -288,4 +288,18 @@ public class UrlRequestController extends BaseController {
|
|||
return this.jumpPage("admin/category/edit");
|
||||
}
|
||||
|
||||
@GetMapping("/file/index")
|
||||
public ModelAndView file_index(){
|
||||
return this.jumpPage("admin/file/list");
|
||||
}
|
||||
|
||||
@GetMapping("/file/add")
|
||||
public ModelAndView file_add(){
|
||||
return this.jumpPage("admin/file/add");
|
||||
}
|
||||
|
||||
@GetMapping("/file/upload")
|
||||
public ModelAndView file_upload(){
|
||||
return this.jumpPage("admin/file/upload");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,6 +78,8 @@ var article_batchRemove_url = gate_way_url + "/" + blog_url + "/article/batchRem
|
|||
//-----------------------------------------------------------------------------------------------------------------
|
||||
//文件上传
|
||||
var file_upload_url = gate_way_url + "/" + file_url + "/upload/file";
|
||||
//文件列表
|
||||
var file_list_url = gate_way_url + "/" + file_url + "/file/list" ;
|
||||
//----------------------------------------------------------------------------------------------------------------
|
||||
//分类列表
|
||||
var category_list_url = gate_way_url + "/" + blog_url + "/category/list";
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@
|
|||
<title>文章管理</title>
|
||||
<link rel="stylesheet" href="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/pear/css/pear.css" />
|
||||
<style>
|
||||
.layui-table-cell{
|
||||
display:table-cell;
|
||||
vertical-align: middle;
|
||||
.layui-table-header, .layui-table-header th {
|
||||
background-color: #d2d2d2 !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
|
@ -170,9 +169,8 @@
|
|||
},
|
||||
page: true,
|
||||
cols: cols,
|
||||
skin: 'line',
|
||||
skin: 'rows',
|
||||
even: true, //开启隔行背景
|
||||
|
||||
toolbar: '#article-toolbar',
|
||||
defaultToolbar: [{
|
||||
title: '刷新',
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@
|
|||
<title>分类管理</title>
|
||||
<link rel="stylesheet"
|
||||
href="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/pear/css/pear.css"/>
|
||||
<style>
|
||||
.layui-table-header, .layui-table-header th {
|
||||
background-color: #d2d2d2 !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="pear-container">
|
||||
<div class="layui-card">
|
||||
|
|
@ -120,7 +125,7 @@
|
|||
},
|
||||
page: true,
|
||||
cols: cols,
|
||||
skin: 'line',
|
||||
skin: 'rows',
|
||||
toolbar: '#category-toolbar',
|
||||
defaultToolbar: [{
|
||||
title: '刷新',
|
||||
|
|
|
|||
|
|
@ -3,11 +3,10 @@
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>文件管理</title>
|
||||
<link rel="stylesheet" href="${springMacroRequestContext.contextPath}/system/component/pear/css/pear.css" />
|
||||
<link rel="stylesheet" href="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/pear/css/pear.css" />
|
||||
<style>
|
||||
.layui-table-cell{
|
||||
display:table-cell;
|
||||
vertical-align: middle;
|
||||
.layui-table-header, .layui-table-header th {
|
||||
background-color: #d2d2d2 !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
|
@ -90,8 +89,9 @@
|
|||
{{# } }}
|
||||
</script>
|
||||
|
||||
<script src="${springMacroRequestContext.contextPath}/system/component/layui/layui.js"></script>
|
||||
<script src="${springMacroRequestContext.contextPath}/system/component/pear/pear.js"></script>
|
||||
<script src="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/layui/layui.js"></script>
|
||||
<script src="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/pear/pear.js"></script>
|
||||
<script src="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/admin/js/mystyle-admin.js"></script>
|
||||
<script>
|
||||
layui.use(['table', 'form', 'jquery','common'], function() {
|
||||
let table = layui.table;
|
||||
|
|
@ -99,8 +99,6 @@
|
|||
let $ = layui.jquery;
|
||||
let common = layui.common;
|
||||
|
||||
let token = localStorage.getItem("token");
|
||||
|
||||
let cols = [
|
||||
[{
|
||||
type: 'checkbox'
|
||||
|
|
@ -110,14 +108,14 @@
|
|||
field: 'addTime',
|
||||
align: 'center',
|
||||
templet: '#file-addTime',
|
||||
width: 180
|
||||
width: 100
|
||||
},
|
||||
|
||||
{
|
||||
title: '文件名称',
|
||||
field: 'name',
|
||||
align: 'center',
|
||||
width: 280
|
||||
width: 200
|
||||
},
|
||||
{
|
||||
title: '文件类型',
|
||||
|
|
@ -131,6 +129,7 @@
|
|||
title: '文件大小',
|
||||
field: 'fileSize',
|
||||
align: 'center',
|
||||
width:100
|
||||
},
|
||||
|
||||
{
|
||||
|
|
@ -138,38 +137,43 @@
|
|||
field: 'path',
|
||||
align: 'center',
|
||||
templet: '#file-view',
|
||||
width: 100
|
||||
width: 156
|
||||
},
|
||||
|
||||
{
|
||||
title: '图片的宽度',
|
||||
field: 'imageWidth',
|
||||
align: 'center'
|
||||
align: 'center',
|
||||
width: 100
|
||||
},
|
||||
|
||||
{
|
||||
title: '图片的高度',
|
||||
field: 'imageHeight',
|
||||
align: 'center'
|
||||
align: 'center',
|
||||
width: 100
|
||||
},
|
||||
|
||||
{
|
||||
title: '视频的封面',
|
||||
field: 'videoImages',
|
||||
align: 'center'
|
||||
align: 'center',
|
||||
width: 156
|
||||
},
|
||||
|
||||
{
|
||||
title: '视频封面的宽',
|
||||
field: 'videoImagesWidth',
|
||||
align: 'center'
|
||||
},
|
||||
|
||||
{
|
||||
title: '视频封面的高',
|
||||
field: 'videoImagesHeight',
|
||||
align: 'center'
|
||||
},
|
||||
// {
|
||||
// title: '视频封面的宽',
|
||||
// field: 'videoImagesWidth',
|
||||
// align: 'center',
|
||||
// width: 100
|
||||
// },
|
||||
//
|
||||
// {
|
||||
// title: '视频封面的高',
|
||||
// field: 'videoImagesHeight',
|
||||
// align: 'center',
|
||||
// width: 100
|
||||
// },
|
||||
{
|
||||
title: '操作',
|
||||
toolbar: '#file-bar',
|
||||
|
|
@ -181,12 +185,13 @@
|
|||
|
||||
table.render({
|
||||
elem: '#file-table',
|
||||
url: '/file/list',
|
||||
headers: {token: localStorage.getItem("token")},
|
||||
url: file_list_url,
|
||||
headers: {
|
||||
access_token:access_token
|
||||
},
|
||||
page: true,
|
||||
cols: cols,
|
||||
skin: 'line',
|
||||
|
||||
skin: 'rows',
|
||||
toolbar: '#file-toolbar',
|
||||
defaultToolbar: [{
|
||||
title: '刷新',
|
||||
|
|
|
|||
|
|
@ -4,6 +4,11 @@
|
|||
<meta charset="UTF-8">
|
||||
<title>权限管理</title>
|
||||
<link rel="stylesheet" href="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/pear/css/pear.css"/>
|
||||
<style>
|
||||
.layui-table-header, .layui-table-header th {
|
||||
background-color: #d2d2d2 !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="pear-container">
|
||||
<div class="layui-card">
|
||||
|
|
@ -98,7 +103,7 @@
|
|||
treeSpid: 0,
|
||||
treeIdName: 'id',
|
||||
treePidName: 'parent_id',
|
||||
skin: 'line',
|
||||
skin: 'rows',
|
||||
method: 'post',
|
||||
treeDefaultClose: true,
|
||||
toolbar: '#power-toolbar',
|
||||
|
|
|
|||
|
|
@ -4,6 +4,11 @@
|
|||
<meta charset="utf-8">
|
||||
<title>角色管理</title>
|
||||
<link href="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/pear/css/pear.css" rel="stylesheet"/>
|
||||
<style>
|
||||
.layui-table-header, .layui-table-header th {
|
||||
background-color: #d2d2d2 !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="pear-container">
|
||||
<div class="layui-card">
|
||||
|
|
@ -142,7 +147,7 @@
|
|||
url: role_list_url,
|
||||
page: true,
|
||||
cols: cols,
|
||||
skin: 'line',
|
||||
skin: 'rows',
|
||||
even: true, //开启隔行背景
|
||||
toolbar: '#role-toolbar',
|
||||
defaultToolbar: [{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,11 @@
|
|||
<meta charset="utf-8">
|
||||
<title>用户管理</title>
|
||||
<link rel="stylesheet" href="${springMacroRequestContext.contextPath}/mystyle-cloud-admin-manager/system/component/pear/css/pear.css" />
|
||||
<style>
|
||||
.layui-table-header, .layui-table-header th {
|
||||
background-color: #d2d2d2 !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="pear-container">
|
||||
<div class="layui-card">
|
||||
|
|
@ -152,7 +157,7 @@
|
|||
url: user_list_url,
|
||||
page: true,
|
||||
cols: cols,
|
||||
skin: 'line',
|
||||
skin: 'rows',
|
||||
toolbar: '#user-toolbar',
|
||||
defaultToolbar: [{
|
||||
title: '刷新',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package com.zhangmeng.api.service.file;
|
||||
|
||||
import com.zhangmeng.model.vo.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@Api(tags = "文件管理")
|
||||
public interface FileControllerApi {
|
||||
|
||||
@ApiOperation("文件列表")
|
||||
public Result list(Integer pageNum, Integer pageSize, String name);
|
||||
|
||||
@ApiOperation("删除文件")
|
||||
public Result delete( String fileId);
|
||||
|
||||
@ApiOperation("批量删除文章")
|
||||
public Result batchRemove( String ids);
|
||||
|
||||
@ApiOperation("文件在线预览")
|
||||
public void onlinePreview(@RequestParam("url") String url, HttpServletResponse response);
|
||||
}
|
||||
|
|
@ -97,5 +97,9 @@
|
|||
<groupId>org.bytedeco</groupId>
|
||||
<artifactId>ffmpeg-platform</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.artofsolving</groupId>
|
||||
<artifactId>jodconverter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.zhangmeng.file.config;
|
||||
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* 请求拦截器
|
||||
*/
|
||||
@Configuration
|
||||
public class FeignOauth2RequestInterceptor implements RequestInterceptor {
|
||||
@Override
|
||||
public void apply(RequestTemplate requestTemplate) {
|
||||
// 获取的全部请求信息
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (attributes != null){
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
// 获取所有的请求头信息
|
||||
Enumeration<String> headerNames = request.getHeaderNames();
|
||||
if (headerNames != null){
|
||||
while (headerNames.hasMoreElements()){
|
||||
// 获取请求头的key
|
||||
String element = headerNames.nextElement();
|
||||
// 获取请求头的value
|
||||
String value = request.getHeader(element);
|
||||
// 将请求头信息放入到请求头
|
||||
requestTemplate.header(element,value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -79,15 +79,7 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
|
|||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
|
||||
/**
|
||||
* - /swagger-ui.html
|
||||
* - /swagger-ui/**
|
||||
* - /swagger-resources/**
|
||||
* - /v2/api-docs
|
||||
* - /v3/api-docs
|
||||
* - /doc.html
|
||||
* - /webjars/springfox-swagger-ui/**
|
||||
*/
|
||||
http.headers().frameOptions().disable();
|
||||
|
||||
// 所有请求必须认证通过
|
||||
http.authorizeRequests()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
package com.zhangmeng.file.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.zhangmeng.api.service.file.FileControllerApi;
|
||||
import com.zhangmeng.file.feign.UserFeignService;
|
||||
import com.zhangmeng.file.service.FileInfoService;
|
||||
import com.zhangmeng.model.base.baseController.BaseController;
|
||||
import com.zhangmeng.model.base.baseUtil.CommonUtil;
|
||||
import com.zhangmeng.model.dto.query.QueryParams;
|
||||
import com.zhangmeng.model.entity.FileInfo;
|
||||
import com.zhangmeng.model.entity.User;
|
||||
import com.zhangmeng.model.vo.Result;
|
||||
import com.zhangmeng.model.vo.StatusCode;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/file")
|
||||
public class FileController extends BaseController implements FileControllerApi {
|
||||
|
||||
@Autowired
|
||||
private FileInfoService fileInfoService;
|
||||
|
||||
@Autowired
|
||||
private UserFeignService userFeignService;
|
||||
|
||||
@Override
|
||||
@GetMapping("/list")
|
||||
public Result list(Integer pageNum, Integer pageSize, String name){
|
||||
Condition condition = new Condition(FileInfo.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
User user = userFeignService.getCurrentUser();
|
||||
criteria.andEqualTo("user_id", Objects.requireNonNull(user).getId());
|
||||
if (CommonUtil.isNotNull(name)){
|
||||
criteria.andLike("name","%"+ name + "%");
|
||||
}
|
||||
PageInfo<FileInfo> pageInfo = this.fileInfoService.findByCondition(new QueryParams(pageNum, pageSize, condition),true);
|
||||
return new Result(true, StatusCode.OK,"查询成功",pageInfo.getTotal(),pageInfo.getList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("/delete")
|
||||
public Result delete( String fileId) {
|
||||
if (CommonUtil.isNotNull(fileId)){
|
||||
this.fileInfoService.deleteById(Long.parseLong(fileId));
|
||||
}
|
||||
return new Result(true, StatusCode.OK,"删除成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("/batchRemove")
|
||||
public Result batchRemove( String ids) {
|
||||
String id_s = CommonUtil.firstLastComma(ids);
|
||||
String[] strings = id_s.split(",");
|
||||
if (strings.length > 0){
|
||||
for (String id : strings) {
|
||||
this.fileInfoService.deleteById(Long.parseLong(id));
|
||||
}
|
||||
}
|
||||
return new Result(true,StatusCode.OK,"删除成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("/onlinePreview")
|
||||
public void onlinePreview(@RequestParam("url") String url, HttpServletResponse response){
|
||||
this.fileInfoService.onlinePreview(url,response);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(SysConstant.mystyle_cloud_admin_manager)
|
||||
@FeignClient(value = SysConstant.mystyle_cloud_admin_manager)
|
||||
public interface UserFeignService {
|
||||
|
||||
@RequestMapping("/user/findByUserName")
|
||||
|
|
@ -18,4 +18,7 @@ public interface UserFeignService {
|
|||
|
||||
@RequestMapping("/permission/findByUserId")
|
||||
List<Permission> findByUserId(@RequestParam(value = "id", defaultValue = "forezp",required = false)Long id);
|
||||
|
||||
@GetMapping("/user/current")
|
||||
public User getCurrentUser();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.zhangmeng.file.service;
|
|||
import com.zhangmeng.model.base.baseService.BaseService;
|
||||
import com.zhangmeng.model.entity.FileInfo;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @date 2021年7月13日10:38:35
|
||||
|
|
@ -12,4 +14,5 @@ public interface FileInfoService extends BaseService<FileInfo> {
|
|||
|
||||
FileInfo findByMd5(String md5);
|
||||
|
||||
void onlinePreview(String url, HttpServletResponse response);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.zhangmeng.file.service.impl;
|
||||
|
||||
import com.zhangmeng.file.service.FileInfoService;
|
||||
import com.zhangmeng.file.utils.FileUtil;
|
||||
import com.zhangmeng.model.base.baseService.impl.AbstractBaseServiceImpl;
|
||||
import com.zhangmeng.model.base.baseUtil.CommonUtil;
|
||||
import com.zhangmeng.model.entity.FileInfo;
|
||||
|
|
@ -9,6 +10,9 @@ import org.springframework.stereotype.Service;
|
|||
import tk.mybatis.mapper.entity.Condition;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
|
@ -28,4 +32,34 @@ public class FileInfoServiceImpl extends AbstractBaseServiceImpl<FileInfo> imple
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onlinePreview(String url, HttpServletResponse response) {
|
||||
try {
|
||||
//获取文件类型
|
||||
String suffix = CommonUtil.guessContentTypeFromStream(url);
|
||||
if(!suffix.equals("txt") && !suffix.equals("doc") && !suffix.equals("docx") && !suffix.equals("xls")
|
||||
&& !suffix.equals("xlsx") && !suffix.equals("ppt") && !suffix.equals("pptx")){
|
||||
throw new RuntimeException("文件格式不支持预览");
|
||||
}
|
||||
InputStream in= FileUtil.convertNetFile(url,suffix);
|
||||
OutputStream outputStream = response.getOutputStream();
|
||||
//创建存放文件内容的数组
|
||||
byte[] buff =new byte[1024];
|
||||
//所读取的内容使用n来接收
|
||||
int n;
|
||||
//当没有读取完时,继续读取,循环
|
||||
while((n=in.read(buff))!=-1){
|
||||
//将字节数组的数据全部写入到输出流中
|
||||
outputStream.write(buff,0,n);
|
||||
}
|
||||
//强制将缓存区的数据进行输出
|
||||
outputStream.flush();
|
||||
//关流
|
||||
outputStream.close();
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,10 +34,19 @@ import java.awt.image.BufferedImage;
|
|||
import java.awt.image.DataBufferByte;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.zhangmeng.model.dto.baidu.LatAndLngToAddress;
|
||||
|
||||
import com.artofsolving.jodconverter.DefaultDocumentFormatRegistry;
|
||||
import com.artofsolving.jodconverter.DocumentConverter;
|
||||
import com.artofsolving.jodconverter.DocumentFormat;
|
||||
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
|
||||
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
|
||||
import com.artofsolving.jodconverter.openoffice.converter.StreamOpenOfficeDocumentConverter;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -690,4 +699,63 @@ public class FileUtil {
|
|||
mat.put(0, 0, pixels);
|
||||
return mat;
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法描述 office文档转换为PDF(处理网络文件)
|
||||
*
|
||||
* @param netFileUrl 网络文件路径
|
||||
* @param suffix 文件后缀
|
||||
* @return InputStream 转换后文件输入流
|
||||
* @author tarzan
|
||||
*/
|
||||
public static InputStream convertNetFile(String netFileUrl, String suffix) throws Exception {
|
||||
// 创建URL
|
||||
URL url = new URL(netFileUrl);
|
||||
// 试图连接并取得返回状态码
|
||||
URLConnection urlconn = url.openConnection();
|
||||
urlconn.connect();
|
||||
HttpURLConnection httpconn = (HttpURLConnection) urlconn;
|
||||
int httpResult = httpconn.getResponseCode();
|
||||
if (httpResult == HttpURLConnection.HTTP_OK) {
|
||||
InputStream inputStream = urlconn.getInputStream();
|
||||
return covertCommonByStream(inputStream, suffix);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 默认转换后文件后缀 */
|
||||
private static final String DEFAULT_SUFFIX = "pdf";
|
||||
/** openoffice_port */
|
||||
private static final Integer OPENOFFICE_PORT = 8100;
|
||||
|
||||
/**
|
||||
* 方法描述 将文件以流的形式转换
|
||||
*
|
||||
* @param inputStream 源文件输入流
|
||||
* @param suffix 源文件后缀
|
||||
* @return InputStream 转换后文件输入流
|
||||
* @author tarzan
|
||||
*/
|
||||
public static InputStream covertCommonByStream(InputStream inputStream, String suffix) throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
OpenOfficeConnection connection = new SocketOpenOfficeConnection(OPENOFFICE_PORT);
|
||||
connection.connect();
|
||||
DocumentConverter converter = new StreamOpenOfficeDocumentConverter(connection);
|
||||
DefaultDocumentFormatRegistry formatReg = new DefaultDocumentFormatRegistry();
|
||||
DocumentFormat targetFormat = formatReg.getFormatByFileExtension(DEFAULT_SUFFIX);
|
||||
DocumentFormat sourceFormat = formatReg.getFormatByFileExtension(suffix);
|
||||
converter.convert(inputStream, sourceFormat, out, targetFormat);
|
||||
connection.disconnect();
|
||||
return outputStreamConvertInputStream(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法描述 outputStream转inputStream
|
||||
*
|
||||
* @author tarzan
|
||||
*/
|
||||
public static ByteArrayInputStream outputStreamConvertInputStream(final OutputStream out) throws Exception {
|
||||
ByteArrayOutputStream baos=(ByteArrayOutputStream) out;
|
||||
return new ByteArrayInputStream(baos.toByteArray());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ package com.zhangmeng.model.base.baseUtil;
|
|||
|
||||
import com.zhangmeng.model.dto.date.DateBean;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.*;
|
||||
|
|
@ -342,4 +346,21 @@ public class CommonUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static String guessContentTypeFromStream(String str_url) {
|
||||
try {
|
||||
BufferedInputStream bis = null;
|
||||
HttpURLConnection urlconnection = null;
|
||||
URL url = null;
|
||||
url = new URL(str_url);
|
||||
urlconnection = (HttpURLConnection) url.openConnection();
|
||||
urlconnection.connect();
|
||||
bis = new BufferedInputStream(urlconnection.getInputStream());
|
||||
String type = HttpURLConnection.guessContentTypeFromStream(bis);
|
||||
urlconnection.disconnect();
|
||||
return type;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
7
pom.xml
7
pom.xml
|
|
@ -55,6 +55,7 @@
|
|||
<ffmpeg-platform.version>4.2.1-1.5.2</ffmpeg-platform.version>
|
||||
<fastjson.version>1.2.75</fastjson.version>
|
||||
<jwt.version>0.9.1</jwt.version>
|
||||
<jodconverter.version>2.2.1</jodconverter.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
|
@ -205,6 +206,12 @@
|
|||
<artifactId>jjwt</artifactId>
|
||||
<version>${jwt.version}</version>
|
||||
</dependency>
|
||||
<!--openoffice-->
|
||||
<dependency>
|
||||
<groupId>com.artofsolving</groupId>
|
||||
<artifactId>jodconverter</artifactId>
|
||||
<version>${jodconverter.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
Loading…
Reference in New Issue