代码提交
parent
a24adf091d
commit
81e3f4bf3e
|
|
@ -49,4 +49,8 @@ alter table "FXKH_TXL"."QXWARNING" modify "PUBLISH_TIME" DATETIME(0);
|
||||||
|
|
||||||
alter table "FXKH_TXL"."QXWARNING" modify "START_TIME" DATETIME(0);
|
alter table "FXKH_TXL"."QXWARNING" modify "START_TIME" DATETIME(0);
|
||||||
|
|
||||||
alter table "FXKH_TXL"."QXWARNING" modify "END_TIME" DATETIME(0);
|
alter table "FXKH_TXL"."QXWARNING" modify "END_TIME" DATETIME(0);
|
||||||
|
|
||||||
|
|
||||||
|
ALTER TABLE FXKH_TXL.QXWARNING
|
||||||
|
ADD CONSTRAINT WARNID UNIQUE (WARNID);
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,13 @@ import com.whdc.utils.DateUtils;
|
||||||
import com.whdc.utils.HttpUtil;
|
import com.whdc.utils.HttpUtil;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.compress.utils.Lists;
|
import org.apache.commons.compress.utils.Lists;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
@ -29,6 +30,8 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.whdc.controller.QXWarnController.QX_TEMP_REDIS_KEY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 李赛
|
* @author 李赛
|
||||||
* @date 2022-07-17 15:33
|
* @date 2022-07-17 15:33
|
||||||
|
|
@ -51,6 +54,10 @@ public class MyPostConstruct {
|
||||||
private IQXWarningService service;
|
private IQXWarningService service;
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, String> stringRedisTemplate;
|
||||||
|
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
@ApiOperation(value = "预警数据同步接口", notes = "预警数据同步接口")
|
@ApiOperation(value = "预警数据同步接口", notes = "预警数据同步接口")
|
||||||
@GetMapping("/syncData")
|
@GetMapping("/syncData")
|
||||||
|
|
@ -115,11 +122,14 @@ public class MyPostConstruct {
|
||||||
qxwarning.setWarnid(warningVO.getWarnid());
|
qxwarning.setWarnid(warningVO.getWarnid());
|
||||||
qxwarning.setCtnm(warningVO.getCtnm());
|
qxwarning.setCtnm(warningVO.getCtnm());
|
||||||
qxwarning.setCnnm(warningVO.getCnnm());
|
qxwarning.setCnnm(warningVO.getCnnm());
|
||||||
|
|
||||||
|
stringRedisTemplate.opsForValue().set(QX_TEMP_REDIS_KEY + qxwarning.getWarnid(),JSON.toJSONString(warningVO));
|
||||||
adds.add(qxwarning);
|
adds.add(qxwarning);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(adds)) {
|
if (CollectionUtils.isNotEmpty(adds)) {
|
||||||
log.info("预警数据同步待添加预警 " + adds.size());
|
log.info("预警数据同步待添加预警 " + adds.size());
|
||||||
if (this.service.saveBatch(adds)) {
|
if (this.service.saveBatch(adds)) {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import org.apache.http.HttpStatus;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
|
@ -35,6 +36,7 @@ import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.whdc.controller.WarningController.THIS_REDIS_KEY;
|
import static com.whdc.controller.WarningController.THIS_REDIS_KEY;
|
||||||
|
import static com.whdc.model.MyConstant.REDIS_KEY;
|
||||||
|
|
||||||
//湖北省防汛抗旱调度系统-气象预警
|
//湖北省防汛抗旱调度系统-气象预警
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|
@ -42,6 +44,10 @@ import static com.whdc.controller.WarningController.THIS_REDIS_KEY;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/qxwarning")
|
@RequestMapping("/qxwarning")
|
||||||
public class QXWarnController {
|
public class QXWarnController {
|
||||||
|
|
||||||
|
public static final String QX_TEMP_REDIS_KEY = REDIS_KEY + "warning:temp:";
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IAddressBookService addressBookService;
|
private IAddressBookService addressBookService;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
@ -53,6 +59,9 @@ public class QXWarnController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IQXWarningService service;
|
private IQXWarningService service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, String> stringRedisTemplate;
|
||||||
|
|
||||||
@Value("${getGroupWarning}")
|
@Value("${getGroupWarning}")
|
||||||
public String getGroupWarning;
|
public String getGroupWarning;
|
||||||
|
|
||||||
|
|
@ -73,17 +82,17 @@ public class QXWarnController {
|
||||||
return ResultJson.ok(save);
|
return ResultJson.ok(save);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Async
|
// @Async
|
||||||
@ApiOperation(value = "预警数据同步接口", notes = "预警数据同步接口")
|
@ApiOperation(value = "预警数据同步接口", notes = "预警数据同步接口")
|
||||||
@PostMapping("/syncData")
|
@PostMapping("/syncData")
|
||||||
// @Scheduled(cron ="0 0/5 * * * ?")
|
// @Scheduled(cron ="0 0/5 * * * ?")
|
||||||
public void syncData( @RequestBody GroupWarningDto dto) {
|
public void syncData(@RequestBody GroupWarningDto dto) {
|
||||||
log.info("预警数据同步开始!!!");
|
log.info("预警数据同步开始!!!");
|
||||||
ApiDto apiDto = new ApiDto();
|
ApiDto apiDto = new ApiDto();
|
||||||
if (StringUtils.isNotBlank(dto.getStartTime())){
|
if (StringUtils.isNotBlank(dto.getStartTime())) {
|
||||||
apiDto.setStartTime(dto.getStartTime());
|
apiDto.setStartTime(dto.getStartTime());
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(dto.getEndTime())){
|
if (StringUtils.isNotBlank(dto.getEndTime())) {
|
||||||
apiDto.setEndTime(dto.getEndTime());
|
apiDto.setEndTime(dto.getEndTime());
|
||||||
}
|
}
|
||||||
apiDto.setFilter(Lists.newArrayList());
|
apiDto.setFilter(Lists.newArrayList());
|
||||||
|
|
@ -144,7 +153,36 @@ public class QXWarnController {
|
||||||
@PostMapping("/getGroupWarning")
|
@PostMapping("/getGroupWarning")
|
||||||
public ResultJson<List<QXWarningVO>> getGroupWarning() {
|
public ResultJson<List<QXWarningVO>> getGroupWarning() {
|
||||||
|
|
||||||
return ResultJson.ok(service.find());
|
Set<String> tempKeys = stringRedisTemplate.keys(QX_TEMP_REDIS_KEY + "*");
|
||||||
|
if (CollectionUtils.isNotEmpty(tempKeys)) {
|
||||||
|
List<QXWarningVO> data = Lists.newArrayList();
|
||||||
|
tempKeys.forEach(o -> {
|
||||||
|
String value = stringRedisTemplate.opsForValue().get(o);
|
||||||
|
QXWarningVO qxWarningVO = JSON.parseObject(value, QXWarningVO.class);
|
||||||
|
data.add(qxWarningVO);
|
||||||
|
});
|
||||||
|
if (CollectionUtils.isNotEmpty(data)) {
|
||||||
|
|
||||||
|
return ResultJson.ok(data.stream().sorted(Comparator.comparing(QXWarningVO::getPublishTime).reversed()).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<QXWarningVO> data = service.find();
|
||||||
|
if (CollectionUtils.isEmpty(data)) {
|
||||||
|
return ResultJson.ok(data);
|
||||||
|
}
|
||||||
|
Set<String> keys = stringRedisTemplate.keys(THIS_REDIS_KEY + ":WARNID:*");
|
||||||
|
data.forEach(o -> {
|
||||||
|
Integer warnid = o.getWarnid();
|
||||||
|
String key = THIS_REDIS_KEY + ":WARNID:" + warnid;
|
||||||
|
if (!keys.contains(key)) {
|
||||||
|
data.get(0).setPlay(true);
|
||||||
|
stringRedisTemplate.opsForValue().set(key, String.valueOf(warnid));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return ResultJson.ok(data);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// /**
|
// /**
|
||||||
|
|
@ -253,7 +291,16 @@ public class QXWarnController {
|
||||||
return ResultJson.error("该名称或编码重复");
|
return ResultJson.error("该名称或编码重复");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dto.getCallTime() == null) {
|
||||||
|
dto.setCallTime(dto.getHandleTime());
|
||||||
|
}
|
||||||
|
|
||||||
boolean save = warnMsgFBService.save(dto);
|
boolean save = warnMsgFBService.save(dto);
|
||||||
|
|
||||||
|
log.info("warnId " + dto.getWarnid());
|
||||||
|
if (Boolean.FALSE.equals(stringRedisTemplate.delete(QX_TEMP_REDIS_KEY + dto.getWarnid()))) {
|
||||||
|
log.error("缓存删除失败: " + dto.getWarnid());
|
||||||
|
}
|
||||||
return ResultJson.ok(save);
|
return ResultJson.ok(save);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,14 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.whdc.model.dto.GroupWarningDto;
|
import com.whdc.model.dto.GroupWarningDto;
|
||||||
import com.whdc.model.entity.QXWarning;
|
import com.whdc.model.entity.QXWarning;
|
||||||
|
import com.whdc.model.vo.QXWarningVO;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface QXWarningMapper extends BaseMapper<QXWarning> {
|
public interface QXWarningMapper extends BaseMapper<QXWarning> {
|
||||||
List<QXWarning> find(@Param("dto")QXWarning dto);
|
List<QXWarning> find(@Param("dto")QXWarning dto);
|
||||||
List<QXWarning> findByMsgIsNull();
|
List<QXWarningVO> findByMsgIsNull();
|
||||||
|
|
||||||
IPage<QXWarning> page(@Param("page") IPage<QXWarning> page, @Param("dto") GroupWarningDto dto);
|
IPage<QXWarning> page(@Param("page") IPage<QXWarning> page, @Param("dto") GroupWarningDto dto);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,10 @@ import lombok.NoArgsConstructor;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class QXWarningVO {
|
public class QXWarningVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否播放报警声音")
|
||||||
|
private Boolean play;
|
||||||
|
|
||||||
@ApiModelProperty(value = "生成时间")
|
@ApiModelProperty(value = "生成时间")
|
||||||
private String createTime;
|
private String createTime;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.whdc.model.dto.GroupWarningDto;
|
import com.whdc.model.dto.GroupWarningDto;
|
||||||
import com.whdc.model.entity.QXWarning;
|
import com.whdc.model.entity.QXWarning;
|
||||||
|
import com.whdc.model.vo.QXWarningVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface IQXWarningService extends IService<QXWarning> {
|
public interface IQXWarningService extends IService<QXWarning> {
|
||||||
List<QXWarning> find();
|
List<QXWarningVO> find();
|
||||||
IPage<QXWarning> page(GroupWarningDto dto);
|
IPage<QXWarning> page(GroupWarningDto dto);
|
||||||
|
|
||||||
List<QXWarning> getWarnAndMsg(String stm,String etm);
|
List<QXWarning> getWarnAndMsg(String stm, String etm);
|
||||||
}
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.whdc.mapper.QXWarningMapper;
|
import com.whdc.mapper.QXWarningMapper;
|
||||||
import com.whdc.model.dto.GroupWarningDto;
|
import com.whdc.model.dto.GroupWarningDto;
|
||||||
import com.whdc.model.entity.QXWarning;
|
import com.whdc.model.entity.QXWarning;
|
||||||
|
import com.whdc.model.vo.QXWarningVO;
|
||||||
import com.whdc.service.IQXWarningService;
|
import com.whdc.service.IQXWarningService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
@ -15,7 +16,7 @@ import java.util.List;
|
||||||
@Service
|
@Service
|
||||||
public class QXWarningServiceImpl extends ServiceImpl<QXWarningMapper, QXWarning> implements IQXWarningService {
|
public class QXWarningServiceImpl extends ServiceImpl<QXWarningMapper, QXWarning> implements IQXWarningService {
|
||||||
@Override
|
@Override
|
||||||
public List<QXWarning> find() {
|
public List<QXWarningVO> find() {
|
||||||
return getBaseMapper().findByMsgIsNull();
|
return getBaseMapper().findByMsgIsNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,10 @@ spring:
|
||||||
# Redis
|
# Redis
|
||||||
redis:
|
redis:
|
||||||
database: 5
|
database: 5
|
||||||
# host: 10.42.6.75
|
host: 10.42.6.75
|
||||||
host: 127.0.0.1
|
# host: 127.0.0.1
|
||||||
password:
|
# password:
|
||||||
# password: Whdc_890
|
password: Whdc_890
|
||||||
port: 6379
|
port: 6379
|
||||||
|
|
||||||
servlet:
|
servlet:
|
||||||
|
|
@ -82,5 +82,5 @@ wx:
|
||||||
appid: wxb9b07668d1ba20fe
|
appid: wxb9b07668d1ba20fe
|
||||||
secret: 99a1b89ac30e28bcc9bba8be973027f4
|
secret: 99a1b89ac30e28bcc9bba8be973027f4
|
||||||
|
|
||||||
getGroupWarning: http://223.75.53.141:8000/shzh/met/zyqxfw/api/warning/getGroupWarning
|
#getGroupWarning: http://223.75.53.141:8000/shzh/met/zyqxfw/api/warning/getGroupWarning
|
||||||
#getGroupWarning: http://127.0.0.1:20000/shzh/met/zyqxfw/api/warning/getGroupWarning
|
getGroupWarning: http://127.0.0.1:20000/shzh/met/zyqxfw/api/warning/getGroupWarning
|
||||||
Loading…
Reference in New Issue