Commit 606c472e authored by YangZhaoJun1's avatar YangZhaoJun1

修改作业目录结构

parent 1bbd11fa
......@@ -3,6 +3,7 @@ package org.rcisoft.business.bcode.controller;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.business.bcode.model.BCodeFile;
import org.rcisoft.business.bcode.service.BCodeService;
import org.rcisoft.common.controller.PaginationController;
import org.rcisoft.core.constant.MessageConstant;
......@@ -12,6 +13,8 @@ import org.rcisoft.core.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* Created by lcy on 18/1/3.
*
......@@ -40,11 +43,19 @@ public class BCodeController extends PaginationController {
public Result queryOwnExamFiles(@RequestParam("slId") String slId,
@RequestParam("chapId") String chapId,
@RequestParam("examType") String examType){
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
bCodeServiceImpl.readExamFiles(slId, chapId, examType, UserUtil.getUserInfoProp(getToken(), UserUtil.USER_ID)));
List<BCodeFile> list = bCodeServiceImpl.readExamFiles(slId, chapId, examType,
UserUtil.getUserInfoProp(getToken(), UserUtil.USER_ID),
UserUtil.getUserInfoProp(getToken(), UserUtil.USER_USERNAME));
if(examType.equals("0001")||examType.equals("1001"))
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
list.get(0));
else
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
list);
}
......@@ -63,7 +74,10 @@ public class BCodeController extends PaginationController {
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
bCodeServiceImpl.saveOwnExamFiles(slId, chapId, examType, content, UserUtil.getUserInfoProp(getToken(), UserUtil.USER_ID)));
bCodeServiceImpl.saveOwnExamFiles(slId, chapId, examType, content,
UserUtil.getUserInfoProp(getToken(), UserUtil.USER_ID),
UserUtil.getUserInfoProp(getToken(), UserUtil.USER_USERNAME)
));
}
......
......@@ -22,7 +22,10 @@ public class BCodeFile {
private Date lastModify;
private List<String> fileNameList;
private String name;
private String id;
private String pId;
private List<BCodeFile> codeFileList;
}
......@@ -2,6 +2,8 @@ package org.rcisoft.business.bcode.service;
import org.rcisoft.business.bcode.model.BCodeFile;
import java.util.List;
/**
* Created by lcy on 18/1/3.
*/
......@@ -14,7 +16,7 @@ public interface BCodeService {
* @param userInfoProp
* @return
*/
BCodeFile readExamFiles(String slId, String chapId, String examType, String userInfoProp);
List<BCodeFile> readExamFiles(String slId, String chapId, String examType, String userInfoProp, String StudentCode);
/**
......@@ -26,7 +28,7 @@ public interface BCodeService {
* @param userInfoProp
* @return
*/
BCodeFile saveOwnExamFiles(String slId, String chapId, String examType, String content, String userInfoProp);
BCodeFile saveOwnExamFiles(String slId, String chapId, String examType, String content, String userInfoProp, String studentCode);
String exportFiles(String slId, String studentId, String type, String slCode);
}
......@@ -5,6 +5,7 @@ import org.apache.commons.io.FileUtils;
import org.rcisoft.business.bchapter.dao.BChapterRepository;
import org.rcisoft.business.bchapter.entity.BChapter;
import org.rcisoft.business.bcode.model.BCodeFile;
import org.rcisoft.business.bcode.model.BCodeLxc;
import org.rcisoft.business.bcode.model.CodeType;
import org.rcisoft.business.bcode.service.BCodeService;
import org.rcisoft.business.brslstudent.dao.BRSlStudentRepository;
......@@ -15,6 +16,7 @@ import org.rcisoft.business.bstudent.entity.BStudent;
import org.rcisoft.business.bstudent.entity.BStudentDto;
import org.rcisoft.common.component.Global;
import org.rcisoft.core.service.RcRedisService;
import org.rcisoft.core.util.IdGen;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
......@@ -59,20 +61,20 @@ public class BCodeServiceImpl implements BCodeService {
* @return
*/
@Override
public BCodeFile readExamFiles(String slId, String chapId, String examType, String userInfo) {
public List<BCodeFile> readExamFiles(String slId, String chapId, String examType, String userInfo, String studentCode) {
/*java 单文件*/
if(examType.equals(global.getJavaSimple()))
return this.readSimpleFile(slId,chapId,CodeType.SIM_JAVA,userInfo);
return this.readSimpleFile(slId,chapId,CodeType.SIM_JAVA,userInfo,studentCode);
/*java 工程*/
if(examType.equals(global.getJavaProject()))
return this.readProjectFile(slId,chapId,userInfo);
return this.readProjectFile(slId,chapId,userInfo,studentCode);
/*html 单文件*/
if(examType.equals(global.getHtmlSimple()))
return this.readSimpleFile(slId,chapId,CodeType.SIM_HTML,userInfo);
return this.readSimpleFile(slId,chapId,CodeType.SIM_HTML,userInfo,studentCode);
/*html 工程*/
if(examType.equals(global.getHtmlProject()))
return this.readProjectFile(slId,chapId,userInfo);
return this.readProjectFile(slId,chapId,userInfo,studentCode);
return null;
}
......@@ -86,15 +88,17 @@ public class BCodeServiceImpl implements BCodeService {
* @param userInfo
* @return
*/
private BCodeFile readSimpleFile(String slId, String chapId, CodeType examType, String userInfo) {
private List<BCodeFile> readSimpleFile(String slId, String chapId, CodeType examType, String userInfo, String studentCode) {
List<BCodeFile> codeFileList = new ArrayList<>();
BCodeFile codeFile = null;
String path = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
+ global.getCOURSE_LOCATION() + File.separator
+ global.getSL_LOCATION() + File.separator
+ slId + File.separator
+ chapId + File.separator
+ global.getCOURSE_CODE_LOCATION();
String file = path + File.separator + userInfo + examType.getPostfix();
+ global.getCOURSE_CODE_LOCATION() + File.separator
+ userInfo + File.separator;
String file = path + studentCode + examType.getPostfix();
try{
File simplePath = new File(path);
if(!simplePath.exists()) {
......@@ -103,20 +107,22 @@ public class BCodeServiceImpl implements BCodeService {
File simpleFile = new File(file);
if(!simpleFile.exists()) {
simpleFile.createNewFile();
codeFile = new BCodeFile("0", "", null, null, null);
codeFile = new BCodeFile("0", "", null, simpleFile.getName(),IdGen.uuid(), "");
codeFileList.add(codeFile);
}else{
String content = FileUtils.readFileToString(simpleFile);
List<String> fileName = new ArrayList<>();
fileName.add(simpleFile.getName());
codeFile = new BCodeFile("0", content,new Date(simpleFile.lastModified()), fileName, null);
///List<String> fileName = new ArrayList<>();
//fileName.add(simpleFile.getName());
codeFile = new BCodeFile("0", content,new Date(simpleFile.lastModified()), simpleFile.getName(), IdGen.uuid(),"");
codeFileList.add(codeFile);
}
}catch (Exception e){
log.debug(file + " is not exist");
codeFile = new BCodeFile("0", "", null, null, null);
codeFile = new BCodeFile("0", "", null, "","", "");
codeFileList.add(codeFile);
}
return codeFile;
return codeFileList;
}
......@@ -126,29 +132,37 @@ public class BCodeServiceImpl implements BCodeService {
* @param userInfo
* @return
*/
private BCodeFile readProjectFile(String slId, String chapterId, String userInfo) {
BCodeFile codeFile = null;
private List<BCodeFile> readProjectFile(String slId, String chapterId, String userInfo, String StudentCode) {
BCodeLxc lxc = new BCodeLxc();
List<BCodeFile> codeFile = new ArrayList<>();
String path = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
+ global.getCOURSE_LOCATION() + File.separator
+ global.getSL_LOCATION() + File.separator
+ slId + File.separator
//+ chapterId +File.separator
+ chapterId +File.separator
+ global.getCOURSE_PROJECT_LOCATION() + File.separator
+ userInfo;
+ userInfo + File.separator
+ StudentCode;
lxc.setUserId(userInfo);
lxc.setWorkingDir(path);
try{
//xuehao
File simplePath = new File(path);
BCodeFile simpleCodeFile = new BCodeFile("0", "", null, "",IdGen.uuid(),"");
codeFile.add(simpleCodeFile);
if(!simplePath.exists()) {
simplePath.mkdirs();
codeFile = new BCodeFile("0", "", null, null,null);
}else{
boolean isFile = true;
codeFile = new BCodeFile();
getFileList(simplePath,codeFile,isFile);
getFileList(simplePath,codeFile,simpleCodeFile,isFile);
}
}catch (Exception e){
log.debug(path + " is not exist");
codeFile = new BCodeFile("0", "", null,null, null);
BCodeFile simpleCodeFile = new BCodeFile("0", "", null,"","", "");
}
return codeFile;
......@@ -161,34 +175,35 @@ public class BCodeServiceImpl implements BCodeService {
* @param codeFile
* @throws IOException
*/
private void getFileList(File files,BCodeFile codeFile,boolean isFile) throws IOException {
List<String> fileNameList = new ArrayList<String>();
List<BCodeFile> directoryList = new ArrayList<BCodeFile>();
codeFile.setFileNameList(fileNameList);
codeFile.setCodeFileList(directoryList);
File[] fs=files.listFiles();
for (File f : fs) {
if(f.isFile()){
if(isFile){
codeFile.setContent(FileUtils.readFileToString(f));
}
codeFile.setFileType("1");
codeFile.setLastModify(new Date(f.lastModified()));
fileNameList.add(f.getName());
isFile = false;
}else if(f.isDirectory()){
BCodeFile directoryChild = new BCodeFile();
codeFile.setContent("");
codeFile.setFileType("0");
codeFile.setLastModify(new Date(f.lastModified()));
fileNameList.add(f.getName());
directoryList.add(directoryChild);
File newFile = new File(f.getPath());
getFileList(newFile,directoryChild,isFile);
private void getFileList(File files,List<BCodeFile> codeFile,BCodeFile parentFile,boolean isFile) throws IOException {
BCodeFile bCodeFile = new BCodeFile();
bCodeFile.setContent("");
bCodeFile.setLastModify(new Date(files.lastModified()));
bCodeFile.setName(files.getName());
bCodeFile.setId(IdGen.uuid());
bCodeFile.setPId(parentFile.getId());
codeFile.add(bCodeFile);
if(files.isFile()){
if(isFile){
bCodeFile.setContent(FileUtils.readFileToString(files));
}
bCodeFile.setFileType("1");
isFile = false;
}else{
bCodeFile.setFileType("0");
File[] ffs=files.listFiles();
for (File ff : ffs) {
getFileList(ff, codeFile, bCodeFile, isFile);
}
}
}
/**
......@@ -201,16 +216,16 @@ public class BCodeServiceImpl implements BCodeService {
* @return
*/
@Override
public BCodeFile saveOwnExamFiles(String slId, String chapId, String examType, String content, String userInfo) {
public BCodeFile saveOwnExamFiles(String slId, String chapId, String examType, String content, String userInfo, String studentCode) {
/*java 单文件*/
if(examType.equals(global.getJavaSimple()))
return this.saveOwnExamFiles(slId,chapId,CodeType.SIM_JAVA,content,userInfo);
return this.saveOwnExamFiles(slId,chapId,CodeType.SIM_JAVA,content,userInfo,studentCode);
/*java 工程*/
if(examType.equals(global.getJavaProject()))
return null;
/*html 单文件*/
if(examType.equals(global.getHtmlSimple()))
return this.saveOwnExamFiles(slId,chapId,CodeType.SIM_HTML,content,userInfo);
return this.saveOwnExamFiles(slId,chapId,CodeType.SIM_HTML,content,userInfo,studentCode);
/*html 工程*/
if(examType.equals(global.getHtmlProject()))
return null;
......@@ -227,15 +242,16 @@ public class BCodeServiceImpl implements BCodeService {
* @param userInfo
* @return
*/
private BCodeFile saveOwnExamFiles(String slId, String chapId, CodeType examType, String content, String userInfo) {
private BCodeFile saveOwnExamFiles(String slId, String chapId, CodeType examType, String content, String userInfo, String studentCode) {
BCodeFile codeFile = null;
String path = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
+ global.getCOURSE_LOCATION() + File.separator
+ global.getSL_LOCATION() + File.separator
+ slId + File.separator
+ chapId + File.separator
+ global.getCOURSE_CODE_LOCATION();
String file = path + File.separator + userInfo + examType.getPostfix();
+ global.getCOURSE_CODE_LOCATION() + File.separator
+ userInfo + File.separator;
String file = path + studentCode + examType.getPostfix();
try{
File simplePath = new File(path);
if(!simplePath.exists()) {
......@@ -246,13 +262,13 @@ public class BCodeServiceImpl implements BCodeService {
simpleFile.createNewFile();
}
FileUtils.write(simpleFile,content,"UTF-8");
List<String> fileName = new ArrayList<>();
fileName.add(simpleFile.getName());
codeFile = new BCodeFile("0", content,new Date(simpleFile.lastModified()),fileName, null);
//List<String> fileName = new ArrayList<>();
//fileName.add(simpleFile.getName());
codeFile = new BCodeFile("0", content,new Date(simpleFile.lastModified()),simpleFile.getName(),IdGen.uuid(), "");
}catch (Exception e){
log.debug(file + "创建失败");
codeFile = new BCodeFile("0", "", null, null,null);
codeFile = new BCodeFile("0", "", null, "","","");
}
return codeFile;
}
......
......@@ -52,6 +52,7 @@ public class JwtUtil {
Map<String,Object> map = new HashedMap();
map.put(userDetails.getUsername(),userDetails);
map.put(UserUtil.USER_ID,jwtUser.getBusinessId());
map.put(UserUtil.USER_USERNAME,jwtUser.getUsername());
String token = jwtBean.generateToken(userDetails.getUsername(),map);
return token;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment