123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- package com.yihu.hos.datacollect.controller;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.fasterxml.jackson.databind.node.ArrayNode;
- import com.yihu.hos.common.Services;
- import com.yihu.hos.core.datatype.CollectionUtil;
- import com.yihu.hos.datacollect.model.RsJobConfig;
- import com.yihu.hos.datacollect.service.DatacollectManager;
- import com.yihu.hos.resource.service.StdService;
- import com.yihu.hos.standard.service.adapter.AdapterSchemeService;
- import com.yihu.hos.system.service.DatasourceManager;
- import com.yihu.hos.web.framework.constant.DateConvert;
- import com.yihu.hos.web.framework.model.ActionResult;
- import com.yihu.hos.web.framework.model.Result;
- import com.yihu.hos.web.framework.util.controller.BaseController;
- import org.apache.commons.beanutils.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import java.lang.reflect.Method;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * 数据采集配置页面
- * Created by hzp on 2015/8/12.
- */
- @RequestMapping("/datacollect")
- @Controller("dataCollectController")
- public class DataCollectController extends BaseController {
- @Resource(name = Services.Datacollect)
- DatacollectManager datacollect;
- @Resource(name = StdService.BEAN_ID)
- StdService stdService;
- @Resource(name = Services.Datasource)
- DatasourceManager datasource;
- @Resource(name = AdapterSchemeService.BEAN_ID)
- private AdapterSchemeService adapterSchemeService;
- @Autowired
- private ObjectMapper objectMapper;
- /****************************
- * 任务管理
- ************************************************/
- /*
- 任务配置
- */
- @RequestMapping("configJob")
- public String configJob(Model model) {
- model.addAttribute("contentPage", "/datacollect/configJob");
- return "partView";
- }
- /*
- 任务新增/编辑
- */
- @RequestMapping("editorJob")
- public String editorJob(Model model, String jobId) {
- try {
- //是否编辑
- if (jobId != null && jobId.length() > 0) {
- //获取任务信息
- RsJobConfig job = datacollect.getJobById(jobId);
- model.addAttribute("model", job);
- String cron = datacollect.getCronByJobId(jobId);
- model.addAttribute("cronExpression", cron);
- }
- //获取方案列表
- List data = stdService.getSchemeVersion();
- String jsonlist = objectMapper.writeValueAsString(data);
- ArrayNode jsonArray = objectMapper.readValue(jsonlist,ArrayNode.class);
- model.addAttribute("schemeList", "{\"detailModelList\":" + (CollectionUtil.isEmpty(data) ? "[]" : jsonArray) + "}");
- model.addAttribute("contentPage", "/datacollect/editorJob");
- return "pageView";
- } catch (Exception ex) {
- model.addAttribute("contentPage", "/datacollect/editorJob");
- return "pageView";
- }
- }
- /*
- 获取任务列表
- */
- @RequestMapping("getJob")
- @ResponseBody
- public Result getJob(String name, int page, int rows) {
- try {
- Map<String, Object> map = new HashMap<>();
- map.put("name", name);
- return datacollect.getJobList(map, page, rows);
- } catch (Exception ex) {
- return Result.error(ex.getMessage());
- }
- }
- @RequestMapping("compareServeTime")
- @ResponseBody
- public Result getJob(String time){
- try {
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if(df.parse(time).before(new Date())) {
- return Result.success("beforeServeTime");
- }
- else
- return Result.error("afterServeTime");
- }catch (Exception ex){
- return Result.error(ex.getMessage());
- }
- }
- /**
- * 根据适配方案获取数据集列表
- */
- @RequestMapping("getSchemeDataset")
- @ResponseBody
- public Result getSchemeDataset(String schemeId, String schemeVersion, String jobId) {
- try {
- return datacollect.getSchemeDataset(schemeId, schemeVersion, jobId);
- } catch (Exception ex) {
- return Result.error(ex.getMessage());
- }
- }
- /**
- * 根据适配方案+数据集获取字段列表
- */
- @RequestMapping("getSchemeDatasetCol")
- @ResponseBody
- public Result getSchemeDatasetCol(String schemeId, String schemeVersion, String datasetId) {
- try {
- return datacollect.getSchemeDatasetCol(schemeId, schemeVersion, datasetId);
- } catch (Exception ex) {
- return Result.error(ex.getMessage());
- }
- }
- /*
- 新增任务
- */
- @RequestMapping("addJob")
- @ResponseBody
- public Result addJob(HttpServletRequest request) {
- try {
- RsJobConfig obj = new RsJobConfig();
- BeanUtils.populate(obj, request.getParameterMap());
- obj.setValid("1");
- String time=request.getParameter("jobNextTime");
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if(df.parse(time).before(new Date())) {
- return Result.error("任务开始时间不能小于当前时间");
- }
- String cron = request.getParameter("cronExpression");
- String jobDataset = request.getParameter("jobDataset");
- return datacollect.addJob(obj, cron, jobDataset);
- } catch (Exception ex) {
- ex.printStackTrace();
- return Result.error("新增任务失败!");
- }
- }
- /*
- 修改任务
- */
- @RequestMapping("updateJob")
- @ResponseBody
- public Result updateJob(HttpServletRequest request) {
- try {
- RsJobConfig obj = new RsJobConfig();
- // ConvertUtils.register(new DateLocaleConverter(), Date.class);
- BeanUtils.populate(obj, request.getParameterMap());
- String time=request.getParameter("jobNextTime");
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if(df.parse(time).before(new Date())) {
- return Result.error("任务开始时间不能小于当前时间");
- }
- String cron = request.getParameter("cronExpression");
- String jobDataset = request.getParameter("jobDataset");
- return datacollect.updateJob(obj, cron, jobDataset);
- } catch (Exception ex) {
- ex.printStackTrace();
- return Result.error("修改任务失败!");
- }
- }
- /*
- 修改任务状态
- */
- @RequestMapping("validJob")
- @ResponseBody
- public Result validJob(String jobId, String valid) {
- try {
- return datacollect.validJob(jobId, valid);
- } catch (Exception ex) {
- return Result.error(ex.getMessage());
- }
- }
- /*
- 删除任务
- */
- @RequestMapping("deleteJob")
- @ResponseBody
- public Result deleteJob(String jobId) {
- try {
- return datacollect.deleteJob(jobId);
- } catch (Exception ex) {
- ex.printStackTrace();
- return Result.error(ex.getMessage());
- }
- }
- /**
- * 获取任务信息
- *
- * @return
- */
- @RequestMapping("getJobInfo")
- @ResponseBody
- public Result getJobInfo(String jobId) {
- try {
- RsJobConfig job = datacollect.getJobById(jobId);
- if (job != null) {
- ActionResult re = new ActionResult(true, "");
- re.setData(job.getValid());
- return re;
- } else {
- return new ActionResult(false, "非法操作!");
- }
- } catch (Exception ex) {
- return Result.error(ex.getMessage());
- }
- }
- /**
- * 根据任务Id获取相关数据集下拉数据
- *
- * @return
- */
- @RequestMapping("getJobDatasetByJobId")
- @ResponseBody
- public Result getJobDatasetByJobId(String jobId) {
- try {
- return datacollect.getJobDatasetByJobId(jobId);
- } catch (Exception ex) {
- return Result.error(ex.getMessage());
- }
- }
- /*************************
- * 数据集--数据源管理
- ******************************************/
- /*
- 数据集配置
- */
- @RequestMapping("configDataset")
- public String configDataset(Model model) {
- try {
- model.addAttribute("stdVersion", "569e19522e3d");
- //获取数据源数据
- model.addAttribute("datasourceList", datasource.getDatasourceByOrg("").toJson());
- model.addAttribute("contentPage", "/datacollect/configDataset");
- return "partView";
- } catch (Exception ex) {
- model.addAttribute("contentPage", "error");
- return "partView";
- }
- }
- /**
- * 数据集数据源管理列表(包含全部数据集)
- *
- * @return
- */
- @RequestMapping("getDatasetSource")
- @ResponseBody
- public Result getDatasetSource(String stdVersion) {
- try {
- return datacollect.getDatasetSource(stdVersion);
- } catch (Exception ex) {
- return Result.error(ex.getMessage());
- }
- }
- /**
- * 更新数据集数据源
- *
- * @return
- */
- @RequestMapping("saveDatasetSource")
- @ResponseBody
- public Result saveDatasetSource(String stdVersion, String json) {
- try {
- return datacollect.saveDatasetSource(json);
- } catch (Exception ex) {
- return Result.error(ex.getMessage());
- }
- }
- /*************************** 任务执行 ************************************************/
- /**
- * 执行任务
- *
- * @return
- */
- @RequestMapping("executeJob")
- @ResponseBody
- public Result executeJob(String jobId) {
- try {
- //获取任务详细信息
- RsJobConfig job = datacollect.getJobById(jobId);
- String content = job.getJobContent();
- Class<?> classType = Class.forName(content);
- Method method = classType.getMethod("execute", new Class[]{String.class});
- method.invoke(classType.newInstance(), jobId);
- return Result.success("处理完成!");
- } catch (Exception ex) {
- return Result.error(ex.getMessage());
- }
- }
- /*
- 任务补采界面
- */
- @RequestMapping("repeatDatacollect")
- public String repeatDatacollect(Model model, String jobId, String jobDatasetId, String jobStatus, String jobTimeFrom, String jobTimeTo) {
- try {
- model.addAttribute("jobId", jobId == null ? "" : jobId);
- model.addAttribute("jobDatasetId", jobDatasetId == null ? "" : jobDatasetId);
- model.addAttribute("jobStatus", jobStatus == null ? "" : jobStatus);
- if (jobTimeFrom != null && jobTimeFrom.length() > 0) {
- Date timeFrom = DateConvert.toDate(jobTimeFrom);
- model.addAttribute("jobTimeFrom", DateConvert.toString(timeFrom));
- } else {
- GregorianCalendar gc = new GregorianCalendar();
- gc.setTime(new Date());
- gc.add(5, -1);
- model.addAttribute("jobTimeFrom", DateConvert.toString(gc.getTime()));
- }
- if (jobTimeTo != null && jobTimeTo.length() > 0) {
- Date timeTo = DateConvert.toDate(jobTimeTo);
- model.addAttribute("jobTimeTo", DateConvert.toString(timeTo));
- } else {
- model.addAttribute("jobTimeTo", DateConvert.toString(new Date()));
- }
- model.addAttribute("contentPage", "/datacollect/repeatDatacollect");
- return "partView";
- } catch (Exception ex) {
- model.addAttribute("contentPage", "error");
- return "partView";
- }
- }
- /**
- * 任务详细日志列表
- *
- * @return
- */
- @RequestMapping("getJobLogDetail")
- @ResponseBody
- public Result getJobLogDetail(String jobId, String jobDatasetId, String jobStatus, String jobTimeFrom, String jobTimeTo, int page, int rows) {
- try {
- Map<String, Object> conditionMap = new HashMap<String, Object>();
- conditionMap.put("jobId", jobId);
- conditionMap.put("jobDatasetId", jobDatasetId);
- conditionMap.put("jobStatus", jobStatus);
- conditionMap.put("jobTimeFrom", jobTimeFrom);
- conditionMap.put("jobTimeTo", jobTimeTo);
- return datacollect.getJobLogDetail(conditionMap, page, rows);
- } catch (Exception ex) {
- return Result.error(ex.getMessage());
- }
- }
- /**
- * 补采数据
- *
- * @return
- */
- @RequestMapping("repeat")
- @ResponseBody
- public Result repeat(String ids) {
- return Result.error("非法操作!");
- }
- /*************************** 任务跟踪 ***********************************/
- /**
- * 任务跟踪界面
- *
- * @return
- */
- @RequestMapping("trackJob")
- public String trackJob(Model model, String jobId) {
- try {
- model.addAttribute("contentPage", "/datacollect/trackJob");
- return "pageView";
- } catch (Exception ex) {
- model.addAttribute("contentPage", "error");
- return "partView";
- }
- }
- /**
- * 任务日志列表
- *
- * @return
- */
- @RequestMapping("getJobLog")
- @ResponseBody
- public Result getJobLog(String jobId, int page, int rows) {
- try {
- Map<String, Object> conditionMap = new HashMap<String, Object>();
- conditionMap.put("jobId", jobId);
- return datacollect.getJobLog(conditionMap, page, rows);
- } catch (Exception ex) {
- return Result.error(ex.getMessage());
- }
- }
- /**
- * 任务详细根据数据集分组
- *
- * @return
- */
- @RequestMapping("getJobLogDataset")
- @ResponseBody
- public Result getJobLogDataset(String logId) {
- try {
- return datacollect.getJobLogDataset(logId);
- } catch (Exception ex) {
- return Result.error(ex.getMessage());
- }
- }
- }
|