|
@@ -1,5 +1,7 @@
|
|
package org.springblade.business.service.impl;
|
|
package org.springblade.business.service.impl;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -11,6 +13,7 @@ import org.springblade.business.service.WeatherInfoService;
|
|
//import org.springframework.scheduling.annotation.Scheduled;
|
|
//import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.manager.entity.ProjectContractArea;
|
|
import org.springblade.manager.entity.ProjectContractArea;
|
|
|
|
+import org.springblade.manager.entity.ProjectInfo;
|
|
import org.springblade.manager.feign.ProjectClient;
|
|
import org.springblade.manager.feign.ProjectClient;
|
|
import org.springblade.manager.feign.ProjectContractAreaClient;
|
|
import org.springblade.manager.feign.ProjectContractAreaClient;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
@@ -18,6 +21,10 @@ import org.springframework.stereotype.Service;
|
|
import org.springblade.core.mp.support.Condition;
|
|
import org.springblade.core.mp.support.Condition;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.time.Duration;
|
|
|
|
+import java.time.Instant;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.ZoneId;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -159,6 +166,57 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ //遍历项目,对比项目的所有合同段天气日期和项目计划开工日期
|
|
|
|
+ Set<String> keySet = map.keySet();
|
|
|
|
+ for (String key : keySet) {
|
|
|
|
+ List<ProjectContractArea> projectContractAreas = map.get(key);
|
|
|
|
+ for (ProjectContractArea projectContractArea : projectContractAreas) {
|
|
|
|
+ //根据合同区域id,找到合同最早的天气日期
|
|
|
|
+ WeatherInfo weatherInfo = baseMapper.selectOne(new LambdaQueryWrapper<WeatherInfo>()
|
|
|
|
+ .eq(WeatherInfo::getContractAreaId, projectContractArea.getId())
|
|
|
|
+ .orderByAsc(WeatherInfo::getRecordTime)
|
|
|
|
+ .last("limit 1"));
|
|
|
|
+ if (weatherInfo == null){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ Date recordTime = weatherInfo.getRecordTime();
|
|
|
|
+ if (new Date().compareTo(recordTime) == -1){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ LocalDateTime t = LocalDateTime.ofInstant(recordTime.toInstant(), ZoneId.systemDefault());
|
|
|
|
+ LocalDateTime ContractTime = LocalDateTime.of(t.getYear(),t.getMonthValue(),t.getDayOfMonth(),0,0,0);
|
|
|
|
+ //获取项目计划开工日期,和合同段天气日期对比
|
|
|
|
+ ProjectInfo projectInfo = projectClient.getById(key);
|
|
|
|
+ //有些项目没有计划开工日期
|
|
|
|
+ if (projectInfo == null || projectInfo.getPlanStartTime() == null){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ LocalDateTime t2 = projectInfo.getPlanStartTime();
|
|
|
|
+ LocalDateTime plainTime = LocalDateTime.of(t2.getYear(),t2.getMonthValue(),t2.getDayOfMonth(),0,0,0);
|
|
|
|
+ Duration duration = Duration.between(plainTime, ContractTime);
|
|
|
|
+ if (duration.toDays() > 0){
|
|
|
|
+ List<WeatherInfo> list = new ArrayList<>();
|
|
|
|
+ while (Duration.between(plainTime,ContractTime).toDays() != 0){
|
|
|
|
+ //获取天气信息(百度天气)
|
|
|
|
+ Map<String,String> weatherMap = BaiduApiUtil.getTodayWeather(projectContractArea.getCity_code());
|
|
|
|
+ if(weatherMap != null){
|
|
|
|
+ //计算平均气温
|
|
|
|
+ BigDecimal aver = (new BigDecimal(weatherMap.get("high")).add(new BigDecimal(weatherMap.get("low")))).divide(new BigDecimal("2"), 1, BigDecimal.ROUND_HALF_UP);
|
|
|
|
+ WeatherInfo newWeather = new WeatherInfo(String.valueOf(projectContractArea.getId()), weatherMap.get("weather"), aver.toString(), weatherMap.get("high"), weatherMap.get("low"), weatherMap.get("windLevel"));
|
|
|
|
+ newWeather.setRecordTime(Date.from( plainTime.atZone( ZoneId.systemDefault()).toInstant()));
|
|
|
|
+// this.save(newWeather);
|
|
|
|
+ list.add(newWeather);
|
|
|
|
+ log.info("历史天气已经同步完成!contractAreaId:" + projectContractArea.getId() + ",syncTime:" + plainTime);
|
|
|
|
+ } else {
|
|
|
|
+ log.info("获取历史天气失败!contractAreaId:" + projectContractArea.getId() + ",syncTime:" + plainTime);
|
|
|
|
+ }
|
|
|
|
+ plainTime = plainTime.plusDays(1);
|
|
|
|
+ }
|
|
|
|
+ this.saveBatch(list);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|