package com.inspect.alarmdifferent.controller;

import com.inspect.alarmdifferent.domain.AlarmDifferent;
import com.inspect.alarmdifferent.service.IAlarmDifferentService;
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 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({"/alarmdifferent"})
public class AlarmDifferentController extends BaseController {
    private final IAlarmDifferentService alarmDifferentService;

    public AlarmDifferentController(IAlarmDifferentService alarmDifferentService) {
        this.alarmDifferentService = alarmDifferentService;
    }

    @RequiresPermissions({"alarmdifferent:alarmdifferent:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(AlarmDifferent alarmDifferent) {
        this.startPage();
        List<AlarmDifferent> list = this.alarmDifferentService.selectAlarmDifferentList(alarmDifferent);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"alarmdifferent:alarmdifferent:export"})
    @Log(
            title = "判别告警条目数组",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, AlarmDifferent alarmDifferent) {
        List<AlarmDifferent> list = this.alarmDifferentService.selectAlarmDifferentList(alarmDifferent);
        ExcelUtil<AlarmDifferent> util = new ExcelUtil<>(AlarmDifferent.class);
        util.exportExcel(response, list, "判别告警条目数组数据");
    }

    @RequiresPermissions({"alarmdifferent:alarmdifferent:query"})
    @GetMapping({"/{lineId}"})
    public AjaxResult getInfo(@PathVariable("lineId") Long lineId) {
        return AjaxResult.success(this.alarmDifferentService.selectAlarmDifferentByLineId(lineId));
    }

    @RequiresPermissions({"alarmdifferent:alarmdifferent:add"})
    @Log(
            title = "判别告警条目数组",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody AlarmDifferent alarmDifferent) {
        return this.toAjax(this.alarmDifferentService.insertAlarmDifferent(alarmDifferent));
    }

    @RequiresPermissions({"alarmdifferent:alarmdifferent:edit"})
    @Log(
            title = "判别告警条目数组",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody AlarmDifferent alarmDifferent) {
        return this.toAjax(this.alarmDifferentService.updateAlarmDifferent(alarmDifferent));
    }

    @RequiresPermissions({"alarmdifferent:alarmdifferent:remove"})
    @Log(
            title = "判别告警条目数组",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{lineIds}"})
    public AjaxResult remove(@PathVariable Long[] lineIds) {
        return this.toAjax(this.alarmDifferentService.deleteAlarmDifferentByLineIds(lineIds));
    }
}
