110 lines
4.5 KiB
Java
110 lines
4.5 KiB
Java
|
|
package com.gunshi.project.ss.service;
|
|||
|
|
|
|||
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
|
|
import com.gunshi.project.ss.mapper.StPptnRDMapper;
|
|||
|
|
import com.gunshi.project.ss.model.StPptnRD;
|
|||
|
|
import lombok.extern.slf4j.Slf4j;
|
|||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|||
|
|
import org.springframework.stereotype.Service;
|
|||
|
|
import org.springframework.transaction.annotation.Transactional;
|
|||
|
|
|
|||
|
|
import java.math.BigDecimal;
|
|||
|
|
import java.text.ParseException;
|
|||
|
|
import java.text.SimpleDateFormat;
|
|||
|
|
import java.util.ArrayList;
|
|||
|
|
import java.util.Calendar;
|
|||
|
|
import java.util.Date;
|
|||
|
|
import java.util.List;
|
|||
|
|
import java.util.Map;
|
|||
|
|
import java.util.stream.Collectors;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 描述:
|
|||
|
|
* author: xusan
|
|||
|
|
* date: 2024-07-08 17:30:38
|
|||
|
|
*/
|
|||
|
|
@Service
|
|||
|
|
@Slf4j
|
|||
|
|
@Transactional(rollbackFor = Exception.class)
|
|||
|
|
public class StPptnRDService extends ServiceImpl<StPptnRDMapper, StPptnRD>
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|||
|
|
|
|||
|
|
@Autowired
|
|||
|
|
private StPptnRService stPptnRService;
|
|||
|
|
|
|||
|
|
public List<StPptnRD> getStcdLastPptnDayData() {
|
|||
|
|
return baseMapper.getStcdLastPptnDayData();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
public void reorganizeStPptnRD(List<String> stcdList, String startDateStr) {
|
|||
|
|
List<StPptnRD> dList = new ArrayList<>();
|
|||
|
|
try {
|
|||
|
|
for (String stcd : stcdList) {
|
|||
|
|
List<Map<String, Object>> pptnRDataList = stPptnRService.getPptnRDataList(stcd, startDateStr);
|
|||
|
|
Map<String, Object> pptnrMap = pptnRDataList.stream().collect(Collectors.toMap(map -> (String) map.get("tm"), map -> map.get("drp")));
|
|||
|
|
for (int i = pptnRDataList.size() - 1; i >= 0; i--) {
|
|||
|
|
Map<String, Object> stringObjectMap = pptnRDataList.get(i);
|
|||
|
|
String tm = stringObjectMap.get("tm").toString();
|
|||
|
|
Date nowTm = sdf.parse(tm);
|
|||
|
|
String drp = stringObjectMap.get("drp").toString();
|
|||
|
|
StPptnRD stPptnRD = new StPptnRD();
|
|||
|
|
stPptnRD.setStcd(stcd);
|
|||
|
|
stPptnRD.setTm(nowTm);
|
|||
|
|
stPptnRD.setDrp(new BigDecimal(drp));
|
|||
|
|
stPptnRD.setYear(Integer.parseInt(tm.substring(0, 4)));
|
|||
|
|
Calendar calendar = Calendar.getInstance();
|
|||
|
|
// 当前时间往前推一天,查看是否是降雨
|
|||
|
|
calendar.setTime(nowTm);
|
|||
|
|
calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|||
|
|
// 如果昨天存在数据
|
|||
|
|
String lastTm = sdf.format(calendar.getTime());
|
|||
|
|
if (pptnrMap.containsKey(lastTm)) {
|
|||
|
|
String lastDrp = pptnrMap.get(lastTm).toString();
|
|||
|
|
String lastDayIsdrp = BigDecimal.ZERO.compareTo(new BigDecimal(lastDrp)) == 0 ? "0" : "1";
|
|||
|
|
stPptnRD.setLastDayIsdrp(lastDayIsdrp);
|
|||
|
|
// 已经往前推过一天了,从1开始
|
|||
|
|
int j = 1;
|
|||
|
|
Boolean isContinue = true;
|
|||
|
|
// 一直往前推
|
|||
|
|
while (isContinue){
|
|||
|
|
calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|||
|
|
String lastContinueTm = sdf.format(calendar.getTime());
|
|||
|
|
if(!pptnrMap.containsKey(lastContinueTm)){
|
|||
|
|
isContinue = false;
|
|||
|
|
} else {
|
|||
|
|
String beforeDrp = pptnrMap.get(lastContinueTm).toString();
|
|||
|
|
if (("0".equals(lastDayIsdrp) && BigDecimal.ZERO.compareTo(new BigDecimal(beforeDrp)) == 0) || ("1".equals(lastDayIsdrp) && BigDecimal.ZERO.compareTo(new BigDecimal(beforeDrp)) != 0)) {
|
|||
|
|
j++;
|
|||
|
|
} else {
|
|||
|
|
isContinue = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
stPptnRD.setIsdrpCount(j);
|
|||
|
|
} else {
|
|||
|
|
stPptnRD.setLastDayIsdrp("2");
|
|||
|
|
stPptnRD.setIsdrpCount(0);
|
|||
|
|
}
|
|||
|
|
dList.add(stPptnRD);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} catch (ParseException e) {
|
|||
|
|
throw new RuntimeException(e);
|
|||
|
|
}
|
|||
|
|
saveBatch(dList);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public StPptnRD getMaxData(String stcd) {
|
|||
|
|
return baseMapper.getMaxData(stcd);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public List<StPptnRD> reorganizePptnRDData(String stcd, StPptnRD maxData) {
|
|||
|
|
return baseMapper.reorganizePptnRDData(stcd, maxData);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|