package com.ho.business;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.ho.business.entity.Station;
import com.ho.business.service.IncomeMeasurementService;
import com.ho.business.vo.DeviceTransfer;
import com.ho.common.tools.constant.CommonConstant;
import com.ho.common.tools.service.RedisService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author fancl
 * @desc:
 * @date 2023/2/16
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class BusinessTest {

    @Autowired
    RedisService redisService;
    @Autowired
    IncomeMeasurementService incomeMeasurementService;

    //测试加工收益数据到 income_total 表
    @Test
    public void test(){
        DeviceTransfer deviceTransfer = new DeviceTransfer();
        deviceTransfer.setValue(new BigDecimal(100));
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("fan", deviceTransfer);
        redisService.hmset("fan", jsonObject);
    }

    @Test
    public void test2(){
        DeviceTransfer deviceTransfer = new DeviceTransfer();
        //deviceTransfer.setValue(new BigDecimal(100));
        deviceTransfer.setUpdateTime(new Date());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("fan", deviceTransfer);
        redisService.hmset("fan", jsonObject);

    }

    @Test
    public void splitAddr(){
        List<Station> stations = new ArrayList<>();
        Station station1 = new Station();
        Station station2 = new Station();
        Station station3 = new Station();
        Station station4 = new Station();
        Station station5 = new Station();
        Station station6 = new Station();

        station1.setAddress("广西壮族自治区南宁市");
        station2.setAddress("香港特别行政区十点多");
        station3.setAddress("江苏省南京市");
        station4.setAddress("重庆市渝中区");
        station5.setAddress("黑龙江省哈尔滨市");
        station6.setAddress("江苏省无锡市");

        stations.add(station1);
        stations.add(station2);
        stations.add(station3);
        stations.add(station4);
        stations.add(station5);
        stations.add(station6);

        Map<String, List<Station>> collect = stations.stream()
                .collect(Collectors.groupingBy(s -> {
                    return s.getAddress().substring(0,3);
        }));

        System.out.println();
    }

    @Test
    public void date(){
        String dateString = "14:00:00-19:00:00";
        String[] split = dateString.split("-");
        Date date = new Date();
        String format = DateUtil.format(date, CommonConstant.DATE_Hms);
        boolean in = DateUtil.isIn( DateUtil.parse(format,CommonConstant.DATE_Hms),DateUtil.parse(split[0], CommonConstant.DATE_Hms), DateUtil.parse(split[1], CommonConstant.DATE_Hms));
        String number = "-3.5~-5.5";
        String[] split1 = number.split("~");
        double random = Math.random()* (Double.valueOf(split1[1]) - (Double.valueOf(split1[0])) + (Double.valueOf(split1[0])));

        Random random1 = new Random();
        int i = random1.nextInt(6001);
        int j = i - 1001;
        System.out.println();
    }

    @Test
    public void isNotNull(){
        List<Integer> list = new ArrayList<>();
        list.get(list.size()-1);
        System.out.println();
    }
}
