备注 | 修改日期 | 修改人 |
创建版本 | 2022-06-30 09:51:10[当前版本] | 系统管理员 |
service
package com.farm.learn.utils; import com.farm.learn.domain.Classt; import com.farm.learn.service.ClasstServiceInter; import com.farm.util.spring.BeanFactory; /** * 保存课程到磁盘 * * @author macpl * */ public class ClassSaveToDisker { private static String curent_classid; /** * 0:完成,1:启动中,2:处理中, */ private static String state = "3"; private static String message = ""; private static ClasstServiceInter classTServiceImpl = (ClasstServiceInter) BeanFactory.getBean("classtServiceImpl"); /** * 执行导出 */ public static void toSave(final String classid) { if (state.equals("0")) { state = "1"; message = "启动中"; curent_classid = null; } Classt classt = classTServiceImpl.getClasstEntity(classid); if (curent_classid != null && !curent_classid.equals(classid)) { throw new RuntimeException("已有课程" + classt.getName() + "正在导出!"); } if (curent_classid != null && curent_classid.equals(classid)) { return; } Thread t = new Thread(new Runnable() { public void run() { curent_classid = classid; state = "2"; message = "处理中..."; try { for (int n = 1; n < 40; n++) { message = "处理中..." + n + "/" + 40; try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } finally { state = "0"; message = "完成"; } } }); t.start(); } /** * 获得导出进度状态 * * @return */ public static String getProgressState() { return state; } /** * 获得导出进度信息 * * @return */ public static String getProgressMessage() { return message; } }
controller
/** * 课程保存到服务器磁盘 * * @return */ @RequestMapping("/saveToDisk") @ResponseBody public Map<String, Object> saveToDisk(String classid, HttpSession session) { try { ClassSaveToDisker.toSave(classid); return ViewMode.getInstance().returnObjMode(); } catch (Exception e) { log.error(e.getMessage()); return ViewMode.getInstance().setError(e.getMessage(), e).returnObjMode(); } } /** * 加载保存到服务器磁盘的进度 * * @return */ @RequestMapping("/loadSDProgress") @ResponseBody public Map<String, Object> loadSDProgress(String classid, HttpSession session) { try { return ViewMode.getInstance().putAttr("state", ClassSaveToDisker.getProgressState()) .putAttr("message", ClassSaveToDisker.getProgressMessage()).returnObjMode(); } catch (Exception e) { log.error(e.getMessage()); return ViewMode.getInstance().setError(e.getMessage(), e).returnObjMode(); } }js
//导出到服务器磁盘 function saveToDisk() { var selectedArray = $(gridClasst).datagrid('getSelections'); if (selectedArray.length == 1) { // 有数据执行操作 var str = "是否立即将所选课程导出到服务器磁盘?"; $.messager.confirm(MESSAGE_PLAT.PROMPT, str, function(flag) { if (flag) { $.messager.progress({ text : '处理中...', interval : 0 }); var classid = $.farm.getCheckedIds(gridClasst, 'ID'); $.post('classt/saveToDisk.do?classid=' + classid, {}, function(flag) { var jsonObject = JSON.parse(flag, null); if (jsonObject.STATE == 0) { //显示导出进度 loadSTProcess(); } else { var str = MESSAGE_PLAT.ERROR_SUBMIT + jsonObject.MESSAGE; $.messager.alert(MESSAGE_PLAT.ERROR, str, 'error'); } }); } }); } else { $.messager.alert(MESSAGE_PLAT.PROMPT, MESSAGE_PLAT.CHOOSE_ONE_ONLY, 'info'); } } //加载远程进度(导出课程) function loadSTProcess() { var classid = $.farm.getCheckedIds(gridClasst, 'ID'); $.post('classt/loadSDProgress.do?classid=' + classid, {}, function(flag) { var state = flag.state; var message = flag.message; $(".progressbar-text").text(state + ":" + message); if (state == '0') { setTimeout(function() { $.messager.progress('close'); }, 1000); } else { setTimeout(function() { loadSTProcess() }, 1000); } }, 'json'); }