package com.fs.app.controller;


import com.fs.app.utils.JwtUtils;
import com.fs.app.websocket.service.WebSocketServer;
import com.fs.common.core.domain.R;
import com.fs.common.core.redis.RedisCache;
import com.fs.company.service.ICompanyWxChatService;
import com.fs.sop.domain.QwSopLogs;
import com.fs.sop.mapper.QwSopLogsMapper;
import com.fs.wxUser.service.ICompanyWxUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;


@Api("公共接口")
@Slf4j
@RestController
@RequestMapping(value="/app/common")
@AllArgsConstructor
public class CommonController {

    private final WebSocketServer webSocketServer;
    private final ICompanyWxUserService companyWxUserService;
    private final ICompanyWxChatService companyWxChatService;
    private final QwSopLogsMapper qwSopLogsMapper;
    private final RedisCache redisCache;
    private final JwtUtils jwtUtils;
//    private final WebSocketServer webSocketServer;

    @GetMapping("/testSend")
    public R testSend( ) throws Exception
    {
        String json="{\"cmd\":\"sendMsg\",\"msg\":\"test\",\"nickName\":\"123\"}";
//        String json="{\"cmd\":\"listenMsg\",\"users\":[\"123\"]}";
        webSocketServer.sendInfo("2020", json);
        return R.ok();
    }

    @GetMapping("/testListen")
    public R testListen( ) throws Exception
    {
//        String json="{\"cmd\":\"sendMsg\",\"msg\":\"test\",\"nickName\":\"123\"}";
        String json="{\"cmd\":\"listenMsg\",\"users\":[\"123\"]}";
        webSocketServer.sendInfo("2020", json);
        return R.ok();
    }
    @GetMapping("/testClickHouse")
    public R testClickHouse( ) throws Exception{
        QwSopLogs qwSopLogs = qwSopLogsMapper.selectById("2c42bded-085b-452c-8166-7ed2b070a016");
        qwSopLogs.setSopId("2324dcea-0a4c-4688-b43d-2d9691ede6b4");
        qwSopLogsMapper.updateById(qwSopLogs);
        return R.ok();
    }

    @ApiOperation("获取发送信息")
    @GetMapping("/getMsgList")
    public R getMsg(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime time){
        return R.ok().put("data", companyWxUserService.getMsg(1, time));
    }

}
