Jay
2024-11-25 ee9f604388a3e77d3f4654e326f3976552e7f532
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();