job
潘志宝
2024-08-26 cd5f8564e84694d098a4eeddecc36aa8ce7cfdf3
job
已修改8个文件
已删除1个文件
已添加1个文件
703 ■■■■ 文件已修改
iailab-module-data/iailab-module-data-biz/db/mysql/mysql.sql 532 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/controller/admin/ChannelModbusDeviceController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/controller/admin/ScheduleJobController.java 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/dao/ScheduleJobDao.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/service/ScheduleJobService.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/service/impl/ScheduleJobServiceImpl.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/utils/ScheduleJob.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/vo/ScheduleJobReqVO.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/resources/application-dev.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/resources/application.yml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/db/mysql/mysql.sql
文件已删除
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/modbus/controller/admin/ChannelModbusDeviceController.java
@@ -8,9 +8,9 @@
import com.iailab.module.data.channel.modbus.service.ChannelModbusDeviceService;
import javax.annotation.Resource;
import javax.validation.Valid;
import com.iailab.module.data.channel.modbus.vo.ModBusDeviceRespVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.UUID;
@@ -35,7 +35,7 @@
     * @param reqVO
     */
    @GetMapping("/page")
    public CommonResult<PageResult<ModBusDeviceRespVO>> list(@Valid ModBusDevicePageReqVO reqVO) {
    public CommonResult<PageResult<ModBusDeviceRespVO>> list(@Validated ModBusDevicePageReqVO reqVO) {
        PageResult<ChannelModBusDeviceEntity> page = channelModbusDeviceService.queryPage(reqVO);
        return success(BeanUtils.toBean(page, ModBusDeviceRespVO.class));
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/controller/admin/ScheduleJobController.java
@@ -1,6 +1,8 @@
package com.iailab.module.data.job.controller.admin;
import com.iailab.framework.common.page.PageData;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.common.util.object.BeanUtils;
import com.iailab.framework.tenant.core.context.TenantContextHolder;
import com.iailab.module.data.common.utils.Constant;
import com.iailab.framework.common.pojo.CommonResult;
import com.iailab.framework.common.util.validation.ValidationUtils;
@@ -8,16 +10,21 @@
import com.iailab.framework.common.validation.group.DefaultGroup;
import com.iailab.framework.common.validation.group.UpdateGroup;
import com.iailab.module.data.job.dto.ScheduleJobDTO;
import com.iailab.module.data.job.entity.ScheduleJobEntity;
import com.iailab.module.data.job.service.ScheduleJobService;
import com.iailab.module.data.job.vo.ScheduleJobReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static com.iailab.framework.common.pojo.CommonResult.success;
/**
 * 定时任务
@@ -25,7 +32,7 @@
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("/sys/schedule")
@RequestMapping("/data/job/schedule")
@Tag(name = "定时任务")
public class ScheduleJobController {
    @Resource
@@ -40,25 +47,26 @@
        @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)") ,
        @Parameter(name = "beanName", description = "beanName")
    })
    @PreAuthorize("@ss.hasPermission('sys:schedule:page')")
    public CommonResult<PageData<ScheduleJobDTO>> page(@RequestParam Map<String, Object> params){
        PageData<ScheduleJobDTO> page = scheduleJobService.page(params);
    @PreAuthorize("@ss.hasPermission('data:schedule:query')")
    public CommonResult<PageResult<ScheduleJobDTO>> page(@Validated ScheduleJobReqVO reqVO){
        reqVO.setTenantId(TenantContextHolder.getTenantId());
        PageResult<ScheduleJobEntity> page = scheduleJobService.page(reqVO);
        return new CommonResult<PageData<ScheduleJobDTO>>().setData(page);
        return success(BeanUtils.toBean(page, ScheduleJobDTO.class));
    }
    @GetMapping("{id}")
    @GetMapping("info")
    @Operation(summary = "信息")
    @PreAuthorize("@ss.hasPermission('sys:schedule:info')")
    public CommonResult<ScheduleJobDTO> info(@PathVariable("id") Long id){
    @PreAuthorize("@ss.hasPermission('data:schedule:query')")
    public CommonResult<ScheduleJobDTO> info(@RequestParam("id") Long id){
        ScheduleJobDTO schedule = scheduleJobService.get(id);
        
        return new CommonResult<ScheduleJobDTO>().setData(schedule);
    }
    @PostMapping
    @PostMapping("/create")
    @Operation(summary = "保存")
    @PreAuthorize("@ss.hasPermission('sys:schedule:save')")
    @PreAuthorize("@ss.hasPermission('data:schedule:create')")
    public CommonResult save(@RequestBody ScheduleJobDTO dto){
        ValidationUtils.validate(dto, AddGroup.class, DefaultGroup.class);
        
@@ -67,9 +75,9 @@
        return new CommonResult();
    }
    @PutMapping
    @PutMapping("/update")
    @Operation(summary = "修改")
    @PreAuthorize("@ss.hasPermission('sys:schedule:update')")
    @PreAuthorize("@ss.hasPermission('data:schedule:update')")
    public CommonResult update(@RequestBody ScheduleJobDTO dto){
        ValidationUtils.validate(dto, UpdateGroup.class, DefaultGroup.class);
                
@@ -78,19 +86,20 @@
        return new CommonResult();
    }
    @DeleteMapping
    @DeleteMapping("/delete")
    @Operation(summary = "删除")
    @PreAuthorize("@ss.hasPermission('sys:schedule:delete')")
    public CommonResult delete(@RequestBody Long[] ids){
        scheduleJobService.deleteBatch(ids);
    @PreAuthorize("@ss.hasPermission('data:schedule:delete')")
    public CommonResult delete(@RequestParam("id") Long id){
        scheduleJobService.deleteBatch(id);
        
        return new CommonResult();
    }
    @PutMapping("/run")
    @Operation(summary = "立即执行")
    @PreAuthorize("@ss.hasPermission('sys:schedule:run')")
    public CommonResult run(@RequestBody Long[] ids){
    public CommonResult run(@RequestParam("id") Long id){
        Long[] ids = new Long[1];
        ids[0] = id;
        scheduleJobService.run(ids);
        
        return new CommonResult();
@@ -98,8 +107,9 @@
    @PutMapping("/pause")
    @Operation(summary = "暂停")
    @PreAuthorize("@ss.hasPermission('sys:schedule:pause')")
    public CommonResult pause(@RequestBody Long[] ids){
    public CommonResult pause(@RequestParam("id") Long id){
        Long[] ids = new Long[1];
        ids[0] = id;
        scheduleJobService.pause(ids);
        
        return new CommonResult();
@@ -107,8 +117,9 @@
    @PutMapping("/resume")
    @Operation(summary = "恢复")
    @PreAuthorize("@ss.hasPermission('sys:schedule:resume')")
    public CommonResult resume(@RequestBody Long[] ids){
    public CommonResult resume(@RequestParam("id") Long id){
        Long[] ids = new Long[1];
        ids[0] = id;
        scheduleJobService.resume(ids);
        
        return new CommonResult();
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/dao/ScheduleJobDao.java
@@ -1,8 +1,11 @@
package com.iailab.module.data.job.dao;
import com.baomidou.dynamic.datasource.annotation.Master;
import com.iailab.framework.common.dao.BaseDao;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.mybatis.core.mapper.BaseMapperX;
import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.iailab.module.data.job.entity.ScheduleJobEntity;
import com.iailab.module.data.job.vo.ScheduleJobReqVO;
import org.apache.ibatis.annotations.Mapper;
import java.util.Map;
@@ -14,7 +17,15 @@
 */
@Master
@Mapper
public interface ScheduleJobDao extends BaseDao<ScheduleJobEntity> {
public interface ScheduleJobDao extends BaseMapperX<ScheduleJobEntity> {
    default PageResult<ScheduleJobEntity> selectPage(ScheduleJobReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ScheduleJobEntity>()
                .likeIfPresent(ScheduleJobEntity::getBeanName, reqVO.getBeanName())
                .eqIfPresent(ScheduleJobEntity::getTenantId, reqVO.getTenantId())
                .orderByDesc(ScheduleJobEntity::getCreateDate));
    }
    
    /**
     * 批量更新状态
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/service/ScheduleJobService.java
@@ -1,20 +1,11 @@
/**
 * Copyright (c) 2018 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有,侵权必究!
 */
package com.iailab.module.data.job.service;
import com.iailab.framework.common.page.PageData;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.common.service.BaseService;
import com.iailab.module.data.job.entity.ScheduleJobEntity;
import com.iailab.module.data.job.entity.ScheduleJobEntity;
import com.iailab.module.data.job.dto.ScheduleJobDTO;
import com.iailab.module.data.job.vo.ScheduleJobReqVO;
import java.util.Map;
/**
 * 定时任务
@@ -23,7 +14,7 @@
 */
public interface ScheduleJobService extends BaseService<ScheduleJobEntity> {
    PageData<ScheduleJobDTO> page(Map<String, Object> params);
    PageResult<ScheduleJobEntity> page(ScheduleJobReqVO reqVO);
    ScheduleJobDTO get(Long id);
@@ -40,7 +31,7 @@
    /**
     * 批量删除定时任务
     */
    void deleteBatch(Long[] ids);
    void deleteBatch(Long id);
    
    /**
     * 批量更新定时任务状态
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/service/impl/ScheduleJobServiceImpl.java
@@ -1,25 +1,20 @@
/**
 * Copyright (c) 2018 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有,侵权必究!
 */
package com.iailab.module.data.job.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.iailab.framework.common.constant.Constant;
import com.iailab.framework.common.page.PageData;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.common.service.impl.BaseServiceImpl;
import com.iailab.framework.common.util.object.ConvertUtils;
import com.iailab.module.data.job.entity.ScheduleJobEntity;
import com.iailab.framework.security.core.util.SecurityFrameworkUtils;
import com.iailab.framework.tenant.core.context.TenantContextHolder;
import com.iailab.module.data.job.entity.ScheduleJobEntity;
import com.iailab.module.data.job.dao.ScheduleJobDao;
import com.iailab.module.data.job.dto.ScheduleJobDTO;
import com.iailab.module.data.job.service.ScheduleJobService;
import com.iailab.module.data.job.utils.ScheduleUtils;
import com.iailab.module.data.job.vo.ScheduleJobReqVO;
import org.apache.commons.lang3.StringUtils;
import org.quartz.Scheduler;
import javax.annotation.Resource;
@@ -37,12 +32,8 @@
    private Scheduler scheduler;
    @Override
    public PageData<ScheduleJobDTO> page(Map<String, Object> params) {
        IPage<ScheduleJobEntity> page = baseDao.selectPage(
            getPage(params, Constant.CREATE_DATE, false),
            getWrapper(params)
        );
        return getPageData(page, ScheduleJobDTO.class);
    public PageResult<ScheduleJobEntity> page(ScheduleJobReqVO reqVO) {
        return baseDao.selectPage(reqVO);
    }
    @Override
@@ -64,9 +55,13 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(ScheduleJobDTO dto) {
        Long tenantId = TenantContextHolder.getRequiredTenantId();
        ScheduleJobEntity entity = ConvertUtils.sourceToTarget(dto, ScheduleJobEntity.class);
        entity.setCreateDate(new Date());
        entity.setId(System.currentTimeMillis());
        entity.setStatus(Constant.ScheduleStatus.NORMAL.getValue());
        entity.setTenantId(tenantId);
        entity.setCreator(SecurityFrameworkUtils.getLoginUser().getId());
        entity.setCreateDate(new Date());
        this.insert(entity);
        
        ScheduleUtils.createScheduleJob(scheduler, entity);
@@ -75,8 +70,11 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(ScheduleJobDTO dto) {
        Long tenantId = TenantContextHolder.getRequiredTenantId();
        ScheduleJobEntity entity = ConvertUtils.sourceToTarget(dto, ScheduleJobEntity.class);
        entity.setUpdateDate(new Date());
        entity.setUpdater(SecurityFrameworkUtils.getLoginUser().getId());
        entity.setTenantId(tenantId);
        ScheduleUtils.updateScheduleJob(scheduler, entity);
                
        this.updateById(entity);
@@ -84,13 +82,10 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteBatch(Long[] ids) {
        for(Long id : ids){
            ScheduleUtils.deleteScheduleJob(scheduler, id);
        }
        //删除数据
        this.deleteBatchIds(Arrays.asList(ids));
    public void deleteBatch(Long id) {
        ScheduleUtils.deleteScheduleJob(scheduler, id);
        baseDao.deleteById(id);
    }
    @Override
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/utils/ScheduleJob.java
@@ -6,6 +6,7 @@
import com.iailab.framework.tenant.core.context.TenantContextHolder;
import com.iailab.module.data.job.entity.ScheduleJobEntity;
import com.iailab.module.data.job.entity.ScheduleJobLogEntity;
import com.iailab.module.data.job.service.ScheduleJobLogService;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
@@ -32,13 +33,16 @@
        //设置当前租户
        TenantContextHolder.setTenantId(scheduleJob.getTenantId());
        Long tenantId = TenantContextHolder.getRequiredTenantId();
        //数据库保存执行记录
        ScheduleJobLogEntity log = new ScheduleJobLogEntity();
        log.setId(System.currentTimeMillis());
        log.setJobId(scheduleJob.getId());
        log.setBeanName(scheduleJob.getBeanName());
        log.setParams(scheduleJob.getParams());
        log.setCreateDate(new Date());
        log.setTenantId(tenantId);
        //任务开始时间
        long startTime = System.currentTimeMillis();
@@ -69,8 +73,8 @@
            log.setError(ExceptionUtils.getErrorStackTrace(e));
        }finally {
            //获取spring bean
            /*ScheduleJobLogService scheduleJobLogService = SpringContextUtils.getBean(ScheduleJobLogService.class);
            scheduleJobLogService.insert(log);*/
            ScheduleJobLogService scheduleJobLogService = SpringContextUtils.getBean(ScheduleJobLogService.class);
            scheduleJobLogService.insert(log);
        }
    }
}
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/vo/ScheduleJobReqVO.java
对比新文件
@@ -0,0 +1,23 @@
package com.iailab.module.data.job.vo;
import com.iailab.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
 * @author PanZhibao
 * @Description
 * @createTime 2024年08月23日
 */
@Schema(description = "数据平台 - 定时任务分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ScheduleJobReqVO extends PageParam {
    private String beanName;
    private Long tenantId;
}
iailab-module-data/iailab-module-data-biz/src/main/resources/application-dev.yml
@@ -38,7 +38,7 @@
      primary: master
      datasource:
        master:
          url: jdbc:mysql://127.0.0.1:3306/iailab_data_master?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
          url: jdbc:mysql://127.0.0.1:3306/iailab_expert_master?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
          username: root
          password: 123456
iailab-module-data/iailab-module-data-biz/src/main/resources/application.yml
@@ -175,6 +175,8 @@
      - qrtz_simple_triggers
      - qrtz_simprop_triggers
      - qrtz_triggers
      - schedule_job
      - schedule_job_log
      - t_channel_kio_device
      - t_channel_kio_tag
      - t_channel_modbus_device