Skip to content

Commit b6568f3

Browse files
author
令狐兄
committed
切换JobExecutionHistory api到后台
1 parent 731714d commit b6568f3

File tree

5 files changed

+190
-0
lines changed

5 files changed

+190
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.linghuxiong.spring.batch.admin.controller;
2+
3+
import com.alibaba.fastjson.JSONObject;
4+
import org.linghuxiong.spring.batch.admin.model.JobExecutionHistoryEntity;
5+
import org.linghuxiong.spring.batch.admin.service.JobExecutionHistoryService;
6+
import org.linghuxiong.spring.batch.admin.service.QuartzService;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.data.domain.Page;
9+
import org.springframework.data.domain.PageRequest;
10+
import org.springframework.data.domain.Pageable;
11+
import org.springframework.web.bind.annotation.*;
12+
13+
/**
14+
* @author linghuxiong
15+
* @date 2019/11/8 1:48 下午
16+
*/
17+
@RestController
18+
@RequestMapping("/jobHistory")
19+
public class JobExecutionHistoryController {
20+
21+
@Autowired
22+
JobExecutionHistoryService jobExecutionHistoryService;
23+
24+
@GetMapping("/load")
25+
public Page<JobExecutionHistoryEntity> loadQuartzPageable(@RequestParam(required = false) Integer currentPage, @RequestParam(required = false) Integer pageSize,
26+
@RequestParam(required = false) Integer status,
27+
@RequestParam(required = false) String userName,
28+
@RequestParam(required = false) String jobName,
29+
@RequestParam(required = false) Long runId) {
30+
if(currentPage == null){
31+
currentPage = Integer.valueOf(1);
32+
}
33+
34+
if(pageSize == null){
35+
pageSize = Integer.valueOf(10);
36+
}
37+
38+
Pageable pageable = PageRequest.of(currentPage-1, pageSize);
39+
return jobExecutionHistoryService.loadJobHistoryPageable(pageable,jobName,userName,status,runId);
40+
}
41+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.linghuxiong.spring.batch.admin.dao;
2+
3+
import org.linghuxiong.spring.batch.admin.model.JobEntity;
4+
import org.linghuxiong.spring.batch.admin.model.JobExecutionHistoryEntity;
5+
import org.springframework.data.domain.Page;
6+
import org.springframework.data.domain.Pageable;
7+
import org.springframework.data.jpa.domain.Specification;
8+
import org.springframework.data.jpa.repository.JpaRepository;
9+
import org.springframework.stereotype.Repository;
10+
11+
/**
12+
* @author linghuxiong
13+
* @date 2019/11/8 4:34 下午
14+
*/
15+
@Repository
16+
public interface JobExecutionHistoryDao extends JpaRepository<JobExecutionHistoryEntity,Long> {
17+
18+
/**
19+
*
20+
* @param queryCondition
21+
* @param pageable
22+
* @return
23+
*/
24+
Page<JobExecutionHistoryEntity> findAll(Specification<JobExecutionHistoryEntity> queryCondition, Pageable pageable);
25+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.linghuxiong.spring.batch.admin.model;
2+
3+
import lombok.Data;
4+
5+
import javax.persistence.*;
6+
import java.util.Date;
7+
8+
/**
9+
* @author linghuxiong
10+
* @date 2019/11/13 10:31 下午
11+
*/
12+
@Data
13+
@Table(name = "T_JOB_EXECUTION_HISTORY")
14+
@Entity
15+
public class JobExecutionHistoryEntity {
16+
17+
@Id
18+
@GeneratedValue(strategy = GenerationType.IDENTITY)
19+
@Column(name = "ID")
20+
private Long id;
21+
22+
@Column(name = "JOB_NAME")
23+
private String jobName;
24+
25+
@Column(name = "RUN_ID")
26+
private Long runId;
27+
28+
@Column(name = "EXIT_CODE")
29+
private String exitCode;
30+
31+
@Column(name = "EXIT_MESSAGE")
32+
private String exitMessage;
33+
34+
@Column(name = "STATUS")
35+
private Integer status;
36+
37+
@Column(name = "USER_NAME")
38+
private String userName;
39+
40+
@Column(name = "START_TIME")
41+
private Date startAt;
42+
43+
@Column(name = "END_TIME")
44+
private Date endAt;
45+
46+
@Column(name = "UPDATE_TIME")
47+
private Date updatedAt;
48+
49+
@Column(name = "INSERT_TIME")
50+
private Date createdAt;
51+
52+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.linghuxiong.spring.batch.admin.service;
2+
3+
import org.linghuxiong.spring.batch.admin.model.JobExecutionHistoryEntity;
4+
import org.springframework.data.domain.Page;
5+
import org.springframework.data.domain.Pageable;
6+
7+
/**
8+
* @author linghuxiong
9+
* @date 2019/11/13 10:46 下午
10+
*/
11+
public interface JobExecutionHistoryService {
12+
13+
Page<JobExecutionHistoryEntity> loadJobHistoryPageable(Pageable pageable, String jobName, String userName, Integer status, Long runId);
14+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.linghuxiong.spring.batch.admin.service.impl;
2+
3+
import org.linghuxiong.spring.batch.admin.dao.JobExecutionHistoryDao;
4+
import org.linghuxiong.spring.batch.admin.model.JobExecutionHistoryEntity;
5+
import org.linghuxiong.spring.batch.admin.model.TriggerEntity;
6+
import org.linghuxiong.spring.batch.admin.service.JobExecutionHistoryService;
7+
import org.springframework.batch.core.repository.dao.JobExecutionDao;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.data.domain.Page;
10+
import org.springframework.data.domain.Pageable;
11+
import org.springframework.data.jpa.domain.Specification;
12+
import org.springframework.stereotype.Service;
13+
14+
import javax.persistence.criteria.CriteriaBuilder;
15+
import javax.persistence.criteria.CriteriaQuery;
16+
import javax.persistence.criteria.Predicate;
17+
import javax.persistence.criteria.Root;
18+
import java.util.ArrayList;
19+
import java.util.List;
20+
21+
/**
22+
* @author linghuxiong
23+
* @date 2019/11/13 10:48 下午
24+
*/
25+
@Service
26+
public class JobExecutionHistoryServiceImpl implements JobExecutionHistoryService {
27+
28+
@Autowired
29+
JobExecutionHistoryDao jobExecutionHistoryDao;
30+
31+
@Override
32+
public Page<JobExecutionHistoryEntity> loadJobHistoryPageable(Pageable pageable, String jobName, String userName, Integer status, Long runId) {
33+
Specification<JobExecutionHistoryEntity> queryCondition = new Specification<JobExecutionHistoryEntity>() {
34+
@Override
35+
public Predicate toPredicate(Root<JobExecutionHistoryEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
36+
List<Predicate> predicateList = new ArrayList<>();
37+
if (jobName != null) {
38+
predicateList.add(criteriaBuilder.like(criteriaBuilder.upper(root.get("jobName")), "%"+jobName.toUpperCase()+"%"));
39+
}
40+
41+
if (userName != null) {
42+
predicateList.add(criteriaBuilder.like(criteriaBuilder.upper(root.get("userName")), "%"+userName.toUpperCase()+"%"));
43+
}
44+
45+
if (status != null) {
46+
predicateList.add(criteriaBuilder.equal(root.get("status"), status));
47+
}
48+
49+
if (runId != null) {
50+
predicateList.add(criteriaBuilder.equal(root.get("runId"), runId));
51+
}
52+
53+
return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
54+
}
55+
};
56+
return jobExecutionHistoryDao.findAll(queryCondition,pageable);
57+
}
58+
}

0 commit comments

Comments
 (0)