32 changed files with 1983 additions and 430 deletions
@ -0,0 +1,130 @@ |
|||||
|
package com.zc.business.controller; |
||||
|
|
||||
|
import com.ruoyi.common.annotation.Log; |
||||
|
import com.ruoyi.common.core.controller.BaseController; |
||||
|
import com.ruoyi.common.core.domain.AjaxResult; |
||||
|
import com.ruoyi.common.core.page.TableDataInfo; |
||||
|
import com.ruoyi.common.enums.BusinessType; |
||||
|
import com.ruoyi.common.exception.job.TaskException; |
||||
|
import com.zc.business.domain.DcBatchFunctionsJob; |
||||
|
import com.zc.business.service.IDcBatchFunctionsJobService; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import org.quartz.SchedulerException; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import javax.validation.Valid; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 定时任务Controller |
||||
|
* |
||||
|
* @author zhaoxianglong |
||||
|
*/ |
||||
|
@Api(tags = {"定时任务"}) |
||||
|
@RestController |
||||
|
@RequestMapping("/business/dcBatchFunctionsJob") |
||||
|
public class DcBatchFunctionsJobController extends BaseController { |
||||
|
@Resource |
||||
|
private IDcBatchFunctionsJobService dcBatchFunctionsJobService; |
||||
|
|
||||
|
//*********************************调用功能记录增删改查******************************************
|
||||
|
|
||||
|
/** |
||||
|
* 分页查询列表 |
||||
|
* |
||||
|
* @param dcBatchFunctionsJob 请求参数 |
||||
|
* @return 分页查询结果 |
||||
|
*/ |
||||
|
@ApiOperation("分页查询列表") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:list')") |
||||
|
@GetMapping("list") |
||||
|
public TableDataInfo listFacility(DcBatchFunctionsJob dcBatchFunctionsJob) { |
||||
|
return getDataTable(dcBatchFunctionsJobService.pageDcBatchFunctionsJob(dcBatchFunctionsJob)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 无分页查询列表 |
||||
|
* |
||||
|
* @param dcBatchFunctionsJob 请求参数 |
||||
|
* @return 查询结果 |
||||
|
*/ |
||||
|
@ApiOperation("无分页查询列表") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:query')") |
||||
|
@GetMapping("query") |
||||
|
public AjaxResult queryFacility(DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException { |
||||
|
return AjaxResult.success(dcBatchFunctionsJobService.listDcBatchFunctionsJob(dcBatchFunctionsJob)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据id查询信息 |
||||
|
* |
||||
|
* @param id id |
||||
|
* @return 查询结果 |
||||
|
*/ |
||||
|
@ApiOperation("根据id查询信息") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:query')") |
||||
|
@GetMapping("{id}") |
||||
|
public AjaxResult getFacility(@PathVariable String id) { |
||||
|
return AjaxResult.success(dcBatchFunctionsJobService.getById(id)); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 新增 |
||||
|
* |
||||
|
* @param dcBatchFunctionsJob 新增参数 |
||||
|
* @return 新增操作结果 |
||||
|
*/ |
||||
|
@ApiOperation("新增") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:add')") |
||||
|
@Log(title = "新增", businessType = BusinessType.INSERT) |
||||
|
@PostMapping |
||||
|
public AjaxResult addFacility(@Valid @RequestBody DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException, TaskException { |
||||
|
return AjaxResult.success(dcBatchFunctionsJobService.addDcBatchFunctionsJob(dcBatchFunctionsJob)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改 |
||||
|
* |
||||
|
* @param dcBatchFunctionsJob 修改参数 |
||||
|
* @return 修改操作结果 |
||||
|
*/ |
||||
|
@ApiOperation("修改") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:edit')") |
||||
|
@Log(title = "修改", businessType = BusinessType.UPDATE) |
||||
|
@PutMapping |
||||
|
public AjaxResult editFacility(@Valid @RequestBody DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException, TaskException { |
||||
|
return toAjax(dcBatchFunctionsJobService.editDcBatchFunctionsJob(dcBatchFunctionsJob)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
* |
||||
|
* @param ids id集 |
||||
|
* @return 删除操作结果 |
||||
|
*/ |
||||
|
@ApiOperation("删除") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:remove')") |
||||
|
@Log(title = "删除", businessType = BusinessType.DELETE) |
||||
|
@DeleteMapping("{ids}") |
||||
|
public AjaxResult removeFacility(@PathVariable List<String> ids) throws SchedulerException, TaskException { |
||||
|
return toAjax(dcBatchFunctionsJobService.removeDcBatchFunctionsJob(ids)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
* |
||||
|
* @return 删除操作结果 |
||||
|
*/ |
||||
|
@ApiOperation("删除") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:remove')") |
||||
|
@Log(title = "删除", businessType = BusinessType.DELETE) |
||||
|
@DeleteMapping("/time/{groupId}/{time}") |
||||
|
public AjaxResult deletesATaskByTime(@PathVariable String groupId, @PathVariable String time) { |
||||
|
return toAjax(dcBatchFunctionsJobService.deletesATaskByTime(groupId, time)); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,135 @@ |
|||||
|
package com.zc.business.controller; |
||||
|
|
||||
|
import com.ruoyi.common.annotation.Log; |
||||
|
import com.ruoyi.common.core.controller.BaseController; |
||||
|
import com.ruoyi.common.core.domain.AjaxResult; |
||||
|
import com.ruoyi.common.core.page.TableDataInfo; |
||||
|
import com.ruoyi.common.enums.BusinessType; |
||||
|
import com.ruoyi.common.exception.job.TaskException; |
||||
|
import com.zc.business.domain.DcBatchFunctionsJobGroup; |
||||
|
import com.zc.business.service.IDcBatchFunctionsJobGroupService; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import org.quartz.SchedulerException; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import javax.validation.Valid; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 定时任务组Controller |
||||
|
* |
||||
|
* @author zhaoxianglong |
||||
|
*/ |
||||
|
@Api(tags = {"定时任务组"}) |
||||
|
@RestController |
||||
|
@RequestMapping("/business/dcBatchFunctionsJobGroup") |
||||
|
public class DcBatchFunctionsJobGroupController extends BaseController { |
||||
|
@Resource |
||||
|
private IDcBatchFunctionsJobGroupService dcBatchFunctionsJobGroupService; |
||||
|
|
||||
|
//*********************************调用功能记录增删改查******************************************
|
||||
|
|
||||
|
/** |
||||
|
* 分页查询列表 |
||||
|
* |
||||
|
* @param dcBatchFunctionsJobGroup 请求参数 |
||||
|
* @return 分页查询结果 |
||||
|
*/ |
||||
|
@ApiOperation("分页查询列表") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:list')") |
||||
|
@GetMapping("list") |
||||
|
public TableDataInfo listFacility(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { |
||||
|
return getDataTable(dcBatchFunctionsJobGroupService.pageDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 无分页查询列表 |
||||
|
* |
||||
|
* @param dcBatchFunctionsJobGroup 请求参数 |
||||
|
* @return 查询结果 |
||||
|
*/ |
||||
|
@ApiOperation("无分页查询列表") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:query')") |
||||
|
@GetMapping("query") |
||||
|
public AjaxResult queryFacility(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { |
||||
|
return AjaxResult.success(dcBatchFunctionsJobGroupService.listDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据id查询信息 |
||||
|
* |
||||
|
* @param id id |
||||
|
* @return 查询结果 |
||||
|
*/ |
||||
|
@ApiOperation("根据id查询信息") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:query')") |
||||
|
@GetMapping("{id}") |
||||
|
public AjaxResult getFacility(@PathVariable String id) { |
||||
|
return AjaxResult.success(dcBatchFunctionsJobGroupService.getById(id)); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 新增 |
||||
|
* |
||||
|
* @param dcBatchFunctionsJobGroup 新增参数 |
||||
|
* @return 新增操作结果 |
||||
|
*/ |
||||
|
@ApiOperation("新增") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:add')") |
||||
|
@Log(title = "新增", businessType = BusinessType.INSERT) |
||||
|
@PostMapping |
||||
|
public AjaxResult addFacility(@Valid @RequestBody DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { |
||||
|
return AjaxResult.success(dcBatchFunctionsJobGroupService.addDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改 |
||||
|
* |
||||
|
* @param dcBatchFunctionsJobGroup 修改参数 |
||||
|
* @return 修改操作结果 |
||||
|
*/ |
||||
|
@ApiOperation("修改") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:edit')") |
||||
|
@Log(title = "修改", businessType = BusinessType.UPDATE) |
||||
|
@PutMapping |
||||
|
public AjaxResult editFacility(@Valid @RequestBody DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { |
||||
|
return AjaxResult.success(dcBatchFunctionsJobGroupService.editDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
* |
||||
|
* @param ids id集 |
||||
|
* @return 删除操作结果 |
||||
|
*/ |
||||
|
@ApiOperation("删除") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:remove')") |
||||
|
@Log(title = "删除", businessType = BusinessType.DELETE) |
||||
|
@DeleteMapping("{ids}") |
||||
|
public AjaxResult removeFacility(@PathVariable List<String> ids) { |
||||
|
return toAjax(dcBatchFunctionsJobGroupService.removeDcBatchFunctionsJobGroup(ids)); |
||||
|
} |
||||
|
|
||||
|
//*********************************定时任务组功能******************************************
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 改变状态 |
||||
|
* |
||||
|
* @param dcBatchFunctionsJobGroup 请求参数 |
||||
|
* @return 删除操作结果 |
||||
|
*/ |
||||
|
@ApiOperation("改变状态") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:remove')") |
||||
|
@Log(title = "改变状态", businessType = BusinessType.DELETE) |
||||
|
@PostMapping("changeStatus") |
||||
|
public AjaxResult changeStatus(@Valid @RequestBody DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) throws SchedulerException, TaskException { |
||||
|
return toAjax(dcBatchFunctionsJobGroupService.changeStatus(dcBatchFunctionsJobGroup)); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,116 @@ |
|||||
|
package com.zc.business.controller; |
||||
|
|
||||
|
import com.ruoyi.common.annotation.Log; |
||||
|
import com.ruoyi.common.core.controller.BaseController; |
||||
|
import com.ruoyi.common.core.domain.AjaxResult; |
||||
|
import com.ruoyi.common.core.page.TableDataInfo; |
||||
|
import com.ruoyi.common.enums.BusinessType; |
||||
|
import com.zc.business.domain.DcOperLog; |
||||
|
import com.zc.business.service.IDcOperLogService; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import javax.validation.Valid; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 调用功能记录Controller |
||||
|
* |
||||
|
* @author zhaoxianglong |
||||
|
*/ |
||||
|
@Api(tags = {"调用功能记录"}) |
||||
|
@RestController |
||||
|
@RequestMapping("/business/dcOperLog") |
||||
|
public class DcOperLogController extends BaseController { |
||||
|
@Resource |
||||
|
private IDcOperLogService dcOperLogService; |
||||
|
|
||||
|
//*********************************调用功能记录增删改查******************************************
|
||||
|
|
||||
|
/** |
||||
|
* 分页查询列表 |
||||
|
* |
||||
|
* @param dcOperLog 请求参数 |
||||
|
* @return 分页查询结果 |
||||
|
*/ |
||||
|
@ApiOperation("分页查询列表") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:list')") |
||||
|
@GetMapping("list") |
||||
|
public TableDataInfo listFacility(DcOperLog dcOperLog,@RequestParam(value = "endTime", required = false)Date endTime,@RequestParam(value = "startTime", required = false)Date startTime) { |
||||
|
return getDataTable(dcOperLogService.pageDcOperLog(dcOperLog,endTime,startTime)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 无分页查询路网设施列表 |
||||
|
* |
||||
|
* @param dcOperLog 请求参数 |
||||
|
* @return 查询结果 |
||||
|
*/ |
||||
|
@ApiOperation("无分页查询列表") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:query')") |
||||
|
@GetMapping("query") |
||||
|
public AjaxResult queryFacility(DcOperLog dcOperLog, @RequestParam(value = "endTime", required = false) Date endTime, @RequestParam(value = "startTime", required = false)Date startTime) { |
||||
|
return AjaxResult.success(dcOperLogService.listDcOperLog(dcOperLog,endTime,startTime)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据id查询路网设施信息 |
||||
|
* |
||||
|
* @param id id |
||||
|
* @return 查询结果 |
||||
|
*/ |
||||
|
@ApiOperation("根据id查询信息") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:query')") |
||||
|
@GetMapping("{id}") |
||||
|
public AjaxResult getFacility(@PathVariable String id) { |
||||
|
return AjaxResult.success(dcOperLogService.getById(id)); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 新增 |
||||
|
* |
||||
|
* @param dcOperLog 新增参数 |
||||
|
* @return 新增操作结果 |
||||
|
*/ |
||||
|
@ApiOperation("新增") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:add')") |
||||
|
@Log(title = "新增", businessType = BusinessType.INSERT) |
||||
|
@PostMapping |
||||
|
public AjaxResult addFacility(@Valid @RequestBody DcOperLog dcOperLog) { |
||||
|
return toAjax(dcOperLogService.addDcOperLog(dcOperLog)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改 |
||||
|
* |
||||
|
* @param dcOperLog 修改参数 |
||||
|
* @return 修改操作结果 |
||||
|
*/ |
||||
|
@ApiOperation("修改") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:edit')") |
||||
|
@Log(title = "修改", businessType = BusinessType.UPDATE) |
||||
|
@PutMapping |
||||
|
public AjaxResult editFacility(@Valid @RequestBody DcOperLog dcOperLog) { |
||||
|
return toAjax(dcOperLogService.editDcOperLog(dcOperLog)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
* |
||||
|
* @param ids id集 |
||||
|
* @return 删除操作结果 |
||||
|
*/ |
||||
|
@ApiOperation("删除") |
||||
|
@PreAuthorize("@ss.hasPermi('iot:facility:remove')") |
||||
|
@Log(title = "删除", businessType = BusinessType.DELETE) |
||||
|
@DeleteMapping("{ids}") |
||||
|
public AjaxResult removeFacility(@PathVariable List<String> ids) { |
||||
|
return toAjax(dcOperLogService.removeDcOperLog(ids)); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,38 @@ |
|||||
|
package com.zc.business.domain; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
@Data |
||||
|
@ApiModel(value = "DcBatchFunctionsJob", description = "定时任务实体") |
||||
|
public class DcBatchFunctionsJob { |
||||
|
|
||||
|
//@TableId(value = "jobId", type = IdType.AUTO)
|
||||
|
private Integer jobId; |
||||
|
@ApiModelProperty("任务组ID") |
||||
|
private String jobGroup; |
||||
|
@ApiModelProperty("调用目标字符串") |
||||
|
private String invokeTarget; |
||||
|
@ApiModelProperty("调用参数") |
||||
|
private String callParameter; |
||||
|
//@ApiModelProperty("cron执行表达式")
|
||||
|
@TableField(exist = false) |
||||
|
private String cronExpression; |
||||
|
//@ApiModelProperty("状态")
|
||||
|
@TableField(exist = false) |
||||
|
private String status; |
||||
|
@TableField(exist = false) |
||||
|
private String time; |
||||
|
@ApiModelProperty("创建者") |
||||
|
private String createBy; |
||||
|
@ApiModelProperty("创建时间") |
||||
|
private Date createTime; |
||||
|
@ApiModelProperty("修改者") |
||||
|
private Date updateBy; |
||||
|
@ApiModelProperty("修改时间") |
||||
|
private Date updateTime; |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
package com.zc.business.domain; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
@Data |
||||
|
@ApiModel(value = "DcBatchFunctionsJobGroup", description = "定时任务组实体") |
||||
|
public class DcBatchFunctionsJobGroup { |
||||
|
|
||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||
|
private Long id; |
||||
|
@ApiModelProperty("任务组名称") |
||||
|
private String groupName; |
||||
|
@ApiModelProperty("状态") |
||||
|
private String status; |
||||
|
@ApiModelProperty("详细配置") |
||||
|
private String detailedConfiguration; |
||||
|
@ApiModelProperty("备注") |
||||
|
private String remark; |
||||
|
@ApiModelProperty("创建者") |
||||
|
private String createBy; |
||||
|
@ApiModelProperty("创建时间") |
||||
|
private Date createTime; |
||||
|
@ApiModelProperty("修改者") |
||||
|
private Date updateBy; |
||||
|
@ApiModelProperty("修改时间") |
||||
|
private Date updateTime; |
||||
|
} |
@ -0,0 +1,42 @@ |
|||||
|
package com.zc.business.domain; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
@Data |
||||
|
@ApiModel(value = "DcOperLog", description = "调用功能记录实体") |
||||
|
public class DcOperLog { |
||||
|
|
||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||
|
private String id; |
||||
|
@ApiModelProperty("设备ID") |
||||
|
private String dcDeviceId; |
||||
|
@ApiModelProperty("设备类型") |
||||
|
private String dcDeviceType; |
||||
|
@ApiModelProperty("设备名称") |
||||
|
private String dcDeviceName; |
||||
|
@ApiModelProperty("操作人员") |
||||
|
private String operName; |
||||
|
@ApiModelProperty("部门名称") |
||||
|
private String deptName; |
||||
|
@ApiModelProperty("操作类型") |
||||
|
private String operType; |
||||
|
@ApiModelProperty("主机地址") |
||||
|
private String operIp; |
||||
|
@ApiModelProperty("操作地点") |
||||
|
private String operLocation; |
||||
|
@ApiModelProperty("请求参数") |
||||
|
private String operParam; |
||||
|
@ApiModelProperty("返回参数") |
||||
|
private String jsonResult; |
||||
|
@ApiModelProperty("操作状态") |
||||
|
private Integer status; |
||||
|
@ApiModelProperty("操作时间") |
||||
|
private Date operTime; |
||||
|
|
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
|
||||
|
package com.zc.business.interfaces; |
||||
|
|
||||
|
import java.lang.annotation.ElementType; |
||||
|
import java.lang.annotation.Retention; |
||||
|
import java.lang.annotation.RetentionPolicy; |
||||
|
import java.lang.annotation.Target; |
||||
|
|
||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||
|
@Target(ElementType.METHOD) |
||||
|
public @interface OperationLog { |
||||
|
//String value() default "";
|
||||
|
|
||||
|
String operUrl(); |
||||
|
} |
@ -0,0 +1,136 @@ |
|||||
|
package com.zc.business.interfaces; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.ruoyi.common.core.domain.entity.SysDept; |
||||
|
import com.ruoyi.common.core.domain.model.LoginUser; |
||||
|
import com.ruoyi.common.utils.SecurityUtils; |
||||
|
import com.ruoyi.common.utils.ServletUtils; |
||||
|
import com.ruoyi.common.utils.ip.IpUtils; |
||||
|
import com.ruoyi.common.utils.spring.SpringUtils; |
||||
|
import com.ruoyi.system.service.ISysDeptService; |
||||
|
import com.zc.business.domain.DcDevice; |
||||
|
import com.zc.business.domain.DcOperLog; |
||||
|
import com.zc.business.service.IDcDeviceService; |
||||
|
import com.zc.business.service.IDcOperLogService; |
||||
|
import org.aspectj.lang.JoinPoint; |
||||
|
import org.aspectj.lang.ProceedingJoinPoint; |
||||
|
import org.aspectj.lang.annotation.*; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import java.util.*; |
||||
|
|
||||
|
@Aspect |
||||
|
@Component |
||||
|
public class OperationLogAspect { |
||||
|
|
||||
|
@AfterReturning(pointcut = "@annotation(operationLog)", returning = "jsonResult") |
||||
|
public void AfterReturning(JoinPoint joinPoint, OperationLog operationLog, Object jsonResult) throws Throwable { |
||||
|
System.out.println("运行成功"); |
||||
|
around((ProceedingJoinPoint) joinPoint, operationLog, "0", jsonResult, null); |
||||
|
} |
||||
|
|
||||
|
@AfterThrowing(value = "@annotation(operationLog)", throwing = "e") |
||||
|
public void AfterThrowing(JoinPoint joinPoint, OperationLog operationLog, Exception e) throws Throwable { |
||||
|
System.out.println("运行失败"); |
||||
|
around((ProceedingJoinPoint) joinPoint, operationLog, "1", null, e); |
||||
|
} |
||||
|
|
||||
|
public void around(ProceedingJoinPoint joinPoint, OperationLog operationLog, String state, Object jsonResult, Exception exception) throws Throwable { |
||||
|
|
||||
|
ISysDeptService deptService = SpringUtils.getBean(ISysDeptService.class); |
||||
|
IDcOperLogService dcOperLogService = SpringUtils.getBean(IDcOperLogService.class); |
||||
|
IDcDeviceService dcDeviceService = SpringUtils.getBean(IDcDeviceService.class); |
||||
|
|
||||
|
try { |
||||
|
DcOperLog dcOperLog = new DcOperLog(); |
||||
|
String operUrl = operationLog.operUrl(); |
||||
|
LoginUser loginUser; |
||||
|
try { |
||||
|
|
||||
|
loginUser = SecurityUtils.getLoginUser(); |
||||
|
}catch (Exception e){ |
||||
|
loginUser = null; |
||||
|
} |
||||
|
Object[] pointArgs = joinPoint.getArgs(); |
||||
|
|
||||
|
HttpServletRequest request; |
||||
|
try { |
||||
|
|
||||
|
request = ServletUtils.getRequest(); |
||||
|
}catch (Exception e){ |
||||
|
request = null; |
||||
|
} |
||||
|
if (operUrl.contains("batchFunctions")) { |
||||
|
if (loginUser != null) { |
||||
|
SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); |
||||
|
|
||||
|
dcOperLog.setOperName(loginUser.getUsername()); |
||||
|
dcOperLog.setDeptName(sysDept.getDeptName()); |
||||
|
dcOperLog.setOperLocation(loginUser.getLoginLocation()); |
||||
|
} |
||||
|
dcOperLog.setOperType("2"); |
||||
|
dcOperLog.setOperIp(IpUtils.getIpAddr(request)); |
||||
|
dcOperLog.setJsonResult(String.valueOf(joinPoint.proceed(pointArgs))); |
||||
|
dcOperLog.setOperTime(new Date()); |
||||
|
|
||||
|
|
||||
|
HashMap<String, ArrayList<JSONObject>> pointArg = (HashMap<String, ArrayList<JSONObject>>) pointArgs[0]; |
||||
|
ArrayList<JSONObject> devices = pointArg.get("devices"); |
||||
|
ArrayList<JSONObject> functions = pointArg.get("functions"); |
||||
|
for (Object dev : devices) { |
||||
|
JSONObject device = (JSONObject) JSON.toJSON(dev); |
||||
|
LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
lambdaQueryWrapper.eq(DcDevice::getId, device.get("id")); |
||||
|
List<DcDevice> list = dcDeviceService.list(lambdaQueryWrapper); |
||||
|
if (list.size() > 0) { |
||||
|
DcDevice dcDevice = list.get(0); |
||||
|
dcOperLog.setDcDeviceId(String.valueOf(dcDevice.getId())); |
||||
|
dcOperLog.setDcDeviceName(dcDevice.getDeviceName()); |
||||
|
dcOperLog.setDcDeviceType(dcDevice.getDeviceType()); |
||||
|
} |
||||
|
for (Object fun : functions) { |
||||
|
JSONObject function = (JSONObject) JSON.toJSON(fun); |
||||
|
dcOperLog.setOperParam(function.getString("params")); |
||||
|
dcOperLogService.addDcOperLog(dcOperLog); |
||||
|
} |
||||
|
} |
||||
|
} else if (operUrl.contains("functions")) { |
||||
|
LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
lambdaQueryWrapper.eq(DcDevice::getIotDeviceId, pointArgs[0]); |
||||
|
List<DcDevice> list = dcDeviceService.list(lambdaQueryWrapper); |
||||
|
if (list.size() > 0) { |
||||
|
DcDevice dcDevice = list.get(0); |
||||
|
dcOperLog.setDcDeviceId(String.valueOf(dcDevice.getId())); |
||||
|
dcOperLog.setDcDeviceName(dcDevice.getDeviceName()); |
||||
|
dcOperLog.setDcDeviceType(dcDevice.getDeviceType()); |
||||
|
} |
||||
|
if (loginUser != null) { |
||||
|
SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); |
||||
|
|
||||
|
dcOperLog.setOperName(loginUser.getUsername()); |
||||
|
dcOperLog.setDeptName(sysDept.getDeptName()); |
||||
|
dcOperLog.setOperLocation(loginUser.getLoginLocation()); |
||||
|
dcOperLog.setOperType("0"); |
||||
|
} else { |
||||
|
dcOperLog.setOperType("1"); |
||||
|
} |
||||
|
dcOperLog.setOperIp(IpUtils.getIpAddr(request)); |
||||
|
dcOperLog.setOperParam(Arrays.toString(joinPoint.getArgs())); |
||||
|
dcOperLog.setJsonResult(String.valueOf(joinPoint.proceed(pointArgs))); |
||||
|
if (Objects.equals(state, "0")) { |
||||
|
dcOperLog.setStatus(0); |
||||
|
} else { |
||||
|
dcOperLog.setStatus(1); |
||||
|
} |
||||
|
dcOperLog.setOperTime(new Date()); |
||||
|
dcOperLogService.addDcOperLog(dcOperLog); |
||||
|
} |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
throw e; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
package com.zc.business.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.zc.business.domain.DcBatchFunctionsJobGroup; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
/** |
||||
|
* 定时任务组Mapper接口 |
||||
|
* |
||||
|
* @author zhaoxianglong |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface DcBatchFunctionsJobGroupMapper extends BaseMapper<DcBatchFunctionsJobGroup> { |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
package com.zc.business.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.zc.business.domain.DcBatchFunctionsJob; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
/** |
||||
|
* 定时任务Mapper接口 |
||||
|
* |
||||
|
* @author zhaoxianglong |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface DcBatchFunctionsJobMapper extends BaseMapper<DcBatchFunctionsJob> { |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
package com.zc.business.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.zc.business.domain.DcOperLog; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
/** |
||||
|
* 调用功能记录Mapper接口 |
||||
|
* |
||||
|
* @author zhaoxianglong |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface DcOperLogMapper extends BaseMapper<DcOperLog> { |
||||
|
} |
@ -0,0 +1,53 @@ |
|||||
|
package com.zc.business.service; |
||||
|
|
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.ruoyi.common.exception.job.TaskException; |
||||
|
import com.zc.business.domain.DcBatchFunctionsJobGroup; |
||||
|
import org.quartz.SchedulerException; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 定时任务组Service接口 |
||||
|
* |
||||
|
* @author zhaoxianglong |
||||
|
*/ |
||||
|
public interface IDcBatchFunctionsJobGroupService extends IService<DcBatchFunctionsJobGroup> { |
||||
|
/** |
||||
|
* 添加信息 |
||||
|
* |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
DcBatchFunctionsJobGroup addDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup); |
||||
|
|
||||
|
/** |
||||
|
* 修改信息 |
||||
|
* |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
DcBatchFunctionsJobGroup editDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup); |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
* |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
boolean removeDcBatchFunctionsJobGroup(List<String> ids); |
||||
|
|
||||
|
/** |
||||
|
* 获取列表 |
||||
|
* |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
List<DcBatchFunctionsJobGroup> pageDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup); |
||||
|
|
||||
|
/** |
||||
|
* 获取列表 |
||||
|
* |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
List<DcBatchFunctionsJobGroup> listDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup); |
||||
|
|
||||
|
boolean changeStatus(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) throws SchedulerException, TaskException; |
||||
|
} |
@ -0,0 +1,57 @@ |
|||||
|
package com.zc.business.service; |
||||
|
|
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.ruoyi.common.exception.job.TaskException; |
||||
|
import com.zc.business.domain.DcBatchFunctionsJob; |
||||
|
import org.quartz.SchedulerException; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 定时任务Service接口 |
||||
|
* |
||||
|
* @author zhaoxianglong |
||||
|
*/ |
||||
|
public interface IDcBatchFunctionsJobService extends IService<DcBatchFunctionsJob> { |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 添加信息 |
||||
|
* |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
DcBatchFunctionsJob addDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) throws TaskException, SchedulerException; |
||||
|
|
||||
|
/** |
||||
|
* 修改信息 |
||||
|
* |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
boolean editDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException, TaskException; |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
* |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
boolean removeDcBatchFunctionsJob(List<String> ids) throws SchedulerException, TaskException; |
||||
|
|
||||
|
/** |
||||
|
* 获取列表 |
||||
|
* |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
List<DcBatchFunctionsJob> pageDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob); |
||||
|
|
||||
|
/** |
||||
|
* 获取列表 |
||||
|
* |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
List<DcBatchFunctionsJob> listDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException; |
||||
|
|
||||
|
boolean changeStatus(DcBatchFunctionsJob dcBatchFunctionsJob, String status) throws SchedulerException, TaskException; |
||||
|
|
||||
|
boolean deletesATaskByTime(String groupId, String time); |
||||
|
} |
@ -0,0 +1,52 @@ |
|||||
|
package com.zc.business.service; |
||||
|
|
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.zc.business.domain.DcOperLog; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* 调用功能记录Service接口 |
||||
|
* |
||||
|
* @author zhaoxianglong |
||||
|
*/ |
||||
|
public interface IDcOperLogService extends IService<DcOperLog> { |
||||
|
|
||||
|
/** |
||||
|
* 添加信息 |
||||
|
* |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
boolean addDcOperLog(DcOperLog dcOperLog); |
||||
|
|
||||
|
/** |
||||
|
* 修改信息 |
||||
|
* |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
boolean editDcOperLog(DcOperLog dcOperLog); |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
* |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
boolean removeDcOperLog(List<String> ids); |
||||
|
|
||||
|
/** |
||||
|
* 获取列表 |
||||
|
* |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
List<DcOperLog> pageDcOperLog(DcOperLog dcOperLog, Date endTime, Date startTime); |
||||
|
|
||||
|
/** |
||||
|
* 获取列表 |
||||
|
* |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
List<DcOperLog> listDcOperLog(DcOperLog dcOperLog,Date endTime,Date startTime); |
||||
|
|
||||
|
} |
@ -0,0 +1,125 @@ |
|||||
|
package com.zc.business.service.impl; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONArray; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.ruoyi.common.exception.job.TaskException; |
||||
|
import com.ruoyi.common.utils.PageUtils; |
||||
|
import com.zc.business.domain.DcBatchFunctionsJob; |
||||
|
import com.zc.business.domain.DcBatchFunctionsJobGroup; |
||||
|
import com.zc.business.mapper.DcBatchFunctionsJobGroupMapper; |
||||
|
import com.zc.business.service.IDcBatchFunctionsJobGroupService; |
||||
|
import com.zc.business.service.IDcBatchFunctionsJobService; |
||||
|
import org.quartz.SchedulerException; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 定时任务组Service业务层处理 |
||||
|
* |
||||
|
* @author zhaoxianglong |
||||
|
*/ |
||||
|
@Service |
||||
|
public class DcBatchFunctionsJobGroupServiceImpl extends ServiceImpl<DcBatchFunctionsJobGroupMapper, DcBatchFunctionsJobGroup> implements IDcBatchFunctionsJobGroupService { |
||||
|
|
||||
|
@Resource |
||||
|
private IDcBatchFunctionsJobService dcBatchFunctionsJobService; |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public DcBatchFunctionsJobGroup addDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { |
||||
|
dcBatchFunctionsJobGroup.setCreateTime(new Date()); |
||||
|
boolean save = save(dcBatchFunctionsJobGroup); |
||||
|
if (save) { |
||||
|
return dcBatchFunctionsJobGroup; |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public DcBatchFunctionsJobGroup editDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { |
||||
|
LambdaQueryWrapper<DcBatchFunctionsJobGroup> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
lambdaQueryWrapper.eq(DcBatchFunctionsJobGroup::getId, dcBatchFunctionsJobGroup.getId()); |
||||
|
dcBatchFunctionsJobGroup.setUpdateTime(new Date()); |
||||
|
boolean update = update(dcBatchFunctionsJobGroup, lambdaQueryWrapper); |
||||
|
if (update) { |
||||
|
return dcBatchFunctionsJobGroup; |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean removeDcBatchFunctionsJobGroup(List<String> ids) { |
||||
|
//LambdaQueryWrapper<DcBatchFunctionsJob> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
//lambdaQueryWrapper.in(DcBatchFunctionsJob::getJobGroup, ids);
|
||||
|
//dcBatchFunctionsJobService.remove(lambdaQueryWrapper);
|
||||
|
//List<DcBatchFunctionsJob> list = dcBatchFunctionsJobService.list();
|
||||
|
//List<Integer> collect = list.stream().filter(item -> {
|
||||
|
// String callParameter = item.getCallParameter();
|
||||
|
// return true;
|
||||
|
//}).map(DcBatchFunctionsJob::getJobId).collect(Collectors.toList());
|
||||
|
//dcBatchFunctionsJobService.removeByIds(collect);
|
||||
|
LambdaQueryWrapper<DcBatchFunctionsJobGroup> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
lambdaQueryWrapper.in(DcBatchFunctionsJobGroup::getId, ids); |
||||
|
List<DcBatchFunctionsJobGroup> list = list(lambdaQueryWrapper); |
||||
|
ArrayList<String> arrayList = new ArrayList<>(); |
||||
|
list.forEach(item -> { |
||||
|
JSONArray detailedConfiguration = JSONArray.parseArray(item.getDetailedConfiguration()); |
||||
|
detailedConfiguration.forEach(ite -> { |
||||
|
JSONObject jsonObject = (JSONObject) ite; |
||||
|
JSONArray tasks = jsonObject.getJSONArray("tasks"); |
||||
|
tasks.forEach(it -> { |
||||
|
arrayList.add(String.valueOf(it)); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
|
dcBatchFunctionsJobService.removeByIds(arrayList); |
||||
|
return removeByIds(ids); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<DcBatchFunctionsJobGroup> pageDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { |
||||
|
PageUtils.startPage(); |
||||
|
return list(getDcBatchFunctionsJobGroupLambdaQueryWrapper(dcBatchFunctionsJobGroup)); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<DcBatchFunctionsJobGroup> listDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { |
||||
|
return list(getDcBatchFunctionsJobGroupLambdaQueryWrapper(dcBatchFunctionsJobGroup)); |
||||
|
} |
||||
|
|
||||
|
private static LambdaQueryWrapper<DcBatchFunctionsJobGroup> getDcBatchFunctionsJobGroupLambdaQueryWrapper(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { |
||||
|
LambdaQueryWrapper<DcBatchFunctionsJobGroup> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
if (dcBatchFunctionsJobGroup.getId() != null) { |
||||
|
lambdaQueryWrapper.eq(DcBatchFunctionsJobGroup::getId, dcBatchFunctionsJobGroup.getId()); |
||||
|
} |
||||
|
if (dcBatchFunctionsJobGroup.getGroupName() != null) { |
||||
|
lambdaQueryWrapper.like(DcBatchFunctionsJobGroup::getGroupName, dcBatchFunctionsJobGroup.getGroupName()); |
||||
|
} |
||||
|
if (dcBatchFunctionsJobGroup.getStatus() != null) { |
||||
|
lambdaQueryWrapper.eq(DcBatchFunctionsJobGroup::getStatus, dcBatchFunctionsJobGroup.getStatus()); |
||||
|
} |
||||
|
return lambdaQueryWrapper; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean changeStatus(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) throws TaskException, SchedulerException { |
||||
|
DcBatchFunctionsJob dcBatchFunctionsJob = new DcBatchFunctionsJob(); |
||||
|
dcBatchFunctionsJob.setJobGroup(String.valueOf(dcBatchFunctionsJobGroup.getId())); |
||||
|
List<DcBatchFunctionsJob> dcBatchFunctionsJobs = dcBatchFunctionsJobService.listDcBatchFunctionsJob(dcBatchFunctionsJob); |
||||
|
for (DcBatchFunctionsJob batchFunctionsJob : dcBatchFunctionsJobs) { |
||||
|
boolean changeStatus = dcBatchFunctionsJobService.changeStatus(batchFunctionsJob, dcBatchFunctionsJobGroup.getStatus()); |
||||
|
if (!changeStatus) { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup1 = editDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup); |
||||
|
return dcBatchFunctionsJobGroup1 != null; |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,257 @@ |
|||||
|
package com.zc.business.service.impl; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONArray; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.ruoyi.common.exception.job.TaskException; |
||||
|
import com.ruoyi.common.utils.PageUtils; |
||||
|
import com.ruoyi.common.utils.spring.SpringUtils; |
||||
|
import com.zc.business.domain.DcBatchFunctionsJob; |
||||
|
import com.zc.business.domain.DcBatchFunctionsJobGroup; |
||||
|
import com.zc.business.mapper.DcBatchFunctionsJobMapper; |
||||
|
import com.zc.business.service.IDcBatchFunctionsJobGroupService; |
||||
|
import com.zc.business.service.IDcBatchFunctionsJobService; |
||||
|
import com.zc.business.utils.ScheduleUtils; |
||||
|
import org.quartz.JobKey; |
||||
|
import org.quartz.Scheduler; |
||||
|
import org.quartz.SchedulerException; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import javax.annotation.PostConstruct; |
||||
|
import javax.annotation.Resource; |
||||
|
import java.util.*; |
||||
|
import java.util.concurrent.ThreadLocalRandom; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* 定时任务Service业务层处理 |
||||
|
* |
||||
|
* @author zhaoxianglong |
||||
|
*/ |
||||
|
@Service |
||||
|
public class DcBatchFunctionsJobServiceImpl extends ServiceImpl<DcBatchFunctionsJobMapper, DcBatchFunctionsJob> implements IDcBatchFunctionsJobService { |
||||
|
|
||||
|
@Resource |
||||
|
private Scheduler scheduler; |
||||
|
@Resource |
||||
|
private IDcBatchFunctionsJobGroupService dcBatchFunctionsJobGroupService; |
||||
|
|
||||
|
/** |
||||
|
* 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据) |
||||
|
*/ |
||||
|
@PostConstruct |
||||
|
public void init() throws TaskException, SchedulerException { |
||||
|
List<DcBatchFunctionsJob> jobList = list(); |
||||
|
for (DcBatchFunctionsJob job : jobList) { |
||||
|
createScheduleJob(job); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void createScheduleJob(DcBatchFunctionsJob job) throws SchedulerException, TaskException { |
||||
|
IDcBatchFunctionsJobGroupService dcBatchFunctionsJobGroupService = SpringUtils.getBean(IDcBatchFunctionsJobGroupService.class); |
||||
|
DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup = dcBatchFunctionsJobGroupService.getById(job.getJobGroup()); |
||||
|
if (dcBatchFunctionsJobGroup != null) { |
||||
|
JSONArray jsonArray = JSONObject.parseArray(dcBatchFunctionsJobGroup.getDetailedConfiguration()); |
||||
|
for (Object o : jsonArray) { |
||||
|
String time = ((JSONObject) o).getString("time"); |
||||
|
String[] times = time.split(":"); |
||||
|
String cron = times[2] + " " + times[1] + " " + times[0] + " " + " * * ?"; |
||||
|
JSONArray tasks = ((JSONObject) o).getJSONArray("tasks"); |
||||
|
for (Object task : tasks) { |
||||
|
if (Objects.equals(String.valueOf(job.getJobId()), String.valueOf(task))) { |
||||
|
job.setCronExpression(cron); |
||||
|
job.setStatus(dcBatchFunctionsJobGroup.getStatus()); |
||||
|
ScheduleUtils.createScheduleJob(scheduler, job); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public DcBatchFunctionsJob addDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) throws TaskException, SchedulerException { |
||||
|
DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup = dcBatchFunctionsJobGroupService.getById(dcBatchFunctionsJob.getJobGroup()); |
||||
|
if (dcBatchFunctionsJobGroup != null) { |
||||
|
JSONArray detailedConfigurations = JSONArray.parseArray(dcBatchFunctionsJobGroup.getDetailedConfiguration()); |
||||
|
String time = dcBatchFunctionsJob.getTime(); |
||||
|
if (time == null) { |
||||
|
return null; |
||||
|
|
||||
|
} |
||||
|
List<Object> detaileds = detailedConfigurations.stream().filter(detailed -> |
||||
|
Objects.equals((String) ((JSONObject) detailed).get("time"), time) |
||||
|
).collect(Collectors.toList()); |
||||
|
Integer id = ThreadLocalRandom.current().nextInt(0, 999999999); |
||||
|
if (detaileds.size() > 0) { |
||||
|
JSONObject detailed = (JSONObject) detaileds.get(0); |
||||
|
JSONArray tasks = detailed.getJSONArray("tasks"); |
||||
|
tasks.add(id); |
||||
|
detailed.put("tasks", tasks); |
||||
|
detailedConfigurations.stream().filter(detailedConfiguration -> Objects.equals((String) ((JSONObject) detailed).get("time"), time)).map(detadetailedConfiguration -> detailed); |
||||
|
} else { |
||||
|
JSONArray tasks = new JSONArray(); |
||||
|
tasks.add(id); |
||||
|
JSONObject detailedConfiguration = new JSONObject(); |
||||
|
detailedConfiguration.put("time", time); |
||||
|
detailedConfiguration.put("tasks", tasks); |
||||
|
detailedConfigurations.add(detailedConfiguration); |
||||
|
} |
||||
|
dcBatchFunctionsJobGroup.setDetailedConfiguration(String.valueOf(detailedConfigurations)); |
||||
|
dcBatchFunctionsJobGroupService.editDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup); |
||||
|
dcBatchFunctionsJob.setJobId(id); |
||||
|
dcBatchFunctionsJob.setCreateTime(new Date()); |
||||
|
createScheduleJob(dcBatchFunctionsJob); |
||||
|
boolean save = save(dcBatchFunctionsJob); |
||||
|
if (save) { |
||||
|
return dcBatchFunctionsJob; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean editDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException, TaskException { |
||||
|
LambdaQueryWrapper<DcBatchFunctionsJob> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
lambdaQueryWrapper.eq(DcBatchFunctionsJob::getJobId, dcBatchFunctionsJob.getJobId()); |
||||
|
dcBatchFunctionsJob.setUpdateTime(new Date()); |
||||
|
boolean update = updateSchedulerJob(dcBatchFunctionsJob, dcBatchFunctionsJob.getJobGroup()); |
||||
|
if (update) { |
||||
|
return update(dcBatchFunctionsJob, lambdaQueryWrapper); |
||||
|
} |
||||
|
return update; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 更新任务 |
||||
|
* |
||||
|
* @param job 任务对象 |
||||
|
* @param jobGroup 任务组名 |
||||
|
*/ |
||||
|
public boolean updateSchedulerJob(DcBatchFunctionsJob job, String jobGroup) throws SchedulerException, TaskException { |
||||
|
Long jobId = Long.valueOf(job.getJobId()); |
||||
|
// 判断是否存在
|
||||
|
JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); |
||||
|
if (scheduler.checkExists(jobKey)) { |
||||
|
// 防止创建时存在数据问题 先移除,然后在执行创建操作
|
||||
|
scheduler.deleteJob(jobKey); |
||||
|
} |
||||
|
|
||||
|
createScheduleJob(job); |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public boolean removeDcBatchFunctionsJob(List<String> ids) throws SchedulerException, TaskException { |
||||
|
for (String id : ids) { |
||||
|
DcBatchFunctionsJob job = new DcBatchFunctionsJob(); |
||||
|
job.setJobId(Integer.valueOf(id)); |
||||
|
List<DcBatchFunctionsJob> dcBatchFunctionsJobs = listDcBatchFunctionsJob(job); |
||||
|
if (dcBatchFunctionsJobs.size() == 0) { |
||||
|
return false; |
||||
|
} |
||||
|
DcBatchFunctionsJob dcBatchFunctionsJob = dcBatchFunctionsJobs.get(0); |
||||
|
ScheduleUtils.deleteJob(scheduler, dcBatchFunctionsJob); |
||||
|
DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup = dcBatchFunctionsJobGroupService.getById(dcBatchFunctionsJob.getJobGroup()); |
||||
|
if (dcBatchFunctionsJobGroup == null) { |
||||
|
return false; |
||||
|
} |
||||
|
JSONArray detailedConfigurations = JSONArray.parseArray(dcBatchFunctionsJobGroup.getDetailedConfiguration()); |
||||
|
List<Object> detaileds = detailedConfigurations.stream().filter(detailed -> { |
||||
|
boolean result = false; |
||||
|
boolean tasks = JSONArray.parseArray(String.valueOf(((JSONObject) detailed).get("tasks"))).contains(id); |
||||
|
JSONObject jsonObject = (JSONObject) detailed; |
||||
|
JSONArray jsonArray = jsonObject.getJSONArray("tasks"); |
||||
|
boolean contains = jsonArray.contains(id); |
||||
|
for (Object o : jsonArray) { |
||||
|
if (Objects.equals(String.valueOf(o), id)) { |
||||
|
result = true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
}).collect(Collectors.toList()); |
||||
|
System.out.println(detaileds); |
||||
|
if (detaileds.size() > 0) { |
||||
|
JSONObject detailed = (JSONObject) detaileds.get(0); |
||||
|
JSONArray tasks = detailed.getJSONArray("tasks"); |
||||
|
|
||||
|
tasks = tasks.stream() |
||||
|
.filter(task -> !Objects.equals(String.valueOf(task), id)) |
||||
|
.collect(Collectors.toCollection(JSONArray::new)); |
||||
|
detailed.put("tasks", tasks); |
||||
|
detailedConfigurations.stream().filter(detailedConfiguration -> ((JSONObject) detailed).get("time") == dcBatchFunctionsJob.getTime()).map(detadetailedConfiguration -> detailed); |
||||
|
dcBatchFunctionsJobGroup.setDetailedConfiguration(String.valueOf(detailedConfigurations)); |
||||
|
dcBatchFunctionsJobGroupService.editDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup); |
||||
|
} |
||||
|
} |
||||
|
LambdaQueryWrapper<DcBatchFunctionsJob> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
lambdaQueryWrapper.in(DcBatchFunctionsJob::getJobId, ids); |
||||
|
return remove(lambdaQueryWrapper); |
||||
|
//return true;
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<DcBatchFunctionsJob> pageDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) { |
||||
|
PageUtils.startPage(); |
||||
|
return list(getDcBatchFunctionsJobLambdaQueryWrapper(dcBatchFunctionsJob)); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<DcBatchFunctionsJob> listDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException { |
||||
|
return list(getDcBatchFunctionsJobLambdaQueryWrapper(dcBatchFunctionsJob)); |
||||
|
} |
||||
|
|
||||
|
private static LambdaQueryWrapper<DcBatchFunctionsJob> getDcBatchFunctionsJobLambdaQueryWrapper(DcBatchFunctionsJob dcBatchFunctionsJob) { |
||||
|
LambdaQueryWrapper<DcBatchFunctionsJob> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
if (dcBatchFunctionsJob.getJobId() != null) { |
||||
|
lambdaQueryWrapper.eq(DcBatchFunctionsJob::getJobId, dcBatchFunctionsJob.getJobId()); |
||||
|
} |
||||
|
//if (dcBatchFunctionsJob.getJobName() != null) {
|
||||
|
// lambdaQueryWrapper.like(DcBatchFunctionsJob::getJobName, dcBatchFunctionsJob.getJobName());
|
||||
|
//}
|
||||
|
if (dcBatchFunctionsJob.getJobGroup() != null) { |
||||
|
lambdaQueryWrapper.eq(DcBatchFunctionsJob::getJobGroup, dcBatchFunctionsJob.getJobGroup()); |
||||
|
} |
||||
|
return lambdaQueryWrapper; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean changeStatus(DcBatchFunctionsJob dcBatchFunctionsJob, String status) throws SchedulerException, TaskException { |
||||
|
if (Objects.equals(status, "0")) { |
||||
|
scheduler.resumeJob(ScheduleUtils.getJobKey(Long.valueOf(dcBatchFunctionsJob.getJobId()), String.valueOf(dcBatchFunctionsJob.getJobGroup()))); |
||||
|
} else { |
||||
|
scheduler.pauseJob(ScheduleUtils.getJobKey(Long.valueOf(dcBatchFunctionsJob.getJobId()), String.valueOf(dcBatchFunctionsJob.getJobGroup()))); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean deletesATaskByTime(String groupId, String time) { |
||||
|
DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup = dcBatchFunctionsJobGroupService.getById(groupId); |
||||
|
JSONArray detailedConfiguration = JSONArray.parseArray(dcBatchFunctionsJobGroup.getDetailedConfiguration()); |
||||
|
List<Object> filter = detailedConfiguration.stream().filter(item -> Objects.equals(((JSONObject) item).getString("time"), time)).collect(Collectors.toList()); |
||||
|
filter.forEach(item -> { |
||||
|
JSONArray tasks = ((JSONObject) item).getJSONArray("tasks"); |
||||
|
tasks.forEach(ite -> { |
||||
|
LambdaQueryWrapper<DcBatchFunctionsJob> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
lambdaQueryWrapper.eq(DcBatchFunctionsJob::getJobId, ite); |
||||
|
remove(lambdaQueryWrapper); |
||||
|
}); |
||||
|
detailedConfiguration.remove(item); |
||||
|
}); |
||||
|
dcBatchFunctionsJobGroup.setDetailedConfiguration(detailedConfiguration.toString()); |
||||
|
DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup1 = dcBatchFunctionsJobGroupService.editDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup); |
||||
|
if (dcBatchFunctionsJobGroup1 != null) { |
||||
|
return true; |
||||
|
} else { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
File diff suppressed because it is too large
@ -0,0 +1,73 @@ |
|||||
|
package com.zc.business.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.ruoyi.common.utils.PageUtils; |
||||
|
import com.zc.business.domain.*; |
||||
|
import com.zc.business.mapper.DcOperLogMapper; |
||||
|
import com.zc.business.service.*; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.*; |
||||
|
|
||||
|
/** |
||||
|
* 调用功能记录Service业务层处理 |
||||
|
* |
||||
|
* @author zhaoxianglong |
||||
|
*/ |
||||
|
@Service |
||||
|
public class DcOperLogServiceImpl extends ServiceImpl<DcOperLogMapper, DcOperLog> implements IDcOperLogService { |
||||
|
|
||||
|
@Override |
||||
|
public boolean addDcOperLog(DcOperLog dcOperLog) { |
||||
|
return save(dcOperLog); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean editDcOperLog(DcOperLog dcOperLog) { |
||||
|
LambdaQueryWrapper<DcOperLog> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
lambdaQueryWrapper.eq(DcOperLog::getId, dcOperLog.getId()); |
||||
|
return update(dcOperLog, lambdaQueryWrapper); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean removeDcOperLog(List<String> ids) { |
||||
|
return removeByIds(ids); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<DcOperLog> pageDcOperLog(DcOperLog dcOperLog, Date endTime, Date startTime) { |
||||
|
PageUtils.startPage(); |
||||
|
return list(getDcOperLogLambdaQueryWrapper(dcOperLog,endTime,startTime)); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<DcOperLog> listDcOperLog(DcOperLog dcOperLog,Date endTime,Date startTime) { |
||||
|
return list(getDcOperLogLambdaQueryWrapper(dcOperLog,endTime,startTime)); |
||||
|
} |
||||
|
|
||||
|
private static LambdaQueryWrapper<DcOperLog> getDcOperLogLambdaQueryWrapper(DcOperLog dcOperLog,Date endTime,Date startTime) { |
||||
|
LambdaQueryWrapper<DcOperLog> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
if (dcOperLog.getId() != null) { |
||||
|
lambdaQueryWrapper.eq(DcOperLog::getId, dcOperLog.getId()); |
||||
|
} |
||||
|
if (dcOperLog.getDcDeviceType() != null) { |
||||
|
lambdaQueryWrapper.like(DcOperLog::getDcDeviceType, dcOperLog.getDcDeviceType()); |
||||
|
} |
||||
|
if (dcOperLog.getDcDeviceName() != null) { |
||||
|
lambdaQueryWrapper.like(DcOperLog::getDcDeviceName, dcOperLog.getDcDeviceName()); |
||||
|
} |
||||
|
if (dcOperLog.getOperName() != null) { |
||||
|
lambdaQueryWrapper.like(DcOperLog::getOperName, dcOperLog.getOperName()); |
||||
|
} |
||||
|
if (dcOperLog.getDeptName() != null) { |
||||
|
lambdaQueryWrapper.like(DcOperLog::getDeptName, dcOperLog.getDeptName()); |
||||
|
} |
||||
|
if (endTime!=null&&startTime!=null) { |
||||
|
lambdaQueryWrapper.between(DcOperLog::getOperTime, startTime, endTime); |
||||
|
} |
||||
|
lambdaQueryWrapper.select(DcOperLog::getId, DcOperLog::getDcDeviceId, DcOperLog::getDcDeviceType, DcOperLog::getDcDeviceType, DcOperLog::getOperName,DcOperLog::getDeptName, DcOperLog::getOperType, DcOperLog::getOperIp, DcOperLog::getOperLocation,DcOperLog::getOperParam, DcOperLog::getJsonResult, DcOperLog::getStatus, DcOperLog::getOperTime); |
||||
|
return lambdaQueryWrapper; |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,36 @@ |
|||||
|
package com.zc.business.task; |
||||
|
|
||||
|
|
||||
|
import com.alibaba.fastjson.JSONArray; |
||||
|
import com.ruoyi.common.utils.spring.SpringUtils; |
||||
|
import com.zc.business.controller.DcDeviceController; |
||||
|
import com.zc.business.domain.DcBatchFunctionsJob; |
||||
|
import com.zc.business.service.impl.DcBatchFunctionsJobServiceImpl; |
||||
|
import com.zc.common.core.httpclient.exception.HttpException; |
||||
|
import org.quartz.SchedulerException; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
|
||||
|
/** |
||||
|
* 定时任务调度测试 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class ScheduledTaskSchedulingTask { |
||||
|
|
||||
|
|
||||
|
public void invokeTarget(DcBatchFunctionsJob dcBatchFunctionsJob) throws HttpException, IOException, InterruptedException, SchedulerException { |
||||
|
|
||||
|
DcBatchFunctionsJobServiceImpl dcBatchFunctionsJobService = SpringUtils.getBean(DcBatchFunctionsJobServiceImpl.class); |
||||
|
DcDeviceController deviceController = SpringUtils.getBean(DcDeviceController.class); |
||||
|
|
||||
|
DcBatchFunctionsJob job = dcBatchFunctionsJobService.listDcBatchFunctionsJob(dcBatchFunctionsJob).get(0); |
||||
|
if (job != null) { |
||||
|
JSONArray jsonArray = JSONArray.parseArray(job.getCallParameter()); |
||||
|
for (Object o : jsonArray) { |
||||
|
deviceController.batchInvokedFunction(o); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,67 @@ |
|||||
|
package com.zc.business.utils; |
||||
|
|
||||
|
import com.ruoyi.common.constant.ScheduleConstants; |
||||
|
import com.ruoyi.common.exception.job.TaskException; |
||||
|
import com.zc.business.domain.DcBatchFunctionsJob; |
||||
|
import org.quartz.*; |
||||
|
|
||||
|
/** |
||||
|
* 定时任务工具类 |
||||
|
* |
||||
|
* @author ruoyi |
||||
|
*/ |
||||
|
public class ScheduleUtils { |
||||
|
|
||||
|
/** |
||||
|
* 构建任务键对象 |
||||
|
*/ |
||||
|
public static JobKey getJobKey(Long jobId, String jobGroup) { |
||||
|
return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 创建定时任务 |
||||
|
*/ |
||||
|
public static void createScheduleJob(Scheduler scheduler, DcBatchFunctionsJob job) throws SchedulerException, TaskException { |
||||
|
Class<? extends Job> jobClass = ScheduledTaskScheduling.class; |
||||
|
// 构建job信息
|
||||
|
Long jobId = Long.valueOf(job.getJobId()); |
||||
|
String jobGroup = String.valueOf(job.getJobGroup()); |
||||
|
JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build(); |
||||
|
|
||||
|
// 表达式调度构建器
|
||||
|
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); |
||||
|
cronScheduleBuilder = cronScheduleBuilder.withMisfireHandlingInstructionIgnoreMisfires(); |
||||
|
|
||||
|
// 按新的cronExpression表达式构建一个新的trigger
|
||||
|
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup)) |
||||
|
.withSchedule(cronScheduleBuilder).build(); |
||||
|
|
||||
|
// 放入参数,运行时的方法可以获取
|
||||
|
jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job); |
||||
|
|
||||
|
// 判断是否存在
|
||||
|
if (scheduler.checkExists(ScheduleUtils.getJobKey(jobId, jobGroup))) { |
||||
|
// 防止创建时存在数据问题 先移除,然后在执行创建操作
|
||||
|
scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
||||
|
} |
||||
|
|
||||
|
scheduler.scheduleJob(jobDetail, trigger); |
||||
|
|
||||
|
// 暂停任务
|
||||
|
if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) |
||||
|
{ |
||||
|
scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除定时任务 |
||||
|
*/ |
||||
|
public static void deleteJob(Scheduler scheduler, DcBatchFunctionsJob job) throws SchedulerException, TaskException { |
||||
|
if (scheduler.checkExists(ScheduleUtils.getJobKey(Long.valueOf(job.getJobId()), String.valueOf(job.getJobGroup())))) { |
||||
|
scheduler.deleteJob(getJobKey(Long.valueOf(job.getJobId()), String.valueOf(job.getJobGroup()))); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
package com.zc.business.utils; |
||||
|
|
||||
|
import com.ruoyi.quartz.domain.SysJob; |
||||
|
import com.ruoyi.quartz.util.AbstractQuartzJob; |
||||
|
import com.zc.business.domain.DcBatchFunctionsJob; |
||||
|
import com.zc.business.task.ScheduledTaskSchedulingTask; |
||||
|
import org.quartz.JobExecutionContext; |
||||
|
|
||||
|
public class ScheduledTaskScheduling extends AbstractQuartzJob { |
||||
|
|
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception { |
||||
|
ScheduledTaskSchedulingTask scheduledTaskSchedulingTask = new ScheduledTaskSchedulingTask(); |
||||
|
DcBatchFunctionsJob dcBatchFunctionsJob = new DcBatchFunctionsJob(); |
||||
|
dcBatchFunctionsJob.setJobId(Math.toIntExact(sysJob.getJobId())); |
||||
|
scheduledTaskSchedulingTask.invokeTarget(dcBatchFunctionsJob); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue