沙钢智慧能源系统后端代码
liriming
2024-12-02 a63c400ff367e3cec30db6425a142d67dbaf158d
shasteel-biz/src/main/java/com/iailab/module/shasteel/job/service/impl/ScheduleJobServiceImpl.java
@@ -1,45 +1,45 @@
package com.iailab.module.shasteel.job.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.iailab.framework.common.constant.Constant;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.common.page.PageData;
import com.iailab.framework.common.service.impl.BaseServiceImpl;
import com.iailab.framework.common.util.object.ConvertUtils;
import com.iailab.framework.security.core.util.SecurityFrameworkUtils;
import com.iailab.framework.tenant.core.context.TenantContextHolder;
import com.iailab.module.shasteel.job.dao.ScheduleJobDao;
import com.iailab.module.shasteel.job.dto.ScheduleJobDTO;
import com.iailab.module.shasteel.job.entity.ScheduleJobEntity;
import com.iailab.module.shasteel.job.service.ScheduleJobService;
import com.iailab.module.shasteel.job.utils.ScheduleUtils;
import com.iailab.module.shasteel.job.vo.ScheduleJobReqVO;
import org.apache.commons.lang3.StringUtils;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Service
public class ScheduleJobServiceImpl extends ServiceImpl<ScheduleJobDao, ScheduleJobEntity> implements ScheduleJobService {
   @Resource
public class ScheduleJobServiceImpl extends BaseServiceImpl<ScheduleJobDao, ScheduleJobEntity> implements ScheduleJobService {
   @Autowired
   private Scheduler scheduler;
   @Resource
   private ScheduleJobDao scheduleJobDao;
   @Override
   public PageResult<ScheduleJobEntity> page(ScheduleJobReqVO reqVO) {
      return scheduleJobDao.selectPage(reqVO);
   public PageData<ScheduleJobDTO> page(Map<String, Object> params) {
      IPage<ScheduleJobEntity> page = baseDao.selectPage(
         getPage(params, "create_date", false),
         getWrapper(params)
      );
      return getPageData(page, ScheduleJobDTO.class);
   }
   @Override
   public ScheduleJobDTO get(Long id) {
      ScheduleJobEntity entity = scheduleJobDao.selectById(id);
      ScheduleJobEntity entity = baseDao.selectById(id);
      return ConvertUtils.sourceToTarget(entity, ScheduleJobDTO.class);
   }
@@ -56,14 +56,12 @@
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void save(ScheduleJobDTO dto) {
      Long tenantId = TenantContextHolder.getRequiredTenantId();
      ScheduleJobEntity entity = ConvertUtils.sourceToTarget(dto, ScheduleJobEntity.class);
      entity.setId(System.currentTimeMillis());
      entity.setStatus(Constant.ScheduleStatus.NORMAL.getValue());
      entity.setTenantId(tenantId);
      entity.setCreator(SecurityFrameworkUtils.getLoginUser().getId());
      entity.setCreateDate(new Date());
      scheduleJobDao.insert(entity);
      entity.setCreator(SecurityFrameworkUtils.getLoginUser().getId());
      entity.setStatus(Constant.ScheduleStatus.NORMAL.getValue());
        this.insert(entity);
        
        ScheduleUtils.createScheduleJob(scheduler, entity);
    }
@@ -71,11 +69,9 @@
   @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);
@@ -83,10 +79,13 @@
   @Override
   @Transactional(rollbackFor = Exception.class)
    public void deleteBatch(Long id) {
      ScheduleUtils.deleteScheduleJob(scheduler, id);
    public void deleteBatch(Long[] ids) {
       for(Long id : ids){
          ScheduleUtils.deleteScheduleJob(scheduler, id);
       }
      scheduleJobDao.deleteById(id);
       //删除数据
       this.deleteBatchIds(Arrays.asList(ids));
   }
   @Override
@@ -94,15 +93,13 @@
       Map<String, Object> map = new HashMap<>(2);
       map.put("ids", ids);
       map.put("status", status);
       return scheduleJobDao.updateBatch(map);
       return baseDao.updateBatch(map);
    }
    
   @Override
   @Transactional(rollbackFor = Exception.class)
    public void run(Long[] ids) {
       for(Long id : ids){
          ScheduleUtils.run(scheduler, scheduleJobDao.selectById(id));
       }
    public void run(Long id) {
      ScheduleUtils.run(scheduler, this.selectById(id));
    }
   @Override