package com.hs.api.controller;

import com.hs.api.common.Result;
import com.hs.api.common.annotations.CurrentUser;
import com.hs.api.common.annotations.Token;
import com.hs.api.model.SerDepartment;
import com.hs.api.model.SysRole;
import com.hs.api.model.SysUser;
import com.hs.api.model.reqmodel.Disease;
import com.hs.api.model.respmodel.SysMenuList;
import com.hs.api.service.SysMenuService;
import com.hs.api.service.SysUserOrgRsService;
import com.hs.api.service.SysUserRoleRsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;


@Api(tags = "用户API", produces = "produces", consumes = "consumes", protocols = "protocols")
@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private SysUserRoleRsService sysUserRoleRsService;
    @Autowired
    private SysMenuService sysMenuService;
    @Autowired
    private SysUserOrgRsService sysUserOrgRsService;


    @GetMapping()
    @ApiIgnore
    public Object user(@CurrentUser @ApiIgnore SysUser user) {
        return Result.success(user);
    }


    /**
     * 根据用户id查询用户角色
     *
     * @param userId 用户id
     * @return
     */
    @PostMapping("roles")
    @Token
    @ApiOperation("查询用户角色")
    public Object getRoleListByUser(@ApiIgnore @CurrentUser Long userId) throws Exception {
        List<SysRole> sysRoleList = sysUserRoleRsService.getRoleListByUser(userId);
        return Result.success(sysRoleList);
    }

    /**
     * 根据用户id查询用户菜单
     *
     * @param userId 用户id
     * @return
     */
    @PostMapping("menus")
    @Token
    @ApiOperation("查询用户菜单")
    public Object getMenuByUser(@ApiIgnore @CurrentUser Long userId) throws Exception {
        List<SysMenuList> sysMenuList = sysMenuService.getMenu(userId);
        return Result.success(sysMenuList);
    }

    /**
     * 根据用户id查询用户机构
     *
     * @param userId 用户id
     * @return
     */
    @PostMapping("dept")
    @Token
    @ApiOperation("查询用户科室")
    public Object getOrgByUser(@ApiIgnore @CurrentUser Long userId, @RequestBody Disease.DiseaseIDorLevel disease) throws Exception {
        List<SerDepartment> sysMenuList = sysUserOrgRsService.getUserOrg(userId, disease.getDisease(), disease.getDate());
        return Result.success(sysMenuList);
    }
}
