From e2b0fcc128214fd105d890dd8ba14bd3690ab2bd Mon Sep 17 00:00:00 2001 From: zhai_lw Date: Wed, 16 Jan 2019 08:58:05 +0800 Subject: [PATCH] rewrite Process --- .../C_StudentUploadFinishedProduct.java | 2 +- src/core/process/C_UploadFile.java | 7 +++ src/dao/DBManagement.java | 7 ++- src/dao/UpdateAll.java | 48 +++++++++++++++++++ src/gdms/GDMS.java | 17 ++++++- src/gdms/test.java | 14 +++--- 6 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 src/core/process/C_UploadFile.java create mode 100644 src/dao/UpdateAll.java diff --git a/src/core/process/C_StudentUploadFinishedProduct.java b/src/core/process/C_StudentUploadFinishedProduct.java index 8c16420..8ebd9ff 100644 --- a/src/core/process/C_StudentUploadFinishedProduct.java +++ b/src/core/process/C_StudentUploadFinishedProduct.java @@ -7,7 +7,7 @@ import java.io.File; import java.util.HashMap; import java.util.Map; -public class C_StudentUploadFinishedProduct extends TempProcess { +public class C_StudentUploadFinishedProduct extends C_UploadFile { File finishedProduct; String graduationDesignId; diff --git a/src/core/process/C_UploadFile.java b/src/core/process/C_UploadFile.java new file mode 100644 index 0000000..4593b24 --- /dev/null +++ b/src/core/process/C_UploadFile.java @@ -0,0 +1,7 @@ +package core.process; + +public abstract class C_UploadFile extends TempProcess { + public String getJspURL(){ + return "/home/upload_file.jsp"; + } +} diff --git a/src/dao/DBManagement.java b/src/dao/DBManagement.java index 6a9eaa8..696ae88 100644 --- a/src/dao/DBManagement.java +++ b/src/dao/DBManagement.java @@ -171,6 +171,11 @@ public class DBManagement { String sql = update.getSQL(); update(sql); } + public static void updateAll(String table, List fields, String increment) throws GExcptSQL { + UpdateAll updateAll = new UpdateAll(table,fields,increment); + String sql = updateAll.getSQL(); + update(sql); + } public static List query(String sql) throws Exception { if(!ifInit) return null; List ls; @@ -222,7 +227,5 @@ public class DBManagement { } } - public static void updateAll(String table, List fields, String increment) { - } } diff --git a/src/dao/UpdateAll.java b/src/dao/UpdateAll.java new file mode 100644 index 0000000..356af2e --- /dev/null +++ b/src/dao/UpdateAll.java @@ -0,0 +1,48 @@ +package dao; + +import java.util.List; + +public class UpdateAll extends SQLStmt { + private static final String fs ="UPDATE "; + List fields; + String increment; + + public UpdateAll(String table, List fields, String increment) { + super(table); + this.setFields(fields); + this.setIncrement(increment); + } + + @Override + public String getSQL() { + return this.getFs()+this.getUs(); + } + + @Override + public String getFs() { + return fs+this.getTable()+" "; + } + public String getUs(){ + String us = "SET "; + for(String s:this.getFields()){ + us+=s+" = "+s+" + "+this.getIncrement()+", "; + } + return utils.Utils.cutTail(us,2); + } + + public List getFields() { + return fields; + } + + public void setFields(List fields) { + this.fields = fields; + } + + public String getIncrement() { + return increment; + } + + public void setIncrement(String increment) { + this.increment = increment; + } +} diff --git a/src/gdms/GDMS.java b/src/gdms/GDMS.java index a3d01c1..900f903 100644 --- a/src/gdms/GDMS.java +++ b/src/gdms/GDMS.java @@ -2,6 +2,7 @@ package gdms; import dao.DBManagement; import error.GExcptInit; +import error.GExcptSQL; import java.util.*; @@ -25,14 +26,26 @@ public class GDMS { public void run() { List fields = new ArrayList<>(); fields.add("teacher_choose_student_status"); - DBManagement.updateAll("graduation_design",fields,"1"); + try { + DBManagement.updateAll("graduation_design",fields,"1"); + } catch (GExcptSQL gExcptSQL) { + gExcptSQL.printStackTrace(); + System.exit(1); + } } }; case "student_choose_teacher_start_date": return new TimerTask() { @Override public void run() { - ; + List fields = new ArrayList<>(); + fields.add("teacher_choose_student_status"); + try { + DBManagement.updateAll("graduation_design",fields,"1"); + } catch (GExcptSQL gExcptSQL) { + gExcptSQL.printStackTrace(); + System.exit(1); + } } }; case "choose_end_date": diff --git a/src/gdms/test.java b/src/gdms/test.java index 8aa8764..05c12b5 100644 --- a/src/gdms/test.java +++ b/src/gdms/test.java @@ -2,7 +2,9 @@ package gdms; import core.operation.utils.Utils; import core.process.C_StudentSelectTeacher; +import dao.DBManagement; import dao.Select; +import dao.UpdateAll; import java.util.ArrayList; import java.util.HashMap; @@ -11,12 +13,12 @@ import java.util.Map; public class test { public static void main(String[] args){ - String s = "graduation_design_finished_product_reviewer_score.reviewer_teacher_id"; - String[] ss = s.split("\\."); - System.out.println(ss[0]); + List ls = new ArrayList<>(); + ls.add("teacher_choose_student_status"); + ls.add("student_choose_teacher_status"); + UpdateAll s = new UpdateAll("graduation_design",ls,"10"); + + System.out.println(s.getSQL()); - } - static void changeB(String a){ - a="B"; } }