package com.zhyc.module.biosafety.controller;

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

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

/**
 * 样品类型Controller
 * 
 * @author ruoyi
 * @date 2025-07-14
 */
@RestController
@RequestMapping("/biosafety/sample")
public class QuarantineSampleController extends BaseController
{
    @Autowired
    private IQuarantineSampleService quarantineSampleService;

    /**
     * 查询样品类型列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:sample:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuarantineSample quarantineSample)
    {
        startPage();
        List<QuarantineSample> list = quarantineSampleService.selectQuarantineSampleList(quarantineSample);
        return getDataTable(list);
    }

    /**
     * 导出样品类型列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:sample:export')")
    @Log(title = "样品类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuarantineSample quarantineSample)
    {
        List<QuarantineSample> list = quarantineSampleService.selectQuarantineSampleList(quarantineSample);
        ExcelUtil<QuarantineSample> util = new ExcelUtil<QuarantineSample>(QuarantineSample.class);
        util.exportExcel(response, list, "样品类型数据");
    }

    /**
     * 获取样品类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('biosafety:sample:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(quarantineSampleService.selectQuarantineSampleById(id));
    }

    /**
     * 新增样品类型
     */
    @PreAuthorize("@ss.hasPermi('biosafety:sample:add')")
    @Log(title = "样品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuarantineSample quarantineSample)
    {
        return toAjax(quarantineSampleService.insertQuarantineSample(quarantineSample));
    }

    /**
     * 修改样品类型
     */
    @PreAuthorize("@ss.hasPermi('biosafety:sample:edit')")
    @Log(title = "样品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuarantineSample quarantineSample)
    {
        return toAjax(quarantineSampleService.updateQuarantineSample(quarantineSample));
    }

    /**
     * 删除样品类型
     */
    @PreAuthorize("@ss.hasPermi('biosafety:sample:remove')")
    @Log(title = "样品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(quarantineSampleService.deleteQuarantineSampleByIds(ids));
    }
}
