package com.inspect.job.controller;

import com.inspect.base.core.utils.poi.ExcelUtil;
import com.inspect.base.core.web.controller.BaseController;
import com.inspect.base.core.web.domain.AjaxResult;
import com.inspect.base.core.web.page.TableDataInfo;
import com.inspect.common.log.annotation.Log;
import com.inspect.common.log.enums.BizType;
import com.inspect.common.security.annotation.RequiresPermissions;
import com.inspect.job.domain.SysJobLog;
import com.inspect.job.service.ISysJobLogService;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/job/log"})
public class SysJobLogController extends BaseController {
   @Autowired
   private ISysJobLogService jobLogService;

   @RequiresPermissions({"monitor:job:list"})
   @GetMapping({"/list"})
   public TableDataInfo list(SysJobLog sysJobLog) {
      this.startPage();
      List<SysJobLog> list = this.jobLogService.selectJobLogList(sysJobLog);
      return this.getDataTable(list);
   }

   @RequiresPermissions({"monitor:job:export"})
   @Log(
      title = "任务调度日志",
      businessType = BizType.EXPORT
   )
   @PostMapping({"/export"})
   public void export(HttpServletResponse response, SysJobLog sysJobLog) {
      List<SysJobLog> list = this.jobLogService.selectJobLogList(sysJobLog);
      ExcelUtil<SysJobLog> util = new ExcelUtil(SysJobLog.class);
      util.exportExcel(response, list, "调度日志");
   }

   @RequiresPermissions({"monitor:job:query"})
   @GetMapping({"/{configId}"})
   public AjaxResult getInfo(@PathVariable Long jobLogId) {
      return AjaxResult.success(this.jobLogService.selectJobLogById(jobLogId));
   }

   @RequiresPermissions({"monitor:job:remove"})
   @Log(
      title = "定时任务调度日志",
      businessType = BizType.DELETE
   )
   @PostMapping({"/remove/{jobLogIds}"})
   public AjaxResult remove(@PathVariable Long[] jobLogIds) {
      return this.toAjax(this.jobLogService.deleteJobLogByIds(jobLogIds));
   }

   @RequiresPermissions({"monitor:job:remove"})
   @Log(
      title = "调度日志",
      businessType = BizType.CLEAN
   )
   @PostMapping({"/clean"})
   public AjaxResult clean() {
      this.jobLogService.cleanJobLog();
      return AjaxResult.success();
   }
}
