package com.zhyc.module.biosafety.controller;

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

import com.zhyc.module.biosafety.domain.SwMedicType;
import com.zhyc.module.biosafety.service.ISwMedicTypeService;
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;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 药品类型Controller
 * 
 * @author ruoyi
 * @date 2025-07-11
 */
@RestController
@RequestMapping("/biosafety/type")
public class SwMedicTypeController extends BaseController
{
    @Autowired
    private ISwMedicTypeService swMedicTypeService;

    /**
     * 查询药品类型列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(SwMedicType swMedicType)
    {
        startPage();
        List<SwMedicType> list = swMedicTypeService.selectSwMedicTypeList(swMedicType);
        return getDataTable(list);
    }

    /**
     * 导出药品类型列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:type:export')")
    @Log(title = "药品类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SwMedicType swMedicType)
    {
        List<SwMedicType> list = swMedicTypeService.selectSwMedicTypeList(swMedicType);
        ExcelUtil<SwMedicType> util = new ExcelUtil<SwMedicType>(SwMedicType.class);
        util.exportExcel(response, list, "药品类型数据");
    }

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

    /**
     * 新增药品类型
     */
    @PreAuthorize("@ss.hasPermi('biosafety:type:add')")
    @Log(title = "药品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SwMedicType swMedicType)
    {
        return toAjax(swMedicTypeService.insertSwMedicType(swMedicType));
    }

    /**
     * 修改药品类型
     */
    @PreAuthorize("@ss.hasPermi('biosafety:type:edit')")
    @Log(title = "药品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SwMedicType swMedicType)
    {
        return toAjax(swMedicTypeService.updateSwMedicType(swMedicType));
    }

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