提交 db4d7fb3 编写于 作者: 小柒2012

简单的文档管理

上级 a91270e0
......@@ -9,6 +9,8 @@
<packaging>war</packaging>
<properties>
<openoffice.version>4.1.2</openoffice.version>
<jodconverter.version>4.3.0</jodconverter.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
......@@ -196,6 +198,43 @@
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>6.0.0</version>
</dependency>
<!-- openoffice -->
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>unoil</artifactId>
<version>${openoffice.version}</version>
</dependency>
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>ridl</artifactId>
<version>${openoffice.version}</version>
</dependency>
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>jurt</artifactId>
<version>${openoffice.version}</version>
</dependency>
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>juh</artifactId>
<version>${openoffice.version}</version>
</dependency>
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-local</artifactId>
<version>${jodconverter.version}</version>
</dependency>
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-core</artifactId>
<version>${jodconverter.version}</version>
</dependency>
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-spring-boot-starter</artifactId>
<version>${jodconverter.version}</version>
</dependency>
</dependencies>
<build>
<finalName>picture-bed</finalName>
......
......@@ -23,6 +23,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
@SpringBootApplication(exclude = { SecurityAutoConfiguration.class })
public class Application extends SpringBootServletInitializer {
private static final Logger logger = LoggerFactory.getLogger(Application.class);
public static void main(String[] args) {
......
package com.tools.module.document.util;
import org.jodconverter.core.office.OfficeException;
import org.jodconverter.core.office.OfficeUtils;
import org.jodconverter.local.JodConverter;
import org.jodconverter.local.office.LocalOfficeManager;
import java.io.File;
/**
* OpenOffice 文件转换
*/
public class OpenOfficeService {
static {
LocalOfficeManager.builder()
.portNumbers(2002)
.build();
}
public static void main(String[] args) {
LocalOfficeManager officeManager = LocalOfficeManager.install();
try {
officeManager.start();
JodConverter
.convert(new File("F:\\前端.txt"))
.to(new File("E:\\home\\1.pdf"))
.execute();
} catch (OfficeException e) {
e.printStackTrace();
} finally {
OfficeUtils.stopQuietly(officeManager);
}
}
}
\ No newline at end of file
package com.tools.module.document.web;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import com.tools.common.config.AbstractController;
import com.tools.common.constant.SystemConstant;
import com.tools.common.model.Result;
import io.swagger.annotations.Api;
import org.jodconverter.core.DocumentConverter;
import org.jodconverter.core.office.OfficeException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
@Api(tags ="文档管理")
@RestController
@RequestMapping("document")
public class ConverterController extends AbstractController {
@Value("${file.path}")
private String filePath;
@Resource
private DocumentConverter documentConverter;
/**
* 文件上传
*/
@RequestMapping("/upload")
public Result upload(MultipartFile file) {
try {
if(file!=null){
File parentFile = createParentFile();
String fileName = file.getOriginalFilename();
String suffix = fileName.substring(fileName.lastIndexOf("."));
String uuid = IdUtil.simpleUUID();
fileName = uuid + suffix;
File imageFile = new File(parentFile,fileName);
FileUtil.writeFromStream(file.getInputStream(), imageFile);
return Result.ok();
}else{
return Result.error();
}
} catch (Exception e) {
return Result.error();
}
}
/**
* 文件上传
*/
@RequestMapping("converter")
public Result converter() {
try {
documentConverter
.convert(new File("F:\\前端.txt"))
.to(new File("E:\\home\\1.pdf")).execute();
} catch (OfficeException e) {
logger.error("转换失败{}",e);
return Result.error();
}
return Result.ok();
}
/**
* 创建多级文件夹
* @return
*/
public File createParentFile(){
File parentFile = new File(filePath+ SystemConstant.SF_FILE_SEPARATOR+ DateUtil.thisYear());
if (!parentFile.exists()) {
parentFile.mkdirs();
}
parentFile = new File(parentFile,(DateUtil.thisMonth()+1)+"");
if (!parentFile.exists()) {
parentFile.mkdirs();
}
parentFile = new File(parentFile,DateUtil.thisDayOfMonth()+"");
if (!parentFile.exists()) {
parentFile.mkdirs();
}
return parentFile;
}
}
......@@ -167,9 +167,25 @@ wx.miniapp.token= **********
wx.miniapp.aesKey= **********
wx.miniapp.msgDataFormat= JSON
# ===================================
# 工作流
# ===================================
#每次应用启动不检查Activiti数据表是否存在及版本号是否匹配,提升应用启动速度
spring.activiti.database-schema-update=true
#保存历史数据级别设置为full最高级别,便于历史数据的追溯
spring.activiti.history-level=full
# 检测身份信息表是否存在 默认值即可
spring.activiti.db-identity-used=false
\ No newline at end of file
spring.activiti.db-identity-used=false
# ===================================
# openOffice
# ===================================
# https://github.com/sbraconnier/jodconverter
jodconverter.local.enabled=true
# 设置openOffice主目录 默认会自动读取
jodconverter.local.office-home=C:/Program Files (x86)/OpenOffice 4
# 开启多个openOffice进程,每个端口对应一个进程
jodconverter.local.portNumbers=8100
# openOffice进程重启前的最大进程数
jodconverter.local.maxTasksPerProcess=100
\ No newline at end of file
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/head :: head(link)"/>
<style>
.home-container {
width: 600px;
margin: 0 auto;
margin-top:100px;
position: relative;
}
</style>
<body>
<div id="wrapper" v-cloak>
<div class="home-container">
<template>
<tabs>
<tab-pane @click="tab(0)" icon="md-build" label="缩短网址"/>
<i-form ref="checkForm" :model="tinyUrl" :rules="ruleValidate">
<form-item prop="url">
<i-input search enter-button="缩短网址" v-model="tinyUrl.url" @on-search="create()" placeholder="请输入长网址" />
</form-item>
<form-item label="选择失效时间:" prop="gmtExpire">
<radio-group v-model="tinyUrl.expire" >
<radio v-for="item in expire" :label="item.code">{{item.name}}</radio>
</radio-group>
</form-item>
</i-form>
</tab-pane>
<tab-pane @click="tab(1)" icon="ios-redo" label="还原网址">
<i-input search enter-button="还原网址" @on-search="restore()" placeholder="请输入短网址" />
</tab-pane>
</tabs>
<div v-show="keyShow">
<i-input id="URL" v-model="tinyUrl.tinykey" style="width: 500px"></i-input>
<i-button data-clipboard-target="#URL" class="btn" @click="copy()" type="primary">复制</i-button>
</div>
</template>
</div>
</div>
<div th:replace="common/foot :: foot(clipboard)"></div>
<script>
new ClipboardJS('.btn');
layui.use(["okUtils", "okLayer"], function () {
var okUtils = layui.okUtils;
var okLayer = layui.okLayer;
var vm = new Vue({
el : '#wrapper',
data:{
tinyUrl:{
expire:0,
tinykey:''
},
keyShow:false,
expire :[{"code":1,"name":"1天"},{"code":3,"name":"3天"},{"code":7,"name":"7天"},{"code":30,"name":"30天"},{"code":0,"name":"永久"}],
ruleValidate : {
url: [
{ required: true, message: '地址不能为空', trigger: 'blur' }
]
},
},
methods : {
create: function() {
var that = this;
vm.$refs.checkForm.validate(function(valid){
if (valid) {
if(that.tinyUrl.expire!=0){
that.tinyUrl.gmtExpire = okUtils.addData(that.tinyUrl.expire)
}else{
that.tinyUrl.gmtExpire = "2049-10-01 00:00:00";
}
okUtils.ajax("/app/tinyUrl/save", "post", that.tinyUrl, false).done(function (response) {
okLayer.msg.greenTick("生成成功", function () {
that.tinyUrl.tinykey = response.msg;
that.keyShow = true;
})
}).fail(function (error) {
console.log(error)
});
}
});
},
restore:function(){
okLayer.msg.yellowQuestion("还原是不可能的,这辈子都不可能!!!");
},
copy:function(){
this.$Notice.success({
title: '复制成功',
desc:'小伙伴,赶紧尝试一下吧'
});
},
tab:function(code){
}
},
created : function() {
}
});
});
</script>
</body>
</html>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册