tangzy
2021-10-20 87204491aac135822f96f3fff297ddca400ea8c9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package org.springblade.modules.mountainrain.controller;
 
import org.springblade.core.tool.api.R;
import org.springblade.modules.mountain.service.IMountainService;
import org.springblade.modules.mountainrain.service.IMountainrainService;
import org.springblade.modules.regionWeight.service.IRegionWeightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
 
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
 
@Component
public class ss {
    @Autowired
    private  IRegionWeightService regionWeightService;
 
    @Autowired
    private IMountainrainService mountainrainService;
 
    @Scheduled(cron = "0 0 8 * * ?")
    public R soleval() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dateNow = sdf.format(new Date());
        //mountainrainService.soildel();
        int intervals = 31;
        ArrayList passDaysList = new ArrayList<>();
        for (int i = 0; i < intervals; i++) {
            passDaysList.add(getDays(i, false));
        }
        Collections.sort(passDaysList);
        //String s = mountainrainService.selectCode();
        String s = regionWeightService.selectCode();
        String[] split = s.split(",");
        String strArrays = "";
        for (int i = 0; i < split.length; i++) {
            strArrays += "'" + split[i] + "',";
        }
        String code = strArrays.substring(0, strArrays.length() - 1);
        for (int i = 0; i < split.length; i++) {
            Integer num = 30;
            double v1 = 0;
            String stcd = null;
            for (int j = 0; j < passDaysList.size() - 2; j++) {
                List<Map<String, Object>> map = mountainrainService.selectMtwo(passDaysList.get(j).toString(), passDaysList.get(j + 1).toString(), code);
                if (map.size() == 0 || i > map.size() - 1) {
                    //stcd=split[i];
                    break;
                }
                BigDecimal w = (BigDecimal) map.get(i).get("drp");
                double drp = w.doubleValue();
                stcd = map.get(i).get("STCD").toString();
                //计算湿度
                if (j == 0) {
                    v1 = formatDouble1((num + drp) * 0.85);
                    if (v1 > 60) {
                        v1 = 60;
                    }
                } else {
                    v1 += drp;
                    v1 = formatDouble1(v1 * 0.85);
                    if (v1 > 60) {
                        v1 = 60;
                    }
                }
            }
            if (v1 > 60) {
                mountainrainService.soleInster(stcd, "60",dateNow);
            } else {
                String a = String.valueOf(v1);
                mountainrainService.soleInster(stcd, a,dateNow);
            }
        }
 
        return R.success("成功");
    }
 
    public static double formatDouble1(double d) {
        return (double) Math.round(d * 10) / 10;
    }
 
    private static String getDays(int i, boolean b) {
        Calendar calendar = Calendar.getInstance();
        if (b) {
            calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + i);
        } else {
            calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - i);
        }
        Date today = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 08:00:00");
        String result = format.format(today);
        return result;
    }
 
}