文档和代码更新

This commit is contained in:
inrgihc
2021-08-31 23:09:44 +08:00
parent 85223a9af7
commit 057b655c7b
21 changed files with 26617 additions and 152 deletions

View File

@@ -359,9 +359,11 @@ bin/startup.sh
- dbswitch-admin的WEB端会根据用户的配置调用dbswitch-data模块执行数据迁移同步 - dbswitch-admin的WEB端会根据用户的配置调用dbswitch-data模块执行数据迁移同步
- dbswitch离线同步工具提供各种数据库间表结构转换RESTful类型的API接口 - dbswitch-admin服务启动时会基于flyway自动建库建表需要保证配置的mysql连接账号具有建库建表等权限
> swagger在线接口文档```htttp://127.0.0.1:9088/swagger-ui.html``` - dbswitch离线同步工具提供各种数据库间表结构转换RESTful类型的在线API接口如下:(详见[接口文档](/INTERFACE.md)
> Swagger在线接口地址 http://127.0.0.1:9088/swagger-ui/
- WEB系统的访问如下 - WEB系统的访问如下
@@ -371,6 +373,8 @@ bin/startup.sh
> 建立源端数据库的连接 -> 建立目的断数据库的连接 -> 配置任务 -> 发布任务 -> 手动/系统调度执行任务 -> 查看调度记录 > 建立源端数据库的连接 -> 建立目的断数据库的连接 -> 配置任务 -> 发布任务 -> 手动/系统调度执行任务 -> 查看调度记录
- WEB系统的部分截图
![admin_01.png](images/admin_01.png) ![admin_01.png](images/admin_01.png)
![admin_02.png](images/admin_02.png) ![admin_02.png](images/admin_02.png)

View File

@@ -19,3 +19,7 @@ npm run build
# build for production and view the bundle analyzer report # build for production and view the bundle analyzer report
npm run build --report npm run build --report
``` ```
## 三、部署
执行`npm run build`命令后将dbswitch-admin-ui\dist目录生成的所有文件拷贝或替换到dbswitch-admin\src\main\resources目录下。然后直接使用mvn对整个dbswitch项目打包即可。

View File

@@ -39,6 +39,9 @@ module.exports = {
{ {
test: /\.js$/, test: /\.js$/,
loader: 'babel-loader', loader: 'babel-loader',
options:{
plugins:['syntax-dynamic-import']
},
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')] include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
}, },
{ {

26500
dbswitch-admin-ui/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -23,6 +23,7 @@
"babel-core": "^6.22.1", "babel-core": "^6.22.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3", "babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.1", "babel-loader": "^7.1.1",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-syntax-jsx": "^6.18.0", "babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0", "babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0", "babel-plugin-transform-vue-jsx": "^3.5.0",

View File

@@ -1,7 +1,7 @@
import Vue from 'vue' import Vue from 'vue'
import Router from 'vue-router' import Router from 'vue-router'
Vue.use(Router) Vue.use(Router);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// 路由配置 // 路由配置

View File

@@ -85,12 +85,17 @@
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId> <artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version> <version>3.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId> <artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version> <version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@@ -82,12 +82,13 @@ public class ShiroConfig {
// anno匿名访问 auth验证 // anno匿名访问 auth验证
filterMap.put("/static/**", "anon"); filterMap.put("/static/**", "anon");
filterMap.put("/index.html", "anon"); filterMap.put("/index.html", "anon");
filterMap.put("/favicon.ico", "anon"); filterMap.put("/favicon.ico*", "anon");
filterMap.put("/webjars/**", "anon"); filterMap.put("/webjars/**", "anon");
filterMap.put(SwaggerConfig.API_V1 + "/authentication/login", "anon"); filterMap.put(SwaggerConfig.API_V1 + "/authentication/login", "anon");
filterMap.put("/swagger/**", "anon"); filterMap.put("/swagger/**", "anon");
filterMap.put("/v2/api-docs", "anon"); filterMap.put("/swagger-ui/**", "anon");
filterMap.put("/swagger-ui.html", "anon"); filterMap.put("/v2/api-docs*", "anon");
filterMap.put("/swagger-ui.html*", "anon");
filterMap.put("/swagger-resources/**", "anon"); filterMap.put("/swagger-resources/**", "anon");
// 除了以上路径,其他都需要权限验证 // 除了以上路径,其他都需要权限验证
filterMap.put("/**", "auth"); filterMap.put("/**", "auth");

View File

@@ -9,6 +9,8 @@
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
package com.gitee.dbswitch.admin.config.shiro; package com.gitee.dbswitch.admin.config.shiro;
import com.gitee.dbswitch.admin.common.excption.DbswitchException;
import com.gitee.dbswitch.admin.common.response.ResultCode;
import com.gitee.dbswitch.admin.dao.SystemUserDAO; import com.gitee.dbswitch.admin.dao.SystemUserDAO;
import com.gitee.dbswitch.admin.entity.SystemUserEntity; import com.gitee.dbswitch.admin.entity.SystemUserEntity;
import com.gitee.dbswitch.admin.util.CacheUtil; import com.gitee.dbswitch.admin.util.CacheUtil;
@@ -91,7 +93,7 @@ public class SystemUserRealm extends AuthorizingRealm {
//根据缓存将token转换成User实体对象 //根据缓存将token转换成User实体对象
Object cache = CacheUtil.get(accessToken); Object cache = CacheUtil.get(accessToken);
if (null == cache) { if (null == cache) {
throw new RuntimeException("token不存在或已经失效请重新登录!"); throw new DbswitchException(ResultCode.ERROR_ACCESS_FORBIDDEN, "token不存在或已经失效请重新登录!");
} }
//判断数据库中的User实体对象的有效性 //判断数据库中的User实体对象的有效性
@@ -103,7 +105,7 @@ public class SystemUserRealm extends AuthorizingRealm {
throw new LockedAccountException("token所使用的认证用户已经被锁定"); // 帐号锁定 throw new LockedAccountException("token所使用的认证用户已经被锁定"); // 帐号锁定
} }
ServletUtil.getHttpServletRequest().setAttribute("username",user.getUsername()); ServletUtil.getHttpServletRequest().setAttribute("username", user.getUsername());
return new SimpleAuthenticationInfo(accessToken, accessToken, this.getName()); return new SimpleAuthenticationInfo(accessToken, accessToken, this.getName());
} }

View File

@@ -46,14 +46,14 @@ public class AssignmentController {
@PostMapping(value = "/create", produces = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/create", produces = MediaType.APPLICATION_JSON_VALUE)
public Result<AssignmentInfoResponse> createAssignment( public Result<AssignmentInfoResponse> createAssignment(
@RequestBody AssigmentCreateRequest request) { @RequestBody AssigmentCreateRequest request) {
return Result.success(assignmentService.create(request)); return Result.success(assignmentService.createAssignment(request));
} }
@OperateLog(name = "修改任务", description = "'修改任务的名称为:'+#request.name") @OperateLog(name = "修改任务", description = "'修改任务的名称为:'+#request.name")
@ApiOperation(value = "修改") @ApiOperation(value = "修改")
@PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
public Result updateAssignment(@RequestBody AssigmentUpdateRequest request) { public Result updateAssignment(@RequestBody AssigmentUpdateRequest request) {
assignmentService.update(request); assignmentService.updateAssignment(request);
return Result.success(); return Result.success();
} }
@@ -61,7 +61,7 @@ public class AssignmentController {
@ApiOperation(value = "删除") @ApiOperation(value = "删除")
@DeleteMapping(value = "/delete/{id}", produces = MediaType.APPLICATION_JSON_VALUE) @DeleteMapping(value = "/delete/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public Result deleteAssignment(@PathVariable("id") Long id) { public Result deleteAssignment(@PathVariable("id") Long id) {
assignmentService.delete(id); assignmentService.deleteAssignment(id);
return Result.success(); return Result.success();
} }
@@ -81,24 +81,24 @@ public class AssignmentController {
@OperateLog(name = "发布任务", description = "'发布任务的ID为'+#ids") @OperateLog(name = "发布任务", description = "'发布任务的ID为'+#ids")
@ApiOperation(value = "发布") @ApiOperation(value = "发布")
@PostMapping(value = "/deploy", produces = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/deploy", produces = MediaType.APPLICATION_JSON_VALUE)
public Result deployAssignment(@RequestParam(value = "ids") List<Long> ids) { public Result deployAssignments(@RequestParam(value = "ids") List<Long> ids) {
assignmentService.deploy(ids); assignmentService.deployAssignments(ids);
return Result.success(); return Result.success();
} }
@OperateLog(name = "手动执行任务", description = "'手动执行任务的ID为'+#ids") @OperateLog(name = "手动执行任务", description = "'手动执行任务的ID为'+#ids")
@ApiOperation(value = "手动执行") @ApiOperation(value = "手动执行")
@RequestMapping(value = "/run", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST) @RequestMapping(value = "/run", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
public Result runAssignment(@RequestBody List<Long> ids) { public Result runAssignments(@RequestBody List<Long> ids) {
assignmentService.run(ids); assignmentService.runAssignments(ids);
return Result.success(); return Result.success();
} }
@OperateLog(name = "下线任务", description = "'下线任务的ID为'+#ids") @OperateLog(name = "下线任务", description = "'下线任务的ID为'+#ids")
@ApiOperation(value = "下线") @ApiOperation(value = "下线")
@PostMapping(value = "/retire", produces = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/retire", produces = MediaType.APPLICATION_JSON_VALUE)
public Result retireAssignment(@RequestParam(value = "ids") List<Long> ids) { public Result retireAssignments(@RequestParam(value = "ids") List<Long> ids) {
assignmentService.retire(ids); assignmentService.retireAssignments(ids);
return Result.success(); return Result.success();
} }

View File

@@ -24,14 +24,17 @@ public class ExceptionController {
@ResponseBody @ResponseBody
@ExceptionHandler(value = Exception.class) @ExceptionHandler(value = Exception.class)
public Result errorHandler(Exception ex) { public Result errorHandler(Exception ex) {
if (ex instanceof DbswitchException) {
DbswitchException learnException = (DbswitchException) ex;
return Result.failed(learnException.getCode(), learnException.getMessage());
}
log.error("ERROR:", ex); log.error("ERROR:", ex);
if (ex instanceof NullPointerException) { if (ex instanceof NullPointerException) {
return Result.failed(ResultCode.ERROR_INTERNAL_ERROR, "Null Pointer Expression"); return Result.failed(ResultCode.ERROR_INTERNAL_ERROR, "Null Pointer Expression");
} else if (ex instanceof DbswitchException) {
DbswitchException learnException = (DbswitchException) ex;
return Result.failed(learnException.getCode(), learnException.getMessage());
} else { } else {
return Result.failed(ResultCode.ERROR_INTERNAL_ERROR, ex.getMessage()); return Result.failed(ResultCode.ERROR_INTERNAL_ERROR, ex.getMessage());
} }
} }
} }

View File

@@ -28,8 +28,9 @@ public class AssignmentJobDAO {
@Resource @Resource
private AssignmentJobMapper assignmentJobMapper; private AssignmentJobMapper assignmentJobMapper;
public AssignmentJobEntity newAssignmentJob(Long assignmentId, Integer scheduleMode , String jobKey) { public AssignmentJobEntity newAssignmentJob(Long assignmentId, Integer scheduleMode,
AssignmentJobEntity assignmentJobEntity =new AssignmentJobEntity(); String jobKey) {
AssignmentJobEntity assignmentJobEntity = new AssignmentJobEntity();
assignmentJobEntity.setAssignmentId(assignmentId); assignmentJobEntity.setAssignmentId(assignmentId);
assignmentJobEntity.setJobKey(jobKey); assignmentJobEntity.setJobKey(jobKey);
assignmentJobEntity.setScheduleMode(scheduleMode); assignmentJobEntity.setScheduleMode(scheduleMode);
@@ -46,20 +47,27 @@ public class AssignmentJobDAO {
public List<AssignmentJobEntity> getByAssignmentId(Long assignmentId) { public List<AssignmentJobEntity> getByAssignmentId(Long assignmentId) {
Objects.requireNonNull(assignmentId, "assignmentId不能为null"); Objects.requireNonNull(assignmentId, "assignmentId不能为null");
AssignmentJobEntity condition = new AssignmentJobEntity();
condition.setAssignmentId(assignmentId);
Example example = new Example(AssignmentJobEntity.class); Example example = new Example(AssignmentJobEntity.class);
example.createCriteria().andEqualTo("assignmentId", assignmentId); example.createCriteria().andEqualTo(condition);
example.orderBy("createTime").desc(); example.orderBy("createTime").desc();
return assignmentJobMapper.selectByExample(example); return assignmentJobMapper.selectByExample(example);
} }
public void updateSelective(AssignmentJobEntity assignmentJobEntity) { public void updateSelective(AssignmentJobEntity assignmentJobEntity) {
Objects.requireNonNull(assignmentJobEntity.getId(),"AssignmentJob的id不能为null"); Objects.requireNonNull(assignmentJobEntity.getId(), "AssignmentJob的id不能为null");
assignmentJobMapper.updateByPrimaryKeySelective(assignmentJobEntity); assignmentJobMapper.updateByPrimaryKeySelective(assignmentJobEntity);
} }
public int getCountByStatus(JobStatusEnum status) { public int getCountByStatus(JobStatusEnum status) {
AssignmentJobEntity condition = new AssignmentJobEntity();
condition.setStatus(status.getValue());
Example example = new Example(AssignmentJobEntity.class); Example example = new Example(AssignmentJobEntity.class);
example.createCriteria().andEqualTo("status", status.getValue()); example.createCriteria().andEqualTo(condition);
return assignmentJobMapper.selectCountByExample(example); return assignmentJobMapper.selectCountByExample(example);
} }
@@ -68,7 +76,7 @@ public class AssignmentJobDAO {
.orElseGet(ArrayList::new).size(); .orElseGet(ArrayList::new).size();
} }
public List<OpsTaskJobTrend> queryTaskJobTrend(Integer days){ public List<OpsTaskJobTrend> queryTaskJobTrend(Integer days) {
return assignmentJobMapper.queryTaskJobTrend(days); return assignmentJobMapper.queryTaskJobTrend(days);
} }

View File

@@ -59,8 +59,11 @@ public class AssignmentTaskDAO {
} }
public int getPublishedCount() { public int getPublishedCount() {
AssignmentTaskEntity condition = new AssignmentTaskEntity();
condition.setPublished(Boolean.TRUE);
Example example = new Example(AssignmentTaskEntity.class); Example example = new Example(AssignmentTaskEntity.class);
example.createCriteria().andEqualTo("published", 1); example.createCriteria().andEqualTo(condition);
return assignmentTaskMapper.selectCountByExample(example); return assignmentTaskMapper.selectCountByExample(example);
} }

View File

@@ -31,7 +31,11 @@ public class SystemLogDAO {
public List<SystemLogEntity> listAll(LogTypeEnum logType) { public List<SystemLogEntity> listAll(LogTypeEnum logType) {
Example example = new Example(SystemLogEntity.class); Example example = new Example(SystemLogEntity.class);
Criteria criteria = example.createCriteria(); Criteria criteria = example.createCriteria();
criteria.andEqualTo("type", logType.getValue());
SystemLogEntity condition=new SystemLogEntity();
condition.setType(logType.getValue());
criteria.andEqualTo(condition);
example.orderBy("createTime").desc(); example.orderBy("createTime").desc();
return systemLogMapper.selectByExample(example); return systemLogMapper.selectByExample(example);
} }

View File

@@ -58,7 +58,7 @@ public class AssignmentService {
private DatabaseConnectionDAO databaseConnectionDAO; private DatabaseConnectionDAO databaseConnectionDAO;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public AssignmentInfoResponse create(AssigmentCreateRequest request) { public AssignmentInfoResponse createAssignment(AssigmentCreateRequest request) {
AssignmentTaskEntity assignment = request.toAssignmentTask(); AssignmentTaskEntity assignment = request.toAssignmentTask();
assignmentTaskDAO.insert(assignment); assignmentTaskDAO.insert(assignment);
@@ -70,12 +70,12 @@ public class AssignmentService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void delete(Long id) { public void deleteAssignment(Long id) {
assignmentTaskDAO.deleteById(id); assignmentTaskDAO.deleteById(id);
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(AssigmentUpdateRequest request) { public void updateAssignment(AssigmentUpdateRequest request) {
AssignmentTaskEntity assignmentTaskEntity = assignmentTaskDAO.getById(request.getId()); AssignmentTaskEntity assignmentTaskEntity = assignmentTaskDAO.getById(request.getId());
if (Objects.isNull(assignmentTaskEntity)) { if (Objects.isNull(assignmentTaskEntity)) {
throw new DbswitchException(ResultCode.ERROR_RESOURCE_NOT_EXISTS, "ID=" + request.getId()); throw new DbswitchException(ResultCode.ERROR_RESOURCE_NOT_EXISTS, "ID=" + request.getId());
@@ -93,10 +93,9 @@ public class AssignmentService {
} }
public PageResult<AssignmentInfoResponse> listAll(String searchText, Integer page, Integer size) { public PageResult<AssignmentInfoResponse> listAll(String searchText, Integer page, Integer size) {
Supplier<List<AssignmentInfoResponse>> method = () -> { Supplier<List<AssignmentInfoResponse>> method = () ->
List<AssignmentTaskEntity> assignments = assignmentTaskDAO.listAll(searchText); ConverterFactory.getConverter(AssignmentInfoConverter.class)
return ConverterFactory.getConverter(AssignmentInfoConverter.class).convert(assignments); .convert(assignmentTaskDAO.listAll(searchText));
};
return PageUtil.getPage(method, page, size); return PageUtil.getPage(method, page, size);
} }
@@ -113,7 +112,7 @@ public class AssignmentService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deploy(List<Long> ids) { public void deployAssignments(List<Long> ids) {
checkAssignmentAllExist(ids); checkAssignmentAllExist(ids);
//检查是否有已经发布过 //检查是否有已经发布过
@@ -147,7 +146,7 @@ public class AssignmentService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void run(List<Long> ids) { public void runAssignments(List<Long> ids) {
checkAssignmentAllExist(ids); checkAssignmentAllExist(ids);
//检查是否有已经都发布了 //检查是否有已经都发布了
@@ -168,12 +167,12 @@ public class AssignmentService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void retire(List<Long> ids) { public void retireAssignments(List<Long> ids) {
checkAssignmentAllExist(ids); checkAssignmentAllExist(ids);
for (Long id : ids) { for (Long id : ids) {
AssignmentTaskEntity assignmentTaskEntity = assignmentTaskDAO.getById(id); AssignmentTaskEntity assignmentTaskEntity = assignmentTaskDAO.getById(id);
if (Objects.nonNull(assignmentTaskEntity.getPublished()) && assignmentTaskEntity if (Objects.nonNull(assignmentTaskEntity.getPublished()) &&
.getPublished()) { assignmentTaskEntity.getPublished()) {
scheduleService.cancelJobByTaskId(id); scheduleService.cancelJobByTaskId(id);
assignmentTaskEntity.setPublished(Boolean.FALSE); assignmentTaskEntity.setPublished(Boolean.FALSE);
assignmentTaskEntity.setContent("{}"); assignmentTaskEntity.setContent("{}");

View File

@@ -62,21 +62,21 @@ public class ScheduleService {
} }
public Trigger getQuartzJobDetail(String jobKey) { // public Trigger getQuartzJobDetail(String jobKey) {
Scheduler scheduler = schedulerFactoryBean.getScheduler(); // Scheduler scheduler = schedulerFactoryBean.getScheduler();
//
String triggerName = jobKey; // String triggerName = jobKey;
String triggerGroup = JobExecutorService.GROUP; // String triggerGroup = JobExecutorService.GROUP;
TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, triggerGroup); // TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, triggerGroup);
try { // try {
Trigger trigger = scheduler.getTrigger(triggerKey); // Trigger trigger = scheduler.getTrigger(triggerKey);
return trigger; // return trigger;
} catch (SchedulerException e) { // } catch (SchedulerException e) {
log.error("Query job trigger detail failed:", e); // log.error("Query job trigger detail failed:", e);
} // }
//
return null; // return null;
} // }
public void scheduleTask(Long taskId, ScheduleModeEnum scheduleMode) { public void scheduleTask(Long taskId, ScheduleModeEnum scheduleMode) {
/** 准备JobDetail */ /** 准备JobDetail */
@@ -84,12 +84,10 @@ public class ScheduleService {
String jobGroup = JobExecutorService.GROUP; String jobGroup = JobExecutorService.GROUP;
JobKey jobKey = JobKey.jobKey(jobName, jobGroup); JobKey jobKey = JobKey.jobKey(jobName, jobGroup);
JobDetail jobDetail = JobBuilder.newJob(JobExecutorService.class) JobBuilder jobBuilder = JobBuilder.newJob(JobExecutorService.class)
.withIdentity(jobKey) .withIdentity(jobKey)
.usingJobData(JobExecutorService.TASK_ID, taskId.toString()) .usingJobData(JobExecutorService.TASK_ID, taskId.toString())
.usingJobData(JobExecutorService.SCHEDULE, scheduleMode.getValue().toString()) .usingJobData(JobExecutorService.SCHEDULE, scheduleMode.getValue().toString());
.storeDurably()
.build();
/** 准备TriggerKey注意这里的triggerName与jobName配置相同 */ /** 准备TriggerKey注意这里的triggerName与jobName配置相同 */
String triggerName = jobName; String triggerName = jobName;
@@ -100,9 +98,9 @@ public class ScheduleService {
AssignmentTaskEntity task = assignmentTaskDAO.getById(taskId); AssignmentTaskEntity task = assignmentTaskDAO.getById(taskId);
if (ScheduleModeEnum.MANUAL == scheduleMode) { if (ScheduleModeEnum.MANUAL == scheduleMode) {
scheduleOnce(jobDetail, triggerKey); scheduleOnce(jobBuilder.storeDurably(false).build(), triggerKey);
} else { } else {
scheduleCron(jobDetail, triggerKey, task.getCronExpression()); scheduleCron(jobBuilder.storeDurably(true).build(), triggerKey, task.getCronExpression());
} }
} }
@@ -132,9 +130,7 @@ public class ScheduleService {
try { try {
scheduler.interrupt(jobKey); scheduler.interrupt(jobKey);
scheduler.pauseTrigger(triggerKey); scheduler.pauseTrigger(triggerKey);
scheduler.unscheduleJob(triggerKey); return scheduler.unscheduleJob(triggerKey) && scheduler.deleteJob(jobKey);
scheduler.deleteJob(jobKey);
return true;
} catch (SchedulerException e) { } catch (SchedulerException e) {
log.error("Quartz stop task job failed. JobKey: {}", jobKey); log.error("Quartz stop task job failed. JobKey: {}", jobKey);
} }

View File

@@ -12,7 +12,6 @@ package com.gitee.dbswitch.admin.util;
import com.gitee.dbswitch.admin.common.response.PageResult; import com.gitee.dbswitch.admin.common.response.PageResult;
import com.gitee.dbswitch.admin.common.response.PageResult.Pagination; import com.gitee.dbswitch.admin.common.response.PageResult.Pagination;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
@@ -20,10 +19,8 @@ public class PageUtil {
public static <E> PageResult<E> getPage(Supplier<List<E>> method, int pageNum, int pageSize) { public static <E> PageResult<E> getPage(Supplier<List<E>> method, int pageNum, int pageSize) {
com.github.pagehelper.Page<E> originPage = PageHelper.startPage(pageNum, pageSize); com.github.pagehelper.Page<E> originPage = PageHelper.startPage(pageNum, pageSize);
List<E> result = method.get();
PageResult<E> resultPage = new PageResult<>(); PageResult<E> resultPage = new PageResult<>();
resultPage.setData(result); resultPage.setData(method.get());
Pagination pagination = new Pagination(); Pagination pagination = new Pagination();
pagination.setTotal((int) originPage.getTotal()); pagination.setTotal((int) originPage.getTotal());
@@ -35,52 +32,8 @@ public class PageUtil {
pagination.setSize(originPage.getPageSize()); pagination.setSize(originPage.getPageSize());
} }
resultPage.setPagination(pagination); resultPage.setPagination(pagination);
return resultPage; return resultPage;
} }
public static <E> PageResult<E> getPage(List<E> pagingList, int pageNum, int pageSize) {
Pagination pagination = new Pagination();
PageResult<E> page = new PageResult<>();
if (pageNum <= 0 || pageSize <= 0) {
pagination.setTotal(pagingList.size());
pagination.setPage(0);
pagination.setSize(0);
page.setPagination(pagination);
page.setData(pagingList);
} else {
pagination.setTotal(pagingList.size());
pagination.setPage(pageNum);
pagination.setSize(pageSize);
page.setPagination(pagination);
page.setData(subList(pagingList, pageNum, pageSize));
}
return page;
}
public static <E> PageResult<E> pacPage(List<E> pagingList, int pageNum, int pageSize, int total) {
Pagination pagination = new Pagination();
PageResult<E> page = new PageResult<>();
pagination.setTotal(total);
pagination.setPage(pageNum);
pagination.setSize(pageSize);
page.setPagination(pagination);
page.setData(pagingList);
return page;
}
private static <E> List<E> subList(List<E> list, int pageNum, int pageSize) {
int size = list.size();
List<E> result = new ArrayList<>();
int idx = (pageNum - 1) * pageSize;
int end = idx + pageSize;
while (idx < size && idx < end) {
result.add(list.get(idx));
idx++;
}
return result;
}
} }

View File

@@ -28,20 +28,8 @@ public class SpringUtil implements ApplicationContextAware {
return SpringUtil.applicationContext; return SpringUtil.applicationContext;
} }
public static Object getBean(String name) {
return SpringUtil.applicationContext.getBean(name);
}
public static <T> T getBean(Class<T> clazz) { public static <T> T getBean(Class<T> clazz) {
return SpringUtil.applicationContext.getBean(clazz); return SpringUtil.applicationContext.getBean(clazz);
} }
public static <T> T getBean(Class<T> clazz, Object... objects) {
return SpringUtil.applicationContext.getBean(clazz, objects);
}
public static <T> T getBean(String name, Class<T> clazz) {
return SpringUtil.applicationContext.getBean(name, clazz);
}
} }

View File

@@ -28,7 +28,7 @@ mybatis:
lazy-loading-enabled: true lazy-loading-enabled: true
aggressive-lazy-loading: false aggressive-lazy-loading: false
map-underscore-to-camel-case: true map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper: mapper:
wrap-keyword: "`{0}`" wrap-keyword: "`{0}`"

View File

@@ -4,7 +4,6 @@
-- STDJDBCDELEGATE说明支持集群所有的任务信息都会保存到数据库中可以控制事物还有就是如果应用服务器关闭或者重启任务信息都不会丢失并且可以恢复因服务器关闭或者重启而导致执行失败的任务 -- STDJDBCDELEGATE说明支持集群所有的任务信息都会保存到数据库中可以控制事物还有就是如果应用服务器关闭或者重启任务信息都不会丢失并且可以恢复因服务器关闭或者重启而导致执行失败的任务
-- THIS IS THE SCRIPT FROM QUARTZ TO CREATE THE TABLES IN A MYSQL DATABASE, MODIFIED TO USE INNODB INSTEAD OF MYISAM -- THIS IS THE SCRIPT FROM QUARTZ TO CREATE THE TABLES IN A MYSQL DATABASE, MODIFIED TO USE INNODB INSTEAD OF MYISAM
-- 存储每一个已配置的JOB的详细信息
CREATE TABLE IF NOT EXISTS DBSWITCH_JOB_DETAILS CREATE TABLE IF NOT EXISTS DBSWITCH_JOB_DETAILS
( (
SCHED_NAME VARCHAR(120) NOT NULL, SCHED_NAME VARCHAR(120) NOT NULL,
@@ -18,9 +17,8 @@ CREATE TABLE IF NOT EXISTS DBSWITCH_JOB_DETAILS
REQUESTS_RECOVERY VARCHAR(1) NOT NULL, REQUESTS_RECOVERY VARCHAR(1) NOT NULL,
JOB_DATA BLOB NULL, JOB_DATA BLOB NULL,
PRIMARY KEY (SCHED_NAME,JOB_NAME,JOB_GROUP) PRIMARY KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)
) ENGINE=INNODB; ) ENGINE=INNODB COMMENT = '存储每一个已配置的JOB的详细信息';
-- 存储已配置的TRIGGER的信息
CREATE TABLE IF NOT EXISTS DBSWITCH_TRIGGERS CREATE TABLE IF NOT EXISTS DBSWITCH_TRIGGERS
( (
SCHED_NAME VARCHAR(120) NOT NULL, SCHED_NAME VARCHAR(120) NOT NULL,
@@ -42,9 +40,8 @@ CREATE TABLE IF NOT EXISTS DBSWITCH_TRIGGERS
PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
FOREIGN KEY (SCHED_NAME,JOB_NAME,JOB_GROUP) FOREIGN KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)
REFERENCES DBSWITCH_JOB_DETAILS(SCHED_NAME,JOB_NAME,JOB_GROUP) REFERENCES DBSWITCH_JOB_DETAILS(SCHED_NAME,JOB_NAME,JOB_GROUP)
) ENGINE=INNODB; ) ENGINE=INNODB COMMENT = '存储已配置的TRIGGER的信息';
-- 存储已配置的SIMPLE TRIGGER的信息
CREATE TABLE IF NOT EXISTS DBSWITCH_SIMPLE_TRIGGERS CREATE TABLE IF NOT EXISTS DBSWITCH_SIMPLE_TRIGGERS
( (
SCHED_NAME VARCHAR(120) NOT NULL, SCHED_NAME VARCHAR(120) NOT NULL,
@@ -56,9 +53,8 @@ CREATE TABLE IF NOT EXISTS DBSWITCH_SIMPLE_TRIGGERS
PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
REFERENCES DBSWITCH_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) REFERENCES DBSWITCH_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
) ENGINE=INNODB; ) ENGINE=INNODB COMMENT = '存储已配置的SIMPLE类型的触发器(包括重复次数,间隔,及已触的次数)';
-- 存储CRON TRIGGER包括CRON表达式和时区信息
CREATE TABLE IF NOT EXISTS DBSWITCH_CRON_TRIGGERS CREATE TABLE IF NOT EXISTS DBSWITCH_CRON_TRIGGERS
( (
SCHED_NAME VARCHAR(120) NOT NULL, SCHED_NAME VARCHAR(120) NOT NULL,
@@ -69,9 +65,8 @@ CREATE TABLE IF NOT EXISTS DBSWITCH_CRON_TRIGGERS
PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
REFERENCES DBSWITCH_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) REFERENCES DBSWITCH_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
) ENGINE=INNODB; ) ENGINE=INNODB COMMENT = '存储CRON类型的触发器(包括Cron表达式和时区信息)';
-- 存储简单的Trigger包括重复次数间隔以及已触的次数
CREATE TABLE IF NOT EXISTS DBSWITCH_SIMPROP_TRIGGERS CREATE TABLE IF NOT EXISTS DBSWITCH_SIMPROP_TRIGGERS
( (
SCHED_NAME VARCHAR(120) NOT NULL, SCHED_NAME VARCHAR(120) NOT NULL,
@@ -91,9 +86,8 @@ CREATE TABLE IF NOT EXISTS DBSWITCH_SIMPROP_TRIGGERS
PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
REFERENCES DBSWITCH_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) REFERENCES DBSWITCH_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
)ENGINE=INNODB; )ENGINE=INNODB COMMENT = '存储CalendarIntervalTrigger和DailyTimeIntervalTrigger两种类型的触发器';
-- TRIGGER作为BLOB类型存储(用于QUARTZ用户用JDBC创建他们自己定制的TRIGGER类型JOBSTORE并不知道如何存储实例的时候)
CREATE TABLE IF NOT EXISTS DBSWITCH_BLOB_TRIGGERS CREATE TABLE IF NOT EXISTS DBSWITCH_BLOB_TRIGGERS
( (
SCHED_NAME VARCHAR(120) NOT NULL, SCHED_NAME VARCHAR(120) NOT NULL,
@@ -104,26 +98,23 @@ CREATE TABLE IF NOT EXISTS DBSWITCH_BLOB_TRIGGERS
INDEX (SCHED_NAME,TRIGGER_NAME, TRIGGER_GROUP), INDEX (SCHED_NAME,TRIGGER_NAME, TRIGGER_GROUP),
FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
REFERENCES DBSWITCH_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) REFERENCES DBSWITCH_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
)ENGINE=INNODB; )ENGINE=INNODB COMMENT = 'TRIGGER作为BLOB类型存储(用于QUARTZ用户用JDBC创建他们自己定制的TRIGGER类型JOBSTORE并不知道如何存储实例的时候)';
-- 以BLOB类型存储QUARTZ的CALENDAR日历信息,QUARTZ可配置一个日历来指定一个时间范围
CREATE TABLE IF NOT EXISTS DBSWITCH_CALENDARS CREATE TABLE IF NOT EXISTS DBSWITCH_CALENDARS
( (
SCHED_NAME VARCHAR(120) NOT NULL, SCHED_NAME VARCHAR(120) NOT NULL,
CALENDAR_NAME VARCHAR(200) NOT NULL, CALENDAR_NAME VARCHAR(200) NOT NULL,
CALENDAR BLOB NOT NULL, CALENDAR BLOB NOT NULL,
PRIMARY KEY (SCHED_NAME,CALENDAR_NAME) PRIMARY KEY (SCHED_NAME,CALENDAR_NAME)
)ENGINE=INNODB; )ENGINE=INNODB COMMENT = '以BLOB类型存储QUARTZ的CALENDAR日历信息,QUARTZ可配置一个日历来指定一个时间范围';
-- 存储已暂停的TRIGGER组的信息
CREATE TABLE IF NOT EXISTS DBSWITCH_PAUSED_TRIGGER_GRPS CREATE TABLE IF NOT EXISTS DBSWITCH_PAUSED_TRIGGER_GRPS
( (
SCHED_NAME VARCHAR(120) NOT NULL, SCHED_NAME VARCHAR(120) NOT NULL,
TRIGGER_GROUP VARCHAR(200) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL,
PRIMARY KEY (SCHED_NAME,TRIGGER_GROUP) PRIMARY KEY (SCHED_NAME,TRIGGER_GROUP)
) ENGINE=INNODB; ) ENGINE=INNODB COMMENT = '存储已暂停的TRIGGER组的信息';
-- 存储与已触发的TRIGGER相关的状态信息以及相联JOB的执行信息
CREATE TABLE IF NOT EXISTS DBSWITCH_FIRED_TRIGGERS CREATE TABLE IF NOT EXISTS DBSWITCH_FIRED_TRIGGERS
( (
SCHED_NAME VARCHAR(120) NOT NULL, SCHED_NAME VARCHAR(120) NOT NULL,
@@ -140,9 +131,8 @@ CREATE TABLE IF NOT EXISTS DBSWITCH_FIRED_TRIGGERS
IS_NONCONCURRENT VARCHAR(1) NULL, IS_NONCONCURRENT VARCHAR(1) NULL,
REQUESTS_RECOVERY VARCHAR(1) NULL, REQUESTS_RECOVERY VARCHAR(1) NULL,
PRIMARY KEY (SCHED_NAME,ENTRY_ID) PRIMARY KEY (SCHED_NAME,ENTRY_ID)
) ENGINE=INNODB; ) ENGINE=INNODB COMMENT = '存储与已触发的TRIGGER相关的状态信息以及相联JOB的执行信息';
-- 存储少量的有关 SCHEDULER的状态信息和别的 SCHEDULER 实例(假如是用于一个集群中)
CREATE TABLE IF NOT EXISTS DBSWITCH_SCHEDULER_STATE CREATE TABLE IF NOT EXISTS DBSWITCH_SCHEDULER_STATE
( (
SCHED_NAME VARCHAR(120) NOT NULL, SCHED_NAME VARCHAR(120) NOT NULL,
@@ -150,7 +140,7 @@ CREATE TABLE IF NOT EXISTS DBSWITCH_SCHEDULER_STATE
LAST_CHECKIN_TIME BIGINT(13) NOT NULL, LAST_CHECKIN_TIME BIGINT(13) NOT NULL,
CHECKIN_INTERVAL BIGINT(13) NOT NULL, CHECKIN_INTERVAL BIGINT(13) NOT NULL,
PRIMARY KEY (SCHED_NAME,INSTANCE_NAME) PRIMARY KEY (SCHED_NAME,INSTANCE_NAME)
) ENGINE=INNODB; ) ENGINE=INNODB COMMENT = '存储少量的有关 SCHEDULER的状态信息和别的 SCHEDULER 实例(假如是用于一个集群中)';
-- 存储程序的非观锁的信息(假如使用了悲观锁) -- 存储程序的非观锁的信息(假如使用了悲观锁)
CREATE TABLE IF NOT EXISTS DBSWITCH_LOCKS CREATE TABLE IF NOT EXISTS DBSWITCH_LOCKS
@@ -158,7 +148,7 @@ CREATE TABLE IF NOT EXISTS DBSWITCH_LOCKS
SCHED_NAME VARCHAR(120) NOT NULL, SCHED_NAME VARCHAR(120) NOT NULL,
LOCK_NAME VARCHAR(40) NOT NULL, LOCK_NAME VARCHAR(40) NOT NULL,
PRIMARY KEY (SCHED_NAME,LOCK_NAME) PRIMARY KEY (SCHED_NAME,LOCK_NAME)
) ENGINE=INNODB; ) ENGINE=INNODB COMMENT = '存储程序的非观锁的信息(假如使用了悲观锁)';
-- 创建索引 -- 创建索引
CREATE INDEX IDX_DBSWITCH_J_REQ_RECOVERY ON DBSWITCH_JOB_DETAILS(SCHED_NAME,REQUESTS_RECOVERY); CREATE INDEX IDX_DBSWITCH_J_REQ_RECOVERY ON DBSWITCH_JOB_DETAILS(SCHED_NAME,REQUESTS_RECOVERY);

View File

@@ -81,9 +81,10 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>net.minidev</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>json-smart</artifactId>
<scope>test</scope> <version>2.3</version>
<scope>runtime</scope>
</dependency> </dependency>
</dependencies> </dependencies>