代码提交

master
徐杰盟 2024-06-24 14:22:42 +08:00
parent a24adf091d
commit 81e3f4bf3e
8 changed files with 85 additions and 17 deletions

View File

@ -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 "END_TIME" DATETIME(0);
alter table "FXKH_TXL"."QXWARNING" modify "END_TIME" DATETIME(0);
ALTER TABLE FXKH_TXL.QXWARNING
ADD CONSTRAINT WARNID UNIQUE (WARNID);

View File

@ -11,12 +11,13 @@ import com.whdc.utils.DateUtils;
import com.whdc.utils.HttpUtil;
import io.swagger.annotations.ApiOperation;
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.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
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.Scheduled;
import org.springframework.stereotype.Component;
@ -29,6 +30,8 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static com.whdc.controller.QXWarnController.QX_TEMP_REDIS_KEY;
/**
* @author
* @date 2022-07-17 15:33
@ -51,6 +54,10 @@ public class MyPostConstruct {
private IQXWarningService service;
@Autowired
private RedisTemplate<String, String> stringRedisTemplate;
@Async
@ApiOperation(value = "预警数据同步接口", notes = "预警数据同步接口")
@GetMapping("/syncData")
@ -115,11 +122,14 @@ public class MyPostConstruct {
qxwarning.setWarnid(warningVO.getWarnid());
qxwarning.setCtnm(warningVO.getCtnm());
qxwarning.setCnnm(warningVO.getCnnm());
stringRedisTemplate.opsForValue().set(QX_TEMP_REDIS_KEY + qxwarning.getWarnid(),JSON.toJSONString(warningVO));
adds.add(qxwarning);
}
}
if (CollectionUtils.isNotEmpty(adds)) {
log.info("预警数据同步待添加预警 " + adds.size());
if (this.service.saveBatch(adds)) {

View File

@ -25,6 +25,7 @@ import org.apache.http.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -35,6 +36,7 @@ import java.util.*;
import java.util.stream.Collectors;
import static com.whdc.controller.WarningController.THIS_REDIS_KEY;
import static com.whdc.model.MyConstant.REDIS_KEY;
//湖北省防汛抗旱调度系统-气象预警
@Slf4j
@ -42,6 +44,10 @@ import static com.whdc.controller.WarningController.THIS_REDIS_KEY;
@RestController
@RequestMapping("/qxwarning")
public class QXWarnController {
public static final String QX_TEMP_REDIS_KEY = REDIS_KEY + "warning:temp:";
@Autowired
private IAddressBookService addressBookService;
@Autowired
@ -53,6 +59,9 @@ public class QXWarnController {
@Autowired
private IQXWarningService service;
@Autowired
private RedisTemplate<String, String> stringRedisTemplate;
@Value("${getGroupWarning}")
public String getGroupWarning;
@ -73,17 +82,17 @@ public class QXWarnController {
return ResultJson.ok(save);
}
// @Async
// @Async
@ApiOperation(value = "预警数据同步接口", notes = "预警数据同步接口")
@PostMapping("/syncData")
// @Scheduled(cron ="0 0/5 * * * ?")
public void syncData( @RequestBody GroupWarningDto dto) {
public void syncData(@RequestBody GroupWarningDto dto) {
log.info("预警数据同步开始!!!");
ApiDto apiDto = new ApiDto();
if (StringUtils.isNotBlank(dto.getStartTime())){
if (StringUtils.isNotBlank(dto.getStartTime())) {
apiDto.setStartTime(dto.getStartTime());
}
if (StringUtils.isNotBlank(dto.getEndTime())){
if (StringUtils.isNotBlank(dto.getEndTime())) {
apiDto.setEndTime(dto.getEndTime());
}
apiDto.setFilter(Lists.newArrayList());
@ -144,7 +153,36 @@ public class QXWarnController {
@PostMapping("/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("该名称或编码重复");
}
if (dto.getCallTime() == null) {
dto.setCallTime(dto.getHandleTime());
}
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);
}

View File

@ -4,13 +4,14 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.whdc.model.dto.GroupWarningDto;
import com.whdc.model.entity.QXWarning;
import com.whdc.model.vo.QXWarningVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface QXWarningMapper extends BaseMapper<QXWarning> {
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);

View File

@ -10,6 +10,10 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
public class QXWarningVO {
@ApiModelProperty(value = "是否播放报警声音")
private Boolean play;
@ApiModelProperty(value = "生成时间")
private String createTime;

View File

@ -4,12 +4,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.whdc.model.dto.GroupWarningDto;
import com.whdc.model.entity.QXWarning;
import com.whdc.model.vo.QXWarningVO;
import java.util.List;
public interface IQXWarningService extends IService<QXWarning> {
List<QXWarning> find();
List<QXWarningVO> find();
IPage<QXWarning> page(GroupWarningDto dto);
List<QXWarning> getWarnAndMsg(String stm,String etm);
List<QXWarning> getWarnAndMsg(String stm, String etm);
}

View File

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whdc.mapper.QXWarningMapper;
import com.whdc.model.dto.GroupWarningDto;
import com.whdc.model.entity.QXWarning;
import com.whdc.model.vo.QXWarningVO;
import com.whdc.service.IQXWarningService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -15,7 +16,7 @@ import java.util.List;
@Service
public class QXWarningServiceImpl extends ServiceImpl<QXWarningMapper, QXWarning> implements IQXWarningService {
@Override
public List<QXWarning> find() {
public List<QXWarningVO> find() {
return getBaseMapper().findByMsgIsNull();
}

View File

@ -40,10 +40,10 @@ spring:
# Redis
redis:
database: 5
# host: 10.42.6.75
host: 127.0.0.1
password:
# password: Whdc_890
host: 10.42.6.75
# host: 127.0.0.1
# password:
password: Whdc_890
port: 6379
servlet:
@ -82,5 +82,5 @@ wx:
appid: wxb9b07668d1ba20fe
secret: 99a1b89ac30e28bcc9bba8be973027f4
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://223.75.53.141:8000/shzh/met/zyqxfw/api/warning/getGroupWarning
getGroupWarning: http://127.0.0.1:20000/shzh/met/zyqxfw/api/warning/getGroupWarning