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.tasklistPage(page);
mv.addObject("taskList", taskList);
mv.addObject("pd", pd);
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,
@RequestParam(value = "taskId", required = false) 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.PmResultlistPage(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,
@RequestParam(value = "taskId", required = false) String taskId)
throws Exception {
Map<String, String> map = new HashMap<String, String>();
PageData pd = new PageData();
pd = this.getPageData();
//taskId = pd.getString("taskId");
JSONArray jsonArray = null;
try {
pd = this.getPageData();
pd.put("taskId", taskId);
page.setPd(pd);
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");
for (PageData pmResult : pmResultsForCharts) {
Series series = new Series(); 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);
seriesList.add(series);
} options.setCategorys(categoryList);
options.setSeries(seriesList); jsonArray = JSONArray.fromObject(options);
}
} catch (Exception e) {
logger.error(e.toString(), e);
} 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,
@RequestParam(value = "step", required = false) 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.java 20160712的更多相关文章

  1. Spring 3整合Quartz 2实现手动设置定时任务:新增,修改,删除,暂停和恢复(附带源码)

    摘要:在项目的管理功能中,对定时任务的管理有时会很常见.但一般定时任务配置都在xml中完成,包括cronExpression表达式,十分的方便.但是如果我的任务信息是保存在数据库的,想要动态的初始化, ...

  2. Go丨语言对MySQL数据库的增、删、改、查操作

    1.建立数据库名为: go_test_db 2.建表名为:userinfo 字段: uid int username varchar language varchar created varchar ...

  3. Collectors.toMap不允许Null Value导致NPE

    背景 线上某任务出现报警,报错日志如下: java.lang.NullPointerException: null at java.util.HashMap.merge(HashMap.java:12 ...

  4. 【记录】【springboot】动态定时任务ScheduledFuture,可添加、修改、删除

    这里只演示添加和删除任务的,因为修改就是删除任务再添加而已. 方便演示,任务就是每3秒打印 1.没有任务 后台 2.添加一个任务 3.再添加一个任务 4.删除一个任务 5.再添加一个任务 6.代码 运 ...

  5. SpringBoot+JPA+SpringSeurity+JWT

    目的:使用这个框架主要就是为了解决高并发环境下登陆操作对数据库及服务器的压力,同时能保证安全性: 加载时,SpringSecurity定义拦截器和添加两个Fitler: 登陆时,登陆成功,通过传入的信 ...

  6. SpringBoot整合quartz实现动态启动,停止定时任务功能

    注意:这个方法当程序重启之后会失效,所以必须将定时任务持久化到数据库,然后程序启动的时候重新把数据库的定时任务加载到quartz中 springboot程序启动初始化代码参考:https://www. ...

  7. Spark案例分析

    一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  8. TaskController.java-20160611

    package main.java.com.zte.controller.system; import java.io.PrintWriter;import java.util.ArrayList;i ...

  9. TaskController

    package main.java.com.zte.controller.system; import java.io.PrintWriter; import java.util.ArrayList; ...

随机推荐

  1. 解决Arcgis10.2.2中dbf文件用EXCEL打开乱码问题

    1.开始 -- 运行,输入”Regedit“,打开 注册表 . 2.如是用的是 10.x 版本 ArcGIS Desktop,定位到 ‘计算机\HKEY_CURRENT_USER\Software\E ...

  2. Windows上编译libtiff

    将libtiff 4.0.3解压到[工作目录]/tiff/tiff-4.0.3 对于Release,编辑tiff/tiff-4.0.3里面的nmake.opt如下选项,去掉注释: JPEG_SUPPO ...

  3. Android系列教程(十六) 在电脑上装Android

    [软件准备] 1.LiveAndroid v0.3 liveCD [点击下载] 2.VirtualBox 3.0.4 [点击下载]       [图片安装流程]       主要安装思路为:通过vir ...

  4. 如何构建Win32汇编的编程环境(ONEPROBLEM个人推荐)

      如何构建Win32汇编的编程环境(ONEPROBLEM个人推荐)1.首先要下载我提供的软件包(里面已经包含所有所需软件); 2.把它解压到D盘根目录下(如果需要安装在其它的地方,请注意设好路径); ...

  5. Android网络通信Volley框架源代码浅析(二)

    尊重原创 http://write.blog.csdn.net/postedit/25921795 在前面的一片文章Volley框架浅析(一)中我们知道在RequestQueue这个类中,有两个队列: ...

  6. matlab 文件遍历

    function MyGetFiles(F)path=F;filelist=dir(fullfile(path,'*.JPG'));n=length(filelist);for i=1:n f=str ...

  7. phpExcel导出文件时内存溢出的问题

    在使用PHPExcel导出文件时,经常会因为文件过大导致PHP内存溢出报错,为了解决这个问题,可以使用PHPExcel提供的参数进行优化.这里说的Excel文件过大并不一定是文件大小,更关键的在于文件 ...

  8. RabbitMQ Zabbix 监控

    RabbitMQ Zabbix 监控 参考: https://github.com/jasonmcintosh/rabbitmq-zabbix copy api.py list_rabbit_node ...

  9. 【HowTo ML】分类问题-&gt;神经网络入门

    非线性分类器(Non-linear hypotheses) 为什么使用非线性分类器 我们举几个栗子: 假如我们有一个数据空间如左上角坐标系所看到的,那么我们要的模型须要如右边公式所看到的的预測函数. ...

  10. Unity3d---> IEnumerator

    Unity3d---> IEnumerator 2013-04-18 10:24 2162人阅读 评论(0) 收藏 举报 Unity3dc# using UnityEngine; using S ...