package com.inspect.exec.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.exec.domain.SilenceTaskPointExecRecord;
import com.inspect.exec.service.ISilenceTaskPointExecRecordService;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/silence"})
public class SilenceTaskPointExecRecordController extends BaseController {
    private final ISilenceTaskPointExecRecordService silenceTaskPointExecRecordService;

    public SilenceTaskPointExecRecordController(ISilenceTaskPointExecRecordService silenceTaskPointExecRecordService) {
        this.silenceTaskPointExecRecordService = silenceTaskPointExecRecordService;
    }

    @RequiresPermissions({"silence:silence:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(SilenceTaskPointExecRecord silenceTaskPointExecRecord) {
        this.startPage();
        List<SilenceTaskPointExecRecord> list = this.silenceTaskPointExecRecordService.selectSilenceTaskPointExecRecordList(silenceTaskPointExecRecord);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"silence:silence:export"})
    @Log(
            title = "静默任务执行点位记录",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, SilenceTaskPointExecRecord silenceTaskPointExecRecord) {
        List<SilenceTaskPointExecRecord> list = this.silenceTaskPointExecRecordService.selectSilenceTaskPointExecRecordList(silenceTaskPointExecRecord);
        ExcelUtil<SilenceTaskPointExecRecord> util = new ExcelUtil<>(SilenceTaskPointExecRecord.class);
        util.exportExcel(response, list, "静默任务执行点位记录数据");
    }

    @RequiresPermissions({"silence:silence:query"})
    @GetMapping({"/{pointId}"})
    public AjaxResult getInfo(@PathVariable("pointId") Long pointId) {
        return AjaxResult.success(this.silenceTaskPointExecRecordService.selectSilenceTaskPointExecRecordByPointId(pointId));
    }

    @RequiresPermissions({"silence:silence:add"})
    @Log(
            title = "静默任务执行点位记录",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody SilenceTaskPointExecRecord silenceTaskPointExecRecord) {
        return this.toAjax(this.silenceTaskPointExecRecordService.insertSilenceTaskPointExecRecord(silenceTaskPointExecRecord));
    }

    @RequiresPermissions({"silence:silence:edit"})
    @Log(
            title = "静默任务执行点位记录",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody SilenceTaskPointExecRecord silenceTaskPointExecRecord) {
        return this.toAjax(this.silenceTaskPointExecRecordService.updateSilenceTaskPointExecRecord(silenceTaskPointExecRecord));
    }

    @RequiresPermissions({"silence:silence:remove"})
    @Log(
            title = "静默任务执行点位记录",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{pointIds}"})
    public AjaxResult remove(@PathVariable Long[] pointIds) {
        return this.toAjax(this.silenceTaskPointExecRecordService.deleteSilenceTaskPointExecRecordByPointIds(pointIds));
    }
}
