TaskController
package main.java.com.zte.controller.system; import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import javax.annotation.Resource; import net.sf.json.JSONArray; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView; import main.java.com.zte.controller.base.BaseController;
import main.java.com.zte.entity.Page;
import main.java.com.zte.entity.Task;
import main.java.com.zte.entity.charts.Option;
import main.java.com.zte.entity.charts.Series;
import main.java.com.zte.service.TaskService;
import main.java.com.zte.util.AppUtil;
import main.java.com.zte.util.Const;
import main.java.com.zte.util.DateUtil;
import main.java.com.zte.util.FileUpload;
import main.java.com.zte.util.ObjectExcelView;
import main.java.com.zte.util.PageData;
import main.java.com.zte.util.PathUtil;
import main.java.com.zte.util.Tools; /**
* 任务Controller
*
* @author 10183302
*
*/
@Controller
@RequestMapping(value = "/task")
public class TaskController extends BaseController { @Resource(name = "taskService")
private TaskService taskService; /**
* 显示任务列表
*
* @param model
* @return
*/
@RequestMapping(value = "/list")
public ModelAndView list(Page page) throws Exception {
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
try {
pd = this.getPageData();
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
String userName = (String) session
.getAttribute(Const.SESSION_USERNAME); // 获取session中的用户名
pd.put(Const.SESSION_USERNAME, userName);
String keyw = pd.getString("keyword");
if (Tools.notEmpty(keyw)) {
keyw = keyw.trim();
pd.put("keyw", keyw);
}
page.setPd(pd);
List<PageData> taskList = taskService.listTaskPage(page);
mv.addObject("taskList", taskList);
mv.setViewName("task/task_list");
} catch (Exception e) {
logger.error(e.toString(), e);
}
return mv;
} /**
* 请求新增任务页面
*
* @param model
* @return
*/
@RequestMapping(value = "/toAdd")
public ModelAndView toAdd() throws Exception {
ModelAndView mv = this.getModelAndView();
try {
PageData pd = new PageData();
pd = this.getPageData();
String ffile = DateUtil.getDays();
String filePath = PathUtil.getClasspath() + Const.FILEPATH_LOG
+ ffile; // 文件上传路径
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
String userName = (String) session
.getAttribute(Const.SESSION_USERNAME); // 获取session中的用户名
String taskTime = DateUtil.getTime().toString();
pd.put("taskId", this.get32UUID());
pd.put("taskNumber", taskTime);
pd.put("name", "分析任务" + Tools.date2Str(new Date()));
pd.put("owner", userName);
pd.put("time", Tools.date2Str(new Date()));
pd.put("logPath", filePath);
pd.put("logURL", filePath);
pd.put("type", "离线任务"); // 状态
pd.put("status", "待启动"); // 状态
taskService.add(pd);
mv.addObject("msg", "success");
} catch (Exception e) {
logger.error(e.toString(), e);
mv.addObject("msg", "failed");
}
mv.setViewName("task/task_add");
return mv;
} /**
* 新增
*/
@RequestMapping(value = "/save")
@ResponseBody
public Object save(@RequestParam(required = false) MultipartFile file)
throws Exception {
logBefore(logger, "上传日志");
PageData pd = new PageData();
Map<String, String> map = new HashMap<String, String>();
try {
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
String userName = (String) session
.getAttribute(Const.SESSION_USERNAME); // 获取session中的用户名
String ffile = DateUtil.getDays(), fileName = "", filePath = "";
if (null != file && !file.isEmpty()) {
filePath = PathUtil.getClasspath() + Const.FILEPATH_LOG + ffile; // 文件上传路径
fileName = FileUpload.fileUp(file, filePath, this.get32UUID()); // 执行上传
System.out.println("文件名称:" + file.getName());
System.out.println("文件路径:" + filePath);
} else {
System.out.println("上传失败");
}
pd.put("logId", this.get32UUID()); // 主键
pd.put("taskNumber", getTaskNumber()); // 任务编号
pd.put("userName", userName); // 上传者
pd.put("fileName", fileName); // 文件名
pd.put("filePath", filePath + "/" + fileName); // 路径
pd.put("createTime", Tools.date2Str(new Date())); // 创建时间
pd.put("remarks", ""); // 备注
taskService.saveLogInfo(pd);
map.put("result", "ok");
} catch (Exception e) {
logger.error(e.toString(), e);
}
return AppUtil.returnObject(pd, map);
} public static String getTaskNumber() {
int r1 = (int) (Math.random() * (10));// 产生2个0-9的随机数
int r2 = (int) (Math.random() * (10));
long now = System.currentTimeMillis();// 一个13位的时间戳
String taskId = String.valueOf(now) + String.valueOf(r1)
+ String.valueOf(r2);// 任务ID
return taskId;
} public static void main(String[] args) {
System.out.println(getTaskNumber());
} /**
* 保存任务信息
*
* @param menu
* @param model
* @return
*/
@RequestMapping(value = "/add")
public ModelAndView add(Task task) throws Exception {
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
pd = this.getPageData();
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
String userName = (String) session.getAttribute(Const.SESSION_USERNAME); // 获取session中的用户名
String taskName = pd.getString("taskName").trim();
String taskTime = DateUtil.getTime().toString();
try {
pd.put("taskTime", taskTime);
pd.put("taskStatus", "待启动"); // 状态
// 目录格式:根目录/userName/taskName-时间
pd.put("task_dir", Const.TASK_ROOT_DIR + userName + "/" + taskName
+ "-" + taskTime);
taskService.add(pd);
mv.addObject("msg", "success");
} catch (Exception e) {
logger.error(e.toString(), e);
mv.addObject("msg", "failed");
}
mv.setViewName("save_result");
return mv;
} /**
* 请求编辑页面
*
* @param
* @return
*/
@RequestMapping(value = "/toEdit")
public ModelAndView toEdit(String taskId) throws Exception {
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
try {
pd = this.getPageData();
pd.put("taskId", taskId);
List<PageData> taskList = taskService.getTaskByTaskId(pd);
mv.addObject("taskList", taskList);
mv.addObject("pd", pd);
mv.setViewName("task/task_edit");
} catch (Exception e) {
logger.error(e.toString(), e);
}
return mv;
} /**
* 保存编辑
*
* @param
* @return
*/
@RequestMapping(value = "/edit")
public ModelAndView edit() throws Exception {
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
try {
pd = this.getPageData();
pd = taskService.edit(pd);
mv.addObject("msg", "success");
} catch (Exception e) {
logger.error(e.toString(), e);
mv.addObject("msg", "failed");
}
mv.setViewName("save_result");
return mv;
} /**
* 获取任务分析结果
*
* @param
* @return
*/
@RequestMapping(value = "/reslut")
public ModelAndView reslut(Page page, String taskId) throws Exception {
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
try {
pd = this.getPageData();
pd.put("taskId", taskId);
page.setPd(pd);
List<PageData> pmResults = taskService.listPmResult(page);
mv.addObject("pmResults", pmResults);
mv.addObject("pd", pd);
if (!pmResults.isEmpty()) {
mv.addObject("msg", "success");
}
mv.setViewName("pm/result_chart");
} catch (Exception e) {
logger.error(e.toString(), e);
}
return mv;
} /**
* 获取任务分析结果
*
* @param
* @return
*/
@RequestMapping(value = "/result_charts")
@ResponseBody
public String result_charts(Page page) throws Exception {
Map<String, String> map = new HashMap<String, String>();
PageData pd = new PageData();
pd = this.getPageData();
String taskId = pd.getString("taskId");
JSONArray jsonArray = null;
try {
pd = this.getPageData();
pd.put("taskId", taskId);
page.setPd(pd);
// List<PageData> pmResults = taskService.listPmResult(page);
List<PageData> pmResultsForCharts = taskService
.listPmResultForCharts(page);
List<Series> seriesList = new ArrayList<Series>();
// 存放类别数据
List<String> categoryList = new ArrayList<String>(); // 存放所有
Option options = new Option(); if (!pmResultsForCharts.isEmpty()) {
map.put("msg", "success");
System.out.println("pmResultsForCharts"+pmResultsForCharts); int i=0;
for (PageData pmResult : pmResultsForCharts) {
Series series = new Series();
System.out.println("pmResultsForCharts["+i+"]"+pmResult);
++i; String[] categorys = pmResult.getString("CATEGORY").trim().split(",");
for(String category:categorys){
if(!categoryList.contains(category.trim())){
categoryList.add(category.trim());
}
} series.setName(pmResult.getString("NEID").trim());
series.setType("bar"); List<Double> datas = new ArrayList<Double>();
String[] pmDatas = pmResult.getString("DATAS").split(",");
for (String pmData : pmDatas) {
Double data = Double.valueOf(pmData.trim());
datas.add(data);
}
series.setData(datas); System.out.println("series["+i+"]"+series);
seriesList.add(series);
System.out.println("seriesList["+i+"]"+seriesList);
} options.setCategorys(categoryList);
options.setSeries(seriesList);
System.out.println("options:"+options); jsonArray = JSONArray.fromObject(options);
}
} catch (Exception e) {
logger.error(e.toString(), e);
}
System.out.println("jsonObject:" + jsonArray);
return jsonArray.toString();
} /**
* 获取任务分析结果
*
* @param
* @return
*/
@RequestMapping(value = "/echarts")
@ResponseBody
public String echarts(Page page) throws Exception {
return null;
} /**
* 获取单个节点上报信息
*
* @param
* @return
*/
@RequestMapping(value = "/pm_detail")
public ModelAndView pmDetail(Page page, String step) throws Exception {
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
try {
pd = this.getPageData();
String stepName = null;
switch (step) {
case "1":
stepName = Const.RECEIVE_REPORT_MSG_TIME;
break;
case "2":
stepName = Const.PROCESS_GET_FILE_TIME;
break;
case "3":
stepName = Const.PROCESS_PARSE_TIME;
break;
case "5":
stepName = Const.PROCESS_STORE_TIME;
break;
case "7":
stepName = Const.PROCESS_FINISH_TIME;
break;
} pd.put("stepName", stepName);
page.setPd(pd);
List<PageData> poResultList = taskService.listPOResult(page);
mv.addObject("poResultList", poResultList);
mv.addObject("pd", pd);
if (!poResultList.isEmpty()) {
mv.addObject("msg", "success");
}
mv.setViewName("pm/po_charts");
} catch (Exception e) {
logger.error(e.toString(), e);
}
return mv;
} /**
* 删除任务
*
* @param task_id
* @param out
*/
@RequestMapping(value = "/delete")
public void delete(@RequestParam String task_id, PrintWriter out)
throws Exception {
try {
taskService.deleteByTaskId(task_id);
out.write("success");
out.flush();
out.close();
} catch (Exception e) {
logger.error(e.toString(), e);
} } /*
* 导出到excel
*
* @return
*/
@RequestMapping(value = "/excel")
public ModelAndView exportExcel() {
logBefore(logger, "导出Pictures到excel");
ModelAndView mv = new ModelAndView();
try {
Map<String, Object> dataMap = new HashMap<String, Object>();
List<String> titles = new ArrayList<String>();
titles.add("编号"); //
titles.add("任务名称"); //
titles.add("创建人"); //
titles.add("创建时间"); //
titles.add("日志路径"); //
titles.add("类型"); //
titles.add("状态"); //
dataMap.put("titles", titles); Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
String userName = (String) session
.getAttribute(Const.SESSION_USERNAME); // 获取session中的用户名
List<Task> taskList = taskService.listTaskByUname(userName);
List<PageData> varList = new ArrayList<PageData>(); for (int i = 0; i < taskList.size(); i++) {
PageData vpd = new PageData();
vpd.put("var1", taskList.get(i).getNumber()); //
vpd.put("var2", taskList.get(i).getName()); //
vpd.put("var3", taskList.get(i).getOwner()); //
vpd.put("var4", taskList.get(i).getTime()); //
vpd.put("var5", taskList.get(i).getLogPath()); //
vpd.put("var6", taskList.get(i).getType()); //
vpd.put("var7", taskList.get(i).getStatus()); //
varList.add(vpd);
}
dataMap.put("varList", varList);
ObjectExcelView erv = new ObjectExcelView();
mv = new ModelAndView(erv, dataMap);
} catch (Exception e) {
logger.error(e.toString(), e);
}
return mv;
}
}
TaskController的更多相关文章
- TaskController.java-20160611
package main.java.com.zte.controller.system; import java.io.PrintWriter;import java.util.ArrayList;i ...
- TaskController.java 20160712
package main.java.com.zte.controller.system; import java.io.PrintWriter; import java.util.ArrayList; ...
- MapReduce剖析笔记之六:TaskTracker初始化任务并启动JVM过程
在上面一节我们分析了JobTracker调用JobQueueTaskScheduler进行任务分配,JobQueueTaskScheduler又调用JobInProgress按照一定顺序查找任务的流程 ...
- JavaScript学习总结(一)——延迟对象、跨域、模板引擎、弹出层、AJAX示例
一.AJAX示例 AJAX全称为“Asynchronous JavaScript And XML”(异步JavaScript和XML) 是指一种创建交互式网页应用的开发技术.改善用户体验,实现无刷新效 ...
- Autofac 依赖注入
介绍 Autofac是一款IOC框架,很轻量级性能非常高,自动注入很给力. NuGet Autofac:Autofac控制反转容器核心 Autofac.MVC5:提供IDependencyResolv ...
- hadoop2.7.3配置文件中过时的属性
过时的属性:Deprecated Properties 该列表保存于:hadoop-2.7.3-src\hadoop-common-project\hadoop-common\src\site\mar ...
- [后端人员耍前端系列]KnockoutJs篇:使用KnockoutJs+Bootstrap实现分页
一.引言 由于最近公司的系统需要改版,改版的新系统我打算使用KnockoutJs来制作Web前端.在做的过程中,遇到一个问题——如何使用KnockoutJs来完成分页的功能.在前一篇文章中并没有介绍使 ...
- 【译】采用MVC模式创建一个简单的javascript App
原文标题:Build A Simple Javascript App The MVC Way 作者:joshcrawmer4 翻译人:huansky 初次翻译,翻译的不好,还请见谅 JavaScrip ...
- WordCount示例深度学习MapReduce过程(1)
我们都安装完Hadoop之后,按照一些案例先要跑一个WourdCount程序,来测试Hadoop安装是否成功.在终端中用命令创建一个文件夹,简单的向两个文件中各写入一段话,然后运行Hadoop,Wou ...
随机推荐
- kafka分区原理图
一个Topic的多个分区,被分布在kafka集群中的多个server上.每一个分区都有一个server为"leader";leader负责全部的读写操作,假设leader失效,那么 ...
- UITextView in iOS7 doesn't scroll
UITextView in iOS7 has been really weird. As you type and are entering the last line of your UITextV ...
- 数据校验DWZ与validator
在做系统时经常会用到数据校验,数据校验可以自己写,也可以用现在成的,现在记录下两种类库使用方法, validato <!DOCTYPE HTML PUBLIC "-//W3C//DTD ...
- linux统计文件夹内文件数
for dir in `find ./ -type d ` ;do echo -n "$dir " ;find $dir -type f | wc -l ;echo " ...
- java静态代码分析工具infer
infer是一个静态代码分析工具,探测bugs. 主要支持Java.C/C++ 安装:brew install infer 在线展示:https://codeboard.io/projects/115 ...
- from __future__ import print_function
1.在python2.x的环境是使用下面语句,则第二句语法检查通过,第三句语法检查失败 from __future__ import print_function priint('good') pri ...
- C#(64位系统) 解决"未能加载文件或程序集,或它的某一个依赖项..."
这个问题通常出在引用第三方DLL或者自己以前写的DLL. 在64位系统下则可能会出现这种问题. 今天下载MySQLDriverCS后引用遍出现了这个问题,参考了一些文档,下面给出解决方法: 将项目的生 ...
- python 抓取alexa数据
要抓取http://www.alexa.cn/rank/baidu.com网站的排名信息:例如抓取以下信息: 需要微信扫描登录 因为这个网站抓取数据是收费,所以就利用网站提供API服务获取json信息 ...
- Charles Proxy for Mac & Windows (4.1.3)破解激活工具
1.简介 2017年7月10日更新本博客,Charles已经更新到了4.1.3版本,并对应地给出破解jar包. Charles是一个Mac和Windows平台都可以使用的抓包工具,它的破解激活非常简单 ...
- 【SDN】SDN相关资料--了解一下电信领域的SDN
SDN相关资料 数据中心架构下ospf bgp如何选择及优缺点? - 数据中心 - 知乎 组播扩展OSPF_百度百科 carrier.huawei.com/cn/products/fixed-netw ...