package com.fjhx.controller.common;

import cn.hutool.core.convert.Convert;
import com.fjhx.utils.Assert;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.system.feign.ISysClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;

@RestController
@RequestMapping("/common")
public class CommonController {

    @Resource
    private ISysClient sysClient;

    @PostMapping("/getInfo")
    public R getInfo() {
        BladeUser user = AuthUtil.getUser();
        if (user == null) {
            return R.fail("未获取登录用户");
        }
        HashMap<String, Object> map = new HashMap<>();
        Long userId = user.getUserId();
        String account = user.getAccount();
        String userName = user.getNickName();
        String deptId = user.getDeptId().split(",")[0];
        R<String> r = sysClient.getDeptName(Convert.toLong(deptId));
        String deptName = Assert.result(r);

        map.put("userId", userId);
        map.put("account", account);
        map.put("userName", userName);
        map.put("deptId", deptId);
        map.put("deptName", deptName);

        return R.success(map);
    }

}
