Browse Source

备份原有页面实时渲染轨迹还原原图的组件,增加新的轨迹还原原图组件,直接使用后台渲染URL,可以适用于图片另存打印

luoshi 6 years ago
parent
commit
aa3e66e34b

+ 13 - 0
stmms-common/src/main/java/cn/com/qmth/stmms/common/utils/PictureUrlBuilder.java

@@ -14,6 +14,8 @@ import org.apache.commons.lang3.StringUtils;
  */
 public class PictureUrlBuilder {
 
+    private static final String INNER_SHEET_URL_TEMPLATE = "/sheet/{0}/{1}-{2}";
+
     private static final String SHEET_URL_TEMPLATE = "/{0}-{1}/{2}/{3}-{4}.{5}";
 
     private static final String SLICE_URL_TEMPLATE = "/{0}-{1}/{2}/{3}-{4}.{5}";
@@ -28,6 +30,17 @@ public class PictureUrlBuilder {
 
     private static final String DOCUMENT_SUFFIX = "pdf";
 
+    public static List<String> getInnerSheetUrls(int examId, String examNumber, int count) {
+        List<String> list = new LinkedList<String>();
+        if (StringUtils.isNotBlank(examNumber) && count > 0) {
+            for (int i = 1; i <= count; i++) {
+                list.add(MessageFormat.format(INNER_SHEET_URL_TEMPLATE, String.valueOf(examId), examNumber,
+                        String.valueOf(i)));
+            }
+        }
+        return list;
+    }
+
     public static List<String> getSheetUrls(int examId, int campusId, String subjectCode, String examNumber,
             int count) {
         List<String> list = new LinkedList<String>();

+ 3 - 8
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/ScoreController.java

@@ -21,8 +21,6 @@ import cn.com.qmth.stmms.admin.dto.ExamStudentDTO;
 import cn.com.qmth.stmms.admin.dto.ScoreEditDTO;
 import cn.com.qmth.stmms.admin.dto.ScoreExportDTO;
 import cn.com.qmth.stmms.admin.thread.ScoreCalculateThread;
-import cn.com.qmth.stmms.biz.campus.model.Campus;
-import cn.com.qmth.stmms.biz.campus.service.CampusService;
 import cn.com.qmth.stmms.biz.exam.model.ExamPackage;
 import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;
 import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
@@ -50,9 +48,6 @@ import net.sf.json.JSONObject;
 @RequestMapping("/admin/exam/score")
 public class ScoreController extends BaseExamController {
 
-    @Autowired
-    private CampusService campusService;
-
     @Autowired
     private ExamSubjectService subjectService;
 
@@ -274,9 +269,9 @@ public class ScoreController extends BaseExamController {
     }
 
     private void buildSheetUrl(ExamStudent student) {
-        Campus campus = campusService.findBySchoolAndName(student.getSchoolId(), student.getCampusName());
-        student.setSheetUrls(PictureUrlBuilder.getSheetUrls(student.getExamId(), campus.getId(),
-                student.getSubjectCode(), student.getExamNumber(), student.getSheetCount()));
+        // 改为内部原图浏览地址,直接附带标记内容
+        student.setSheetUrls(PictureUrlBuilder.getInnerSheetUrls(student.getExamId(), student.getExamNumber(),
+                student.getSheetCount()));
     }
 
     private void buildPackageUrl(ExamStudent student) {

+ 6 - 6
stmms-web/src/main/java/cn/com/qmth/stmms/api/controller/PictureController.java

@@ -41,7 +41,7 @@ import cn.com.qmth.stmms.common.utils.PictureUrlBuilder;
 import net.sf.json.JSONObject;
 
 @Controller("pictureController")
-@RequestMapping("/api")
+@RequestMapping("/")
 public class PictureController {
 
     protected static final Logger log = LoggerFactory.getLogger(PictureController.class);
@@ -98,9 +98,9 @@ public class PictureController {
         }
     }
 
-    @RequestMapping("/sheets/{examId}")
+    @RequestMapping("/sheet/{examId}/save")
     @ResponseBody
-    public Object getAllSheet(HttpServletResponse response, @PathVariable Integer examId,
+    public Object saveAllSheet(HttpServletResponse response, @PathVariable Integer examId,
             @RequestParam(required = false, defaultValue = "true") Boolean withTag) throws IOException {
         JSONObject result = new JSONObject();
         Exam exam = examService.findById(examId);
@@ -115,15 +115,15 @@ public class PictureController {
             return result;
         }
         if (lockService.trylock(LockType.EXAM, examId)) {
-            taskExecutor.submit(new SheetDownloadThread(examId, saveDir, this, studentService, lockService));
+            taskExecutor.submit(new SheetDownloadThread(examId, saveDir, withTag, this, studentService, lockService));
         }
         result.accumulate("running", lockService.isLocked(LockType.EXAM, examId));
         return result;
     }
 
-    @RequestMapping("/sheets/{examId}/status")
+    @RequestMapping("/sheet/{examId}/status")
     @ResponseBody
-    public Object getAllSheet(HttpServletResponse response, @PathVariable Integer examId) throws IOException {
+    public Object saveAllSheetStatus(HttpServletResponse response, @PathVariable Integer examId) throws IOException {
         JSONObject result = new JSONObject();
         result.accumulate("running", lockService.isLocked(LockType.EXAM, examId));
         return result;

+ 9 - 7
stmms-web/src/main/java/cn/com/qmth/stmms/api/utils/SheetDownloadThread.java

@@ -19,22 +19,23 @@ public class SheetDownloadThread implements Runnable {
 
     public static final Logger log = LoggerFactory.getLogger(SheetDownloadThread.class);
 
-    public static final String PREFIX = "tag-sheet";
-
     private Integer examId;
 
     private File baseDir;
 
+    private Boolean withTag;
+
     private PictureController controller;
 
     private ExamStudentService studentService;
 
     private LockService lockService;
 
-    public SheetDownloadThread(Integer examId, String dir, PictureController controller,
+    public SheetDownloadThread(Integer examId, String dir, Boolean withTag, PictureController controller,
             ExamStudentService studentService, LockService lockService) {
         this.examId = examId;
-        this.baseDir = new File(dir, PREFIX);
+        this.baseDir = new File(dir);
+        this.withTag = withTag;
         this.controller = controller;
         this.studentService = studentService;
         this.lockService = lockService;
@@ -56,7 +57,7 @@ public class SheetDownloadThread implements Runnable {
             }
 
             for (ExamStudent student : query.getResult()) {
-                log.warn("write for student: " + student.getExamNumber());
+                log.info("write for student: " + student.getExamNumber());
                 for (int i = 1; i <= student.getSheetCount(); i++) {
                     download(student, i);
                 }
@@ -72,9 +73,10 @@ public class SheetDownloadThread implements Runnable {
         try {
             file.getParentFile().mkdirs();
             BufferedImage image = SheetBuildUtil.buildSheetImage(controller.getSheetImage(student, index),
-                    studentService.buildSheetTags(student).get(index));
+                    withTag != null && withTag.booleanValue() ? studentService.buildSheetTags(student).get(index)
+                            : null);
             ImageIO.write(image, "jpg", file);
-            log.warn("write sheet file success: " + file.getAbsolutePath());
+            log.info("write sheet file success: " + file.getAbsolutePath());
         } catch (Exception e) {
             log.error("write sheet file error: " + file.getAbsolutePath(), e);
         }

+ 12 - 31
stmms-web/src/main/webapp/WEB-INF/views/include/sheetTagView.jsp

@@ -10,24 +10,21 @@ $(document).ready(function() {
 });
 
 function initSheetTagPopover(id, title, sheetServer, sheetUrl, answerUrl) {
-    $.post('${ctx}/admin/exam/student/sheetTag', {id: id}, function(tags){
-        //暂时屏蔽答案PDF显示
-        initSheetTagPopoverContent(sheetServer, sheetUrl.split(','), '', tags, function(){
-            sheetTagModal.setTitle(title);
-            sheetTagModal.setContent($('#sheet-tag-content'));
-        });
-    });
-    
     $('#sheet-tag-tab-nav').empty();
     $('#sheet-tag-tab-content').empty();
     
 	sheetTagModal.setWidth($(window).width()*0.9);
 	sheetTagModal.setHeight($(window).height()*0.85);
 	sheetTagModal.setTitle('正在加载');
+	//暂时屏蔽答案PDF显示
+    initSheetTagPopoverContent(sheetServer, sheetUrl.split(','), '', function(){
+        sheetTagModal.setTitle(title);
+        sheetTagModal.setContent($('#sheet-tag-content'));
+    });
 	sheetTagModal.open();
 }
 
-function initSheetTagPopoverContent(sheetServer, sheetUrls, answerUrl, tags, callback){
+function initSheetTagPopoverContent(sheetServer, sheetUrls, answerUrl, callback){
     var leftDiv = $('#sheet-tag-left');  
     var rightDiv = $('#sheet-tag-right');
     var tabNav = $('#sheet-tag-tab-nav');
@@ -46,34 +43,18 @@ function initSheetTagPopoverContent(sheetServer, sheetUrls, answerUrl, tags, cal
 
     tabNav.empty();
     tabContent.empty();
-    var loadCount=0;
 	for(var i=0;i<sheetUrls.length;i++){
 		tabNav.append($('<li><a href="#sheet_tag_'+i+'" data-toggle="tab">第'+(i+1)+'页</a></li>'));
-		tabContent.append($('<div class="tab-pane fade" id="sheet_tag_'+i+'" style="overflow: scroll;"><canvas id="sheet-tag-canvas-'+i+'"></canvas></div>'));
-	
+		tabContent.append($('<div class="tab-pane fade" id="sheet_tag_'+i+'" style="overflow: scroll;"></div>'));
 		var image = new Image();
-		image.tagList = tags[i+1] || [];
-		image.canvas = $('#sheet-tag-canvas-'+i)[0];
+		image.src = sheetServer + sheetUrls[i];
 		image.onload = function(){
-		    this.canvas.width = Math.min(this.width, tabContent.width()>0?tabContent.width():($(window).width()*0.9-40));
-		    this.scaleRate = this.canvas.width / this.width;
-		    this.canvas.height = this.height * this.scaleRate;
-		    this.ctx = this.canvas.getContext("2d");
-		    this.ctx.drawImage(this, 0, 0, this.width, this.height, 0, 0, this.canvas.width, this.canvas.height);
-		    this.ctx.font ="20px Arial";
-            this.ctx.fillStyle ='red';
-		    for(var j=0;j<this.tagList.length;j++) {
-		        var tag = this.tagList[j];
-		        this.ctx.fillText(tag.content, tag.left * this.scaleRate, tag.top * this.scaleRate);
-		    }
-		    loadCount++;
-		    if(loadCount==sheetUrls.length) {
-		        callback();
-		    }
-		};
-		image.src = sheetServer + sheetUrls[i] + '?' + new Date().getTime();
+		    this.width = Math.min(this.width, tabContent.width()>0?tabContent.width():($(window).width()*0.9-40));
+		}
+		$(image).appendTo($('#sheet_tag_'+i));
 	}
 	tabNav.find('a:first').trigger('click');
+	callback();
 }
 </script>
 <div id="sheet-tag-content" class="container-fluid" style="display:none">

+ 91 - 0
stmms-web/src/main/webapp/WEB-INF/views/include/sheetTagViewCanvas.jsp

@@ -0,0 +1,91 @@
+<%@ page contentType="text/html;charset=UTF-8"%>
+<link rel="stylesheet" type="text/css" href="${ctxStatic}/jBox/Source/jBox.css">
+<script type="text/javascript" src="${ctxStatic}/jBox/Source/jBox.min.js"></script>
+<script type="text/javascript">
+var sheetTagModal = new jBox('Modal');
+var sheetTagContainer = $('#sheet-tag-content');
+
+$(document).ready(function() {
+    sheetTagContainer.find('iframe').height($(window).height()*0.83);
+});
+
+function initSheetTagPopover(id, title, sheetServer, sheetUrl, answerUrl) {
+    $.post('${ctx}/admin/exam/student/sheetTag', {id: id}, function(tags){
+        //暂时屏蔽答案PDF显示
+        initSheetTagPopoverContent(sheetServer, sheetUrl.split(','), '', tags, function(){
+            sheetTagModal.setTitle(title);
+            sheetTagModal.setContent($('#sheet-tag-content'));
+        });
+    });
+    
+    $('#sheet-tag-tab-nav').empty();
+    $('#sheet-tag-tab-content').empty();
+    
+	sheetTagModal.setWidth($(window).width()*0.9);
+	sheetTagModal.setHeight($(window).height()*0.85);
+	sheetTagModal.setTitle('正在加载');
+	sheetTagModal.open();
+}
+
+function initSheetTagPopoverContent(sheetServer, sheetUrls, answerUrl, tags, callback){
+    var leftDiv = $('#sheet-tag-left');  
+    var rightDiv = $('#sheet-tag-right');
+    var tabNav = $('#sheet-tag-tab-nav');
+    var tabContent = $('#sheet-tag-tab-content');
+    if(answerUrl!=undefined && answerUrl.length>0){
+        rightDiv.removeClass('span12');
+        rightDiv.addClass('span6');
+		leftDiv.find('iframe').attr('src', answerUrl);
+		leftDiv.show();
+	}else{
+	    rightDiv.removeClass('span6');
+	    rightDiv.addClass('span12');
+		leftDiv.find('iframe').attr('src', '');
+		leftDiv.hide();
+	}
+
+    tabNav.empty();
+    tabContent.empty();
+    var loadCount=0;
+	for(var i=0;i<sheetUrls.length;i++){
+		tabNav.append($('<li><a href="#sheet_tag_'+i+'" data-toggle="tab">第'+(i+1)+'页</a></li>'));
+		tabContent.append($('<div class="tab-pane fade" id="sheet_tag_'+i+'" style="overflow: scroll;"><canvas id="sheet-tag-canvas-'+i+'"></canvas></div>'));
+	
+		var image = new Image();
+		image.tagList = tags[i+1] || [];
+		image.canvas = $('#sheet-tag-canvas-'+i)[0];
+		image.onload = function(){
+		    this.canvas.width = Math.min(this.width, tabContent.width()>0?tabContent.width():($(window).width()*0.9-40));
+		    this.scaleRate = this.canvas.width / this.width;
+		    this.canvas.height = this.height * this.scaleRate;
+		    this.ctx = this.canvas.getContext("2d");
+		    this.ctx.drawImage(this, 0, 0, this.width, this.height, 0, 0, this.canvas.width, this.canvas.height);
+		    this.ctx.font ="20px Arial";
+            this.ctx.fillStyle ='red';
+		    for(var j=0;j<this.tagList.length;j++) {
+		        var tag = this.tagList[j];
+		        this.ctx.fillText(tag.content, tag.left * this.scaleRate, tag.top * this.scaleRate);
+		    }
+		    loadCount++;
+		    if(loadCount==sheetUrls.length) {
+		        callback();
+		    }
+		};
+		image.src = sheetServer + sheetUrls[i] + '?' + new Date().getTime();
+	}
+	tabNav.find('a:first').trigger('click');
+}
+</script>
+<div id="sheet-tag-content" class="container-fluid" style="display:none">
+	<div class="row-fluid">
+		<div class="span6" style="overflow:scroll" id="sheet-tag-left">
+			<iframe src="" border="0" scrolling="yes" width="100%"></iframe>
+		</div>
+		<div class="span6" id="sheet-tag-right">
+			<ul class="nav nav-tabs" id="sheet-tag-tab-nav">
+			</ul>
+			<div class="tab-content" id="sheet-tag-tab-content">
+			</div>
+		</div>
+	</div>
+</div>

+ 1 - 13
stmms-web/src/main/webapp/WEB-INF/views/include/sheetView.jsp

@@ -11,16 +11,9 @@
 <script type="text/javascript">
 var sheetModal = new jBox('Modal');
 $(document).ready(function() {
-	//$('#sheet-view-content').find('object').each(function(index, obj){
-		//obj.width = $(window).width()*0.4;
-		//obj.height = $(window).height()*0.83;
-	//});
 	$('#left-answer-div').find('iframe').height($(window).height()*0.83);
 });
 function initSheetPopover(title, sheetServer, sheetUrl, answerUrl) {
-	//if(sheetModal!=undefined){
-	//	sheetModal.destroy();
-	//}
 	initSheetPopoverContent(sheetServer, sheetUrl.split(','), answerUrl);
 
 	sheetModal.setWidth($(window).width()*0.9);
@@ -31,15 +24,11 @@ function initSheetPopover(title, sheetServer, sheetUrl, answerUrl) {
 }
 function initSheetPopoverContent(sheetServer, sheetUrls, answerUrl){
 	if(answerUrl!=undefined && answerUrl.length>0){
-		//$('#left-answer-div').find('#object-src').val(answerUrl+'#scrollbar=1');
-		//$('#left-answer-div').find('#object-data').attr('data',answerUrl+'#scrollbar=1');
 		$('#right-sheet-div').removeClass('span12');
 		$('#right-sheet-div').addClass('span6');
 		$('#left-answer-div').find('iframe').attr('src', answerUrl);
 		$('#left-answer-div').show();
 	}else{
-		//$('#left-answer-div').find('#object-src').val('');
-		//$('#left-answer-div').find('#object-data').attr('data','');
 		$('#right-sheet-div').removeClass('span6');
 		$('#right-sheet-div').addClass('span12');
 		$('#left-answer-div').find('iframe').attr('src', '');
@@ -50,8 +39,7 @@ function initSheetPopoverContent(sheetServer, sheetUrls, answerUrl){
 	for(var i=0;i<sheetUrls.length;i++){
 		var url = sheetServer+sheetUrls[i];
 		$('#right-nav').append('<li><a href="#sheet_'+i+'" data-toggle="tab">第'+(i+1)+'页</a></li>');
-		/* $('#right-content').append('<div class="tab-pane fade" id="sheet_'+i+'"><img src="'+url+'"/></div>') */
-
+		
 		var pane = $('<div class="tab-pane fade" id="sheet_'+i+'" style="overflow: hidden;"><div class="image-holder" style="position: relative;width:100%"></div></div>').appendTo($('#right-content'));
 		pane.find('.image-holder').height($(window).height()*0.8);
 		pane.find('.image-holder').iviewer({

+ 3 - 8
stmms-web/src/main/webapp/WEB-INF/views/modules/exam/scoreList.jsp

@@ -180,12 +180,6 @@
 	<%@include file="/WEB-INF/views/include/imageView.jsp" %>
 <script type="text/javascript">
 $(document).ready(function() {
-    /* new jBox('Image', {
-    	imageFade: 0,
-    	delayOpen: 0,
-    	delayClose: 0,
-    	maxHeight: $(window).height()*0.88
-    }); */
 	$("#searchForm").validate();
     
     $('.detail-link').click(function(){
@@ -193,8 +187,9 @@ $(document).ready(function() {
     	window.location.href = url;
     });
     $('.sheet-link').click(function(){
-    	initSheetTagPopover($(this).attr('data-id'), $(this).attr('data-title'), '${imageServer}', $(this).attr('data-sheet-url'), $(this).attr('data-answer-url'));
-    	return false;
+    	initSheetTagPopover($(this).attr('data-id'), $(this).attr('data-title'), '', $(this).attr('data-sheet-url'), $(this).attr('data-answer-url'));
+    	//initSheetPopover($(this).attr('data-title'), '', $(this).attr('data-sheet-url'));
+        return false;
     });
     $('.package-link').click(function(){
     	initImagePopover($(this).attr('data-title'), '${packageServer}', $(this).attr('data-image-url'));