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.PatrolPresetParam;
import com.inspect.patrol.service.IPatrolPresetParamService;

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({"/preset/param"})
public class PatrolPresetParamController extends BaseController {
    private final IPatrolPresetParamService patrolPresetParamService;

    public PatrolPresetParamController(IPatrolPresetParamService patrolPresetParamService) {
        this.patrolPresetParamService = patrolPresetParamService;
    }

    @GetMapping({"/list"})
    public TableDataInfo list(PatrolPresetParam patrolPresetParam) {
        this.startPage();
        List<PatrolPresetParam> list = this.patrolPresetParamService.selectPatrolPresetParamList(patrolPresetParam);
        return this.getDataTable(list);
    }

    @Log(
            title = "预置参数(hongww)",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, PatrolPresetParam patrolPresetParam) {
        List<PatrolPresetParam> list = this.patrolPresetParamService.selectPatrolPresetParamList(patrolPresetParam);
        ExcelUtil<PatrolPresetParam> util = new ExcelUtil<>(PatrolPresetParam.class);
        util.exportExcel(response, list, "预置参数(hongww)数据");
    }

    @GetMapping({"/{posParamId}"})
    public AjaxResult getInfo(@PathVariable("posParamId") Long posParamId) {
        return AjaxResult.success(this.patrolPresetParamService.selectPatrolPresetParamByPosPatrolPresetId(posParamId));
    }

    @Log(
            title = "预置参数(hongww)",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody PatrolPresetParam patrolPresetParam) {
        return this.toAjax(this.patrolPresetParamService.insertPatrolPresetParam(patrolPresetParam));
    }

    @Log(
            title = "预置参数(hongww)",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody PatrolPresetParam patrolPresetParam) {
        return this.toAjax(this.patrolPresetParamService.updatePatrolPresetParam(patrolPresetParam));
    }

    @Log(
            title = "预置参数(hongww)",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{posParamIds}"})
    public AjaxResult remove(@PathVariable Long[] posParamIds) {
        return this.toAjax(this.patrolPresetParamService.deletePatrolPresetParamByPosParamIds(posParamIds));
    }
}
