package com.gxwebsoft;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.gxwebsoft.hjm.controller.PushCallback;
import com.gxwebsoft.hjm.entity.HjmCar;
import com.gxwebsoft.hjm.service.HjmCarService;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.text.ParseException;

/**
 * Created by WebSoft on 2020-03-23 23:37
 */
@SpringBootTest
public class TestMain {
  private static final Logger logger = LoggerFactory.getLogger(PushCallback.class);

  @Resource
  private HjmCarService hjmCarService;

  /**
   * 生成唯一的key用于jwt工具类
   */
  @Test
  public void testGenJwtKey() {

    BigDecimal bigDecimal = new BigDecimal(NumberUtil.decimalFormat("0.00", 1 * 0.01));
    System.out.println("实际付款金额111111111 = " + bigDecimal);

    final HjmCar byGpsNo = hjmCarService.getByGpsNo("gps1");
    System.out.println("byGpsNo = " + byGpsNo.getSpeed());
    if(StrUtil.isBlank(byGpsNo.getSpeed())){
      System.out.println("空的 = ");
    }
    if(byGpsNo.getSpeed() == null){
      System.out.println("getSpeed = ");
    }
//    System.out.println(JwtUtil.encodeKey(JwtUtil.randomKey()));

//    final String encrypt = CommonUtil.encrypt("123456");
//    System.out.println("encrypt = " + encrypt);
//
//    final String decrypt = CommonUtil.decrypt(encrypt);
//    System.out.println("decrypt = " + decrypt);
  }

//  @Test
//  public void mqtt() throws MqttException {
////tcp://MQTT安装的服务器地址:MQTT定义的端口号
//    String HOST = "tcp://1.14.159.185:1883";
//
//    //定义MQTT的ID，可以在MQTT服务配置中指定
//    String clientid = "mqttx_aec633ca2";
//
//    MqttClient client;
//    String userName = "swdev";
//    String passWord = "Sw20250523";
//
//    client = new MqttClient(HOST, clientid, new MemoryPersistence());
//
//    final MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
//    mqttConnectOptions.setUserName(userName);
//    mqttConnectOptions.setPassword(passWord.toCharArray());
//    mqttConnectOptions.setCleanSession(true);
//
//    client.setCallback(new MqttCallback() {
//      @Override
//      public void connectionLost(Throwable throwable) {
//        logger.info("连接丢失.............");
//      }
//
//      @Override
//      public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
//        logger.info("接收消息主题 : " + topic);
//        logger.info("接收消息Qos : " + mqttMessage.getQos());
//        logger.info("接收消息内容 : " + new String(mqttMessage.getPayload()));
//      }
//
//      @Override
//      public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
//        logger.info("deliveryComplete.............");
//      }
//    });
//    client.connect(mqttConnectOptions);
//    client.subscribe("/SW_GSP/#", 2);
//    while (true);
//  }
}
