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

/**
 * orders
 * @author lsw
 * @date 2024-07-24
 */
@Api(tags = "医嘱信息管理")
@Anonymous
@RestController
@RequestMapping("/work/orders")
public class OrdersController extends BaseController {
    @Autowired
    private IOrdersService ordersService;


    @PreAuthorize("@ss.hasPermi('work:orders:list')")
    @GetMapping("/list")
    public TableDataInfo list(Orders orders){
        startPage();
        List<Orders> list = ordersService.selectList(orders);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('work:orders:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id){
        return AjaxResult.success(ordersService.getById(id));
    }

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

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

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