提交 7ade9c92 authored 作者: renjianyu's avatar renjianyu

--no commit message

上级 b087c4b2
......@@ -52,6 +52,7 @@ import tk.mybatis.mapper.entity.Example;
import com.zrqx.core.exception.BaseException;
import com.zrqx.core.form.file.CreatreQRCodeForm;
import com.zrqx.core.form.file.QrcodeForm;
import com.zrqx.core.model.file.FileInfo;
import com.zrqx.core.util.datatype.UUIDUtil;
import com.zrqx.core.util.download.DownloadUtil;
......@@ -216,11 +217,11 @@ public class FileController {
}
@ApiOperation(value = "生成二维码zip")
@RequestMapping(value = "/download/zip", method = RequestMethod.POST)
public String downLoad(HttpServletResponse response,@RequestBody List<String> fileNames) throws Exception {
public String downLoad(HttpServletResponse response,@RequestBody QrcodeForm form ) throws Exception {
Example example =service.createExample();
example.createCriteria().andIn("fileName", fileNames);
example.createCriteria().andIn("fileName", form.getFileNames());
List<FileInfo> list = service.selectByExample(example);
return ZipUtil.zip(rootPath, list);
return ZipUtil.zip(rootPath, list,form.getType());
}
@ApiOperation(value = "导出二维码zip")
@RequestMapping(value = "/download/zip", method = RequestMethod.GET)
......
......@@ -36,13 +36,18 @@ public class BookUtil {
String originalFilename = file.getOriginalFilename();
System.out.println(file.getContentType());
// 源文件的名称,不带后缀
String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
String fileName = "";
if(originalFilename.contains("/")){
fileName = originalFilename.substring(originalFilename.lastIndexOf("/")+1, originalFilename.lastIndexOf("."));
}else{
fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
}
FileInfo fileInfo = new FileInfo();
fileInfo.setOriginalFileName(originalFilename);
int count = service.selectCount(fileInfo);
if (count > 0) {
//int count = service.selectCount(fileInfo);
/* if (count > 0) {
throw new BaseException("epub已存在");
}
}*/
Ebook ebook = new Ebook();
Book book = new Book();
......@@ -61,22 +66,47 @@ public class BookUtil {
ev.setBook(book);
ev.setEbook(ebook);
/*ev.setBookgoods(bookgoods);
ev.setBookissued(bookissued);*/
//isbn
book.setIsbn(epubUtil.getISBN());
ev = er.setBookInfo(epubUtil, ev);
/**
* 保存元数据相关内容
*/
// 名称
book.setName(epubUtil.getBookTitle());
book.setName(epubUtil.getName());
// 作者
book.setAuthor(epubUtil.getAuthor());
// 出版时间
book.setPublishTime(DateUtils.dateTimeToStrYMD(epubUtil.getPublishDate()));
book.setIsbn(epubUtil.getISBN());
// 关键字(图书的名字)20
ebook.setKeywords(epubUtil.getBookTitle());
// 出版单位
book.setPublisher(epubUtil.getPublisher());
// 字数
book.setFontCount(epubUtil.getFontCount());
// 版次
book.setRevision(epubUtil.getRevision());
// 关键字
ebook.setKeywords(epubUtil.getKeywords());
// 开本
//book.setFormat(epubUtil.getFormat());
// 印张
//book.setPrintCount(epubUtil.getPrintCount());
// 页数
// book.setTotalPages(epubUtil.getTotalPages());
//印次
//book.setPrintNo(epubUtil.getPrintNo());
//中图分类
// book.setMidpicid(epubUtil.getMidpicid());
//邮编
// book.setZipCode(epubUtil.getZipcode());
//CIP
// book.setCIP(epubUtil.getCIP());
//承印
book.setPrint(epubUtil.getPrint());
//定价
ebook.setPrice(epubUtil.getPrice());
ebook.setPriceOption(1);
//售价
ebook.setRealPrice(epubUtil.getPrice());
// 保存封面
if(epubUtil.getCover() != null){
String imgName = epubUtil.getCover().getHref().substring(epubUtil.getCover().getHref().lastIndexOf("/") + 1);
......
package com.zrqx.file.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.zip.ZipInputStream;
import org.apache.commons.lang3.StringUtils;
import nl.siegmann.epublib.domain.Author;
import nl.siegmann.epublib.domain.Book;
import nl.siegmann.epublib.domain.Date;
......@@ -21,24 +23,26 @@ import nl.siegmann.epublib.domain.Resource;
import nl.siegmann.epublib.domain.Resources;
import nl.siegmann.epublib.domain.SpineReference;
import nl.siegmann.epublib.domain.TOCReference;
import nl.siegmann.epublib.domain.TableOfContents;
import nl.siegmann.epublib.epub.EpubReader;
/**
* epub 数字书籍格式 数据工具包
*
* @author Administrator
*
*/
public class EpubUtil {
private Book book=null;
private EpubReader epubReader=null;
private Book book = null;
private EpubReader epubReader = null;
/**
* 设置Book实例对象
*
* @return
*/
public EpubUtil setEpubFile(File file){
public EpubUtil setEpubFile(File file) {
try {
return setEpubFile(new FileInputStream(file));
} catch (FileNotFoundException e) {
......@@ -46,277 +50,487 @@ public class EpubUtil {
}
return this;
}
/**
* 设置Book实例对象
*
* @return
*/
public EpubUtil setEpubFile(InputStream in){
public EpubUtil setEpubFile(InputStream in) {
try {
epubReader=getEpubReader();
book=epubReader.readEpub(in);
epubReader = getEpubReader();
book = epubReader.readEpub(in);
} catch (IOException e) {
e.printStackTrace();
}
return this;
}
/**
* 设置Book实例对象
*
* @return
*/
public EpubUtil setEpubFile(InputStream in, String encoding){
public EpubUtil setEpubFile(InputStream in, String encoding) {
try {
epubReader=getEpubReader();
book=epubReader.readEpub(in,encoding);
epubReader = getEpubReader();
book = epubReader.readEpub(in, encoding);
} catch (IOException e) {
e.printStackTrace();
}
return this;
}
/**
* 设置Book实例对象
*
* @return
*/
public EpubUtil setEpubFile(ZipInputStream in){
public EpubUtil setEpubFile(ZipInputStream in) {
try {
epubReader=getEpubReader();
book=epubReader.readEpub(in);
epubReader = getEpubReader();
book = epubReader.readEpub(in);
} catch (IOException e) {
e.printStackTrace();
}
return this;
}
/**
* 设置Book实例对象
*
* @return
*/
public EpubUtil setEpubFile(ZipInputStream in,String encoding){
public EpubUtil setEpubFile(ZipInputStream in, String encoding) {
try {
epubReader=getEpubReader();
book=epubReader.readEpub(in,encoding);
epubReader = getEpubReader();
book = epubReader.readEpub(in, encoding);
} catch (IOException e) {
e.printStackTrace();
}
return this;
}
/**
* 获取所有的资源对象
*
* @return
*/
public Resources getResources(){
public Resources getResources() {
return book.getResources();
}
/**
* 获取封面
*/
public Resource getCover(){
//epub格式的书籍中都没有将封面图片的信息放到<metadata>标签下的cover标签中。所以用第二种fangs
public Resource getCover() {
// epub格式的书籍中都没有将封面图片的信息放到<metadata>标签下的cover标签中。所以用第二种fangs
Resource res = book.getCoverImage();
if(res!=null){
if (res != null) {
return res;
}else{
Resources ress = book.getResources();
res = ress.getById("cover");
} else {
Resources ress = book.getResources();
res = ress.getById("cover");
if (res == null) {
res = ress.getById("cover-image");
}
if (res == null) {
res = ress.getById("Cover");
}
return res;
}
}
/**
* 获取制定的文件资源
*
* @param mediaTypes
* @return
*/
public List<Resource> getResources(MediaType ... mediaTypes){
public List<Resource> getResources(MediaType... mediaTypes) {
return getResources().getResourcesByMediaTypes(mediaTypes);
}
/**
* 获取图书的css资源文件
*
* @return
*/
public Resource getCssResource(){
List<Resource> list=getResources(new MediaType("text/css","css"));
if(list!=null && list.size()>0){
public Resource getCssResource() {
List<Resource> list = getResources(new MediaType("text/css", "css"));
if (list != null && list.size() > 0) {
return list.get(0);
}
return null;
}
/**
* 获取图书的图片资源
*
* @return
*/
public List<Resource> getImagesResources(){
return getResources(
new MediaType("image/jpeg","jpg"),
new MediaType("image/gif","gif"),
new MediaType("image/png","png")
);
public List<Resource> getImagesResources() {
return getResources(new MediaType("image/jpeg", "jpg"), new MediaType("image/gif", "gif"),
new MediaType("image/png", "png"));
}
/**
*获取根据阅读顺序获取图书的内容资源(html)文件资源
* 获取根据阅读顺序获取图书的内容资源(html)文件资源
*
* @return
*/
public List<SpineReference> getSpineReferences(){
public List<SpineReference> getSpineReferences() {
return book.getSpine().getSpineReferences();
}
/**
*获取图书的目录结构标题及对应的资源内容
* 获取图书的目录结构标题及对应的资源内容
*
* @return
*/
public List<TOCReference> getTocReferences(){
public List<TOCReference> getTocReferences() {
return book.getTableOfContents().getTocReferences();
}
/**
* 获取图书
* @return
* author:haopeng
*
* @return author:haopeng
*/
public Book getBook(){
public Book getBook() {
return book;
}
/**
* 获取图书信息
* @return
* author:haopeng
* @throws Exception
*
* @return author:haopeng
* @throws Exception
*/
public Metadata getMetadata() throws Exception{
if(book==null){
throw new NullPointerException("图书Book属性为null");
}
return book.getMetadata();
public Metadata getMetadata() throws Exception {
if (book == null) {
throw new NullPointerException("图书Book属性为null");
}
return book.getMetadata();
}
/**
* 获取文件读取器
*
* @return
*/
private EpubReader getEpubReader(){
if(epubReader==null){
epubReader=new EpubReader();
private EpubReader getEpubReader() {
if (epubReader == null) {
epubReader = new EpubReader();
}
return epubReader;
}
/**
* 获取图书ISBN号
* @throws Exception
*/
public String getISBN() throws Exception{
String isbn=null;
List<Identifier> identifiers=getMetadata().getIdentifiers();
for(Identifier identifier:identifiers){
String value=identifier.getValue();
// if(value.matches("^97[8|9]\\d{10}$") ){//新版isbn号格式
if(value.contains("-")){
value=value.replaceAll("-", "");
isbn=value;
break;
*
* @throws Exception
*/
public String getISBN() throws Exception {
String isbn = null;
try {
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("ISBN")) {
isbn = identifier.getValue();
if (StringUtils.isNotBlank(isbn)) {
isbn = isbn.replace("-", "");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return isbn;
}
/**
* 获取图书作者
* 获取图书名称
*
* @throws Exception
*/
public String getAuthor(){
List<Author> authors = null;
public String getName() throws Exception {
String name = null;
/**
* 获取图书的名字
*/
// List<String> bookTitle2 = null;
try {
authors = getMetadata().getAuthors();
name = getMetadata().getFirstTitle();
// bookTitle2 = getMetadata().getTitles();
} catch (Exception e) {
e.printStackTrace();
}
String author = "";
if(authors.size()>0){
author = authors.get(0).getFirstname()+authors.get(0).getLastname();
author = author.replaceAll("[\\[\\],]"," ");
return name;
}
/**
* 获取图书作者
*
* @throws Exception
*/
public String getAuthor() throws Exception {
String author = null;
try {
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("creator")) {
author = identifier.getValue();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return author;
}
/**
* 获取出版日期
*/
public java.util.Date getPublishDate(){
List<Date> dates = null;
public java.util.Date getPublishDate() {
java.util.Date publicDate = null;
String date = null;
try {
dates = getMetadata().getDates();
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("date")) {
date = identifier.getValue();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
publicDate = sdf.parse(date);
}
}
} catch (Exception e) {
System.out.println("日期转换错误!");
e.printStackTrace();
}
SimpleDateFormat sdf = new SimpleDateFormat("yyy");
String tempDate = "";
if(dates.size()>0){
if(dates.get(0).toString().contains(".")){
sdf= new SimpleDateFormat("yyy.MM");
return publicDate;
}
/**
* 出版单位
*/
public String getPublisher() throws Exception {
String publisher = null;
try {
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("publisher")) {
publisher = identifier.getValue();
}
}
if(dates.get(0).toString().contains("-")){
sdf= new SimpleDateFormat("yyy-MM");
} catch (Exception e) {
e.printStackTrace();
}
return publisher;
}
/**
* 获取图书的字数
*/
public String getFontCount() {
String fontCount = null;
try {
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("words")) {
fontCount = identifier.getValue();
}
}
tempDate= dates.get(0).toString();
} catch (Exception e) {
e.printStackTrace();
}
java.util.Date publicDate = null;
return fontCount;
}
/**
* 获取图书的版次
*/
public String getRevision() {
String revision = null;
try {
if(tempDate!=null && !tempDate.equals("")){
publicDate = sdf.parse(tempDate);
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("version")) {
revision = identifier.getValue();
}
}
} catch (ParseException e) {
System.out.println("日期转换错误!");
} catch (Exception e) {
e.printStackTrace();
}
return publicDate;
return revision;
}
/**
* 出版单位
* 获取图书的关键词
*/
public String getPublisher(){
String publisher = "";
List<String> publishers;
public String getKeywords() {
String keywords = null;
try {
publishers = getMetadata().getPublishers();
for(String p : publishers){
if(p.contains("-")){
publisher = publisher + "、" + p;
break;
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("keywords")) {
keywords = identifier.getValue();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return publisher;
return keywords;
}
/**
* 获取图书的开本
*/
public String getFormat() {
String format = null;
try {
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("format")) {
format = identifier.getValue();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return format;
}
/**
* 获取图书的印张
*/
public String getPrintCount() {
String printcount = null;
try {
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("pagenumber")) {
printcount = identifier.getValue();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return printcount;
}
/**
* 获取图书的页数
*/
public String getTotalPages() {
String totalPages = null;
try {
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("pagenumber")) {
totalPages = identifier.getValue();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return totalPages;
}
/**
* 获取图书的印次
*/
public String getPrintNo() {
String printNo = null;
try {
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("printno")) {
printNo = identifier.getValue();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return printNo;
}
/**
* 获取图书的中图分类
*/
public String getMidpicid() {
String midpicid = null;
try {
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("clcnumber")) {
midpicid = identifier.getValue();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return midpicid;
}
/**
* 获取图书的邮编
*/
public String getZipcode() {
String zipcode = null;
try {
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("zipcode")) {
zipcode = identifier.getValue();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return zipcode;
}
/**
* 获取图书的CIP
*/
public String getCIP() {
String CIP = null;
try {
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("CIP")) {
CIP = identifier.getValue();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return CIP;
}
/**
* 获取图书的承印
*/
public String getPrint() {
String print = null;
try {
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("printcompany")) {
print = identifier.getValue();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return print;
}
/**
* 获取图书的名字
* 获取图书的定价
*/
public String getBookTitle(){
String bookTitle = "";
//List<String> bookTitle2 = null;
public BigDecimal getPrice() {
String price = null;
BigDecimal p = null;
try {
bookTitle = getMetadata().getFirstTitle();
//bookTitle2 = getMetadata().getTitles();
for (Identifier identifier : getMetadata().getIdentifiers()) {
if (identifier.getScheme().equals("price")) {
price = identifier.getValue();
if (StringUtils.isNotBlank(price)) {
p = new BigDecimal(price);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return bookTitle;
return p;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论