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.HospitalUserRole;
import com.fs.hospital.service.IHospitalUserRoleService;
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/hospitalUserRole")
public class HospitalUserRoleController extends BaseController
{
    @Autowired
    private IHospitalUserRoleService hospitalUserRoleService;

    /**
     * 查询用户和角色关联列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUserRole:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalUserRole hospitalUserRole)
    {
        startPage();
        List<HospitalUserRole> list = hospitalUserRoleService.selectHospitalUserRoleList(hospitalUserRole);
        return getDataTable(list);
    }

    /**
     * 导出用户和角色关联列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUserRole:export')")
    @Log(title = "用户和角色关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalUserRole hospitalUserRole)
    {
        List<HospitalUserRole> list = hospitalUserRoleService.selectHospitalUserRoleList(hospitalUserRole);
        ExcelUtil<HospitalUserRole> util = new ExcelUtil<HospitalUserRole>(HospitalUserRole.class);
        return util.exportExcel(list, "hospitalUserRole");
    }

    /**
     * 获取用户和角色关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUserRole:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(hospitalUserRoleService.selectHospitalUserRoleById(userId));
    }

    /**
     * 新增用户和角色关联
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUserRole:add')")
    @Log(title = "用户和角色关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalUserRole hospitalUserRole)
    {
        return toAjax(hospitalUserRoleService.insertHospitalUserRole(hospitalUserRole));
    }

    /**
     * 修改用户和角色关联
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUserRole:edit')")
    @Log(title = "用户和角色关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalUserRole hospitalUserRole)
    {
        return toAjax(hospitalUserRoleService.updateHospitalUserRole(hospitalUserRole));
    }

    /**
     * 删除用户和角色关联
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalUserRole:remove')")
    @Log(title = "用户和角色关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(hospitalUserRoleService.deleteHospitalUserRoleByIds(userIds));
    }
}
