package com.ruoyi.web.work.controller;

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

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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.DeptInfo;
import com.ruoyi.web.work.service.IDeptInfoService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科室信息
 * @author zeng
 * @date 2024-07-18
 */
@Anonymous
@RestController
@RequestMapping("/work/dept_info")
public class DeptInfoController extends BaseController {
    @Autowired
    private IDeptInfoService deptInfoService;

    //@PreAuthorize("@ss.hasPermi('work:dept_info:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeptInfo deptInfo){
        startPage();
        List<DeptInfo> list = deptInfoService.selectList(deptInfo);
        return getDataTable(list);
    }

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

    //@PreAuthorize("@ss.hasPermi('work:dept_info:add')")
    @Log(title = "科室信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody DeptInfo deptInfo){
        return toAjax(deptInfoService.save(deptInfo));
    }

    //@PreAuthorize("@ss.hasPermi('work:dept_info:edit')")
    @Log(title = "科室信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody DeptInfo deptInfo){
        return toAjax(deptInfoService.updateById(deptInfo));
    }

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