@ResponseBody @RequestMapping(value = "/stopJob", method = RequestMethod.POST) public void stopJob(@RequestParam Map<String, Object> map) throws Exception { String selectid = (String) map.get("selectid"); AssertHelper.notEmpty_assert(selectid, "执行的任务id不能为空"); JobDefinition jobDefinition = (JobDefinition) jobDefinitionService.get(JobDefinition.class, selectid); jobDefinition.setState(JobState.stopping); jobDefinition.setEndDate(new Date()); jobDefinitionService.update(jobDefinition); try { JobHistory jobhistory = new JobHistory(); jobhistory.setEndDate(jobDefinition.getEndDate()); jobhistory.setId(IdGenerator.getUUID()); jobhistory.setJobId(selectid); jobhistory.setSuccessful(true); jobDefinitionService.save(jobhistory); } catch (Exception e) { e.printStackTrace(); JobHistory jobhistory = new JobHistory(); jobhistory.setEndDate(jobDefinition.getEndDate()); jobhistory.setStartDate(jobDefinition.getStartDate()); jobhistory.setId(IdGenerator.getUUID()); jobhistory.setJobId(selectid); jobhistory.setSuccessful(false); jobDefinitionService.save(jobhistory); } }
@ResponseBody @RequestMapping(value = "/saveJobDefinition", method = RequestMethod.POST) public JobDefinition saveJobDefinition( @ModelAttribute("jobDefinitionForm") JobDefinition inParam, HttpServletResponse response) throws Exception { if (AssertHelper.empty(inParam.getId())) { inParam.setId(IdGenerator.getUUID()); jobDefinitionService.save(inParam); } else { jobDefinitionService.update(inParam); } inParam.setId(inParam.getId()); return inParam; }
@ResponseBody @RequestMapping(value = "/removeJobDefinition") public void removeJobDefinition( @RequestParam("id") String clientKeys, HttpServletResponse response) throws Exception { AssertHelper.notEmpty_assert(clientKeys, "需要删除的job数据不能为空"); for (String clientId : clientKeys.split(",")) { JobDefinition entity = (JobDefinition) jobDefinitionService.get(JobDefinition.class, clientId); jobDefinitionService.remove(entity); } JSONObject object = new JSONObject(); object.put("result", "true"); object.put("success", "true"); object.put("msg", "删除成功"); retJson(response, object); }
/** * 立即执行 * * @param map * @throws Exception */ @ResponseBody @RequestMapping(value = "/exeJob", method = RequestMethod.POST) public void exeJob(@RequestParam Map<String, Object> map, HttpServletResponse response) throws Exception { String selectid = (String) map.get("selectid"); AssertHelper.notEmpty_assert(selectid, "执行的任务id不能为空"); JobDefinition jobDefinition = (JobDefinition) jobDefinitionService.get(JobDefinition.class, selectid); AssertHelper.notEmpty_assert(jobDefinition, "id为" + selectid + "的job定义没有找到"); String beanId = jobDefinition.getBeanId(); AssertHelper.notEmpty_assert(jobDefinition, "id为" + selectid + "的job没有定义beanId"); Object job = SpringUtil.getBean(beanId); AssertHelper.notEmpty_assert(job, "beanId为" + beanId + "的bean没有找到"); if (!((job instanceof Job) && (job instanceof JobTest))) { throw new BusinessException("beanId为" + beanId + "的bean必须实现的是org.quartz.Job和JobTest接口"); } JobTest jobTest = (JobTest) job; JSONObject object = new JSONObject(); object.put("success", "true"); try { jobTest.execute(); JobHistory jobhistory = new JobHistory(); jobhistory.setEndDate(jobDefinition.getEndDate()); jobhistory.setStartDate(jobDefinition.getStartDate()); jobhistory.setId(IdGenerator.getUUID()); jobhistory.setJobId(beanId); jobhistory.setSuccessful(true); jobDefinitionService.save(jobhistory); retJson(response, object); } catch (Exception e) { e.printStackTrace(); JobHistory jobhistory = new JobHistory(); jobhistory.setEndDate(jobDefinition.getEndDate()); jobhistory.setStartDate(jobDefinition.getStartDate()); jobhistory.setId(IdGenerator.getUUID()); jobhistory.setJobId(beanId); jobhistory.setSuccessful(false); jobDefinitionService.save(jobhistory); object.put("errorMsg", e.getMessage()); object.put("success", "false"); retJson(response, object); } }
/** * jobs数据加载 * * @param response * @param parameter * @return * @throws Exception */ @ResponseBody @RequestMapping(value = "/getJobDefinitions") public DaoPage loadJobDefinitions( HttpServletResponse response, @RequestParam Map<String, Object> parameter) throws Exception { DaoPage daoPage = jobDefinitionService.loadJobs( parameter, PageUtils.getPageNumber(parameter), PageUtils.getPageSize( parameter)); // (parameter,PageUtils.getPageNumber(parameter),PageUtils.getPageSize(parameter)); JSONObject result = new JSONObject(); result.put("total", daoPage.getRecordCount()); result.put("rows", daoPage.getResult()); // daoPage.getr result.put("pages", daoPage.getPageCount()); result.put("success", true); retJson(response, result); return null; }
@ResponseBody @RequestMapping(value = "/loadModifyJobDefinition") public void loadModifyJobDefinition( @RequestParam Map<String, Object> map, HttpServletResponse response) throws Exception { Object id = map.get("id"); JSONObject jsonObject = new JSONObject(); if (!AssertHelper.isOrNotEmpty_assert(id)) { AssertHelper.notEmpty_assert(id, "需要删除的数据不能为空"); jsonObject.put("success", "false"); jsonObject.put("errorMsg", "编辑的主键不能为空"); } else { JobDefinition entity = (JobDefinition) jobDefinitionService.get(JobDefinition.class, id.toString()); jsonObject.put("success", "true"); JobDefinitionInParam aa = new JobDefinitionInParam(); ReflectUtils.copyProperties(entity, aa); jsonObject.put("taskShceduleForm", aa); retJson(response, jsonObject); } }
/** * 显示历史jobs信息 * * @param response * @return * @throws Exception */ @ResponseBody @RequestMapping(value = "/loadhistory") public DaoPage getJobByName( HttpServletResponse response, @RequestParam Map<String, Object> parameter) throws Exception { StringBuffer sqlBuffer = new StringBuffer(); System.out.println((String) parameter.get("id")); DaoPage daoPage = jobDefinitionService.getJobByName( parameter, Integer.parseInt(parameter.get("page").toString()), Integer.parseInt(parameter.get("rows").toString())); JSONObject result = new JSONObject(); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor()); JSONArray jsonArray = JSONArray.fromObject(daoPage.getResult(), jsonConfig); result.put("total", daoPage.getRecordCount()); result.put("rows", jsonArray); // daoPage.getr result.put("pages", daoPage.getPageCount()); result.put("success", true); retJson(response, result); return null; }
public void updateModifyJobDefinition(ClientInParam inParam) throws Exception { JobDefinition entity = (JobDefinition) jobDefinitionService.get(JobDefinition.class, inParam.getId()); ReflectUtils.copyProperties(inParam, entity); jobDefinitionService.update(entity); }