package com.inspect.alarmdefect.controller;

import com.inspect.alarmdefect.domain.AlarmDefect;
import com.inspect.alarmdefect.service.IAlarmDefectService;
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({"/alarmdefect"})
public class AlarmDefectController extends BaseController {

    final IAlarmDefectService alarmDefectService;

    @Autowired
    public AlarmDefectController(IAlarmDefectService alarmDefectService) {
        this.alarmDefectService = alarmDefectService;
    }

    @RequiresPermissions({"alarmdefect:alarmdefect:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(AlarmDefect alarmDefect) {
        this.startPage();
        List<AlarmDefect> list = this.alarmDefectService.selectAlarmDefectList(alarmDefect);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"alarmdefect:alarmdefect:export"})
    @Log(
            title = "缺陷告警条目数组",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, AlarmDefect alarmDefect) {
        List<AlarmDefect> list = this.alarmDefectService.selectAlarmDefectList(alarmDefect);
        ExcelUtil<AlarmDefect> util = new ExcelUtil<>(AlarmDefect.class);
        util.exportExcel(response, list, "缺陷告警条目数组数据");
    }

    @RequiresPermissions({"alarmdefect:alarmdefect:query"})
    @GetMapping({"/{lineId}"})
    public AjaxResult getInfo(@PathVariable("lineId") Long lineId) {
        return AjaxResult.success(this.alarmDefectService.selectAlarmDefectByLineId(lineId));
    }

    @RequiresPermissions({"alarmdefect:alarmdefect:add"})
    @Log(
            title = "缺陷告警条目数组",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody AlarmDefect alarmDefect) {
        return this.toAjax(this.alarmDefectService.insertAlarmDefect(alarmDefect));
    }

    @RequiresPermissions({"alarmdefect:alarmdefect:edit"})
    @Log(
            title = "缺陷告警条目数组",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody AlarmDefect alarmDefect) {
        return this.toAjax(this.alarmDefectService.updateAlarmDefect(alarmDefect));
    }

    @RequiresPermissions({"alarmdefect:alarmdefect:remove"})
    @Log(
            title = "缺陷告警条目数组",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{lineIds}"})
    public AjaxResult remove(@PathVariable Long[] lineIds) {
        return this.toAjax(this.alarmDefectService.deleteAlarmDefectByLineIds(lineIds));
    }
}
