Commit 7398ef7d authored by YangZhaoJun1's avatar YangZhaoJun1

ppt转pdf,智能评分

parent ad8204f3
......@@ -224,6 +224,7 @@ public class BChapterController extends PaginationController<BChapter> {
@ApiImplicitParams({@ApiImplicitParam(name = "score", value = "分数", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "slId", value = "开课ID", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "chapterId", value = "章节id", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "filePath", value = "文件路径", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "studentId", value = "学生学号", required = true, dataType = "varchar")})
@PreAuthorize("hasRole('ROLE_1003')")
@PostMapping(value = "/complete")
......
package org.rcisoft.business.bchapter.controller;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeManager;
import java.io.File;
import java.io.FileNotFoundException;
/**
* Created by Administrator on 2018/1/19.
*/
public class PptToPdf {
private static OfficeManager officeManager;
private static String OFFICE_HOME = "D:/oppenOffice/openOffice";
private static int port[] = { 8100 };
public void convert2PDF(String inputFile, String outputFile) throws FileNotFoundException {
startService();
System.out.println("进行文档转换转换:" + inputFile + " --> " + outputFile);
OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
converter.convert(new File(inputFile), new File(outputFile));
stopService();
System.out.println();
}
// 打开服务器
public static void startService() {
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
try {
System.out.println("准备启动服务....");
configuration.setOfficeHome(OFFICE_HOME);// 设置OpenOffice.org安装目录
configuration.setPortNumbers(port); // 设置转换端口,默认为8100
configuration.setTaskExecutionTimeout(1000 * 60 * 5L);// 设置任务执行超时为5分钟
configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);// 设置任务队列超时为24小时
officeManager = configuration.buildOfficeManager();
officeManager.start(); // 启动服务
System.out.println("office转换服务启动成功!");
} catch (Exception ce) {
System.out.println("office转换服务启动失败!详细信息:" + ce);
}
}
// 关闭服务器
public static void stopService() {
System.out.println("关闭office转换服务....");
if (officeManager != null) {
officeManager.stop();
}
System.out.println("关闭office转换成功!");
}
public static void main(String[] args) throws Exception {
String path = "C:/Users/Administrator/Desktop/";
PptToPdf opc = new PptToPdf();
opc.convert2PDF(path+"abc.pptx", path+"1.pdf");
}
}
......@@ -143,7 +143,7 @@ public interface BChapterRepository extends BaseMapper<BChapter> {
* @param scoreInfoDTO
* @return
*/
@Insert("<script>insert into b_r_student_chapter(business_id,student_id,chapter_id,is_complete,sl_id) values (#{businessId},#{studentId},#{chapterId},#{isComplete},#{slId})</script>")
@Insert("<script>insert into b_r_student_chapter(business_id,student_id,chapter_id,is_complete,sl_id,score) values (#{businessId},#{studentId},#{chapterId},#{isComplete},#{slId},#{score})</script>")
int updateIsComplete(ScoreInfoDTO scoreInfoDTO);
/**
......
......@@ -13,4 +13,6 @@ public class ScoreInfoDTO extends IdEntity<ScoreInfoDTO> {
String studentId;
String isComplete;
String slId;
String filePath;
String examType;
}
......@@ -109,14 +109,8 @@ public class BChapter extends IdEntity<BChapter> {
private String studentName;
public BChapter(String businessId) {
this.businessId = businessId;
}
}
......@@ -12,6 +12,7 @@ import org.rcisoft.business.bchapter.enums.HasMarkEnum;
import org.rcisoft.business.bchapter.enums.StateEnum;
import org.rcisoft.business.bchapter.service.BChapterService;
import org.rcisoft.business.bchapter.vo.StudentChapterScoreVO;
import org.rcisoft.business.bcode.model.IntellEvaluation;
import org.rcisoft.business.blesson.dao.BLessonRepository;
import org.rcisoft.business.blesson.entity.BLesson;
import org.rcisoft.business.brslstudent.dao.BRSlStudentRepository;
......@@ -195,15 +196,31 @@ public class BChapterServiceImpl implements BChapterService {
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
@Override
public void updateIsComplete(ScoreInfoDTO scoreInfoDTO,String token) {
try {
String stuid = bStudentRepository.queryStudentByUserId(scoreInfoDTO.getStudentId());
scoreInfoDTO.setStudentId(stuid);
if(bChapterRepository.selectIdByStudentIdAndChapterId(scoreInfoDTO.getChapterId(),scoreInfoDTO.getStudentId())!=null)
return;
scoreInfoDTO.setCommonBusinessId();
UserUtil.setCurrentMergeOperation(scoreInfoDTO);
BChapter bChapter = bChapterRepository.selectOne(new BChapter(scoreInfoDTO.getChapterId()));
if(bChapter.getAutomatic().equals("1")){//智评
//获取智评分数
int score = IntellEvaluation.IntellEvaluation(scoreInfoDTO.getFilePath(),bChapter.getExperimentType());
scoreInfoDTO.setScore(score);
}
int result = bChapterRepository.updateIsComplete(scoreInfoDTO);
if(bChapter.getExperimentType().equals("2")||bChapter.getExperimentType().equals("4")){
}
if(result<1)
throw new ServiceException(ResultServiceEnums.UPDATE_ERROR);
} catch (Exception e) {
e.printStackTrace();
}
}
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
......
package org.rcisoft.business.bcode.model;
import org.apache.commons.io.FileUtils;
import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.result.ResultServiceEnums;
import java.io.File;
/**
* 智能评分
* Created by yangzhaojun on 2018/1/22.
*
* 智能评分规则:
*
* 【单文件】
* 1) 50——文件内容为空
* 2) 60——文件内容非空
* 3) 80——.java 文件字符个数>77; .html 文件字符个数>140;
* 4) 100——.java 文件字符个数>140; .html 文件字符个数>280;
*
* 【多文件】
* 1) 50——.java 文件个数为0或1;.html文件个数为0或1
* 2) 60——.java 文件个数大于1;.html文件个数为大于1
* 3) “ .java 文件字符个数>77”有一个就+10分,上限100;“ .html、.css、.js 文件字符个数>140”有一个就+10分,上限100;
*/
public class IntellEvaluation {
public static int IntellEvaluation(String filePath, String experimentType) throws Exception{
int score = 0;
String content = "";
File file = new File(filePath);
if(!file.exists()){
throw new ServiceException(ResultServiceEnums.PASSWORD_ERROR);
}
if(experimentType.equals("1")){
//java单文件
content = FileUtils.readFileToString(file);
score = getJavaSingleScore(content);
}else if(experimentType.equals("2")){
//java工程
score = getJavaProjectScore(file);
}else if(experimentType.equals("3")){
//html单文件
content = FileUtils.readFileToString(file);
score = getHtmlSingleScore(content);
}else if(experimentType.equals("4")){
//html工程
score = getHtmlProjectScore(file);
}
return score;
}
//java单文件评分
private static int getJavaSingleScore(String content) {
int score = 0;
if(!content.equals("")&&content!=null){
if(content.length()>=77&&content.length()<140){
score = 80;
}else if(content.length()>=140){
score = 100;
}else{
score = 60;
}
}else{
score = 50;
}
return score;
}
//java工程评分
private static int getJavaProjectScore(File file) throws Exception{
File[] dirFiles = file.listFiles();
int score = 0;
int javaFileNum = 0;//java文件个数
int BonusScore = 0;//额外加分
for(File javaFile : dirFiles){
if(javaFile.isFile()&&javaFile.getAbsolutePath().endsWith(".java")){
javaFileNum += 1;
String content = FileUtils.readFileToString(javaFile);
if(content.length()>=77){
BonusScore += 10;
}
}
}
if(javaFileNum>1){
score = 60 + BonusScore;
if(score>100){
score = 100;
}
}else{
score = 50 + BonusScore;
if(score>100){
score = 100;
}
}
return score;
}
//html单文件评分
private static int getHtmlSingleScore(String content) {
int score = 0;
if(!content.equals("")&&content!=null){
if(content.length()>=140&&content.length()<280){
score = 80;
}else if(content.length()>=280){
score = 100;
}else{
score = 60;
}
}else{
score = 50;
}
return score;
}
//html工程评分
private static int getHtmlProjectScore(File file) throws Exception{
File[] dirFiles = file.listFiles();
int score = 0;
int htmlFileNum = 0;//java文件个数
int BonusScore = 0;//额外加分
for(File htmlFile : dirFiles){
if(htmlFile.isFile()&&htmlFile.getAbsolutePath().endsWith(".html")){
htmlFileNum += 1;
String content = FileUtils.readFileToString(htmlFile);
if(content.length()>=140){
BonusScore += 10;
}
}
if((htmlFile.isFile()&&htmlFile.getAbsolutePath().endsWith(".css"))||(htmlFile.isFile()&&htmlFile.getAbsolutePath().endsWith(".js"))){
String content = FileUtils.readFileToString(htmlFile);
if(content.length()>=140){
BonusScore += 10;
}
}
}
if(htmlFileNum>1){
score = 60 + BonusScore;
if(score>100){
score = 100;
}
}else{
score = 50 + BonusScore;
if(score>100){
score = 100;
}
}
return score;
}
}
......@@ -12,6 +12,8 @@ public class StudentFile {
private String studentName;
private String name;
/*0代表文件 1代表工程*/
private String projectOrFile;
......
......@@ -486,6 +486,7 @@ public class BCodeServiceImpl implements BCodeService {
StudentFile studentFile = new StudentFile();
studentFile.setBCodeFile(codeFile);
studentFile.setStudentName(studentName);
studentFile.setName(chapter.getStudentName());
studentFile.setProjectOrFile("0");
studentFiles.add(studentFile);
}else if(file.isDirectory()){//工程的处理
......@@ -496,6 +497,7 @@ public class BCodeServiceImpl implements BCodeService {
getFileList(file,codeFiles,simpleCodeFile,isFile);
StudentFile studentFile = new StudentFile();
studentFile.setProject(codeFiles);
studentFile.setName(chapter.getStudentName());
studentFile.setStudentName(studentName);
studentFile.setProjectOrFile("1");
studentFiles.add(studentFile);
......
package org.rcisoft.business.bfile.service.impl;
import org.apache.commons.io.FileUtils;
import org.rcisoft.business.bfile.dao.BFileRepository;
import org.rcisoft.business.bfile.entity.BFile;
import org.rcisoft.business.bfile.service.BFileService;
......@@ -8,6 +9,7 @@ import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.constant.DelStatus;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.util.IdGen;
import org.rcisoft.core.util.PptToPdf;
import org.rcisoft.core.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -127,7 +129,7 @@ public class BFileServiceImpl implements BFileService {
* @param url
* @param bFile
*/
private void removeVideoToTemp(String url, String fileName, BFile bFile) {
private void removeVideoToTemp(String url, String fileName, BFile bFile) throws Exception{
String path;
String pathName;
if(bFile.getLessonId()!=null&&!bFile.getLessonId().equals("")){
......@@ -135,50 +137,59 @@ public class BFileServiceImpl implements BFileService {
}else{
path = global.getSL_LOCATION() + File.separator + bFile.getSlId() + File.separator;
}
boolean ppt = false;
if (bFile.getType().equals("0")){
pathName = global.getVIDEO_LOCATION();//视频路径
}else if(bFile.getType().equals("1")){
pathName = global.getFILE_LOCATION();//文件路径
}else if(bFile.getType().equals("2")){
ppt = true;
pathName = global.getPPT_LOCATION();//ppt路径
}else{
pathName = global.getPDF_LOCATION();//pdf路径
}
String oldPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + url;
String tempPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
+ global.getCOURSE_LOCATION() + File.separator
+ global.getTEMP_LOCATION() + File.separator
+ path + bFile.getChapterId() + File.separator + pathName;
+ path + bFile.getChapterId();// + File.separator + pathName;
File filePath = new File(tempPath);
if(!filePath.exists()){
filePath.mkdirs();
}
try {
int bytesum = 0;
int byteread = 0;
File oldfile = new File(oldPath);
if (oldfile.exists()) { //文件存在时
InputStream inStream = new FileInputStream(oldPath); //读入原文件
FileOutputStream fs = new FileOutputStream(tempPath+ File.separator+fileName);
byte[] buffer = new byte[1024000];
int length;
while ( (byteread = inStream.read(buffer)) != -1) {
bytesum += byteread; //字节数 文件大小
fs.write(buffer, 0, byteread);
if(ppt){
String pptPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
+ global.getCOURSE_LOCATION() + File.separator
+ path + bFile.getChapterId() + File.separator + pathName;
File pptDirectory = new File(pptPath);
FileUtils.moveDirectory(pptDirectory,filePath);
}else{
String oldPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + url;
try {
int bytesum = 0;
int byteread = 0;
File oldfile = new File(oldPath);
if (oldfile.exists()) { //文件存在时
InputStream inStream = new FileInputStream(oldPath); //读入原文件
FileOutputStream fs = new FileOutputStream(tempPath + File.separator + pathName + File.separator+fileName);
byte[] buffer = new byte[1024000];
int length;
while ( (byteread = inStream.read(buffer)) != -1) {
bytesum += byteread; //字节数 文件大小
fs.write(buffer, 0, byteread);
}
inStream.close();
fs.close();
oldfile.delete();
}
inStream.close();
fs.close();
oldfile.delete();
}
}
catch (Exception e) {
System.out.println("出错");
e.printStackTrace();
catch (Exception e) {
System.out.println("出错");
e.printStackTrace();
}
}
}
/**
......@@ -241,13 +252,23 @@ public class BFileServiceImpl implements BFileService {
+ path + bFile.getChapterId() + File.separator
+ pathName + File.separator;
if(uploadFileSuffix.equals("ppt")||uploadFileSuffix.equals("pptx")){//ppt转pdf
String inputFile = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
+ newPath+ filename;
String outputFile = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
+ newPath + uploadFileName + ".pdf";
PptToPdf pptToPdf = new PptToPdf();
pptToPdf.pptToPdf(inputFile,outputFile);
}
bFile.setVideoName(name+ "." +uploadFileSuffix);//文件名
if (bFile.getType().equals("0")){
bFile.setVideoUrl(newPath+ filename);//视频路径
}else if(bFile.getType().equals("1")){
bFile.setFileUrl(newPath+ filename);//文件路径
}else if(bFile.getType().equals("2")){
bFile.setPptUrl(newPath+ filename);//ppt路径
bFile.setPptUrl(newPath + uploadFileName + ".pdf");//ppt路径
}else{
bFile.setPdfUrl(newPath+ filename);//pdf路径
}
......
......@@ -213,4 +213,8 @@ public class Global {
/*导出的学生作业暂存路径*/
@Value("${global.path.student_code_location}")
private String STUDENT_CODE_LOCATION;
/*openOffice安装路径*/
@Value("${global.other.open_office_home}")
private String OPEN_OFFICE_HOME;
}
......@@ -132,7 +132,9 @@ public enum ResultServiceEnums {
DOWNLOAD_ERROR(73,"下载失败"),
COMPILING_CODE (74,"运行失败,请重试")
COMPILING_CODE (74,"运行失败,请重试"),
STUDENT_CODE_NOT_EXISTS (74,"未查询到该学生的代码文件")
;
private Integer code;
......
......@@ -13,7 +13,7 @@ server:
druid:
url: jdbc:mysql://127.0.0.1:3306/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
username: root
password: cy
password: root
initial-size: 1
min-idle: 1
max-active: 20
......@@ -104,7 +104,7 @@ global:
min_password: 6
max_password: 16
path:
base_upload_server_location: /working/resource/eduServer/
base_upload_server_location: E:\\eduServer
course_location: course
lesson_location: lesson
sl_location: sl
......@@ -127,8 +127,9 @@ global:
student_code_location: studentCode
other:
server_url: http://gwf.natapp.cc/eduServer
is_server_linux: 1
is_server_linux: 5
max_code_length: 15
open_office_home: D:/oppenOffice/openOffice
code:
admin: ROLE_1001
teacher: ROLE_1002
......
......@@ -55,7 +55,7 @@ spring:
add-mappings: false
redis:
host: 106.2.3.134
port: 7481
port: 7482
pool:
max-idle: 50
max-active: 1000
......@@ -129,6 +129,7 @@ global:
server_url: http://gwf.natapp.cc/eduServer
is_server_linux: 1
max_code_length: 15
open_office_home: D:/oppenOffice/openOffice
code:
admin: ROLE_1001
teacher: ROLE_1002
......
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