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.patrol.domain.PatrolPresetAction;
import com.inspect.patrol.service.IPatrolPresetActionService;

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;
import springfox.documentation.annotations.ApiIgnore;

@ApiIgnore
@RestController
@RequestMapping({"/action"})
public class PatrolPresetActionController extends BaseController {
    private final IPatrolPresetActionService patrolPresetActionService;

    public PatrolPresetActionController(IPatrolPresetActionService patrolPresetActionService) {
        this.patrolPresetActionService = patrolPresetActionService;
    }

    @GetMapping({"/list"})
    public TableDataInfo list(PatrolPresetAction patrolPresetAction) {
        this.startPage();
        List<PatrolPresetAction> list = this.patrolPresetActionService.selectPatrolPresetActionList(patrolPresetAction);
        return this.getDataTable(list);
    }

    @Log(
            title = "预置点动作(hongww)",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, PatrolPresetAction patrolPresetAction) {
        List<PatrolPresetAction> list = this.patrolPresetActionService.selectPatrolPresetActionList(patrolPresetAction);
        ExcelUtil<PatrolPresetAction> util = new ExcelUtil<>(PatrolPresetAction.class);
        util.exportExcel(response, list, "预置点动作(hongww)数据");
    }

    @GetMapping({"/{patrolPresetActionId}"})
    public AjaxResult getInfo(@PathVariable("patrolPresetActionId") Long patrolPresetActionId) {
        return AjaxResult.success(this.patrolPresetActionService.selectPatrolPresetActionByPatrolPresetPosId(patrolPresetActionId));
    }

    @Log(
            title = "预置点动作(hongww)",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody PatrolPresetAction patrolPresetAction) {
        return this.toAjax(this.patrolPresetActionService.insertPatrolPresetAction(patrolPresetAction));
    }

    @Log(
            title = "预置点动作(hongww)",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody PatrolPresetAction patrolPresetAction) {
        return this.toAjax(this.patrolPresetActionService.updatePatrolPresetAction(patrolPresetAction));
    }

    @Log(
            title = "预置点动作(hongww)",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{patrolPresetActionIds}"})
    public AjaxResult remove(@PathVariable Long[] patrolPresetActionIds) {
        return this.toAjax(this.patrolPresetActionService.deletePatrolPresetActionByPatrolPresetActionIds(patrolPresetActionIds));
    }
}
