package com.zhyc.module.biosafety.controller;

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

import com.zhyc.module.biosafety.domain.Deworm;
import com.zhyc.module.biosafety.service.IDewormService;
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-15
 */
@RestController
@RequestMapping("/biosafety/deworm")
public class DewormController extends BaseController
{
    @Autowired
    private IDewormService dewormService;

    /**
     * 查询驱虫列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:deworm:list')")
    @GetMapping("/list")
    public TableDataInfo list(Deworm deworm)
    {
        startPage();
        List<Deworm> list = dewormService.selectDewormList(deworm);
        return getDataTable(list);
    }

    /**
     * 导出驱虫列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:deworm:export')")
    @Log(title = "驱虫", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Deworm deworm)
    {
        List<Deworm> list = dewormService.selectDewormList(deworm);
        ExcelUtil<Deworm> util = new ExcelUtil<Deworm>(Deworm.class);
        util.exportExcel(response, list, "驱虫数据");
    }

    /**
     * 获取驱虫详细信息
     */
    @PreAuthorize("@ss.hasPermi('biosafety:deworm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dewormService.selectDewormById(id));
    }

    /**
     * 新增驱虫
     */
    @PreAuthorize("@ss.hasPermi('biosafety:deworm:add')")
    @Log(title = "驱虫", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Deworm deworm)
    {
        deworm.setDeptId(getDeptId());
        deworm.setUserId(getUserId());
        return toAjax(dewormService.insertDeworm(deworm));
    }

    /**
     * 修改驱虫
     */
    @PreAuthorize("@ss.hasPermi('biosafety:deworm:edit')")
    @Log(title = "驱虫", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Deworm deworm)
    {
        return toAjax(dewormService.updateDeworm(deworm));
    }

    /**
     * 删除驱虫
     */
    @PreAuthorize("@ss.hasPermi('biosafety:deworm:remove')")
    @Log(title = "驱虫", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dewormService.deleteDewormByIds(ids));
    }
}
