package com.zd.chemical.controller;

import com.zd.chemical.domain.HxpAlarmConfig;
import com.zd.chemical.domain.vo.HxpAlarmConfigVo;
import com.zd.chemical.service.IHxpAlarmConfigService;
import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.utils.poi.ExcelUtil;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.ResultData;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 化学品报警配置Controller
 *
 * @author liubo
 * @date 2022-06-16
 */
@RestController
@Api(tags = "【化学品报警配置】")
@RequestMapping("/hxpAlarmConfig")
public class HxpAlarmConfigController extends BaseController {
    @Autowired
    private IHxpAlarmConfigService hxpAlarmConfigService;

    /**
     * 查询化学品报警配置列表
     */
    @PreAuthorize(hasPermi = "chemical:hxpAlarmConfig:list")
    @GetMapping("/list")
    @ApiOperation(value = "查询化学品报警配置列表")
    public TableDataInfo<HxpAlarmConfig> list(HxpAlarmConfig hxpAlarmConfig) {
        startPage();
        List<HxpAlarmConfig> list = hxpAlarmConfigService.selectHxpAlarmConfigList(hxpAlarmConfig);
        return getDataTable(list);
    }

    /**
     * 导出化学品报警配置列表
     */
    @ApiOperation(value = "导出化学品报警配置列表")
    @PreAuthorize(hasPermi = "chemical:hxpAlarmConfig:export")
    @Log(title = "化学品报警配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HxpAlarmConfig hxpAlarmConfig) throws IOException {
        List<HxpAlarmConfig> list = hxpAlarmConfigService.selectHxpAlarmConfigList(hxpAlarmConfig);
        ExcelUtil<HxpAlarmConfig> util = new ExcelUtil<HxpAlarmConfig>(HxpAlarmConfig.class);
        util.exportExcel(response, list, "化学品报警配置数据");
    }

    /**
     * 获取化学品报警配置详细信息
     */
    @ApiOperation(value = "获取化学品报警配置详细信息")
    @PreAuthorize(hasPermi = "chemical:hxpAlarmConfig:query")
    @GetMapping(value = "/{id}")
    public ResultData<HxpAlarmConfig> getInfo(@PathVariable("id") Long id) {
        return ResultData.success(hxpAlarmConfigService.selectHxpAlarmConfigById(id));
    }

    /**
     * 新增化学品报警配置
     */
    @ApiOperation(value = "新增化学品报警配置")
    @PreAuthorize(hasPermi = PerPrefix.HXP_ALARMRECORD+ PerFun.CONFIGADD)
    @Log(title = "化学品报警配置", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody HxpAlarmConfigVo hxpAlarmConfigVo) {
        return ResultData.result(hxpAlarmConfigService.insertHxpAlarmConfig(hxpAlarmConfigVo));
    }

    /**
     * 修改化学品报警配置
     */
    @ApiOperation(value = "修改化学品报警配置")
    @PreAuthorize(hasPermi = PerPrefix.HXP_ALARMRECORD+ PerFun.CONFIGADD)
    @Log(title = "化学品报警配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody HxpAlarmConfig hxpAlarmConfig) {
        return ResultData.result(hxpAlarmConfigService.updateHxpAlarmConfig(hxpAlarmConfig));
    }

    /**
     * 删除化学品报警配置
     */
    @ApiOperation(value = "删除化学品报警配置")
    @PreAuthorize(hasPermi = "chemical:hxpAlarmConfig:remove")
    @Log(title = "化学品报警配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids) {
        return ResultData.result(hxpAlarmConfigService.deleteHxpAlarmConfigByIds(ids));
    }


    /**
     * 获取化学品报警配置详细信息
     */
    @ApiOperation(value = "获取化学品报警配置详细信息")
    @PreAuthorize(hasPermi = PerPrefix.HXP_ALARMRECORD+ PerFun.CONFIGQUERY)
    @GetMapping(value = "/getDeptDetail/{alarmDeptId}")
    public ResultData<List<HxpAlarmConfig>> getDeptDetail(@PathVariable("alarmDeptId") Long alarmDeptId) {
        return ResultData.success(hxpAlarmConfigService.getDeptDetail(alarmDeptId));
    }
}
