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

/**
 * obx
 * @author lsw
 * @date 2024-07-23
 */
@Api(tags = "检测项目管理")
@Anonymous
@RestController
@RequestMapping("/work/obx")
public class ObxController extends BaseController {
    @Autowired
    private IObxService obxService;


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

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

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

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

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