package com.ho.business;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.ho.business.entity.DeviceTypeCol;
import com.ho.business.entity.VirtualDeviceCol;
import com.ho.business.mapper.VirtualDeviceColMapper;
import com.ho.business.service.DeviceTypeColService;
import com.ho.business.service.ReportFormService;
import com.ho.common.tools.constant.CommonConstant;
import com.ho.common.tools.service.RedisService;
import com.ho.common.tools.util.BigDecimalUtil;
import com.ho.common.tools.vo.req.StatisticsCurve;
import ma.glasnost.orika.MapperFacade;
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.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description 测试报表下载
 * Author yule
 * Date 2023/2/27 14:26
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class TestReport {

    @Autowired
    ReportFormService reportFormService;

    @Autowired
    BigDecimalUtil bigDecimalUtil;

    @Autowired
    RedisService redisService;

    @Autowired
    DeviceTypeColService deviceTypeColService;

    @Autowired
    VirtualDeviceColMapper virtualDeviceColMapper;

    @Autowired
    private MapperFacade mapperFacade;

    @Test
    public void getHash(){
        String key = "fan3";
    }

    //@Test
    public void testString(){
        String processTimeStr = "2023-03-01 00:00:00";
        Date processTime = DateUtil.parse(processTimeStr,CommonConstant.DATE);
        String strdate = null;
        if(processTimeStr.endsWith(CommonConstant.START_SUFFIX_TIMESTAMP)){
            strdate = DateUtil.format(DateUtil.offsetDay(processTime, -1), CommonConstant.DATE_YMD);
        }else {
            strdate = DateUtil.format(processTime, CommonConstant.DATE_YMD);
        }
        System.out.println();
    }

    public static void main(String[] args) {
        TestReport testReport = new TestReport();
        testReport.testString();
    }

    @Test
    public void testRang(){
        Date date = new Date();
        DateTime dateTime = DateUtil.offsetDay(date, -6);
        List<DateTime> dateTimes = DateUtil.rangeToList(dateTime, date, DateField.DAY_OF_MONTH);

        System.out.println();
    }

    @Test
    public void test(){
        int num =16;
        for (int i = 0; i < 16; i++) {
            StringBuffer str = new StringBuffer();
            str.append("INSERT INTO `user_center_db`.`sys_sub_dict` (`type`, `label`, `value`, `sort`, `desc`, `create_time`, `update_time`, `deleted`) VALUES ('virtualMappingType', '单体温度").append(i+1)
                    .append("', 'cSingleT").append(i+1).append("', ").append(num+i+1).append(", '', now(), now(), 1);");
            System.out.println(str);
        }
        System.out.println();
    }

    @Test
    public void setVirtualDevice(){
        List<DeviceTypeCol> list = deviceTypeColService.selectByDeviceType("emu_349",null);
        list = list.stream().filter(s->{
           return CommonConstant.TWO.equals(s.getSensType());
        }).collect(Collectors.toList());
        List<VirtualDeviceCol> result = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if (i<35){
                VirtualDeviceCol virtualDeviceCol = new VirtualDeviceCol();
                virtualDeviceCol.setStationId(349);
                virtualDeviceCol.setSrcId(-21);
                virtualDeviceCol.setDeviceColId(list.get(i).getId());
                virtualDeviceCol.setCol(list.get(i).getCol());
                virtualDeviceCol.setColName(list.get(i).getColName());
                result.add(virtualDeviceCol);
            }
            else if (35 <= i && i <41){
                VirtualDeviceCol virtualDeviceCol = new VirtualDeviceCol();
                virtualDeviceCol.setStationId(349);
                virtualDeviceCol.setSrcId(-22);
                virtualDeviceCol.setDeviceColId(list.get(i).getId());
                virtualDeviceCol.setCol(list.get(i).getCol());
                virtualDeviceCol.setColName(list.get(i).getColName());
                result.add(virtualDeviceCol);
            }
            else if (41 <= i && i <47){
                VirtualDeviceCol virtualDeviceCol = new VirtualDeviceCol();
                virtualDeviceCol.setStationId(349);
                virtualDeviceCol.setSrcId(-23);
                virtualDeviceCol.setDeviceColId(list.get(i).getId());
                virtualDeviceCol.setCol(list.get(i).getCol());
                virtualDeviceCol.setColName(list.get(i).getColName());
                result.add(virtualDeviceCol);
            }
            else {
                VirtualDeviceCol virtualDeviceCol = new VirtualDeviceCol();
                virtualDeviceCol.setStationId(349);
                virtualDeviceCol.setSrcId(-24);
                virtualDeviceCol.setDeviceColId(list.get(i).getId());
                virtualDeviceCol.setCol(list.get(i).getCol());
                virtualDeviceCol.setColName(list.get(i).getColName());
                result.add(virtualDeviceCol);
            }
        }
        System.out.println();
        virtualDeviceColMapper.insertList(result);
    }

    @Test
    public void testCopy(){
        List<StatisticsCurve> list = new ArrayList<>();
        StatisticsCurve curve = new StatisticsCurve();
        curve.setDigital(1d);
        list.add(curve);
        curve = new StatisticsCurve();
        curve.setDigital(2d);
        list.add(curve);
        List<StatisticsCurve> list2 = mapperFacade.mapAsList(list,StatisticsCurve.class);
        list2.get(0).setDigital(3d);
        System.out.println();
    }
}
