diff --git a/HomeWork-java/src/com/wetoband/template/action/ToolTemplateAction.java b/HomeWork-java/src/com/wetoband/template/action/ToolTemplateAction.java index 2d72b19fe839a18204d545a98ee3387d8b5af5c7..74407fd22bbaaa38df310379fa6637ec685babb8 100644 --- a/HomeWork-java/src/com/wetoband/template/action/ToolTemplateAction.java +++ b/HomeWork-java/src/com/wetoband/template/action/ToolTemplateAction.java @@ -1,37 +1,21 @@ package com.wetoband.template.action; -import cn.hutool.core.date.DateUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import com.fy.basejar.tool.ActionToolBase; import com.wetoband.template.AppConfig; -import com.wetoband.template.entity.HomeWork; - -import com.wetoband.template.entity.Question; -import com.wetoband.template.entity.User; -import com.wetoband.template.entity.WrongQuestion; - +import com.wetoband.template.entity.*; import com.wetoband.template.service.*; -import com.wetoband.template.service.impl.HomeWorkServiceImpl; -import com.wetoband.template.service.impl.QuestionServiceImpl; -import com.wetoband.template.service.impl.UserServiceImpl; -import com.wetoband.template.service.impl.WrongQuestionServiceImpl; +import com.wetoband.template.service.impl.*; import com.wetoband.template.util.R; -import org.springframework.beans.factory.annotation.Autowired; +import org.jetbrains.annotations.NotNull; import org.springframework.context.ApplicationContext; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; - +import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; +import java.io.IOException; import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @@ -42,14 +26,13 @@ public class ToolTemplateAction extends ActionToolBase { //获取service实例 HomeWorkService homeWorkService=IOC.getBean(HomeWorkServiceImpl.class); WrongQuestionService wrongQuestionService=IOC.getBean(WrongQuestionServiceImpl.class); - QuestionService questionService=IOC.getBean(QuestionServiceImpl.class); UserService userService=IOC.getBean(UserServiceImpl.class); - FileUploadService fileUploadService= IOC.getBean(FileUploadService.class); + TroubleshootingService troubleshootingService=IOC.getBean(TroubleshootingServiceImpl.class); + QuestionService questionService=IOC.getBean(QuestionServiceImpl.class); @Action public R get(HttpServletRequest request ) throws Exception { - return R.ok().put("msg", "Hello World").message("GET请求成功"); } @@ -104,50 +87,63 @@ public class ToolTemplateAction extends ActionToolBase { return R.ok().put("data",wrongQuestion); } - - - //提交作业(简答题) @Action public R submitHomework(HttpServletRequest request) throws Exception { + + + + + + + + String[] userAnswers = request.getParameterValues("user_answers"); + System.out.println(123); + System.out.println("userAnswers:"+userAnswers); Integer studentId =Integer.parseInt(request.getParameter("student_id")); Integer homeworkId =Integer.parseInt(request.getParameter("homework_id")); //获取提交时间设置为年月日格式 String submitTimeStr = request.getParameter("submitTime"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date submitTimeDate = sdf.parse(submitTimeStr); - String text = request.getParameter("text"); + String text = "123"; homeWorkService.submitHomework(studentId,homeworkId,submitTimeDate,text); return R.ok().message("请求成功"); } - //提交疑难点 @Action - public R submitQuestions(HttpServletRequest request) throws Exception { - Question question = new Question(); - question.setHomework_id(Integer.parseInt(request.getParameter("homework_id"))); - question.setStudent_id(Integer.parseInt(request.getParameter("student_id"))); - question.setContent(request.getParameter("content")); + public R submitTroubleshooting(@NotNull HttpServletRequest request) throws Exception { + Troubleshooting troubleshooting = new Troubleshooting(); + troubleshooting.setQuestion_id(Integer.parseInt(request.getParameter("question_id"))); + troubleshooting.setHomework_id(Integer.parseInt(request.getParameter("homework_id"))); + troubleshooting.setStudent_id(Integer.parseInt(request.getParameter("student_id"))); + troubleshooting.setContent(request.getParameter("content")); String submitTimeStr = request.getParameter("submitTime"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date submitTimeDate = sdf.parse(submitTimeStr); - question.setSubmit_time(submitTimeDate); - questionService.submitQuestions(question); + troubleshooting.setSubmit_time(submitTimeDate); + troubleshootingService.submitTroubleshooting(troubleshooting); return R.ok().message("请求成功"); } - - //文件上传miniIo + //获取题目(选择题) @Action - public R fileUploadService(@RequestParam(value = "file") MultipartFile multipartFile) {//前端要传一个名字叫 file 的参数 - - String fileUrl = fileUploadService.fileUpload(multipartFile) ; - return R.ok().put("data",fileUrl);//返回一个fileurl给前端 + public R getQuestion(HttpServletRequest request) throws Exception { + Integer homework_id =Integer.parseInt(request.getParameter("homework_id")); + List question = questionService.getQuestion(homework_id); + return R.ok().put("data",question); } + //文件上传miniIo + @Action + public R fileUploadService(HttpServletRequest request) throws ServletException, IOException {//前端要传一个名字叫 file 的参数 + MultipartFile filePart = (MultipartFile) request.getPart("file"); +// String fileUrl = fileUploadService.fileUpload(filePart) ; + return R.ok().put("data",filePart);//返回一个fileurl给前端 + } public static String runTool(String toolId, String action, Map map, String bandId) { diff --git a/HomeWork-java/src/com/wetoband/template/dao/QuestionDao.java b/HomeWork-java/src/com/wetoband/template/dao/QuestionDao.java index f2beb66b8fa40e55222bd3a1f8bdc98afc5301b3..c24dadfc36795fa66d20764e3c7ba71884482c0d 100644 --- a/HomeWork-java/src/com/wetoband/template/dao/QuestionDao.java +++ b/HomeWork-java/src/com/wetoband/template/dao/QuestionDao.java @@ -1,9 +1,12 @@ package com.wetoband.template.dao; import com.wetoband.template.entity.Question; +import com.wetoband.template.entity.Troubleshooting; import java.sql.Connection; +import java.util.ArrayList; +import java.util.Map; public interface QuestionDao { - public void submitQuestions(Connection connection, Question question); + public ArrayList getQuestion(Connection connection, int homeworkId) throws Exception; } diff --git a/HomeWork-java/src/com/wetoband/template/dao/TroubleshootingDao.java b/HomeWork-java/src/com/wetoband/template/dao/TroubleshootingDao.java new file mode 100644 index 0000000000000000000000000000000000000000..28359a4ef57f5e63c5f8d71f742ac264ecd583ea --- /dev/null +++ b/HomeWork-java/src/com/wetoband/template/dao/TroubleshootingDao.java @@ -0,0 +1,10 @@ +package com.wetoband.template.dao; + +import com.wetoband.template.entity.Question; +import com.wetoband.template.entity.Troubleshooting; + +import java.sql.Connection; + +public interface TroubleshootingDao { + public void submitTroubleshooting(Connection connection, Troubleshooting troubleshooting); +} diff --git a/HomeWork-java/src/com/wetoband/template/dao/impl/QuestionDaoImpl.java b/HomeWork-java/src/com/wetoband/template/dao/impl/QuestionDaoImpl.java index 2d93fa58caeb506e0ce3555a479ac225285c8909..712cef362154193a54d0503dc1bd4f0fcbf75602 100644 --- a/HomeWork-java/src/com/wetoband/template/dao/impl/QuestionDaoImpl.java +++ b/HomeWork-java/src/com/wetoband/template/dao/impl/QuestionDaoImpl.java @@ -3,25 +3,43 @@ package com.wetoband.template.dao.impl; import com.wetoband.template.dao.QuestionDao; import com.wetoband.template.entity.HomeWork; import com.wetoband.template.entity.Question; +import com.wetoband.template.entity.Troubleshooting; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import java.sql.*; +import java.util.ArrayList; @Repository public class QuestionDaoImpl implements QuestionDao { @Override - public void submitQuestions(Connection connection, Question question) { - String sql = "INSERT INTO question (homework_id,content,student_id,teacher_id) VALUES (?,?,?,(SELECT teacher_id FROM homework WHERE homework_id = ?))" ; - try (PreparedStatement pstm = connection.prepareStatement(sql)) { - pstm.setInt(1, question.getHomework_id()); - pstm.setString(2, question.getContent()); - pstm.setInt(3, question.getStudent_id()); - pstm.setInt(4, question.getHomework_id()); - pstm.executeUpdate(); - } catch (SQLException e) { - throw new RuntimeException(e); + public ArrayList getQuestion(Connection connection, int homework_id) throws Exception { + ArrayList questions = new ArrayList<>(); + try (PreparedStatement pstm = connection.prepareStatement("SELECT * FROM question WHERE question_id in(SELECT homework_question.question_id FROM homework_question WHERE homework_id = ?)")) { + pstm.setInt(1, homework_id); + try (ResultSet rs = pstm.executeQuery()) { + while (rs.next()) { + Question question = new Question(); + question.setQuestion_id(rs.getInt("question_id")); + question.setTitle(rs.getString("title")); + question.setType(rs.getInt("type")); + if (rs.getString("option_A")!=null){ + question.setOption_A(rs.getString("option_A")); + } + if (rs.getString("option_B")!=null){ + question.setOption_B(rs.getString("option_B")); + } + if (rs.getString("option_C")!=null){ + question.setOption_C(rs.getString("option_C")); + } + if (rs.getString("option_D")!=null){ + question.setOption_D(rs.getString("option_D")); + } + questions.add(question); + } + } } + return questions; } } diff --git a/HomeWork-java/src/com/wetoband/template/dao/impl/TroubleshootingDaoImpl.java b/HomeWork-java/src/com/wetoband/template/dao/impl/TroubleshootingDaoImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..fefc003471d590a897c2ad86c27f4db16044fc7c --- /dev/null +++ b/HomeWork-java/src/com/wetoband/template/dao/impl/TroubleshootingDaoImpl.java @@ -0,0 +1,28 @@ +package com.wetoband.template.dao.impl; + +import com.wetoband.template.dao.TroubleshootingDao; +import com.wetoband.template.entity.Question; +import com.wetoband.template.entity.Troubleshooting; +import org.springframework.stereotype.Repository; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +@Repository +public class TroubleshootingDaoImpl implements TroubleshootingDao { + @Override + public void submitTroubleshooting(Connection connection, Troubleshooting Troubleshooting) { + String sql = "INSERT INTO Troubleshooting (question_id,homework_id,content,student_id,teacher_id) VALUES (?,?,?,?,(SELECT teacher_id FROM homework WHERE homework_id = ?))" ; + try (PreparedStatement pstm = connection.prepareStatement(sql)) { + pstm.setInt(1, Troubleshooting.getQuestion_id()); + pstm.setInt(2, Troubleshooting.getHomework_id()); + pstm.setString(3, Troubleshooting.getContent()); + pstm.setInt(4, Troubleshooting.getStudent_id()); + pstm.setInt(5, Troubleshooting.getHomework_id()); + pstm.executeUpdate(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/HomeWork-java/src/com/wetoband/template/entity/Question.java b/HomeWork-java/src/com/wetoband/template/entity/Question.java index 02d2b4177de98416d46401a0abd34007a2ebaa09..08aa8c006dd6489e3de3ed252876856da9f95721 100644 --- a/HomeWork-java/src/com/wetoband/template/entity/Question.java +++ b/HomeWork-java/src/com/wetoband/template/entity/Question.java @@ -11,22 +11,22 @@ import java.util.Date; @Table(name = "question") public class Question { @Id - @Column(name = "question_id") + @Column(name ="question_id") private Integer question_id; - @Column(name = "student_id") - private Integer student_id; - @Column(name = "teacher_id") - private Integer teacher_id; - @Column(name = "homework_id") - private Integer homework_id; - @Column(name = "submit_time") - private Date submit_time; - @Column(name = "content") - private String content; - @Column(name = "solve_status") - private String solve_status; - @Column(name = "solve_content") - private String solve_content; - @Column(name = "solve_time") - private String solve_time; + @Column(name ="title") + private String title; + @Column(name ="type") + private int type; + @Column(name ="option_A") + private String option_A; + @Column(name ="option_B") + private String option_B; + @Column(name ="option_C") + private String option_C; + @Column(name ="option_D") + private String option_D; + @Column(name ="correct_answer") + private String correct_answer; + + } diff --git a/HomeWork-java/src/com/wetoband/template/entity/Troubleshooting.java b/HomeWork-java/src/com/wetoband/template/entity/Troubleshooting.java new file mode 100644 index 0000000000000000000000000000000000000000..7694c3501e0b82e06c7381d22eb71854967a546d --- /dev/null +++ b/HomeWork-java/src/com/wetoband/template/entity/Troubleshooting.java @@ -0,0 +1,34 @@ +package com.wetoband.template.entity; + +import lombok.Data; + +import javax.persistence.Column; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.Date; + +@Data +@Table(name = "Troubleshooting") +public class Troubleshooting { + @Id + @Column(name = "troubleshooting_id") + private Integer troubleshooting_id; + @Column(name = "question_id") + private Integer question_id; + @Column(name = "student_id") + private Integer student_id; + @Column(name = "teacher_id") + private Integer teacher_id; + @Column(name = "homework_id") + private Integer homework_id; + @Column(name = "submit_time") + private Date submit_time; + @Column(name = "content") + private String content; + @Column(name = "solve_status") + private String solve_status; + @Column(name = "solve_content") + private String solve_content; + @Column(name = "solve_time") + private String solve_time; +} \ No newline at end of file diff --git a/HomeWork-java/src/com/wetoband/template/service/QuestionService.java b/HomeWork-java/src/com/wetoband/template/service/QuestionService.java index 0b309cc83c887beb6c56e4fef8054c3c97e54f49..0f037c7a3fe37fe31c06bdd9a031bf29e6716380 100644 --- a/HomeWork-java/src/com/wetoband/template/service/QuestionService.java +++ b/HomeWork-java/src/com/wetoband/template/service/QuestionService.java @@ -2,6 +2,8 @@ package com.wetoband.template.service; import com.wetoband.template.entity.Question; +import java.util.ArrayList; + public interface QuestionService { - public void submitQuestions(Question question) throws Exception; + public ArrayList getQuestion(int homework_id) throws Exception; } diff --git a/HomeWork-java/src/com/wetoband/template/service/TroubleshootingService.java b/HomeWork-java/src/com/wetoband/template/service/TroubleshootingService.java new file mode 100644 index 0000000000000000000000000000000000000000..ed92f0469aaf5071c6c73fd8584cee25bae608f0 --- /dev/null +++ b/HomeWork-java/src/com/wetoband/template/service/TroubleshootingService.java @@ -0,0 +1,8 @@ +package com.wetoband.template.service; + +import com.wetoband.template.entity.Question; +import com.wetoband.template.entity.Troubleshooting; + +public interface TroubleshootingService { + public void submitTroubleshooting(Troubleshooting troubleshooting) throws Exception; +} diff --git a/HomeWork-java/src/com/wetoband/template/service/impl/QuestionServiceImpl.java b/HomeWork-java/src/com/wetoband/template/service/impl/QuestionServiceImpl.java index c839733bf3d9a4648a279066836d2eb5d17610ba..7d6600366d0e5982b42e5e13608124d763ad7bfe 100644 --- a/HomeWork-java/src/com/wetoband/template/service/impl/QuestionServiceImpl.java +++ b/HomeWork-java/src/com/wetoband/template/service/impl/QuestionServiceImpl.java @@ -9,15 +9,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.sql.Connection; +import java.util.ArrayList; @Service @NoArgsConstructor public class QuestionServiceImpl implements QuestionService { + @Autowired private QuestionDao questionDao; @Override - public void submitQuestions(Question question) throws Exception { + public ArrayList getQuestion(int homework_id) throws Exception { final Connection connection = ActionToolBase.getDBConnection(); - questionDao.submitQuestions(connection, question); + return questionDao.getQuestion(connection,homework_id); } } diff --git a/HomeWork-java/src/com/wetoband/template/service/impl/TroubleshootingServiceImpl.java b/HomeWork-java/src/com/wetoband/template/service/impl/TroubleshootingServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..c1bb62cd79eed10547989f31caadf8fb851b5af8 --- /dev/null +++ b/HomeWork-java/src/com/wetoband/template/service/impl/TroubleshootingServiceImpl.java @@ -0,0 +1,25 @@ +package com.wetoband.template.service.impl; + +import com.fy.basejar.tool.ActionToolBase; +import com.wetoband.template.dao.QuestionDao; +import com.wetoband.template.dao.TroubleshootingDao; +import com.wetoband.template.entity.Question; +import com.wetoband.template.entity.Troubleshooting; +import com.wetoband.template.service.TroubleshootingService; +import lombok.NoArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.sql.Connection; + +@Service +@NoArgsConstructor +public class TroubleshootingServiceImpl implements TroubleshootingService { + @Autowired + private TroubleshootingDao troubleshootingDao; + @Override + public void submitTroubleshooting(Troubleshooting troubleshooting) throws Exception { + final Connection connection = ActionToolBase.getDBConnection(); + troubleshootingDao.submitTroubleshooting(connection, troubleshooting); + } +} diff --git a/HomeWork-java/target/classes/config.properties b/HomeWork-java/target/classes/config.properties index bb52fb7284bcce4d897f40f21c075d33e4969552..5842d6bea96912e1b52549e8070773e0503f1b9a 100644 --- a/HomeWork-java/target/classes/config.properties +++ b/HomeWork-java/target/classes/config.properties @@ -27,12 +27,6 @@ JDBC_PASSWORD=123456 #JDBC_USERNAME=root #JDBC_PASSWORD=root -MONGODB_IP=localhost -MONGODB_PORT=27017 -MONGODB_DBNAME=admin -MONGODB_USERNAME=root -MONGODB_PASSWORD=root - SWAP_VALUE_MAX_SIZE=0 SWAP_VALUE_SERVER_PORT=6666 GET_SWAP_VALUE_IP=192.168.10.254 @@ -42,4 +36,3 @@ GET_SWAP_VALUE_PORT=6666 - diff --git a/HomeWork-java/tempResources/config.properties b/HomeWork-java/tempResources/config.properties index bb52fb7284bcce4d897f40f21c075d33e4969552..5842d6bea96912e1b52549e8070773e0503f1b9a 100644 --- a/HomeWork-java/tempResources/config.properties +++ b/HomeWork-java/tempResources/config.properties @@ -27,12 +27,6 @@ JDBC_PASSWORD=123456 #JDBC_USERNAME=root #JDBC_PASSWORD=root -MONGODB_IP=localhost -MONGODB_PORT=27017 -MONGODB_DBNAME=admin -MONGODB_USERNAME=root -MONGODB_PASSWORD=root - SWAP_VALUE_MAX_SIZE=0 SWAP_VALUE_SERVER_PORT=6666 GET_SWAP_VALUE_IP=192.168.10.254 @@ -42,4 +36,3 @@ GET_SWAP_VALUE_PORT=6666 - diff --git a/HomeWork-vite/src/views/HomeWorkManager/HomeWorkManger.vue b/HomeWork-vite/src/views/HomeWorkManager/HomeWorkManger.vue index da80e1ee1ca5d119e7b0ab145ce14ec855590256..a35f20be122089d6aef4891926767e08119e8bfa 100644 --- a/HomeWork-vite/src/views/HomeWorkManager/HomeWorkManger.vue +++ b/HomeWork-vite/src/views/HomeWorkManager/HomeWorkManger.vue @@ -34,7 +34,9 @@ 上传作业 + style="background-color:blueviolet;">上传作业 + + @@ -97,7 +99,8 @@ const worng = () => { } const upload = () => { - router.push('./uploadHomeWork') + // router.push('./uploadHomeWork') + router.push('./MultipleChoiceQuestions') } const tableData = ref([ diff --git a/HomeWork-vite/src/views/HomeWorkManager/MultipleChoiceQuestions.vue b/HomeWork-vite/src/views/HomeWorkManager/MultipleChoiceQuestions.vue index 61716311fa44278e127381c2d49347f426af0c3d..2d92a93d8406104ceb6596969b9d3a2a20fe7ace 100644 --- a/HomeWork-vite/src/views/HomeWorkManager/MultipleChoiceQuestions.vue +++ b/HomeWork-vite/src/views/HomeWorkManager/MultipleChoiceQuestions.vue @@ -25,7 +25,6 @@ - {{ String.fromCharCode(65 + index) }}. @@ -42,57 +41,80 @@