//package com.ruoyi;
//
//import cn.hutool.core.collection.CollUtil;
//import cn.hutool.core.date.DateTime;
//import cn.hutool.core.date.DateUtil;
//import cn.hutool.core.util.NumberUtil;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.ruoyi.ucp.entity.*;
//import com.ruoyi.ucp.feign.AdapterApi;
//import com.ruoyi.ucp.service.ITurbineInfoDayService;
//import com.ruoyi.ucp.util.CalcCache;
//import org.junit.runner.RunWith;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.test.context.junit4.SpringRunner;
//
//import javax.annotation.Resource;
//import java.util.*;
//import java.util.concurrent.ConcurrentHashMap;
//import java.util.concurrent.atomic.AtomicReference;
//import java.util.function.Function;
//import java.util.stream.Collectors;
//
///**
// * Author: malijun
// * Data  : 2024: 07: 03
// **/
//@SpringBootTest
//@RunWith(SpringRunner.class)
//public class Test {
//
//    @Resource
//    private AdapterApi adapter;
//    @Resource
//    private JavaFunctionJobHandler javaFunctionJobHandler;
//    @Resource
//    private ITurbineInfoDayService turbineInfoDayService;
//
//
//    @org.junit.Test
//    public void test() {
//        javaFunctionJobHandler.cutInWindSpeed();
//        javaFunctionJobHandler.calcGlqxnh_edfs();
//    }
//
//    //平均温度
//    @org.junit.Test
//    public void ambientTemperature() {
//        //date当天零点
//        DateTime timeNow00 = DateUtil.beginOfDay(new Date());
//        //date昨天零点
//        DateTime timeBegin00 = DateUtil.offsetDay(timeNow00, -1);
//        //上个月
//        DateTime timeBegin2 = DateUtil.offsetMonth(timeBegin00, -1);
//        //上个月第一天
//        DateTime timeBegin1 = DateUtil.beginOfMonth(timeBegin2);
//        //上个月最后一天
//        DateTime timeEnd2 = DateUtil.endOfMonth(timeBegin2);
//        //上个月天数
//        int days = (int) DateUtil.betweenDay(timeBegin1, timeEnd2, false);
//        //遍历天数
//        for (int i = 1; i <= days; i++) {
//            DateTime timeNow = DateUtil.offsetDay(timeBegin1, i);
//            DateTime timeBegin = DateUtil.offsetDay(timeBegin1, i - 1);
//
//
//            //所有风机的温度
//            QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
//            queryWrapper.eq("uniform_code", "AI072");
//
//            List<PointInfo> pointInfos = javaFunctionJobHandler.getEntity("AI072", "turbine");
//
//            //插入集合
//            List<TurbineInfoDay> interest = new ArrayList<>();
//            //更新集合
//            List<TurbineInfoDay> update = new ArrayList<>();
//
//
//            //遍历pointInfos
//            for (PointInfo turbine : pointInfos) {
//                List<PointData> pointDatas = adapter.getHistorySnap(javaFunctionJobHandler.goldenUri(), turbine.getPointKey(), timeBegin.getTime(), timeNow.getTime(), 10);
//                //遍历pointDatas,取出数据算平均值
//                double avgCutInWindSpeed = 0;
//                for (PointData pointData : pointDatas) {
//                    avgCutInWindSpeed += pointData.getValue();
//                }
//                avgCutInWindSpeed /= pointDatas.size();
//
//                //存入数据库
//                String turbineId = turbine.getTurbineId();
//                Date jdkDate = timeBegin.toJdkDate();
//                System.out.println(turbineId + " " + jdkDate);
//                QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
//                turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
//                turbineInfoDayQueryWrapper.eq("record_date", timeBegin.toJdkDate());
//                TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
//                System.out.println(one);
//                if (one == null) {
//                    TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
//                    turbineInfoDay.setTurbineId(turbine.getTurbineId());
//                    turbineInfoDay.setRecordDate(timeBegin.toJdkDate());
//                    turbineInfoDay.setHjwd(avgCutInWindSpeed);
//                    System.out.println(turbineInfoDay);
//                    interest.add(turbineInfoDay);
////                turbineInfoDayService.save(turbineInfoDay);
//                } else {
//                    one.setHjwd(avgCutInWindSpeed);
//                    System.out.println(one);
//                    update.add(one);
////                turbineInfoDayService.updateById(one);
//                }
//
//            }
////        //批量插入
////        turbineInfoDayService.saveBatch(interest);
////        //批量更新
////        turbineInfoDayService.updateBatchById(update);
////        //批量插入或更新
//        turbineInfoDayService.saveOrUpdateBatch(interest);
//        turbineInfoDayService.saveOrUpdateBatch(update);
//        }
//
//    }
//
//
//    @org.junit.Test
//    public void test1() {
//        Date date = DateUtil.date().toJdkDate();
////        javaFunctionJobHandler.writeReportPool(date);
////        javaFunctionJobHandler.writeReportPoolProject(date);
//        javaFunctionJobHandler.writeReportPoolPjfs(date);
//
//    }
//
//    @org.junit.Test
//    public void test2() {
//        Date date = DateUtil.date().toJdkDate();
////        javaFunctionJobHandler.gongsizhibiao(date);
//        javaFunctionJobHandler.writeReportPoolLLFDL(date);
//
//    }
//
//
//}
//
