package com.phm.manage.controller;

import com.phm.common.annotation.Log;
import com.phm.common.core.controller.BaseController;
import com.phm.common.core.domain.AjaxResult;
import com.phm.common.core.page.TableDataInfo;
import com.phm.common.enums.BusinessType;
import com.phm.common.utils.poi.ExcelUtil;
import com.phm.manage.domain.DiagnoseResult;
import com.phm.manage.service.IDiagnoseResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 诊断结果Controller
 *
 * @author phm
 * @date 2023-08-31
 */
@RestController
@RequestMapping("/manage/diagnoseResult")
public class DiagnoseResultController extends BaseController {
    @Autowired
    private IDiagnoseResultService diagnoseResultService;

    /**
     * 查询诊断结果列表
     */
    @PreAuthorize("@ss.hasPermi('manage:diagnoseResult:list')")
    @GetMapping("/list")
    public TableDataInfo list(DiagnoseResult diagnoseResult) {
        startPage();
        List<DiagnoseResult> list = diagnoseResultService.selectDiagnoseResultList(diagnoseResult);
        return getDataTable(list);
    }

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

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

    /**
     * 新增诊断结果
     */
    @PreAuthorize("@ss.hasPermi('manage:diagnoseResult:add')")
    @Log(title = "诊断结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DiagnoseResult diagnoseResult) {
        return toAjax(diagnoseResultService.insertDiagnoseResult(diagnoseResult));
    }

    /**
     * 修改诊断结果
     */
    @PreAuthorize("@ss.hasPermi('manage:diagnoseResult:edit')")
    @Log(title = "诊断结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DiagnoseResult diagnoseResult) {
        return toAjax(diagnoseResultService.updateDiagnoseResult(diagnoseResult));
    }

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