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.Obr;
import com.ruoyi.web.work.service.IObrService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * obr
 * @author lsw
 * @date 2024-07-23
 */
@Api(tags = "科室申请管理")
@Anonymous
@RestController
@RequestMapping("/work/obr")
public class ObrController extends BaseController {
    @Autowired
    private IObrService obrService;

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

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

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

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

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