Compare commits
No commits in common. 'feature_dwy' and 'main' have entirely different histories.
feature_dw
...
main
|
Before Width: | Height: | Size: 53 KiB |
|
Before Width: | Height: | Size: 50 KiB |
|
Before Width: | Height: | Size: 90 KiB |
Binary file not shown.
Binary file not shown.
@ -1,3 +0,0 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="cstatm206004" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@ -1,2 +0,0 @@
|
||||
# cstatm206004
|
||||
|
||||
@ -1,117 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- 修改cstatm206004,可批量替换 -->
|
||||
<!-- 1修改groupId:org.atm -->
|
||||
<groupId>org.atm</groupId>
|
||||
<!-- 修改cstatm206004 -->
|
||||
<artifactId>cstatm206004</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<!-- 修改cstatm206004 -->
|
||||
<name>cstatm206004</name>
|
||||
<description>期中考试 cstatm206004</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.report.outputEncoding>UTF-8</project.report.outputEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.release>17</maven.compiler.release>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.30</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.1.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>3.10.0.2594</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<!-- 2修改主类com.atm.view.gui.Gui -->
|
||||
<mainClass>
|
||||
org.atm.view.gui.Gui
|
||||
</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<configuration>
|
||||
<skipTests>false</skipTests>
|
||||
<argLine>${argLine} -Dfile.encoding=UTF-8</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.11</version>
|
||||
<configuration>
|
||||
<skip>false</skip>
|
||||
<destFile>target/coverage-reports/jacoco-unit.exec</destFile>
|
||||
<dataFile>target/coverage-reports/jacoco-unit.exec</dataFile>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>jacoco-initialize</id>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>jacoco-site</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@ -1,46 +0,0 @@
|
||||
package org.atm.ctrl;
|
||||
|
||||
import org.atm.model.Person;
|
||||
import org.atm.dao.PersonDAO;
|
||||
import java.util.List;
|
||||
|
||||
public class PersonController {
|
||||
|
||||
private PersonDAO personDAO;
|
||||
|
||||
public PersonController() {
|
||||
this.personDAO = new PersonDAO();
|
||||
}
|
||||
|
||||
public boolean addPerson(Person person) {
|
||||
if (Validate.is7RandNumeric(person.getPid()) && person.getPname() != null && !person.getPname().isEmpty()) {
|
||||
return personDAO.addPerson(person);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updatePerson(Person person) {
|
||||
if (Validate.is7RandNumeric(person.getPid())) {
|
||||
return personDAO.updatePerson(person);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean deletePerson(String pid) {
|
||||
if (Validate.is7RandNumeric(pid)) {
|
||||
return personDAO.deletePerson(pid);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Person getPersonById(String pid) {
|
||||
if (Validate.is7RandNumeric(pid)) {
|
||||
return personDAO.getPersonById(pid);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Person> getAllPersons() {
|
||||
return personDAO.getAllPersons();
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
package org.atm.ctrl;
|
||||
|
||||
public class Validate {
|
||||
|
||||
private static final int len = 7;
|
||||
|
||||
public static boolean is7RandNumeric(String str) {
|
||||
boolean flag = str != null && str.matches("\\d{" + len + "}");
|
||||
if (!flag) {
|
||||
System.out.println(str + " must is " + len + " Numeric!");
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
}// end Validate
|
||||
@ -1,34 +0,0 @@
|
||||
package org.atm.dao;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.atm.model.Customer;
|
||||
|
||||
public class Login {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param c
|
||||
*/
|
||||
public Customer login(Customer c) {
|
||||
Customer returnCustomer = null;
|
||||
try {
|
||||
ResultSet rs = DbUtil.executeQuery(
|
||||
"select * from customer where cid='" + c.getCid() + "' and cpin='" + c.getCpin() + "'");
|
||||
if (rs!=null && rs.next()) {
|
||||
returnCustomer = new Customer();
|
||||
returnCustomer.setCid(rs.getString("cid"));
|
||||
returnCustomer.setCpin(rs.getString("cpin"));
|
||||
returnCustomer.setCname(rs.getString("cname"));
|
||||
System.out.println("welcome," + rs.getString("cname"));
|
||||
return returnCustomer;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Fetch ResultSet Failed!");
|
||||
return returnCustomer;
|
||||
}
|
||||
System.out.println("No Customer!");
|
||||
return returnCustomer;
|
||||
}
|
||||
}// end Login
|
||||
@ -1,85 +0,0 @@
|
||||
package org.atm.dao;
|
||||
|
||||
import org.atm.model.Person;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PersonDAO {
|
||||
|
||||
public boolean addPerson(Person person) {
|
||||
String sql = "INSERT INTO person (pid, pname, page, pphone) VALUES ('" +
|
||||
person.getPid() + "', '" + person.getPname() + "', '" +
|
||||
person.getPage() + "', '" + person.getPphone() + "')";
|
||||
try {
|
||||
DbUtil.executeUpdate(sql);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
System.err.println("Add Person Failed! " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updatePerson(Person person) {
|
||||
String sql = "UPDATE person SET pname='" + person.getPname() +
|
||||
"', page='" + person.getPage() +
|
||||
"', pphone='" + person.getPphone() +
|
||||
"' WHERE pid='" + person.getPid() + "'";
|
||||
try {
|
||||
DbUtil.executeUpdate(sql);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
System.err.println("Update Person Failed! " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deletePerson(String pid) {
|
||||
String sql = "DELETE FROM person WHERE pid='" + pid + "'";
|
||||
try {
|
||||
DbUtil.executeUpdate(sql);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
System.err.println("Delete Person Failed! " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Person getPersonById(String pid) {
|
||||
String sql = "SELECT * FROM person WHERE pid='" + pid + "'";
|
||||
try {
|
||||
ResultSet rs = DbUtil.executeQuery(sql);
|
||||
if (rs != null && rs.next()) {
|
||||
Person person = new Person();
|
||||
person.setPid(rs.getString("pid"));
|
||||
person.setPname(rs.getString("pname"));
|
||||
person.setPage(rs.getString("page"));
|
||||
person.setPphone(rs.getString("pphone"));
|
||||
return person;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Get Person Failed! " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Person> getAllPersons() {
|
||||
List<Person> persons = new ArrayList<>();
|
||||
String sql = "SELECT * FROM person";
|
||||
try {
|
||||
ResultSet rs = DbUtil.executeQuery(sql);
|
||||
while (rs != null && rs.next()) {
|
||||
Person person = new Person();
|
||||
person.setPid(rs.getString("pid"));
|
||||
person.setPname(rs.getString("pname"));
|
||||
person.setPage(rs.getString("page"));
|
||||
person.setPphone(rs.getString("pphone"));
|
||||
persons.add(person);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Get All Persons Failed! " + e.getMessage());
|
||||
}
|
||||
return persons;
|
||||
}
|
||||
}
|
||||
@ -1,77 +0,0 @@
|
||||
package org.atm.model;
|
||||
|
||||
public class Customer {
|
||||
|
||||
private String cid;
|
||||
private String cname;
|
||||
private String cpin;
|
||||
|
||||
public Customer() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cid
|
||||
* @param cpin
|
||||
*/
|
||||
public Customer(String cid, String cpin) {
|
||||
this.cid = cid;
|
||||
this.cpin = cpin;
|
||||
this.cname = "";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cid
|
||||
* @param cpin
|
||||
* @param cname
|
||||
*/
|
||||
public Customer(String cid, String cpin, String cname) {
|
||||
this.cid = cid;
|
||||
this.cpin = cpin;
|
||||
this.cname = cname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String return the cid
|
||||
*/
|
||||
public String getCid() {
|
||||
return cid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cid the cid to set
|
||||
*/
|
||||
public void setCid(String cid) {
|
||||
this.cid = cid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String return the cname
|
||||
*/
|
||||
public String getCname() {
|
||||
return cname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cname the cname to set
|
||||
*/
|
||||
public void setCname(String cname) {
|
||||
this.cname = cname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String return the cpin
|
||||
*/
|
||||
public String getCpin() {
|
||||
return cpin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cpin the cpin to set
|
||||
*/
|
||||
public void setCpin(String cpin) {
|
||||
this.cpin = cpin;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
package org.atm.model;
|
||||
|
||||
public class Person {
|
||||
|
||||
private String pid;
|
||||
private String pname;
|
||||
private String page;
|
||||
private String pphone;
|
||||
|
||||
public Person() {
|
||||
}
|
||||
|
||||
public Person(String pid, String pname, String page, String pphone) {
|
||||
this.pid = pid;
|
||||
this.pname = pname;
|
||||
this.page = page;
|
||||
this.pphone = pphone;
|
||||
}
|
||||
|
||||
public String getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(String pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getPname() {
|
||||
return pname;
|
||||
}
|
||||
|
||||
public void setPname(String pname) {
|
||||
this.pname = pname;
|
||||
}
|
||||
|
||||
public String getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(String page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public String getPphone() {
|
||||
return pphone;
|
||||
}
|
||||
|
||||
public void setPphone(String pphone) {
|
||||
this.pphone = pphone;
|
||||
}
|
||||
}
|
||||
@ -1,93 +0,0 @@
|
||||
package org.atm.view.gui;
|
||||
|
||||
import org.atm.model.Customer;
|
||||
import org.atm.ctrl.Validate;
|
||||
import org.atm.dao.Login;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JPasswordField;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class Gui extends JFrame {
|
||||
|
||||
private JButton jButtonLogin;
|
||||
private JLabel jLabelCid;
|
||||
private JLabel jLabelCpin;
|
||||
private JPanel jPanel;
|
||||
private JPanel jPanelBtn;
|
||||
private JPanel jPanelCid;
|
||||
private JPanel jPanelCpin;
|
||||
private JTextField jTextFieldCid;
|
||||
private JPasswordField jTextFieldCpin;
|
||||
|
||||
public Gui() {
|
||||
this.setTitle("GUI ATM MTE From EA For CS231");
|
||||
this.setSize(300, 200);
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setResizable(false);
|
||||
|
||||
jPanel = new JPanel(new GridLayout(3, 1));
|
||||
jPanelCid = new JPanel();
|
||||
jLabelCid = new JLabel("CID");
|
||||
jLabelCid.setForeground(Color.RED);
|
||||
jLabelCid.setFont(new Font("", Font.BOLD, 15));
|
||||
jTextFieldCid = new JTextField(15);
|
||||
jPanelCid.add(jLabelCid);
|
||||
jPanelCid.add(jTextFieldCid);
|
||||
|
||||
jPanelCpin = new JPanel();
|
||||
jLabelCpin = new JLabel("CPIN");
|
||||
jLabelCpin.setForeground(Color.RED);
|
||||
jLabelCpin.setFont(new Font("", Font.BOLD, 15));
|
||||
jTextFieldCpin = new JPasswordField(15);
|
||||
jPanelCpin.add(jLabelCpin);
|
||||
jPanelCpin.add(jTextFieldCpin);
|
||||
|
||||
jPanelBtn = new JPanel();
|
||||
jButtonLogin = new JButton("LOGIN");
|
||||
jPanelBtn.add(jButtonLogin);
|
||||
jPanel.add(jPanelCid);
|
||||
jPanel.add(jPanelCpin);
|
||||
jPanel.add(jPanelBtn);
|
||||
this.add(jPanel);
|
||||
this.setVisible(true);
|
||||
jButtonLogin.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String cid = new String(jTextFieldCid.getText());
|
||||
if (cid.length() <= 0) {
|
||||
JOptionPane.showMessageDialog(null, "CID NULL");
|
||||
System.out.println("CID NULL");
|
||||
} else {
|
||||
String cpin = new String(jTextFieldCpin.getPassword());
|
||||
Customer inputCustomer = new Customer(cid, cpin);
|
||||
Customer returnCustomer = null;
|
||||
if (Validate.is7RandNumeric(cid) && Validate.is7RandNumeric(cpin))
|
||||
returnCustomer = new Login().login(inputCustomer);
|
||||
if (returnCustomer != null) {
|
||||
JOptionPane.showMessageDialog(null, "LOGIN SUCCEEDED!", "PROMPT",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "ID OR PIN ERROR!", "PROMPT",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Gui();
|
||||
}
|
||||
}// end Gui
|
||||
@ -1,58 +0,0 @@
|
||||
package org.atm.ctrl;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.atm.ctrl.Validate;
|
||||
|
||||
public class ValidateTest extends junit.framework.TestCase {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param arg0
|
||||
*/
|
||||
public ValidateTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @exception Exception
|
||||
*/
|
||||
protected void setUp()
|
||||
throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @exception Exception
|
||||
*/
|
||||
protected void tearDown()
|
||||
throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public final void testIsNumeric_01_7() {
|
||||
Assert.assertTrue(Validate.is7RandNumeric("2060041"));
|
||||
}
|
||||
public final void testIsNumeric_02_d() {
|
||||
Assert.assertFalse(Validate.is7RandNumeric("123456d"));
|
||||
}
|
||||
public final void testIsNumeric_03_8() {
|
||||
Assert.assertFalse(Validate.is7RandNumeric("12345678"));
|
||||
}
|
||||
public final void testIsNumeric_04_null() {
|
||||
Assert.assertFalse(Validate.is7RandNumeric(""));
|
||||
}
|
||||
public final void testIsNumeric_05_6() {
|
||||
Assert.assertFalse(Validate.is7RandNumeric("123456"));
|
||||
}
|
||||
}// end ValidateTest
|
||||
@ -1,16 +0,0 @@
|
||||
package org.atm.dao;
|
||||
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runner.RunWith;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.framework.Test;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({org.atm.ctrl.ValidateTest.class, org.atm.dao.LoginTest.class})
|
||||
public class LoginIntegratedTest {
|
||||
|
||||
public static Test suit() {
|
||||
TestSuite suite = new TestSuite();
|
||||
return suite;
|
||||
}
|
||||
}// end LoginITest
|
||||
@ -1,15 +0,0 @@
|
||||
package org.atm.dao;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.atm.dao.Login;
|
||||
import org.atm.model.Customer;
|
||||
|
||||
public class LoginTest extends junit.framework.TestCase {
|
||||
public final void testLogin_01() {
|
||||
Assert.assertNotNull(new Login().login(new Customer("2060041", "2060041")));
|
||||
}
|
||||
public final void testLogin_02() {
|
||||
Assert.assertNull(new Login().login(new Customer("1234578", "1234589")));
|
||||
}
|
||||
}
|
||||
@ -1,96 +0,0 @@
|
||||
package org.atm.dao;
|
||||
|
||||
import org.atm.model.Person;
|
||||
import org.atm.ctrl.PersonController;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.List;
|
||||
|
||||
public class PersonTest {
|
||||
|
||||
private PersonController personController = new PersonController();
|
||||
|
||||
@Test
|
||||
public void testAddPerson() {
|
||||
// 创建测试人员
|
||||
Person person = new Person("1234567", "测试人员", "30", "13800138000");
|
||||
boolean result = personController.addPerson(person);
|
||||
System.out.println("添加人员测试结果: " + (result ? "成功" : "失败"));
|
||||
|
||||
// 验证添加是否成功
|
||||
Person addedPerson = personController.getPersonById("1234567");
|
||||
assertNotNull("添加的人员应该存在", addedPerson);
|
||||
assertEquals("人员姓名应该匹配", "测试人员", addedPerson.getPname());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPersonById() {
|
||||
// 先添加一个测试人员
|
||||
Person person = new Person("2345678", "测试查询", "25", "13900139000");
|
||||
personController.addPerson(person);
|
||||
|
||||
// 测试查询
|
||||
Person retrievedPerson = personController.getPersonById("2345678");
|
||||
assertNotNull("通过ID查询的人员应该存在", retrievedPerson);
|
||||
assertEquals("人员ID应该匹配", "2345678", retrievedPerson.getPid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePerson() {
|
||||
// 先添加一个测试人员
|
||||
Person person = new Person("3456789", "测试更新", "35", "13700137000");
|
||||
personController.addPerson(person);
|
||||
|
||||
// 更新人员信息
|
||||
person.setPname("已更新人员");
|
||||
person.setPage("36");
|
||||
boolean result = personController.updatePerson(person);
|
||||
System.out.println("更新人员测试结果: " + (result ? "成功" : "失败"));
|
||||
|
||||
// 验证更新是否成功
|
||||
Person updatedPerson = personController.getPersonById("3456789");
|
||||
assertEquals("人员姓名应该已更新", "已更新人员", updatedPerson.getPname());
|
||||
assertEquals("人员年龄应该已更新", "36", updatedPerson.getPage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletePerson() {
|
||||
// 先添加一个测试人员
|
||||
Person person = new Person("4567890", "测试删除", "40", "13600136000");
|
||||
personController.addPerson(person);
|
||||
|
||||
// 删除人员
|
||||
boolean result = personController.deletePerson("4567890");
|
||||
System.out.println("删除人员测试结果: " + (result ? "成功" : "失败"));
|
||||
|
||||
// 验证删除是否成功
|
||||
Person deletedPerson = personController.getPersonById("4567890");
|
||||
assertNull("删除的人员应该不存在", deletedPerson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllPersons() {
|
||||
// 确保有一些测试数据
|
||||
personController.addPerson(new Person("5678901", "人员1", "28", "13500135001"));
|
||||
personController.addPerson(new Person("6789012", "人员2", "32", "13500135002"));
|
||||
|
||||
// 获取所有人员
|
||||
List<Person> persons = personController.getAllPersons();
|
||||
assertNotNull("人员列表不应该为空", persons);
|
||||
System.out.println("获取到的人员数量: " + persons.size());
|
||||
assertTrue("人员列表应该至少包含2个人员", persons.size() >= 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidation() {
|
||||
// 测试无效的ID
|
||||
Person invalidPerson = new Person("123", "无效ID", "25", "13800138000");
|
||||
boolean result = personController.addPerson(invalidPerson);
|
||||
assertFalse("无效ID的人员不应添加成功", result);
|
||||
|
||||
// 测试空姓名
|
||||
Person emptyNamePerson = new Person("7890123", "", "25", "13800138000");
|
||||
result = personController.addPerson(emptyNamePerson);
|
||||
assertFalse("空姓名的人员不应添加成功", result);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -1 +0,0 @@
|
||||
EAConnectString:D:\CS231_SEB09\CHZU_CS231_SEBG09\实验一软件项目计划个人报告作.qea
|
||||
Binary file not shown.
@ -1,21 +0,0 @@
|
||||
@echo off
|
||||
echo ========================================
|
||||
echo 校园代取系统 - 人员交互功能
|
||||
echo ========================================
|
||||
echo.
|
||||
|
||||
echo 正在编译Java源文件...
|
||||
javac -d bin -cp "lib/*" src/main/java/com/campus/pickup/**/*.java
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
echo 编译失败,请检查代码!
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo 编译成功!
|
||||
|
||||
echo.
|
||||
echo 正在运行校园代取系统...
|
||||
java -cp "bin;lib/*" com.campus.pickup.view.MainView
|
||||
|
||||
pause
|
||||
@ -1,69 +0,0 @@
|
||||
package com.campus.pickup.controller;
|
||||
|
||||
import com.campus.pickup.model.User;
|
||||
import com.campus.pickup.model.Message;
|
||||
import com.campus.pickup.model.Review;
|
||||
import com.campus.pickup.service.UserService;
|
||||
import com.campus.pickup.service.MessageService;
|
||||
import com.campus.pickup.service.ReviewService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 控制器核心代码
|
||||
*/
|
||||
public class ControllerMainCode {
|
||||
|
||||
// ========== 用户控制器核心功能 ==========
|
||||
|
||||
public boolean register(String username, String password, String realName, String phone, String email, String studentId, String dormitory) {
|
||||
User user = new User();
|
||||
user.setUserId(java.util.UUID.randomUUID().toString().replace("-", ""));
|
||||
user.setUsername(username);
|
||||
user.setPassword(password);
|
||||
user.setRealName(realName);
|
||||
user.setPhone(phone);
|
||||
user.setEmail(email);
|
||||
user.setStudentId(studentId);
|
||||
user.setDormitory(dormitory);
|
||||
|
||||
return new UserService().register(user);
|
||||
}
|
||||
|
||||
public User login(String username, String password) {
|
||||
return new UserService().login(username, password);
|
||||
}
|
||||
|
||||
public User getUserInfo(String userId) {
|
||||
return new UserService().getUserById(userId);
|
||||
}
|
||||
|
||||
// ========== 消息控制器核心功能 ==========
|
||||
|
||||
public boolean sendMessage(String senderId, String receiverId, String content, int typeCode) {
|
||||
Message.MessageType type = Message.MessageType.fromCode(typeCode);
|
||||
return new MessageService().sendMessage(senderId, receiverId, content, type);
|
||||
}
|
||||
|
||||
public List<Message> getReceivedMessages(String receiverId) {
|
||||
return new MessageService().getReceivedMessages(receiverId);
|
||||
}
|
||||
|
||||
public int getUnreadMessageCount(String receiverId) {
|
||||
return new MessageService().getUnreadMessageCount(receiverId);
|
||||
}
|
||||
|
||||
// ========== 评价控制器核心功能 ==========
|
||||
|
||||
public boolean addReview(String orderId, String reviewerId, String reviewedId, int rating, String content) {
|
||||
return new ReviewService().addReview(orderId, reviewerId, reviewedId, rating, content);
|
||||
}
|
||||
|
||||
public List<Review> getReviewsReceivedByUser(String userId) {
|
||||
return new ReviewService().getReviewsReceivedByUser(userId);
|
||||
}
|
||||
|
||||
public double getAverageRatingForUser(String userId) {
|
||||
return new ReviewService().getAverageRatingForUser(userId);
|
||||
}
|
||||
}
|
||||
@ -1,285 +0,0 @@
|
||||
package com.campus.pickup.controller;
|
||||
|
||||
import com.campus.pickup.model.Message;
|
||||
import com.campus.pickup.service.MessageService;
|
||||
import com.campus.pickup.util.DatabaseUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 消息控制器类
|
||||
* 处理消息相关的请求
|
||||
*/
|
||||
public class MessageController {
|
||||
private MessageService messageService;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public MessageController() {
|
||||
this.messageService = new MessageService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @param senderId 发送者ID
|
||||
* @param receiverId 接收者ID
|
||||
* @param content 消息内容
|
||||
* @param typeCode 消息类型代码
|
||||
* @return 发送结果
|
||||
*/
|
||||
public Map<String, Object> sendMessage(String senderId, String receiverId, String content, int typeCode) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
// 检查输入参数
|
||||
if (senderId == null || senderId.isEmpty() || receiverId == null ||
|
||||
receiverId.isEmpty() || content == null || content.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "发送者ID、接收者ID和消息内容不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获取消息类型
|
||||
Message.MessageType type = Message.MessageType.fromCode(typeCode);
|
||||
if (type == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "无效的消息类型");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 调用服务层发送消息
|
||||
boolean success = messageService.sendMessage(senderId, receiverId, content, type);
|
||||
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "消息发送成功");
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "消息发送失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "发送消息过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送系统通知
|
||||
* @param receiverId 接收者ID
|
||||
* @param content 通知内容
|
||||
* @return 发送结果
|
||||
*/
|
||||
public Map<String, Object> sendSystemNotification(String receiverId, String content) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
// 检查输入参数
|
||||
if (receiverId == null || receiverId.isEmpty() || content == null || content.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "接收者ID和通知内容不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 调用服务层发送系统通知
|
||||
boolean success = messageService.sendSystemNotification(receiverId, content);
|
||||
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "系统通知发送成功");
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "系统通知发送失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "发送系统通知过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取消息详情
|
||||
* @param messageId 消息ID
|
||||
* @return 消息详情
|
||||
*/
|
||||
public Map<String, Object> getMessageDetail(String messageId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
if (messageId == null || messageId.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "消息ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
Message message = messageService.getMessageById(messageId);
|
||||
|
||||
if (message != null) {
|
||||
result.put("success", true);
|
||||
result.put("message", message);
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "消息不存在");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "获取消息详情过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户收到的所有消息
|
||||
* @param receiverId 接收者ID
|
||||
* @return 消息列表
|
||||
*/
|
||||
public Map<String, Object> getReceivedMessages(String receiverId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
if (receiverId == null || receiverId.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "接收者ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Message> messages = messageService.getReceivedMessages(receiverId);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("messages", messages);
|
||||
result.put("count", messages.size());
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "获取消息列表过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户未读消息数量
|
||||
* @param receiverId 接收者ID
|
||||
* @return 未读消息数量
|
||||
*/
|
||||
public Map<String, Object> getUnreadMessageCount(String receiverId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
if (receiverId == null || receiverId.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "接收者ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
int count = messageService.getUnreadMessageCount(receiverId);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("unreadCount", count);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "获取未读消息数量过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取两个用户之间的消息记录
|
||||
* @param userId1 用户1 ID
|
||||
* @param userId2 用户2 ID
|
||||
* @return 消息列表
|
||||
*/
|
||||
public Map<String, Object> getMessagesBetweenUsers(String userId1, String userId2) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
if (userId1 == null || userId1.isEmpty() || userId2 == null || userId2.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "用户ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Message> messages = messageService.getMessagesBetweenUsers(userId1, userId2);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("messages", messages);
|
||||
result.put("count", messages.size());
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "获取用户间消息记录过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记消息为已读
|
||||
* @param messageId 消息ID
|
||||
* @return 操作结果
|
||||
*/
|
||||
public Map<String, Object> markMessageAsRead(String messageId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
if (messageId == null || messageId.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "消息ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean success = messageService.markMessageAsRead(messageId);
|
||||
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "消息已标记为已读");
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "标记消息为已读失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "标记消息为已读过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量标记消息为已读
|
||||
* @param receiverId 接收者ID
|
||||
* @return 操作结果
|
||||
*/
|
||||
public Map<String, Object> markAllMessagesAsRead(String receiverId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
if (receiverId == null || receiverId.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "接收者ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean success = messageService.markAllMessagesAsRead(receiverId);
|
||||
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "所有消息已标记为已读");
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "批量标记消息为已读失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "批量标记消息为已读过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -1,153 +0,0 @@
|
||||
package com.campus.pickup.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 消息实体类
|
||||
* 用于存储校园代取系统中的用户交互消息
|
||||
*/
|
||||
public class Message {
|
||||
private String messageId;
|
||||
private String senderId;
|
||||
private String receiverId;
|
||||
private String content;
|
||||
private LocalDateTime sendTime;
|
||||
private LocalDateTime readTime;
|
||||
private int status; // 0-未读 1-已读 2-已删除
|
||||
private MessageType type; // 消息类型:系统通知、用户消息、订单消息等
|
||||
|
||||
public enum MessageType {
|
||||
SYSTEM_NOTIFICATION(0, "系统通知"),
|
||||
USER_MESSAGE(1, "用户消息"),
|
||||
ORDER_MESSAGE(2, "订单消息"),
|
||||
REVIEW_MESSAGE(3, "评价消息");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
MessageType(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static MessageType fromCode(int code) {
|
||||
for (MessageType type : MessageType.values()) {
|
||||
if (type.getCode() == code) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Message() {
|
||||
this.sendTime = LocalDateTime.now();
|
||||
this.status = 0;
|
||||
this.type = MessageType.USER_MESSAGE;
|
||||
}
|
||||
|
||||
public Message(String senderId, String receiverId, String content, MessageType type) {
|
||||
this();
|
||||
this.senderId = senderId;
|
||||
this.receiverId = receiverId;
|
||||
this.content = content;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Message(String messageId, String senderId, String receiverId, String content, LocalDateTime sendTime, LocalDateTime readTime, int status, MessageType type) {
|
||||
this.messageId = messageId;
|
||||
this.senderId = senderId;
|
||||
this.receiverId = receiverId;
|
||||
this.content = content;
|
||||
this.sendTime = sendTime;
|
||||
this.readTime = readTime;
|
||||
this.status = status;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(String messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public String getSenderId() {
|
||||
return senderId;
|
||||
}
|
||||
|
||||
public void setSenderId(String senderId) {
|
||||
this.senderId = senderId;
|
||||
}
|
||||
|
||||
public String getReceiverId() {
|
||||
return receiverId;
|
||||
}
|
||||
|
||||
public void setReceiverId(String receiverId) {
|
||||
this.receiverId = receiverId;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public LocalDateTime getSendTime() {
|
||||
return sendTime;
|
||||
}
|
||||
|
||||
public void setSendTime(LocalDateTime sendTime) {
|
||||
this.sendTime = sendTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getReadTime() {
|
||||
return readTime;
|
||||
}
|
||||
|
||||
public void setReadTime(LocalDateTime readTime) {
|
||||
this.readTime = readTime;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public MessageType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(MessageType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Message{" +
|
||||
"messageId='" + messageId + '\'' +
|
||||
", senderId='" + senderId + '\'' +
|
||||
", receiverId='" + receiverId + '\'' +
|
||||
", content='" + content + '\'' +
|
||||
", sendTime=" + sendTime +
|
||||
", readTime=" + readTime +
|
||||
", status=" + status +
|
||||
", type=" + type +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,252 +0,0 @@
|
||||
package com.campus.pickup.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 订单实体类
|
||||
* 用于存储校园代取系统中的订单信息
|
||||
*/
|
||||
public class Order {
|
||||
private String orderId;
|
||||
private String orderNumber; // 订单编号
|
||||
private String customerId; // 下单用户ID
|
||||
private String deliveryPersonId; // 配送员ID
|
||||
private String itemType; // 物品类型(快递、外卖、文件等)
|
||||
private String description; // 物品描述
|
||||
private String pickupLocation; // 取件地点
|
||||
private String deliveryLocation; // 配送地点
|
||||
private BigDecimal fee; // 配送费用
|
||||
private LocalDateTime pickupTime; // 预计取件时间
|
||||
private LocalDateTime deliveryTime; // 实际送达时间
|
||||
private LocalDateTime createTime; // 创建时间
|
||||
private LocalDateTime updateTime; // 更新时间
|
||||
private OrderStatus status; // 订单状态
|
||||
private String remarks; // 备注
|
||||
|
||||
public enum OrderStatus {
|
||||
PENDING(0, "待接单"),
|
||||
ACCEPTED(1, "已接单"),
|
||||
PICKED_UP(2, "已取件"),
|
||||
DELIVERING(3, "配送中"),
|
||||
COMPLETED(4, "已完成"),
|
||||
CANCELLED(5, "已取消");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
OrderStatus(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static OrderStatus fromCode(int code) {
|
||||
for (OrderStatus status : OrderStatus.values()) {
|
||||
if (status.getCode() == code) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Order() {
|
||||
this.createTime = LocalDateTime.now();
|
||||
this.updateTime = LocalDateTime.now();
|
||||
this.status = OrderStatus.PENDING;
|
||||
this.fee = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
public Order(String customerId, String itemType, String description,
|
||||
String pickupLocation, String deliveryLocation, BigDecimal fee,
|
||||
LocalDateTime pickupTime, String remarks) {
|
||||
this();
|
||||
this.orderNumber = generateOrderNumber();
|
||||
this.customerId = customerId;
|
||||
this.itemType = itemType;
|
||||
this.description = description;
|
||||
this.pickupLocation = pickupLocation;
|
||||
this.deliveryLocation = deliveryLocation;
|
||||
this.fee = fee;
|
||||
this.pickupTime = pickupTime;
|
||||
this.remarks = remarks;
|
||||
}
|
||||
|
||||
public Order(String orderId, String orderNumber, String customerId, String deliveryPersonId,
|
||||
String itemType, String description, String pickupLocation, String deliveryLocation,
|
||||
BigDecimal fee, LocalDateTime pickupTime, LocalDateTime deliveryTime,
|
||||
LocalDateTime createTime, LocalDateTime updateTime, OrderStatus status, String remarks) {
|
||||
this.orderId = orderId;
|
||||
this.orderNumber = orderNumber;
|
||||
this.customerId = customerId;
|
||||
this.deliveryPersonId = deliveryPersonId;
|
||||
this.itemType = itemType;
|
||||
this.description = description;
|
||||
this.pickupLocation = pickupLocation;
|
||||
this.deliveryLocation = deliveryLocation;
|
||||
this.fee = fee;
|
||||
this.pickupTime = pickupTime;
|
||||
this.deliveryTime = deliveryTime;
|
||||
this.createTime = createTime;
|
||||
this.updateTime = updateTime;
|
||||
this.status = status;
|
||||
this.remarks = remarks;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成订单编号
|
||||
* @return 订单编号
|
||||
*/
|
||||
private String generateOrderNumber() {
|
||||
return "ORD" + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public String getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(String orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public String getOrderNumber() {
|
||||
return orderNumber;
|
||||
}
|
||||
|
||||
public void setOrderNumber(String orderNumber) {
|
||||
this.orderNumber = orderNumber;
|
||||
}
|
||||
|
||||
public String getCustomerId() {
|
||||
return customerId;
|
||||
}
|
||||
|
||||
public void setCustomerId(String customerId) {
|
||||
this.customerId = customerId;
|
||||
}
|
||||
|
||||
public String getDeliveryPersonId() {
|
||||
return deliveryPersonId;
|
||||
}
|
||||
|
||||
public void setDeliveryPersonId(String deliveryPersonId) {
|
||||
this.deliveryPersonId = deliveryPersonId;
|
||||
}
|
||||
|
||||
public String getItemType() {
|
||||
return itemType;
|
||||
}
|
||||
|
||||
public void setItemType(String itemType) {
|
||||
this.itemType = itemType;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getPickupLocation() {
|
||||
return pickupLocation;
|
||||
}
|
||||
|
||||
public void setPickupLocation(String pickupLocation) {
|
||||
this.pickupLocation = pickupLocation;
|
||||
}
|
||||
|
||||
public String getDeliveryLocation() {
|
||||
return deliveryLocation;
|
||||
}
|
||||
|
||||
public void setDeliveryLocation(String deliveryLocation) {
|
||||
this.deliveryLocation = deliveryLocation;
|
||||
}
|
||||
|
||||
public BigDecimal getFee() {
|
||||
return fee;
|
||||
}
|
||||
|
||||
public void setFee(BigDecimal fee) {
|
||||
this.fee = fee;
|
||||
}
|
||||
|
||||
public LocalDateTime getPickupTime() {
|
||||
return pickupTime;
|
||||
}
|
||||
|
||||
public void setPickupTime(LocalDateTime pickupTime) {
|
||||
this.pickupTime = pickupTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getDeliveryTime() {
|
||||
return deliveryTime;
|
||||
}
|
||||
|
||||
public void setDeliveryTime(LocalDateTime deliveryTime) {
|
||||
this.deliveryTime = deliveryTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public OrderStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(OrderStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getRemarks() {
|
||||
return remarks;
|
||||
}
|
||||
|
||||
public void setRemarks(String remarks) {
|
||||
this.remarks = remarks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Order{" +
|
||||
"orderId='" + orderId + '\'' +
|
||||
", orderNumber='" + orderNumber + '\'' +
|
||||
", customerId='" + customerId + '\'' +
|
||||
", deliveryPersonId='" + deliveryPersonId + '\'' +
|
||||
", itemType='" + itemType + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", pickupLocation='" + pickupLocation + '\'' +
|
||||
", deliveryLocation='" + deliveryLocation + '\'' +
|
||||
", fee=" + fee +
|
||||
", pickupTime=" + pickupTime +
|
||||
", deliveryTime=" + deliveryTime +
|
||||
", createTime=" + createTime +
|
||||
", updateTime=" + updateTime +
|
||||
", status=" + status +
|
||||
", remarks='" + remarks + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,133 +0,0 @@
|
||||
package com.campus.pickup.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 评价实体类
|
||||
* 用于存储校园代取系统中的用户评价信息
|
||||
*/
|
||||
public class Review {
|
||||
private String reviewId;
|
||||
private String orderId;
|
||||
private String reviewerId; // 评价人ID
|
||||
private String reviewedId; // 被评价人ID
|
||||
private int rating; // 评分 1-5星
|
||||
private String content; // 评价内容
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private int status; // 0-正常 1-已删除
|
||||
|
||||
public Review() {
|
||||
this.createTime = LocalDateTime.now();
|
||||
this.updateTime = LocalDateTime.now();
|
||||
this.status = 0;
|
||||
}
|
||||
|
||||
public Review(String orderId, String reviewerId, String reviewedId, int rating, String content) {
|
||||
this();
|
||||
this.orderId = orderId;
|
||||
this.reviewerId = reviewerId;
|
||||
this.reviewedId = reviewedId;
|
||||
this.rating = rating;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Review(String reviewId, String orderId, String reviewerId, String reviewedId, int rating, String content, LocalDateTime createTime, LocalDateTime updateTime, int status) {
|
||||
this.reviewId = reviewId;
|
||||
this.orderId = orderId;
|
||||
this.reviewerId = reviewerId;
|
||||
this.reviewedId = reviewedId;
|
||||
this.rating = rating;
|
||||
this.content = content;
|
||||
this.createTime = createTime;
|
||||
this.updateTime = updateTime;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getReviewId() {
|
||||
return reviewId;
|
||||
}
|
||||
|
||||
public void setReviewId(String reviewId) {
|
||||
this.reviewId = reviewId;
|
||||
}
|
||||
|
||||
public String getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(String orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public String getReviewerId() {
|
||||
return reviewerId;
|
||||
}
|
||||
|
||||
public void setReviewerId(String reviewerId) {
|
||||
this.reviewerId = reviewerId;
|
||||
}
|
||||
|
||||
public String getReviewedId() {
|
||||
return reviewedId;
|
||||
}
|
||||
|
||||
public void setReviewedId(String reviewedId) {
|
||||
this.reviewedId = reviewedId;
|
||||
}
|
||||
|
||||
public int getRating() {
|
||||
return rating;
|
||||
}
|
||||
|
||||
public void setRating(int rating) {
|
||||
this.rating = rating;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Review{" +
|
||||
"reviewId='" + reviewId + '\'' +
|
||||
", orderId='" + orderId + '\'' +
|
||||
", reviewerId='" + reviewerId + '\'' +
|
||||
", reviewedId='" + reviewedId + '\'' +
|
||||
", rating=" + rating +
|
||||
", content='" + content + '\'' +
|
||||
", createTime=" + createTime +
|
||||
", updateTime=" + updateTime +
|
||||
", status=" + status +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,156 +0,0 @@
|
||||
package com.campus.pickup.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户实体类
|
||||
* 用于存储校园代取系统中的用户信息
|
||||
*/
|
||||
public class User {
|
||||
private String userId;
|
||||
private String username;
|
||||
private String password;
|
||||
private String realName;
|
||||
private String phone;
|
||||
private String email;
|
||||
private String studentId;
|
||||
private String dormitory;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private int status; // 0-正常 1-禁用
|
||||
|
||||
public User() {
|
||||
this.createTime = LocalDateTime.now();
|
||||
this.updateTime = LocalDateTime.now();
|
||||
this.status = 0;
|
||||
}
|
||||
|
||||
public User(String username, String password, String realName, String phone, String email, String studentId, String dormitory) {
|
||||
this();
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.realName = realName;
|
||||
this.phone = phone;
|
||||
this.email = email;
|
||||
this.studentId = studentId;
|
||||
this.dormitory = dormitory;
|
||||
}
|
||||
|
||||
public User(String userId, String username, String password, String realName, String phone, String email, String studentId, String dormitory, LocalDateTime createTime, LocalDateTime updateTime, int status) {
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.realName = realName;
|
||||
this.phone = phone;
|
||||
this.email = email;
|
||||
this.studentId = studentId;
|
||||
this.dormitory = dormitory;
|
||||
this.createTime = createTime;
|
||||
this.updateTime = updateTime;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
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 String getRealName() {
|
||||
return realName;
|
||||
}
|
||||
|
||||
public void setRealName(String realName) {
|
||||
this.realName = realName;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getStudentId() {
|
||||
return studentId;
|
||||
}
|
||||
|
||||
public void setStudentId(String studentId) {
|
||||
this.studentId = studentId;
|
||||
}
|
||||
|
||||
public String getDormitory() {
|
||||
return dormitory;
|
||||
}
|
||||
|
||||
public void setDormitory(String dormitory) {
|
||||
this.dormitory = dormitory;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"userId='" + userId + '\'' +
|
||||
", username='" + username + '\'' +
|
||||
", realName='" + realName + '\'' +
|
||||
", phone='" + phone + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", studentId='" + studentId + '\'' +
|
||||
", dormitory='" + dormitory + '\'' +
|
||||
", createTime=" + createTime +
|
||||
", updateTime=" + updateTime +
|
||||
", status=" + status +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
package com.campus.pickup.util;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 数据库连接工具类
|
||||
* 用于管理校园代取系统的数据库连接
|
||||
*/
|
||||
public class DatabaseUtil {
|
||||
private static final String DRIVER = "org.postgresql.Driver";
|
||||
private static final String URL = "jdbc:postgresql://localhost:5432/campus_pickup";
|
||||
private static final String USERNAME = "postgres";
|
||||
private static final String PASSWORD = "postgres";
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName(DRIVER);
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.err.println("加载数据库驱动失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库连接
|
||||
* @return 数据库连接对象
|
||||
* @throws SQLException 数据库连接异常
|
||||
*/
|
||||
public static Connection getConnection() throws SQLException {
|
||||
Properties props = new Properties();
|
||||
props.setProperty("user", USERNAME);
|
||||
props.setProperty("password", PASSWORD);
|
||||
props.setProperty("ssl", "false");
|
||||
return DriverManager.getConnection(URL, props);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭数据库连接
|
||||
* @param conn 数据库连接对象
|
||||
*/
|
||||
public static void closeConnection(Connection conn) {
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
System.err.println("关闭数据库连接失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试数据库连接
|
||||
* @return 连接是否成功
|
||||
*/
|
||||
public static boolean testConnection() {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = getConnection();
|
||||
return conn != null && !conn.isClosed();
|
||||
} catch (SQLException e) {
|
||||
System.err.println("数据库连接测试失败:" + e.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
closeConnection(conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,144 +0,0 @@
|
||||
package com.campus.pickup.view;
|
||||
|
||||
import com.campus.pickup.model.User;
|
||||
|
||||
/**
|
||||
* 主视图类
|
||||
* 处理应用程序的主界面和流程控制
|
||||
*/
|
||||
public class MainView {
|
||||
private UserView userView;
|
||||
private MessageView messageView;
|
||||
private ReviewView reviewView;
|
||||
private OrderView orderView;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public MainView() {
|
||||
this.userView = new UserView();
|
||||
this.messageView = new MessageView();
|
||||
this.reviewView = new ReviewView();
|
||||
this.orderView = new OrderView();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示欢迎界面
|
||||
*/
|
||||
public void showWelcomeScreen() {
|
||||
System.out.println("========================================");
|
||||
System.out.println(" 欢迎使用校园代取系统");
|
||||
System.out.println("========================================");
|
||||
System.out.println("本系统提供以下功能:");
|
||||
System.out.println("- 用户注册与登录");
|
||||
System.out.println("- 个人信息管理");
|
||||
System.out.println("- 消息交流");
|
||||
System.out.println("- 评价管理");
|
||||
System.out.println("- 订单配送管理");
|
||||
System.out.println("========================================");
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示主菜单
|
||||
* @return 用户选择的菜单项
|
||||
*/
|
||||
public int showMainMenu() {
|
||||
System.out.println("\n===== 校园代取系统 - 主菜单 =====");
|
||||
System.out.println("1. 用户注册");
|
||||
System.out.println("2. 用户登录");
|
||||
System.out.println("0. 退出系统");
|
||||
System.out.print("请选择操作: ");
|
||||
|
||||
try {
|
||||
java.util.Scanner scanner = new java.util.Scanner(System.in);
|
||||
int choice = Integer.parseInt(scanner.nextLine());
|
||||
return choice;
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("请输入有效的数字选项!");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行应用程序
|
||||
*/
|
||||
public void run() {
|
||||
showWelcomeScreen();
|
||||
|
||||
User currentUser = null;
|
||||
int choice;
|
||||
|
||||
do {
|
||||
if (currentUser == null) {
|
||||
choice = showMainMenu();
|
||||
|
||||
switch (choice) {
|
||||
case 1:
|
||||
userView.showRegistrationForm();
|
||||
break;
|
||||
case 2:
|
||||
currentUser = userView.showLoginForm();
|
||||
break;
|
||||
case 0:
|
||||
System.out.println("感谢使用校园代取系统,再见!");
|
||||
break;
|
||||
default:
|
||||
System.out.println("无效的选项,请重新选择!");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
choice = userView.showUserMenu(currentUser);
|
||||
|
||||
switch (choice) {
|
||||
case 1:
|
||||
userView.showUserInfo(currentUser.getUserId());
|
||||
break;
|
||||
case 2:
|
||||
userView.showUpdateUserInfoForm(currentUser.getUserId());
|
||||
break;
|
||||
case 3:
|
||||
userView.showChangePasswordForm(currentUser.getUserId());
|
||||
break;
|
||||
case 4:
|
||||
messageView.handleMessageManagement(currentUser);
|
||||
break;
|
||||
case 5:
|
||||
reviewView.handleReviewManagement(currentUser);
|
||||
break;
|
||||
case 6:
|
||||
orderView.showOrderMenu();
|
||||
break;
|
||||
case 0:
|
||||
System.out.println("已退出登录,返回主菜单...");
|
||||
currentUser = null;
|
||||
break;
|
||||
default:
|
||||
System.out.println("无效的选项,请重新选择!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (choice != 0 || currentUser != null);
|
||||
|
||||
// 关闭资源
|
||||
closeResources();
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭所有视图资源
|
||||
*/
|
||||
private void closeResources() {
|
||||
userView.close();
|
||||
messageView.close();
|
||||
reviewView.close();
|
||||
orderView.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用程序入口点
|
||||
* @param args 命令行参数
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
MainView mainView = new MainView();
|
||||
mainView.run();
|
||||
}
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package com.campus.pickup;
|
||||
|
||||
import org.junit.platform.suite.api.SelectClasses;
|
||||
import org.junit.platform.suite.api.Suite;
|
||||
|
||||
/**
|
||||
* 测试套件类
|
||||
* 运行所有人员交互功能相关的测试
|
||||
*/
|
||||
@Suite
|
||||
@SelectClasses({
|
||||
com.campus.pickup.model.UserTest.class,
|
||||
com.campus.pickup.model.MessageTest.class,
|
||||
com.campus.pickup.model.ReviewTest.class,
|
||||
com.campus.pickup.service.UserServiceTest.class,
|
||||
com.campus.pickup.service.MessageServiceTest.class,
|
||||
com.campus.pickup.service.ReviewServiceTest.class
|
||||
})
|
||||
public class PersonnelInteractionTestSuite {
|
||||
}
|
||||
@ -1,122 +0,0 @@
|
||||
package com.campus.pickup.model;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* Message实体类测试
|
||||
*/
|
||||
public class MessageTest {
|
||||
private Message message;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
message = new Message();
|
||||
message.setMessageId("msg001");
|
||||
message.setSenderId("sender001");
|
||||
message.setReceiverId("receiver001");
|
||||
message.setContent("这是一条测试消息");
|
||||
message.setSendTime(LocalDateTime.now());
|
||||
message.setReadTime(LocalDateTime.now());
|
||||
message.setStatus(0);
|
||||
message.setType(Message.MessageType.USER_MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetMessageId() {
|
||||
assertEquals("msg001", message.getMessageId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetSenderId() {
|
||||
assertEquals("sender001", message.getSenderId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetReceiverId() {
|
||||
assertEquals("receiver001", message.getReceiverId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetContent() {
|
||||
assertEquals("这是一条测试消息", message.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetStatus() {
|
||||
assertEquals(0, message.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetType() {
|
||||
assertEquals(Message.MessageType.USER_MESSAGE, message.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMessageTypeEnum() {
|
||||
// 测试枚举值
|
||||
assertEquals(0, Message.MessageType.SYSTEM_NOTIFICATION.getCode());
|
||||
assertEquals("系统通知", Message.MessageType.SYSTEM_NOTIFICATION.getDescription());
|
||||
|
||||
assertEquals(1, Message.MessageType.USER_MESSAGE.getCode());
|
||||
assertEquals("用户消息", Message.MessageType.USER_MESSAGE.getDescription());
|
||||
|
||||
assertEquals(2, Message.MessageType.ORDER_MESSAGE.getCode());
|
||||
assertEquals("订单消息", Message.MessageType.ORDER_MESSAGE.getDescription());
|
||||
|
||||
assertEquals(3, Message.MessageType.REVIEW_MESSAGE.getCode());
|
||||
assertEquals("评价消息", Message.MessageType.REVIEW_MESSAGE.getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMessageTypeFromCode() {
|
||||
assertEquals(Message.MessageType.SYSTEM_NOTIFICATION, Message.MessageType.fromCode(0));
|
||||
assertEquals(Message.MessageType.USER_MESSAGE, Message.MessageType.fromCode(1));
|
||||
assertEquals(Message.MessageType.ORDER_MESSAGE, Message.MessageType.fromCode(2));
|
||||
assertEquals(Message.MessageType.REVIEW_MESSAGE, Message.MessageType.fromCode(3));
|
||||
|
||||
// 测试无效代码
|
||||
assertNull(Message.MessageType.fromCode(-1));
|
||||
assertNull(Message.MessageType.fromCode(99));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
String messageString = message.toString();
|
||||
assertTrue(messageString.contains("msg001"));
|
||||
assertTrue(messageString.contains("sender001"));
|
||||
assertTrue(messageString.contains("receiver001"));
|
||||
assertTrue(messageString.contains("这是一条测试消息"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultConstructor() {
|
||||
Message newMessage = new Message();
|
||||
assertNotNull(newMessage);
|
||||
assertNull(newMessage.getMessageId());
|
||||
assertNull(newMessage.getSenderId());
|
||||
assertNull(newMessage.getReceiverId());
|
||||
assertNull(newMessage.getContent());
|
||||
assertNull(newMessage.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testParameterizedConstructor() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
Message newMessage = new Message("msg002", "sender002", "receiver002",
|
||||
"新消息内容", now, now, 1,
|
||||
Message.MessageType.SYSTEM_NOTIFICATION);
|
||||
|
||||
assertEquals("msg002", newMessage.getMessageId());
|
||||
assertEquals("sender002", newMessage.getSenderId());
|
||||
assertEquals("receiver002", newMessage.getReceiverId());
|
||||
assertEquals("新消息内容", newMessage.getContent());
|
||||
assertEquals(now, newMessage.getSendTime());
|
||||
assertEquals(now, newMessage.getReadTime());
|
||||
assertEquals(1, newMessage.getStatus());
|
||||
assertEquals(Message.MessageType.SYSTEM_NOTIFICATION, newMessage.getType());
|
||||
}
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
package com.campus.pickup.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* Review实体类测试
|
||||
*/
|
||||
public class ReviewTest {
|
||||
private Review review;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
review = new Review();
|
||||
review.setReviewId("review001");
|
||||
review.setOrderId("order001");
|
||||
review.setReviewerId("reviewer001");
|
||||
review.setReviewedId("reviewed001");
|
||||
review.setRating(5);
|
||||
review.setContent("非常满意的服务");
|
||||
review.setCreateTime(LocalDateTime.now());
|
||||
review.setUpdateTime(LocalDateTime.now());
|
||||
review.setStatus(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetReviewId() {
|
||||
assertEquals("review001", review.getReviewId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetOrderId() {
|
||||
assertEquals("order001", review.getOrderId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetReviewerId() {
|
||||
assertEquals("reviewer001", review.getReviewerId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetReviewedId() {
|
||||
assertEquals("reviewed001", review.getReviewedId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetRating() {
|
||||
assertEquals(5, review.getRating());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetContent() {
|
||||
assertEquals("非常满意的服务", review.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetStatus() {
|
||||
assertEquals(0, review.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
String reviewString = review.toString();
|
||||
assertTrue(reviewString.contains("review001"));
|
||||
assertTrue(reviewString.contains("order001"));
|
||||
assertTrue(reviewString.contains("reviewer001"));
|
||||
assertTrue(reviewString.contains("reviewed001"));
|
||||
assertTrue(reviewString.contains("非常满意的服务"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultConstructor() {
|
||||
Review newReview = new Review();
|
||||
assertNotNull(newReview);
|
||||
assertNull(newReview.getReviewId());
|
||||
assertNull(newReview.getOrderId());
|
||||
assertNull(newReview.getReviewerId());
|
||||
assertNull(newReview.getReviewedId());
|
||||
assertEquals(0, newReview.getRating());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testParameterizedConstructor() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
Review newReview = new Review("review002", "order002", "reviewer002",
|
||||
"reviewed002", 4, "服务很好", now, now, 0);
|
||||
|
||||
assertEquals("review002", newReview.getReviewId());
|
||||
assertEquals("order002", newReview.getOrderId());
|
||||
assertEquals("reviewer002", newReview.getReviewerId());
|
||||
assertEquals("reviewed002", newReview.getReviewedId());
|
||||
assertEquals(4, newReview.getRating());
|
||||
assertEquals("服务很好", newReview.getContent());
|
||||
assertEquals(now, newReview.getCreateTime());
|
||||
assertEquals(now, newReview.getUpdateTime());
|
||||
assertEquals(0, newReview.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRatingBoundary() {
|
||||
// 测试评分边界值
|
||||
Review minRatingReview = new Review();
|
||||
minRatingReview.setRating(1);
|
||||
assertEquals(1, minRatingReview.getRating());
|
||||
|
||||
Review maxRatingReview = new Review();
|
||||
maxRatingReview.setRating(5);
|
||||
assertEquals(5, maxRatingReview.getRating());
|
||||
}
|
||||
}
|
||||
@ -1,112 +0,0 @@
|
||||
package com.campus.pickup.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 测试核心代码
|
||||
*/
|
||||
public class TestMainCode {
|
||||
|
||||
// ========== User测试核心 ==========
|
||||
|
||||
@Test
|
||||
void testUserModel() {
|
||||
User user = new User();
|
||||
user.setUserId("user001");
|
||||
user.setUsername("testuser");
|
||||
user.setPassword("password123");
|
||||
|
||||
assertEquals("user001", user.getUserId());
|
||||
assertEquals("testuser", user.getUsername());
|
||||
assertEquals("password123", user.getPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUserParameterizedConstructor() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
User user = new User("user002", "newuser", "newpass", "新用户",
|
||||
"13900139000", "new@example.com", "20210002",
|
||||
"西区2号楼202", now, now, 0);
|
||||
|
||||
assertEquals("user002", user.getUserId());
|
||||
assertEquals("newuser", user.getUsername());
|
||||
assertEquals("newpass", user.getPassword());
|
||||
}
|
||||
|
||||
// ========== Message测试核心 ==========
|
||||
|
||||
@Test
|
||||
void testMessageModel() {
|
||||
Message message = new Message();
|
||||
message.setMessageId("msg001");
|
||||
message.setSenderId("sender001");
|
||||
message.setReceiverId("receiver001");
|
||||
message.setContent("这是一条测试消息");
|
||||
message.setType(Message.MessageType.USER_MESSAGE);
|
||||
|
||||
assertEquals("msg001", message.getMessageId());
|
||||
assertEquals("sender001", message.getSenderId());
|
||||
assertEquals("receiver001", message.getReceiverId());
|
||||
assertEquals("这是一条测试消息", message.getContent());
|
||||
assertEquals(Message.MessageType.USER_MESSAGE, message.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMessageTypeEnum() {
|
||||
assertEquals(0, Message.MessageType.SYSTEM_NOTIFICATION.getCode());
|
||||
assertEquals(1, Message.MessageType.USER_MESSAGE.getCode());
|
||||
assertEquals(2, Message.MessageType.ORDER_MESSAGE.getCode());
|
||||
assertEquals(3, Message.MessageType.REVIEW_MESSAGE.getCode());
|
||||
|
||||
assertEquals(Message.MessageType.SYSTEM_NOTIFICATION, Message.MessageType.fromCode(0));
|
||||
assertEquals(Message.MessageType.USER_MESSAGE, Message.MessageType.fromCode(1));
|
||||
assertNull(Message.MessageType.fromCode(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMessageParameterizedConstructor() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
Message message = new Message("msg002", "sender002", "receiver002",
|
||||
"新消息内容", now, now, 1,
|
||||
Message.MessageType.SYSTEM_NOTIFICATION);
|
||||
|
||||
assertEquals("msg002", message.getMessageId());
|
||||
assertEquals("sender002", message.getSenderId());
|
||||
assertEquals(Message.MessageType.SYSTEM_NOTIFICATION, message.getType());
|
||||
}
|
||||
|
||||
// ========== Review测试核心 ==========
|
||||
|
||||
@Test
|
||||
void testReviewModel() {
|
||||
Review review = new Review();
|
||||
review.setReviewId("review001");
|
||||
review.setOrderId("order001");
|
||||
review.setReviewerId("reviewer001");
|
||||
review.setReviewedId("reviewed001");
|
||||
review.setRating(5);
|
||||
review.setContent("非常满意的服务");
|
||||
|
||||
assertEquals("review001", review.getReviewId());
|
||||
assertEquals("order001", review.getOrderId());
|
||||
assertEquals("reviewer001", review.getReviewerId());
|
||||
assertEquals("reviewed001", review.getReviewedId());
|
||||
assertEquals(5, review.getRating());
|
||||
assertEquals("非常满意的服务", review.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReviewParameterizedConstructor() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
Review review = new Review("review002", "order002", "reviewer002",
|
||||
"reviewed002", 4, "服务很好", now, now, 0);
|
||||
|
||||
assertEquals("review002", review.getReviewId());
|
||||
assertEquals("order002", review.getOrderId());
|
||||
assertEquals(4, review.getRating());
|
||||
assertEquals("服务很好", review.getContent());
|
||||
}
|
||||
}
|
||||
@ -1,111 +0,0 @@
|
||||
package com.campus.pickup.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* User实体类测试
|
||||
*/
|
||||
public class UserTest {
|
||||
private User user;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
user = new User();
|
||||
user.setUserId("user001");
|
||||
user.setUsername("testuser");
|
||||
user.setPassword("password123");
|
||||
user.setRealName("测试用户");
|
||||
user.setPhone("13800138000");
|
||||
user.setEmail("test@example.com");
|
||||
user.setStudentId("20210001");
|
||||
user.setDormitory("东区1号楼101");
|
||||
user.setCreateTime(LocalDateTime.now());
|
||||
user.setUpdateTime(LocalDateTime.now());
|
||||
user.setStatus(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetUserId() {
|
||||
assertEquals("user001", user.getUserId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetUsername() {
|
||||
assertEquals("testuser", user.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetPassword() {
|
||||
assertEquals("password123", user.getPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetRealName() {
|
||||
assertEquals("测试用户", user.getRealName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetPhone() {
|
||||
assertEquals("13800138000", user.getPhone());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetEmail() {
|
||||
assertEquals("test@example.com", user.getEmail());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetStudentId() {
|
||||
assertEquals("20210001", user.getStudentId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetDormitory() {
|
||||
assertEquals("东区1号楼101", user.getDormitory());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetStatus() {
|
||||
assertEquals(0, user.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
String userString = user.toString();
|
||||
assertTrue(userString.contains("user001"));
|
||||
assertTrue(userString.contains("testuser"));
|
||||
assertTrue(userString.contains("测试用户"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultConstructor() {
|
||||
User newUser = new User();
|
||||
assertNotNull(newUser);
|
||||
assertNull(newUser.getUserId());
|
||||
assertNull(newUser.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testParameterizedConstructor() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
User newUser = new User("user002", "newuser", "newpass", "新用户",
|
||||
"13900139000", "new@example.com", "20210002",
|
||||
"西区2号楼202", now, now, 0);
|
||||
|
||||
assertEquals("user002", newUser.getUserId());
|
||||
assertEquals("newuser", newUser.getUsername());
|
||||
assertEquals("newpass", newUser.getPassword());
|
||||
assertEquals("新用户", newUser.getRealName());
|
||||
assertEquals("13900139000", newUser.getPhone());
|
||||
assertEquals("new@example.com", newUser.getEmail());
|
||||
assertEquals("20210002", newUser.getStudentId());
|
||||
assertEquals("西区2号楼202", newUser.getDormitory());
|
||||
assertEquals(now, newUser.getCreateTime());
|
||||
assertEquals(now, newUser.getUpdateTime());
|
||||
assertEquals(0, newUser.getStatus());
|
||||
}
|
||||
}
|
||||
@ -1,326 +0,0 @@
|
||||
package com.campus.pickup.service;
|
||||
|
||||
import com.campus.pickup.dao.ReviewDao;
|
||||
import com.campus.pickup.model.Review;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* ReviewService测试类
|
||||
*/
|
||||
public class ReviewServiceTest {
|
||||
@Mock
|
||||
private ReviewDao reviewDao;
|
||||
|
||||
private ReviewService reviewService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
reviewService = new ReviewService();
|
||||
// 使用反射设置私有字段
|
||||
try {
|
||||
java.lang.reflect.Field field = ReviewService.class.getDeclaredField("reviewDao");
|
||||
field.setAccessible(true);
|
||||
field.set(reviewService, reviewDao);
|
||||
} catch (Exception e) {
|
||||
fail("设置测试环境失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddReviewSuccess() {
|
||||
// 准备测试数据
|
||||
String orderId = "order001";
|
||||
String reviewerId = "reviewer001";
|
||||
String reviewedId = "reviewed001";
|
||||
int rating = 5;
|
||||
String content = "非常满意的服务";
|
||||
|
||||
// 模拟DAO行为
|
||||
when(reviewDao.getReviewByOrderId(orderId)).thenReturn(null);
|
||||
when(reviewDao.addReview(any(Review.class))).thenReturn(true);
|
||||
|
||||
// 执行测试
|
||||
boolean result = reviewService.addReview(orderId, reviewerId, reviewedId, rating, content);
|
||||
|
||||
// 验证结果
|
||||
assertTrue(result);
|
||||
verify(reviewDao).getReviewByOrderId(orderId);
|
||||
verify(reviewDao).addReview(any(Review.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddReviewInvalidRating() {
|
||||
// 准备测试数据
|
||||
String orderId = "order001";
|
||||
String reviewerId = "reviewer001";
|
||||
String reviewedId = "reviewed001";
|
||||
int rating = 6; // 无效评分
|
||||
String content = "非常满意的服务";
|
||||
|
||||
// 执行测试
|
||||
boolean result = reviewService.addReview(orderId, reviewerId, reviewedId, rating, content);
|
||||
|
||||
// 验证结果
|
||||
assertFalse(result);
|
||||
verify(reviewDao, never()).addReview(any(Review.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddReviewOrderAlreadyReviewed() {
|
||||
// 准备测试数据
|
||||
String orderId = "order001";
|
||||
String reviewerId = "reviewer001";
|
||||
String reviewedId = "reviewed001";
|
||||
int rating = 5;
|
||||
String content = "非常满意的服务";
|
||||
|
||||
Review existingReview = new Review();
|
||||
existingReview.setOrderId(orderId);
|
||||
|
||||
// 模拟DAO行为
|
||||
when(reviewDao.getReviewByOrderId(orderId)).thenReturn(existingReview);
|
||||
|
||||
// 执行测试
|
||||
boolean result = reviewService.addReview(orderId, reviewerId, reviewedId, rating, content);
|
||||
|
||||
// 验证结果
|
||||
assertFalse(result);
|
||||
verify(reviewDao).getReviewByOrderId(orderId);
|
||||
verify(reviewDao, never()).addReview(any(Review.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetReviewById() {
|
||||
// 准备测试数据
|
||||
String reviewId = "review001";
|
||||
Review review = new Review();
|
||||
review.setReviewId(reviewId);
|
||||
review.setRating(5);
|
||||
review.setContent("非常满意的服务");
|
||||
|
||||
// 模拟DAO行为
|
||||
when(reviewDao.getReviewById(reviewId)).thenReturn(review);
|
||||
|
||||
// 执行测试
|
||||
Review result = reviewService.getReviewById(reviewId);
|
||||
|
||||
// 验证结果
|
||||
assertNotNull(result);
|
||||
assertEquals(reviewId, result.getReviewId());
|
||||
assertEquals(5, result.getRating());
|
||||
assertEquals("非常满意的服务", result.getContent());
|
||||
verify(reviewDao).getReviewById(reviewId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetReviewByOrderId() {
|
||||
// 准备测试数据
|
||||
String orderId = "order001";
|
||||
Review review = new Review();
|
||||
review.setReviewId("review001");
|
||||
review.setOrderId(orderId);
|
||||
review.setRating(4);
|
||||
review.setContent("服务很好");
|
||||
|
||||
// 模拟DAO行为
|
||||
when(reviewDao.getReviewByOrderId(orderId)).thenReturn(review);
|
||||
|
||||
// 执行测试
|
||||
Review result = reviewService.getReviewByOrderId(orderId);
|
||||
|
||||
// 验证结果
|
||||
assertNotNull(result);
|
||||
assertEquals(orderId, result.getOrderId());
|
||||
assertEquals(4, result.getRating());
|
||||
assertEquals("服务很好", result.getContent());
|
||||
verify(reviewDao).getReviewByOrderId(orderId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetReviewsReceivedByUser() {
|
||||
// 准备测试数据
|
||||
String userId = "user001";
|
||||
List<Review> reviews = Arrays.asList(
|
||||
createReview("review001", "order001", "reviewer001", userId, 5, "非常满意"),
|
||||
createReview("review002", "order002", "reviewer002", userId, 4, "满意")
|
||||
);
|
||||
|
||||
// 模拟DAO行为
|
||||
when(reviewDao.getReviewsByReviewedId(userId)).thenReturn(reviews);
|
||||
|
||||
// 执行测试
|
||||
List<Review> result = reviewService.getReviewsReceivedByUser(userId);
|
||||
|
||||
// 验证结果
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("review001", result.get(0).getReviewId());
|
||||
assertEquals("review002", result.get(1).getReviewId());
|
||||
verify(reviewDao).getReviewsByReviewedId(userId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAverageRatingForUser() {
|
||||
// 准备测试数据
|
||||
String userId = "user001";
|
||||
double averageRating = 4.5;
|
||||
|
||||
// 模拟DAO行为
|
||||
when(reviewDao.getAverageRatingByUserId(userId)).thenReturn(averageRating);
|
||||
|
||||
// 执行测试
|
||||
double result = reviewService.getAverageRatingForUser(userId);
|
||||
|
||||
// 验证结果
|
||||
assertEquals(averageRating, result);
|
||||
verify(reviewDao).getAverageRatingByUserId(userId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateReviewSuccess() {
|
||||
// 准备测试数据
|
||||
String reviewId = "review001";
|
||||
int newRating = 4;
|
||||
String newContent = "更新后的评价内容";
|
||||
|
||||
Review existingReview = new Review();
|
||||
existingReview.setReviewId(reviewId);
|
||||
existingReview.setRating(5);
|
||||
existingReview.setContent("原始评价内容");
|
||||
|
||||
// 模拟DAO行为
|
||||
when(reviewDao.getReviewById(reviewId)).thenReturn(existingReview);
|
||||
when(reviewDao.updateReview(any(Review.class))).thenReturn(true);
|
||||
|
||||
// 执行测试
|
||||
boolean result = reviewService.updateReview(reviewId, newRating, newContent);
|
||||
|
||||
// 验证结果
|
||||
assertTrue(result);
|
||||
assertEquals(newRating, existingReview.getRating());
|
||||
assertEquals(newContent, existingReview.getContent());
|
||||
verify(reviewDao).getReviewById(reviewId);
|
||||
verify(reviewDao).updateReview(existingReview);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateReviewInvalidRating() {
|
||||
// 准备测试数据
|
||||
String reviewId = "review001";
|
||||
int newRating = 6; // 无效评分
|
||||
String newContent = "更新后的评价内容";
|
||||
|
||||
// 执行测试
|
||||
boolean result = reviewService.updateReview(reviewId, newRating, newContent);
|
||||
|
||||
// 验证结果
|
||||
assertFalse(result);
|
||||
verify(reviewDao, never()).getReviewById(anyString());
|
||||
verify(reviewDao, never()).updateReview(any(Review.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteReviewSuccess() {
|
||||
// 准备测试数据
|
||||
String reviewId = "review001";
|
||||
|
||||
// 模拟DAO行为
|
||||
when(reviewDao.deleteReview(reviewId)).thenReturn(true);
|
||||
|
||||
// 执行测试
|
||||
boolean result = reviewService.deleteReview(reviewId);
|
||||
|
||||
// 验证结果
|
||||
assertTrue(result);
|
||||
verify(reviewDao).deleteReview(reviewId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCanUserReviewOrderUnreviewedOrder() {
|
||||
// 准备测试数据
|
||||
String orderId = "order001";
|
||||
String userId = "user001";
|
||||
|
||||
// 模拟DAO行为
|
||||
when(reviewDao.getReviewByOrderId(orderId)).thenReturn(null);
|
||||
|
||||
// 执行测试
|
||||
boolean result = reviewService.canUserReviewOrder(orderId, userId);
|
||||
|
||||
// 验证结果
|
||||
assertTrue(result);
|
||||
verify(reviewDao).getReviewByOrderId(orderId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCanUserReviewOrderSameReviewer() {
|
||||
// 准备测试数据
|
||||
String orderId = "order001";
|
||||
String userId = "user001";
|
||||
|
||||
Review existingReview = new Review();
|
||||
existingReview.setOrderId(orderId);
|
||||
existingReview.setReviewerId(userId);
|
||||
|
||||
// 模拟DAO行为
|
||||
when(reviewDao.getReviewByOrderId(orderId)).thenReturn(existingReview);
|
||||
|
||||
// 执行测试
|
||||
boolean result = reviewService.canUserReviewOrder(orderId, userId);
|
||||
|
||||
// 验证结果
|
||||
assertTrue(result);
|
||||
verify(reviewDao).getReviewByOrderId(orderId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCanUserReviewOrderDifferentReviewer() {
|
||||
// 准备测试数据
|
||||
String orderId = "order001";
|
||||
String userId = "user001";
|
||||
String otherUserId = "user002";
|
||||
|
||||
Review existingReview = new Review();
|
||||
existingReview.setOrderId(orderId);
|
||||
existingReview.setReviewerId(otherUserId);
|
||||
|
||||
// 模拟DAO行为
|
||||
when(reviewDao.getReviewByOrderId(orderId)).thenReturn(existingReview);
|
||||
|
||||
// 执行测试
|
||||
boolean result = reviewService.canUserReviewOrder(orderId, userId);
|
||||
|
||||
// 验证结果
|
||||
assertFalse(result);
|
||||
verify(reviewDao).getReviewByOrderId(orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建测试用的评价对象
|
||||
*/
|
||||
private Review createReview(String reviewId, String orderId, String reviewerId,
|
||||
String reviewedId, int rating, String content) {
|
||||
Review review = new Review();
|
||||
review.setReviewId(reviewId);
|
||||
review.setOrderId(orderId);
|
||||
review.setReviewerId(reviewerId);
|
||||
review.setReviewedId(reviewedId);
|
||||
review.setRating(rating);
|
||||
review.setContent(content);
|
||||
review.setCreateTime(LocalDateTime.now());
|
||||
review.setUpdateTime(LocalDateTime.now());
|
||||
review.setStatus(0);
|
||||
return review;
|
||||
}
|
||||
}
|
||||
@ -1,290 +0,0 @@
|
||||
package com.campus.pickup.service;
|
||||
|
||||
import com.campus.pickup.dao.UserDao;
|
||||
import com.campus.pickup.model.User;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* UserService测试类
|
||||
*/
|
||||
public class UserServiceTest {
|
||||
@Mock
|
||||
private UserDao userDao;
|
||||
|
||||
private UserService userService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
userService = new UserService();
|
||||
// 使用反射设置私有字段
|
||||
try {
|
||||
java.lang.reflect.Field field = UserService.class.getDeclaredField("userDao");
|
||||
field.setAccessible(true);
|
||||
field.set(userService, userDao);
|
||||
} catch (Exception e) {
|
||||
fail("设置测试环境失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRegisterSuccess() {
|
||||
// 准备测试数据
|
||||
User user = new User();
|
||||
user.setUsername("newuser");
|
||||
user.setPassword("password123");
|
||||
user.setRealName("新用户");
|
||||
user.setPhone("13800138000");
|
||||
user.setEmail("newuser@example.com");
|
||||
user.setStudentId("20210001");
|
||||
user.setDormitory("东区1号楼101");
|
||||
|
||||
// 模拟DAO行为
|
||||
when(userDao.getUserByUsername("newuser")).thenReturn(null);
|
||||
when(userDao.addUser(any(User.class))).thenReturn(true);
|
||||
|
||||
// 执行测试
|
||||
boolean result = userService.register(user);
|
||||
|
||||
// 验证结果
|
||||
assertTrue(result);
|
||||
verify(userDao).getUserByUsername("newuser");
|
||||
verify(userDao).addUser(any(User.class));
|
||||
assertEquals(0, user.getStatus()); // 默认状态应为正常
|
||||
assertNotNull(user.getCreateTime());
|
||||
assertNotNull(user.getUpdateTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRegisterUsernameExists() {
|
||||
// 准备测试数据
|
||||
User user = new User();
|
||||
user.setUsername("existinguser");
|
||||
user.setPassword("password123");
|
||||
|
||||
User existingUser = new User();
|
||||
existingUser.setUsername("existinguser");
|
||||
|
||||
// 模拟DAO行为
|
||||
when(userDao.getUserByUsername("existinguser")).thenReturn(existingUser);
|
||||
|
||||
// 执行测试
|
||||
boolean result = userService.register(user);
|
||||
|
||||
// 验证结果
|
||||
assertFalse(result);
|
||||
verify(userDao).getUserByUsername("existinguser");
|
||||
verify(userDao, never()).addUser(any(User.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLoginSuccess() {
|
||||
// 准备测试数据
|
||||
User user = new User();
|
||||
user.setUserId("user001");
|
||||
user.setUsername("testuser");
|
||||
user.setPassword("password123");
|
||||
user.setStatus(0); // 正常状态
|
||||
|
||||
// 模拟DAO行为
|
||||
when(userDao.getUserByUsername("testuser")).thenReturn(user);
|
||||
|
||||
// 执行测试
|
||||
User result = userService.login("testuser", "password123");
|
||||
|
||||
// 验证结果
|
||||
assertNotNull(result);
|
||||
assertEquals("testuser", result.getUsername());
|
||||
assertEquals("password123", result.getPassword());
|
||||
verify(userDao).getUserByUsername("testuser");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLoginWrongPassword() {
|
||||
// 准备测试数据
|
||||
User user = new User();
|
||||
user.setUsername("testuser");
|
||||
user.setPassword("password123");
|
||||
user.setStatus(0); // 正常状态
|
||||
|
||||
// 模拟DAO行为
|
||||
when(userDao.getUserByUsername("testuser")).thenReturn(user);
|
||||
|
||||
// 执行测试
|
||||
User result = userService.login("testuser", "wrongpassword");
|
||||
|
||||
// 验证结果
|
||||
assertNull(result);
|
||||
verify(userDao).getUserByUsername("testuser");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLoginUserNotFound() {
|
||||
// 模拟DAO行为
|
||||
when(userDao.getUserByUsername("nonexistent")).thenReturn(null);
|
||||
|
||||
// 执行测试
|
||||
User result = userService.login("nonexistent", "password123");
|
||||
|
||||
// 验证结果
|
||||
assertNull(result);
|
||||
verify(userDao).getUserByUsername("nonexistent");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLoginUserDisabled() {
|
||||
// 准备测试数据
|
||||
User user = new User();
|
||||
user.setUsername("disableduser");
|
||||
user.setPassword("password123");
|
||||
user.setStatus(1); // 禁用状态
|
||||
|
||||
// 模拟DAO行为
|
||||
when(userDao.getUserByUsername("disableduser")).thenReturn(user);
|
||||
|
||||
// 执行测试
|
||||
User result = userService.login("disableduser", "password123");
|
||||
|
||||
// 验证结果
|
||||
assertNull(result);
|
||||
verify(userDao).getUserByUsername("disableduser");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetUserById() {
|
||||
// 准备测试数据
|
||||
User user = new User();
|
||||
user.setUserId("user001");
|
||||
user.setUsername("testuser");
|
||||
|
||||
// 模拟DAO行为
|
||||
when(userDao.getUserById("user001")).thenReturn(user);
|
||||
|
||||
// 执行测试
|
||||
User result = userService.getUserById("user001");
|
||||
|
||||
// 验证结果
|
||||
assertNotNull(result);
|
||||
assertEquals("user001", result.getUserId());
|
||||
assertEquals("testuser", result.getUsername());
|
||||
verify(userDao).getUserById("user001");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateUser() {
|
||||
// 准备测试数据
|
||||
User user = new User();
|
||||
user.setUserId("user001");
|
||||
user.setUsername("testuser");
|
||||
user.setRealName("测试用户");
|
||||
|
||||
// 模拟DAO行为
|
||||
when(userDao.updateUser(any(User.class))).thenReturn(true);
|
||||
|
||||
// 执行测试
|
||||
boolean result = userService.updateUser(user);
|
||||
|
||||
// 验证结果
|
||||
assertTrue(result);
|
||||
verify(userDao).updateUser(user);
|
||||
assertNotNull(user.getUpdateTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testChangePasswordSuccess() {
|
||||
// 准备测试数据
|
||||
User user = new User();
|
||||
user.setUserId("user001");
|
||||
user.setPassword("oldpassword");
|
||||
|
||||
// 模拟DAO行为
|
||||
when(userDao.getUserById("user001")).thenReturn(user);
|
||||
when(userDao.updateUser(any(User.class))).thenReturn(true);
|
||||
|
||||
// 执行测试
|
||||
boolean result = userService.changePassword("user001", "oldpassword", "newpassword");
|
||||
|
||||
// 验证结果
|
||||
assertTrue(result);
|
||||
assertEquals("newpassword", user.getPassword());
|
||||
verify(userDao).getUserById("user001");
|
||||
verify(userDao).updateUser(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testChangePasswordWrongOldPassword() {
|
||||
// 准备测试数据
|
||||
User user = new User();
|
||||
user.setUserId("user001");
|
||||
user.setPassword("oldpassword");
|
||||
|
||||
// 模拟DAO行为
|
||||
when(userDao.getUserById("user001")).thenReturn(user);
|
||||
|
||||
// 执行测试
|
||||
boolean result = userService.changePassword("user001", "wrongpassword", "newpassword");
|
||||
|
||||
// 验证结果
|
||||
assertFalse(result);
|
||||
assertEquals("oldpassword", user.getPassword()); // 密码不应改变
|
||||
verify(userDao).getUserById("user001");
|
||||
verify(userDao, never()).updateUser(any(User.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testChangeUserStatus() {
|
||||
// 准备测试数据
|
||||
User user = new User();
|
||||
user.setUserId("user001");
|
||||
user.setStatus(0); // 正常状态
|
||||
|
||||
// 模拟DAO行为
|
||||
when(userDao.getUserById("user001")).thenReturn(user);
|
||||
when(userDao.updateUser(any(User.class))).thenReturn(true);
|
||||
|
||||
// 执行测试
|
||||
boolean result = userService.changeUserStatus("user001", 1); // 禁用用户
|
||||
|
||||
// 验证结果
|
||||
assertTrue(result);
|
||||
assertEquals(1, user.getStatus());
|
||||
verify(userDao).getUserById("user001");
|
||||
verify(userDao).updateUser(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAllUsers() {
|
||||
// 准备测试数据
|
||||
List<User> users = Arrays.asList(
|
||||
new User("user001", "user1", "pass1", "用户1", "13800138001",
|
||||
"user1@example.com", "20210001", "东区1号楼101",
|
||||
LocalDateTime.now(), LocalDateTime.now(), 0),
|
||||
new User("user002", "user2", "pass2", "用户2", "13800138002",
|
||||
"user2@example.com", "20210002", "东区1号楼102",
|
||||
LocalDateTime.now(), LocalDateTime.now(), 0)
|
||||
);
|
||||
|
||||
// 模拟DAO行为
|
||||
when(userDao.getAllUsers()).thenReturn(users);
|
||||
|
||||
// 执行测试
|
||||
List<User> result = userService.getAllUsers();
|
||||
|
||||
// 验证结果
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("user1", result.get(0).getUsername());
|
||||
assertEquals("user2", result.get(1).getUsername());
|
||||
verify(userDao).getAllUsers();
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
@echo off
|
||||
echo ========================================
|
||||
echo 校园代取系统 - 运行单元测试
|
||||
echo ========================================
|
||||
echo.
|
||||
|
||||
echo 正在编译测试文件...
|
||||
javac -d bin -cp "lib/*;junit-platform-console-standalone-1.7.0.jar" src/main/java/com/campus/pickup/**/*.java src/test/java/com/campus/pickup/**/*.java
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
echo 编译失败,请检查代码!
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo 编译成功!
|
||||
|
||||
echo.
|
||||
echo 正在运行单元测试...
|
||||
java -jar junit-platform-console-standalone-1.7.0.jar --class-path "bin" --scan-class-path
|
||||
|
||||
pause
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -1,21 +0,0 @@
|
||||
@echo off
|
||||
echo ========================================
|
||||
echo 校园代取系统 - 人员交互功能
|
||||
echo ========================================
|
||||
echo.
|
||||
|
||||
echo 正在编译Java源文件...
|
||||
javac -d bin -cp "lib/*" src/main/java/com/campus/pickup/**/*.java
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
echo 编译失败,请检查代码!
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo 编译成功!
|
||||
|
||||
echo.
|
||||
echo 正在运行校园代取系统...
|
||||
java -cp "bin;lib/*" com.campus.pickup.view.MainView
|
||||
|
||||
pause
|
||||
@ -1,69 +0,0 @@
|
||||
package com.campus.pickup.controller;
|
||||
|
||||
import com.campus.pickup.model.User;
|
||||
import com.campus.pickup.model.Message;
|
||||
import com.campus.pickup.model.Review;
|
||||
import com.campus.pickup.service.UserService;
|
||||
import com.campus.pickup.service.MessageService;
|
||||
import com.campus.pickup.service.ReviewService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 控制器核心代码
|
||||
*/
|
||||
public class ControllerMainCode {
|
||||
|
||||
// ========== 用户控制器核心功能 ==========
|
||||
|
||||
public boolean register(String username, String password, String realName, String phone, String email, String studentId, String dormitory) {
|
||||
User user = new User();
|
||||
user.setUserId(java.util.UUID.randomUUID().toString().replace("-", ""));
|
||||
user.setUsername(username);
|
||||
user.setPassword(password);
|
||||
user.setRealName(realName);
|
||||
user.setPhone(phone);
|
||||
user.setEmail(email);
|
||||
user.setStudentId(studentId);
|
||||
user.setDormitory(dormitory);
|
||||
|
||||
return new UserService().register(user);
|
||||
}
|
||||
|
||||
public User login(String username, String password) {
|
||||
return new UserService().login(username, password);
|
||||
}
|
||||
|
||||
public User getUserInfo(String userId) {
|
||||
return new UserService().getUserById(userId);
|
||||
}
|
||||
|
||||
// ========== 消息控制器核心功能 ==========
|
||||
|
||||
public boolean sendMessage(String senderId, String receiverId, String content, int typeCode) {
|
||||
Message.MessageType type = Message.MessageType.fromCode(typeCode);
|
||||
return new MessageService().sendMessage(senderId, receiverId, content, type);
|
||||
}
|
||||
|
||||
public List<Message> getReceivedMessages(String receiverId) {
|
||||
return new MessageService().getReceivedMessages(receiverId);
|
||||
}
|
||||
|
||||
public int getUnreadMessageCount(String receiverId) {
|
||||
return new MessageService().getUnreadMessageCount(receiverId);
|
||||
}
|
||||
|
||||
// ========== 评价控制器核心功能 ==========
|
||||
|
||||
public boolean addReview(String orderId, String reviewerId, String reviewedId, int rating, String content) {
|
||||
return new ReviewService().addReview(orderId, reviewerId, reviewedId, rating, content);
|
||||
}
|
||||
|
||||
public List<Review> getReviewsReceivedByUser(String userId) {
|
||||
return new ReviewService().getReviewsReceivedByUser(userId);
|
||||
}
|
||||
|
||||
public double getAverageRatingForUser(String userId) {
|
||||
return new ReviewService().getAverageRatingForUser(userId);
|
||||
}
|
||||
}
|
||||
@ -1,285 +0,0 @@
|
||||
package com.campus.pickup.controller;
|
||||
|
||||
import com.campus.pickup.model.Message;
|
||||
import com.campus.pickup.service.MessageService;
|
||||
import com.campus.pickup.util.DatabaseUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 消息控制器类
|
||||
* 处理消息相关的请求
|
||||
*/
|
||||
public class MessageController {
|
||||
private MessageService messageService;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public MessageController() {
|
||||
this.messageService = new MessageService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @param senderId 发送者ID
|
||||
* @param receiverId 接收者ID
|
||||
* @param content 消息内容
|
||||
* @param typeCode 消息类型代码
|
||||
* @return 发送结果
|
||||
*/
|
||||
public Map<String, Object> sendMessage(String senderId, String receiverId, String content, int typeCode) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
// 检查输入参数
|
||||
if (senderId == null || senderId.isEmpty() || receiverId == null ||
|
||||
receiverId.isEmpty() || content == null || content.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "发送者ID、接收者ID和消息内容不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获取消息类型
|
||||
Message.MessageType type = Message.MessageType.fromCode(typeCode);
|
||||
if (type == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "无效的消息类型");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 调用服务层发送消息
|
||||
boolean success = messageService.sendMessage(senderId, receiverId, content, type);
|
||||
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "消息发送成功");
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "消息发送失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "发送消息过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送系统通知
|
||||
* @param receiverId 接收者ID
|
||||
* @param content 通知内容
|
||||
* @return 发送结果
|
||||
*/
|
||||
public Map<String, Object> sendSystemNotification(String receiverId, String content) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
// 检查输入参数
|
||||
if (receiverId == null || receiverId.isEmpty() || content == null || content.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "接收者ID和通知内容不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 调用服务层发送系统通知
|
||||
boolean success = messageService.sendSystemNotification(receiverId, content);
|
||||
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "系统通知发送成功");
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "系统通知发送失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "发送系统通知过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取消息详情
|
||||
* @param messageId 消息ID
|
||||
* @return 消息详情
|
||||
*/
|
||||
public Map<String, Object> getMessageDetail(String messageId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
if (messageId == null || messageId.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "消息ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
Message message = messageService.getMessageById(messageId);
|
||||
|
||||
if (message != null) {
|
||||
result.put("success", true);
|
||||
result.put("message", message);
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "消息不存在");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "获取消息详情过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户收到的所有消息
|
||||
* @param receiverId 接收者ID
|
||||
* @return 消息列表
|
||||
*/
|
||||
public Map<String, Object> getReceivedMessages(String receiverId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
if (receiverId == null || receiverId.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "接收者ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Message> messages = messageService.getReceivedMessages(receiverId);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("messages", messages);
|
||||
result.put("count", messages.size());
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "获取消息列表过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户未读消息数量
|
||||
* @param receiverId 接收者ID
|
||||
* @return 未读消息数量
|
||||
*/
|
||||
public Map<String, Object> getUnreadMessageCount(String receiverId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
if (receiverId == null || receiverId.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "接收者ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
int count = messageService.getUnreadMessageCount(receiverId);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("unreadCount", count);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "获取未读消息数量过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取两个用户之间的消息记录
|
||||
* @param userId1 用户1 ID
|
||||
* @param userId2 用户2 ID
|
||||
* @return 消息列表
|
||||
*/
|
||||
public Map<String, Object> getMessagesBetweenUsers(String userId1, String userId2) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
if (userId1 == null || userId1.isEmpty() || userId2 == null || userId2.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "用户ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Message> messages = messageService.getMessagesBetweenUsers(userId1, userId2);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("messages", messages);
|
||||
result.put("count", messages.size());
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "获取用户间消息记录过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记消息为已读
|
||||
* @param messageId 消息ID
|
||||
* @return 操作结果
|
||||
*/
|
||||
public Map<String, Object> markMessageAsRead(String messageId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
if (messageId == null || messageId.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "消息ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean success = messageService.markMessageAsRead(messageId);
|
||||
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "消息已标记为已读");
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "标记消息为已读失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "标记消息为已读过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量标记消息为已读
|
||||
* @param receiverId 接收者ID
|
||||
* @return 操作结果
|
||||
*/
|
||||
public Map<String, Object> markAllMessagesAsRead(String receiverId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
if (receiverId == null || receiverId.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "接收者ID不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean success = messageService.markAllMessagesAsRead(receiverId);
|
||||
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "所有消息已标记为已读");
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "批量标记消息为已读失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "批量标记消息为已读过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -1,153 +0,0 @@
|
||||
package com.campus.pickup.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 消息实体类
|
||||
* 用于存储校园代取系统中的用户交互消息
|
||||
*/
|
||||
public class Message {
|
||||
private String messageId;
|
||||
private String senderId;
|
||||
private String receiverId;
|
||||
private String content;
|
||||
private LocalDateTime sendTime;
|
||||
private LocalDateTime readTime;
|
||||
private int status; // 0-未读 1-已读 2-已删除
|
||||
private MessageType type; // 消息类型:系统通知、用户消息、订单消息等
|
||||
|
||||
public enum MessageType {
|
||||
SYSTEM_NOTIFICATION(0, "系统通知"),
|
||||
USER_MESSAGE(1, "用户消息"),
|
||||
ORDER_MESSAGE(2, "订单消息"),
|
||||
REVIEW_MESSAGE(3, "评价消息");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
MessageType(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static MessageType fromCode(int code) {
|
||||
for (MessageType type : MessageType.values()) {
|
||||
if (type.getCode() == code) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Message() {
|
||||
this.sendTime = LocalDateTime.now();
|
||||
this.status = 0;
|
||||
this.type = MessageType.USER_MESSAGE;
|
||||
}
|
||||
|
||||
public Message(String senderId, String receiverId, String content, MessageType type) {
|
||||
this();
|
||||
this.senderId = senderId;
|
||||
this.receiverId = receiverId;
|
||||
this.content = content;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Message(String messageId, String senderId, String receiverId, String content, LocalDateTime sendTime, LocalDateTime readTime, int status, MessageType type) {
|
||||
this.messageId = messageId;
|
||||
this.senderId = senderId;
|
||||
this.receiverId = receiverId;
|
||||
this.content = content;
|
||||
this.sendTime = sendTime;
|
||||
this.readTime = readTime;
|
||||
this.status = status;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(String messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public String getSenderId() {
|
||||
return senderId;
|
||||
}
|
||||
|
||||
public void setSenderId(String senderId) {
|
||||
this.senderId = senderId;
|
||||
}
|
||||
|
||||
public String getReceiverId() {
|
||||
return receiverId;
|
||||
}
|
||||
|
||||
public void setReceiverId(String receiverId) {
|
||||
this.receiverId = receiverId;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public LocalDateTime getSendTime() {
|
||||
return sendTime;
|
||||
}
|
||||
|
||||
public void setSendTime(LocalDateTime sendTime) {
|
||||
this.sendTime = sendTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getReadTime() {
|
||||
return readTime;
|
||||
}
|
||||
|
||||
public void setReadTime(LocalDateTime readTime) {
|
||||
this.readTime = readTime;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public MessageType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(MessageType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Message{" +
|
||||
"messageId='" + messageId + '\'' +
|
||||
", senderId='" + senderId + '\'' +
|
||||
", receiverId='" + receiverId + '\'' +
|
||||
", content='" + content + '\'' +
|
||||
", sendTime=" + sendTime +
|
||||
", readTime=" + readTime +
|
||||
", status=" + status +
|
||||
", type=" + type +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,252 +0,0 @@
|
||||
package com.campus.pickup.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 订单实体类
|
||||
* 用于存储校园代取系统中的订单信息
|
||||
*/
|
||||
public class Order {
|
||||
private String orderId;
|
||||
private String orderNumber; // 订单编号
|
||||
private String customerId; // 下单用户ID
|
||||
private String deliveryPersonId; // 配送员ID
|
||||
private String itemType; // 物品类型(快递、外卖、文件等)
|
||||
private String description; // 物品描述
|
||||
private String pickupLocation; // 取件地点
|
||||
private String deliveryLocation; // 配送地点
|
||||
private BigDecimal fee; // 配送费用
|
||||
private LocalDateTime pickupTime; // 预计取件时间
|
||||
private LocalDateTime deliveryTime; // 实际送达时间
|
||||
private LocalDateTime createTime; // 创建时间
|
||||
private LocalDateTime updateTime; // 更新时间
|
||||
private OrderStatus status; // 订单状态
|
||||
private String remarks; // 备注
|
||||
|
||||
public enum OrderStatus {
|
||||
PENDING(0, "待接单"),
|
||||
ACCEPTED(1, "已接单"),
|
||||
PICKED_UP(2, "已取件"),
|
||||
DELIVERING(3, "配送中"),
|
||||
COMPLETED(4, "已完成"),
|
||||
CANCELLED(5, "已取消");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
OrderStatus(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static OrderStatus fromCode(int code) {
|
||||
for (OrderStatus status : OrderStatus.values()) {
|
||||
if (status.getCode() == code) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Order() {
|
||||
this.createTime = LocalDateTime.now();
|
||||
this.updateTime = LocalDateTime.now();
|
||||
this.status = OrderStatus.PENDING;
|
||||
this.fee = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
public Order(String customerId, String itemType, String description,
|
||||
String pickupLocation, String deliveryLocation, BigDecimal fee,
|
||||
LocalDateTime pickupTime, String remarks) {
|
||||
this();
|
||||
this.orderNumber = generateOrderNumber();
|
||||
this.customerId = customerId;
|
||||
this.itemType = itemType;
|
||||
this.description = description;
|
||||
this.pickupLocation = pickupLocation;
|
||||
this.deliveryLocation = deliveryLocation;
|
||||
this.fee = fee;
|
||||
this.pickupTime = pickupTime;
|
||||
this.remarks = remarks;
|
||||
}
|
||||
|
||||
public Order(String orderId, String orderNumber, String customerId, String deliveryPersonId,
|
||||
String itemType, String description, String pickupLocation, String deliveryLocation,
|
||||
BigDecimal fee, LocalDateTime pickupTime, LocalDateTime deliveryTime,
|
||||
LocalDateTime createTime, LocalDateTime updateTime, OrderStatus status, String remarks) {
|
||||
this.orderId = orderId;
|
||||
this.orderNumber = orderNumber;
|
||||
this.customerId = customerId;
|
||||
this.deliveryPersonId = deliveryPersonId;
|
||||
this.itemType = itemType;
|
||||
this.description = description;
|
||||
this.pickupLocation = pickupLocation;
|
||||
this.deliveryLocation = deliveryLocation;
|
||||
this.fee = fee;
|
||||
this.pickupTime = pickupTime;
|
||||
this.deliveryTime = deliveryTime;
|
||||
this.createTime = createTime;
|
||||
this.updateTime = updateTime;
|
||||
this.status = status;
|
||||
this.remarks = remarks;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成订单编号
|
||||
* @return 订单编号
|
||||
*/
|
||||
private String generateOrderNumber() {
|
||||
return "ORD" + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public String getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(String orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public String getOrderNumber() {
|
||||
return orderNumber;
|
||||
}
|
||||
|
||||
public void setOrderNumber(String orderNumber) {
|
||||
this.orderNumber = orderNumber;
|
||||
}
|
||||
|
||||
public String getCustomerId() {
|
||||
return customerId;
|
||||
}
|
||||
|
||||
public void setCustomerId(String customerId) {
|
||||
this.customerId = customerId;
|
||||
}
|
||||
|
||||
public String getDeliveryPersonId() {
|
||||
return deliveryPersonId;
|
||||
}
|
||||
|
||||
public void setDeliveryPersonId(String deliveryPersonId) {
|
||||
this.deliveryPersonId = deliveryPersonId;
|
||||
}
|
||||
|
||||
public String getItemType() {
|
||||
return itemType;
|
||||
}
|
||||
|
||||
public void setItemType(String itemType) {
|
||||
this.itemType = itemType;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getPickupLocation() {
|
||||
return pickupLocation;
|
||||
}
|
||||
|
||||
public void setPickupLocation(String pickupLocation) {
|
||||
this.pickupLocation = pickupLocation;
|
||||
}
|
||||
|
||||
public String getDeliveryLocation() {
|
||||
return deliveryLocation;
|
||||
}
|
||||
|
||||
public void setDeliveryLocation(String deliveryLocation) {
|
||||
this.deliveryLocation = deliveryLocation;
|
||||
}
|
||||
|
||||
public BigDecimal getFee() {
|
||||
return fee;
|
||||
}
|
||||
|
||||
public void setFee(BigDecimal fee) {
|
||||
this.fee = fee;
|
||||
}
|
||||
|
||||
public LocalDateTime getPickupTime() {
|
||||
return pickupTime;
|
||||
}
|
||||
|
||||
public void setPickupTime(LocalDateTime pickupTime) {
|
||||
this.pickupTime = pickupTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getDeliveryTime() {
|
||||
return deliveryTime;
|
||||
}
|
||||
|
||||
public void setDeliveryTime(LocalDateTime deliveryTime) {
|
||||
this.deliveryTime = deliveryTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public OrderStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(OrderStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getRemarks() {
|
||||
return remarks;
|
||||
}
|
||||
|
||||
public void setRemarks(String remarks) {
|
||||
this.remarks = remarks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Order{" +
|
||||
"orderId='" + orderId + '\'' +
|
||||
", orderNumber='" + orderNumber + '\'' +
|
||||
", customerId='" + customerId + '\'' +
|
||||
", deliveryPersonId='" + deliveryPersonId + '\'' +
|
||||
", itemType='" + itemType + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", pickupLocation='" + pickupLocation + '\'' +
|
||||
", deliveryLocation='" + deliveryLocation + '\'' +
|
||||
", fee=" + fee +
|
||||
", pickupTime=" + pickupTime +
|
||||
", deliveryTime=" + deliveryTime +
|
||||
", createTime=" + createTime +
|
||||
", updateTime=" + updateTime +
|
||||
", status=" + status +
|
||||
", remarks='" + remarks + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,133 +0,0 @@
|
||||
package com.campus.pickup.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 评价实体类
|
||||
* 用于存储校园代取系统中的用户评价信息
|
||||
*/
|
||||
public class Review {
|
||||
private String reviewId;
|
||||
private String orderId;
|
||||
private String reviewerId; // 评价人ID
|
||||
private String reviewedId; // 被评价人ID
|
||||
private int rating; // 评分 1-5星
|
||||
private String content; // 评价内容
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private int status; // 0-正常 1-已删除
|
||||
|
||||
public Review() {
|
||||
this.createTime = LocalDateTime.now();
|
||||
this.updateTime = LocalDateTime.now();
|
||||
this.status = 0;
|
||||
}
|
||||
|
||||
public Review(String orderId, String reviewerId, String reviewedId, int rating, String content) {
|
||||
this();
|
||||
this.orderId = orderId;
|
||||
this.reviewerId = reviewerId;
|
||||
this.reviewedId = reviewedId;
|
||||
this.rating = rating;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Review(String reviewId, String orderId, String reviewerId, String reviewedId, int rating, String content, LocalDateTime createTime, LocalDateTime updateTime, int status) {
|
||||
this.reviewId = reviewId;
|
||||
this.orderId = orderId;
|
||||
this.reviewerId = reviewerId;
|
||||
this.reviewedId = reviewedId;
|
||||
this.rating = rating;
|
||||
this.content = content;
|
||||
this.createTime = createTime;
|
||||
this.updateTime = updateTime;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getReviewId() {
|
||||
return reviewId;
|
||||
}
|
||||
|
||||
public void setReviewId(String reviewId) {
|
||||
this.reviewId = reviewId;
|
||||
}
|
||||
|
||||
public String getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(String orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public String getReviewerId() {
|
||||
return reviewerId;
|
||||
}
|
||||
|
||||
public void setReviewerId(String reviewerId) {
|
||||
this.reviewerId = reviewerId;
|
||||
}
|
||||
|
||||
public String getReviewedId() {
|
||||
return reviewedId;
|
||||
}
|
||||
|
||||
public void setReviewedId(String reviewedId) {
|
||||
this.reviewedId = reviewedId;
|
||||
}
|
||||
|
||||
public int getRating() {
|
||||
return rating;
|
||||
}
|
||||
|
||||
public void setRating(int rating) {
|
||||
this.rating = rating;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Review{" +
|
||||
"reviewId='" + reviewId + '\'' +
|
||||
", orderId='" + orderId + '\'' +
|
||||
", reviewerId='" + reviewerId + '\'' +
|
||||
", reviewedId='" + reviewedId + '\'' +
|
||||
", rating=" + rating +
|
||||
", content='" + content + '\'' +
|
||||
", createTime=" + createTime +
|
||||
", updateTime=" + updateTime +
|
||||
", status=" + status +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,156 +0,0 @@
|
||||
package com.campus.pickup.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户实体类
|
||||
* 用于存储校园代取系统中的用户信息
|
||||
*/
|
||||
public class User {
|
||||
private String userId;
|
||||
private String username;
|
||||
private String password;
|
||||
private String realName;
|
||||
private String phone;
|
||||
private String email;
|
||||
private String studentId;
|
||||
private String dormitory;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private int status; // 0-正常 1-禁用
|
||||
|
||||
public User() {
|
||||
this.createTime = LocalDateTime.now();
|
||||
this.updateTime = LocalDateTime.now();
|
||||
this.status = 0;
|
||||
}
|
||||
|
||||
public User(String username, String password, String realName, String phone, String email, String studentId, String dormitory) {
|
||||
this();
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.realName = realName;
|
||||
this.phone = phone;
|
||||
this.email = email;
|
||||
this.studentId = studentId;
|
||||
this.dormitory = dormitory;
|
||||
}
|
||||
|
||||
public User(String userId, String username, String password, String realName, String phone, String email, String studentId, String dormitory, LocalDateTime createTime, LocalDateTime updateTime, int status) {
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.realName = realName;
|
||||
this.phone = phone;
|
||||
this.email = email;
|
||||
this.studentId = studentId;
|
||||
this.dormitory = dormitory;
|
||||
this.createTime = createTime;
|
||||
this.updateTime = updateTime;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
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 String getRealName() {
|
||||
return realName;
|
||||
}
|
||||
|
||||
public void setRealName(String realName) {
|
||||
this.realName = realName;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getStudentId() {
|
||||
return studentId;
|
||||
}
|
||||
|
||||
public void setStudentId(String studentId) {
|
||||
this.studentId = studentId;
|
||||
}
|
||||
|
||||
public String getDormitory() {
|
||||
return dormitory;
|
||||
}
|
||||
|
||||
public void setDormitory(String dormitory) {
|
||||
this.dormitory = dormitory;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"userId='" + userId + '\'' +
|
||||
", username='" + username + '\'' +
|
||||
", realName='" + realName + '\'' +
|
||||
", phone='" + phone + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", studentId='" + studentId + '\'' +
|
||||
", dormitory='" + dormitory + '\'' +
|
||||
", createTime=" + createTime +
|
||||
", updateTime=" + updateTime +
|
||||
", status=" + status +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
package com.campus.pickup.util;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 数据库连接工具类
|
||||
* 用于管理校园代取系统的数据库连接
|
||||
*/
|
||||
public class DatabaseUtil {
|
||||
private static final String DRIVER = "org.postgresql.Driver";
|
||||
private static final String URL = "jdbc:postgresql://localhost:5432/campus_pickup";
|
||||
private static final String USERNAME = "postgres";
|
||||
private static final String PASSWORD = "postgres";
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName(DRIVER);
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.err.println("加载数据库驱动失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库连接
|
||||
* @return 数据库连接对象
|
||||
* @throws SQLException 数据库连接异常
|
||||
*/
|
||||
public static Connection getConnection() throws SQLException {
|
||||
Properties props = new Properties();
|
||||
props.setProperty("user", USERNAME);
|
||||
props.setProperty("password", PASSWORD);
|
||||
props.setProperty("ssl", "false");
|
||||
return DriverManager.getConnection(URL, props);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭数据库连接
|
||||
* @param conn 数据库连接对象
|
||||
*/
|
||||
public static void closeConnection(Connection conn) {
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
System.err.println("关闭数据库连接失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试数据库连接
|
||||
* @return 连接是否成功
|
||||
*/
|
||||
public static boolean testConnection() {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = getConnection();
|
||||
return conn != null && !conn.isClosed();
|
||||
} catch (SQLException e) {
|
||||
System.err.println("数据库连接测试失败:" + e.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
closeConnection(conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,144 +0,0 @@
|
||||
package com.campus.pickup.view;
|
||||
|
||||
import com.campus.pickup.model.User;
|
||||
|
||||
/**
|
||||
* 主视图类
|
||||
* 处理应用程序的主界面和流程控制
|
||||
*/
|
||||
public class MainView {
|
||||
private UserView userView;
|
||||
private MessageView messageView;
|
||||
private ReviewView reviewView;
|
||||
private OrderView orderView;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public MainView() {
|
||||
this.userView = new UserView();
|
||||
this.messageView = new MessageView();
|
||||
this.reviewView = new ReviewView();
|
||||
this.orderView = new OrderView();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示欢迎界面
|
||||
*/
|
||||
public void showWelcomeScreen() {
|
||||
System.out.println("========================================");
|
||||
System.out.println(" 欢迎使用校园代取系统");
|
||||
System.out.println("========================================");
|
||||
System.out.println("本系统提供以下功能:");
|
||||
System.out.println("- 用户注册与登录");
|
||||
System.out.println("- 个人信息管理");
|
||||
System.out.println("- 消息交流");
|
||||
System.out.println("- 评价管理");
|
||||
System.out.println("- 订单配送管理");
|
||||
System.out.println("========================================");
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示主菜单
|
||||
* @return 用户选择的菜单项
|
||||
*/
|
||||
public int showMainMenu() {
|
||||
System.out.println("\n===== 校园代取系统 - 主菜单 =====");
|
||||
System.out.println("1. 用户注册");
|
||||
System.out.println("2. 用户登录");
|
||||
System.out.println("0. 退出系统");
|
||||
System.out.print("请选择操作: ");
|
||||
|
||||
try {
|
||||
java.util.Scanner scanner = new java.util.Scanner(System.in);
|
||||
int choice = Integer.parseInt(scanner.nextLine());
|
||||
return choice;
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("请输入有效的数字选项!");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行应用程序
|
||||
*/
|
||||
public void run() {
|
||||
showWelcomeScreen();
|
||||
|
||||
User currentUser = null;
|
||||
int choice;
|
||||
|
||||
do {
|
||||
if (currentUser == null) {
|
||||
choice = showMainMenu();
|
||||
|
||||
switch (choice) {
|
||||
case 1:
|
||||
userView.showRegistrationForm();
|
||||
break;
|
||||
case 2:
|
||||
currentUser = userView.showLoginForm();
|
||||
break;
|
||||
case 0:
|
||||
System.out.println("感谢使用校园代取系统,再见!");
|
||||
break;
|
||||
default:
|
||||
System.out.println("无效的选项,请重新选择!");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
choice = userView.showUserMenu(currentUser);
|
||||
|
||||
switch (choice) {
|
||||
case 1:
|
||||
userView.showUserInfo(currentUser.getUserId());
|
||||
break;
|
||||
case 2:
|
||||
userView.showUpdateUserInfoForm(currentUser.getUserId());
|
||||
break;
|
||||
case 3:
|
||||
userView.showChangePasswordForm(currentUser.getUserId());
|
||||
break;
|
||||
case 4:
|
||||
messageView.handleMessageManagement(currentUser);
|
||||
break;
|
||||
case 5:
|
||||
reviewView.handleReviewManagement(currentUser);
|
||||
break;
|
||||
case 6:
|
||||
orderView.showOrderMenu();
|
||||
break;
|
||||
case 0:
|
||||
System.out.println("已退出登录,返回主菜单...");
|
||||
currentUser = null;
|
||||
break;
|
||||
default:
|
||||
System.out.println("无效的选项,请重新选择!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (choice != 0 || currentUser != null);
|
||||
|
||||
// 关闭资源
|
||||
closeResources();
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭所有视图资源
|
||||
*/
|
||||
private void closeResources() {
|
||||
userView.close();
|
||||
messageView.close();
|
||||
reviewView.close();
|
||||
orderView.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用程序入口点
|
||||
* @param args 命令行参数
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
MainView mainView = new MainView();
|
||||
mainView.run();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue