package com.fs.hospital.controller.hospital;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.hospital.domain.HospitalUserPost;
import com.fs.hospital.service.IHospitalUserPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户与岗位关联Controller
 *
 * @author fs
 * @date 2021-10-04
 */
@RestController
@RequestMapping("/hospital/hospitalUserPost")
public class HospitalUserPostController extends BaseController
{
    @Autowired
    IHospitalUserPostService hospitalUserPostService;

    /**
     * 查询用户与岗位关联列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUserPost:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalUserPost hospitalUserPost)
    {
        startPage();
        List<HospitalUserPost> list = hospitalUserPostService.selectHospitalUserPostList(hospitalUserPost);
        return getDataTable(list);
    }

    /**
     * 导出用户与岗位关联列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUserPost:export')")
    @Log(title = "用户与岗位关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalUserPost hospitalUserPost)
    {
        List<HospitalUserPost> list = hospitalUserPostService.selectHospitalUserPostList(hospitalUserPost);
        ExcelUtil<HospitalUserPost> util = new ExcelUtil<HospitalUserPost>(HospitalUserPost.class);
        return util.exportExcel(list, "hospitalUserPost");
    }

    /**
     * 获取用户与岗位关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUserPost:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(hospitalUserPostService.selectHospitalUserPostByUserId(userId));
    }

    /**
     * 新增用户与岗位关联
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUserPost:add')")
    @Log(title = "用户与岗位关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalUserPost hospitalUserPost)
    {
        return toAjax(hospitalUserPostService.insertHospitalUserPost(hospitalUserPost));
    }

    /**
     * 修改用户与岗位关联
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUserPost:edit')")
    @Log(title = "用户与岗位关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalUserPost hospitalUserPost)
    {
        return toAjax(hospitalUserPostService.updateHospitalUserPost(hospitalUserPost));
    }

    /**
     * 删除用户与岗位关联
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUserPost:remove')")
    @Log(title = "用户与岗位关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(hospitalUserPostService.deleteHospitalUserPostByUserIds(userIds));
    }
}
