package org.jeecg.modules.wps.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.wps.base.Response;
import org.jeecg.modules.wps.service.IWpsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author zm
 * 用户相关回调接口
 */
@Slf4j
@RestController
@RequestMapping("v1/3rd")
public class UserCallBackController{

    @Autowired
    private IWpsUserService wpsUserService;

    /**
     * 获取用户信息
     */
    @PostMapping("user/info")
    public ResponseEntity<Object> userInfo(@RequestBody JSONObject reqObj){
        log.info("获取用户信息param:{}", JSON.toJSON(reqObj));
        try {
            Map<String,Object> map =
                    wpsUserService.userInfo(reqObj);
            return Response.success(map);
        }catch (Exception e){
            return Response.bad("获取用户信息异常");
        }
    }

    /**
     * 回调通知
     */
    @PostMapping("onnotify")
    public ResponseEntity<Object> onNotify(@RequestBody JSONObject obj){
        log.info("回调通知param:{}", JSON.toJSON(obj));
        // TODO
        // 返回数据暂不处理
        return Response.success();
    }

}
