Commit 606c472e authored by YangZhaoJun1's avatar YangZhaoJun1

修改作业目录结构

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