From ccf75464534965c47866449b2b4e457a6dadede9 Mon Sep 17 00:00:00 2001
From: liriming <1343021927@qq.com>
Date: 星期一, 14 十月 2024 14:13:00 +0800
Subject: [PATCH] 定时任务权限修改

---
 shasteel-biz/src/main/java/com/iailab/module/shasteel/job/service/impl/ScheduleJobServiceImpl.java |  128 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 128 insertions(+), 0 deletions(-)

diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/service/impl/ScheduleJobServiceImpl.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/service/impl/ScheduleJobServiceImpl.java
new file mode 100644
index 0000000..ad9b2ad
--- /dev/null
+++ b/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/service/impl/ScheduleJobServiceImpl.java
@@ -0,0 +1,128 @@
+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.iailab.framework.common.constant.Constant;
+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.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.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+@Service
+public class ScheduleJobServiceImpl extends ServiceImpl<ScheduleJobDao, ScheduleJobEntity> implements ScheduleJobService {
+	@Resource
+	private Scheduler scheduler;
+
+	@Resource
+	private ScheduleJobDao scheduleJobDao;
+
+	@Override
+	public PageResult<ScheduleJobEntity> page(ScheduleJobReqVO reqVO) {
+		return scheduleJobDao.selectPage(reqVO);
+	}
+
+	@Override
+	public ScheduleJobDTO get(Long id) {
+		ScheduleJobEntity entity = scheduleJobDao.selectById(id);
+
+		return ConvertUtils.sourceToTarget(entity, ScheduleJobDTO.class);
+	}
+
+	private QueryWrapper<ScheduleJobEntity> getWrapper(Map<String, Object> params){
+		String beanName = (String)params.get("beanName");
+
+		QueryWrapper<ScheduleJobEntity> wrapper = new QueryWrapper<>();
+		wrapper.like(StringUtils.isNotBlank(beanName), "bean_name", beanName);
+
+		return wrapper;
+	}
+
+	@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);
+        
+        ScheduleUtils.createScheduleJob(scheduler, entity);
+    }
+	
+	@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);
+    }
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+    public void deleteBatch(Long id) {
+		ScheduleUtils.deleteScheduleJob(scheduler, id);
+
+		scheduleJobDao.deleteById(id);
+	}
+
+	@Override
+    public int updateBatch(Long[] ids, int status){
+    	Map<String, Object> map = new HashMap<>(2);
+    	map.put("ids", ids);
+    	map.put("status", status);
+    	return scheduleJobDao.updateBatch(map);
+    }
+    
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+    public void run(Long[] ids) {
+    	for(Long id : ids){
+    		ScheduleUtils.run(scheduler, scheduleJobDao.selectById(id));
+    	}
+    }
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+    public void pause(Long[] ids) {
+        for(Long id : ids){
+    		ScheduleUtils.pauseJob(scheduler, id);
+    	}
+        
+    	updateBatch(ids, Constant.ScheduleStatus.PAUSE.getValue());
+    }
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+    public void resume(Long[] ids) {
+    	for(Long id : ids){
+    		ScheduleUtils.resumeJob(scheduler, id);
+    	}
+
+    	updateBatch(ids, Constant.ScheduleStatus.NORMAL.getValue());
+    }
+    
+}
\ No newline at end of file

--
Gitblit v1.9.3