package com.fs.qw;

import com.alibaba.fastjson.JSON;
import com.fs.common.core.domain.R;
import com.fs.qwApi.domain.*;
import com.fs.qwApi.service.QwWorkApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/msg")
public class QwWorkController {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    QwWorkApiService qwWorkApiService;
    @PostMapping
    public void msg(@RequestBody String  decryptForm)
    {
        logger.info("消息回调");
        logger.info(decryptForm);
        QwWorkMsg qwWorkMsg = JSON.parseObject(decryptForm, QwWorkMsg.class);
        logger.info("消息"+qwWorkMsg);
    }


    @GetMapping("/login/{id}")
    public R login(@PathVariable String id)
    {
        QwWorkMsgResult login = qwWorkApiService.login();
      return   R.ok().put("data",login);
    }

    @GetMapping("/sendAppMsg/{id}")
    public R sendAppMsg(@PathVariable String id)
    {
        QwWorkExternalSendApp app = new QwWorkExternalSendApp();
        app.setAvatar_url("http://mmbiz.qpic.cn/mmbiz_png/bssDiaXdRbEYwwNe32GVfoLMwWNNdQvEFurS8KCGk8qWDyUZricsZGdq7IRBXBWsq3C4HY9UrnSuD1U6DmoufQgw/640?wx_fmt=png&wxfrom=200");
        app.setUser_id(id);
        app.setDesc("描述信息");
        app.setTitle("标题");
        app.setCover_path("https://cos.his.cdwjyyh.com/fs/20240510/7233cddde2b8485593da5c4de30c5099.png");
        app.setApp_id("wxc3f0a952b7bc2b94");
        app.setWechat_id("gh_7a6a32e5ef61@app");
        app.setPage_path("pages/index/index.html");
        qwWorkApiService.sendAppMsg(app);
        QwWorkMsgResult login = qwWorkApiService.login();
        return   R.ok().put("data",login);
    }

    @GetMapping("/getUserList")
    public R getUserList()
    {
        QwWorkExternalContactListResult userList = qwWorkApiService.getUserList();
        return   R.ok().put("data",userList);
    }

    @GetMapping("/sendMsg/{id}")
    public R sendMsg(@PathVariable String id)
    {
        QwWorkMsgResult s = qwWorkApiService.sendMsg(id, "测试消息");

        return   R.ok().put("data",s);
    }
    @GetMapping("/sendImageMsg/{id}")
    public R sendImageMsg(@PathVariable String id)
    {
        QwWorkMsgResult s = qwWorkApiService.sendImageMsg("7881302616973822", "https://cos.his.cdwjyyh.com/fs/20240510/7233cddde2b8485593da5c4de30c5099.png");
        return   R.ok().put("data",s);
    }


    @GetMapping("/loginStatus")
    public R loginStatus()
    {
        QwWorkLoginStatus send = qwWorkApiService.loginStatus();
        return   R.ok().put("data",send);
    }
}
