package cn.iocoder.yudao.module.system.controller.admin.auth;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
import cn.iocoder.yudao.module.system.util.FineReportUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 帆软报表相关")
@RestController
@RequestMapping("/rq/iot-fine-report")
@Validated
public class IotFineReportController {

    @Autowired
    private AdminUserMapper userMapper;

    @GetMapping("createSsoToken")
    @Operation(summary = "创建帆软报表单点登录token")
    public CommonResult<String> createIotInfoClassify() {
        String ssoToken = StrUtil.EMPTY;
        // 获取当前登录人的工号等信息
        Long userId = WebFrameworkUtils.getLoginUserId();
        if (ObjUtil.isNotEmpty(userId)) {
            AdminUserDO user = userMapper.selectById(userId);
            if (ObjUtil.isNotEmpty(user)) {
                String username = user.getUsername();
                ssoToken = FineReportUtils.RsaEncrypt(username);
            }
        }
        return success(ssoToken);
    }

}
