package com.zhyc.module.biosafety.controller;

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

import com.zhyc.module.biosafety.service.IImmunityService;
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.module.biosafety.domain.Immunity;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 免疫Controller
 * 
 * @author ruoyi
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/biosafety/immunity")
public class ImmunityController extends BaseController
{
    @Autowired
    private IImmunityService immunityService;

    /**
     * 查询免疫列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:immunity:list')")
    @GetMapping("/list")
    public TableDataInfo list(Immunity immunity)
    {
        startPage();
        List<Immunity> list = immunityService.selectImmunityList(immunity);
        return getDataTable(list);
    }

    /**
     * 导出免疫列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:immunity:export')")
    @Log(title = "免疫", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Immunity immunity)
    {
        List<Immunity> list = immunityService.selectImmunityList(immunity);
        ExcelUtil<Immunity> util = new ExcelUtil<Immunity>(Immunity.class);
        util.exportExcel(response, list, "免疫数据");
    }

    /**
     * 获取免疫详细信息
     */
    @PreAuthorize("@ss.hasPermi('biosafety:immunity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(immunityService.selectImmunityById(id));
    }

    /**
     * 新增免疫
     */
    @PreAuthorize("@ss.hasPermi('biosafety:immunity:add')")
    @Log(title = "免疫", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Immunity immunity)
    {
        immunity.setDeptId(getDeptId());
        immunity.setUserId(getUserId());
        return toAjax(immunityService.insertImmunity(immunity));
    }

    /**
     * 修改免疫
     */
    @PreAuthorize("@ss.hasPermi('biosafety:immunity:edit')")
    @Log(title = "免疫", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Immunity immunity)
    {
        return toAjax(immunityService.updateImmunity(immunity));
    }

    /**
     * 删除免疫
     */
    @PreAuthorize("@ss.hasPermi('biosafety:immunity:remove')")
    @Log(title = "免疫", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(immunityService.deleteImmunityByIds(ids));
    }
}
