package com.inspect.patrol.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.patrol.domain.PatrolPresetRecord;
import com.inspect.patrol.service.IPatrolPresetRecordService;

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

@RestController
@RequestMapping({"/record"})
public class PatrolPresetRecordController extends BaseController {
    private final IPatrolPresetRecordService patrolPresetRecordService;

    public PatrolPresetRecordController(IPatrolPresetRecordService patrolPresetRecordService) {
        this.patrolPresetRecordService = patrolPresetRecordService;
    }

    @RequiresPermissions({"patrol:record:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(PatrolPresetRecord patrolPresetRecord) {
        this.startPage();
        List<PatrolPresetRecord> list = this.patrolPresetRecordService.selectPatrolPresetRecordList(patrolPresetRecord);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"patrol:record:export"})
    @Log(
            title = "通道预置位信息",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, PatrolPresetRecord patrolPresetRecord) {
        List<PatrolPresetRecord> list = this.patrolPresetRecordService.selectPatrolPresetRecordList(patrolPresetRecord);
        ExcelUtil<PatrolPresetRecord> util = new ExcelUtil<>(PatrolPresetRecord.class);
        util.exportExcel(response, list, "通道预置位信息数据");
    }

    @RequiresPermissions({"patrol:record:query"})
    @GetMapping({"/{presetRecordId}"})
    public AjaxResult getInfo(@PathVariable("presetRecordId") Long presetRecordId) {
        return AjaxResult.success(this.patrolPresetRecordService.selectPatrolPresetRecordByPresetRecordId(presetRecordId));
    }

    @RequiresPermissions({"patrol:record:add"})
    @Log(
            title = "通道预置位信息",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody PatrolPresetRecord patrolPresetRecord) {
        return this.toAjax(this.patrolPresetRecordService.insertPatrolPresetRecord(patrolPresetRecord));
    }

    @RequiresPermissions({"patrol:record:edit"})
    @Log(
            title = "通道预置位信息",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody PatrolPresetRecord patrolPresetRecord) {
        return this.toAjax(this.patrolPresetRecordService.updatePatrolPresetRecord(patrolPresetRecord));
    }

    @RequiresPermissions({"patrol:record:remove"})
    @Log(
            title = "通道预置位信息",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{presetRecordIds}"})
    public AjaxResult remove(@PathVariable Long[] presetRecordIds) {
        return this.toAjax(this.patrolPresetRecordService.deletePatrolPresetRecordByPresetRecordIds(presetRecordIds));
    }
}
