package com.fs.app.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fs.app.annotation.Login;
import com.fs.app.param.SendSopParam;
import com.fs.app.utils.JwtUtils;
import com.fs.app.websocket.bean.MsgBean;
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.domain.CompanyConfig;
import com.fs.company.domain.CompanyMoneyLogs;
import com.fs.company.service.ICompanyConfigService;
import com.fs.company.service.ICompanyWxChatService;
import com.fs.his.service.IFsAppVersionService;
import com.fs.his.service.IFsCityService;
import com.fs.his.service.IFsInquiryOrderMsgService;
import com.fs.his.utils.ConfigUtil;
import com.fs.sop.domain.QwSopLogs;
import com.fs.sop.mapper.QwSopLogsMapper;
import com.fs.system.service.ISysConfigService;
import com.fs.system.service.ISysDictDataService;
import com.fs.wx.kf.dto.WeixinKfMsgDTO;
import com.fs.wx.kf.dto.WeixinKfMsgSendDTO;
import com.fs.wx.kf.dto.WeixinKfTextMsgDTO;
import com.fs.wx.kf.service.IWeixinKfService;
import com.fs.wx.kf.vo.WeixinKfMsgItemVO;
import com.fs.wx.kf.vo.WeixinKfMsgVO;
import com.fs.wxUser.service.ICompanyWxUserService;
import com.google.code.kaptcha.Producer;
import com.qq.weixin.mp.aes.AesException;
import com.qq.weixin.mp.aes.WXBizMsgCrypt;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.w3c.dom.Element;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;

import static com.fs.common.constant.FsConstants.REDIS_CHAT_NEXTCURSOR;


@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));
    }

}
