job
潘志宝
2024-08-26 cd5f8564e84694d098a4eeddecc36aa8ce7cfdf3
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