首次git提交,用于lichx个人的多端同步
This commit is contained in:
commit
d3a94abd6d
|
|
@ -0,0 +1,29 @@
|
|||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="@127.0.0.1" uuid="11d26e98-f022-4cdd-82a4-a9a4a1456d73">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://127.0.0.1:3306</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<component name="libraryTable">
|
||||
<library name="mysql-connector-java-8.0.27">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/libs/mysql-connector-java-8.0.27.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="20" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Object-oriented vs. multithreaded synthesis experiments.iml" filepath="$PROJECT_DIR$/Object-oriented vs. multithreaded synthesis experiments.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="mysql-connector-java-8.0.27" level="project" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="file://$MODULE_DIR$/../../../Java-lib/javafx-sdk-20.0.1/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<jarDirectory url="file://$MODULE_DIR$/../../../Java-lib/javafx-sdk-20.0.1/lib" recursive="false" />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
||||
Binary file not shown.
|
|
@ -0,0 +1,119 @@
|
|||
package com.qst.dms.db;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
import com.qst.dms.util.Config;
|
||||
|
||||
|
||||
public class DBUtil {
|
||||
Connection conn = null;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
/**
|
||||
* 得到数据库连接
|
||||
*/
|
||||
public Connection getConnection() throws ClassNotFoundException,
|
||||
SQLException, InstantiationException, IllegalAccessException {
|
||||
// 通过Config获取MySQL数据库配置信息
|
||||
String driver = Config.getValue("driver");
|
||||
String url = Config.getValue("url");
|
||||
String user = Config.getValue("user");
|
||||
String pwd = Config.getValue("password");
|
||||
try {
|
||||
// 指定驱动程序
|
||||
Class.forName(driver);
|
||||
// 建立数据库连结
|
||||
conn = DriverManager.getConnection(url, user, pwd);
|
||||
return conn;
|
||||
} catch (Exception e) {
|
||||
// 如果连接过程出现异常,抛出异常信息
|
||||
throw new SQLException("驱动错误或连接失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放资源
|
||||
*/
|
||||
public void closeAll() {
|
||||
// 如果rs不空,关闭rs
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// 如果pstmt不空,关闭pstmt
|
||||
if (pstmt != null) {
|
||||
try {
|
||||
pstmt.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// 如果conn不空,关闭conn
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行SQL语句,可以进行查询
|
||||
*/
|
||||
public ResultSet executeQuery(String preparedSql, Object[] param) {
|
||||
// 处理SQL,执行SQL
|
||||
try {
|
||||
// 得到PreparedStatement对象
|
||||
pstmt = conn.prepareStatement(preparedSql);
|
||||
if (param != null) {
|
||||
for (int i = 0; i < param.length; i++) {
|
||||
// 为预编译sql设置参数
|
||||
pstmt.setObject(i + 1, param[i]);
|
||||
}
|
||||
}
|
||||
// 执行SQL语句
|
||||
rs = pstmt.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
// 处理SQLException异常
|
||||
e.printStackTrace();
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行SQL语句,可以进行增、删、改的操作,不能执行查询
|
||||
*/
|
||||
public int executeUpdate(String preparedSql, Object[] param) throws SQLIntegrityConstraintViolationException
|
||||
{
|
||||
int num = 0;
|
||||
// 处理SQL,执行SQL
|
||||
try {
|
||||
// 得到PreparedStatement对象
|
||||
pstmt = conn.prepareStatement(preparedSql);
|
||||
if (param != null) {
|
||||
for (int i = 0; i < param.length; i++) {
|
||||
// 为预编译sql设置参数
|
||||
pstmt.setObject(i + 1, param[i]);
|
||||
}
|
||||
}
|
||||
// 执行SQL语句
|
||||
num = pstmt.executeUpdate();
|
||||
}
|
||||
catch(SQLIntegrityConstraintViolationException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
//你都catch完了 我catch啥 那SQLIntegrityConstraintViolationException应该打印吗?
|
||||
//我觉得直接catch然后throw给外部吧
|
||||
catch (SQLException e) {
|
||||
// 处理SQLException异常
|
||||
e.printStackTrace();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
driver = com.mysql.cj.jdbc.Driver
|
||||
url = jdbc:mysql://localhost:3306/q_dms?useUnicode=true&characterEncoding=UTF-8
|
||||
user = root
|
||||
password = 123456
|
||||
serverIP=127.0.0.1
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package com.qst.dms.dos;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
import com.qst.dms.entity.DataBase;
|
||||
import com.qst.dms.entity.LogRec;
|
||||
import com.qst.dms.entity.MatchedLogRec;
|
||||
import com.qst.dms.entity.MatchedTransport;
|
||||
import com.qst.dms.entity.Transport;
|
||||
import com.qst.dms.service.LogRecService;
|
||||
import com.qst.dms.service.TransportService;
|
||||
|
||||
public class DBDemo {
|
||||
public static void main(String[] args) {
|
||||
// 创建一个日志业务类
|
||||
LogRecService logService = new LogRecService();
|
||||
ArrayList<MatchedLogRec> matchLogs = new ArrayList<>();
|
||||
matchLogs.add(new MatchedLogRec(
|
||||
new LogRec(1001, new Date(), "青島",DataBase.GATHER, "zhangsan", "192.168.1.1", 1),
|
||||
new LogRec(1002, new Date(), "青島", DataBase.GATHER, "zhangsan", "192.168.1.1", 0)));
|
||||
matchLogs.add(new MatchedLogRec(
|
||||
new LogRec(1003, new Date(), "北京",DataBase.GATHER, "lisi", "192.168.1.6", 1),
|
||||
new LogRec(1004, new Date(), "北京", DataBase.GATHER, "lisi", "192.168.1.6", 0)));
|
||||
matchLogs.add(new MatchedLogRec(
|
||||
new LogRec(1005, new Date(), "济南",DataBase.GATHER, "wangwu", "192.168.1.89", 1),
|
||||
new LogRec(1006, new Date(), "济南", DataBase.GATHER, "wangwu", "192.168.1.89", 0)));
|
||||
//保存匹配的日志信息到数据库中
|
||||
logService.saveMatchLogToDB(matchLogs);
|
||||
//从数据库中读取匹配的日志信息
|
||||
ArrayList<MatchedLogRec> logList = null;
|
||||
try
|
||||
{
|
||||
logList = logService.readMatchedLogFromDB();
|
||||
} catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
logService.showMatchLog(logList);
|
||||
|
||||
// 创建一个物流业务类
|
||||
TransportService tranService = new TransportService();
|
||||
ArrayList<MatchedTransport> matchTrans = new ArrayList<>();
|
||||
matchTrans.add(new MatchedTransport(
|
||||
new Transport(2001, new Date(), "青島",DataBase.GATHER,"zhangsan","zhaokel",1),
|
||||
new Transport(2002, new Date(), "北京",DataBase.GATHER,"lisi","zhaokel",2),
|
||||
new Transport(2003, new Date(), "北京",DataBase.GATHER,"wangwu","zhaokel",3)));
|
||||
matchTrans.add(new MatchedTransport(
|
||||
new Transport(2004, new Date(), "青島",DataBase.GATHER,"maliu","w",1),
|
||||
new Transport(2005, new Date(), "北京",DataBase.GATHER,"sunqi","w",2),
|
||||
new Transport(2006, new Date(), "北京",DataBase.GATHER,"fengba","w",3)));
|
||||
//保存匹配的物流信息到数据库中
|
||||
tranService.saveMatchTransportToDB(matchTrans);
|
||||
//从数据库中中读取匹配的物流信息
|
||||
ArrayList<MatchedTransport> transportList = null;
|
||||
try
|
||||
{
|
||||
transportList = tranService.readMatchedTransportFromDB();
|
||||
} catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
tranService.showMatchTransport(transportList);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.qst.dms.dos;
|
||||
|
||||
import com.qst.dms.entity.LogRec;
|
||||
import com.qst.dms.entity.Transport;
|
||||
import com.qst.dms.service.LogRecService;
|
||||
import com.qst.dms.service.TransportService;
|
||||
|
||||
public class EntityDataDemo {
|
||||
public static void main(String[] args) {
|
||||
// 创建一个日志业务类
|
||||
LogRecService logService = new LogRecService();
|
||||
// 创建一个日志对象数组,用于存放采集的三个日志信息
|
||||
LogRec[] logs = new LogRec[3];
|
||||
for (int i = 0; i < logs.length; i++) {
|
||||
System.out.println("第"+(i+1)+"个日志数据采集:");
|
||||
logs[i] = logService.inputLog();
|
||||
}
|
||||
// 输出采集的日志信息
|
||||
logService.showLog(logs);
|
||||
|
||||
// 创建一个物流业务类
|
||||
TransportService tranService = new TransportService();
|
||||
// 创建一个物流对象数组,用于存放采集的两个物流信息
|
||||
Transport[] transports = new Transport[2];
|
||||
for (int i = 0; i < transports.length; i++) {
|
||||
System.out.println("第"+(i+1)+"个物流数据采集:");
|
||||
transports[i] = tranService.inputTransport();
|
||||
}
|
||||
//输出采集的物流信息
|
||||
tranService.showTransport(transports);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.qst.dms.dos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
import com.qst.dms.entity.DataBase;
|
||||
import com.qst.dms.entity.LogRec;
|
||||
import com.qst.dms.entity.MatchedLogRec;
|
||||
import com.qst.dms.entity.MatchedTransport;
|
||||
import com.qst.dms.entity.Transport;
|
||||
import com.qst.dms.service.LogRecService;
|
||||
import com.qst.dms.service.TransportService;
|
||||
|
||||
public class FileDemo {
|
||||
public static void main(String[] args) {
|
||||
// 创建一个日志业务类
|
||||
LogRecService logService = new LogRecService();
|
||||
ArrayList<MatchedLogRec> matchLogs = new ArrayList<>();
|
||||
matchLogs.add(new MatchedLogRec(
|
||||
new LogRec(1001, new Date(), "青島",DataBase.GATHER, "zhangsan", "192.168.1.1", 1),
|
||||
new LogRec(1002, new Date(), "青島", DataBase.GATHER, "zhangsan", "192.168.1.1", 0)));
|
||||
matchLogs.add(new MatchedLogRec(
|
||||
new LogRec(1003, new Date(), "北京",DataBase.GATHER, "lisi", "192.168.1.6", 1),
|
||||
new LogRec(1004, new Date(), "北京", DataBase.GATHER, "lisi", "192.168.1.6", 0)));
|
||||
matchLogs.add(new MatchedLogRec(
|
||||
new LogRec(1005, new Date(), "济南",DataBase.GATHER, "wangwu", "192.168.1.89", 1),
|
||||
new LogRec(1006, new Date(), "济南", DataBase.GATHER, "wangwu", "192.168.1.89", 0)));
|
||||
//保存匹配的日志信息到文件中
|
||||
//logService.saveMatchLog(matchLogs);
|
||||
logService.saveAndAppendMatchLog(matchLogs); //追加测试
|
||||
//保存匹配的日志信息到数据库中
|
||||
//logService.saveMatchLogToDB(matchLogs);
|
||||
//从文件中读取匹配的日志信息
|
||||
ArrayList<MatchedLogRec> list1 = logService.readMatchLog();
|
||||
logService.showMatchLog(list1);
|
||||
|
||||
// 创建一个物流业务类
|
||||
TransportService tranService = new TransportService();
|
||||
ArrayList<MatchedTransport> matchTrans = new ArrayList<>();
|
||||
matchTrans.add(new MatchedTransport(
|
||||
new Transport(2001, new Date(), "青島",DataBase.GATHER,"zhangsan","zhaokel",1),
|
||||
new Transport(2002, new Date(), "北京",DataBase.GATHER,"lisi","zhaokel",2),
|
||||
new Transport(2003, new Date(), "北京",DataBase.GATHER,"wangwu","zhaokel",3)));
|
||||
matchTrans.add(new MatchedTransport(
|
||||
new Transport(2004, new Date(), "青島",DataBase.GATHER,"maliu","zhaokel",1),
|
||||
new Transport(2005, new Date(), "北京",DataBase.GATHER,"sunqi","zhaokel",2),
|
||||
new Transport(2006, new Date(), "北京",DataBase.GATHER,"fengba","zhaokel",3)));
|
||||
//保存匹配的物流信息到文件中
|
||||
tranService.saveMatchedTransport(matchTrans);
|
||||
//保存匹配的物流信息到数据库中
|
||||
//tranService.saveMatchTransportToDB(matchTrans);
|
||||
//从文件中读取匹配的物流信息
|
||||
ArrayList<MatchedTransport> list2 = tranService.readMatchedTransport();
|
||||
tranService.showMatchTransport(list2);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.qst.dms.dos;
|
||||
|
||||
import com.qst.dms.entity.LogRec;
|
||||
import com.qst.dms.service.LogRecService;
|
||||
|
||||
public class LogRecDemo {
|
||||
public static void main(String[] args) {
|
||||
// 创建一个日志业务类
|
||||
LogRecService logService = new LogRecService();
|
||||
// 创建一个日志对象数组,用于存放采集的三个日志信息
|
||||
LogRec[] logs = new LogRec[3];
|
||||
for (int i = 0; i < logs.length; i++) {
|
||||
System.out.println("第" + (i + 1) + "个日志数据采集:");
|
||||
logs[i] = logService.inputLog();
|
||||
}
|
||||
// 显示日志信息
|
||||
logService.showLog(logs);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,210 @@
|
|||
package com.qst.dms.dos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import com.qst.dms.entity.LogRec;
|
||||
import com.qst.dms.entity.MatchedLogRec;
|
||||
import com.qst.dms.entity.MatchedTransport;
|
||||
import com.qst.dms.entity.Transport;
|
||||
import com.qst.dms.gather.LogRecAnalyse;
|
||||
import com.qst.dms.gather.TransportAnalyse;
|
||||
import com.qst.dms.service.LogRecService;
|
||||
import com.qst.dms.service.TransportService;
|
||||
|
||||
public class MenuDriver
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// 建立一个从键盘接收数据的扫描器
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
// 创建一个泛型ArrayList集合存储日志数据
|
||||
ArrayList<LogRec> logRecList = new ArrayList<>();
|
||||
// 创建一个泛型ArrayList集合存储物流数据
|
||||
ArrayList<Transport> transportList = new ArrayList<>();
|
||||
|
||||
// 创建一个日志业务类
|
||||
LogRecService logService = new LogRecService();
|
||||
// 创建一个物流业务类
|
||||
TransportService tranService = new TransportService();
|
||||
|
||||
// 日志数据匹配集合
|
||||
ArrayList<MatchedLogRec> matchedLogs = null;
|
||||
// 物流数据匹配集合
|
||||
ArrayList<MatchedTransport> matchedTrans = null;
|
||||
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
// 输出菜单界面,需补充
|
||||
//...
|
||||
System.out.println("********************************************");
|
||||
System.out.println("欢迎进入日志物流信息管理系统!");
|
||||
System.out.println("* 1、数据采集 2、数据匹配 *");
|
||||
System.out.println("* 3、数据记录 4、数据显示 *");
|
||||
System.out.println("* 5、数据发送 0、退出应用 *");
|
||||
System.out.println("********************************************");
|
||||
// 提示用户输入要操作的菜单项
|
||||
System.out.println("请输入菜单项(0~5):");
|
||||
// 接收键盘输入的选项
|
||||
int choice;
|
||||
for (; ; )
|
||||
try
|
||||
{
|
||||
choice = scanner.nextInt();
|
||||
break;
|
||||
} catch (InputMismatchException e)
|
||||
{
|
||||
System.out.println("输入数据不合法,请重新输入");
|
||||
scanner.nextLine();
|
||||
}
|
||||
switch (choice)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
System.out.println("请输入采集数据类型:1.日志 2.物流");
|
||||
// 接收键盘输入的选项
|
||||
int type = scanner.nextInt();
|
||||
if (type == 1)
|
||||
{
|
||||
System.out.println("正在采集日志数据,请输入正确信息,确保数据的正常采集!");
|
||||
// 采集日志数据,需补充LogService类中的inputLog方法
|
||||
LogRec log = logService.inputLog();
|
||||
// 将采集的日志数据添加到logRecList集合中
|
||||
logRecList.add(log);
|
||||
} else if (type == 2)
|
||||
{
|
||||
System.out.println("正在采集物流数据,请输入正确信息,确保数据的正常采集!");
|
||||
// 采集物流数据,需补充tranService类中的inputTransport方法
|
||||
Transport tran = tranService.inputTransport();
|
||||
// 将采集的物流数据添加到transportList集合中
|
||||
transportList.add(tran);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
System.out.println("请输入匹配数据类型:1.日志 2.物流");
|
||||
// 接收键盘输入的选项
|
||||
int type = scanner.nextInt();
|
||||
if (type == 1)
|
||||
{
|
||||
System.out.println("正在日志数据过滤匹配...");
|
||||
// 创建日志数据分析对象,用于日志数据筛选与匹配
|
||||
LogRecAnalyse logAn = new LogRecAnalyse(logRecList);
|
||||
// 需实现doFilter抽象方法,对日志数据进行过滤,根据日志登录状态
|
||||
//分别放在登录和登出两个集合中
|
||||
logAn.doFilter();
|
||||
// 日志数据分析
|
||||
matchedLogs = logAn.matchData();
|
||||
System.out.println("日志数据过滤匹配完成!");
|
||||
} else if (type == 2)
|
||||
{
|
||||
System.out.println("正在物流数据过滤匹配...");
|
||||
// 创建物流数据分析对象
|
||||
TransportAnalyse transAn = new TransportAnalyse(
|
||||
transportList);
|
||||
// 物流数据过滤
|
||||
transAn.doFilter();
|
||||
// 物流数据分析
|
||||
matchedTrans = transAn.matchData();
|
||||
System.out.println("物流数据过滤匹配完成!");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
System.out.println("请输入记录数据类型:1.日志 2.物流");
|
||||
int type = 0;
|
||||
while (true)
|
||||
{
|
||||
if (scanner.hasNextInt())
|
||||
{
|
||||
type = scanner.nextInt();
|
||||
if (type >= 1 && type <= 2)
|
||||
break;
|
||||
else
|
||||
System.out.println("请输入合法的数字");
|
||||
} else
|
||||
{
|
||||
System.out.println("请输入合法的数字");
|
||||
scanner.nextLine();
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
if (type == 1)
|
||||
{
|
||||
//logService.saveMatchLog(matchedLogs); 2023.11.17 改为追加方式
|
||||
logService.saveAndAppendMatchLog(matchedLogs);
|
||||
logService.saveMatchLogToDB(matchedLogs);//添加至DB
|
||||
logRecList.clear();
|
||||
matchedLogs.clear();
|
||||
//添加数据库追加
|
||||
} else if (type == 2)
|
||||
{
|
||||
//tranService.saveMatchedTransport(matchedTrans); 2023.11.17 改为追加方式
|
||||
tranService.saveAndAppendTransport(matchedTrans);
|
||||
tranService.saveMatchTransportToDB(matchedTrans);//添加至DB
|
||||
transportList.clear();
|
||||
matchedTrans.clear();
|
||||
}
|
||||
}
|
||||
catch(NullPointerException ex)
|
||||
{
|
||||
System.out.println("没有信息需要记录");
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
System.out.println("显示匹配的数据:");
|
||||
// ArrayList<MatchedLogRec> last_log = logService.readMatchLog();
|
||||
// ArrayList<MatchedTransport> last_transport = tranService.readMatchedTransport(); 2023.11.25改为读取数据库数据
|
||||
ArrayList<MatchedLogRec>last_log = logService.readMatchedLogFromDB();
|
||||
ArrayList<MatchedTransport>last_transport = tranService.readMatchedTransportFromDB();
|
||||
if (last_log.isEmpty() && (matchedLogs == null || matchedLogs.isEmpty()))
|
||||
{
|
||||
System.out.println("匹配的日志记录是0条!");
|
||||
} else
|
||||
{
|
||||
//输出匹配的日志信息
|
||||
System.out.println("日志:");
|
||||
if (!last_log.isEmpty())
|
||||
logService.showMatchLog(last_log);
|
||||
if (matchedLogs != null && (!matchedLogs.isEmpty()))
|
||||
logService.showMatchLog(matchedLogs);
|
||||
}
|
||||
if (last_transport.isEmpty() && (matchedTrans == null || matchedTrans.isEmpty()))
|
||||
{
|
||||
System.out.println("匹配的物流记录是0条!");
|
||||
} else
|
||||
{
|
||||
// 输出匹配的物流信息
|
||||
System.out.println("物流:");
|
||||
if (!last_transport.isEmpty())
|
||||
tranService.showMatchTransport(last_transport);
|
||||
if (matchedTrans != null && (!matchedTrans.isEmpty()))
|
||||
tranService.showMatchTransport(matchedTrans);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
System.out.println("数据发送 中...");
|
||||
break;
|
||||
case 0:
|
||||
// 应用程序退出
|
||||
System.exit(0);
|
||||
default:
|
||||
System.out.println("请输入正确的菜单项(0~5)!");
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e)
|
||||
{
|
||||
System.out.println("输入的数据不合法!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.qst.dms.dos;
|
||||
|
||||
import com.qst.dms.entity.Transport;
|
||||
import com.qst.dms.service.TransportService;
|
||||
|
||||
public class TransportDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 创建一个物流业务类
|
||||
TransportService tranService = new TransportService();
|
||||
// 创建一个物流对象数组,用于存放采集的四个物流信息
|
||||
Transport[] transports = new Transport[4];
|
||||
for (int i = 0; i < transports.length; i++) {
|
||||
System.out.println("第" + (i + 1) + "个物流数据采集:");
|
||||
transports[i] = tranService.inputTransport();
|
||||
}
|
||||
// 显示物流信息
|
||||
tranService.showTransport(transports);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.qst.dms.entity;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
public class AppendObjectOutputStream extends ObjectOutputStream
|
||||
{
|
||||
public static File file = null;
|
||||
public AppendObjectOutputStream() throws IOException
|
||||
{
|
||||
super(new FileOutputStream(file,true));
|
||||
//AppendObjectOutputStream.file = file; 这不可行 因为 上面的构造函数调用了writeStreamHeadler 然后file=null 所以需要在外部提前赋值
|
||||
}
|
||||
public void writeStreamHeader() throws IOException
|
||||
{
|
||||
if(file!=null)
|
||||
{
|
||||
if (file.length() == 0)
|
||||
super.writeStreamHeader();
|
||||
else
|
||||
{
|
||||
//super.
|
||||
this.reset();
|
||||
}
|
||||
} else
|
||||
super.writeStreamHeader();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
package com.qst.dms.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
//数据基础类
|
||||
|
||||
public class DataBase implements Serializable{
|
||||
// ID标识
|
||||
private int id;
|
||||
// 时间
|
||||
private Date time;
|
||||
// 地点
|
||||
private String address;
|
||||
// 状态
|
||||
private int type;
|
||||
// 状态常量
|
||||
public static final int GATHER=1;//"采集"
|
||||
public static final int MATHCH=2;//"匹配";
|
||||
public static final int RECORD=3;//"记录";
|
||||
public static final int SEND=4;//"发送";
|
||||
public static final int RECIVE=5;//"接收";
|
||||
public static final int WRITE=6;//"归档";
|
||||
public static final int SAVE=7;//"保存";
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public Date getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
public void setTime(Date time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public DataBase() {
|
||||
}
|
||||
|
||||
public DataBase(int id, Date time, String address, int type) {
|
||||
this.id = id;
|
||||
this.time = time;
|
||||
this.address = address;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return id + "," + time + "," + address + "," + type;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
|
||||
package com.qst.dms.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
|
||||
//用户登录日志记录
|
||||
public class LogRec extends DataBase implements Serializable{
|
||||
/**
|
||||
* 登录用户名
|
||||
*/
|
||||
private String user;
|
||||
/**
|
||||
* 登录用户主机IP地址
|
||||
*/
|
||||
private String ip;
|
||||
/**
|
||||
* 登录状态:登录、登出
|
||||
*/
|
||||
private int logType;
|
||||
/**
|
||||
* 登录常量LOG_IN、登出常量常量LOG_OUT
|
||||
*/
|
||||
public static final int LOG_IN=1;
|
||||
public static final int LOG_OUT=0;
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public int getLogType() {
|
||||
return logType;
|
||||
}
|
||||
|
||||
public static LogRec get_LogRec(Object[] info)
|
||||
{
|
||||
int id = (int)info[0],type = (int)info[3],logtype = (int)info[6];
|
||||
Date time = Date.from( ((LocalDateTime)info[1]).atZone( ZoneId.systemDefault()).toInstant());
|
||||
String address = (String)info[2],username = (String)info[4],ip = (String)info[5];
|
||||
return new LogRec(id,time,address,type,username,ip,logtype);
|
||||
}
|
||||
public Object[] get_DB_param()
|
||||
{
|
||||
return new Object[]{
|
||||
this.getId(),
|
||||
new Timestamp(this.getTime().getTime()),
|
||||
this.getAddress(),this.getType(),this.getUser(),
|
||||
this.getIp(),this.getLogType()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void setLogType(int logType) {
|
||||
this.logType = logType;
|
||||
}
|
||||
|
||||
public LogRec() {
|
||||
}
|
||||
|
||||
public LogRec(int id, Date time, String address, int type,String user,String ip,int logType) {
|
||||
super(id,time,address,type);
|
||||
this.user=user;
|
||||
this.ip=ip;
|
||||
this.logType=logType;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getId() + "," +this.getTime() + "," +this.getAddress() + "," + this.getType() + ","+user+","+ip+","+logType;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
|
||||
package com.qst.dms.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
//匹配日志记录,"登录登出对" 类型
|
||||
|
||||
public class MatchedLogRec implements Serializable {
|
||||
|
||||
private LogRec login;
|
||||
private LogRec logout;
|
||||
|
||||
// user用户登录名
|
||||
public String getUser() {
|
||||
return login.getUser();
|
||||
}
|
||||
|
||||
//登录地点
|
||||
public String getAddress(){return login.getAddress();}
|
||||
// 登入时刻
|
||||
public Date getLogInTime() {
|
||||
return login.getTime();
|
||||
}
|
||||
|
||||
// 登出时刻
|
||||
public Date getLogoutTime() {
|
||||
return logout.getTime();
|
||||
}
|
||||
|
||||
// 登入记录
|
||||
public LogRec getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
// 登出记录
|
||||
public LogRec getLogout() {
|
||||
return logout;
|
||||
}
|
||||
|
||||
public Object[] get_DB_param()
|
||||
{
|
||||
return new Object[]{
|
||||
login.getId(),logout.getId()
|
||||
};
|
||||
}
|
||||
public MatchedLogRec() {
|
||||
}
|
||||
|
||||
public MatchedLogRec(LogRec login, LogRec logout) {
|
||||
if (login.getLogType() != LogRec.LOG_IN) {
|
||||
throw new RuntimeException("不是登录记录!");
|
||||
}
|
||||
if (logout.getLogType() != LogRec.LOG_OUT) {
|
||||
throw new RuntimeException("不是登出记录");
|
||||
}
|
||||
if (!login.getUser().equals(logout.getUser())) {
|
||||
throw new RuntimeException("登录登出必须是同一个用户!");
|
||||
}
|
||||
if (!login.getIp().equals(logout.getIp())) {
|
||||
throw new RuntimeException("登录登出必须是同一个IP地址!");
|
||||
}
|
||||
this.login = login;
|
||||
this.logout = logout;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return login.toString() + " | " + logout.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* @公司 青软实训QST
|
||||
* @作者 zhaokl
|
||||
*/
|
||||
package com.qst.dms.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class MatchedTransport implements Serializable{
|
||||
private Transport send;
|
||||
private Transport trans;
|
||||
private Transport receive;
|
||||
|
||||
public Transport getSend() {
|
||||
return send;
|
||||
}
|
||||
|
||||
public void setSend(Transport send) {
|
||||
this.send = send;
|
||||
}
|
||||
|
||||
public Transport getTrans() {
|
||||
return trans;
|
||||
}
|
||||
|
||||
public void setTrans(Transport trans) {
|
||||
this.trans = trans;
|
||||
}
|
||||
|
||||
public Transport getReceive() {
|
||||
return receive;
|
||||
}
|
||||
|
||||
public void setReceive(Transport receive) {
|
||||
this.receive = receive;
|
||||
}
|
||||
|
||||
public MatchedTransport() {
|
||||
|
||||
}
|
||||
|
||||
public MatchedTransport(Transport send, Transport trans, Transport receive) {
|
||||
if (send.getTransportType() != Transport.SENDING) {
|
||||
throw new RuntimeException("不是发货记录!");
|
||||
}
|
||||
if (trans.getTransportType() != Transport.TRANSPORTING) {
|
||||
throw new RuntimeException("不是送货记录!");
|
||||
}
|
||||
if (receive.getTransportType() != Transport.RECEIVED) {
|
||||
throw new RuntimeException("不是签收记录!");
|
||||
}
|
||||
this.send = send;
|
||||
this.trans = trans;
|
||||
this.receive = receive;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
// TODO Auto-generated method stub
|
||||
return send.toString() + "|" + trans.toString() + "|" + receive;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/**
|
||||
* @公司 青软实训QST
|
||||
* @作者 zhaokl
|
||||
*/
|
||||
package com.qst.dms.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
|
||||
//货运物流信息
|
||||
public class Transport extends DataBase implements Serializable{
|
||||
/**
|
||||
* 经手人
|
||||
*/
|
||||
private String handler;
|
||||
/**
|
||||
* 收货人
|
||||
*/
|
||||
private String reciver;
|
||||
/**
|
||||
* 物流状态
|
||||
*/
|
||||
private int transportType;
|
||||
/**
|
||||
* 物流状态常量:发货中, 送货中, 已签收
|
||||
*/
|
||||
public static final int SENDING = 1;// 发货中
|
||||
public static final int TRANSPORTING = 2;// 送货中
|
||||
public static final int RECEIVED = 3;// 已签收
|
||||
|
||||
public String getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public void setHandler(String handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public String getReciver() {
|
||||
return reciver;
|
||||
}
|
||||
|
||||
public void setReciver(String reciver) {
|
||||
this.reciver = reciver;
|
||||
}
|
||||
|
||||
public int getTransportType() {
|
||||
return transportType;
|
||||
}
|
||||
|
||||
public void setTransportType(int transportType) {
|
||||
this.transportType = transportType;
|
||||
}
|
||||
|
||||
public Transport() {
|
||||
|
||||
}
|
||||
|
||||
public Transport(int id, Date time, String address, int type,
|
||||
String handler, String reciver, int transportType) {
|
||||
super(id, time, address, type);
|
||||
this.handler = handler;
|
||||
this.reciver = reciver;
|
||||
this.transportType = transportType;
|
||||
}
|
||||
|
||||
static public Transport get_Transport(Object[] info)
|
||||
{
|
||||
int id = (Integer) info[0],type = (Integer) info[3],transportType = (Integer) info[6];
|
||||
Date time = Date.from( ((LocalDateTime)info[1]).atZone( ZoneId.systemDefault()).toInstant());
|
||||
String address = (String) info[2],handler = (String) info[4],reciver = (String)info[5];
|
||||
return new Transport(id,time,address,type,handler,reciver,transportType);
|
||||
}
|
||||
|
||||
public Object[] get_DB_param()
|
||||
{
|
||||
return new Object[]{
|
||||
this.getId(),new Timestamp(this.getTime().getTime()),
|
||||
this.getAddress(),this.getType(),this.getHandler(),this.getReciver(),
|
||||
this.getTransportType()
|
||||
};
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getId() + "," + this.getTime() + "," + this.getAddress()
|
||||
+ "," + this.getType() + "," + handler + "," + transportType;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
package com.qst.dms.entity;
|
||||
|
||||
//用户实体
|
||||
public class User {
|
||||
// 用户id
|
||||
private int id;
|
||||
// 用户名
|
||||
private String username;
|
||||
// 密码
|
||||
private String password;
|
||||
// 性别
|
||||
private int sex;
|
||||
// 爱好
|
||||
private String hobby;
|
||||
// 地址
|
||||
private String address;
|
||||
// 学历
|
||||
private String degree;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public int getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(int sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public String getHobby() {
|
||||
return hobby;
|
||||
}
|
||||
|
||||
public void setHobby(String hobby) {
|
||||
this.hobby = hobby;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getDegree() {
|
||||
return degree;
|
||||
}
|
||||
|
||||
public void setDegree(String degree) {
|
||||
this.degree = degree;
|
||||
}
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(String username, String password, int sex, String hobby,
|
||||
String address, String degree) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.sex = sex;
|
||||
this.hobby = hobby;
|
||||
this.address = address;
|
||||
this.degree = degree;
|
||||
}
|
||||
|
||||
public User(int id, String username, String password, int sex,
|
||||
String hobby, String address, String degree) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.sex = sex;
|
||||
this.hobby = hobby;
|
||||
this.address = address;
|
||||
this.degree = degree;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.qst.dms.exception;
|
||||
|
||||
public class DataAnalyseException extends Exception {
|
||||
public DataAnalyseException() {
|
||||
}
|
||||
|
||||
public DataAnalyseException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.qst.dms.gather;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.qst.dms.entity.DataBase;
|
||||
|
||||
//数据过滤抽象类
|
||||
public abstract class DataFilter {
|
||||
// 数据集合,使用泛型集合
|
||||
private ArrayList<? extends DataBase> datas;
|
||||
|
||||
public ArrayList<? extends DataBase> getDatas() {
|
||||
return datas;
|
||||
}
|
||||
|
||||
public void setDatas(ArrayList<? extends DataBase> datas) {
|
||||
this.datas = datas;
|
||||
}
|
||||
|
||||
// 构造方法
|
||||
public DataFilter() {
|
||||
|
||||
}
|
||||
|
||||
public DataFilter(ArrayList<? extends DataBase> datas) {
|
||||
this.datas = datas;
|
||||
}
|
||||
|
||||
// 数据过滤抽象方法
|
||||
public abstract void doFilter();
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.qst.dms.gather;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
//数据分析接口
|
||||
public interface IDataAnalyse {
|
||||
// 进行数据匹配,返回泛型ArrayList集合
|
||||
ArrayList<?> matchData();
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
package com.qst.dms.gather;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.qst.dms.entity.DataBase;
|
||||
import com.qst.dms.entity.LogRec;
|
||||
import com.qst.dms.entity.MatchedLogRec;
|
||||
import com.qst.dms.exception.DataAnalyseException;
|
||||
|
||||
//日志分析类,继承DataFilter抽象类,实现数据分析接口
|
||||
public class LogRecAnalyse extends DataFilter implements IDataAnalyse {
|
||||
// “登录”集合
|
||||
private ArrayList<LogRec> logIns = new ArrayList<>();
|
||||
// “登出”集合
|
||||
private ArrayList<LogRec> logOuts = new ArrayList<>();
|
||||
|
||||
// 构造方法
|
||||
public LogRecAnalyse() {
|
||||
}
|
||||
|
||||
public LogRecAnalyse(ArrayList<LogRec> logRecs) {
|
||||
super(logRecs);
|
||||
}
|
||||
|
||||
// 实现DataFilter抽象类中的过滤抽象方法
|
||||
public void doFilter() {
|
||||
// 获取数据集合
|
||||
ArrayList<LogRec> logs = (ArrayList<LogRec>) this.getDatas();
|
||||
// 遍历,对日志数据进行过滤,根据日志登录状态分别放在不同的数组中
|
||||
// 添加到“登录”日志集合中
|
||||
// 添加到“登出”日志集合中
|
||||
for (LogRec log:logs)
|
||||
{
|
||||
//1是登录,0是登出
|
||||
if(log.getLogType()==1)
|
||||
logIns.add(log);
|
||||
else
|
||||
logOuts.add(log);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// 实现IDataAnalyse接口中数据分析方法
|
||||
public ArrayList<MatchedLogRec> matchData() {
|
||||
// 创建日志匹配集合
|
||||
ArrayList<MatchedLogRec> matchLogs = new ArrayList<>();
|
||||
|
||||
// 数据匹配分析
|
||||
try
|
||||
{
|
||||
for(LogRec logIn:logIns)
|
||||
for(LogRec logOut:logOuts)
|
||||
try
|
||||
{
|
||||
matchLogs.add(new MatchedLogRec(logIn,logOut));
|
||||
}
|
||||
catch(RuntimeException e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(matchLogs.isEmpty())
|
||||
throw new DataAnalyseException("没有匹配的数据");
|
||||
}
|
||||
catch (DataAnalyseException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
//try
|
||||
// 没找到匹配的数据,抛出DataAnalyseException异常
|
||||
//catch (DataAnalyseException e) {
|
||||
//e.printStackTrace();
|
||||
return matchLogs;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
package com.qst.dms.gather;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.qst.dms.entity.DataBase;
|
||||
import com.qst.dms.entity.MatchedTransport;
|
||||
import com.qst.dms.entity.Transport;
|
||||
import com.qst.dms.exception.DataAnalyseException;
|
||||
|
||||
//物流分析类,继承DataFilter抽象类,实现数据分析接口
|
||||
public class TransportAnalyse extends DataFilter implements IDataAnalyse {
|
||||
// 发货集合
|
||||
private ArrayList<Transport> transSends = new ArrayList<>();
|
||||
// 送货集合
|
||||
private ArrayList<Transport> transIngs = new ArrayList<>();
|
||||
// 已签收集合
|
||||
private ArrayList<Transport> transRecs = new ArrayList<>();
|
||||
|
||||
// 构造方法
|
||||
public TransportAnalyse() {
|
||||
}
|
||||
|
||||
public TransportAnalyse(ArrayList<Transport> trans) {
|
||||
super(trans);
|
||||
}
|
||||
|
||||
// 实现DataFilter抽象类中的过滤抽象方法
|
||||
public void doFilter() {
|
||||
// 获取数据集合
|
||||
ArrayList<Transport> trans = (ArrayList<Transport>) this.getDatas();
|
||||
|
||||
// 遍历,对物流数据进行过滤,根据物流状态分别放在不同的集合中
|
||||
for (Transport tran : trans) {
|
||||
if (tran.getTransportType() == Transport.SENDING) {
|
||||
transSends.add(tran);
|
||||
} else if (tran.getTransportType() == Transport.TRANSPORTING) {
|
||||
transIngs.add(tran);
|
||||
} else if (tran.getTransportType() == Transport.RECEIVED) {
|
||||
transRecs.add(tran);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 实现IDataAnalyse接口中数据分析方法
|
||||
public ArrayList<MatchedTransport> matchData() {
|
||||
// 创建物流匹配集合
|
||||
ArrayList<MatchedTransport> matchTrans = new ArrayList<>();
|
||||
// 数据匹配分析
|
||||
for (Transport send : transSends) {
|
||||
for (Transport tran : transIngs) {
|
||||
for (Transport rec : transRecs) {
|
||||
if ((send.getReciver().equals(tran.getReciver()))
|
||||
&& (send.getReciver().equals(rec.getReciver()))) {
|
||||
// 修改物流状态类型为“匹配”
|
||||
send.setType(DataBase.MATHCH);
|
||||
tran.setType(DataBase.MATHCH);
|
||||
rec.setType(DataBase.MATHCH);
|
||||
// 添加到匹配集合中
|
||||
matchTrans.add(new MatchedTransport(send, tran, rec));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (matchTrans.size() == 0) {
|
||||
// 没找到匹配的数据,抛出DataAnalyseException异常
|
||||
throw new DataAnalyseException("没有匹配的物流数据!");
|
||||
}
|
||||
} catch (DataAnalyseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return matchTrans;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.qst.dms.security;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class String_SHA_256
|
||||
{
|
||||
public static String String_to_SHA256(String password)
|
||||
{
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
if (password == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// 创建MessageDigest实例并指定算法为SHA-256
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
// 计算散列值
|
||||
byte[] hashBytes = digest.digest(password.getBytes());
|
||||
// 将散列值转换为十六进制字符串表示
|
||||
for (byte b : hashBytes) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
return hexString.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,260 @@
|
|||
package com.qst.dms.service;
|
||||
import java.io.EOFException;
|
||||
import java.io.*;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.Scanner;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import com.qst.dms.db.DBUtil;
|
||||
import com.qst.dms.entity.*;
|
||||
import com.sun.net.httpserver.Request;
|
||||
|
||||
//日志业务类
|
||||
public class LogRecService {
|
||||
// 日志数据采集
|
||||
public LogRec inputLog() {
|
||||
LogRec log = null;
|
||||
// 建立一个从键盘接收数据的扫描器
|
||||
Scanner scanner = new Scanner(System.in);
|
||||