package com.zhyc.module.biosafety.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.Diagnosis;
import com.zhyc.module.biosafety.service.IDiagnosisService;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 诊疗结果Controller
 * 
 * @author ruoyi
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/diagnosis/diagnosis")
public class DiagnosisController extends BaseController
{
    @Autowired
    private IDiagnosisService diagnosisService;

    /**
     * 查询诊疗结果列表
     */
    @PreAuthorize("@ss.hasPermi('diagnosis:diagnosis:list')")
    @GetMapping("/list")
    public TableDataInfo list(Diagnosis diagnosis)
    {
        startPage();
        List<Diagnosis> list = diagnosisService.selectDiagnosisList(diagnosis);
        return getDataTable(list);
    }

    /**
     * 导出诊疗结果列表
     */
    @PreAuthorize("@ss.hasPermi('diagnosis:diagnosis:export')")
    @Log(title = "诊疗结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Diagnosis diagnosis)
    {
        List<Diagnosis> list = diagnosisService.selectDiagnosisList(diagnosis);
        ExcelUtil<Diagnosis> util = new ExcelUtil<Diagnosis>(Diagnosis.class);
        util.exportExcel(response, list, "诊疗结果数据");
    }

    /**
     * 获取诊疗结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('diagnosis:diagnosis:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(diagnosisService.selectDiagnosisById(id));
    }

    /**
     * 新增诊疗结果
     */
    @PreAuthorize("@ss.hasPermi('diagnosis:diagnosis:add')")
    @Log(title = "诊疗结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Diagnosis diagnosis)
    {
        diagnosis.setDeptId(getDeptId());
        diagnosis.setUserId(getUserId());
        return toAjax(diagnosisService.insertDiagnosis(diagnosis));
    }

    /**
     * 新增批量诊疗结果
     */
    @PreAuthorize("@ss.hasPermi('diagnosis:diagnosis:add')")
    @Log(title = "诊疗结果", businessType = BusinessType.INSERT)
    @PostMapping("/adds")
    public AjaxResult adds(@RequestBody Diagnosis diagnosis)
    {
        return toAjax(diagnosisService.insertDiagnosisList(diagnosis));
    }

    /**
     * 修改诊疗结果
     */
    @PreAuthorize("@ss.hasPermi('diagnosis:diagnosis:edit')")
    @Log(title = "诊疗结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Diagnosis diagnosis)
    {
        return toAjax(diagnosisService.updateDiagnosis(diagnosis));
    }

    /**
     * 删除诊疗结果
     */
    @PreAuthorize("@ss.hasPermi('diagnosis:diagnosis:remove')")
    @Log(title = "诊疗结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(diagnosisService.deleteDiagnosisByIds(ids));
    }
}
