package com.zhyc.module.biosafety.controller;

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

import com.zhyc.module.biosafety.domain.Treatment;
import com.zhyc.module.biosafety.service.ITreatmentService;
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("/treatment/treatment")
public class TreatmentController extends BaseController
{
    @Autowired
    private ITreatmentService treatmentService;

    /**
     * 查询治疗记录列表
     */
    @PreAuthorize("@ss.hasPermi('treatment:treatment:list')")
    @GetMapping("/list")
    public TableDataInfo list(Treatment treatment)
    {
        startPage();
        List<Treatment> list = treatmentService.selectTreatmentList(treatment);
        return getDataTable(list);
    }

    /**
     * 导出治疗记录列表
     */
    @PreAuthorize("@ss.hasPermi('treatment:treatment:export')")
    @Log(title = "治疗记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Treatment treatment)
    {
        List<Treatment> list = treatmentService.selectTreatmentList(treatment);
        ExcelUtil<Treatment> util = new ExcelUtil<Treatment>(Treatment.class);
        util.exportExcel(response, list, "治疗记录数据");
    }

    /**
     * 获取治疗记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('treatment:treatment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(treatmentService.selectTreatmentById(id));
    }

    /**
     * 新增治疗记录
     */
    @PreAuthorize("@ss.hasPermi('treatment:treatment:add')")
    @Log(title = "治疗记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Treatment treatment)
    {
        treatment.setDeptId(getDeptId());
        treatment.setUserId(getUserId());
        return toAjax(treatmentService.insertTreatment(treatment));
    }

    /**
     * 修改治疗记录
     */
    @PreAuthorize("@ss.hasPermi('treatment:treatment:edit')")
    @Log(title = "治疗记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Treatment treatment)
    {
        return toAjax(treatmentService.updateTreatment(treatment));
    }

    /**
     * 删除治疗记录
     */
    @PreAuthorize("@ss.hasPermi('treatment:treatment:remove')")
    @Log(title = "治疗记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(treatmentService.deleteTreatmentByIds(ids));
    }
}
