增加整编日降水接口,统计前面降雨天数
parent
08d9a806d3
commit
c5654346ab
|
|
@ -15,11 +15,11 @@ import org.springframework.web.bind.annotation.*;
|
|||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
/**
|
||||
* 描述:
|
||||
* 描述: 降水量天表
|
||||
* author: xusan
|
||||
* date: 2024-07-08 17:40:37
|
||||
*/
|
||||
@Tag(name = "")
|
||||
@Tag(name = "降水量天表")
|
||||
@RestController
|
||||
@RequestMapping(value="/stPptnRD")
|
||||
public class StPptnRDController {
|
||||
|
|
@ -54,10 +54,15 @@ public class StPptnRDController {
|
|||
return R.ok(service.lambdaQuery().list());
|
||||
}
|
||||
|
||||
// @Operation(summary = "分页")
|
||||
// @PostMapping("/page")
|
||||
@Operation(summary = "分页")
|
||||
@PostMapping("/page")
|
||||
public R<List<StPptnRD>> page() {
|
||||
return R.ok(service.page(null,null));
|
||||
}
|
||||
|
||||
}
|
||||
@Operation(summary = "整编降雨历史降雨情况")
|
||||
@PostMapping("/reorganizeStPptnRD")
|
||||
public void reorganizeStPptnRD(@Schema(name = "stcdList", description = "站码列表") @RequestParam("stcdList") List<String> stcdList, @Schema(name = "startDateStr", description = "开始时间") @RequestParam("startDateStr") String startDateStr) {
|
||||
service.reorganizeStPptnRD(stcdList, startDateStr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
|
||||
import com.gunshi.core.dateformat.DateFormatString;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
|
@ -35,6 +36,7 @@ public class StPptnRD implements Serializable {
|
|||
/**
|
||||
* 测站编码
|
||||
*/
|
||||
@MppMultiId
|
||||
@TableId(value="stcd", type= IdType.AUTO)
|
||||
@Schema(description="测站编码")
|
||||
@Size(max = 20,message = "测站编码最大长度要小于 20")
|
||||
|
|
@ -44,6 +46,7 @@ public class StPptnRD implements Serializable {
|
|||
/**
|
||||
* 时间
|
||||
*/
|
||||
@MppMultiId
|
||||
@TableField(value="tm")
|
||||
@Schema(description="时间")
|
||||
// @Size(max = 0,message = "时间最大长度要小于 0")
|
||||
|
|
@ -62,11 +65,26 @@ public class StPptnRD implements Serializable {
|
|||
/**
|
||||
* year
|
||||
*/
|
||||
@MppMultiId
|
||||
@TableField(value="year")
|
||||
@Schema(description="year")
|
||||
@NotNull(message = "year不能为空")
|
||||
private Integer year;
|
||||
|
||||
/**
|
||||
* 前一天是否降雨(0无雨 1有降雨)
|
||||
*/
|
||||
@TableField(value="last_day_isdrp")
|
||||
@Schema(description="last_day_isdrp")
|
||||
private String lastDayIsdrp;
|
||||
|
||||
/**
|
||||
* 之前有无雨的连续天数
|
||||
*/
|
||||
@TableField(value="isdrp_count")
|
||||
@Schema(description="isdrp_count")
|
||||
private Integer isdrpCount;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Date stm;// 同步的数据的开始时间
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,19 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
import com.gunshi.project.xyt.mapper.StPptnRDMapper;
|
||||
import com.gunshi.project.xyt.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;
|
||||
|
||||
/**
|
||||
* 描述:
|
||||
|
|
@ -20,9 +29,73 @@ import java.util.List;
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -226,8 +226,8 @@ public class DataTask {
|
|||
* @auther: cxw
|
||||
* @date: 2024-07-11, 周四, 14:21:35
|
||||
*/
|
||||
@Async
|
||||
@Scheduled(cron = "0 30 8 * * ?")
|
||||
// @Async
|
||||
// @Scheduled(cron = "0 30 8 * * ?")
|
||||
public void getSkYqDayData() {
|
||||
Date now = new Date();
|
||||
System.out.println("雨情按天定时任务,执行时间:" + sdf.format(now));
|
||||
|
|
|
|||
Loading…
Reference in New Issue