diff --git a/MyCourse/.idea/artifacts/MyCourse_war_exploded.xml b/MyCourse/.idea/artifacts/MyCourse_war_exploded.xml new file mode 100644 index 0000000..0f7217d --- /dev/null +++ b/MyCourse/.idea/artifacts/MyCourse_war_exploded.xml @@ -0,0 +1,47 @@ + + + $PROJECT_DIR$/out/artifacts/MyCourse_war_exploded + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/compiler.xml b/MyCourse/.idea/compiler.xml new file mode 100644 index 0000000..faa0c44 --- /dev/null +++ b/MyCourse/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/encodings.xml b/MyCourse/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/MyCourse/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__cglib_cglib_3_2_12.xml b/MyCourse/.idea/libraries/Maven__cglib_cglib_3_2_12.xml new file mode 100644 index 0000000..e0e203c --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__cglib_cglib_3_2_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__com_alibaba_fastjson_1_2_58.xml b/MyCourse/.idea/libraries/Maven__com_alibaba_fastjson_1_2_58.xml new file mode 100644 index 0000000..f838f59 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__com_alibaba_fastjson_1_2_58.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__com_github_penggle_kaptcha_2_3_2.xml b/MyCourse/.idea/libraries/Maven__com_github_penggle_kaptcha_2_3_2.xml new file mode 100644 index 0000000..bc88169 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__com_github_penggle_kaptcha_2_3_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__com_google_protobuf_protobuf_java_3_6_1.xml b/MyCourse/.idea/libraries/Maven__com_google_protobuf_protobuf_java_3_6_1.xml new file mode 100644 index 0000000..233670d --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__com_google_protobuf_protobuf_java_3_6_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__com_jhlabs_filters_2_0_235_1.xml b/MyCourse/.idea/libraries/Maven__com_jhlabs_filters_2_0_235_1.xml new file mode 100644 index 0000000..f674d8e --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__com_jhlabs_filters_2_0_235_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__commons_fileupload_commons_fileupload_1_4.xml b/MyCourse/.idea/libraries/Maven__commons_fileupload_commons_fileupload_1_4.xml new file mode 100644 index 0000000..3b9dcc0 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__commons_fileupload_commons_fileupload_1_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__commons_io_commons_io_2_6.xml b/MyCourse/.idea/libraries/Maven__commons_io_commons_io_2_6.xml new file mode 100644 index 0000000..d722698 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__commons_io_commons_io_2_6.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__javax_servlet_javax_servlet_api_4_0_1.xml b/MyCourse/.idea/libraries/Maven__javax_servlet_javax_servlet_api_4_0_1.xml new file mode 100644 index 0000000..d05c196 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__javax_servlet_javax_servlet_api_4_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__javax_servlet_jstl_1_2.xml b/MyCourse/.idea/libraries/Maven__javax_servlet_jstl_1_2.xml new file mode 100644 index 0000000..f329893 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__javax_servlet_jstl_1_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__junit_junit_4_12.xml b/MyCourse/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 0000000..d411041 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__mysql_mysql_connector_java_8_0_13.xml b/MyCourse/.idea/libraries/Maven__mysql_mysql_connector_java_8_0_13.xml new file mode 100644 index 0000000..fc36ef0 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__mysql_mysql_connector_java_8_0_13.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__ognl_ognl_3_1_21.xml b/MyCourse/.idea/libraries/Maven__ognl_ognl_3_1_21.xml new file mode 100644 index 0000000..e02003f --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__ognl_ognl_3_1_21.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_8_1.xml b/MyCourse/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_8_1.xml new file mode 100644 index 0000000..33b78e9 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_8_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_apache_logging_log4j_log4j_api_2_11_2.xml b/MyCourse/.idea/libraries/Maven__org_apache_logging_log4j_log4j_api_2_11_2.xml new file mode 100644 index 0000000..fe93f54 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_apache_logging_log4j_log4j_api_2_11_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_apache_logging_log4j_log4j_core_2_11_2.xml b/MyCourse/.idea/libraries/Maven__org_apache_logging_log4j_log4j_core_2_11_2.xml new file mode 100644 index 0000000..c7e1697 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_apache_logging_log4j_log4j_core_2_11_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_apache_struts_struts2_core_2_5_20.xml b/MyCourse/.idea/libraries/Maven__org_apache_struts_struts2_core_2_5_20.xml new file mode 100644 index 0000000..d2d70a8 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_apache_struts_struts2_core_2_5_20.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_apache_struts_struts2_spring_plugin_2_5_20.xml b/MyCourse/.idea/libraries/Maven__org_apache_struts_struts2_spring_plugin_2_5_20.xml new file mode 100644 index 0000000..72e2fcf --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_apache_struts_struts2_spring_plugin_2_5_20.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_aspectj_aspectjweaver_1_9_4.xml b/MyCourse/.idea/libraries/Maven__org_aspectj_aspectjweaver_1_9_4.xml new file mode 100644 index 0000000..d51ce49 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_aspectj_aspectjweaver_1_9_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_freemarker_freemarker_2_3_28.xml b/MyCourse/.idea/libraries/Maven__org_freemarker_freemarker_2_3_28.xml new file mode 100644 index 0000000..3471c5b --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_freemarker_freemarker_2_3_28.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/MyCourse/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_javassist_javassist_3_20_0_GA.xml b/MyCourse/.idea/libraries/Maven__org_javassist_javassist_3_20_0_GA.xml new file mode 100644 index 0000000..c21c9b0 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_javassist_javassist_3_20_0_GA.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_mybatis_mybatis_3_5_1.xml b/MyCourse/.idea/libraries/Maven__org_mybatis_mybatis_3_5_1.xml new file mode 100644 index 0000000..e633f81 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_mybatis_mybatis_3_5_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_mybatis_mybatis_spring_2_0_1.xml b/MyCourse/.idea/libraries/Maven__org_mybatis_mybatis_spring_2_0_1.xml new file mode 100644 index 0000000..f49fd3a --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_mybatis_mybatis_spring_2_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_ow2_asm_asm_7_1.xml b/MyCourse/.idea/libraries/Maven__org_ow2_asm_asm_7_1.xml new file mode 100644 index 0000000..1d8827d --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_ow2_asm_asm_7_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_springframework_spring_aop_5_1_8_RELEASE.xml b/MyCourse/.idea/libraries/Maven__org_springframework_spring_aop_5_1_8_RELEASE.xml new file mode 100644 index 0000000..c1a6cbf --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_springframework_spring_aop_5_1_8_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_springframework_spring_beans_5_1_8_RELEASE.xml b/MyCourse/.idea/libraries/Maven__org_springframework_spring_beans_5_1_8_RELEASE.xml new file mode 100644 index 0000000..d17293b --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_springframework_spring_beans_5_1_8_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_springframework_spring_context_5_1_8_RELEASE.xml b/MyCourse/.idea/libraries/Maven__org_springframework_spring_context_5_1_8_RELEASE.xml new file mode 100644 index 0000000..c68626e --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_springframework_spring_context_5_1_8_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_springframework_spring_core_5_1_8_RELEASE.xml b/MyCourse/.idea/libraries/Maven__org_springframework_spring_core_5_1_8_RELEASE.xml new file mode 100644 index 0000000..8580e90 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_springframework_spring_core_5_1_8_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_springframework_spring_expression_5_1_8_RELEASE.xml b/MyCourse/.idea/libraries/Maven__org_springframework_spring_expression_5_1_8_RELEASE.xml new file mode 100644 index 0000000..aae055d --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_springframework_spring_expression_5_1_8_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_springframework_spring_jcl_5_1_8_RELEASE.xml b/MyCourse/.idea/libraries/Maven__org_springframework_spring_jcl_5_1_8_RELEASE.xml new file mode 100644 index 0000000..1a99c90 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_springframework_spring_jcl_5_1_8_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_springframework_spring_jdbc_5_1_8_RELEASE.xml b/MyCourse/.idea/libraries/Maven__org_springframework_spring_jdbc_5_1_8_RELEASE.xml new file mode 100644 index 0000000..5647436 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_springframework_spring_jdbc_5_1_8_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_springframework_spring_test_5_1_8_RELEASE.xml b/MyCourse/.idea/libraries/Maven__org_springframework_spring_test_5_1_8_RELEASE.xml new file mode 100644 index 0000000..684e11b --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_springframework_spring_test_5_1_8_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_springframework_spring_tx_5_1_8_RELEASE.xml b/MyCourse/.idea/libraries/Maven__org_springframework_spring_tx_5_1_8_RELEASE.xml new file mode 100644 index 0000000..a1addd7 --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_springframework_spring_tx_5_1_8_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/libraries/Maven__org_springframework_spring_web_5_1_8_RELEASE.xml b/MyCourse/.idea/libraries/Maven__org_springframework_spring_web_5_1_8_RELEASE.xml new file mode 100644 index 0000000..1cbea8a --- /dev/null +++ b/MyCourse/.idea/libraries/Maven__org_springframework_spring_web_5_1_8_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/misc.xml b/MyCourse/.idea/misc.xml new file mode 100644 index 0000000..a2e787a --- /dev/null +++ b/MyCourse/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/modules.xml b/MyCourse/.idea/modules.xml new file mode 100644 index 0000000..fd0999f --- /dev/null +++ b/MyCourse/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/MyCourse/.idea/vcs.xml b/MyCourse/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/MyCourse/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MyCourse/MyCourse.iml b/MyCourse/MyCourse.iml new file mode 100644 index 0000000..c7b79d5 --- /dev/null +++ b/MyCourse/MyCourse.iml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + file://$MODULE_DIR$/src/main/resources/struts.xml + jar://$MAVEN_REPOSITORY$/org/apache/struts/struts2-core/2.5.20/struts2-core-2.5.20.jar!/struts-default.xml + jar://$MAVEN_REPOSITORY$/org/apache/struts/struts2-spring-plugin/2.5.20/struts2-spring-plugin-2.5.20.jar!/struts-plugin.xml + + + + + + + + + file://$MODULE_DIR$/src/main/resources/applicationContext.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/pom.xml b/MyCourse/pom.xml new file mode 100644 index 0000000..be00712 --- /dev/null +++ b/MyCourse/pom.xml @@ -0,0 +1,136 @@ + + + 4.0.0 + + com.whileskies + MyCourse + 1.0-SNAPSHOT + + + + + org.springframework + spring-context + 5.1.8.RELEASE + + + + junit + junit + 4.12 + + + + org.springframework + spring-test + 5.1.8.RELEASE + test + + + + + org.mybatis + mybatis + 3.5.1 + + + + mysql + mysql-connector-java + 8.0.13 + + + + org.apache.logging.log4j + log4j-api + 2.11.2 + + + + org.apache.logging.log4j + log4j-core + 2.11.2 + + + + org.springframework + spring-jdbc + 5.1.8.RELEASE + + + + org.mybatis + mybatis-spring + 2.0.1 + + + + org.springframework + spring-web + 5.1.8.RELEASE + + + + javax.servlet + javax.servlet-api + 4.0.1 + provided + + + + javax.servlet + jstl + 1.2 + + + + org.aspectj + aspectjweaver + 1.9.4 + + + + cglib + cglib + 3.2.12 + + + + org.apache.struts + struts2-core + 2.5.20 + + + + org.apache.struts + struts2-spring-plugin + 2.5.20 + + + + + com.github.penggle + kaptcha + 2.3.2 + + + + com.alibaba + fastjson + 1.2.58 + + + + + + + + + UTF-8 + 9 + 9 + + + \ No newline at end of file diff --git a/MyCourse/src/main/java/file/action/ResourceDownloadAction.java b/MyCourse/src/main/java/file/action/ResourceDownloadAction.java new file mode 100644 index 0000000..372f300 --- /dev/null +++ b/MyCourse/src/main/java/file/action/ResourceDownloadAction.java @@ -0,0 +1,107 @@ +package file.action; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import file.pojo.CourseResource; +import file.service.CourseResourceService; +import login.pojo.User; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.ServletActionContext; +import org.springframework.beans.factory.annotation.Autowired; +import util.DownloadFileNameOp; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; + + +public class ResourceDownloadAction extends ActionSupport { + private static final Logger LOG = LogManager.getLogger(ResourceDownloadAction.class); + + private User user; + + private Integer resourceId; + private CourseResource resource; + private File file; + + private final CourseResourceService courseResourceService; + + @Autowired + public ResourceDownloadAction(CourseResourceService courseResourceService) { + this.courseResourceService = courseResourceService; + } + + + public String download() { + user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (resourceId == null) + return ERROR; + + resource = courseResourceService.findByResourceId(resourceId); + + if (resource != null) + return SUCCESS; + else + return ERROR; + } + + + public InputStream getInputStream() throws FileNotFoundException { + + file = new File(resource.getFilePath()); + + return new FileInputStream(file); + } + + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + + public String getFileName() throws Exception { + LOG.debug("fileName: " + resource.getFileName()); + + return DownloadFileNameOp.downToUtf8String(resource.getFileName(), ServletActionContext.getRequest()); + + } + + + public Long getContentLength() { + return file.length(); + } + + public Integer getResourceId() { + return resourceId; + } + + public void setResourceId(Integer resourceId) { + this.resourceId = resourceId; + } + + public CourseResource getResource() { + return resource; + } + + public void setResource(CourseResource resource) { + this.resource = resource; + } + + public File getFile() { + return file; + } + + public void setFile(File file) { + this.file = file; + } +} diff --git a/MyCourse/src/main/java/file/action/ResourceUploadAction.java b/MyCourse/src/main/java/file/action/ResourceUploadAction.java new file mode 100644 index 0000000..ec9d4cc --- /dev/null +++ b/MyCourse/src/main/java/file/action/ResourceUploadAction.java @@ -0,0 +1,82 @@ +package file.action; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import file.service.CourseResourceService; +import login.pojo.User; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.ServletActionContext; +import org.springframework.beans.factory.annotation.Autowired; + +import java.io.File; +import java.io.IOException; +import java.util.List; + + +public class ResourceUploadAction extends ActionSupport { + private static final Logger LOG = LogManager.getLogger(ResourceUploadAction.class); + private List file; + private List fileFileName; + private List fileContentType; + + private final CourseResourceService courseResourceService; + + private Integer courseId; + + @Autowired + public ResourceUploadAction(CourseResourceService courseResourceService) { + this.courseResourceService = courseResourceService; + } + + public String uploadFiles() throws IOException { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (courseId == null) + return ERROR; + + LOG.debug("fileName: " + fileFileName + " courseId: " + courseId); + String webInfPath = ServletActionContext.getRequest().getSession().getServletContext().getRealPath("/WEB-INF"); + + if (courseResourceService.uploadFiles(file, webInfPath, fileFileName, courseId)) + return NONE; + else + return ERROR; + } + + + public List getFile() { + return file; + } + + public void setFile(List file) { + this.file = file; + } + + public List getFileFileName() { + return fileFileName; + } + + public void setFileFileName(List fileFileName) { + this.fileFileName = fileFileName; + } + + public List getFileContentType() { + return fileContentType; + } + + public void setFileContentType(List fileContentType) { + this.fileContentType = fileContentType; + } + + public int getCourseId() { + return courseId; + } + + public void setCourseId(int courseId) { + this.courseId = courseId; + } +} diff --git a/MyCourse/src/main/java/file/action/TaskFileDownloadAction.java b/MyCourse/src/main/java/file/action/TaskFileDownloadAction.java new file mode 100644 index 0000000..2ca0c57 --- /dev/null +++ b/MyCourse/src/main/java/file/action/TaskFileDownloadAction.java @@ -0,0 +1,120 @@ +package file.action; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import file.pojo.TaskFile; +import file.service.TaskFileService; +import login.pojo.User; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.ServletActionContext; +import org.springframework.beans.factory.annotation.Autowired; +import util.DownloadFileNameOp; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; + + +public class TaskFileDownloadAction extends ActionSupport { + private static final Logger LOG = LogManager.getLogger(TaskFileDownloadAction.class); + + private Integer taskId; + private User user; + + + private TaskFile taskFile; + private File file; + + private final TaskFileService taskFileService; + + @Autowired + public TaskFileDownloadAction(TaskFileService taskFileService) { + this.taskFileService = taskFileService; + } + + + public String download() { + user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (taskId == null) + return ERROR; + + taskFile = taskFileService.findByTaskIdStudentId(taskId, user.getId()); + + if (taskFile != null) + return SUCCESS; + else + return ERROR; + } + + private Integer studentId; + public String teacherDownload() { + user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (taskId == null || studentId == null) + return ERROR; + + taskFile = taskFileService.findByTaskIdStudentId(taskId, studentId); + + if (taskFile != null) + return SUCCESS; + else + return ERROR; + } + + public InputStream getInputStream() throws FileNotFoundException { + + file = new File(taskFile.getFilePath()); + + + return new FileInputStream(file); + } + + + public Integer getTaskId() { + return taskId; + } + + public void setTaskId(Integer taskId) { + this.taskId = taskId; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public Integer getStudentId() { + return studentId; + } + + public void setStudentId(Integer studentId) { + this.studentId = studentId; + } + + public String getFileName() throws Exception { + LOG.debug("fileName: " + taskFile.getFileName()); + + //return new String(taskFile.getFileName().getBytes(), "ISO-8859-1"); + // return new String(taskFile.getFileName().getBytes(), "UTF-8"); + return DownloadFileNameOp.downToUtf8String(taskFile.getFileName(), ServletActionContext.getRequest()); + + } + + + + public Long getContentLength() { + return file.length(); + } +} diff --git a/MyCourse/src/main/java/file/action/TaskFileUploadAction.java b/MyCourse/src/main/java/file/action/TaskFileUploadAction.java new file mode 100644 index 0000000..faf162f --- /dev/null +++ b/MyCourse/src/main/java/file/action/TaskFileUploadAction.java @@ -0,0 +1,97 @@ +package file.action; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import file.service.TaskFileService; +import login.pojo.User; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.ServletActionContext; +import org.springframework.beans.factory.annotation.Autowired; + +import java.io.File; +import java.io.IOException; + + +public class TaskFileUploadAction extends ActionSupport { + private static final Logger LOG = LogManager.getLogger(TaskFileUploadAction.class); + + private File file; + + private String fileFileName; + + private String fileContentType; + + private Integer taskId; + + private Integer courseId; + + private final TaskFileService taskFileService; + + @Autowired + public TaskFileUploadAction(TaskFileService taskFileService) { + this.taskFileService = taskFileService; + } + + + public String upload() throws IOException { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (fileFileName == null || fileFileName.trim().equals("") || + taskId == null || courseId == null) + return ERROR; + + LOG.debug("fileName: " + fileFileName + " taskId: " + taskId + " courseId: " + courseId); + + String webInfPath = ServletActionContext.getRequest().getSession().getServletContext().getRealPath("/WEB-INF"); + + if (taskFileService.upload(file, webInfPath, fileFileName, taskId, courseId, user.getId())) { + return NONE; + } else + return ERROR; + + } + + public File getFile() { + return file; + } + + public void setFile(File file) { + this.file = file; + } + + public String getFileFileName() { + return fileFileName; + } + + public void setFileFileName(String fileFileName) { + this.fileFileName = fileFileName; + } + + public String getFileContentType() { + return fileContentType; + } + + public void setFileContentType(String fileContentType) { + this.fileContentType = fileContentType; + } + + public Integer getTaskId() { + return taskId; + } + + public void setTaskId(Integer taskId) { + this.taskId = taskId; + } + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } +} diff --git a/MyCourse/src/main/java/file/action/ZipTaskFileDownloadAction.java b/MyCourse/src/main/java/file/action/ZipTaskFileDownloadAction.java new file mode 100644 index 0000000..c01d1f8 --- /dev/null +++ b/MyCourse/src/main/java/file/action/ZipTaskFileDownloadAction.java @@ -0,0 +1,69 @@ +package file.action; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import file.service.TaskFileService; +import login.pojo.User; +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.interceptor.ServletRequestAware; +import org.springframework.beans.factory.annotation.Autowired; +import util.DownloadFileNameOp; + +import javax.servlet.http.HttpServletRequest; +import java.io.*; + +public class ZipTaskFileDownloadAction extends ActionSupport implements ServletRequestAware { + + private Integer taskId; + private File file; + + private final TaskFileService taskFileService; + + @Autowired + public ZipTaskFileDownloadAction(TaskFileService taskFileService) { + this.taskFileService = taskFileService; + } + + public String downloadZip() throws IOException { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (taskId == null) + return ERROR; + + String webInf = ServletActionContext.getRequest().getSession().getServletContext().getRealPath("/WEB-INF"); + file = taskFileService.downloadAsZip(webInf, taskId); + + return SUCCESS; + } + + public InputStream getInputStream() throws FileNotFoundException { + return new FileInputStream(file); + } + + public String getFileName() throws Exception { + //return new String(file.getName().getBytes("UTF-8"), "ISO-8859-1"); + return DownloadFileNameOp.downToUtf8String(file.getName(), ServletActionContext.getRequest()); + } + + public Long getContentLength() { + return file.length(); + } + + public Integer getTaskId() { + return taskId; + } + + public void setTaskId(Integer taskId) { + this.taskId = taskId; + } + + + + private HttpServletRequest request; + public void setServletRequest(HttpServletRequest request) { + this.request = request; + } +} diff --git a/MyCourse/src/main/java/file/mapper/CourseResourceMapper.java b/MyCourse/src/main/java/file/mapper/CourseResourceMapper.java new file mode 100644 index 0000000..0d71dee --- /dev/null +++ b/MyCourse/src/main/java/file/mapper/CourseResourceMapper.java @@ -0,0 +1,15 @@ +package file.mapper; + +import file.pojo.CourseResource; + +import java.util.List; + +public interface CourseResourceMapper { + CourseResource selectById(Integer id); + + List selectAllByCourseId(Integer courseId); + + int insert(CourseResource courseResource); + + int delete(Integer resourceId); +} diff --git a/MyCourse/src/main/java/file/mapper/TaskFileMapper.java b/MyCourse/src/main/java/file/mapper/TaskFileMapper.java new file mode 100644 index 0000000..9f953fd --- /dev/null +++ b/MyCourse/src/main/java/file/mapper/TaskFileMapper.java @@ -0,0 +1,17 @@ +package file.mapper; + +import file.pojo.TaskFile; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface TaskFileMapper { + + TaskFile selectByTaskIdStudentId(@Param("taskId") Integer taskId, @Param("studentId") Integer StudentId); + + List selectAllByTaskId(Integer taskId); + + int insert(TaskFile taskFile); + + int update(TaskFile taskFile); +} diff --git a/MyCourse/src/main/java/file/pojo/CourseResource.java b/MyCourse/src/main/java/file/pojo/CourseResource.java new file mode 100644 index 0000000..07f7a96 --- /dev/null +++ b/MyCourse/src/main/java/file/pojo/CourseResource.java @@ -0,0 +1,83 @@ +package file.pojo; + +import java.util.Date; + +public class CourseResource { + private Integer id; + private Integer courseId; + private String fileName; + private String filePath; + private Date uploadTime; + + private String hUploadTime; + private String hFileSize; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public Date getUploadTime() { + return uploadTime; + } + + public void setUploadTime(Date uploadTime) { + this.uploadTime = uploadTime; + } + + public String gethUploadTime() { + return hUploadTime; + } + + public void sethUploadTime(String hUploadTime) { + this.hUploadTime = hUploadTime; + } + + public String gethFileSize() { + return hFileSize; + } + + public void sethFileSize(String hFileSize) { + this.hFileSize = hFileSize; + } + + @Override + public String toString() { + return "CourseResource{" + + "id=" + id + + ", courseId=" + courseId + + ", fileName='" + fileName + '\'' + + ", filePath='" + filePath + '\'' + + ", uploadTime=" + uploadTime + + ", hUploadTime='" + hUploadTime + '\'' + + ", hFileSize='" + hFileSize + '\'' + + '}'; + } +} diff --git a/MyCourse/src/main/java/file/pojo/TaskFile.java b/MyCourse/src/main/java/file/pojo/TaskFile.java new file mode 100644 index 0000000..f4f6b02 --- /dev/null +++ b/MyCourse/src/main/java/file/pojo/TaskFile.java @@ -0,0 +1,83 @@ +package file.pojo; + +import java.util.Date; + +public class TaskFile { + private Integer id; + private Integer taskId; + private Integer userId; + private Date uploadTime; + private String fileName; + private String filePath; + + private String hUploadTime; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getTaskId() { + return taskId; + } + + public void setTaskId(Integer taskId) { + this.taskId = taskId; + } + + public Integer getUserId() { + return userId; + } + + public void setUserId(Integer userId) { + this.userId = userId; + } + + public Date getUploadTime() { + return uploadTime; + } + + public void setUploadTime(Date uploadTime) { + this.uploadTime = uploadTime; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public String gethUploadTime() { + return hUploadTime; + } + + public void sethUploadTime(String hUploadTime) { + this.hUploadTime = hUploadTime; + } + + @Override + public String toString() { + return "TaskFile{" + + "id=" + id + + ", taskId=" + taskId + + ", userId=" + userId + + ", uploadTime=" + uploadTime + + ", fileName='" + fileName + '\'' + + ", filePath='" + filePath + '\'' + + ", hUploadTime='" + hUploadTime + '\'' + + '}'; + } +} diff --git a/MyCourse/src/main/java/file/service/CourseResourceService.java b/MyCourse/src/main/java/file/service/CourseResourceService.java new file mode 100644 index 0000000..c031933 --- /dev/null +++ b/MyCourse/src/main/java/file/service/CourseResourceService.java @@ -0,0 +1,19 @@ +package file.service; + +import file.pojo.CourseResource; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +public interface CourseResourceService { + + boolean uploadFiles(List files, String webInfPath, List fileNames, Integer courseId) throws IOException; + + List findByCourseId(Integer courseId); + + CourseResource findByResourceId(Integer resourceId); + + boolean deleteResource(Integer resourceId); + +} diff --git a/MyCourse/src/main/java/file/service/TaskFileService.java b/MyCourse/src/main/java/file/service/TaskFileService.java new file mode 100644 index 0000000..00b5d79 --- /dev/null +++ b/MyCourse/src/main/java/file/service/TaskFileService.java @@ -0,0 +1,17 @@ +package file.service; + +import file.pojo.TaskFile; + +import java.io.File; +import java.io.IOException; + +public interface TaskFileService { + + boolean upload(File file, String webInfPath, String fileName, Integer taskId, Integer courseId, Integer userId) throws IOException; + + TaskFile findByTaskIdStudentId(Integer taskId, Integer studentId); + + TaskFile findTaskFile(Integer taskId, Integer userId); + + File downloadAsZip(String webInfPath, Integer taskId) throws IOException; +} diff --git a/MyCourse/src/main/java/file/service/impl/CourseResourceServiceImpl.java b/MyCourse/src/main/java/file/service/impl/CourseResourceServiceImpl.java new file mode 100644 index 0000000..d8f663f --- /dev/null +++ b/MyCourse/src/main/java/file/service/impl/CourseResourceServiceImpl.java @@ -0,0 +1,105 @@ +package file.service.impl; + +import file.mapper.CourseResourceMapper; +import file.pojo.CourseResource; +import file.service.CourseResourceService; +import org.apache.commons.io.FileUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +@Service +public class CourseResourceServiceImpl implements CourseResourceService { + private static final String BASE_DIR = "/upload/"; + + private final CourseResourceMapper courseResourceMapper; + + @Autowired + public CourseResourceServiceImpl(CourseResourceMapper courseResourceMapper) { + this.courseResourceMapper = courseResourceMapper; + } + + public boolean uploadFiles(List files, String webInfPath, List fileNames, Integer courseId) throws IOException { + String courseDirStr = webInfPath + BASE_DIR + "course-" + courseId; + File courseDir = new File(courseDirStr); + if (!courseDir.exists()) { + if (!courseDir.mkdirs()) + return false; + } + + String resourceDirStr = courseDirStr + "/resource"; + File resourceDirFile = new File(resourceDirStr); + if (!resourceDirFile.exists()) { + if (!resourceDirFile.mkdirs()) + return false; + } + + for (int i = 0; i < files.size(); i++) { + CourseResource resource = new CourseResource(); + + String uuid = UUID.randomUUID().toString(); + String uuidFileName = resourceDirStr + "/" + uuid; + File uuidFile = new File(uuidFileName); + + resource.setCourseId(courseId); + resource.setFileName(fileNames.get(i)); + resource.setUploadTime(new Date()); + resource.setFilePath(uuidFile.getAbsolutePath()); + + FileUtils.copyFile(files.get(i), uuidFile); + + if (courseResourceMapper.insert(resource) < 1) { + uuidFile.deleteOnExit(); + return false; + } + } + + return true; + } + + public List findByCourseId(Integer courseId) { + List courseResources = courseResourceMapper.selectAllByCourseId(courseId); + + for (CourseResource resource : courseResources) { + SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + resource.sethUploadTime(f.format(resource.getUploadTime())); + File file = new File(resource.getFilePath()); + String fileSizeStr; + long fileSize = file.length(); + if (fileSize < 1024) + fileSizeStr = Long.toString(fileSize) + "B"; + else if (fileSize < 1024 * 1024) + fileSizeStr = String.format("%.2f", fileSize / 1024.0) + "KB"; + else if (fileSize < 1024 * 1024 * 1024) + fileSizeStr = String.format("%.2f", fileSize / 1024.0 / 1024.0) + "MB"; + else + fileSizeStr = String.format("%.2f", fileSize / 1024.0 / 1024.0 / 1024.0) + "GB"; + resource.sethFileSize(fileSizeStr); + } + + return courseResources; + } + + public CourseResource findByResourceId(Integer resourceId) { + return courseResourceMapper.selectById(resourceId); + } + + public boolean deleteResource(Integer resourceId) { + CourseResource resource = courseResourceMapper.selectById(resourceId); + if (resource == null) + return false; + + File file = new File(resource.getFilePath()); + if (!file.delete()) + return false; + courseResourceMapper.delete(resourceId); + + return true; + } +} diff --git a/MyCourse/src/main/java/file/service/impl/TaskFileServiceImpl.java b/MyCourse/src/main/java/file/service/impl/TaskFileServiceImpl.java new file mode 100644 index 0000000..ec3e63a --- /dev/null +++ b/MyCourse/src/main/java/file/service/impl/TaskFileServiceImpl.java @@ -0,0 +1,156 @@ +package file.service.impl; + +import file.mapper.TaskFileMapper; +import file.pojo.TaskFile; +import file.service.TaskFileService; +import login.mapper.UserMapper; +import login.pojo.User; +import org.apache.commons.io.FileUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import teacher.mapper.TeaCourseMapper; +import teacher.mapper.TeaCourseTaskMapper; +import teacher.pojo.TeaCourse; +import teacher.pojo.TeaTask; + +import java.io.*; +import java.util.Date; +import java.util.List; +import java.util.UUID; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +@Service +public class TaskFileServiceImpl implements TaskFileService { + private static final Logger LOG = LogManager.getLogger(TaskFileServiceImpl.class); + private static final String BASE_DIR = "/upload/"; + + private final TaskFileMapper taskFileMapper; + + private final TeaCourseTaskMapper teaCourseTaskMapper; + + private final TeaCourseMapper teaCourseMapper; + + private final UserMapper userMapper; + + @Autowired + public TaskFileServiceImpl(TaskFileMapper taskFileMapper, TeaCourseTaskMapper teaCourseTaskMapper, TeaCourseMapper teaCourseMapper, UserMapper userMapper) { + this.taskFileMapper = taskFileMapper; + this.teaCourseTaskMapper = teaCourseTaskMapper; + this.teaCourseMapper = teaCourseMapper; + this.userMapper = userMapper; + } + + public boolean upload(File file, String webInfPath, String fileName, Integer taskId, Integer courseId, Integer userId) throws IOException { + String courseDirStr = webInfPath + BASE_DIR + "course-" + courseId; + File courseDir = new File(courseDirStr); + if (!courseDir.exists()) { + if (!courseDir.mkdirs()) + return false; + } + + String taskDirStr = courseDirStr + "/task-" + taskId; + File taskDir = new File(taskDirStr); + if (!taskDir.exists()) { + if (!taskDir.mkdirs()) + return false; + } + + File taskFile = null; + + TaskFile old = taskFileMapper.selectByTaskIdStudentId(taskId, userId); + if (old != null) { + //原文件存在,替换 + taskFile = new File(old.getFilePath()); + FileUtils.copyFile(file, taskFile); + + old.setFileName(fileName); + old.setUploadTime(new Date()); + + if (taskFileMapper.update(old) > 0) { + return true; + } else { + taskFile.deleteOnExit(); + return false; + } + + } else { + String uuidName = UUID.randomUUID().toString(); + String taskFileName = taskDirStr + "/" + uuidName; + taskFile = new File(taskFileName); + + //原文件不存在 + TaskFile tf = new TaskFile(); + tf.setFileName(fileName); + tf.setTaskId(taskId); + tf.setUserId(userId); + tf.setUploadTime(new Date()); + tf.setFilePath(taskFile.getAbsolutePath()); + + FileUtils.copyFile(file, taskFile); + + if(taskFileMapper.insert(tf) > 0) { + return true; + } else { + taskFile.deleteOnExit(); + return false; + } + } + + } + + public TaskFile findByTaskIdStudentId(Integer taskId, Integer studentId) { + return taskFileMapper.selectByTaskIdStudentId(taskId, studentId); + } + + public TaskFile findTaskFile(Integer taskId, Integer userId) { + return taskFileMapper.selectByTaskIdStudentId(taskId, userId); + } + + public File downloadAsZip(String webInfPath, Integer taskId) throws IOException { + String tmpDir = webInfPath + BASE_DIR + "tmp/"; + + TeaTask task = teaCourseTaskMapper.selectByTaskId(taskId); + TeaCourse teaCourse = teaCourseMapper.selectByCourseId(task.getCourseId()); + + String zipName = tmpDir + teaCourse.getName() + "-" + task.getTitle() + ".zip"; + + ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipName)); + + List taskFiles = taskFileMapper.selectAllByTaskId(taskId); + + for (TaskFile t : taskFiles) { + BufferedInputStream bis = new BufferedInputStream( + new FileInputStream(t.getFilePath()) + ); + + User stu = userMapper.selectById(t.getUserId()); + + String entryName = ""; + + if (!stu.getSchoolId().equals("")) + entryName += stu.getSchoolId() + "-"; + entryName += stu.getName() + "-" + t.getFileName(); + + zos.putNextEntry(new ZipEntry(entryName)); + + while (true) { + byte[] b = new byte[100]; + int len = bis.read(b); + if (len == -1) + break; + zos.write(b, 0, len); + } + + bis.close(); + } + + zos.close(); + + return new File(zipName); + } + + +} diff --git a/MyCourse/src/main/java/login/action/LoginAction.java b/MyCourse/src/main/java/login/action/LoginAction.java new file mode 100644 index 0000000..dd190ae --- /dev/null +++ b/MyCourse/src/main/java/login/action/LoginAction.java @@ -0,0 +1,177 @@ +package login.action; + + +import com.alibaba.fastjson.JSON; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import login.pojo.User; +import login.service.LoginService; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.interceptor.ServletResponseAware; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; + + +public class LoginAction extends ActionSupport implements ServletResponseAware { + + private String email; + private String password; + private String verificationCode; + + private final LoginService loginService; + + private ServletResponse response; + + private static final Logger LOG = LogManager.getLogger(LoginAction.class); + + @Autowired + public LoginAction(LoginService loginService) { + this.loginService = loginService; + } + + public String toLogin() { + return SUCCESS; + } + + public String login() throws IOException { + LoginJson loginJson = new LoginJson(); + loginJson.code = LOGIN_CODE; + if (email == null || email.trim().length() == 0 || password == null || password.trim().length() == 0 + || verificationCode == null || verificationCode.trim().length() == 0) { + loginJson.msg = "存在空字段"; + loginJson.status = FAIL_EMPYT_PARAM; + } else { + Map session = ActionContext.getContext().getSession(); + String realVerificationCode = (String) session.get("verificationCode"); + + if (verificationCode.equals(realVerificationCode)) { + User user = new User(); + user.setEmail(email); + user.setPassword(password); + + user = loginService.loginByEmailPassword(user); + if (user == null) { + loginJson.msg = "账号或密码错误"; + loginJson.status = FAIL_EMAIL_PASS; + } else { + LOG.debug("user: " + user); + loginJson.msg = "登录成功"; + loginJson.status = SUCC_STATUS; + loginJson.data.put("user_id", user.getId().toString()); + loginJson.data.put("user_role", user.getRole()); + + ActionContext.getContext().getSession().put("user", user); + } + + } else { + loginJson.msg = "验证码错误"; + loginJson.status = FAIL_VERIFICATION; + } + } + + response.setCharacterEncoding("utf-8"); + response.setContentType("application/json;charset=utf-8"); + String ret = JSON.toJSONString(loginJson); + LOG.debug("ret: " + loginJson); + LOG.debug("json: " + ret); + PrintWriter writer = response.getWriter(); + writer.print(ret); + writer.flush(); + writer.close(); + + return NONE; + } + + public String logout() { + ActionContext.getContext().getSession().remove("user"); + return SUCCESS; + } + + public void setServletResponse(HttpServletResponse response) { + this.response = response; + } + + public void setEmail(String email) { + this.email = email; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setVerificationCode(String verificationCode) { + this.verificationCode = verificationCode; + } + + /** + * code:登录业务代码 + * msg:消息 + * status:0-成功 1-验证码错误 2-邮箱或密码错误 3-存在空字段 + * data:{'user_id' : '1', 'user_role' : 's'} + */ + + private static final int LOGIN_CODE = 1; + private static final int SUCC_STATUS = 0; + private static final int FAIL_VERIFICATION = 1; + private static final int FAIL_EMAIL_PASS = 2; + private static final int FAIL_EMPYT_PARAM = 3; + + class LoginJson { + int code; + String msg; + int status; + Map data = new HashMap(); + + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public Map getData() { + return data; + } + + public void setData(Map data) { + this.data = data; + } + + @Override + public String toString() { + return "LoginJson{" + + "code=" + code + + ", msg='" + msg + '\'' + + ", status=" + status + + ", data=" + data + + '}'; + } + } + +} + diff --git a/MyCourse/src/main/java/login/action/RegisterAction.java b/MyCourse/src/main/java/login/action/RegisterAction.java new file mode 100644 index 0000000..6c7e1cd --- /dev/null +++ b/MyCourse/src/main/java/login/action/RegisterAction.java @@ -0,0 +1,245 @@ +package login.action; + +import com.alibaba.fastjson.JSON; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import login.pojo.User; +import login.service.LoginService; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.interceptor.ServletResponseAware; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; + + +public class RegisterAction extends ActionSupport implements ServletResponseAware { + + private static final Logger LOG = LogManager.getLogger(RegisterJson.class); + + private String email; + private String password; + private String role; + private String name; + private String schoolId; + private String school; + private String dept; + private String major; + private String schoolClass; + + private final LoginService loginService; + + private HttpServletResponse response; + + @Autowired + public RegisterAction(LoginService loginService) { + this.loginService = loginService; + } + + public String toRegister() { + return SUCCESS; + } + + public String register() throws IOException { + RegisterJson registerJson = new RegisterJson(); + registerJson.code = REGISTER_CODE; + if (email == null || email.trim().length() == 0 || password == null || password.trim().length() == 0 || + (!role.equals("s") && !role.equals("t")) || name == null || name.trim().length() == 0 || + !testEmail(email) || !testPassword(password)) { + registerJson.msg = "存在非法字段"; + registerJson.status = INVALID_FILD_STATUS; + } else { + User user = new User(); + user.setEmail(email.trim()); + user.setPassword(password.trim()); + user.setRole(role); + user.setName(name.trim()); + if (schoolId == null) + user.setSchoolId(""); + else + user.setSchoolId(schoolId.trim()); + if (school == null) + user.setSchool(""); + else + user.setSchool(school.trim()); + if (dept == null) + user.setDept(""); + else + user.setDept(dept.trim()); + if (major == null) + user.setMajor(""); + else + user.setMajor(major.trim()); + if (schoolClass == null) + user.setSchoolClass(""); + else + user.setSchoolClass(schoolClass); + + int ret = loginService.registerUser(user); + + if (ret == LoginService.REGISTER_SUCC) { + registerJson.msg = "注册成功"; + registerJson.status = SUCC_STATUS; + registerJson.data.put("user_id", user.getId().toString()); + registerJson.data.put("user_role", user.getRole()); + ActionContext.getContext().getSession().put("user", user); + } else if (ret == LoginService.REGISTER_EMAIL_EXISTS) { + registerJson.msg = "邮箱已存在"; + registerJson.status = EMAIL_EXITS_STATUS; + } else if (ret == LoginService.REGISTER_ERROR) { + registerJson.msg = "注册失败"; + registerJson.status = ERROR_STATUS; + } + } + + response.setCharacterEncoding("utf-8"); + response.setContentType("application/json;charset=utf-8"); + String ret = JSON.toJSONString(registerJson); + LOG.debug("json: " + ret); + PrintWriter writer = response.getWriter(); + writer.print(ret); + writer.flush(); + writer.close(); + + return NONE; + } + + private boolean testEmail(String email) { + String re = "^[A-Za-z\\d]+([-_.][A-Za-z\\d]+)*@([A-Za-z\\d]+[-.])+[A-Za-z\\d]{2,4}$"; + return Pattern.matches(re, email); + } + + private boolean testPassword(String password) { + String re = "^[0-9a-zA-Z_]{6,18}$"; + return Pattern.matches(re, password); + } + + + private static final int REGISTER_CODE = 2; + private static final int SUCC_STATUS = 0; + private static final int INVALID_FILD_STATUS = 1; + private static final int EMAIL_EXITS_STATUS = 2; + private static final int ERROR_STATUS = 3; + + + class RegisterJson { + int code; + String msg; + int status; + Map data = new HashMap(); + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public Map getData() { + return data; + } + + public void setData(Map data) { + this.data = data; + } + } + + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSchoolId() { + return schoolId; + } + + public void setSchoolId(String schoolId) { + this.schoolId = schoolId; + } + + public String getSchool() { + return school; + } + + public void setSchool(String school) { + this.school = school; + } + + public String getDept() { + return dept; + } + + public void setDept(String dept) { + this.dept = dept; + } + + public String getMajor() { + return major; + } + + public void setMajor(String major) { + this.major = major; + } + + public String getSchoolClass() { + return schoolClass; + } + + public void setSchoolClass(String schoolClass) { + this.schoolClass = schoolClass; + } + + public void setServletResponse(HttpServletResponse response) { + this.response = response; + } +} diff --git a/MyCourse/src/main/java/login/action/VerificationCodeAction.java b/MyCourse/src/main/java/login/action/VerificationCodeAction.java new file mode 100644 index 0000000..72df3fe --- /dev/null +++ b/MyCourse/src/main/java/login/action/VerificationCodeAction.java @@ -0,0 +1,67 @@ +package login.action; + +import com.google.code.kaptcha.Producer; +import com.opensymphony.xwork2.ActionSupport; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.interceptor.ServletRequestAware; +import org.apache.struts2.interceptor.ServletResponseAware; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.imageio.ImageIO; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.awt.image.BufferedImage; +import java.io.IOException; + + +public class VerificationCodeAction extends ActionSupport implements ServletRequestAware, ServletResponseAware { + private final static Logger LOG = LogManager.getLogger(VerificationCodeAction.class); + private HttpServletRequest request; + private HttpServletResponse response; + + private final Producer captchaProducer; + + @Autowired + public VerificationCodeAction(Producer captchaProducer) { + this.captchaProducer = captchaProducer; + } + + public String execute() throws IOException { + HttpSession session = request.getSession(); + response.setDateHeader("Expires", 0); + response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); + response.addHeader("Cache-Control", "post-check=0, pre-check=0"); + response.setHeader("Pragma", "no-cache"); + response.setContentType("image/jpeg"); + + //生成验证码 + String capText = captchaProducer.createText(); + session.setAttribute("verificationCode", capText); + LOG.debug("verificationCode: " + capText); + + + //向客户端写出 + BufferedImage bi = captchaProducer.createImage(capText); + ServletOutputStream out = response.getOutputStream(); + ImageIO.write(bi, "jpg", out); + try { + out.flush(); + } finally { + out.close(); + } + + return NONE; + } + + public void setServletRequest(HttpServletRequest request) { + this.request = request; + } + + public void setServletResponse(HttpServletResponse response) { + this.response = response; + } + +} diff --git a/MyCourse/src/main/java/login/mapper/UserMapper.java b/MyCourse/src/main/java/login/mapper/UserMapper.java new file mode 100644 index 0000000..78acb98 --- /dev/null +++ b/MyCourse/src/main/java/login/mapper/UserMapper.java @@ -0,0 +1,13 @@ +package login.mapper; + +import login.pojo.User; + +public interface UserMapper { + User selectByEmailPassword(User user); + + User selectById(Integer id); + + User selectByEmail(String email); + + int insertUser(User user); +} diff --git a/MyCourse/src/main/java/login/pojo/User.java b/MyCourse/src/main/java/login/pojo/User.java new file mode 100644 index 0000000..15f0221 --- /dev/null +++ b/MyCourse/src/main/java/login/pojo/User.java @@ -0,0 +1,110 @@ +package login.pojo; + +public class User { + private Integer id; + private String email = ""; + private String password = ""; + private String role = ""; + private String name = ""; + private String schoolId = ""; + private String school = ""; + private String dept = ""; + private String major = ""; + private String schoolClass = ""; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSchoolId() { + return schoolId; + } + + public void setSchoolId(String schoolId) { + this.schoolId = schoolId; + } + + public String getSchool() { + return school; + } + + public void setSchool(String school) { + this.school = school; + } + + public String getDept() { + return dept; + } + + public void setDept(String dept) { + this.dept = dept; + } + + public String getMajor() { + return major; + } + + public void setMajor(String major) { + this.major = major; + } + + public String getSchoolClass() { + return schoolClass; + } + + public void setSchoolClass(String schoolClass) { + this.schoolClass = schoolClass; + } + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", email='" + email + '\'' + + ", password='" + password + '\'' + + ", role='" + role + '\'' + + ", name='" + name + '\'' + + ", schoolId='" + schoolId + '\'' + + ", school='" + school + '\'' + + ", dept='" + dept + '\'' + + ", major='" + major + '\'' + + ", schoolClass='" + schoolClass + '\'' + + '}'; + } +} diff --git a/MyCourse/src/main/java/login/service/LoginService.java b/MyCourse/src/main/java/login/service/LoginService.java new file mode 100644 index 0000000..4311485 --- /dev/null +++ b/MyCourse/src/main/java/login/service/LoginService.java @@ -0,0 +1,23 @@ +package login.service; + +import login.pojo.User; + +public interface LoginService { + + /** + * 根据账号和密码进行登录 + * @param user 用户对象 + * @return user详细信息,null表示邮箱或密码错误 + */ + User loginByEmailPassword(User user); + + /** + * 注册用户 + * @param user 用户对象 + * @return 注册结果状态 + */ + int REGISTER_EMAIL_EXISTS = 1; + int REGISTER_ERROR = 2; + int REGISTER_SUCC = 3; + int registerUser(User user); +} diff --git a/MyCourse/src/main/java/login/service/impl/LoginServiceImpl.java b/MyCourse/src/main/java/login/service/impl/LoginServiceImpl.java new file mode 100644 index 0000000..6a819ec --- /dev/null +++ b/MyCourse/src/main/java/login/service/impl/LoginServiceImpl.java @@ -0,0 +1,35 @@ +package login.service.impl; + +import login.mapper.UserMapper; +import login.pojo.User; +import login.service.LoginService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class LoginServiceImpl implements LoginService { + private final UserMapper userMapper; + + @Autowired + public LoginServiceImpl(UserMapper userMapper) { + this.userMapper = userMapper; + } + + public User loginByEmailPassword(User user) { + return userMapper.selectByEmailPassword(user); + } + + public int registerUser(User user) { + User u = userMapper.selectByEmail(user.getEmail()); + if (u == null) { + int ret = userMapper.insertUser(user); + if (ret > 0) { + return REGISTER_SUCC; + } else { + return REGISTER_ERROR; + } + } else { + return REGISTER_EMAIL_EXISTS; + } + } +} diff --git a/MyCourse/src/main/java/student/action/StuCourseListAction.java b/MyCourse/src/main/java/student/action/StuCourseListAction.java new file mode 100644 index 0000000..4f57206 --- /dev/null +++ b/MyCourse/src/main/java/student/action/StuCourseListAction.java @@ -0,0 +1,194 @@ +package student.action; + +import com.alibaba.fastjson.JSON; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import login.mapper.UserMapper; +import login.pojo.User; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.interceptor.ServletResponseAware; +import org.springframework.beans.factory.annotation.Autowired; +import student.pojo.StuCourse; +import student.pojo.StuTask; +import student.service.StuCourseListService; +import student.service.StuCourseService; +import student.service.StuCourseTaskService; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Date; +import java.util.List; + + +public class StuCourseListAction extends ActionSupport implements ServletResponseAware { + private static final Logger LOG = LogManager.getLogger(StuCourseListAction.class); + @Autowired + private UserMapper userMapper; + + private final StuCourseListService stuCourseListService; + + private final StuCourseService stuCourseService; + + @Autowired + private StuCourseTaskService stuCourseTaskService; + + @Autowired + public StuCourseListAction(StuCourseListService stuCourseListService, StuCourseService stuCourseService) { + this.stuCourseListService = stuCourseListService; + this.stuCourseService = stuCourseService; + } + + + private List stuCourses; + public String showCourseList() { + + User user = (User) ActionContext.getContext().getSession().get("user"); + + LOG.debug(user); + if (user == null) + return LOGIN; + + stuCourses = stuCourseListService.findSCourses(user); + LOG.debug("stuCourses: " + stuCourses); + + + for (StuCourse s : stuCourses) { + List stuTasks = stuCourseTaskService.findTasks(s); + for (StuTask task : stuTasks) { + if (task.getTitle().length() > 12) + task.setTitle(task.getTitle().substring(0, 12) + "..."); + } + + if (stuTasks.size() > 3) + s.setStuTasks(stuTasks.subList(0, 3)); + else + s.setStuTasks(stuTasks); + } + + return SUCCESS; + } + + public List getStuCourses() { + return stuCourses; + } + + public void setStuCourses(List stuCourses) { + this.stuCourses = stuCourses; + } + + private HttpServletResponse response; + private String courseCode; + + private static final int ENTER_COURSE_CODE = 4; + private static final int SUCC_STATUS = 0; + private static final int INVAID_FILED_STATUS = 1; + private static final int NO_COURSE_STATUS = 2; + private static final int HAS_ENTERED_STATUS = 3; + private static final int ERROR_STATUS = 4; + + + public String enterCourse() throws IOException { + User user = (User) ActionContext.getContext().getSession().get("user"); + LOG.debug(user); + if (user == null) + return LOGIN; + + EnterCourseJson enterCourseJson = new EnterCourseJson(); + enterCourseJson.code = ENTER_COURSE_CODE; + + if (courseCode == null || courseCode.trim().equals("")) { + enterCourseJson.msg = "存在空字段"; + enterCourseJson.status = INVAID_FILED_STATUS; + } else { + StuCourse stuCourse = new StuCourse(); + stuCourse.setCode(courseCode.trim().toUpperCase()); + stuCourse.setEnterTime(new Date()); + + int ret = stuCourseListService.enterCourse(stuCourse, user); + + if (ret == StuCourseListService.ENTER_COURSE_NOT_EXISTS) { + enterCourseJson.msg = "该课程不存在"; + enterCourseJson.status = NO_COURSE_STATUS; + } else if (ret == StuCourseListService.ENTER_HAS_ENTERED) { + enterCourseJson.msg = "已加入该课程"; + enterCourseJson.status = HAS_ENTERED_STATUS; + } else if (ret == StuCourseListService.ENTER_FAIL) { + enterCourseJson.msg = "加入失败"; + enterCourseJson.status = ERROR_STATUS; + } else if (ret == StuCourseListService.ENTER_SUCC) { + enterCourseJson.msg = "加入成功"; + enterCourseJson.status = SUCC_STATUS; + enterCourseJson.name = stuCourse.getName(); + } + + LOG.debug("stuCourse: " + stuCourse); + } + + response.setCharacterEncoding("utf-8"); + response.setContentType("application/json;charset=utf-8"); + String ret = JSON.toJSONString(enterCourseJson); + LOG.debug("json: " + ret); + PrintWriter writer = response.getWriter(); + writer.print(ret); + writer.flush(); + writer.close(); + + return NONE; + } + + class EnterCourseJson { + int code; + String msg; + int status; + String name; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + public void setServletResponse(HttpServletResponse response) { + this.response = response; + } + + public String getCourseCode() { + return courseCode; + } + + public void setCourseCode(String courseCode) { + this.courseCode = courseCode; + } + + + +} diff --git a/MyCourse/src/main/java/student/action/StuCourseNoticeAction.java b/MyCourse/src/main/java/student/action/StuCourseNoticeAction.java new file mode 100644 index 0000000..3a27bfc --- /dev/null +++ b/MyCourse/src/main/java/student/action/StuCourseNoticeAction.java @@ -0,0 +1,98 @@ +package student.action; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import login.mapper.UserMapper; +import login.pojo.User; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import student.pojo.StuCourse; +import student.pojo.StuNotice; +import student.service.StuCourseNoticeService; +import student.service.StuCourseService; + +import java.util.List; + + +public class StuCourseNoticeAction extends ActionSupport{ + private static final Logger LOG = LogManager.getLogger(StuCourseNoticeAction.class); + + private Integer courseId; + + private final StuCourseNoticeService stuCourseNoticeService; + + private final StuCourseService stuCourseService; + + private final UserMapper userMapper; + + @Autowired + public StuCourseNoticeAction(StuCourseNoticeService stuCourseNoticeService, StuCourseService stuCourseService, UserMapper userMapper) { + this.stuCourseNoticeService = stuCourseNoticeService; + this.stuCourseService = stuCourseService; + this.userMapper = userMapper; + } + +/* private void autoLogin() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user != null) + return; + + user = new User(); + + user.setEmail("gt110@qq.com"); + user.setPassword("gt1997531"); + user = userMapper.selectByEmailPassword(user); + + ActionContext.getContext().getSession().put("user", user); + }*/ + + private List stuNotices; + private StuCourse stuCourse; + + public String getNotice() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (courseId == null) + return ERROR; + + StuCourse s = new StuCourse(); + s.setId(courseId); + + stuNotices = stuCourseNoticeService.findNotices(s); + stuCourse = stuCourseService.findStuCourse(s); + LOG.debug("stuNotices: " + stuNotices); + LOG.debug("stuCourse: " + stuCourse); + + return SUCCESS; + } + + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } + + public List getStuNotices() { + return stuNotices; + } + + public void setStuNotices(List stuNotices) { + this.stuNotices = stuNotices; + } + + public StuCourse getStuCourse() { + return stuCourse; + } + + public void setStuCourse(StuCourse stuCourse) { + this.stuCourse = stuCourse; + } +} diff --git a/MyCourse/src/main/java/student/action/StuCourseResourceAction.java b/MyCourse/src/main/java/student/action/StuCourseResourceAction.java new file mode 100644 index 0000000..01f67d7 --- /dev/null +++ b/MyCourse/src/main/java/student/action/StuCourseResourceAction.java @@ -0,0 +1,76 @@ +package student.action; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import file.pojo.CourseResource; +import file.service.CourseResourceService; +import login.pojo.User; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import student.pojo.StuCourse; +import student.service.StuCourseService; + +import java.util.List; + + +public class StuCourseResourceAction extends ActionSupport { + private static final Logger LOG = LogManager.getLogger(StuCourseResourceAction.class); + + private Integer courseId; + + private StuCourse stuCourse; + + @Autowired + private StuCourseService stuCourseService; + @Autowired + private CourseResourceService courseResourceService; + + + private List resources; + + public String getResource() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (courseId == null) + return ERROR; + + StuCourse s = new StuCourse(); + s.setId(courseId); + + stuCourse = stuCourseService.findStuCourse(s); + + resources = courseResourceService.findByCourseId(courseId); + LOG.debug("resources " + resources); + + return SUCCESS; + } + + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } + + public StuCourse getStuCourse() { + return stuCourse; + } + + public void setStuCourse(StuCourse stuCourse) { + this.stuCourse = stuCourse; + } + + public List getResources() { + return resources; + } + + public void setResources(List resources) { + this.resources = resources; + } +} diff --git a/MyCourse/src/main/java/student/action/StuCourseTaskAction.java b/MyCourse/src/main/java/student/action/StuCourseTaskAction.java new file mode 100644 index 0000000..fa42365 --- /dev/null +++ b/MyCourse/src/main/java/student/action/StuCourseTaskAction.java @@ -0,0 +1,143 @@ +package student.action; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import file.pojo.TaskFile; +import file.service.TaskFileService; +import login.pojo.User; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import student.pojo.StuCourse; +import student.pojo.StuTask; +import student.service.StuCourseService; +import student.service.StuCourseTaskService; + +import java.text.SimpleDateFormat; +import java.util.List; + + +public class StuCourseTaskAction extends ActionSupport{ + private static final Logger LOG = LogManager.getLogger(StuCourseTaskAction.class); + + private final StuCourseTaskService stuCourseTaskService; + private final StuCourseService stuCourseService; + private final TaskFileService taskFileService; + + @Autowired + public StuCourseTaskAction(StuCourseTaskService stuCourseTaskService, StuCourseService stuCourseService, TaskFileService taskFileService) { + this.stuCourseTaskService = stuCourseTaskService; + this.stuCourseService = stuCourseService; + this.taskFileService = taskFileService; + } + + + + private List stuTasks; + private StuCourse stuCourse; + private Integer courseId; + + public String getTasks() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (courseId == null) + return ERROR; + + StuCourse s = new StuCourse(); + s.setId(courseId); + + stuTasks = stuCourseTaskService.findTasks(s); + stuCourse = stuCourseService.findStuCourse(s); + LOG.debug("stuTasks: " + stuTasks); + LOG.debug("stuCourse: " + stuCourse); + + return SUCCESS; + } + + + private Integer taskId; + private StuTask stuTask; + + private TaskFile taskFile; + + public String taskDetail() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (taskId == null || courseId == null) + return ERROR; + + stuTask = stuCourseTaskService.findTaskById(taskId); + + StuCourse s = new StuCourse(); + s.setId(courseId); + + stuCourse = stuCourseService.findStuCourse(s); + + taskFile = taskFileService.findByTaskIdStudentId(taskId, user.getId()); + if (taskFile != null) { + SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + taskFile.sethUploadTime(f.format(taskFile.getUploadTime())); + } + + if (stuTask == null || stuCourse == null) + return ERROR; + else + return SUCCESS; + + } + + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } + + public List getStuTasks() { + return stuTasks; + } + + public void setStuTasks(List stuTasks) { + this.stuTasks = stuTasks; + } + + public StuCourse getStuCourse() { + return stuCourse; + } + + public void setStuCourse(StuCourse stuCourse) { + this.stuCourse = stuCourse; + } + + public Integer getTaskId() { + return taskId; + } + + public void setTaskId(Integer taskId) { + this.taskId = taskId; + } + + public StuTask getStuTask() { + return stuTask; + } + + public void setStuTask(StuTask stuTask) { + this.stuTask = stuTask; + } + + public TaskFile getTaskFile() { + return taskFile; + } + + public void setTaskFile(TaskFile taskFile) { + this.taskFile = taskFile; + } +} diff --git a/MyCourse/src/main/java/student/mapper/StuCourseMapper.java b/MyCourse/src/main/java/student/mapper/StuCourseMapper.java new file mode 100644 index 0000000..202d94e --- /dev/null +++ b/MyCourse/src/main/java/student/mapper/StuCourseMapper.java @@ -0,0 +1,26 @@ +package student.mapper; + +import login.pojo.User; +import org.apache.ibatis.annotations.Param; +import student.pojo.StuCourse; + +import java.util.Date; +import java.util.List; + + +public interface StuCourseMapper { + List selectByStudentId(Integer studentId); + + StuCourse selectByCourseId(Integer courseId); + + StuCourse selectByCode(String code); + + int selectStudentCount(Integer courseId); + + User selectTeacherByCourseId(Integer courseId); + + Date selectEnterTimeByStudentId(@Param("courseId") Integer courseId, @Param("studentId") Integer studentId); + + int insertCourseStudent(@Param("courseId") Integer courseId, @Param("studentId") Integer studentId, @Param("enterTime") Date enterTime); + +} \ No newline at end of file diff --git a/MyCourse/src/main/java/student/mapper/StuCourseNoticeMapper.java b/MyCourse/src/main/java/student/mapper/StuCourseNoticeMapper.java new file mode 100644 index 0000000..ebbee9e --- /dev/null +++ b/MyCourse/src/main/java/student/mapper/StuCourseNoticeMapper.java @@ -0,0 +1,12 @@ +package student.mapper; + +import student.pojo.StuNotice; + +import java.util.List; + +public interface StuCourseNoticeMapper { + List selectAllByCourseId(Integer courseId); + + + +} diff --git a/MyCourse/src/main/java/student/mapper/StuCourseTaskMapper.java b/MyCourse/src/main/java/student/mapper/StuCourseTaskMapper.java new file mode 100644 index 0000000..0b158b4 --- /dev/null +++ b/MyCourse/src/main/java/student/mapper/StuCourseTaskMapper.java @@ -0,0 +1,11 @@ +package student.mapper; + +import student.pojo.StuTask; + +import java.util.List; + +public interface StuCourseTaskMapper { + List selectAllByCourseId(Integer courseId); + + StuTask selectByTaskId(Integer taskId); +} diff --git a/MyCourse/src/main/java/student/pojo/StuCourse.java b/MyCourse/src/main/java/student/pojo/StuCourse.java new file mode 100644 index 0000000..555fa01 --- /dev/null +++ b/MyCourse/src/main/java/student/pojo/StuCourse.java @@ -0,0 +1,98 @@ +package student.pojo; + +import login.pojo.User; + +import java.util.Date; +import java.util.List; + +public class StuCourse { + private Integer id; + private String code; + private String name; + private Date createTime; + + private Integer studentCount; + + private User teacher; + + private Date EnterTime; + + private List stuTasks; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Integer getStudentCount() { + return studentCount; + } + + public void setStudentCount(Integer studentCount) { + this.studentCount = studentCount; + } + + public User getTeacher() { + return teacher; + } + + public void setTeacher(User teacher) { + this.teacher = teacher; + } + + public Date getEnterTime() { + return EnterTime; + } + + public void setEnterTime(Date enterTime) { + EnterTime = enterTime; + } + + public List getStuTasks() { + return stuTasks; + } + + public void setStuTasks(List stuTasks) { + this.stuTasks = stuTasks; + } + + @Override + public String toString() { + return "StuCourse{" + + "id=" + id + + ", code='" + code + '\'' + + ", name='" + name + '\'' + + ", createTime=" + createTime + + ", studentCount=" + studentCount + + ", teacher=" + teacher + + ", EnterTime=" + EnterTime + + '}'; + } +} diff --git a/MyCourse/src/main/java/student/pojo/StuNotice.java b/MyCourse/src/main/java/student/pojo/StuNotice.java new file mode 100644 index 0000000..042a1e9 --- /dev/null +++ b/MyCourse/src/main/java/student/pojo/StuNotice.java @@ -0,0 +1,115 @@ +package student.pojo; + +import login.pojo.User; + +import java.util.Date; + +public class StuNotice { + private Integer id; + private Integer courseId; + private String title; + private String content; + private String plainTextContent; + private Integer writerId; + private Date createTime; + private Date updateTime; + + private User teacher; + private String hUpdateTime; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getPlainTextContent() { + return plainTextContent; + } + + public void setPlainTextContent(String plainTextContent) { + this.plainTextContent = plainTextContent; + } + + public Integer getWriterId() { + return writerId; + } + + public void setWriterId(Integer writerId) { + this.writerId = writerId; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public User getTeacher() { + return teacher; + } + + public void setTeacher(User teacher) { + this.teacher = teacher; + } + + public String gethUpdateTime() { + return hUpdateTime; + } + + public void sethUpdateTime(String hUpdateTime) { + this.hUpdateTime = hUpdateTime; + } + + @Override + public String toString() { + return "TeaNotice{" + + "id=" + id + + ", courseId=" + courseId + + ", title='" + title + '\'' + + ", content='" + content + '\'' + + ", plainTextContent='" + plainTextContent + '\'' + + ", writerId=" + writerId + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", teacher=" + teacher + + ", hUpdateTime='" + hUpdateTime + '\'' + + '}'; + } +} diff --git a/MyCourse/src/main/java/student/pojo/StuTask.java b/MyCourse/src/main/java/student/pojo/StuTask.java new file mode 100644 index 0000000..ca6a709 --- /dev/null +++ b/MyCourse/src/main/java/student/pojo/StuTask.java @@ -0,0 +1,136 @@ +package student.pojo; + +import login.pojo.User; + +import java.util.Date; + +public class StuTask { + private Integer id; + private Integer courseId; + private String title; + private String content; + private Date deadline; + private Integer writerId; + private Date createTime; + private Date updateTime; + + private String plainTextContent; + + private User teacher; + private String hUpdateTime; + private String hDeadline; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public Date getDeadline() { + return deadline; + } + + public void setDeadline(Date deadline) { + this.deadline = deadline; + } + + public Integer getWriterId() { + return writerId; + } + + public void setWriterId(Integer writerId) { + this.writerId = writerId; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public String getPlainTextContent() { + return plainTextContent; + } + + public void setPlainTextContent(String plainTextContent) { + this.plainTextContent = plainTextContent; + } + + public User getTeacher() { + return teacher; + } + + public void setTeacher(User teacher) { + this.teacher = teacher; + } + + public String gethUpdateTime() { + return hUpdateTime; + } + + public void sethUpdateTime(String hUpdateTime) { + this.hUpdateTime = hUpdateTime; + } + + public String gethDeadline() { + return hDeadline; + } + + public void sethDeadline(String hDeadline) { + this.hDeadline = hDeadline; + } + + @Override + public String toString() { + return "TeaTask{" + + "id=" + id + + ", courseId=" + courseId + + ", title='" + title + '\'' + + ", content='" + content + '\'' + + ", deadline=" + deadline + + ", writerId=" + writerId + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", plainTextContent='" + plainTextContent + '\'' + + ", teacher=" + teacher + + ", hUpdateTime='" + hUpdateTime + '\'' + + ", hDeadline='" + hDeadline + '\'' + + '}'; + } +} diff --git a/MyCourse/src/main/java/student/service/StuCourseListService.java b/MyCourse/src/main/java/student/service/StuCourseListService.java new file mode 100644 index 0000000..1238fd3 --- /dev/null +++ b/MyCourse/src/main/java/student/service/StuCourseListService.java @@ -0,0 +1,27 @@ +package student.service; + +import login.pojo.User; +import student.pojo.StuCourse; + +import java.util.List; + +public interface StuCourseListService { + /** + * 查询user用户拥有的课程 + * @param user 用户 + * @return 课程列表 + */ + List findSCourses(User user); + + /** + * 进入课堂 + * @param course 课程对象 + * @param student 学生对象 + * @return 状态码 + */ + int ENTER_COURSE_NOT_EXISTS = 0; + int ENTER_HAS_ENTERED = 1; + int ENTER_FAIL = 2; + int ENTER_SUCC = 3; + int enterCourse(StuCourse course, User student); +} diff --git a/MyCourse/src/main/java/student/service/StuCourseNoticeService.java b/MyCourse/src/main/java/student/service/StuCourseNoticeService.java new file mode 100644 index 0000000..69a89af --- /dev/null +++ b/MyCourse/src/main/java/student/service/StuCourseNoticeService.java @@ -0,0 +1,18 @@ +package student.service; + +import student.pojo.StuCourse; +import student.pojo.StuNotice; + +import java.util.List; + +public interface StuCourseNoticeService { + + /** + * 获取课程所有通知 + * @param stuCourse 课程对象 + * @return 通知集合 + */ + List findNotices(StuCourse stuCourse); + + +} diff --git a/MyCourse/src/main/java/student/service/StuCourseService.java b/MyCourse/src/main/java/student/service/StuCourseService.java new file mode 100644 index 0000000..d869e26 --- /dev/null +++ b/MyCourse/src/main/java/student/service/StuCourseService.java @@ -0,0 +1,12 @@ +package student.service; + +import student.pojo.StuCourse; + +public interface StuCourseService { + /** + * 根据courseId或courseCode查询课程信息 + * @param stuCourse 课程对象 + * @return 查找结果对象 + */ + StuCourse findStuCourse(StuCourse stuCourse); +} diff --git a/MyCourse/src/main/java/student/service/StuCourseTaskService.java b/MyCourse/src/main/java/student/service/StuCourseTaskService.java new file mode 100644 index 0000000..51a4f42 --- /dev/null +++ b/MyCourse/src/main/java/student/service/StuCourseTaskService.java @@ -0,0 +1,25 @@ +package student.service; + +import student.pojo.StuCourse; +import student.pojo.StuTask; + +import java.util.List; + +public interface StuCourseTaskService { + + /** + * 获取课程所有作业 + * @param stuCourse 课程对象 + * @return 作业集合 + */ + List findTasks(StuCourse stuCourse); + + + /** + * 根据id获取作业对象 + * @param taskId 作业id + * @return 作业对象 + */ + StuTask findTaskById(Integer taskId); + +} diff --git a/MyCourse/src/main/java/student/service/impl/StuCourseListServiceImpl.java b/MyCourse/src/main/java/student/service/impl/StuCourseListServiceImpl.java new file mode 100644 index 0000000..4e23a62 --- /dev/null +++ b/MyCourse/src/main/java/student/service/impl/StuCourseListServiceImpl.java @@ -0,0 +1,47 @@ +package student.service.impl; + +import login.pojo.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import student.mapper.StuCourseMapper; +import student.pojo.StuCourse; +import student.service.StuCourseListService; + +import java.util.List; + +@Service +public class StuCourseListServiceImpl implements StuCourseListService { + private final StuCourseMapper stuCourseMapper; + + @Autowired + public StuCourseListServiceImpl(StuCourseMapper stuCourseMapper) { + this.stuCourseMapper = stuCourseMapper; + } + + + public List findSCourses(User user) { + List stuCourses = stuCourseMapper.selectByStudentId(user.getId()); + + for (StuCourse stuCourse : stuCourses) { + stuCourse.setStudentCount(stuCourseMapper.selectStudentCount(stuCourse.getId())); + stuCourse.setTeacher(stuCourseMapper.selectTeacherByCourseId(stuCourse.getId())); + } + + return stuCourses; + } + + public int enterCourse(StuCourse course, User student) { + StuCourse old = stuCourseMapper.selectByCode(course.getCode()); + if (old == null) + return ENTER_COURSE_NOT_EXISTS; + course.setId(old.getId()); + course.setName(old.getName()); + if (stuCourseMapper.selectEnterTimeByStudentId(course.getId(), student.getId()) != null) + return ENTER_HAS_ENTERED; + boolean ret = stuCourseMapper.insertCourseStudent(course.getId(), student.getId(), course.getEnterTime()) > 0; + if (ret) + return ENTER_SUCC; + else + return ENTER_FAIL; + } +} diff --git a/MyCourse/src/main/java/student/service/impl/StuCourseNoticeServiceImpl.java b/MyCourse/src/main/java/student/service/impl/StuCourseNoticeServiceImpl.java new file mode 100644 index 0000000..b36670e --- /dev/null +++ b/MyCourse/src/main/java/student/service/impl/StuCourseNoticeServiceImpl.java @@ -0,0 +1,42 @@ +package student.service.impl; + +import login.mapper.UserMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import student.mapper.StuCourseNoticeMapper; +import student.pojo.StuCourse; +import student.pojo.StuNotice; +import student.service.StuCourseNoticeService; +import util.Html2Text; + +import java.text.SimpleDateFormat; +import java.util.List; + +@Service +public class StuCourseNoticeServiceImpl implements StuCourseNoticeService { + private final StuCourseNoticeMapper stuCourseNoticeMapper; + private final UserMapper userMapper; + + + @Autowired + public StuCourseNoticeServiceImpl(StuCourseNoticeMapper stuCourseNoticeMapper, UserMapper userMapper) { + this.stuCourseNoticeMapper = stuCourseNoticeMapper; + this.userMapper = userMapper; + } + + + public List findNotices(StuCourse stuCourse) { + List stuNotices = stuCourseNoticeMapper.selectAllByCourseId(stuCourse.getId()); + + for (StuNotice stuNotice : stuNotices) { + stuNotice.setPlainTextContent(Html2Text.StripHT(stuNotice.getContent(), 100)); + + SimpleDateFormat f = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); + stuNotice.sethUpdateTime(f.format(stuNotice.getUpdateTime())); + stuNotice.setTeacher(userMapper.selectById(stuNotice.getWriterId())); + } + + return stuNotices; + } + +} diff --git a/MyCourse/src/main/java/student/service/impl/StuCourseServiceImpl.java b/MyCourse/src/main/java/student/service/impl/StuCourseServiceImpl.java new file mode 100644 index 0000000..cf05721 --- /dev/null +++ b/MyCourse/src/main/java/student/service/impl/StuCourseServiceImpl.java @@ -0,0 +1,25 @@ +package student.service.impl; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import student.mapper.StuCourseMapper; +import student.pojo.StuCourse; +import student.service.StuCourseService; + +@Service +public class StuCourseServiceImpl implements StuCourseService { + private final StuCourseMapper stuCourseMapper; + + @Autowired + public StuCourseServiceImpl(StuCourseMapper stuCourseMapper) { + this.stuCourseMapper = stuCourseMapper; + } + + public StuCourse findStuCourse(StuCourse stuCourse) { + if (stuCourse.getId() != null) + return stuCourseMapper.selectByCourseId(stuCourse.getId()); + if (stuCourse.getCode() != null) + return stuCourseMapper.selectByCode(stuCourse.getCode()); + return null; + } +} diff --git a/MyCourse/src/main/java/student/service/impl/StuCourseTaskServiceImpl.java b/MyCourse/src/main/java/student/service/impl/StuCourseTaskServiceImpl.java new file mode 100644 index 0000000..427b0b1 --- /dev/null +++ b/MyCourse/src/main/java/student/service/impl/StuCourseTaskServiceImpl.java @@ -0,0 +1,58 @@ +package student.service.impl; + +import login.mapper.UserMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import student.mapper.StuCourseTaskMapper; +import student.pojo.StuCourse; +import student.pojo.StuTask; +import student.service.StuCourseTaskService; +import util.Html2Text; + +import java.text.SimpleDateFormat; +import java.util.List; + +@Service +public class StuCourseTaskServiceImpl implements StuCourseTaskService { + + private final StuCourseTaskMapper stuCourseTaskMapper; + private final UserMapper userMapper; + + @Autowired + public StuCourseTaskServiceImpl(StuCourseTaskMapper stuCourseTaskMapper, UserMapper userMapper) { + this.stuCourseTaskMapper = stuCourseTaskMapper; + this.userMapper = userMapper; + } + + public List findTasks(StuCourse stuCourse) { + List stuTasks = stuCourseTaskMapper.selectAllByCourseId(stuCourse.getId()); + + for (StuTask stuTask : stuTasks) { + stuTask.setPlainTextContent(Html2Text.StripHT(stuTask.getContent(), 100)); + + SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + stuTask.sethUpdateTime(f.format(stuTask.getUpdateTime())); + if (stuTask.getDeadline() != null) + stuTask.sethDeadline(f.format(stuTask.getDeadline())); + stuTask.setTeacher(userMapper.selectById(stuTask.getWriterId())); + } + + return stuTasks; + } + + public StuTask findTaskById(Integer taskId) { + StuTask stuTask = stuCourseTaskMapper.selectByTaskId(taskId); + SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + + stuTask.sethUpdateTime(f.format(stuTask.getUpdateTime())); + if (stuTask.getDeadline() != null) + stuTask.sethDeadline(f.format(stuTask.getDeadline())); + + stuTask.setTeacher(userMapper.selectById(stuTask.getWriterId())); + + return stuTask; + } + + +} + diff --git a/MyCourse/src/main/java/teacher/action/ResourceDeleteAction.java b/MyCourse/src/main/java/teacher/action/ResourceDeleteAction.java new file mode 100644 index 0000000..463efc9 --- /dev/null +++ b/MyCourse/src/main/java/teacher/action/ResourceDeleteAction.java @@ -0,0 +1,51 @@ +package teacher.action; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import file.service.CourseResourceService; +import login.pojo.User; +import org.springframework.beans.factory.annotation.Autowired; + +public class ResourceDeleteAction extends ActionSupport { + + private Integer resourceId; + + private Integer courseId; + + @Autowired + private CourseResourceService courseResourceService; + + public String delete() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (resourceId == null || courseId == null) + return ERROR; + + if (courseResourceService.deleteResource(resourceId)) { + return SUCCESS; + } else { + return ERROR; + } + + } + + + public Integer getResourceId() { + return resourceId; + } + + public void setResourceId(Integer resourceId) { + this.resourceId = resourceId; + } + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } +} diff --git a/MyCourse/src/main/java/teacher/action/TeaCourseListAction.java b/MyCourse/src/main/java/teacher/action/TeaCourseListAction.java new file mode 100644 index 0000000..5d54788 --- /dev/null +++ b/MyCourse/src/main/java/teacher/action/TeaCourseListAction.java @@ -0,0 +1,206 @@ +package teacher.action; + +import com.alibaba.fastjson.JSON; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import login.pojo.User; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.interceptor.ServletResponseAware; +import org.springframework.beans.factory.annotation.Autowired; +import teacher.pojo.TeaCourse; +import teacher.pojo.TeaTask; +import teacher.service.TeaCourseListService; +import teacher.service.TeaCourseService; +import teacher.service.TeaCourseTaskService; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.List; + + +public class TeaCourseListAction extends ActionSupport implements ServletResponseAware { + private static final Logger LOG = LogManager.getLogger(TeaCourseListAction.class); + + private final TeaCourseListService TeaCourseListService; + + @Autowired + private TeaCourseTaskService teaCourseTaskService; + + @Autowired + private TeaCourseService teaCourseService; + + @Autowired + public TeaCourseListAction(TeaCourseListService TeaCourseListService) { + this.TeaCourseListService = TeaCourseListService; + } + + + + private List teaCourses; + + public String showCourseList() { + + User user = (User) ActionContext.getContext().getSession().get("user"); + + LOG.debug(user); + if (user == null) + return LOGIN; + + teaCourses = TeaCourseListService.findTCourses(user); + LOG.debug("courses: " + teaCourses); + + for (TeaCourse t : teaCourses) { + List teaTasks = teaCourseTaskService.findTasks(t); + for (TeaTask task : teaTasks) { + if (task.getTitle().length() > 12) + task.setTitle(task.getTitle().substring(0, 12) + "..."); + } + + if (teaTasks.size() > 3) + t.setTeaTasks(teaTasks.subList(0, 3)); + else + t.setTeaTasks(teaTasks); + } + + return SUCCESS; + } + + public List getTeaCourses() { + return teaCourses; + } + + public void setTeaCourses(List teaCourses) { + this.teaCourses = teaCourses; + } + + private HttpServletResponse response; + private String courseName; + + private static final int CREATE_COURSE_CODE = 3; + private static final int SUCC_STATUS = 0; + private static final int INVAID_FILED_STATUS = 1; + private static final int FAIL_STATUS = 2; + + + + public String createCourse() throws IOException { + User user = (User) ActionContext.getContext().getSession().get("user"); + LOG.debug(user); + if (user == null) + return LOGIN; + + CreateCourseJson createCourseJson = new CreateCourseJson(); + createCourseJson.code = CREATE_COURSE_CODE; + if (courseName == null || courseName.trim().equals("")) { + createCourseJson.msg = "存在空字段"; + createCourseJson.status = INVAID_FILED_STATUS; + } else { + TeaCourse teaCourse = new TeaCourse(); + teaCourse.setName(courseName.trim()); + boolean ret = TeaCourseListService.addCourse(teaCourse, user); + if (ret) { + //创建课程成功 + createCourseJson.msg = "创建成功"; + createCourseJson.status = SUCC_STATUS; + createCourseJson.data.put("code", teaCourse.getCode()); + createCourseJson.data.put("id", teaCourse.getId()); + } else { + createCourseJson.msg = "创建失败"; + createCourseJson.status = FAIL_STATUS; + } + } + + response.setCharacterEncoding("utf-8"); + response.setContentType("application/json;charset=utf-8"); + String ret = JSON.toJSONString(createCourseJson); + LOG.debug("json: " + ret); + PrintWriter writer = response.getWriter(); + writer.print(ret); + writer.flush(); + writer.close(); + + return NONE; + } + + class CreateCourseJson { + int code; + String msg; + int status; + HashMap data = new HashMap(); + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public HashMap getData() { + return data; + } + + public void setData(HashMap data) { + this.data = data; + } + } + + + private Integer courseId; + public String deleteCourse() { + User user = (User) ActionContext.getContext().getSession().get("user"); + if (user == null) + return LOGIN; + + if (courseId == null) + return ERROR; + + if (teaCourseService.deleteByCourseId(courseId)) { + return SUCCESS; + } else { + return ERROR; + } + } + + public void setServletResponse(HttpServletResponse response) { + this.response = response; + } + + public String getCourseName() { + return courseName; + } + + public void setCourseName(String courseName) { + this.courseName = courseName; + } + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } +} + + + diff --git a/MyCourse/src/main/java/teacher/action/TeaCourseNoticeAction.java b/MyCourse/src/main/java/teacher/action/TeaCourseNoticeAction.java new file mode 100644 index 0000000..79603ef --- /dev/null +++ b/MyCourse/src/main/java/teacher/action/TeaCourseNoticeAction.java @@ -0,0 +1,153 @@ +package teacher.action; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import login.pojo.User; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import teacher.pojo.TeaCourse; +import teacher.pojo.TeaNotice; +import teacher.service.TeaCourseNoticeService; +import teacher.service.TeaCourseService; + +import java.util.Date; +import java.util.List; + + +public class TeaCourseNoticeAction extends ActionSupport{ + private static final Logger LOG = LogManager.getLogger(TeaCourseNoticeAction.class); + + private Integer courseId; + + private final TeaCourseNoticeService teaCourseNoticeService; + + private final TeaCourseService teaCourseService; + + @Autowired + public TeaCourseNoticeAction(TeaCourseNoticeService teaCourseNoticeService, TeaCourseService teaCourseService) { + this.teaCourseNoticeService = teaCourseNoticeService; + this.teaCourseService = teaCourseService; + } + + + private List teaNotices; + private TeaCourse teaCourse; + + public String getNotice() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (courseId == null) + return ERROR; + + TeaCourse c = new TeaCourse(); + c.setId(courseId); + + teaNotices = teaCourseNoticeService.findNotices(c); + teaCourse = teaCourseService.findTCourse(c); + LOG.debug("teaNotices: " + teaNotices); + LOG.debug("teaCourse: " + teaCourse); + + return SUCCESS; + } + + private String noticeName; + private String noticeContent; + + public String addNotice() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (noticeName == null || noticeName.trim().equals("") || + noticeContent == null || courseId == null) + return ERROR; + + TeaNotice teaNotice = new TeaNotice(); + teaNotice.setTitle(noticeName.trim()); + teaNotice.setContent(noticeContent); + teaNotice.setCourseId(courseId); + teaNotice.setWriterId(user.getId()); + teaNotice.setCreateTime(new Date()); + teaNotice.setUpdateTime(new Date()); + + if (teaCourseNoticeService.addNotice(teaNotice)) + return SUCCESS; + else + return ERROR; + } + + + private Integer noticeId; + public String deleteNotice() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (noticeId == null || courseId == null) + return ERROR; + + TeaNotice teaNotice = new TeaNotice(); + teaNotice.setId(noticeId); + if (teaCourseNoticeService.deleteNotice(teaNotice)) + return SUCCESS; + else + return ERROR; + } + + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } + + public List getTeaNotices() { + return teaNotices; + } + + public void setTeaNotices(List teaNotices) { + this.teaNotices = teaNotices; + } + + public TeaCourse getTeaCourse() { + return teaCourse; + } + + public void setTeaCourse(TeaCourse teaCourse) { + this.teaCourse = teaCourse; + } + + public String getNoticeName() { + return noticeName; + } + + public void setNoticeName(String noticeName) { + this.noticeName = noticeName; + } + + public String getNoticeContent() { + return noticeContent; + } + + public void setNoticeContent(String noticeContent) { + this.noticeContent = noticeContent; + } + + public Integer getNoticeId() { + return noticeId; + } + + public void setNoticeId(Integer noticeId) { + this.noticeId = noticeId; + } +} + + diff --git a/MyCourse/src/main/java/teacher/action/TeaCourseResourceAction.java b/MyCourse/src/main/java/teacher/action/TeaCourseResourceAction.java new file mode 100644 index 0000000..79198db --- /dev/null +++ b/MyCourse/src/main/java/teacher/action/TeaCourseResourceAction.java @@ -0,0 +1,79 @@ +package teacher.action; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import file.pojo.CourseResource; +import file.service.CourseResourceService; +import login.pojo.User; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import teacher.pojo.TeaCourse; +import teacher.service.TeaCourseService; + +import java.util.List; + + +public class TeaCourseResourceAction extends ActionSupport { + private static final Logger LOG = LogManager.getLogger(TeaCourseResourceAction.class); + + private Integer courseId; + + private TeaCourse teaCourse; + + private final TeaCourseService teaCourseService; + private final CourseResourceService courseResourceService; + + @Autowired + public TeaCourseResourceAction(TeaCourseService teaCourseService, CourseResourceService courseResourceService) { + this.teaCourseService = teaCourseService; + this.courseResourceService = courseResourceService; + } + + private List resources; + + public String getResource() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (courseId == null) + return ERROR; + + TeaCourse c = new TeaCourse(); + c.setId(courseId); + + teaCourse = teaCourseService.findTCourse(c); + + resources = courseResourceService.findByCourseId(courseId); + LOG.debug("resources " + resources); + + return SUCCESS; + } + + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } + + public TeaCourse getTeaCourse() { + return teaCourse; + } + + public void setTeaCourse(TeaCourse teaCourse) { + this.teaCourse = teaCourse; + } + + public List getResources() { + return resources; + } + + public void setResources(List resources) { + this.resources = resources; + } +} diff --git a/MyCourse/src/main/java/teacher/action/TeaCourseStudentAction.java b/MyCourse/src/main/java/teacher/action/TeaCourseStudentAction.java new file mode 100644 index 0000000..31589bd --- /dev/null +++ b/MyCourse/src/main/java/teacher/action/TeaCourseStudentAction.java @@ -0,0 +1,69 @@ +package teacher.action; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import login.pojo.User; +import org.springframework.beans.factory.annotation.Autowired; +import teacher.pojo.TeaCourse; +import teacher.service.TeaCourseService; +import teacher.service.TeaCourseStudentService; + +import java.util.List; + +public class TeaCourseStudentAction extends ActionSupport { + + private Integer courseId; + + private List students; + + private TeaCourse teaCourse; + + @Autowired + private TeaCourseService teaCourseService; + + @Autowired + private TeaCourseStudentService teaCourseStudentService; + + public String findStudents() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if(user == null) + return LOGIN; + + if(courseId == null) + return ERROR; + + students = teaCourseStudentService.findAllByCourseId(courseId); + + TeaCourse c = new TeaCourse(); + c.setId(courseId); + + teaCourse = teaCourseService.findTCourse(c); + + return SUCCESS; + } + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } + + public void setStudents(List students) { + this.students = students; + } + + public List getStudents() { + return students; + } + + public TeaCourse getTeaCourse() { + return teaCourse; + } + + public void setTeaCourse(TeaCourse teaCourse) { + this.teaCourse = teaCourse; + } +} diff --git a/MyCourse/src/main/java/teacher/action/TeaCourseTaskAction.java b/MyCourse/src/main/java/teacher/action/TeaCourseTaskAction.java new file mode 100644 index 0000000..9c24963 --- /dev/null +++ b/MyCourse/src/main/java/teacher/action/TeaCourseTaskAction.java @@ -0,0 +1,278 @@ +package teacher.action; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import login.pojo.User; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import teacher.pojo.StuTaskFiles; +import teacher.pojo.TeaCourse; +import teacher.pojo.TeaTask; +import teacher.service.TeaCourseService; +import teacher.service.TeaCourseTaskService; + +import java.util.Date; +import java.util.List; + + +public class TeaCourseTaskAction extends ActionSupport{ + private static final Logger LOG = LogManager.getLogger(TeaCourseTaskAction.class); + + private Integer courseId; + private final TeaCourseTaskService teaCourseTaskService; + private final TeaCourseService teaCourseService; + + @Autowired + public TeaCourseTaskAction(TeaCourseTaskService teaCourseTaskService, TeaCourseService teaCourseService) { + this.teaCourseTaskService = teaCourseTaskService; + this.teaCourseService = teaCourseService; + } + + + private List teaTasks; + private TeaCourse teaCourse; + + public String getTasks() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (courseId == null) + return ERROR; + + TeaCourse c = new TeaCourse(); + c.setId(courseId); + + teaTasks = teaCourseTaskService.findTasks(c); + teaCourse = teaCourseService.findTCourse(c); + LOG.debug("teaTasks: " + teaTasks); + LOG.debug("teaCourse: " + teaCourse); + + return SUCCESS; + } + + private String taskName; + private String taskContent; + private long deadlineTime; + + public String addTask() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (taskName == null || taskName.trim().equals("") || + taskContent == null || courseId == null) + return ERROR; + + TeaTask teaTask = new TeaTask(); + teaTask.setTitle(taskName.trim()); + teaTask.setContent(taskContent); + teaTask.setCourseId(courseId); + teaTask.setWriterId(user.getId()); + teaTask.setCreateTime(new Date()); + teaTask.setUpdateTime(new Date()); + if (deadlineTime != 0) + teaTask.setDeadline(new Date(deadlineTime)); + + if (teaCourseTaskService.addTask(teaTask)) + return SUCCESS; + else + return ERROR; + } + + public String updateTask() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (taskName == null || taskName.trim().equals("") || + taskContent == null || courseId == null || taskId == null) + return ERROR; + + TeaTask teaTask = teaCourseTaskService.findTaskById(taskId); + if (teaTask == null || !courseId.equals(teaTask.getCourseId())) return ERROR; + + teaTask.setTitle(taskName.trim()); + teaTask.setContent(taskContent); + teaTask.setWriterId(user.getId()); + teaTask.setUpdateTime(new Date()); + if(deadlineTime != 0) + teaTask.setDeadline(new Date(deadlineTime)); + else + teaTask.setDeadline(null); + + if (teaCourseTaskService.updateTask(teaTask)) + return SUCCESS; + else + return ERROR; + } + + + private Integer taskId; + + public String deleteTask() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (taskId == null || courseId == null) + return ERROR; + + TeaTask teaTask = new TeaTask(); + teaTask.setId(taskId); + if (teaCourseTaskService.deleteTask(teaTask)) + return SUCCESS; + else + return ERROR; + } + + + private TeaTask teaTask; + public String toUpdate() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (taskId == null || courseId == null) + return ERROR; + + teaTask = teaCourseTaskService.findTaskById(taskId); + TeaCourse t = new TeaCourse(); + t.setId(courseId); + + teaCourse = teaCourseService.findTCourse(t); + + if (teaTask == null || teaCourse == null) + return ERROR; + else + return SUCCESS; + } + + + private List stuTaskFiles; + private int allNum = 0; + private int uploadNum = 0; + public String taskDetail() { + User user = (User) ActionContext.getContext().getSession().get("user"); + + if (user == null) + return LOGIN; + + if (taskId == null || courseId == null) + return ERROR; + + teaTask = teaCourseTaskService.findTaskById(taskId); + + TeaCourse t = new TeaCourse(); + t.setId(courseId); + teaCourse = teaCourseService.findTCourse(t); + + stuTaskFiles = teaCourseTaskService.findStuTaskFiles(courseId, taskId); + + LOG.debug("stuTaskFiles: " + stuTaskFiles); + + allNum = stuTaskFiles.size(); + for (StuTaskFiles s : stuTaskFiles) { + if (s.getTaskFile() != null) + uploadNum++; + } + + return SUCCESS; + } + + + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } + + public List getTeaTasks() { + return teaTasks; + } + + public void setTeaTasks(List teaTasks) { + this.teaTasks = teaTasks; + } + + public TeaCourse getTeaCourse() { + return teaCourse; + } + + public void setTeaCourse(TeaCourse teaCourse) { + this.teaCourse = teaCourse; + } + + public String getTaskName() { + return taskName; + } + + public void setTaskName(String taskName) { + this.taskName = taskName; + } + + public String getTaskContent() { + return taskContent; + } + + public void setTaskContent(String taskContent) { + this.taskContent = taskContent; + } + + public long getDeadlineTime() { + return deadlineTime; + } + + public void setDeadlineTime(long deadlineTime) { + this.deadlineTime = deadlineTime; + } + + public Integer getTaskId() { + return taskId; + } + + public void setTaskId(Integer taskId) { + this.taskId = taskId; + } + + public TeaTask getTeaTask() { + return teaTask; + } + + public void setTeaTask(TeaTask teaTask) { + this.teaTask = teaTask; + } + + public List getStuTaskFiles() { + return stuTaskFiles; + } + + public void setStuTaskFiles(List stuTaskFiles) { + this.stuTaskFiles = stuTaskFiles; + } + + public int getAllNum() { + return allNum; + } + + public void setAllNum(int allNum) { + this.allNum = allNum; + } + + public int getUploadNum() { + return uploadNum; + } + + public void setUploadNum(int uploadNum) { + this.uploadNum = uploadNum; + } +} diff --git a/MyCourse/src/main/java/teacher/action/TeaCourseTestAction.java b/MyCourse/src/main/java/teacher/action/TeaCourseTestAction.java new file mode 100644 index 0000000..619ffe8 --- /dev/null +++ b/MyCourse/src/main/java/teacher/action/TeaCourseTestAction.java @@ -0,0 +1,10 @@ +package teacher.action; + +import com.opensymphony.xwork2.ActionSupport; + +public class TeaCourseTestAction extends ActionSupport { + + public String toAddTest() { + return SUCCESS; + } +} diff --git a/MyCourse/src/main/java/teacher/mapper/StuTaskFilesMapper.java b/MyCourse/src/main/java/teacher/mapper/StuTaskFilesMapper.java new file mode 100644 index 0000000..e8dcc61 --- /dev/null +++ b/MyCourse/src/main/java/teacher/mapper/StuTaskFilesMapper.java @@ -0,0 +1,5 @@ +package teacher.mapper; + +public interface StuTaskFilesMapper { + +} diff --git a/MyCourse/src/main/java/teacher/mapper/TeaCourseMapper.java b/MyCourse/src/main/java/teacher/mapper/TeaCourseMapper.java new file mode 100644 index 0000000..57b41da --- /dev/null +++ b/MyCourse/src/main/java/teacher/mapper/TeaCourseMapper.java @@ -0,0 +1,26 @@ +package teacher.mapper; + +import login.pojo.User; +import org.apache.ibatis.annotations.Param; +import teacher.pojo.TeaCourse; + +import java.util.List; + + +public interface TeaCourseMapper { + List selectByTeacherId(Integer teacherId); + + TeaCourse selectByCode(String code); + + TeaCourse selectByCourseId(Integer courseId); + + int selectStudentCount(TeaCourse teaCourse); + + int insertCourse(TeaCourse teaCourse); + + int insertCourseTeacher(@Param("courseId") Integer courseId, @Param("teacherId") Integer teacherId); + + List selectCourseStudent(Integer courseId); + + int delete(Integer courseId); +} \ No newline at end of file diff --git a/MyCourse/src/main/java/teacher/mapper/TeaCourseNoticeMapper.java b/MyCourse/src/main/java/teacher/mapper/TeaCourseNoticeMapper.java new file mode 100644 index 0000000..bda5751 --- /dev/null +++ b/MyCourse/src/main/java/teacher/mapper/TeaCourseNoticeMapper.java @@ -0,0 +1,13 @@ +package teacher.mapper; + +import teacher.pojo.TeaNotice; + +import java.util.List; + +public interface TeaCourseNoticeMapper { + List selectAllByCourseId(Integer courseId); + + int insertNotice(TeaNotice teaNotice); + + int deleteNotice(Integer noticeId); +} diff --git a/MyCourse/src/main/java/teacher/mapper/TeaCourseTaskMapper.java b/MyCourse/src/main/java/teacher/mapper/TeaCourseTaskMapper.java new file mode 100644 index 0000000..c5db8a1 --- /dev/null +++ b/MyCourse/src/main/java/teacher/mapper/TeaCourseTaskMapper.java @@ -0,0 +1,17 @@ +package teacher.mapper; + +import teacher.pojo.TeaTask; + +import java.util.List; + +public interface TeaCourseTaskMapper { + List selectAllByCourseId(Integer courseId); + + TeaTask selectByTaskId(Integer taskId); + + int insertTask(TeaTask teaTask); + + int updateTask(TeaTask teaTask); + + int deleteTask(Integer taskId); +} diff --git a/MyCourse/src/main/java/teacher/pojo/StuTaskFiles.java b/MyCourse/src/main/java/teacher/pojo/StuTaskFiles.java new file mode 100644 index 0000000..12be6f0 --- /dev/null +++ b/MyCourse/src/main/java/teacher/pojo/StuTaskFiles.java @@ -0,0 +1,33 @@ +package teacher.pojo; + +import file.pojo.TaskFile; +import login.pojo.User; + +public class StuTaskFiles { + private User user; + private TaskFile taskFile; + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public TaskFile getTaskFile() { + return taskFile; + } + + public void setTaskFile(TaskFile taskFile) { + this.taskFile = taskFile; + } + + @Override + public String toString() { + return "StuTaskFiles{" + + "user=" + user + + ", taskFile=" + taskFile + + '}'; + } +} diff --git a/MyCourse/src/main/java/teacher/pojo/TeaCourse.java b/MyCourse/src/main/java/teacher/pojo/TeaCourse.java new file mode 100644 index 0000000..45dc1ca --- /dev/null +++ b/MyCourse/src/main/java/teacher/pojo/TeaCourse.java @@ -0,0 +1,74 @@ +package teacher.pojo; + +import java.util.Date; +import java.util.List; + +public class TeaCourse { + private Integer id; + private String code; + private String name; + private Date createTime; + + private Integer studentCount; + + private List teaTasks; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Integer getStudentCount() { + return studentCount; + } + + public void setStudentCount(Integer studentCount) { + this.studentCount = studentCount; + } + + public List getTeaTasks() { + return teaTasks; + } + + public void setTeaTasks(List teaTasks) { + this.teaTasks = teaTasks; + } + + @Override + public String toString() { + return "StuCourse{" + + "id=" + id + + ", code='" + code + '\'' + + ", name='" + name + '\'' + + ", createTime=" + createTime + + ", studentCount=" + studentCount + + '}'; + } +} diff --git a/MyCourse/src/main/java/teacher/pojo/TeaNotice.java b/MyCourse/src/main/java/teacher/pojo/TeaNotice.java new file mode 100644 index 0000000..acd608e --- /dev/null +++ b/MyCourse/src/main/java/teacher/pojo/TeaNotice.java @@ -0,0 +1,115 @@ +package teacher.pojo; + +import login.pojo.User; + +import java.util.Date; + +public class TeaNotice { + private Integer id; + private Integer courseId; + private String title; + private String content; + private String plainTextContent; + private Integer writerId; + private Date createTime; + private Date updateTime; + + private User teacher; + private String hUpdateTime; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getPlainTextContent() { + return plainTextContent; + } + + public void setPlainTextContent(String plainTextContent) { + this.plainTextContent = plainTextContent; + } + + public Integer getWriterId() { + return writerId; + } + + public void setWriterId(Integer writerId) { + this.writerId = writerId; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public User getTeacher() { + return teacher; + } + + public void setTeacher(User teacher) { + this.teacher = teacher; + } + + public String gethUpdateTime() { + return hUpdateTime; + } + + public void sethUpdateTime(String hUpdateTime) { + this.hUpdateTime = hUpdateTime; + } + + @Override + public String toString() { + return "TeaNotice{" + + "id=" + id + + ", courseId=" + courseId + + ", title='" + title + '\'' + + ", content='" + content + '\'' + + ", plainTextContent='" + plainTextContent + '\'' + + ", writerId=" + writerId + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", teacher=" + teacher + + ", hUpdateTime='" + hUpdateTime + '\'' + + '}'; + } +} diff --git a/MyCourse/src/main/java/teacher/pojo/TeaTask.java b/MyCourse/src/main/java/teacher/pojo/TeaTask.java new file mode 100644 index 0000000..6ed7a0f --- /dev/null +++ b/MyCourse/src/main/java/teacher/pojo/TeaTask.java @@ -0,0 +1,136 @@ +package teacher.pojo; + +import login.pojo.User; + +import java.util.Date; + +public class TeaTask { + private Integer id; + private Integer courseId; + private String title; + private String content; + private Date deadline; + private Integer writerId; + private Date createTime; + private Date updateTime; + + private String plainTextContent; + + private User teacher; + private String hUpdateTime; + private String hDeadline; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getCourseId() { + return courseId; + } + + public void setCourseId(Integer courseId) { + this.courseId = courseId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public Date getDeadline() { + return deadline; + } + + public void setDeadline(Date deadline) { + this.deadline = deadline; + } + + public Integer getWriterId() { + return writerId; + } + + public void setWriterId(Integer writerId) { + this.writerId = writerId; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public String getPlainTextContent() { + return plainTextContent; + } + + public void setPlainTextContent(String plainTextContent) { + this.plainTextContent = plainTextContent; + } + + public User getTeacher() { + return teacher; + } + + public void setTeacher(User teacher) { + this.teacher = teacher; + } + + public String gethUpdateTime() { + return hUpdateTime; + } + + public void sethUpdateTime(String hUpdateTime) { + this.hUpdateTime = hUpdateTime; + } + + public String gethDeadline() { + return hDeadline; + } + + public void sethDeadline(String hDeadline) { + this.hDeadline = hDeadline; + } + + @Override + public String toString() { + return "TeaTask{" + + "id=" + id + + ", courseId=" + courseId + + ", title='" + title + '\'' + + ", content='" + content + '\'' + + ", deadline=" + deadline + + ", writerId=" + writerId + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", plainTextContent='" + plainTextContent + '\'' + + ", teacher=" + teacher + + ", hUpdateTime='" + hUpdateTime + '\'' + + ", hDeadline='" + hDeadline + '\'' + + '}'; + } +} diff --git a/MyCourse/src/main/java/teacher/service/TeaCourseListService.java b/MyCourse/src/main/java/teacher/service/TeaCourseListService.java new file mode 100644 index 0000000..344d023 --- /dev/null +++ b/MyCourse/src/main/java/teacher/service/TeaCourseListService.java @@ -0,0 +1,23 @@ +package teacher.service; + +import login.pojo.User; +import teacher.pojo.TeaCourse; + +import java.util.List; + +public interface TeaCourseListService { + /** + * 查询user用户拥有的课程 + * @param user 用户 + * @return 课程列表 + */ + List findTCourses(User user); + + /** + * 添加新课程 + * @param teaCourse 课程对象 + * @param user 创建者对象 + * @return 是否成功 + */ + boolean addCourse(TeaCourse teaCourse, User user); +} diff --git a/MyCourse/src/main/java/teacher/service/TeaCourseNoticeService.java b/MyCourse/src/main/java/teacher/service/TeaCourseNoticeService.java new file mode 100644 index 0000000..1b99503 --- /dev/null +++ b/MyCourse/src/main/java/teacher/service/TeaCourseNoticeService.java @@ -0,0 +1,32 @@ +package teacher.service; + +import teacher.pojo.TeaCourse; +import teacher.pojo.TeaNotice; + +import java.util.List; + +public interface TeaCourseNoticeService { + + /** + * 获取课程所有通知 + * @param teaCourse 课程对象 + * @return 通知集合 + */ + List findNotices(TeaCourse teaCourse); + + /** + * 增加公告 + * @param teaNotice 公告 + * @return 是否成功 + */ + boolean addNotice(TeaNotice teaNotice); + + + /** + * 删除公告 + * @param teaNotice 公告对象 + * @return 是否成功删除 + */ + boolean deleteNotice(TeaNotice teaNotice); + +} diff --git a/MyCourse/src/main/java/teacher/service/TeaCourseService.java b/MyCourse/src/main/java/teacher/service/TeaCourseService.java new file mode 100644 index 0000000..603f2b9 --- /dev/null +++ b/MyCourse/src/main/java/teacher/service/TeaCourseService.java @@ -0,0 +1,14 @@ +package teacher.service; + +import teacher.pojo.TeaCourse; + +public interface TeaCourseService { + /** + * 根据courseId或courseCode查询课程信息 + * @param teaCourse 课程对象 + * @return 查找结果对象 + */ + TeaCourse findTCourse(TeaCourse teaCourse); + + boolean deleteByCourseId(Integer courseId); +} diff --git a/MyCourse/src/main/java/teacher/service/TeaCourseStudentService.java b/MyCourse/src/main/java/teacher/service/TeaCourseStudentService.java new file mode 100644 index 0000000..07cbc7b --- /dev/null +++ b/MyCourse/src/main/java/teacher/service/TeaCourseStudentService.java @@ -0,0 +1,9 @@ +package teacher.service; + +import login.pojo.User; + +import java.util.List; + +public interface TeaCourseStudentService { + List findAllByCourseId(Integer courseId); +} diff --git a/MyCourse/src/main/java/teacher/service/TeaCourseTaskService.java b/MyCourse/src/main/java/teacher/service/TeaCourseTaskService.java new file mode 100644 index 0000000..65fa607 --- /dev/null +++ b/MyCourse/src/main/java/teacher/service/TeaCourseTaskService.java @@ -0,0 +1,55 @@ +package teacher.service; + +import teacher.pojo.StuTaskFiles; +import teacher.pojo.TeaCourse; +import teacher.pojo.TeaTask; + +import java.util.List; + +public interface TeaCourseTaskService { + + /** + * 获取课程所有作业 + * @param teaCourse 课程对象 + * @return 作业集合 + */ + List findTasks(TeaCourse teaCourse); + + + /** + * 根据id获取作业对象 + * @param taskId 作业id + * @return 作业对象 + */ + TeaTask findTaskById(Integer taskId); + + /** + * 增加作业 + * @param teaTask 作业 + * @return 是否成功 + */ + boolean addTask(TeaTask teaTask); + + /** + * 修改作业 + * @param teaTask 作业 + * @return 是否成功 + */ + boolean updateTask(TeaTask teaTask); + + /** + * 删除作业 + * @param teaTask 作业对象 + * @return 是否成功删除 + */ + boolean deleteTask(TeaTask teaTask); + + /** + * 获取学生作业文件集 + * @param courseId 课程id + * @param taskId 作业id + * @return 作业集 + */ + List findStuTaskFiles(Integer courseId, Integer taskId); + +} diff --git a/MyCourse/src/main/java/teacher/service/impl/TeaCourseListServiceImpl.java b/MyCourse/src/main/java/teacher/service/impl/TeaCourseListServiceImpl.java new file mode 100644 index 0000000..2c9c9e0 --- /dev/null +++ b/MyCourse/src/main/java/teacher/service/impl/TeaCourseListServiceImpl.java @@ -0,0 +1,54 @@ +package teacher.service.impl; + +import login.pojo.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import teacher.mapper.TeaCourseMapper; +import teacher.pojo.TeaCourse; +import teacher.service.TeaCourseListService; +import util.GenerateCode; + +import java.util.Date; +import java.util.List; + +@Service +public class TeaCourseListServiceImpl implements TeaCourseListService { + private final TeaCourseMapper teaCourseMapper; + + @Autowired + public TeaCourseListServiceImpl(TeaCourseMapper teaCourseMapper) { + this.teaCourseMapper = teaCourseMapper; + } + + public List findTCourses(User user) { + List teaCourses = teaCourseMapper.selectByTeacherId(user.getId()); + + for (TeaCourse teaCourse : teaCourses) { + teaCourse.setStudentCount(teaCourseMapper.selectStudentCount(teaCourse)); + } + + return teaCourses; + } + + public boolean addCourse(TeaCourse teaCourse, User user) { + String code = GenerateCode.generate(); + + boolean norepeat = false; + + while (!norepeat) { + if (teaCourseMapper.selectByCode(code) == null) + norepeat = true; + else + code = GenerateCode.generate(); + } + + teaCourse.setCode(code); + teaCourse.setCreateTime(new Date()); + + boolean ret = teaCourseMapper.insertCourse(teaCourse) > 0 && teaCourseMapper.insertCourseTeacher(teaCourse.getId(), user.getId()) > 0; + if (ret) { + teaCourse = teaCourseMapper.selectByCode(code); + } + return ret; + } +} diff --git a/MyCourse/src/main/java/teacher/service/impl/TeaCourseNoticeServiceImpl.java b/MyCourse/src/main/java/teacher/service/impl/TeaCourseNoticeServiceImpl.java new file mode 100644 index 0000000..8dd09d6 --- /dev/null +++ b/MyCourse/src/main/java/teacher/service/impl/TeaCourseNoticeServiceImpl.java @@ -0,0 +1,49 @@ +package teacher.service.impl; + +import login.mapper.UserMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import teacher.mapper.TeaCourseNoticeMapper; +import teacher.pojo.TeaCourse; +import teacher.pojo.TeaNotice; +import teacher.service.TeaCourseNoticeService; +import util.Html2Text; + +import java.text.SimpleDateFormat; +import java.util.List; + +@Service +public class TeaCourseNoticeServiceImpl implements TeaCourseNoticeService { + private final TeaCourseNoticeMapper teaCourseNoticeMapper; + + private final UserMapper userMapper; + + @Autowired + public TeaCourseNoticeServiceImpl(TeaCourseNoticeMapper teaCourseNoticeMapper, UserMapper userMapper) { + this.teaCourseNoticeMapper = teaCourseNoticeMapper; + this.userMapper = userMapper; + } + + + public List findNotices(TeaCourse teaCourse) { + List teaNotices = teaCourseNoticeMapper.selectAllByCourseId(teaCourse.getId()); + + for (TeaNotice teaNotice : teaNotices) { + teaNotice.setPlainTextContent(Html2Text.StripHT(teaNotice.getContent(), 100)); + + SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + teaNotice.sethUpdateTime(f.format(teaNotice.getUpdateTime())); + teaNotice.setTeacher(userMapper.selectById(teaNotice.getWriterId())); + } + + return teaNotices; + } + + public boolean addNotice(TeaNotice teaNotice) { + return teaCourseNoticeMapper.insertNotice(teaNotice) > 0; + } + + public boolean deleteNotice(TeaNotice teaNotice) { + return teaCourseNoticeMapper.deleteNotice(teaNotice.getId()) > 0; + } +} diff --git a/MyCourse/src/main/java/teacher/service/impl/TeaCourseServiceImpl.java b/MyCourse/src/main/java/teacher/service/impl/TeaCourseServiceImpl.java new file mode 100644 index 0000000..c629114 --- /dev/null +++ b/MyCourse/src/main/java/teacher/service/impl/TeaCourseServiceImpl.java @@ -0,0 +1,29 @@ +package teacher.service.impl; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import teacher.mapper.TeaCourseMapper; +import teacher.pojo.TeaCourse; +import teacher.service.TeaCourseService; + +@Service +public class TeaCourseServiceImpl implements TeaCourseService { + private final TeaCourseMapper teaCourseMapper; + + @Autowired + public TeaCourseServiceImpl(TeaCourseMapper teaCourseMapper) { + this.teaCourseMapper = teaCourseMapper; + } + + public TeaCourse findTCourse(TeaCourse teaCourse) { + if (teaCourse.getId() != null) + return teaCourseMapper.selectByCourseId(teaCourse.getId()); + if (teaCourse.getCode() != null) + return teaCourseMapper.selectByCode(teaCourse.getCode()); + return null; + } + + public boolean deleteByCourseId(Integer courseId) { + return teaCourseMapper.delete(courseId) > 0; + } +} diff --git a/MyCourse/src/main/java/teacher/service/impl/TeaCourseStudentServiceImpl.java b/MyCourse/src/main/java/teacher/service/impl/TeaCourseStudentServiceImpl.java new file mode 100644 index 0000000..74eaf0b --- /dev/null +++ b/MyCourse/src/main/java/teacher/service/impl/TeaCourseStudentServiceImpl.java @@ -0,0 +1,24 @@ +package teacher.service.impl; + +import login.pojo.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import teacher.mapper.TeaCourseMapper; +import teacher.service.TeaCourseStudentService; + +import java.util.List; + +@Service +public class TeaCourseStudentServiceImpl implements TeaCourseStudentService { + + private final TeaCourseMapper teaCourseMapper; + + @Autowired + public TeaCourseStudentServiceImpl(TeaCourseMapper teaCourseMapper) { + this.teaCourseMapper = teaCourseMapper; + } + + public List findAllByCourseId(Integer courseId) { + return teaCourseMapper.selectCourseStudent(courseId); + } +} diff --git a/MyCourse/src/main/java/teacher/service/impl/TeaCourseTaskServiceImpl.java b/MyCourse/src/main/java/teacher/service/impl/TeaCourseTaskServiceImpl.java new file mode 100644 index 0000000..2a1c4a6 --- /dev/null +++ b/MyCourse/src/main/java/teacher/service/impl/TeaCourseTaskServiceImpl.java @@ -0,0 +1,107 @@ +package teacher.service.impl; + +import file.mapper.TaskFileMapper; +import file.pojo.TaskFile; +import login.mapper.UserMapper; +import login.pojo.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import teacher.mapper.TeaCourseMapper; +import teacher.mapper.TeaCourseTaskMapper; +import teacher.pojo.StuTaskFiles; +import teacher.pojo.TeaCourse; +import teacher.pojo.TeaTask; +import teacher.service.TeaCourseTaskService; +import util.Html2Text; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +@Service +public class TeaCourseTaskServiceImpl implements TeaCourseTaskService { + + private final TeaCourseTaskMapper teaCourseTaskMapper; + private final UserMapper userMapper; + + private final TeaCourseMapper teaCourseMapper; + + private final TaskFileMapper taskFileMapper; + + @Autowired + public TeaCourseTaskServiceImpl(TeaCourseTaskMapper teaCourseTaskMapper, UserMapper userMapper, TeaCourseMapper teaCourseMapper, TaskFileMapper taskFileMapper) { + this.teaCourseTaskMapper = teaCourseTaskMapper; + this.userMapper = userMapper; + this.teaCourseMapper = teaCourseMapper; + this.taskFileMapper = taskFileMapper; + } + + public List findTasks(TeaCourse teaCourse) { + List teaTasks = teaCourseTaskMapper.selectAllByCourseId(teaCourse.getId()); + + for (TeaTask teaTask : teaTasks) { + teaTask.setPlainTextContent(Html2Text.StripHT(teaTask.getContent(), 100)); + + SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + teaTask.sethUpdateTime(f.format(teaTask.getUpdateTime())); + if (teaTask.getDeadline() != null) + teaTask.sethDeadline(f.format(teaTask.getDeadline())); + teaTask.setTeacher(userMapper.selectById(teaTask.getWriterId())); + } + + return teaTasks; + } + + public TeaTask findTaskById(Integer taskId) { + TeaTask teaTask = teaCourseTaskMapper.selectByTaskId(taskId); + SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + + teaTask.sethUpdateTime(f.format(teaTask.getUpdateTime())); + if (teaTask.getDeadline() != null) + teaTask.sethDeadline(f.format(teaTask.getDeadline())); + + teaTask.setTeacher(userMapper.selectById(teaTask.getWriterId())); + + return teaTask; + } + + public boolean addTask(TeaTask teaTask) { + return teaCourseTaskMapper.insertTask(teaTask) > 0; + } + + public boolean updateTask(TeaTask teaTask) { + return teaCourseTaskMapper.updateTask(teaTask) > 0; + } + + public boolean deleteTask(TeaTask teaTask) { + return teaCourseTaskMapper.deleteTask(teaTask.getId()) > 0; + } + + public List findStuTaskFiles(Integer courseId, Integer taskId) { + List students = teaCourseMapper.selectCourseStudent(courseId); + + if (students != null) { + List stuTaskFiles = new ArrayList(); + + for (User s : students) { + StuTaskFiles stf = new StuTaskFiles(); + stf.setUser(s); + + TaskFile taskFile = taskFileMapper.selectByTaskIdStudentId(taskId, s.getId()); + + if (taskFile != null) { + stf.setTaskFile(taskFile); + taskFile.sethUploadTime(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(taskFile.getUploadTime())); + } + + stuTaskFiles.add(stf); + } + + + return stuTaskFiles; + } else + return null; + } + +} + diff --git a/MyCourse/src/main/java/util/DownloadFileNameOp.java b/MyCourse/src/main/java/util/DownloadFileNameOp.java new file mode 100644 index 0000000..42b3392 --- /dev/null +++ b/MyCourse/src/main/java/util/DownloadFileNameOp.java @@ -0,0 +1,17 @@ +package util; + +import javax.servlet.http.HttpServletRequest; + +public class DownloadFileNameOp { + public static String downToUtf8String(String s, HttpServletRequest request) throws Exception { + String agent = request.getHeader("User-Agent"); + agent = agent.toLowerCase(); + if (agent.contains("firefox")) { + s = s.replaceAll("\\s+", "-"); + s = new String(s.getBytes(), "iso8859-1"); + } else { + s = java.net.URLEncoder.encode(s, "UTF-8"); + } + return s; + } +} diff --git a/MyCourse/src/main/java/util/GenerateCode.java b/MyCourse/src/main/java/util/GenerateCode.java new file mode 100644 index 0000000..bd62d45 --- /dev/null +++ b/MyCourse/src/main/java/util/GenerateCode.java @@ -0,0 +1,17 @@ +package util; + +import java.util.UUID; + +public class GenerateCode { + public static String generate() { + String code; + UUID uuid = UUID.randomUUID(); + code = uuid.toString().substring(0, 6).toUpperCase(); + return code; + } + + public static void main(String[] args) { + for (int i = 0; i < 10; i++) + System.out.println(GenerateCode.generate()); + } +} diff --git a/MyCourse/src/main/java/util/Html2Text.java b/MyCourse/src/main/java/util/Html2Text.java new file mode 100644 index 0000000..f573e49 --- /dev/null +++ b/MyCourse/src/main/java/util/Html2Text.java @@ -0,0 +1,22 @@ +package util; + + +public class Html2Text { + public static String StripHT(String strHtml, int len) { + + String txtcontent = strHtml.replaceAll("]+>", "").replaceAll(" ", "");//剔出的标签 + txtcontent = txtcontent.replaceAll("\\s*|\t|\r|\n", "");//去除字符串中的空格,回车,换行符,制表符 + if (txtcontent.length() > len) + return txtcontent.substring(0, len) + "..."; + else + return txtcontent; + + + } + + public static void main(String[] args) { + System.out.println(StripHT("

    Java是一种广泛使用的计算机编程语言,拥有跨平台面向对象泛型编程的特性,广泛应用于企业级Web应用开发和移动应用开发。

    任职于太阳微系统詹姆斯·高斯林等人于1990年代初开发Java语言的雏形,最初被命名为Oak,目标设置在家用电器等小型系统的编程语言,应用在电视机电话闹钟烤面包机等家用电器的控制和通信。由于这些智能化家电的市场需求没有预期的高,Sun公司放弃了该项计划。随着1990年代互联网的发展,Sun公司看见Oak在互联网上应用的前景,于是改造了Oak,于1995年5月以Java的名称正式发布。Java伴随着互联网的迅猛发展而发展,逐渐成为重要的网络编程语言。

    Java编程语言的风格十分接近C++语言。继承了C++语言面向对象技术的核心,舍弃了容易引起错误的指针,以引用取代;移除了C++中的运算符重载多重继承特性,用接口取代;增加垃圾回收器功能。在Java SE 1.5版本中引入了泛型编程类型安全的枚举、不定长参数和自动装/拆箱特性。太阳微系统对Java语言的解释是:“Java编程语言是个简单、面向对象、分布式、解释性、健壮、安全与系统无关、可移植、高性能、多线程和动态的语言”

    Java不同于一般的编译语言解释型语言。它首先将源代码编译成字节码,再依赖各种不同平台上的虚拟机来解释执行字节码,从而具有“一次编写,到处运行”的跨平台特性。在早期JVM中,这在一定程度上降低了Java程序的运行效率。但在J2SE1.4.2发布后,Java的运行速度有了大幅提升。

    与传统类型不同,Sun公司在推出Java时就将其作为开放的技术。全球的Java开发公司被要求所设计的Java软件必须相互兼容。“Java语言靠群体的力量而非公司的力量”是Sun公司的口号之一,并获得了广大软件开发商的认同。这与微软公司所倡导的注重精英和封闭式的模式完全不同,此外,微软公司后来推出了与之竞争的.NET平台以及模仿Java的C#语言。后来Sun公司被甲骨文公司并购,Java也随之成为甲骨文公司的产品。

    现时,移动操作系统Android大部分的代码采用Java编程语言编程。

import java.util.UUID;

public class GenerateCode {
public static String generate() {
String code;
UUID uuid = UUID.randomUUID();
code = uuid.toString().substring(0, 6).toUpperCase();
return code;
}

public static void main(String[] args) {
for (int i = 0; i < 10; i++)
System.out.println(GenerateCode.generate());
}
}


", 30)); + + } + +} diff --git a/MyCourse/src/main/resources/applicationContext.xml b/MyCourse/src/main/resources/applicationContext.xml new file mode 100644 index 0000000..4aedc7c --- /dev/null +++ b/MyCourse/src/main/resources/applicationContext.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + no + black + 125 + 40 + 35 + 4 + 50,128,252 + com.google.code.kaptcha.impl.ShadowGimpy + white + white + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/src/main/resources/db.properties b/MyCourse/src/main/resources/db.properties new file mode 100644 index 0000000..e4958d1 --- /dev/null +++ b/MyCourse/src/main/resources/db.properties @@ -0,0 +1,4 @@ +jdbc.driver=com.mysql.cj.jdbc.Driver +jdbc.url=jdbc:mysql://localhost:3306/mycourse2?serverTimezone=Asia/Shanghai +jdbc.username=root +jdbc.password=mysql \ No newline at end of file diff --git a/MyCourse/src/main/resources/file/mapper/CourseResourceMapper.xml b/MyCourse/src/main/resources/file/mapper/CourseResourceMapper.xml new file mode 100644 index 0000000..8425cc7 --- /dev/null +++ b/MyCourse/src/main/resources/file/mapper/CourseResourceMapper.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + insert into resource(course_id, file_name, file_path, upload_time) + values (#{courseId}, #{fileName}, #{filePath}, #{uploadTime}) + + + + delete from resource + where id = #{resourceId} + + + \ No newline at end of file diff --git a/MyCourse/src/main/resources/file/mapper/TaskFileMapper.xml b/MyCourse/src/main/resources/file/mapper/TaskFileMapper.xml new file mode 100644 index 0000000..f935d3e --- /dev/null +++ b/MyCourse/src/main/resources/file/mapper/TaskFileMapper.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + insert into task_file(task_id, user_id, upload_time, file_name, file_path) + values (#{taskId}, #{userId}, #{uploadTime}, #{fileName}, #{filePath}) + + + + update task_file + set task_id = #{taskId}, user_id = #{userId}, upload_time = #{uploadTime}, + file_name = #{fileName}, file_path = #{filePath} + where id = #{id} + + + + diff --git a/MyCourse/src/main/resources/log4j2.xml b/MyCourse/src/main/resources/log4j2.xml new file mode 100644 index 0000000..f4aa6fd --- /dev/null +++ b/MyCourse/src/main/resources/log4j2.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/src/main/resources/login/mapper/UserMapper.xml b/MyCourse/src/main/resources/login/mapper/UserMapper.xml new file mode 100644 index 0000000..fb9b14a --- /dev/null +++ b/MyCourse/src/main/resources/login/mapper/UserMapper.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + insert into user(id, email, password, role, name, school_id, school, dept, major, class) + values(#{id}, #{email}, #{password}, #{role}, #{name}, #{schoolId}, #{school}, #{dept}, + #{major}, #{schoolClass}) + + + \ No newline at end of file diff --git a/MyCourse/src/main/resources/struts.xml b/MyCourse/src/main/resources/struts.xml new file mode 100644 index 0000000..009078e --- /dev/null +++ b/MyCourse/src/main/resources/struts.xml @@ -0,0 +1,220 @@ + + + + + + + + + + + + + + + / + /404.html + + + + / + + + + + + + + /WEB-INF/login/register.jsp + + + + + + + toLogin + + + + + + + / + /404.html + + + + /WEB-INF/teacher/courselist.jsp + + + + + + + + showCourseList + + + + + /WEB-INF/teacher/course_notice.jsp + + + + + notice + ${courseId} + + + + + + notice + ${courseId} + + + + + /WEB-INF/teacher/course_task.jsp + + + + + task + ${courseId} + + + + + + task + ${courseId} + + + + + /WEB-INF/teacher/course_task_update.jsp + + + + + task + ${courseId} + + + + + /WEB-INF/teacher/course_task_detail.jsp + + + + /WEB-INF/teacher/course_resource.jsp + + + + + resource + ${courseId} + + + + + /WEB-INF/teacher/course_student.jsp + + + + /WEB-INF/teacher/add_test.jsp + + + + + + + + + / + /404.html + + + + /WEB-INF/student/courselist.jsp + + + + + + /WEB-INF/student/course_notice.jsp + + + + /WEB-INF/student/course_task.jsp + + + + /WEB-INF/student/course_task_detail.jsp + + + + /WEB-INF/student/course_resource.jsp + + + + + + + / + /404.html + + + + + 52428800 + + + + + + inputStream + attachment;filename=${fileName} + ${contentLength} + utf-8 + + + + + + inputStream + attachment;filename=${fileName} + ${contentLength} + utf-8 + + + + + + + inputStream + attachment;filename=${fileName} + ${contentLength} + + + + + + 524288000 + + + + + + inputStream + attachment;filename=${fileName} + ${contentLength} + + + + + + \ No newline at end of file diff --git a/MyCourse/src/main/resources/student/mapper/StuCourseMapper.xml b/MyCourse/src/main/resources/student/mapper/StuCourseMapper.xml new file mode 100644 index 0000000..8bc4bb2 --- /dev/null +++ b/MyCourse/src/main/resources/student/mapper/StuCourseMapper.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert into course_student(course_id, user_id, enter_time) + values (#{courseId}, #{studentId}, #{enterTime}); + + + + + + \ No newline at end of file diff --git a/MyCourse/src/main/resources/student/mapper/StuCourseNoticeMapper.xml b/MyCourse/src/main/resources/student/mapper/StuCourseNoticeMapper.xml new file mode 100644 index 0000000..aa79138 --- /dev/null +++ b/MyCourse/src/main/resources/student/mapper/StuCourseNoticeMapper.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/src/main/resources/student/mapper/StuCourseTaskMapper.xml b/MyCourse/src/main/resources/student/mapper/StuCourseTaskMapper.xml new file mode 100644 index 0000000..4c86ebc --- /dev/null +++ b/MyCourse/src/main/resources/student/mapper/StuCourseTaskMapper.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyCourse/src/main/resources/teacher/mapper/TeaCourseMapper.xml b/MyCourse/src/main/resources/teacher/mapper/TeaCourseMapper.xml new file mode 100644 index 0000000..76f7b38 --- /dev/null +++ b/MyCourse/src/main/resources/teacher/mapper/TeaCourseMapper.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert into course(code, name, create_time) + values (#{code}, #{name}, #{createTime}) + + + + insert into course_teacher(course_id, user_id) values (#{courseId}, #{teacherId}) + + + + + + delete from course + where id = #{courseId} + + \ No newline at end of file diff --git a/MyCourse/src/main/resources/teacher/mapper/TeaCourseNoticeMapper.xml b/MyCourse/src/main/resources/teacher/mapper/TeaCourseNoticeMapper.xml new file mode 100644 index 0000000..b0220f3 --- /dev/null +++ b/MyCourse/src/main/resources/teacher/mapper/TeaCourseNoticeMapper.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + insert into notice(course_id, title, content, writer_id, create_time, update_time) + values (#{courseId}, #{title}, #{content}, #{writerId}, #{createTime}, #{updateTime}) + + + + delete + from notice + where id = #{noticeId} + + \ No newline at end of file diff --git a/MyCourse/src/main/resources/teacher/mapper/TeaCourseTaskMapper.xml b/MyCourse/src/main/resources/teacher/mapper/TeaCourseTaskMapper.xml new file mode 100644 index 0000000..c0dd253 --- /dev/null +++ b/MyCourse/src/main/resources/teacher/mapper/TeaCourseTaskMapper.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + insert into task(course_id, title, content, deadline, writer_id, create_time, update_time) + values (#{courseId}, #{title}, #{content}, #{deadline}, #{writerId}, #{createTime}, #{updateTime}) + + + + update task + set course_id = #{courseId}, title = #{title}, content = #{content}, deadline = #{deadline}, + writer_id = #{writerId}, create_time = #{createTime}, update_time = #{updateTime} + where id = #{id} + + + + delete + from task + where id = #{taskId} + + + \ No newline at end of file diff --git a/MyCourse/web/404.html b/MyCourse/web/404.html new file mode 100644 index 0000000..1cb906b --- /dev/null +++ b/MyCourse/web/404.html @@ -0,0 +1,20 @@ + + + + + 404 + + + + + + + \ No newline at end of file diff --git a/MyCourse/web/WEB-INF/login/register.jsp b/MyCourse/web/WEB-INF/login/register.jsp new file mode 100644 index 0000000..f3dd70d --- /dev/null +++ b/MyCourse/web/WEB-INF/login/register.jsp @@ -0,0 +1,283 @@ + +<%@ page contentType="text/html;charset=UTF-8" %> + + + + 我的课堂注册 + + + + + + + + + +
+ + + + +
+

注册

+ +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + +
+ +
+ +
+ + + + diff --git a/MyCourse/web/WEB-INF/student/course_notice.jsp b/MyCourse/web/WEB-INF/student/course_notice.jsp new file mode 100644 index 0000000..df8d521 --- /dev/null +++ b/MyCourse/web/WEB-INF/student/course_notice.jsp @@ -0,0 +1,200 @@ +<%@ taglib prefix="s" uri="/struts-tags" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%-- + User: Gao Tian + Date: 2019/6/27 + Time: 8:46 +--%> +<%@ page contentType="text/html;charset=UTF-8" %> + + + + ${stuCourse.name} + + + + + + + + + + + + + + + +
+ +
+
+
+ ${stuCourse.name} +
+
+ 邀请码:${stuCourse.code} +
+
+
+ + + +

暂无公告

+
+ +
+ +
+ +
+ ${stuNotice.plainTextContent} +
+ + +
+ + +
+
+ + + + diff --git a/MyCourse/web/WEB-INF/student/course_resource.jsp b/MyCourse/web/WEB-INF/student/course_resource.jsp new file mode 100644 index 0000000..7460d54 --- /dev/null +++ b/MyCourse/web/WEB-INF/student/course_resource.jsp @@ -0,0 +1,114 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + User: Gao Tian + Date: 2019/7/1 + Time: 10:08 +--%> +<%@ page contentType="text/html;charset=UTF-8" %> + + + + ${stuCourse.name} + + + + + + + + + + + + + + + + +
+

资源列表

+ +
+ + +
+ + + + + + diff --git a/MyCourse/web/WEB-INF/student/course_task.jsp b/MyCourse/web/WEB-INF/student/course_task.jsp new file mode 100644 index 0000000..1fde04e --- /dev/null +++ b/MyCourse/web/WEB-INF/student/course_task.jsp @@ -0,0 +1,137 @@ + +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + User: Gao Tian + Date: 2019/6/27 + Time: 8:46 +--%> +<%@ page contentType="text/html;charset=UTF-8" %> + + + + ${stuCourse.name} + + + + + + + + + + + + + + +
+ +
+
+
+ ${stuCourse.name} +
+
+ 邀请码:${stuCourse.code} +
+
+
+ + +

暂无作业

+
+ +
+ +
+ +
+ ${stuTask.plainTextContent} +
+ + +
+
+
+ +
+ + + + + diff --git a/MyCourse/web/WEB-INF/student/course_task_detail.jsp b/MyCourse/web/WEB-INF/student/course_task_detail.jsp new file mode 100644 index 0000000..e77ba0f --- /dev/null +++ b/MyCourse/web/WEB-INF/student/course_task_detail.jsp @@ -0,0 +1,159 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + User: Gao Tian + Date: 2019/6/29 + Time: 13:05 +--%> +<%@ page contentType="text/html;charset=UTF-8" %> + + + + ${stuTask.title} + + + + + + + + + + + + + + + +
+
+ +
+

${stuTask.title}

+ +
+
发布者
+
${stuTask.teacher.name}
+
更新时间
+
${stuTask.hUpdateTime}
+
截止时间
+
${stuTask.hDeadline}
+
+ +
+ +
+ ${stuTask.content} +
+ +
+
    + +
+
+
+ +
+

上传作业:

+ +

已交: ${taskFile.fileName}    提交时间:${taskFile.hUploadTime}

+

再次上传将覆盖原文件

+
+ +
+
+
+ +
+
+
+
+ + +
+
+
+
+ + + + + diff --git a/MyCourse/web/WEB-INF/student/courselist.jsp b/MyCourse/web/WEB-INF/student/courselist.jsp new file mode 100644 index 0000000..a187837 --- /dev/null +++ b/MyCourse/web/WEB-INF/student/courselist.jsp @@ -0,0 +1,295 @@ +<%@ page import="java.util.List" %> +<%@ page import="java.util.ArrayList" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + User: Gao Tian + Date: 2019/6/25 + Time: 21:23 +--%> +<%@ page contentType="text/html;charset=UTF-8" %> + + + + 课程列表 + + + + + + + + + + + + + + +
+
+ + +
+ +
+ <% + List linears = new ArrayList<>(); + linears.add("background-image: linear-gradient(0deg,rgb(53,191,254) 0%,rgb(27,144,254) 100%)!important;"); + linears.add("background-image: linear-gradient(0deg,rgb(86,205,189) 0%,rgb(33,203,103) 100%)!important;"); + linears.add("background-image: linear-gradient(0deg,rgb(250,214,96) 0%,rgb(254,144,80) 100%)!important;"); + linears.add("background-image: linear-gradient(0deg,rgb(163,132,254) 0%,rgb(74,80,254) 100%)!important"); + linears.add("background-image: linear-gradient(0deg,rgb(254,127,172) 0%,rgb(249,93,85) 99%)!important;"); + linears.add("background-image: linear-gradient(0deg,rgb(69,213,211) 0%,rgb(4,173,184) 99%)!important;"); + request.setAttribute("linears", linears); + %> + + +
+
+ ${course.name}
+

 ${course.studentCount}名学生

+ + +
+
+

近期作业

+ + ${t.title}
+
+
+ +
+ +
+
+ +
+ + + + + + + + diff --git a/MyCourse/web/WEB-INF/teacher/add_test.jsp b/MyCourse/web/WEB-INF/teacher/add_test.jsp new file mode 100644 index 0000000..7fb1bfa --- /dev/null +++ b/MyCourse/web/WEB-INF/teacher/add_test.jsp @@ -0,0 +1,79 @@ +<%-- + User: Gao Tian + Date: 2019/7/19 + Time: 22:23 +--%> +<%@ page contentType="text/html;charset=UTF-8" %> + + + + ${teaCourse.name}-新建测试 + + + + + + + + + + + + + + +
+ 发送到发的 + +
+ + + diff --git a/MyCourse/web/WEB-INF/teacher/course_notice.jsp b/MyCourse/web/WEB-INF/teacher/course_notice.jsp new file mode 100644 index 0000000..1d1077b --- /dev/null +++ b/MyCourse/web/WEB-INF/teacher/course_notice.jsp @@ -0,0 +1,294 @@ +<%@ taglib prefix="s" uri="/struts-tags" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + User: Gao Tian + Date: 2019/6/27 + Time: 8:46 +--%> +<%@ page contentType="text/html;charset=UTF-8" %> + + + + ${teaCourse.name} + + + + + + + + + + + + + + + +
+
+
+
+ ${teaCourse.name} +
+
+ 邀请码:${teaCourse.code} +
+
+
+ + +
+ + +
+ +
+ +
+ +
+ ${teaNotice.plainTextContent} +
+ + +
+ + +
+
+ + + + + + diff --git a/MyCourse/web/WEB-INF/teacher/course_resource.jsp b/MyCourse/web/WEB-INF/teacher/course_resource.jsp new file mode 100644 index 0000000..8aeacfd --- /dev/null +++ b/MyCourse/web/WEB-INF/teacher/course_resource.jsp @@ -0,0 +1,176 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + User: Gao Tian + Date: 2019/7/1 + Time: 10:08 +--%> +<%@ page contentType="text/html;charset=UTF-8" %> + + + + ${teaCourse.name} + + + + + + + + + + + + + + + + +
+
+
+
+ +
+
+
+
+ + +
+
+ +
+

资源列表

+ +
+ + +
+ + + +
+ + + + + + diff --git a/MyCourse/web/WEB-INF/teacher/course_student.jsp b/MyCourse/web/WEB-INF/teacher/course_student.jsp new file mode 100644 index 0000000..a2d8deb --- /dev/null +++ b/MyCourse/web/WEB-INF/teacher/course_student.jsp @@ -0,0 +1,126 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + User: Gao Tian + Date: 2019/7/1 + Time: 21:17 +--%> +<%@ page contentType="text/html;charset=UTF-8" %> + + + + ${teaCourse.name} + + + + + + + + + + + + + + + + +
+ +
+ + +
+ + + + + diff --git a/MyCourse/web/WEB-INF/teacher/course_task.jsp b/MyCourse/web/WEB-INF/teacher/course_task.jsp new file mode 100644 index 0000000..d378457 --- /dev/null +++ b/MyCourse/web/WEB-INF/teacher/course_task.jsp @@ -0,0 +1,286 @@ + +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + User: Gao Tian + Date: 2019/6/27 + Time: 8:46 +--%> +<%@ page contentType="text/html;charset=UTF-8" %> + + + + ${teaCourse.name} + + + + + + + + + + + + + + +
+ + +
+ + + <%----%> + + +
+ +
+ +
+ +
+ ${teaTask.plainTextContent} +
+ + +
+ + + +
+
+ +
+ + + + + + + + diff --git a/MyCourse/web/WEB-INF/teacher/course_task_detail.jsp b/MyCourse/web/WEB-INF/teacher/course_task_detail.jsp new file mode 100644 index 0000000..11f8179 --- /dev/null +++ b/MyCourse/web/WEB-INF/teacher/course_task_detail.jsp @@ -0,0 +1,182 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + User: Gao Tian + Date: 2019/6/29 + Time: 13:05 +--%> +<%@ page contentType="text/html;charset=UTF-8" %> + + + + ${teaTask.title} + + + + + + + + + + + + + + + + + + +
+
+ +
+

${teaTask.title}

+ +
+
发布者
+
${teaTask.teacher.name}
+
更新时间
+
${teaTask.hUpdateTime}
+
截止时间
+
${teaTask.hDeadline}
+
+ +
+ +
+ ${teaTask.content} +
+ +
+
    + +
+
+
+ +
+

学生作业:

+

+ 总计:${allNum}     已交:${uploadNum}     未交:${allNum - uploadNum} +      + + 打包下载 + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
姓名email学号专业班级作业提交时间操作
${f.user.name}${f.user.email}${f.user.schoolId}${f.user.major}${f.user.schoolClass}${f.taskFile.fileName}${f.taskFile.hUploadTime}   
+ + + +
+ + + + + +
+ + diff --git a/MyCourse/web/WEB-INF/teacher/course_task_update.jsp b/MyCourse/web/WEB-INF/teacher/course_task_update.jsp new file mode 100644 index 0000000..dcf68a5 --- /dev/null +++ b/MyCourse/web/WEB-INF/teacher/course_task_update.jsp @@ -0,0 +1,227 @@ +<%-- + User: Gao Tian + Date: 2019/6/29 + Time: 13:05 +--%> +<%@ page contentType="text/html;charset=UTF-8" %> + + + + 修改-${teaTask.title} + + + + + + + + + + + + + + +
+ +
+ + + + + diff --git a/MyCourse/web/WEB-INF/teacher/courselist.jsp b/MyCourse/web/WEB-INF/teacher/courselist.jsp new file mode 100644 index 0000000..9b80514 --- /dev/null +++ b/MyCourse/web/WEB-INF/teacher/courselist.jsp @@ -0,0 +1,303 @@ +<%@ page import="java.util.List" %> +<%@ page import="java.util.ArrayList" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + User: Gao Tian + Date: 2019/6/25 + Time: 21:23 +--%> +<%@ page contentType="text/html;charset=UTF-8" %> + + + + 课程列表 + + + + + + + + + + + + + + + + +
+ +
+ + +
+ +
+ <% + List linears = new ArrayList<>(); + linears.add("background-image: linear-gradient(0deg,rgb(53,191,254) 0%,rgb(27,144,254) 100%)!important;"); + linears.add("background-image: linear-gradient(0deg,rgb(86,205,189) 0%,rgb(33,203,103) 100%)!important;"); + linears.add("background-image: linear-gradient(0deg,rgb(250,214,96) 0%,rgb(254,144,80) 100%)!important;"); + linears.add("background-image: linear-gradient(0deg,rgb(163,132,254) 0%,rgb(74,80,254) 100%)!important"); + linears.add("background-image: linear-gradient(0deg,rgb(254,127,172) 0%,rgb(249,93,85) 99%)!important;"); + linears.add("background-image: linear-gradient(0deg,rgb(69,213,211) 0%,rgb(4,173,184) 99%)!important;"); + request.setAttribute("linears", linears); + %> + + +
+
+ ${course.name}
+

 ${course.studentCount}名学生

+ +
+
+

近期作业

+ + ${t.title}
+
+
+ +
+ +
+
+ +
+ + + + + + + + + + diff --git a/MyCourse/web/WEB-INF/web.xml b/MyCourse/web/WEB-INF/web.xml new file mode 100644 index 0000000..96ca600 --- /dev/null +++ b/MyCourse/web/WEB-INF/web.xml @@ -0,0 +1,26 @@ + + + + + contextConfigLocation + classpath:applicationContext.xml + + + + org.springframework.web.context.ContextLoaderListener + + + + struts2 + org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter + + + struts2 + /* + + + + \ No newline at end of file diff --git a/MyCourse/web/image/404.png b/MyCourse/web/image/404.png new file mode 100644 index 0000000..8cf5c77 Binary files /dev/null and b/MyCourse/web/image/404.png differ diff --git a/MyCourse/web/image/img_code.jpg b/MyCourse/web/image/img_code.jpg new file mode 100644 index 0000000..1c7bf6f Binary files /dev/null and b/MyCourse/web/image/img_code.jpg differ diff --git a/MyCourse/web/image/login_bg.jpg b/MyCourse/web/image/login_bg.jpg new file mode 100644 index 0000000..f55d20b Binary files /dev/null and b/MyCourse/web/image/login_bg.jpg differ diff --git a/MyCourse/web/image/login_bg_bak.jpg b/MyCourse/web/image/login_bg_bak.jpg new file mode 100644 index 0000000..1b072fd Binary files /dev/null and b/MyCourse/web/image/login_bg_bak.jpg differ diff --git a/MyCourse/web/index.jsp b/MyCourse/web/index.jsp new file mode 100644 index 0000000..25c56d5 --- /dev/null +++ b/MyCourse/web/index.jsp @@ -0,0 +1,219 @@ +<%@ page contentType="text/html;charset=UTF-8" %> + + + + 登录 + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/MyCourse/web/lib/bootbox/bootbox.css b/MyCourse/web/lib/bootbox/bootbox.css new file mode 100644 index 0000000..bc82d65 --- /dev/null +++ b/MyCourse/web/lib/bootbox/bootbox.css @@ -0,0 +1,3 @@ +.bootbox.modal .modal-dialog { + width: 400px; + } diff --git a/MyCourse/web/lib/bootbox/bootbox.js b/MyCourse/web/lib/bootbox/bootbox.js new file mode 100644 index 0000000..af8a6ff --- /dev/null +++ b/MyCourse/web/lib/bootbox/bootbox.js @@ -0,0 +1,847 @@ +/* ======================================================================== + * Bootbox: bootbox.js [v4.4.0] + * http://bootboxjs.com/ + * + * ZUI: The file has been changed in ZUI. It will not keep update with the + * official version in the future. + * http://zui.sexy + * ======================================================================== + * http://bootboxjs.com/license.txt + * Improvement in ZUI: + * 1. Determine client language and apply setting automatically. + * 2. Changed button position. + * ======================================================================== */ + +/*! bootbox.js v4.4.0 http://bootboxjs.com/license.txt */ + +// @see https://github.com/makeusabrew/bootbox/issues/180 +// @see https://github.com/makeusabrew/bootbox/issues/186 +(function(root, factory) { + + 'use strict'; + if(typeof define === "function" && define.amd) { + // AMD. Register as an anonymous module. + define(["jquery"], factory); + } else if(typeof exports === "object") { + // Node. Does not work with strict CommonJS, but + // only CommonJS-like environments that support module.exports, + // like Node. + module.exports = factory(require("jquery")); + } else { + // Browser globals (root is window) + root.bootbox = factory(root.jQuery); + } + +}(this, function init($, undefined) { + + 'use strict'; + + // the base DOM structure needed to create a modal + var templates = { + dialog: "", + header: "", + footer: "", + closeButton: "", + form: "
", + inputs: { + text: "", + textarea: "", + email: "", + select: "", + checkbox: "
", + date: "", + time: "", + number: "", + password: "" + } + }; + + var defaults = { + // default language + locale: $.zui && $.zui.clientLang ? $.zui.clientLang() : 'zh_cn', + // show backdrop or not. Default to static so user has to interact with dialog + backdrop: "static", + // animate the modal in/out + animate: true, + // additional class string applied to the top level dialog + className: null, + // whether or not to include a close button + closeButton: true, + // show the dialog immediately by default + show: true, + // dialog container + container: "body" + }; + + // our public object; augmented after our private API + var exports = {}; + + /** + * @private + */ + function _t(key) { + var locale = locales[defaults.locale]; + return locale ? locale[key] : locales.en[key]; + } + + function processCallback(e, dialog, callback) { + e.stopPropagation(); + e.preventDefault(); + + // by default we assume a callback will get rid of the dialog, + // although it is given the opportunity to override this + + // so, if the callback can be invoked and it *explicitly returns false* + // then we'll set a flag to keep the dialog active... + var preserveDialog = $.isFunction(callback) && callback.call(dialog, e) === false; + + // ... otherwise we'll bin it + if(!preserveDialog) { + dialog.modal("hide"); + } + } + + function getKeyLength(obj) { + // @TODO defer to Object.keys(x).length if available? + var k, t = 0; + for(k in obj) { + t++; + } + return t; + } + + function each(collection, iterator) { + var index = 0; + $.each(collection, function(key, value) { + iterator(key, value, index++); + }); + } + + function sanitize(options) { + var buttons; + var total; + + if(typeof options !== "object") { + throw new Error("Please supply an object of options"); + } + + if(!options.message) { + throw new Error("Please specify a message"); + } + + // make sure any supplied options take precedence over defaults + options = $.extend({}, defaults, options); + + if(!options.buttons) { + options.buttons = {}; + } + + buttons = options.buttons; + + total = getKeyLength(buttons); + + each(buttons, function(key, button, index) { + + if($.isFunction(button)) { + // short form, assume value is our callback. Since button + // isn't an object it isn't a reference either so re-assign it + button = buttons[key] = { + callback: button + }; + } + + // before any further checks make sure by now button is the correct type + if($.type(button) !== "object") { + throw new Error("button with key " + key + " must be an object"); + } + + if(!button.label) { + // the lack of an explicit label means we'll assume the key is good enough + button.label = key; + } + + if(!button.className) { + if((total === 2 && (key === 'ok' || key === 'confirm')) || total === 1) { + // always add a primary to the main option in a two-button dialog + button.className = "btn-primary"; + } else { + button.className = "btn-default"; + } + } + }); + + return options; + } + + /** + * map a flexible set of arguments into a single returned object + * if args.length is already one just return it, otherwise + * use the properties argument to map the unnamed args to + * object properties + * so in the latter case: + * mapArguments(["foo", $.noop], ["message", "callback"]) + * -> { message: "foo", callback: $.noop } + */ + function mapArguments(args, properties) { + var argn = args.length; + var options = {}; + + if(argn < 1 || argn > 2) { + throw new Error("Invalid argument length"); + } + + if(argn === 2 || typeof args[0] === "string") { + options[properties[0]] = args[0]; + options[properties[1]] = args[1]; + } else { + options = args[0]; + } + + return options; + } + + /** + * merge a set of default dialog options with user supplied arguments + */ + function mergeArguments(defaults, args, properties) { + return $.extend( + // deep merge + true, + // ensure the target is an empty, unreferenced object + {}, + // the base options object for this type of dialog (often just buttons) + defaults, + // args could be an object or array; if it's an array properties will + // map it to a proper options object + mapArguments( + args, + properties + ) + ); + } + + /** + * this entry-level method makes heavy use of composition to take a simple + * range of inputs and return valid options suitable for passing to bootbox.dialog + */ + function mergeDialogOptions(className, labels, properties, args) { + // build up a base set of dialog properties + var baseOptions = { + className: "bootbox-" + className, + buttons: createLabels.apply(null, labels) + }; + + // ensure the buttons properties generated, *after* merging + // with user args are still valid against the supplied labels + return validateButtons( + // merge the generated base properties with user supplied arguments + mergeArguments( + baseOptions, + args, + // if args.length > 1, properties specify how each arg maps to an object key + properties + ), + labels + ); + } + + /** + * from a given list of arguments return a suitable object of button labels + * all this does is normalise the given labels and translate them where possible + * e.g. "ok", "confirm" -> { ok: "OK, cancel: "Annuleren" } + */ + function createLabels() { + var buttons = {}; + + for(var i = 0, j = arguments.length; i < j; i++) { + var argument = arguments[i]; + var key = argument.toLowerCase(); + var value = argument.toUpperCase(); + + buttons[key] = { + label: _t(value) + }; + } + + return buttons; + } + + function validateButtons(options, buttons) { + var allowedButtons = {}; + each(buttons, function(key, value) { + allowedButtons[value] = true; + }); + + each(options.buttons, function(key) { + if(allowedButtons[key] === undefined) { + throw new Error("button key " + key + " is not allowed (options are " + buttons.join("\n") + ")"); + } + }); + + return options; + } + + exports.alert = function() { + var options; + + options = mergeDialogOptions("alert", ["ok"], ["message", "callback"], arguments); + + if(options.callback && !$.isFunction(options.callback)) { + throw new Error("alert requires callback property to be a function when provided"); + } + + /** + * overrides + */ + options.buttons.ok.callback = options.onEscape = function() { + if($.isFunction(options.callback)) { + return options.callback.call(this); + } + return true; + }; + + return exports.dialog(options); + }; + + exports.confirm = function() { + var options; + + // ZUI change begin + options = mergeDialogOptions("confirm", ["confirm", "cancel"], ["message", "callback"], arguments); + // OLD WAY: options = mergeDialogOptions("confirm", ["cancel", "confirm"], ["message", "callback"], arguments); + // ZUI change end + + /** + * overrides; undo anything the user tried to set they shouldn't have + */ + options.buttons.cancel.callback = options.onEscape = function() { + return options.callback.call(this, false); + }; + + options.buttons.confirm.callback = function() { + return options.callback.call(this, true); + }; + + // confirm specific validation + if(!$.isFunction(options.callback)) { + throw new Error("confirm requires a callback"); + } + + return exports.dialog(options); + }; + + exports.prompt = function() { + var options; + var defaults; + var dialog; + var form; + var input; + var shouldShow; + var inputOptions; + + // we have to create our form first otherwise + // its value is undefined when gearing up our options + // @TODO this could be solved by allowing message to + // be a function instead... + form = $(templates.form); + + // prompt defaults are more complex than others in that + // users can override more defaults + // @TODO I don't like that prompt has to do a lot of heavy + // lifting which mergeDialogOptions can *almost* support already + // just because of 'value' and 'inputType' - can we refactor? + defaults = { + className: "bootbox-prompt", + buttons: createLabels("cancel", "confirm"), + value: "", + inputType: "text" + }; + + options = validateButtons( + // ZUI change begin + mergeArguments(defaults, arguments, ["title", "callback"]), ["confirm", "cancel"] + // OLD WAY: mergeArguments(defaults, arguments, ["title", "callback"]), ["cancel", "confirm"]arguments); + // ZUI change end + ); + + // capture the user's show value; we always set this to false before + // spawning the dialog to give us a chance to attach some handlers to + // it, but we need to make sure we respect a preference not to show it + shouldShow = (options.show === undefined) ? true : options.show; + + /** + * overrides; undo anything the user tried to set they shouldn't have + */ + options.message = form; + + options.buttons.cancel.callback = options.onEscape = function() { + return options.callback.call(this, null); + }; + + options.buttons.confirm.callback = function() { + var value; + + switch(options.inputType) { + case "text": + case "textarea": + case "email": + case "select": + case "date": + case "time": + case "number": + case "password": + value = input.val(); + break; + + case "checkbox": + var checkedItems = input.find("input:checked"); + + // we assume that checkboxes are always multiple, + // hence we default to an empty array + value = []; + + each(checkedItems, function(_, item) { + value.push($(item).val()); + }); + break; + } + + return options.callback.call(this, value); + }; + + options.show = false; + + // prompt specific validation + if(!options.title) { + throw new Error("prompt requires a title"); + } + + if(!$.isFunction(options.callback)) { + throw new Error("prompt requires a callback"); + } + + if(!templates.inputs[options.inputType]) { + throw new Error("invalid prompt type"); + } + + // create the input based on the supplied type + input = $(templates.inputs[options.inputType]); + + switch(options.inputType) { + case "text": + case "textarea": + case "email": + case "date": + case "time": + case "number": + case "password": + input.val(options.value); + break; + + case "select": + var groups = {}; + inputOptions = options.inputOptions || []; + + if(!$.isArray(inputOptions)) { + throw new Error("Please pass an array of input options"); + } + + if(!inputOptions.length) { + throw new Error("prompt with select requires options"); + } + + each(inputOptions, function(_, option) { + + // assume the element to attach to is the input... + var elem = input; + + if(option.value === undefined || option.text === undefined) { + throw new Error("given options in wrong format"); + } + + // ... but override that element if this option sits in a group + + if(option.group) { + // initialise group if necessary + if(!groups[option.group]) { + groups[option.group] = $("").attr("label", option.group); + } + + elem = groups[option.group]; + } + + elem.append(""); + }); + + each(groups, function(_, group) { + input.append(group); + }); + + // safe to set a select's value as per a normal input + input.val(options.value); + break; + + case "checkbox": + var values = $.isArray(options.value) ? options.value : [options.value]; + inputOptions = options.inputOptions || []; + + if(!inputOptions.length) { + throw new Error("prompt with checkbox requires options"); + } + + if(!inputOptions[0].value || !inputOptions[0].text) { + throw new Error("given options in wrong format"); + } + + // checkboxes have to nest within a containing element, so + // they break the rules a bit and we end up re-assigning + // our 'input' element to this container instead + input = $("
"); + + each(inputOptions, function(_, option) { + var checkbox = $(templates.inputs[options.inputType]); + + checkbox.find("input").attr("value", option.value); + checkbox.find("label").append(option.text); + + // we've ensured values is an array so we can always iterate over it + each(values, function(_, value) { + if(value === option.value) { + checkbox.find("input").prop("checked", true); + } + }); + + input.append(checkbox); + }); + break; + } + + // @TODO provide an attributes option instead + // and simply map that as keys: vals + if(options.placeholder) { + input.attr("placeholder", options.placeholder); + } + + if(options.pattern) { + input.attr("pattern", options.pattern); + } + + if(options.maxlength) { + input.attr("maxlength", options.maxlength); + } + + // now place it in our form + form.append(input); + + form.on("submit", function(e) { + e.preventDefault(); + // Fix for SammyJS (or similar JS routing library) hijacking the form post. + e.stopPropagation(); + // @TODO can we actually click *the* button object instead? + // e.g. buttons.confirm.click() or similar + dialog.find(".btn-primary").click(); + }); + + dialog = exports.dialog(options); + + // clear the existing handler focusing the submit button... + dialog.off("shown.zui.modal"); + + // ...and replace it with one focusing our input, if possible + dialog.on("shown.zui.modal", function() { + // need the closure here since input isn't + // an object otherwise + input.focus(); + }); + + if(shouldShow === true) { + dialog.modal("show"); + } + + return dialog; + }; + + exports.dialog = function(options) { + options = sanitize(options); + + + var dialog = $(templates.dialog); + var innerDialog = dialog.find(".modal-dialog"); + var body = dialog.find(".modal-body"); + var buttons = options.buttons; + var buttonStr = ""; + var callbacks = { + onEscape: options.onEscape + }; + + if($.fn.modal === undefined) { + throw new Error( + "$.fn.modal is not defined; please double check you have included " + + "the Bootstrap JavaScript library. See http://getbootstrap.com/javascript/ " + + "for more details." + ); + } + + each(buttons, function(key, button) { + + // @TODO I don't like this string appending to itself; bit dirty. Needs reworking + // can we just build up button elements instead? slower but neater. Then button + // can just become a template too + buttonStr += ""; + callbacks[key] = button.callback; + }); + + body.find(".bootbox-body").html(options.message); + + if(options.animate === true) { + dialog.addClass("fade"); + } + + if(options.className) { + dialog.addClass(options.className); + } + + if(options.size === "large") { + innerDialog.addClass("modal-lg"); + } else if(options.size === "small") { + innerDialog.addClass("modal-sm"); + } + + if(options.title) { + body.before(templates.header); + } + + if(options.closeButton) { + var closeButton = $(templates.closeButton); + + if(options.title) { + dialog.find(".modal-header").prepend(closeButton); + } else { + closeButton.css("margin-top", "-10px").prependTo(body); + } + } + + if(options.title) { + dialog.find(".modal-title").html(options.title); + } + + if(buttonStr.length) { + body.after(templates.footer); + dialog.find(".modal-footer").html(buttonStr); + } + + + /** + * Bootstrap event listeners; used handle extra + * setup & teardown required after the underlying + * modal has performed certain actions + */ + + dialog.on("hidden.zui.modal", function(e) { + // ensure we don't accidentally intercept hidden events triggered + // by children of the current dialog. We shouldn't anymore now BS + // namespaces its events; but still worth doing + if(e.target === this) { + dialog.remove(); + } + }); + + /* + dialog.on("show.zui.modal", function() { + // sadly this doesn't work; show is called *just* before + // the backdrop is added so we'd need a setTimeout hack or + // otherwise... leaving in as would be nice + if (options.backdrop) { + dialog.next(".modal-backdrop").addClass("bootbox-backdrop"); + } + }); + */ + + dialog.on("shown.zui.modal", function() { + dialog.find(".btn-primary:first").focus(); + }); + + /** + * Bootbox event listeners; experimental and may not last + * just an attempt to decouple some behaviours from their + * respective triggers + */ + + if(options.backdrop !== "static") { + // A boolean true/false according to the Bootstrap docs + // should show a dialog the user can dismiss by clicking on + // the background. + // We always only ever pass static/false to the actual + // $.modal function because with `true` we can't trap + // this event (the .modal-backdrop swallows it) + // However, we still want to sort of respect true + // and invoke the escape mechanism instead + dialog.on("click.dismiss.zui.modal", function(e) { + // @NOTE: the target varies in >= 3.3.x releases since the modal backdrop + // moved *inside* the outer dialog rather than *alongside* it + if(dialog.children(".modal-backdrop").length) { + e.currentTarget = dialog.children(".modal-backdrop").get(0); + } + + if(e.target !== e.currentTarget) { + return; + } + + dialog.trigger("escape.close.bb"); + }); + } + + dialog.on("escape.close.bb", function(e) { + if(callbacks.onEscape) { + processCallback(e, dialog, callbacks.onEscape); + } + }); + + /** + * Standard jQuery event listeners; used to handle user + * interaction with our dialog + */ + + dialog.on("click", ".modal-footer button", function(e) { + var callbackKey = $(this).data("bb-handler"); + + processCallback(e, dialog, callbacks[callbackKey]); + }); + + dialog.on("click", ".bootbox-close-button", function(e) { + // onEscape might be falsy but that's fine; the fact is + // if the user has managed to click the close button we + // have to close the dialog, callback or not + processCallback(e, dialog, callbacks.onEscape); + }); + + dialog.on("keyup", function(e) { + if(e.which === 27) { + dialog.trigger("escape.close.bb"); + } + }); + + // the remainder of this method simply deals with adding our + // dialogent to the DOM, augmenting it with Bootstrap's modal + // functionality and then giving the resulting object back + // to our caller + + $(options.container).append(dialog); + + dialog.modal({ + backdrop: options.backdrop ? "static" : false, + keyboard: false, + show: false + }); + + if(options.show) { + dialog.modal("show"); + } + + // @TODO should we return the raw element here or should + // we wrap it in an object on which we can expose some neater + // methods, e.g. var d = bootbox.alert(); d.hide(); instead + // of d.modal("hide"); + + /* + function BBDialog(elem) { + this.elem = elem; + } + + BBDialog.prototype = { + hide: function() { + return this.elem.modal("hide"); + }, + show: function() { + return this.elem.modal("show"); + } + }; + */ + + return dialog; + + }; + + exports.setDefaults = function() { + var values = {}; + + if(arguments.length === 2) { + // allow passing of single key/value... + values[arguments[0]] = arguments[1]; + } else { + // ... and as an object too + values = arguments[0]; + } + + $.extend(defaults, values); + }; + + exports.hideAll = function() { + $(".bootbox").modal("hide"); + + return exports; + }; + + + /** + * standard locales. Please add more according to ISO 639-1 standard. Multiple language variants are + * unlikely to be required. If this gets too large it can be split out into separate JS files. + */ + var locales = { + en: { + OK: "OK", + CANCEL: "Cancel", + CONFIRM: "OK" + }, + zh_cn: { + OK: "确认", + CANCEL: "取消", + CONFIRM: "确认" + }, + zh_tw: { + OK: "確認", + CANCEL: "取消", + CONFIRM: "確認" + } + }; + + exports.addLocale = function(name, values) { + $.each(["OK", "CANCEL", "CONFIRM"], function(_, v) { + if(!values[v]) { + throw new Error("Please supply a translation for '" + v + "'"); + } + }); + + locales[name] = { + OK: values.OK, + CANCEL: values.CANCEL, + CONFIRM: values.CONFIRM + }; + + return exports; + }; + + exports.removeLocale = function(name) { + delete locales[name]; + + return exports; + }; + + exports.setLocale = function(name) { + return exports.setDefaults("locale", name); + }; + + exports.init = function(_$) { + return init(_$ || $); + }; + + return exports; +})); diff --git a/MyCourse/web/lib/bootbox/bootbox.min.css b/MyCourse/web/lib/bootbox/bootbox.min.css new file mode 100644 index 0000000..4483c69 --- /dev/null +++ b/MyCourse/web/lib/bootbox/bootbox.min.css @@ -0,0 +1 @@ +.bootbox.modal .modal-dialog{width:400px} \ No newline at end of file diff --git a/MyCourse/web/lib/bootbox/bootbox.min.js b/MyCourse/web/lib/bootbox/bootbox.min.js new file mode 100644 index 0000000..c392995 --- /dev/null +++ b/MyCourse/web/lib/bootbox/bootbox.min.js @@ -0,0 +1,2 @@ +/*! bootbox.js v4.4.0 http://bootboxjs.com/license.txt */ +!function(t,o){"use strict";"function"==typeof define&&define.amd?define(["jquery"],o):"object"==typeof exports?module.exports=o(require("jquery")):t.bootbox=o(t.jQuery)}(this,function t(o,e){"use strict";function a(t){var o=h[f.locale];return o?o[t]:h.en[t]}function n(t,e,a){t.stopPropagation(),t.preventDefault();var n=o.isFunction(a)&&a.call(e,t)===!1;n||e.modal("hide")}function r(t){var o,e=0;for(o in t)e++;return e}function i(t,e){var a=0;o.each(t,function(t,o){e(t,o,a++)})}function c(t){var e,a;if("object"!=typeof t)throw new Error("Please supply an object of options");if(!t.message)throw new Error("Please specify a message");return t=o.extend({},f,t),t.buttons||(t.buttons={}),e=t.buttons,a=r(e),i(e,function(t,n,r){if(o.isFunction(n)&&(n=e[t]={callback:n}),"object"!==o.type(n))throw new Error("button with key "+t+" must be an object");n.label||(n.label=t),n.className||(2===a&&("ok"===t||"confirm"===t)||1===a?n.className="btn-primary":n.className="btn-default")}),t}function l(t,o){var e=t.length,a={};if(e<1||e>2)throw new Error("Invalid argument length");return 2===e||"string"==typeof t[0]?(a[o[0]]=t[0],a[o[1]]=t[1]):a=t[0],a}function s(t,e,a){return o.extend(!0,{},t,l(e,a))}function u(t,o,e,a){var n={className:"bootbox-"+t,buttons:p.apply(null,o)};return b(s(n,a,e),o)}function p(){for(var t={},o=0,e=arguments.length;o
",header:"",footer:"",closeButton:"",form:"
",inputs:{text:"",textarea:"",email:"",select:"",checkbox:"
",date:"",time:"",number:"",password:""}},f={locale:o.zui&&o.zui.clientLang?o.zui.clientLang():"zh_cn",backdrop:"static",animate:!0,className:null,closeButton:!0,show:!0,container:"body"},m={};m.alert=function(){var t;if(t=u("alert",["ok"],["message","callback"],arguments),t.callback&&!o.isFunction(t.callback))throw new Error("alert requires callback property to be a function when provided");return t.buttons.ok.callback=t.onEscape=function(){return!o.isFunction(t.callback)||t.callback.call(this)},m.dialog(t)},m.confirm=function(){var t;if(t=u("confirm",["confirm","cancel"],["message","callback"],arguments),t.buttons.cancel.callback=t.onEscape=function(){return t.callback.call(this,!1)},t.buttons.confirm.callback=function(){return t.callback.call(this,!0)},!o.isFunction(t.callback))throw new Error("confirm requires a callback");return m.dialog(t)},m.prompt=function(){var t,a,n,r,c,l,u;if(r=o(d.form),a={className:"bootbox-prompt",buttons:p("cancel","confirm"),value:"",inputType:"text"},t=b(s(a,arguments,["title","callback"]),["confirm","cancel"]),l=t.show===e||t.show,t.message=r,t.buttons.cancel.callback=t.onEscape=function(){return t.callback.call(this,null)},t.buttons.confirm.callback=function(){var e;switch(t.inputType){case"text":case"textarea":case"email":case"select":case"date":case"time":case"number":case"password":e=c.val();break;case"checkbox":var a=c.find("input:checked");e=[],i(a,function(t,a){e.push(o(a).val())})}return t.callback.call(this,e)},t.show=!1,!t.title)throw new Error("prompt requires a title");if(!o.isFunction(t.callback))throw new Error("prompt requires a callback");if(!d.inputs[t.inputType])throw new Error("invalid prompt type");switch(c=o(d.inputs[t.inputType]),t.inputType){case"text":case"textarea":case"email":case"date":case"time":case"number":case"password":c.val(t.value);break;case"select":var f={};if(u=t.inputOptions||[],!o.isArray(u))throw new Error("Please pass an array of input options");if(!u.length)throw new Error("prompt with select requires options");i(u,function(t,a){var n=c;if(a.value===e||a.text===e)throw new Error("given options in wrong format");a.group&&(f[a.group]||(f[a.group]=o("").attr("label",a.group)),n=f[a.group]),n.append("")}),i(f,function(t,o){c.append(o)}),c.val(t.value);break;case"checkbox":var h=o.isArray(t.value)?t.value:[t.value];if(u=t.inputOptions||[],!u.length)throw new Error("prompt with checkbox requires options");if(!u[0].value||!u[0].text)throw new Error("given options in wrong format");c=o("
"),i(u,function(e,a){var n=o(d.inputs[t.inputType]);n.find("input").attr("value",a.value),n.find("label").append(a.text),i(h,function(t,o){o===a.value&&n.find("input").prop("checked",!0)}),c.append(n)})}return t.placeholder&&c.attr("placeholder",t.placeholder),t.pattern&&c.attr("pattern",t.pattern),t.maxlength&&c.attr("maxlength",t.maxlength),r.append(c),r.on("submit",function(t){t.preventDefault(),t.stopPropagation(),n.find(".btn-primary").click()}),n=m.dialog(t),n.off("shown.zui.modal"),n.on("shown.zui.modal",function(){c.focus()}),l===!0&&n.modal("show"),n},m.dialog=function(t){t=c(t);var a=o(d.dialog),r=a.find(".modal-dialog"),l=a.find(".modal-body"),s=t.buttons,u="",p={onEscape:t.onEscape};if(o.fn.modal===e)throw new Error("$.fn.modal is not defined; please double check you have included the Bootstrap JavaScript library. See http://getbootstrap.com/javascript/ for more details.");if(i(s,function(t,o){u+="",p[t]=o.callback}),l.find(".bootbox-body").html(t.message),t.animate===!0&&a.addClass("fade"),t.className&&a.addClass(t.className),"large"===t.size?r.addClass("modal-lg"):"small"===t.size&&r.addClass("modal-sm"),t.title&&l.before(d.header),t.closeButton){var b=o(d.closeButton);t.title?a.find(".modal-header").prepend(b):b.css("margin-top","-10px").prependTo(l)}return t.title&&a.find(".modal-title").html(t.title),u.length&&(l.after(d.footer),a.find(".modal-footer").html(u)),a.on("hidden.zui.modal",function(t){t.target===this&&a.remove()}),a.on("shown.zui.modal",function(){a.find(".btn-primary:first").focus()}),"static"!==t.backdrop&&a.on("click.dismiss.zui.modal",function(t){a.children(".modal-backdrop").length&&(t.currentTarget=a.children(".modal-backdrop").get(0)),t.target===t.currentTarget&&a.trigger("escape.close.bb")}),a.on("escape.close.bb",function(t){p.onEscape&&n(t,a,p.onEscape)}),a.on("click",".modal-footer button",function(t){var e=o(this).data("bb-handler");n(t,a,p[e])}),a.on("click",".bootbox-close-button",function(t){n(t,a,p.onEscape)}),a.on("keyup",function(t){27===t.which&&a.trigger("escape.close.bb")}),o(t.container).append(a),a.modal({backdrop:!!t.backdrop&&"static",keyboard:!1,show:!1}),t.show&&a.modal("show"),a},m.setDefaults=function(){var t={};2===arguments.length?t[arguments[0]]=arguments[1]:t=arguments[0],o.extend(f,t)},m.hideAll=function(){return o(".bootbox").modal("hide"),m};var h={en:{OK:"OK",CANCEL:"Cancel",CONFIRM:"OK"},zh_cn:{OK:"确认",CANCEL:"取消",CONFIRM:"确认"},zh_tw:{OK:"確認",CANCEL:"取消",CONFIRM:"確認"}};return m.addLocale=function(t,e){return o.each(["OK","CANCEL","CONFIRM"],function(t,o){if(!e[o])throw new Error("Please supply a translation for '"+o+"'")}),h[t]={OK:e.OK,CANCEL:e.CANCEL,CONFIRM:e.CONFIRM},m},m.removeLocale=function(t){return delete h[t],m},m.setLocale=function(t){return m.setDefaults("locale",t)},m.init=function(e){return t(e||o)},m}); \ No newline at end of file diff --git a/MyCourse/web/lib/datatable/zui.datatable.css b/MyCourse/web/lib/datatable/zui.datatable.css new file mode 100644 index 0000000..45d3670 --- /dev/null +++ b/MyCourse/web/lib/datatable/zui.datatable.css @@ -0,0 +1,200 @@ +/*! + * ZUI: 数据表格 - v1.9.1 - 2019-05-10 + * http://zui.sexy + * GitHub: https://github.com/easysoft/zui.git + * Copyright (c) 2019 cnezsoft.com; Licensed MIT + */ + +.datatable-head, +.datatable-rows { + display: table; + width: 100%; + table-layout: fixed; + } +.datatable { + margin-bottom: 20px; + } +.datatable > .datatable-head { + -webkit-transition: -webkit-box-shadow .2s; + -o-transition: box-shadow .2s; + transition: -webkit-box-shadow .2s; + transition: box-shadow .2s; + transition: box-shadow .2s, -webkit-box-shadow .2s; + } +.datatable .table { + margin: 0; + table-layout: fixed; + } +.datatable .table > tbody > tr > td, +.datatable .table > thead > tr > th { + min-width: 20px; + } +.datatable .table > tbody > tr > td.check-btn, +.datatable .table > thead > tr > th.check-btn { + width: 30px; + color: #9b9b9b; + text-align: center; + cursor: pointer; + } +.datatable .table > tbody > tr.hover > td.check-btn, +.datatable .table > tbody > tr.active > td.check-btn, +.datatable .table > thead > tr > th.check-btn:hover, +.datatable .table > tbody > tr > td.check-btn:hover, +.datatable .table > thead > tr > th.check-btn.checked, +.datatable .table > tbody > tr > td.check-btn.checked { + color: #4f4f4f; + } +.datatable .table > thead > tr > th.check-btn.checked > .icon-check-empty:before, +.datatable .table > tbody > tr > td.check-btn.checked > .icon-check-empty:before, +.datatable .table > tbody > tr.active > td.check-btn > .icon-check-empty:before { + content: '\e642'; + } +.datatable .table > thead > tr > th.col-hover { + background-color: #e2e2e2; + } +.datatable .table > tbody > tr > td.col-hover, +.datatable .table > tbody > tr.hover > td { + background-color: #ebf2f9; + } +.datatable .table > tbody > tr.active.hover td { + background-color: #ffdea2; + } +.datatable.head-fixed > .datatable-head { + position: fixed; + z-index: 1030; + -webkit-box-shadow: 0 1px 4px 0 rgba(0, 0, 0, .15); + box-shadow: 0 1px 4px 0 rgba(0, 0, 0, .15); + } +.datatable.sortable .datatable-head-span .table > thead > tr > th { + overflow: hidden; + white-space: nowrap; + cursor: pointer; + } +.datatable.sortable .datatable-head-span .table > thead > tr > th.text-center { + padding-right: 0; + padding-left: 0; + } +.datatable.sortable .datatable-head-span .table > thead > tr > th:after { + display: inline-block; + margin-left: 5px; + font-family: ZenIcon; + font-size: 14px; + font-style: normal; + font-weight: normal; + font-variant: normal; + line-height: 1; + color: #808080; + text-transform: none; + content: '\e6bd'; + + speak: none; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + } +.datatable.sortable .datatable-head-span .table > thead > tr > th.sort-down:after { + color: #145ccd; + content: '\e6b8'; + } +.datatable.sortable .datatable-head-span .table > thead > tr > th.sort-up:after { + color: #145ccd; + content: '\e6b9'; + } +.datatable.sortable .datatable-head-span .table > thead > tr > th.check-btn:after, +.datatable.sortable .datatable-head-span .table > thead > tr > th.sort-disabled:after { + display: none; + } +.datatable.sortable .datatable-head-span .table > thead > tr > th.sort-disabled { + cursor: default; + } +.datatable-wrapper { + position: relative; + } +.datatable-span { + display: table-cell; + vertical-align: top; + } +.datatable-span.flexarea { + overflow: hidden; + } +.datatable-span.flexarea.datatable-head-span.dragging { + cursor: move !important; + } +.datatable-span.flexarea .table { + position: relative; + top: 0; + left: 0; + } +.datatable-span.flexarea .scrolled-shadow { + position: absolute; + top: 0; + bottom: 0; + display: none; + width: 20px; + -webkit-box-shadow: 0 0 10px rgba(0, 0, 0, .15); + box-shadow: 0 0 10px rgba(0, 0, 0, .15); + opacity: 0; + -webkit-transition: all .4s cubic-bezier(.175, .885, .32, 1); + -o-transition: all .4s cubic-bezier(.175, .885, .32, 1); + transition: all .4s cubic-bezier(.175, .885, .32, 1); + } +.datatable-span.flexarea .scrolled-in-shadow { + left: -30px; + } +.datatable-span.flexarea .scrolled-out-shadow { + right: -30px; + } +.datatable > .scroll-wrapper { + position: relative; + width: 100%; + } +.datatable .scroll-slide { + position: absolute; + right: -1px; + bottom: 0; + left: -1px; + display: none; + height: 11px; + background: #e5e5e5; + background: rgba(128, 128, 128, .1); + border: 1px solid #e5e5e5; + border-bottom: none; + opacity: 0; + -webkit-transition: opacity .5s, background .3s; + -o-transition: opacity .5s, background .3s; + transition: opacity .5s, background .3s; + } +.datatable .scroll-slide > .bar { + position: absolute; + top: 0; + left: 0; + min-width: 50px; + height: 10px; + cursor: move; + background-color: #a6a6a6; + } +.datatable .scroll-slide:hover > .bar { + background-color: #808080; + } +.datatable .scroll-slide.scroll-pos-out { + bottom: -14px; + height: 15px; + } +.datatable .scroll-slide.scroll-pos-out > .bar { + height: 14px; + } +.datatable.show-scroll-slide:hover .scroll-slide, +.datatable.show-scroll-slide.scrolling .scroll-slide, +.datatable.show-scroll-slide:hover .scrolled-shadow, +.datatable.show-scroll-slide.scrolling .scrolled-shadow { + opacity: 1; + } +.datatable.show-scroll-slide .scroll-slide, +.datatable.show-scroll-slide .scrolled-shadow { + display: block; + } +.datatable.show-scroll-slide.scrolled-in .scrolled-in-shadow { + left: -20px; + } +.datatable.show-scroll-slide.scrolled-out .scrolled-out-shadow { + right: -20px; + } diff --git a/MyCourse/web/lib/datatable/zui.datatable.js b/MyCourse/web/lib/datatable/zui.datatable.js new file mode 100644 index 0000000..1b3a358 --- /dev/null +++ b/MyCourse/web/lib/datatable/zui.datatable.js @@ -0,0 +1,947 @@ +/*! + * ZUI: 数据表格 - v1.9.1 - 2019-05-10 + * http://zui.sexy + * GitHub: https://github.com/easysoft/zui.git + * Copyright (c) 2019 cnezsoft.com; Licensed MIT + */ + +/* ======================================================================== + * ZUI: datatable.js + * http://zui.sexy + * ======================================================================== + * Copyright (c) 2014-2016 cnezsoft.com; Licensed MIT + * ======================================================================== */ +(function($) { + 'use strict'; + + var name = 'zui.datatable'; + var store = $.zui.store; + + /** + * Datatable class + * + * @param object element DOM element or jquery element + * @param object options Datatable options + */ + var DataTable = function(element, options) { + this.name = name; + this.$ = $(element); + this.isTable = (this.$[0].tagName === 'TABLE'); + this.firstShow = true; + if(this.isTable) { + this.$table = this.$; + this.id = 'datatable-' + (this.$.attr('id') || $.zui.uuid()); + } else { + this.$datatable = this.$.addClass('datatable'); + if(this.$.attr('id')) { + this.id = this.$.attr('id'); + } else { + this.id = 'datatable-' + $.zui.uuid(); + this.$.attr('id', this.id); + } + } + this.getOptions(options); + this.load(); + + this.callEvent('ready'); + }; + + // default options + DataTable.DEFAULTS = { + // Check options + checkable: false, // added check icon to the head of rows + checkByClickRow: true, // change check status by click anywhere on a row + checkedClass: 'active', // apply CSS class to an checked row + checkboxName: null, + selectable: true, + + // Sort options + sortable: false, // enable sorter + + // storage + storage: true, // enable storage + + // fixed header of columns + fixedHeader: false, // fixed header + fixedHeaderOffset: 0, // set top offset of header when fixed + fixedLeftWidth: '30%', // set left width after first render + fixedRightWidth: '30%', // set right width after first render + flexHeadDrag: true, // scroll flexarea by drag header + scrollPos: 'in', // scroll bar position: 'out' | 'in' + + // hover effection + rowHover: true, // apply hover effection to row + colHover: true, // apply hover effection to head + hoverClass: 'hover', + colHoverClass: 'col-hover', + + + // Fix cell height + fixCellHeight: true, + + // Merge rows + mergeRows: false, // Merge rows + + // custom columns size + // customizable: false, // enable customizable + minColWidth: 20, // min width of columns + minFixedLeftWidth: 200, // min left width + minFixedRightWidth: 200, // min right width + minFlexAreaWidth: 200 // min flexarea width + }; + + // Get options + DataTable.prototype.getOptions = function(options) { + var $e = this.$; + options = $.extend({}, DataTable.DEFAULTS, this.$.data(), options); + + options.tableClass = options.tableClass || ''; + options.tableClass = ' ' + options.tableClass + ' table-datatable'; + + $.each(['bordered', 'condensed', 'striped', 'condensed', 'fixed'], function(idx, cls) { + cls = 'table-' + cls; + if($e.hasClass(cls)) options.tableClass += ' ' + cls; + }); + + if($e.hasClass('table-hover') || options.rowHover) { + options.tableClass += ' table-hover'; + } + + if(!options.checkable || !$.fn.selectable) options.selectable = false; + + this.options = options; + }; + + // Load data form options or table dom + DataTable.prototype.load = function(data) { + var options = this.options, + cols; + + if($.isFunction(data)) { + data = data(this.data, this); + data.keepSort = true; + } else if($.isPlainObject(data)) { + this.data = data; + } else if(typeof data === 'string') { + var $table = $(data); + if($table.length) { + this.$table = $table.first(); + this.$table.data(name, this); + this.isTable = true; + } + data = null; + } else { + data = options.data; + } + + if(!data) { + if(this.isTable) { + data = { + cols: [], + rows: [] + }; + cols = data.cols; + var rows = data.rows, + i, + $th, $tr, $td, row, $t = this.$table, + colSpan; + + $t.children('thead').children('tr:first').children('th').each(function() { + $th = $(this); + cols.push($.extend({ + text: $th.html(), + flex: false || $th.hasClass('flex-col'), + width: 'auto', + cssClass: $th.attr('class'), + css: $th.attr('style'), + type: 'string', + ignore: $th.hasClass('ignore'), + sort: !$th.hasClass('sort-disabled'), + mergeRows: $th.attr('merge-rows'), + title: $th.attr('title') + }, $th.data())); + }); + + $t.children('tbody').children('tr').each(function() { + $tr = $(this); + row = $.extend({ + data: [], + checked: false, + cssClass: $tr.attr('class'), + css: $tr.attr('style'), + id: $tr.attr('id') + }, $tr.data()); + + $tr.children('td').each(function() { + $td = $(this); + colSpan = $td.attr('colspan') || 1; + row.data.push($.extend({ + cssClass: $td.attr('class'), + css: $td.attr('style'), + text: $td.html(), + colSpan: colSpan, + title: $td.attr('title') + }, $td.data())); + + if(colSpan > 1) { + for(i = 1; i < colSpan; i++) { + row.data.push({ + empty: true + }); + } + } + }); + + rows.push(row); + }); + + var $tfoot = $t.children('tfoot'); + if($tfoot.length) { + data.footer = $('
').append($tfoot); + } + } else { + throw new Error('No data avaliable!'); + } + } + + data.flexStart = -1; + data.flexEnd = -1; + + cols = data.cols; + data.colsLength = cols.length; + for(var i = 0; i < data.colsLength; ++i) { + var col = cols[i]; + if(col.flex) { + if(data.flexStart < 0) { + data.flexStart = i; + } + + data.flexEnd = i; + } + } + + if(data.flexStart === 0 && data.flexEnd === data.colsLength) { + data.flexStart = -1; + data.flexEnd = -1; + } + + data.flexArea = data.flexStart >= 0; + data.fixedRight = data.flexEnd >= 0 && data.flexEnd < (data.colsLength - 1); + data.fixedLeft = data.flexStart > 0; + if(data.flexStart < 0 && data.flexEnd < 0) { + data.fixedLeft = true; + data.flexStart = data.colsLength; + data.flexEnd = data.colsLength; + } + + this.data = data; + + this.callEvent('afterLoad', { + data: data + }); + + this.render(); + }; + + // Render datatable + DataTable.prototype.render = function() { + var that = this; + var $datatable = that.$datatable || (that.isTable ? $('
') : that.$datatable), + options = that.options, + data = that.data, + cols = that.data.cols, + rows = that.data.rows; + var checkable = options.checkable, + $left, + i, + $right, + $flex, + dataRowSpan = '
', + dataHeadSpan = '
'; + + $datatable.children('.datatable-head, .datatable-rows, .scroll-wrapper').remove(); + + // Set css class to datatable by options + $datatable.toggleClass('sortable', options.sortable); + // $datatable.toggleClass('customizable', options.customizable); + + // Head + var $head = $('
'), + $tr, + $th, + col; + $left = $(''); + $right = $(''); + $flex = $(''); + for(i = 0; i < cols.length; i++) { + col = cols[i]; + $tr = i < data.flexStart ? $left : ((i >= data.flexStart && i <= data.flexEnd) ? $flex : $right); + if(i === 0 && checkable) { + $tr.append(''); + } + if(col.ignore) continue; + + $th = $(''); + + // set sort class + $th.toggleClass('sort-down', col.sort === 'down') + .toggleClass('sort-up', col.sort === 'up') + .toggleClass('sort-disabled', col.sort === false); + + $th.addClass(col.cssClass) + .addClass(col.colClass) + .html(col.text) + .attr({ + 'data-index': i, + 'data-type': col.type, + style: col.css, + title: col.title, + }).css('width', col.width); + $tr.append($th); + } + + var $headSpan; + if(data.fixedLeft) { + $headSpan = $(dataHeadSpan); + $headSpan.addClass('fixed-left') + // .find('.datatable-wrapper') + // .append('
') + .find('table') + .addClass(options.tableClass) + .find('thead').append($left); + $head.append($headSpan); + } + if(data.flexArea) { + $headSpan = $(dataHeadSpan); + $headSpan.addClass('flexarea') + .find('.datatable-wrapper') + .append('
') + .find('table') + .addClass(options.tableClass) + .find('thead').append($flex); + $head.append($headSpan); + } + if(data.fixedRight) { + $headSpan = $(dataHeadSpan); + $headSpan.addClass('fixed-right') + // .find('.datatable-wrapper') + // .append('
') + .find('table') + .addClass(options.tableClass) + .find('thead').append($right); + $head.append($headSpan); + } + $datatable.append($head); + + // Rows + var $rows = $('
'); + var $leftRow, + $flexRow, + $rightRow, + // $tr, + $td, + $cTd, + row, + rowLen = rows.length, + rowCol, + rowColLen; + $left = $(''); + $right = $(''); + $flex = $(''); + + for(var r = 0; r < rowLen; ++r) { + row = rows[r]; + + // format row + if(typeof row.id === 'undefined') { + row.id = r; + } + row.index = r; + + $leftRow = $(''); + $leftRow.addClass(row.cssClass) + .toggleClass(options.checkedClass, !!row.checked) + .attr({ + 'data-index': r, + 'data-id': row.id + }); + $flexRow = $leftRow.clone().addClass('datatable-row-flex'); + $rightRow = $leftRow.clone().addClass('datatable-row-right'); + $leftRow.addClass('datatable-row-left'); + + rowColLen = row.data.length; + for(i = 0; i < rowColLen; ++i) { + rowCol = row.data[i]; + if(i > 0 && rowCol.empty) { + continue; + } + + $tr = i < data.flexStart ? $leftRow : ((i >= data.flexStart && i <= data.flexEnd) ? $flexRow : $rightRow); + if(i === 0 && checkable) { + $cTd = $(''); + if(options.checkboxName) { + $cTd.append(''); + } + $tr.append($cTd); + } + + if(cols[i].ignore) continue; + + // format row column + if(!$.isPlainObject(rowCol)) { + rowCol = { + text: rowCol, + row: r, + index: i + }; + } else { + rowCol.row = r; + rowCol.index = i; + } + row.data[i] = rowCol; + + $td = $(''); + + $td.html(rowCol.text) + .addClass(rowCol.cssClass) + .addClass(cols[i].colClass) + .attr('colspan', rowCol.colSpan) + .attr({ + 'data-row': r, + 'data-index': i, + 'data-flex': false, + 'data-type': cols[i].type, + style: rowCol.css, + title: rowCol.title || '' + }).css('width', cols[i].width); + + + $tr.append($td); + } + + $left.append($leftRow); + $flex.append($flexRow); + $right.append($rightRow); + } + + + var $rowSpan; + if(data.fixedLeft) { + $rowSpan = $(dataRowSpan); + $rowSpan.addClass('fixed-left') + .find('table') + .addClass(options.tableClass) + .append($left); + $rows.append($rowSpan); + } + if(data.flexArea) { + $rowSpan = $(dataRowSpan); + $rowSpan.addClass('flexarea') + .find('.datatable-wrapper') + .append('
') + .find('table') + .addClass(options.tableClass) + .append($flex); + $rows.append($rowSpan); + } + if(data.fixedRight) { + $rowSpan = $(dataRowSpan); + $rowSpan.addClass('fixed-right') + .find('table') + .addClass(options.tableClass) + .append($right); + $rows.append($rowSpan); + } + $datatable.append($rows); + + if(data.flexArea) { + $datatable.append('
'); + } + + var $oldFooter = $datatable.children('.datatable-footer').detach(); + if(data.footer) { + $datatable.append($('