package com.zhyc.module.biosafety.controller;

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

import com.zhyc.module.biosafety.domain.SwDisease;
import com.zhyc.module.biosafety.service.ISwDiseaseService;
import org.springframework.security.access.prepost.PreAuthorize;
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.zhyc.common.annotation.Log;
import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult;
import com.zhyc.common.enums.BusinessType;
import com.zhyc.common.utils.poi.ExcelUtil;

/**
 * 疾病Controller
 * 
 * @author ruoyi
 * @date 2025-07-09
 */
@RestController
@RequestMapping("/biosafety/disease")
public class SwDiseaseController extends BaseController
{
    @Autowired
    private ISwDiseaseService swDiseaseService;

    /**
     * 查询疾病列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:disease:list')")
    @GetMapping("/list")
    public AjaxResult list(SwDisease swDisease)
    {
        List<SwDisease> list = swDiseaseService.selectSwDiseaseList(swDisease);
        return success(list);
    }

    /**
     * 导出疾病列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:disease:export')")
    @Log(title = "疾病", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SwDisease swDisease)
    {
        List<SwDisease> list = swDiseaseService.selectSwDiseaseList(swDisease);
        ExcelUtil<SwDisease> util = new ExcelUtil<SwDisease>(SwDisease.class);
        util.exportExcel(response, list, "疾病数据");
    }

    /**
     * 获取疾病详细信息
     */
    @PreAuthorize("@ss.hasPermi('biosafety:disease:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(swDiseaseService.selectSwDiseaseById(id));
    }

    /**
     * 新增疾病
     */
    @PreAuthorize("@ss.hasPermi('biosafety:disease:add')")
    @Log(title = "疾病", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SwDisease swDisease)
    {
        return toAjax(swDiseaseService.insertSwDisease(swDisease));
    }

    /**
     * 修改疾病
     */
    @PreAuthorize("@ss.hasPermi('biosafety:disease:edit')")
    @Log(title = "疾病", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SwDisease swDisease)
    {
        return toAjax(swDiseaseService.updateSwDisease(swDisease));
    }

    /**
     * 删除疾病
     */
    @PreAuthorize("@ss.hasPermi('biosafety:disease:remove')")
    @Log(title = "疾病", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(swDiseaseService.deleteSwDiseaseByIds(ids));
    }
}
