package com.gxwebsoft;

import com.gxwebsoft.apps.service.HualalaService;
import com.gxwebsoft.apps.service.TestDataService;
import com.gxwebsoft.common.system.mapper.RoleMapper;
import com.gxwebsoft.common.system.mapper.UserMapper;
import com.gxwebsoft.common.system.service.SettingService;
import com.gxwebsoft.common.system.service.UserService;
import com.gxwebsoft.love.service.CertificateService;
import com.gxwebsoft.shop.mapper.OrderGoodsMapper;
import com.gxwebsoft.shop.mapper.OrderMapper;
import com.gxwebsoft.shop.service.OrderService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Created by WebSoft on 2020-03-23 23:37
 */
@SpringBootTest
public class TestMain {
  @Resource
  private StringRedisTemplate stringRedisTemplate;
  @Resource
  private OrderService orderService;
  @Resource
  private OrderGoodsMapper orderGoodsMapper;
  @Resource
  private OrderMapper orderMapper;
  @Resource
  private TestDataService testDataService;
  @Resource
  private HualalaService hualalaService;
  @Resource
  private SettingService settingService;
  @Resource
  private UserService userService;
  @Resource
  private UserMapper userMapper;
  @Resource
  private RoleMapper roleMapper;

  @Resource
  private CertificateService certificateService;

  /**
   * 生成唯一的key用于jwt工具类
   */
//  @Test
//  public void testGenJwtKey() {
//    System.out.println(JwtUtil.encodeKey(JwtUtil.randomKey()));
//  }

  /**
   * 生成加密后的登录密码
   * @return
   */
  @Test
  public void testEncodePassword() throws UnsupportedEncodingException {
//    DateTime date = DateUtil.date();
//    System.out.println("date = " + date);
//    final String today = DateUtil.today();
//    System.out.println("today = " + today);
//    final DateTime dateTime = DateUtil.beginOfDay(date);
//    System.out.println("dateTime = " + dateTime);
//    System.out.println(new BCryptPasswordEncoder().encode("admin"));
    String encodedReturnUrl = URLEncoder.encode("https://server.gxwebsoft.com/api/open/wx-work/saveAccessToken","UTF-8");
//    System.out.println("encodedReturnUrl = " + encodedReturnUrl);
//    System.out.println("encodedReturnUrl = " + encodedReturnUrl);
//    log.info("生成加密后的登录密码:" + encodedReturnUrl);
  }

//  @Test
//  public void test3() {
//    String key = "test:user:10";
//    HashMap<String, Object> map = new HashMap<>();
//    map.put("name", "科技小王子");
//    map.put("sex", "男");
//    map.put("phone", "13737128880");
//    map.put("money", "238585.215");
//    stringRedisTemplate.opsForHash().putAll(key, map);
//  }

//      OrderParam param = new OrderParam();
//      param.setPayStatus(30);
//      param.setOrderNo("202303118310602");
//      final List<Order> all = orderMapper.getAll(param);
//      System.out.println("all = " + all);
//      OrderParam param = new OrderParam();
//      param.setOrderNo("2023031181184283");
//      param.setPayStatus(20);
//      boolean b = orderMapper.updatePayStatus(param);
//      System.out.println("b = " + b);

//      Order order = orderService.getByOutTradeNo("20230301761610059");
//      OrderParam orderParam = new OrderParam();
//      orderParam.setPayStatus(20);
//      orderParam.setOrderNo("20230301761610059");
//      orderMapper.updatePayStatus(orderParam);
//      System.out.println("order = " + order);
//      Order order = new Order();
//      order.setOrderId(400);
//      order.setComments("sdfsdfsdfs");
//
//      boolean update = orderService.lambdaUpdate()
//        .eq(Order::getOrderId, order.getOrderId())
//        .update(order);
//      System.out.println("update = " + update);

//      OrderParam param = new OrderParam();
//      param.setOrderNo("20230301761610059");
//      Order order = orderService.getByOutTradeNo("20230301761610059");
//      System.out.println("order = " + order);
//      final int i = orderMapper.updateById(order);
//      System.out.println("i = " + i);


//      final Order one = param.getOne(orderMapper.getOne(param));
//      one.setTotalPrice(new BigDecimal("2.22"));
//      one.setPayStatus(20);
//      orderMapper.updateById(one);
//      System.out.println("one = " + one);
//      Order order = orderService.getByOutTradeNo("20230301761610059");
//      order.setPayStatus(20);
//      order.setTotalPrice(new BigDecimal("1.11"));
//      if (orderService.updateById(order)) {
//        System.out.println("成功");
//      }

//  @Test
//  public void test() {
//      final TestData testData = new TestData();
//      testData.setTitle("测试");
//      testData.setContent("内容...");
//      testData.setTenantId(10);
//      testDataService.save(testData);

//    final boolean b = testDataService.removeById(2496);

//  }

//  @Test
//  public void query() {
//    HashMap<String, Object> params = new HashMap<>();
//    params.put("shopID", Long.valueOf("76230180"));
//    JSONObject response = hualalaService.doPost("/doc/getPaySubject", params);
//    System.out.println("response = " + response);
//  }

  // 推送订单到哗啦啦
//    @Test
//    public void pushOrder(){
//      Order orderInfo = orderService.getByOutTradeNo("202303118345835");
//      final List<OrderGoods> goodsInfo = orderGoodsMapper.selectByOrderId(orderInfo.getOrderId());
//      System.out.println("orderInfo = " + orderInfo);
//      System.out.println("goodsInfo = " + goodsInfo);
//      // 菜品信息
//      ArrayList<Object> orderItem = new ArrayList<>();
//      JSONObject item = new JSONObject();
//      item.put("foodID",603798638);
//      item.put("foodName","肉汁煲霜打萝卜.");
//      item.put("foodUnit","份");
//      item.put("foodUnitID","1748099318");
//      item.put("isSetFood",0);
//      item.put("isBatching",0);
//      item.put("foodCount",1);
//      item.put("originPrice","100");
//      item.put("takeoutPackagingFee","1");
//      item.put("isDiscount",0);
//      item.put("duePrice","1");
//      orderItem.add(item);
//      // 支付信息
//      ArrayList<Object> payInfo = new ArrayList<>();
//      JSONObject payItem = new JSONObject();
//      payItem.put("paymentSubjectID",Long.valueOf("51010440"));
//      payItem.put("paymentSubjectName","微信小程序实收");
//      payItem.put("dueAmount","1");
//      payItem.put("paymentStatus",20);
//      payItem.put("payWay",70);
//      payInfo.add(payItem);
//
//      // 订单信息
//      JSONObject order = new JSONObject();
//      order.put("orderSubType",20);
//      order.put("orderStatus",20);
//      order.put("discountTotalAmount","1");
//      order.put("dinners",1);
//      // 期望送达时间
//      SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmm");
//      order.put("orderTime",sdf1.format(orderInfo.getCreateTime()));
//      order.put("orderItem",orderItem);
//      order.put("takeoutAddress","外送地址:");
//      order.put("deliveryAmount","0");
//      order.put("serviceAmount","0");
//      order.put("channelKey","399_weixin");
//      order.put("isAlreadyPaid","1");
//      order.put("orderMode",1);
//      order.put("OrderRemark","");
//      order.put("payment",payInfo);
//
//      HashMap<String,Object> params = new HashMap<>();
//      params.put("shopID",Long.valueOf("76230180"));
//      params.put("isCheackOut",0);
//      params.put("isThirdPay",2);
//      params.put("bankCode","weChat");
//      params.put("order",order);
//      params.put("isSentMsg",1);
//      params.put("msgType",120);
//      params.put("thirdOrderID",orderInfo.getOrderNo());
//
////      JSONObject response = hualalaService.doPost("/order/submitordernew", params);
////      System.out.println("response = " + response);
//    }


//  @Test
//  public void chat() {
//
//    String endpoint = "https://api.openai.com/v1/engines/davinci-codex/completions";
//    String apiKey = "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";
//
//
//    // 构建请求
//    HttpRequest request = HttpRequest.get("https://api.openai.com/v1/engines/davinci-codex/completions")
//      .header("Authorization", "Bearer ".concat(apiKey));
//
//    // 发送请求并获取响应
//    HttpResponse response = request.execute();
//
//    // 处理响应结果
//    int statusCode = response.getStatus();
//    String body = response.body();
//    System.out.println("body = " + body);
//  }


//  @Test
//  public void chatGPT() {
//    String abc = "{\"finish_reason\":\"stop\",\"index\":0,\"message\":{\"role\":\"assistant\",\"content\":\"您好！有什么我能为您效劳的吗？\"}}";
//    final JSONObject jsonObject = JSONObject.parseObject(abc);
//    final String message = jsonObject.getString("message");
//    System.out.println("message = " + message);
//    final JSONObject jsonObject1 = JSONObject.parseObject(message);
//    final String content = jsonObject1.getString("content");
//    System.out.println("content = " + content);
//  }


// 自定义参数，这部分是Hutool工具封装的
//  @Test
//  public void initQrConfig() {
//    // 生成指定url对应的二维码到文件，宽和高都是300像素
//    QrCodeUtil.generate("https://hutool.cn/", 300, 300, FileUtil.file("/Users/gxwebsoft/Documents/uploads/qrcode.jpg"));
//  }


  @Test
  public void allIdCard() {
//    List<User> users = userService.list(new QueryWrapper<>());
//    System.out.println(users.size());
//    List<Certificate> certificateList = new ArrayList<>();
//    for (User user : users) {
//      Certificate certificate = new Certificate();
//      certificate.setFullName("xxx");
//      certificate.setCertificateCode("XXX");
//      certificate.setCertificateType("idCard");
//      certificate.setExpirationTime(LocalDateTime.now());
//      certificate.setAuthentication(1);
//      certificate.setUserId(user.getUserId());
//      certificate.setTenantId(10053);
//      certificateService.save(certificate);
//    }

  }


  public void setProfile(){
  }
}
