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() {
|
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");
|
} else {
|
String a = String.valueOf(v1);
|
mountainrainService.soleInster(stcd, a);
|
}
|
}
|
|
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;
|
}
|
|
}
|