Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.xxl.job.admin.controller;

import com.xxl.job.admin.core.cron.CronExpression;
import com.xxl.job.admin.core.exception.XxlJobException;
import com.xxl.job.admin.core.model.XxlJobGroup;
import com.xxl.job.admin.core.model.XxlJobInfo;
Expand All @@ -19,18 +18,29 @@
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
import com.xxl.job.core.glue.GlueTypeEnum;
import com.xxl.job.core.util.DateUtil;
import com.xxl.job.core.util.GsonTool;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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 javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.*;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* index controller
Expand All @@ -45,7 +55,7 @@ public class JobInfoController {
private XxlJobGroupDao xxlJobGroupDao;
@Resource
private XxlJobService xxlJobService;

@RequestMapping
public String index(HttpServletRequest request, Model model, @RequestParam(required = false, defaultValue = "-1") int jobGroup) {

Expand Down Expand Up @@ -97,46 +107,78 @@ public static void validPermission(HttpServletRequest request, int jobGroup) {
throw new RuntimeException(I18nUtil.getString("system_permission_limit") + "[username="+ loginUser.getUsername() +"]");
}
}

@RequestMapping("/pageList")
@ResponseBody
public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int start,
public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int start,
@RequestParam(required = false, defaultValue = "10") int length,
int jobGroup, int triggerStatus, String jobDesc, String executorHandler, String author) {

return xxlJobService.pageList(start, length, jobGroup, triggerStatus, jobDesc, executorHandler, author);
}


@RequestMapping("/export")
@ResponseBody
public void export(HttpServletResponse response, @RequestParam(required = false, defaultValue = "0") int start,
@RequestParam(required = false, defaultValue = "100") int length,
int jobGroup, int triggerStatus, String jobDesc, String executorHandler, String author) {

Map<String, Object> export = xxlJobService.export(start, length, jobGroup, triggerStatus, jobDesc, executorHandler, author);
String exportJson = GsonTool.toJson(export);
try(ServletOutputStream outputStream = response.getOutputStream()) {
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename=jobInfos.json");
IOUtils.copyLarge(new ByteArrayInputStream(exportJson.getBytes(StandardCharsets.UTF_8)), outputStream);
} catch (IOException e) {
// reset response
response.reset();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
ReturnT<String> returnT = new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_api_error")));
try {
response.getWriter().println(GsonTool.toJson(returnT));
} catch (IOException ex) {
ex.printStackTrace();
}
}
}

@RequestMapping("/import")
@ResponseBody
public ReturnT<String> jobImport(MultipartFile file, String importStrategy) {
return xxlJobService.jobImport(file, importStrategy);
}

@RequestMapping("/add")
@ResponseBody
public ReturnT<String> add(XxlJobInfo jobInfo) {
return xxlJobService.add(jobInfo);
}

@RequestMapping("/update")
@ResponseBody
public ReturnT<String> update(XxlJobInfo jobInfo) {
return xxlJobService.update(jobInfo);
}

@RequestMapping("/remove")
@ResponseBody
public ReturnT<String> remove(int id) {
return xxlJobService.remove(id);
}

@RequestMapping("/stop")
@ResponseBody
public ReturnT<String> pause(int id) {
return xxlJobService.stop(id);
}

@RequestMapping("/start")
@ResponseBody
public ReturnT<String> start(int id) {
return xxlJobService.start(id);
}

@RequestMapping("/trigger")
@ResponseBody
//@PermissionLimit(limit = false)
Expand Down Expand Up @@ -176,5 +218,5 @@ public ReturnT<List<String>> nextTriggerTime(String scheduleType, String schedul
return new ReturnT<List<String>>(result);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.xxl.job.admin.core.model;

import java.util.List;

/**
* @author acton
*/
public class XxlJobInfoImport {
private List<XxlJobGroup> jobGroups;
private List<XxlJobInfo> jobInfos;

public List<XxlJobGroup> getJobGroups() {
return jobGroups;
}

public void setJobGroups(List<XxlJobGroup> jobGroups) {
this.jobGroups = jobGroups;
}

public List<XxlJobInfo> getJobInfos() {
return jobInfos;
}

public void setJobInfos(List<XxlJobInfo> jobInfos) {
this.jobInfos = jobInfos;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;

/**
Expand Down Expand Up @@ -34,4 +35,26 @@ public int pageListCount(@Param("offset") int offset,
@Param("appname") String appname,
@Param("title") String title);

/**
* load batch by ids
*
* @param jobGroupIds
* @return
*/
List<XxlJobGroup> loadByIds(@Param("jobGroupIds") Collection<Integer> jobGroupIds);

/**
* removeAll
*
* @return
*/
int removeAll();

/**
* saveWithId
*
* @param jobGroup
* @return
*/
int saveWithId(XxlJobGroup jobGroup);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public int pageListCount(@Param("offset") int offset,
@Param("jobDesc") String jobDesc,
@Param("executorHandler") String executorHandler,
@Param("author") String author);

public int save(XxlJobInfo info);

public XxlJobInfo loadById(@Param("id") int id);

public int update(XxlJobInfo xxlJobInfo);

public int delete(@Param("id") long id);

public List<XxlJobInfo> getJobsByGroup(@Param("jobGroup") int jobGroup);
Expand All @@ -45,5 +45,18 @@ public int pageListCount(@Param("offset") int offset,

public int scheduleUpdate(XxlJobInfo xxlJobInfo);


/**
* deleteAll
*
* @return
*/
int deleteAll();

/**
* saveWithId
*
* @param jobInfo
* @return
*/
int saveWithId(XxlJobInfo jobInfo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.core.biz.model.ReturnT;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.Map;

/**
* core job action for xxl-job
*
*
* @author xuxueli 2016-5-28 15:30:33
*/
public interface XxlJobService {
Expand Down Expand Up @@ -83,4 +84,26 @@ public interface XxlJobService {
*/
public ReturnT<Map<String,Object>> chartInfo(Date startDate, Date endDate);

/**
* export job
*
* @param start
* @param length
* @param jobGroup
* @param triggerStatus
* @param jobDesc
* @param executorHandler
* @param author
* @return
*/
Map<String, Object> export(int start, int length, int jobGroup, int triggerStatus, String jobDesc, String executorHandler, String author);

/**
* import job
*
* @param file
* @param importStrategy
* @return
*/
ReturnT<String> jobImport(MultipartFile file, String importStrategy);
}
Loading