package com.ruoyi.web.work.controller;

import java.util.Arrays;
import java.util.List;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.web.work.domain.Request;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.work.domain.Result;
import com.ruoyi.web.work.service.IResultService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * request
 * @author lsw
 * @date 2024-07-23
 */
@Api(tags = "检测项目管理")
@Anonymous
@RestController
@RequestMapping("/work/result")
public class ResultController extends BaseController {
    @Autowired
    private IResultService resultService;


    @ApiOperation(value = "根据患者ID获取此人的全部检查结果列表")
    //@PreAuthorize("@ss.hasPermi('work:request:list')")
    @GetMapping("/patid/{patId}")
    public TableDataInfo getAllResultByPatId(@PathVariable("patId") Long patId){
        startPage();
        List<Result> list = resultService.getAllResultByPatId(patId);
        return getDataTable(list);
    }

    @ApiOperation(value = "获取检测项目列表")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:request:list')")
    @GetMapping("/list")
    public TableDataInfo list(Result result){
        startPage();
        List<Result> list = resultService.selectList(result);
        return getDataTable(list);
    }

    @ApiOperation(value = "根据Id获取检测项目列表")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:request:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id){
        return AjaxResult.success(resultService.getById(id));
    }

    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:request:add')")
    @Log(title = "request", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Result request){
        return toAjax(resultService.save(request));
    }

    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:request:edit')")
    @Log(title = "request", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Result request){
        return toAjax(resultService.updateById(request));
    }

    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:request:remove')")
    @Log(title = "request", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(resultService.removeByIds(Arrays.asList(ids)));
    }
}
