mirror of
https://gitee.com/freshday/radar.git
synced 2026-03-22 04:37:16 +08:00
feats: add sync status.
feihu.wang
This commit is contained in:
@@ -54,4 +54,11 @@ public class MainController {
|
||||
CommonResult result = engineApi.uploadInfo(request.getGuid(), request.getReqId(), request.getJsonInfo());
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/syncStatus")
|
||||
@ApiOperation(value = "事件状态同步接口")
|
||||
public CommonResult syncStatus(@Valid @RequestBody StatusSyncRequest request) {
|
||||
CommonResult result = engineApi.syncStatus(request.getGuid(), request.getEventId(), request.getStatus());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.pgmmers.radar.controller;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 状态同步请求。
|
||||
* @author feihu.wang
|
||||
*/
|
||||
public class StatusSyncRequest {
|
||||
@ApiModelProperty(value = "模型guid")
|
||||
@NotBlank(message = "guid 不能为空")
|
||||
private String guid;
|
||||
|
||||
@ApiModelProperty(value = "eventId")
|
||||
@NotBlank(message = "eventId 不能为空")
|
||||
private String eventId;
|
||||
|
||||
@ApiModelProperty(value = "status")
|
||||
@NotNull(message = "status 不能为空")
|
||||
private String status;
|
||||
|
||||
public String getGuid() {
|
||||
return guid;
|
||||
}
|
||||
|
||||
public void setGuid(String guid) {
|
||||
this.guid = guid;
|
||||
}
|
||||
|
||||
public String getEventId() {
|
||||
return eventId;
|
||||
}
|
||||
|
||||
public void setEventId(String eventId) {
|
||||
this.eventId = eventId;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
@@ -141,5 +141,18 @@ public class RiskAnalysisEngineServiceImpl implements RiskAnalysisEngineService
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult syncStatus(String modelGuid, String eventId, String status) {
|
||||
CommonResult result = new CommonResult();
|
||||
ModelVO model = modelService.getModelByGuid(modelGuid);
|
||||
if (model == null) {
|
||||
result.setMsg("模型不存在!");
|
||||
return result;
|
||||
}
|
||||
long cnt = entityService.update(model.getId(), eventId, status);
|
||||
result.setSuccess(cnt > 0 ? true : false);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class MongoServiceImpl implements MongoService {
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,8 +27,14 @@ public class AggregateCommandImpl implements AggregateCommand {
|
||||
@Override
|
||||
public long count(String modelId, String searchField, Object searchFieldValue, String refDateName, Date begin,
|
||||
Date end) {
|
||||
return count(modelId, searchField, searchFieldValue, refDateName,"1", begin, end);
|
||||
}
|
||||
|
||||
public long count(String modelId, String searchField, Object searchFieldValue, String refDateName, String status, Date begin,
|
||||
Date end) {
|
||||
String collectionName = "entity_" + modelId;
|
||||
Long qty = mongoService.count(collectionName, Filters.and(Filters.eq(searchField, searchFieldValue),
|
||||
Filters.eq("status", status),
|
||||
Filters.gte(refDateName, begin.getTime()), Filters.lte(refDateName, end.getTime())));
|
||||
return qty;
|
||||
}
|
||||
@@ -36,6 +42,12 @@ public class AggregateCommandImpl implements AggregateCommand {
|
||||
@Override
|
||||
public long distinctCount(String modelId, String searchField, Object searchFieldValue, String refDateName,
|
||||
Date begin, Date end, String distinctBy) {
|
||||
return distinctCount(modelId,searchField,searchFieldValue,refDateName,"1", begin, end, distinctBy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long distinctCount(String modelId, String searchField, Object searchFieldValue, String refDateName,
|
||||
String status, Date begin, Date end, String distinctBy) {
|
||||
String collectionName = "entity_" + modelId;
|
||||
Long qty = mongoService.distinctCount(collectionName, Filters.and(Filters.eq(searchField, searchFieldValue),
|
||||
Filters.gte(refDateName, begin.getTime()), Filters.lte(refDateName, end.getTime())), distinctBy);
|
||||
|
||||
@@ -12,14 +12,16 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class EntityServiceImpl implements EntityService {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(EntityServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private ModelService modelService;
|
||||
@Autowired
|
||||
@Resource
|
||||
private MongoService mongoService;
|
||||
|
||||
|
||||
@@ -47,27 +49,42 @@ public class EntityServiceImpl implements EntityService {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long update(Long modelId, String eventId, String status) {
|
||||
ModelVO model = modelService.getModelById(modelId);
|
||||
Document filter = new Document();
|
||||
filter.append(model.getEntryName(), eventId);
|
||||
Document updateDoc = new Document();
|
||||
updateDoc.append("status",status);
|
||||
String collectionName = buildCollectionName(modelId);
|
||||
return mongoService.update(collectionName, filter, updateDoc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int save(Long modelId, String jsonString, String attachJson,
|
||||
boolean isAllowDuplicate) {
|
||||
String tmpUrl = "entity_" + modelId;
|
||||
String collectionName = buildCollectionName(modelId);
|
||||
Document doc = Document.parse(jsonString);
|
||||
Document atta = Document.parse(attachJson);
|
||||
Document attach = Document.parse(attachJson);
|
||||
ModelVO model = modelService.getModelById(modelId);
|
||||
atta.put("radar_ref_datetime", new Date(doc.getLong(model.getReferenceDate())));
|
||||
doc.putAll(atta);
|
||||
attach.put("radar_ref_datetime", new Date(doc.getLong(model.getReferenceDate())));
|
||||
doc.putAll(attach);
|
||||
if (!isAllowDuplicate) {
|
||||
//设置查询条件
|
||||
Document filter = new Document();
|
||||
filter.append(model.getEntryName(), doc.get(model.getEntryName()));
|
||||
long qty = mongoService.count(tmpUrl, filter);
|
||||
long qty = mongoService.count(collectionName, filter);
|
||||
if (qty > 0) {
|
||||
logger.info("record has already exsit!");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
mongoService.insert(tmpUrl, doc);
|
||||
mongoService.insert(collectionName, doc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private String buildCollectionName(Long modelId) {
|
||||
return "entity_" + modelId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,7 +47,14 @@ public interface RiskAnalysisEngineService {
|
||||
* @author feihu.wang
|
||||
*
|
||||
*/
|
||||
|
||||
CommonResult getScore(String modelGuid, String reqId);
|
||||
|
||||
/**
|
||||
* sync event status.
|
||||
* @param modelGuid
|
||||
* @param eventId
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
CommonResult syncStatus(String modelGuid, String eventId, String status);
|
||||
}
|
||||
|
||||
@@ -55,4 +55,9 @@ public interface MongoService {
|
||||
MongoCollection<Document> collection = getCollection(collectionName);
|
||||
return collection.find(filter);
|
||||
}
|
||||
|
||||
default long update(String collectionName, Bson filter, Document updateDoc) {
|
||||
MongoCollection<Document> collection = getCollection(collectionName);
|
||||
return collection.updateOne(filter, updateDoc).getModifiedCount();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,10 @@ public interface AggregateCommand {
|
||||
* 2016年8月4日
|
||||
*/
|
||||
public long count(String modelId, String searchField, Object searchFieldValue, String refDateName, Date begin, Date end);
|
||||
|
||||
|
||||
public long count(String modelId, String searchField, Object searchFieldValue, String refDateName, String status, Date begin, Date end);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 累计去重.
|
||||
@@ -47,6 +50,9 @@ public interface AggregateCommand {
|
||||
public long distinctCount(String modelId, String searchField, Object searchFieldValue, String refDateName, Date begin, Date end,
|
||||
String distinctBy);
|
||||
|
||||
public long distinctCount(String modelId, String searchField, Object searchFieldValue, String refDateName, String status, Date begin, Date end,
|
||||
String distinctBy);
|
||||
|
||||
/**
|
||||
*
|
||||
* 求和.
|
||||
|
||||
@@ -5,13 +5,19 @@ import java.util.List;
|
||||
|
||||
public interface EntityService {
|
||||
|
||||
public int save(Long modelId, String jsonString, boolean isAllowDuplicate);
|
||||
int save(Long modelId, String jsonString, boolean isAllowDuplicate);
|
||||
|
||||
public int save(Long modelId, String jsonString, String attachJson, boolean isAllowDuplicate);
|
||||
int save(Long modelId, String jsonString, String attachJson, boolean isAllowDuplicate);
|
||||
|
||||
public List<Object> find(Long modelId, String conds);
|
||||
|
||||
|
||||
List<Object> find(Long modelId, String conds);
|
||||
|
||||
/**
|
||||
* update status.
|
||||
* @param modelId
|
||||
* @param eventId
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
long update(Long modelId, String eventId, String status);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user