package com.zhyc.module.biosafety.controller;

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

import com.zhyc.common.utils.SecurityUtils;
import com.zhyc.module.biosafety.service.IHealthService;
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.Health;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 保健Controller
 * 
 * @author ruoyi
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/biosafety/health")
public class HealthController extends BaseController
{
    @Autowired
    private IHealthService healthService;

    /**
     * 查询保健列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:health:list')")
    @GetMapping("/list")
    public TableDataInfo list(Health health)
    {
        startPage();
        List<Health> list = healthService.selectHealthList(health);
        return getDataTable(list);
    }

    /**
     * 导出保健列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:health:export')")
    @Log(title = "保健", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Health health)
    {
        List<Health> list = healthService.selectHealthList(health);
        ExcelUtil<Health> util = new ExcelUtil<Health>(Health.class);
        util.exportExcel(response, list, "保健数据");
    }

    /**
     * 获取保健详细信息
     */
    @PreAuthorize("@ss.hasPermi('biosafety:health:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(healthService.selectHealthById(id));
    }

    /**
     * 新增保健
     */
    @PreAuthorize("@ss.hasPermi('biosafety:health:add')")
    @Log(title = "保健", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Health health)
    {
        health.setDeptId(getDeptId());
        health.setUserId(getUserId());
        return toAjax(healthService.insertHealth(health));
    }

    /**
     * 修改保健
     */
    @PreAuthorize("@ss.hasPermi('biosafety:health:edit')")
    @Log(title = "保健", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Health health)
    {
        return toAjax(healthService.updateHealth(health));
    }

    /**
     * 删除保健
     */
    @PreAuthorize("@ss.hasPermi('biosafety:health:remove')")
    @Log(title = "保健", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(healthService.deleteHealthByIds(ids));
    }
}
