Skip to content

Commit

Permalink
修复bug,并且增加资料管理模块
Browse files Browse the repository at this point in the history
  • Loading branch information
amos-chen committed Apr 30, 2018
1 parent d83cddd commit 48277b8
Show file tree
Hide file tree
Showing 70 changed files with 3,737 additions and 479 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/config-manager/config-pojo/target/
/config-manager/config-service/target/
/config-manager/config-web/target/
/config-manager/config-web/src/test/
8 changes: 8 additions & 0 deletions config-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>fontbox</artifactId>
</dependency>
</dependencies>
<build />

Expand Down
219 changes: 219 additions & 0 deletions config-common/src/main/java/com/amos/utils/FtpUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
package com.amos.utils;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;

import javax.servlet.http.HttpServletResponse;
import java.io.*;

/**
* ftp上传下载工具类
* <p>Title: FtpUtil</p>
* <p>Description: </p>
* <p>Company: www.itcast.com</p>
*
* @author 入云龙
* @version 1.0
* @date 2015年7月29日下午8:11:51
*/
public class FtpUtil {

/**
* Description: 向FTP服务器上传文件
*
* @param host FTP服务器hostname
* @param port FTP服务器端口
* @param username FTP登录账号
* @param password FTP登录密码
* @param basePath FTP服务器基础目录
* @param filePath FTP服务器文件存放路径。例如分日期存放:/2015/01/01。文件的路径为basePath+filePath
* @param filename 上传到FTP服务器上的文件名
* @param input 输入流
* @return 成功返回true,否则返回false
*/
public static boolean uploadFile(String host, int port, String username, String password, String basePath,
String filePath, String filename, InputStream input) throws Exception {
boolean result = false;
FTPClient ftp = new FTPClient();
basePath = new String(basePath.getBytes(), "iso-8859-1");
filePath = new String(filePath.getBytes(), "iso-8859-1");
filename = new String(filename.getBytes(), "iso-8859-1");
try {
int reply;
ftp.connect(host, port);// 连接FTP服务器
// 如果采用默认端口,可以使用ftp.connect(host)的方式直接连接FTP服务器
ftp.login(username, password);// 登录
ftp.setControlEncoding("UTF-8");
ftp.enterLocalPassiveMode(); //设置被动模式 通知server端开通端口传输数据
ftp.setBufferSize(256);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return result;
}
//切换到上传目录
if (!ftp.changeWorkingDirectory(basePath + filePath)) {
//如果目录不存在创建目录
String[] dirs = filePath.split("/");
String tempPath = basePath;
for (String dir : dirs) {
if (null == dir || "".equals(dir)) continue;
tempPath += "/" + dir;
if (!ftp.changeWorkingDirectory(tempPath)) {
if (!ftp.makeDirectory(tempPath)) {
return result;
} else {
ftp.changeWorkingDirectory(tempPath);
}
}
}
}
//设置上传文件的类型为二进制类型
ftp.setFileType(FTP.BINARY_FILE_TYPE);
//上传文件
if (!ftp.storeFile(filename, input)) {
return result;
}
input.close();
ftp.logout();
result = true;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
}
}
}
return result;
}

/**
* Description: 从FTP服务器下载文件
*
* @param host FTP服务器hostname
* @param port FTP服务器端口
* @param username FTP登录账号
* @param password FTP登录密码
* @param remotePath FTP服务器上的相对路径
* @param fileName 要下载的文件名
* @param localPath 下载后保存到本地的路径
* @return
*/
public static boolean downloadFile(String host, int port, String username, String password, String remotePath,
String fileName, String localPath) {
boolean result = false;
FTPClient ftp = new FTPClient();
try {
remotePath = new String(remotePath.getBytes(), "iso-8859-1");
// fileName = new String(fileName.getBytes(), "iso-8859-1");
localPath = new String(localPath.getBytes(), "iso-8859-1");
int reply;
ftp.connect(host, port);
ftp.setControlEncoding("UTF-8");
ftp.enterLocalPassiveMode(); //设置被动模式 通知server端开通端口传输数据
ftp.setBufferSize(256);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
// 如果采用默认端口,可以使用ftp.connect(host)的方式直接连接FTP服务器
ftp.login(username, password);// 登录
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return result;
}
ftp.changeWorkingDirectory(remotePath);// 转移到FTP服务器目录
FTPFile[] fs = ftp.listFiles();
for (FTPFile ff : fs) {
if (ff.getName().equals(fileName)) {
File localFile = new File(localPath + "/" + ff.getName());
OutputStream is = new FileOutputStream(localFile);
ftp.retrieveFile(ff.getName(), is);
is.close();
}
}

ftp.logout();
result = true;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
}
}
}
return result;
}

public static boolean downloadFile(String host, int port, String username, String password, String remotePath,
String fileName, HttpServletResponse response) {
boolean result = false;
FTPClient ftp = new FTPClient();
try {
remotePath = new String(remotePath.getBytes(), "iso-8859-1");
// fileName = new String(fileName.getBytes(), "iso-8859-1");
int reply;
ftp.connect(host, port);
// 如果采用默认端口,可以使用ftp.connect(host)的方式直接连接FTP服务器
ftp.login(username, password);// 登录
ftp.enterLocalPassiveMode(); //设置被动模式 通知server端开通端口传输数据
ftp.setBufferSize(256);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.setControlEncoding("utf-8");
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return result;
}
ftp.changeWorkingDirectory(remotePath);// 转移到FTP服务器目录
FTPFile[] fs = ftp.listFiles();
for (FTPFile ff : fs) {
if (ff.getName().equals(fileName)) {
String fileNameNew = new String(fileName.getBytes(),"iso-8859-1");
OutputStream is = response.getOutputStream();
ftp.retrieveFile(fileNameNew, is);
is.close();
}
}
ftp.logout();
result = true;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
}
}
}
return result;
}

public static boolean deleteFile(String host, Integer port, String userName, String password,
String filePath, String fileName) {
boolean flag = false;
try {
FTPClient ftpClient = new FTPClient();
ftpClient.connect(host, port);
ftpClient.login(userName, password);
flag = ftpClient.deleteFile(filePath + fileName);
} catch (Exception e) {
e.printStackTrace();
}
return flag;
}

public static void main(String[] args) throws Exception {
File file = new File("C:\\Users\\Amos\\Desktop\\GB12-4.2规格书.pdf");
InputStream inputStream = new FileInputStream(file);
uploadFile("127.0.0.1", 21, "test", "123456", "/datasheet", "/GB系列", file.getName(), inputStream);
}
}
96 changes: 96 additions & 0 deletions config-common/src/main/java/com/amos/utils/PDFUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.amos.utils;

import org.apache.pdfbox.io.RandomAccessBuffer;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
* Created by ${chenlunwei} on 2018/4/28.
*/
public class PDFUtils {

public static List<Double> getDimension(InputStream inputStream) throws Exception {
PDFParser parser = new PDFParser(new RandomAccessBuffer(inputStream));
parser.parse();
PDDocument document = parser.getPDDocument();
int pages = document.getNumberOfPages();
// 读文本内容
PDFTextStripper stripper = new PDFTextStripper();
// 设置按顺序输出
stripper.setSortByPosition(true);
stripper.setStartPage(1);
stripper.setEndPage(pages);
String content = stripper.getText(document);
List<Double> dimensionList = new ArrayList<>();
String[] contentList = content.split("\n");
for (String string : contentList) {
if (string.contains("*")) {
System.out.println(1);
System.out.println(string);
string = string.replace("mm", "");
String[] temp = string.split("\\s+");
String dimension = temp[temp.length - 1];
String[] dimensions = dimension.split("\\*");
for (String str : dimensions) {
dimensionList.add(Double.parseDouble(str));
}
} else if (string.contains("×")) {
if (string.contains("mm×")) {
System.out.println(2);
System.out.println(string);
string = string.replace("mm", "");
String[] originTemp = string.split("\\s+");
String dimensionTemp = originTemp[originTemp.length - 1];
String[] temp = dimensionTemp.split("×");
if (dimensionTemp.contains("L")) {
for (int i = 0; i < temp.length; i++) {
dimensionList.add(Double.parseDouble(temp[i].substring(1)));
}
}else{
for (int i = 0; i < temp.length; i++) {
dimensionList.add(Double.parseDouble(temp[i]));
}
}
} else {
System.out.println(3);
System.out.println(string);
string = string.replace("mm", "");
String[] temp = string.split("\\s+");
String dimension = temp[temp.length - 1];
String[] dimensions = dimension.split("×");
for (String str : dimensions) {
dimensionList.add(Double.parseDouble(str));
}
}
} else if (string.contains("Dimension (mm)")) {
System.out.println(4);
System.out.println(string);
string = string.replace("mm", "").replace("x", "");
String[] temp = string.split("\\s+");
for (int i = 0; i < temp.length; i++) {
if (i > 1) {
dimensionList.add(Double.parseDouble(temp[i].substring(1)));
}
}
}
}

for (double d : dimensionList) {
System.out.println(d);
}
return dimensionList;
}


public static void main(String[] args) throws Exception {
File file = new File("C:\\Users\\Amos\\Desktop\\规格书\\LSE2-200.pdf");
getDimension(new FileInputStream(file));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ public interface ApplicationInfoMapper {

int updateBatchByPrimaryKeySelective(List<ApplicationInfo> records);

List<ApplicationInfo> selectList(@Param("search") String search);
List<ApplicationInfo> selectList(@Param("search") String search,@Param("order") String order);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ public interface ConfigurationInfoMapper {
int updateBatchByPrimaryKeySelective(List<ConfigurationInfo> records);

ConfigurationInfo selectBaseInfoById(@Param("configId") Integer configId);

ConfigurationInfo selectFullInfoById(@Param("configId") Integer configId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.amos.dao;

import com.amos.pojo.HardwareCategory;

import java.util.List;

/**
* Created by ${chenlunwei} on 2018/4/11.
*/
public interface HardwareCategoryMapper {

int insertCategory(HardwareCategory hardwareCategory);

HardwareCategory selectByPrimaryKey(Integer id);

int updateByPrimaryKey(HardwareCategory hardwareCategory);

int deleteByPrimaryKey(Integer id);

List<HardwareCategory> selectList();

List<HardwareCategory> queryByParentId(Integer parentId);

String queryCatName(Integer id);
}
Loading

0 comments on commit 48277b8

Please sign in to comment.