package com.qingyun.web.controller.api;


import com.qingyun.common.core.domain.R;
import com.qingyun.common.core.domain.entity.SysUser;
import com.qingyun.common.core.domain.model.LoginUser;
import com.qingyun.common.helper.LoginHelper;
import com.qingyun.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户模块
 *
 * @author PC
 */
@RestController
@RequestMapping("/api/user")
@RequiredArgsConstructor
public class ApiUserController {

    private final ISysUserService userService;

//    private final DtService dtService;

    /**
     * 获取用户信息
     *
     * @return
     */
    @GetMapping("/getInfo")
    public R<Map<String, Object>> getInfo() {
        LoginUser loginUser = LoginHelper.getLoginUser();
        SysUser user = userService.selectUserById(loginUser.getUserId());
        Map<String, Object> ajax = new HashMap<>();
        ajax.put("user", user);
        ajax.put("roles", loginUser.getRolePermission());
        ajax.put("permissions", loginUser.getMenuPermission());
        return R.ok(ajax);
    }

//    @GetMapping("sign")
//    public R<Map<String, Object>> sign(String url) throws Exception {
//        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/get_jsapi_ticket");
//        OapiGetJsapiTicketRequest req = new OapiGetJsapiTicketRequest();
//        req.setHttpMethod("GET");
//        OapiGetJsapiTicketResponse rsp = client.execute(req, dtService.getDtConfigStorage().getAccessToken());
//        JSONObject json = JSON.parseObject(rsp.getBody());
//        long time = System.currentTimeMillis();
//        String sign = DdConfigSign.sign(json.getString("ticket"), "abcdefg", time, url);
//        Map<String, Object> map = new HashMap<>();
//        map.put("agentId", String.valueOf(dtService.getDtConfigStorage().getAgentId()));
//        map.put("corpId", dtService.getDtConfigStorage().getCorpId());
//        map.put("timeStamp", String.valueOf(time));
//        map.put("nonceStr", "abcdefg");
//        map.put("signature", sign);
//        return R.ok(map);
//    }

}
