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.PatrolTaskExecRecord;
import com.inspect.exec.service.IPatrolTaskExecRecordService;

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({"/taskrecord"})
public class PatrolTaskExecRecordController extends BaseController {
    private final IPatrolTaskExecRecordService patrolTaskExecRecordService;

    public PatrolTaskExecRecordController(IPatrolTaskExecRecordService patrolTaskExecRecordService) {
        this.patrolTaskExecRecordService = patrolTaskExecRecordService;
    }

    @RequiresPermissions({"task:task:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(PatrolTaskExecRecord patrolTaskExecRecord) {
        this.startPage();
        List<PatrolTaskExecRecord> list = this.patrolTaskExecRecordService.selectPatrolTaskExecRecordList(patrolTaskExecRecord);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"task:task:export"})
    @Log(
            title = "任务执行记录数据",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, PatrolTaskExecRecord patrolTaskExecRecord) {
        List<PatrolTaskExecRecord> list = this.patrolTaskExecRecordService.selectPatrolTaskExecRecordList(patrolTaskExecRecord);
        ExcelUtil<PatrolTaskExecRecord> util = new ExcelUtil<>(PatrolTaskExecRecord.class);
        util.exportExcel(response, list, "任务执行记录数据数据");
    }

    @RequiresPermissions({"task:task:query"})
    @GetMapping({"/{taskPatrolledId}"})
    public AjaxResult getInfo(@PathVariable("taskPatrolledId") String taskPatrolledId) {
        return AjaxResult.success(this.patrolTaskExecRecordService.selectPatrolTaskExecRecordByTaskPatrolId(taskPatrolledId));
    }

    @RequiresPermissions({"task:task:add"})
    @Log(
            title = "任务执行记录数据",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody PatrolTaskExecRecord patrolTaskExecRecord) {
        return this.toAjax(this.patrolTaskExecRecordService.insertPatrolTaskExecRecord(patrolTaskExecRecord));
    }

    @RequiresPermissions({"task:task:edit"})
    @Log(
            title = "任务执行记录数据",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody PatrolTaskExecRecord patrolTaskExecRecord) {
        return this.toAjax(this.patrolTaskExecRecordService.updatePatrolTaskExecRecord(patrolTaskExecRecord));
    }

    @RequiresPermissions({"task:task:remove"})
    @Log(
            title = "任务执行记录数据",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{taskPatrolledIds}"})
    public AjaxResult remove(@PathVariable String[] taskPatrolledIds) {
        return this.toAjax(this.patrolTaskExecRecordService.deletePatrolTaskExecRecordByTaskPatrolIds(taskPatrolledIds));
    }
}
