commit
0e8a2a1ebb
@ -1,12 +1,27 @@
|
|||||||
package core.operation;
|
package core.operation;
|
||||||
|
|
||||||
import core.user.User;
|
import core.user.User;
|
||||||
|
import dao.DBManagement;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class DownloadFile extends Operation{
|
public class DownloadFile extends Operation{
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> execute(User subject) throws Exception {
|
public Map<String, Object> execute(User subject) throws Exception {
|
||||||
|
String table = (String) this.getOptions().get("file_type");
|
||||||
|
Map<String,String> limits = (Map<String, String>) this.getOptions().get("limits");
|
||||||
|
String field = core.operation.utils.Utils.getFileField(table);
|
||||||
|
List<String> ls = new ArrayList<>();
|
||||||
|
ls.add(field);
|
||||||
|
ResultSet rs = DBManagement.select(ls,table,limits,0,1);
|
||||||
|
rs.next();
|
||||||
|
String filePath = rs.getString(0);
|
||||||
|
File file = new File(filePath);
|
||||||
|
this.getOptions().put("file",file);
|
||||||
return this.getOptions();
|
return this.getOptions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
{
|
{
|
||||||
"options":{
|
"options":{
|
||||||
|
"file_type":"String",
|
||||||
|
"limits":"Map<String,String>"
|
||||||
},
|
},
|
||||||
"return":{}
|
"return":{
|
||||||
|
"file":"File"
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,13 +1,38 @@
|
|||||||
package core.operation;
|
package core.operation;
|
||||||
|
|
||||||
import core.user.User;
|
import core.user.User;
|
||||||
|
import dao.DBManagement;
|
||||||
import error.GExcptSQL;
|
import error.GExcptSQL;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class UploadFileOperation extends Operation {
|
public class UploadFileOperation extends Operation {
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> execute(User subject) throws GExcptSQL {
|
public Map<String, Object> execute(User subject) throws Exception {
|
||||||
|
File file = (File) this.getOptions().get("file");
|
||||||
|
String table = (String) this.getOptions().get("file_type");
|
||||||
|
Map<String,String> limits = (Map<String, String>) this.getOptions().get("limits");
|
||||||
|
|
||||||
|
String field = core.operation.utils.Utils.getFileField(table);
|
||||||
|
String filePath = core.operation.utils.Utils.getFilePathName(table,file.getName());
|
||||||
|
Map<String,String> vMap = new HashMap<>();
|
||||||
|
vMap.put(field,filePath);
|
||||||
|
|
||||||
|
file.renameTo(new File(filePath));
|
||||||
|
//todo
|
||||||
|
|
||||||
|
List<String> ls = new ArrayList<>();
|
||||||
|
ls.add(field);
|
||||||
|
ResultSet rs = DBManagement.select(ls,table,limits,0,1);
|
||||||
|
rs.next();
|
||||||
|
String lastFilePath = rs.getString(0);
|
||||||
|
new File(lastFilePath).delete();
|
||||||
|
DBManagement.update(table,vMap,limits);
|
||||||
return this.getOptions();
|
return this.getOptions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
"options":{
|
"options":{
|
||||||
"file": "File"
|
"file": "File",
|
||||||
|
"file_type": "String",
|
||||||
|
"limits":"Map<String,String>"
|
||||||
},
|
},
|
||||||
"return":{}
|
"return":{}
|
||||||
}
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"公告文件": "announcement",
|
||||||
|
"开题报告":"graduation_design_reply",
|
||||||
|
"毕业设计定稿":"graduation_design_finished_product"
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package core.operation.utils;
|
||||||
|
|
||||||
|
import error.GExcptFormat;
|
||||||
|
import gdms.Configuration;
|
||||||
|
import gdms.Mode;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface Utils {
|
||||||
|
Map<String,String> fileTableField = new HashMap<>() {
|
||||||
|
{
|
||||||
|
put("announcement","annex_url");
|
||||||
|
put("graduation_design_finished_product","graduation_design_url");
|
||||||
|
put("graduation_design_opening_report","report_url");
|
||||||
|
}};
|
||||||
|
static String stringOptionsFormat(String options){
|
||||||
|
return options.replaceAll(" {2,}", " ") ;
|
||||||
|
}
|
||||||
|
static Map<String, Object> string2MapOptions(String sOptions) throws GExcptFormat {
|
||||||
|
sOptions = stringOptionsFormat(sOptions);
|
||||||
|
Map<String, Object> options = new HashMap<>();
|
||||||
|
String[] sOpts = sOptions.split(" ");
|
||||||
|
for(int i=0;i<sOpts.length;i++){
|
||||||
|
if(Mode.strict==1){
|
||||||
|
if(sOpts[i].indexOf(0)=='-')
|
||||||
|
throw new GExcptFormat("options format error");
|
||||||
|
}
|
||||||
|
options.put(sOpts[i].substring(1),sOpts[++i]);
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
static String getFileField(String table){
|
||||||
|
return fileTableField.get(table);
|
||||||
|
}
|
||||||
|
static String getFilePath(String table){
|
||||||
|
return Configuration.filePath+table+"/";
|
||||||
|
}
|
||||||
|
static String getFileName(String fileName){
|
||||||
|
SimpleDateFormat simpleDateFormat;
|
||||||
|
simpleDateFormat = new SimpleDateFormat("yyMMddHHmmssSSS");
|
||||||
|
Date date = new Date();
|
||||||
|
String str = simpleDateFormat.format(date);
|
||||||
|
str+=(int)(Math.random()*100000);
|
||||||
|
str+= utils.Utils.getFileType(fileName);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
static String getFilePathName(String table, String fileName){
|
||||||
|
return getFilePath(table)+getFileName(fileName);
|
||||||
|
}
|
||||||
|
}
|
@ -1,26 +0,0 @@
|
|||||||
package core.operation.utils;
|
|
||||||
|
|
||||||
import error.GExcptFormat;
|
|
||||||
import gdms.Mode;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface util {
|
|
||||||
static String stringOptionsFormat(String options){
|
|
||||||
return options.replaceAll(" {2,}", " ") ;
|
|
||||||
}
|
|
||||||
static Map<String, Object> string2MapOptions(String sOptions) throws GExcptFormat {
|
|
||||||
sOptions = stringOptionsFormat(sOptions);
|
|
||||||
Map<String, Object> options = new HashMap<>();
|
|
||||||
String[] sOpts = sOptions.split(" ");
|
|
||||||
for(int i=0;i<sOpts.length;i++){
|
|
||||||
if(Mode.strict==1){
|
|
||||||
if(sOpts[i].indexOf(0)=='-')
|
|
||||||
throw new GExcptFormat("options format error");
|
|
||||||
}
|
|
||||||
options.put(sOpts[i].substring(1),sOpts[++i]);
|
|
||||||
}
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +1,15 @@
|
|||||||
package core.utils;
|
package core.utils;
|
||||||
|
|
||||||
|
import core.operation.Operation;
|
||||||
|
import core.user.User;
|
||||||
|
|
||||||
public interface GetObjectByName {
|
public interface GetObjectByName {
|
||||||
String userClassPath = "core.user";
|
String userClassPath = "core.user";
|
||||||
String operationClassPath = "core.operation";
|
String operationClassPath = "core.operation";
|
||||||
static Object getUserByName(String name) throws Exception {
|
static User getUserByName(String name) throws Exception {
|
||||||
return Class.forName(userClassPath+"."+name).getDeclaredConstructor().newInstance();
|
return (User)Class.forName(userClassPath+"."+name).getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
static Object getOperationByName(String name) throws Exception{
|
static Operation getOperationByName(String name) throws Exception{
|
||||||
return Class.forName(operationClassPath+"."+name).getDeclaredConstructor().newInstance();
|
return (Operation)Class.forName(operationClassPath+"."+name).getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package gdms;
|
||||||
|
|
||||||
|
public interface Configuration {
|
||||||
|
//file
|
||||||
|
String filePath = "/";
|
||||||
|
//database
|
||||||
|
String dbUrl="jdbc:mariadb://localhost:3306/gdms";
|
||||||
|
String dbUsername="gdms";
|
||||||
|
String dbPassword="GDMS";
|
||||||
|
}
|
Loading…
Reference in new issue