package com.zd.laboratory.controller;

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

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.web.domain.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.laboratory.domain.LabNoticeconfig;
import com.zd.laboratory.service.ILabNoticeconfigService;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.zd.common.swagger.config.Knife4jConfiguration;

import com.zd.common.core.web.page.TableDataInfo;

/**
 * 通知配置Controller
 *
 * @author zd
 * @date 2022-03-09
 */
@RestController
@Api(tags = "【通知配置】")
//作者手动加入 ，在接口上加作者@ApiOperationSupport(author = "XXX")
@ApiSupport(author = Knife4jConfiguration.Author.CYL)
@RequestMapping("/noticeconfig")
public class LabNoticeconfigController extends BaseController
{
    @Autowired
    private ILabNoticeconfigService labNoticeconfigService;

    /**
     * 查询通知配置列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_NOTICECONFIG + PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询通知配置列表")
    public TableDataInfo<LabNoticeconfig> list(LabNoticeconfig labNoticeconfig)
    {
        startPage();
        List<LabNoticeconfig> list = labNoticeconfigService.selectLabNoticeconfigList(labNoticeconfig);
        return getDataTable(list);
    }

    /**
     * 导出通知配置列表
     */
    @ApiOperation(value = "导出通知配置列表")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_NOTICECONFIG + PerFun.EXPORT)
    @Log(title = "通知配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabNoticeconfig labNoticeconfig) throws IOException
    {
        List<LabNoticeconfig> list = labNoticeconfigService.selectLabNoticeconfigList(labNoticeconfig);
        ExcelUtil<LabNoticeconfig> util = new ExcelUtil<LabNoticeconfig>(LabNoticeconfig.class);
        util.exportExcel(response, list, "通知配置数据");
    }

    /**
     * 获取通知配置详细信息
     */
    @ApiOperation(value = "获取通知配置详细信息")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_NOTICECONFIG + PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public ResultData<LabNoticeconfig> getInfo(@PathVariable("id") Long id)
    {
        return ResultData.success(labNoticeconfigService.selectLabNoticeconfigById(id));
    }

    /**
     * 新增通知配置
     */
    @ApiOperation(value = "新增通知配置")
//    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_NOTICECONFIG + PerFun.ADD)
    @Log(title = "通知配置", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody LabNoticeconfig labNoticeconfig)
    {
        return ResultData.result(labNoticeconfigService.insertLabNoticeconfig(labNoticeconfig));
    }

    /**
     * 修改通知配置
     */
    @ApiOperation(value = "修改通知配置")
//    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_NOTICECONFIG + PerFun.EDIT)
    @Log(title = "通知配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody LabNoticeconfig labNoticeconfig)
    {
        return  ResultData.result(labNoticeconfigService.updateLabNoticeconfig(labNoticeconfig));
    }

    /**
     * 删除通知配置
     */
    @ApiOperation(value = "删除通知配置")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_NOTICECONFIG + PerFun.REMOVE)
    @Log(title = "通知配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids)
    {
        return ResultData.result(labNoticeconfigService.deleteLabNoticeconfigByIds(ids));
    }



    /**
     * 查询通知配置列表
     */
//    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_NOTICECONFIG + PerFun.LIST)
    @GetMapping("/getNoticeconfigInfo")
    @ApiOperation(value = "查询通知配置列表")
    public ResultData<LabNoticeconfig> getNoticeconfigInfo(LabNoticeconfig labNoticeconfig)
    {
        List<LabNoticeconfig> list = labNoticeconfigService.selectLabNoticeconfigList(labNoticeconfig);
        LabNoticeconfig noticeconfig = new LabNoticeconfig();
        if(list.size()>0){
            noticeconfig = list.get(0);
        }
        return ResultData.success(noticeconfig);
    }
}
