package com.ruoyi.web.work.controller;

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

import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
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.Request;
import com.ruoyi.web.work.service.IRequestService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * request
 * @author lsw
 * @date 2024-07-23
 */
@Api(tags = "科室申请管理")
@RestController
@RequestMapping("/work/request")
public class RequestController extends BaseController {

    @Autowired
    private IRequestService requestService;

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


    @ApiOperation(value = "获取科室申请列表")
    @PreAuthorize("@ss.hasPermi('work:request:list')")
    @GetMapping("/list")
    public TableDataInfo list(Request request){
        startPage();
        List<Request> list = requestService.selectList(request);
        return getDataTable(list);
    }

    @ApiOperation(value = "根据Id获取科室申请列表")
    @PreAuthorize("@ss.hasPermi('work:request:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id){
        return AjaxResult.success(requestService.getById(id));
    }

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

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

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