预警统计接口新增
parent
23c0238a6d
commit
1e0b174c74
|
|
@ -15,6 +15,7 @@ import com.whdc.utils.HttpUtil;
|
|||
import com.whdc.utils.ResultJson;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
|
|
@ -23,10 +24,7 @@ import org.apache.http.HttpStatus;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
|
@ -330,7 +328,6 @@ public class QXWarnController {
|
|||
// List<QXWarningVO> qxWarningList = getLatestTen(data);
|
||||
|
||||
|
||||
|
||||
return ResultJson.ok(warnStatsVO);
|
||||
}
|
||||
|
||||
|
|
@ -764,9 +761,11 @@ public class QXWarnController {
|
|||
|
||||
return warnList;
|
||||
}
|
||||
|
||||
static String zerofill(int number) {
|
||||
return String.valueOf(number).length() > 1 ? String.valueOf(number) : "0" + String.valueOf(number);
|
||||
}
|
||||
|
||||
static String CalendarDayStartToString(Calendar calendarTime) {
|
||||
int year = calendarTime.get(Calendar.YEAR);
|
||||
int month = calendarTime.get(Calendar.MONTH) + 1; //第一个月从0开始,所以得到月份+1
|
||||
|
|
@ -777,6 +776,7 @@ public class QXWarnController {
|
|||
return zerofill(year) + "-" + zerofill(month) + "-" + zerofill(day) + " " +
|
||||
"00" + ":" + "00" + ":" + "00";
|
||||
}
|
||||
|
||||
//统计函数
|
||||
private int getCount2(List<WarningData> data) {
|
||||
int sum = 0;
|
||||
|
|
@ -795,6 +795,7 @@ public class QXWarnController {
|
|||
warnList = warnList.stream().filter(o -> "红色".equals(o.getWarnSignalLevel()) || "橙色".equals(o.getWarnSignalLevel())).collect(Collectors.toList());
|
||||
return warnList.size();
|
||||
}
|
||||
|
||||
static String CalendarDayStartToString2(Calendar calendarTime) {
|
||||
int year = calendarTime.get(Calendar.YEAR);
|
||||
int month = calendarTime.get(Calendar.MONTH) + 1; //第一个月从0开始,所以得到月份+1
|
||||
|
|
@ -805,4 +806,136 @@ public class QXWarnController {
|
|||
return zerofill(year) + "-" + zerofill(month) + "-" + zerofill(day) + " " +
|
||||
"00" + ":" + "08" + ":" + "00";
|
||||
}
|
||||
|
||||
/**
|
||||
* https://shdata.cloudowr.cn/shwarn/msg/totalquery?stm=2024-06-01&etm=2024-06-12
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "预警统计")
|
||||
@GetMapping(value = "/statistics/{stm}/{etm}")
|
||||
public ResultJson<QXWarnStatisticsVo> totalquery(@PathVariable("stm") @ApiParam(name = "stm", value = "开始时间, yyyy-MM-dd") String stmStr,
|
||||
@PathVariable("etm") @ApiParam(name = "etm", value = "结束时间, yyyy-MM-dd") String etmStr) {
|
||||
|
||||
|
||||
LocalDate stm = LocalDate.parse(stmStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
LocalDate etm = LocalDate.parse(etmStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
|
||||
QXWarnStatisticsVo vo = new QXWarnStatisticsVo();
|
||||
|
||||
String str = HttpUtil.getBySetCookie("https://shdata.cloudowr.cn/shwarn/msg/totalquery?stm=" + stm + "&etm=" + etm,
|
||||
"userobj=%7B%22_id%22%3A%2260a7da8809d9cfa5622920a6%22%2C%22name%22%3A%22%E9%B2%A7%E7%9F%B3%E5%80%BC%E7%8F%AD%E4%B8%93%E7%94%A8%22%2C%22phone%22%3A%2218888888888%22%2C%22utype%22%3A0%2C%22dept%22%3A%22%E9%B2%A7%E7%9F%B3%22%2C%22tm%22%3A%222024-03-23T01%3A54%3A46.225Z%22%2C%22token%22%3A%226726a6d2e96b902d23381a19dcdc18cb%22%2C%22ctm%22%3A%222021-05-21T16%3A06%3A32.707Z%22%2C%22chkc%22%3Afalse%2C%22ywjk%22%3Afalse%2C%22yywh%22%3Afalse%7D; token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3aXRoRXhwaXJlc0F0IjoxNzE4MzMzNTYzOTE3LCJleHAiOjE3MTgzMzM1NjMsInVzZXJuYW1lIjoiYWRtaW4ifQ.-leem8iPu0zzPuGtRTZ-Lp5m_mLBzX1UzJfLbDBSpjc");
|
||||
JSONObject json = JSON.parseObject(str);
|
||||
if (json != null && json.getInteger("ok") == 1) {
|
||||
TotalQueryVo data = json.getJSONObject("results").toJavaObject(TotalQueryVo.class);
|
||||
StringBuilder warnStr = new StringBuilder();
|
||||
warnStr.append(stm.getYear()).append("年").append(stm.getMonthValue()).append("月").append(stm.getDayOfMonth()).append("日至")
|
||||
.append(etm.getYear()).append("年").append(etm.getMonthValue()).append("月").append(etm.getDayOfMonth()).append("日,湖北省");
|
||||
|
||||
List<TotalQueryVo.Yjtj> yjtj = data.getYjtj();
|
||||
TotalQueryVo.Summary summary = data.getSummary();
|
||||
|
||||
|
||||
long sum = yjtj.stream().mapToLong(TotalQueryVo.Yjtj::getCount).sum();
|
||||
long wbSum = yjtj.stream().mapToLong(TotalQueryVo.Yjtj::getWbcount).sum();
|
||||
|
||||
List<TotalQueryVo.Page> page = data.getPage();
|
||||
long yjrs = page.stream().mapToLong(TotalQueryVo.Page::getYjrs).sum();
|
||||
long rs = page.stream().mapToLong(TotalQueryVo.Page::getRs).sum();
|
||||
|
||||
long dxzs = page.stream().mapToLong(TotalQueryVo.Page::getYj).sum()
|
||||
+ page.stream().mapToLong(TotalQueryVo.Page::getZdy).sum()
|
||||
+ page.stream().mapToLong(TotalQueryVo.Page::getQt).sum()
|
||||
+ page.stream().mapToLong(TotalQueryVo.Page::getGb).sum();
|
||||
|
||||
List<TotalQueryVo.Outlist> outlist = data.getSsdxtj().getOutlist();
|
||||
|
||||
long szdxls = outlist.stream().filter(o -> !"420000000000".equals(o.getAdcd())).mapToLong(TotalQueryVo.Outlist::getSum).sum();
|
||||
long szdxlsAll = outlist.stream().mapToLong(TotalQueryVo.Outlist::getSum).sum();
|
||||
|
||||
|
||||
TotalQueryVo.Syw syw = data.getSyw();
|
||||
TotalQueryVo.Sgxpt sgxpt = data.getSgxpt();
|
||||
|
||||
warnStr.append(yjtj.size()).append("个县共产生山洪预警").append(sum).append("次,")
|
||||
.append("对外发布预警").append(wbSum).append("次,")
|
||||
.append("共发送山洪预警短信").append(summary.getYj()).append("条,")
|
||||
.append("涉及防汛责任人").append(yjrs).append("人次,")
|
||||
.append("另发送防洪警示短信").append(dxzs - summary.getYj()).append("条,")
|
||||
.append("涉及防汛责任人").append(rs - yjrs).append("人次;")
|
||||
.append("市级平台共发送防洪警示短信").append(szdxls).append("条,")
|
||||
.append("涉及防汛责任人").append(szdxls).append("人次;")
|
||||
.append("省级平台共发送防洪警示、运维提示短信").append(syw.getSum() + sgxpt.getCNT() + szdxlsAll).append("条,")
|
||||
.append("涉及防汛责任人").append(syw.getRs() + sgxpt.getRS() + szdxlsAll).append("人次。")
|
||||
;
|
||||
vo.setShWarnStr(warnStr.toString());
|
||||
}
|
||||
|
||||
List<QXWarning> list = service.getWarnAndMsg(stm.toString(), etm.toString());
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
StringBuilder warnStr = new StringBuilder();
|
||||
|
||||
warnStr.append(stm.getYear()).append("年").append(stm.getMonthValue()).append("月").append(stm.getDayOfMonth()).append("日至")
|
||||
.append(etm.getYear()).append("年").append(etm.getMonthValue()).append("月").append(etm.getDayOfMonth()).append("日,");
|
||||
|
||||
Map<String, List<QXWarning>> map = list.stream()
|
||||
.collect(Collectors.groupingBy(QXWarning::getWarnSignalLevel));
|
||||
List<QXWarning> orange = map.get("橙色");
|
||||
List<QXWarning> red = map.get("红色");
|
||||
|
||||
if (CollectionUtils.isNotEmpty(orange) && CollectionUtils.isNotEmpty(red)) {
|
||||
warnStr.append("我省共产生橙色气象预警").append(orange.size()).append("次,电话叫应");
|
||||
Map<String, List<QXWarning>> orangeList = orange.stream().collect(Collectors.groupingBy(QXWarning::getCtnm, Collectors.toList()));
|
||||
|
||||
orangeList.forEach((k, v) -> {
|
||||
warnStr.append(getCnnmStr(v));
|
||||
});
|
||||
warnStr.setCharAt(warnStr.length() -1 , '。');
|
||||
|
||||
warnStr.append("红色气象预警").append(red.size()).append("次,电话叫应");
|
||||
Map<String, List<QXWarning>> redList = red.stream().collect(Collectors.groupingBy(QXWarning::getCtnm, Collectors.toList()));
|
||||
|
||||
redList.forEach((k, v) -> {
|
||||
warnStr.append(getCnnmStr(v));
|
||||
});
|
||||
warnStr.setCharAt(warnStr.length() -1 , '。');
|
||||
|
||||
} else if (CollectionUtils.isNotEmpty(orange) && CollectionUtils.isEmpty(red)) {
|
||||
warnStr.append("我省共产生橙色气象预警").append(orange.size()).append("次,电话叫应");
|
||||
Map<String, List<QXWarning>> orangeList = orange.stream().collect(Collectors.groupingBy(QXWarning::getCtnm, Collectors.toList()));
|
||||
|
||||
orangeList.forEach((k, v) -> {
|
||||
warnStr.append(getCnnmStr(v));
|
||||
});
|
||||
warnStr.setCharAt(warnStr.length() -1 , '。');
|
||||
|
||||
} else if (CollectionUtils.isNotEmpty(red) && CollectionUtils.isEmpty(orange)) {
|
||||
warnStr.append("我省共产生红色气象预警").append(red.size()).append("次,电话叫应");
|
||||
Map<String, List<QXWarning>> redList = red.stream().collect(Collectors.groupingBy(QXWarning::getCtnm, Collectors.toList()));
|
||||
|
||||
redList.forEach((k, v) -> {
|
||||
warnStr.append(getCnnmStr(v));
|
||||
});
|
||||
}
|
||||
|
||||
vo.setByWarnStr(warnStr.toString());
|
||||
}
|
||||
|
||||
return ResultJson.ok(vo);
|
||||
|
||||
}
|
||||
|
||||
private StringBuilder getCnnmStr(List<QXWarning> list) {
|
||||
List<String> lists = list.stream().map(QXWarning::getCnnm).distinct().collect(Collectors.toList());
|
||||
|
||||
HashSet<String> cnnmSet = Sets.newHashSet();
|
||||
for (String str : lists) {
|
||||
String[] split = str.split(",");
|
||||
cnnmSet.addAll(Arrays.asList(split));
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
cnnmSet.forEach(s -> builder.append(s).append("、"));
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,4 +8,6 @@ import java.util.List;
|
|||
|
||||
public interface QXWarningMapper extends BaseMapper<QXWarning> {
|
||||
List<QXWarning> find(@Param("dto")QXWarning dto);
|
||||
|
||||
List<QXWarning> getWarnAndMsg(@Param("stm") String stm,@Param("etm") String etm);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.whdc.model.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Created by XuSan on 2024/6/13.
|
||||
*
|
||||
* @author XuSan
|
||||
* @version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class QXWarnStatisticsVo {
|
||||
|
||||
@ApiModelProperty(value = "山洪预警叫应")
|
||||
private String ShWarnStr;
|
||||
|
||||
@ApiModelProperty(value = "暴雨预警叫应")
|
||||
private String ByWarnStr;
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
package com.whdc.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Created by XuSan on 2024/6/13.
|
||||
*
|
||||
* @author XuSan
|
||||
* @version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class TotalQueryVo {
|
||||
|
||||
private List<Page> page;
|
||||
private Sgxpt sgxpt;
|
||||
private Ssdxtj ssdxtj;
|
||||
private Summary summary;
|
||||
private Syw syw;
|
||||
private List<Yjtj> yjtj;
|
||||
|
||||
@Data
|
||||
public static class Syw {
|
||||
|
||||
private Long rs;
|
||||
private Long sum;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Outlist {
|
||||
|
||||
private String adcd;
|
||||
private String adnm;
|
||||
private Long sum;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
public static class Summary {
|
||||
|
||||
private Long gb;
|
||||
private Long qt;
|
||||
private Long rs;
|
||||
private Long wbcount;
|
||||
private Long yj;
|
||||
private Long zdy;
|
||||
private Long zs;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Sgxpt {
|
||||
|
||||
private Long cNT;
|
||||
private Long rS;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Page {
|
||||
|
||||
private _id _id;
|
||||
private Long gb;
|
||||
private Long qt;
|
||||
private Long rs;
|
||||
private Long wbcount;
|
||||
private Long yj;
|
||||
private Long yjrs;
|
||||
private Long zdy;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class _id {
|
||||
|
||||
private String adcd;
|
||||
private String adnm;
|
||||
|
||||
}
|
||||
@Data
|
||||
public static class Ssdxtj {
|
||||
|
||||
private Long allcnt;
|
||||
private List<Outlist> outlist;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Yjtj {
|
||||
|
||||
private _id _id;
|
||||
private Long count;
|
||||
private Long sdcount;
|
||||
private Long wbcount;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -7,4 +7,5 @@ import java.util.List;
|
|||
|
||||
public interface IQXWarningService extends IService<QXWarning> {
|
||||
List<QXWarning> find(QXWarning dto);
|
||||
List<QXWarning> getWarnAndMsg(String stm,String etm);
|
||||
}
|
||||
|
|
@ -16,4 +16,9 @@ public class QXWarningServiceImpl extends ServiceImpl<QXWarningMapper, QXWarnin
|
|||
public List<QXWarning> find(QXWarning dto) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QXWarning> getWarnAndMsg(String stm, String etm) {
|
||||
return getBaseMapper().getWarnAndMsg(stm,etm);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,6 +136,85 @@ public class HttpUtil {
|
|||
}
|
||||
|
||||
|
||||
public static String getBySetCookie(String _url,String cookie) {
|
||||
InputStream is = null;
|
||||
BufferedReader br = null;
|
||||
HttpURLConnection conn = null;
|
||||
String jstr = null;
|
||||
try {
|
||||
|
||||
log.info("请求地址: " + _url);
|
||||
|
||||
URL url = new URL(_url);
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
|
||||
if (StringUtils.isNotBlank(cookie)){
|
||||
// 设置cookie
|
||||
conn.setRequestProperty("Cookie", cookie);
|
||||
}
|
||||
|
||||
conn.setConnectTimeout(5000);
|
||||
conn.setReadTimeout(5000);
|
||||
conn.connect();
|
||||
if (conn.getResponseCode() == 200) {
|
||||
is = conn.getInputStream();
|
||||
if (is != null) {
|
||||
br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String tmp = "";
|
||||
while ((tmp = br.readLine()) != null) {
|
||||
sb.append(tmp);
|
||||
}
|
||||
jstr = sb.toString();
|
||||
|
||||
log.info("响应参数: " + jstr);
|
||||
|
||||
jstr = jsonFormat(jstr);
|
||||
|
||||
|
||||
return jstr;
|
||||
}
|
||||
} else if (conn.getResponseCode() == 500) {
|
||||
is = conn.getErrorStream();
|
||||
if (is != null) {
|
||||
br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String tmp = "";
|
||||
while ((tmp = br.readLine()) != null) {
|
||||
sb.append(tmp);
|
||||
}
|
||||
jstr = sb.toString();
|
||||
if (jstr.contains("Token失效,请重新登录")) { // 第三方token失效处理
|
||||
return "{\"code\": 301,\"extMessage\":\"Token失效,请重新登录\"}";
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.disconnect();
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static String get(String _url, String authorization) {
|
||||
InputStream is = null;
|
||||
BufferedReader br = null;
|
||||
|
|
|
|||
|
|
@ -4,4 +4,17 @@
|
|||
<select id="find" resultType="com.whdc.model.entity.QXWarning">
|
||||
|
||||
</select>
|
||||
<select id="getWarnAndMsg" resultType="com.whdc.model.entity.QXWarning">
|
||||
SELECT
|
||||
Q.WARN_SIGNAL_LEVEL,
|
||||
Q.CTNM,
|
||||
Q.CNNM
|
||||
FROM
|
||||
FXKH_TXL.WARNMSG_FEEDBACK WF
|
||||
LEFT JOIN FXKH_TXL.QXWARNING Q ON WF.WARNID = Q.WARNID
|
||||
WHERE
|
||||
WF.HANDLE_TIME BETWEEN #{stm} AND #{etm}
|
||||
AND Q.WARN_SIGNAL_LEVEL IS NOT NULL
|
||||
AND Q.CNNM IS NOT NULL
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue