Commit 1d9180de by 朱海

[chg]增加店员库操作相关接口

1 parent fba0e3f1
......@@ -49,6 +49,12 @@ public class MainController {
return personService.updatePerson(requestVo);
case CountMatchPerson:
return personService.countMatchPerson(requestVo);
case DelPoolData:
return poolService.deletePoolData(requestVo);
case DelStaffPoolData:
return poolService.deleteStaffPoolData(requestVo);
case UpdateStaff:
return personService.updateStaff(requestVo);
default:
return ResponseVo.commandNotFound(rid);
}
......
......@@ -67,6 +67,10 @@ public class RequestVo {
//暂时无用
private FaceFeature newFaceFeature;
private Long mallId;
private List<String> fidList;
public void setPoolId(String poolId) {
this.poolId = poolId.toLowerCase();
}
......
......@@ -14,5 +14,8 @@ public enum CommandEnum {
QueryPersonPool,
MatchPerson,
UpdatePerson,
CountMatchPerson
CountMatchPerson,
DelPoolData,
DelStaffPoolData,
UpdateStaff;
}
......@@ -21,11 +21,14 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.core.CountRequest;
import org.elasticsearch.client.core.CountResponse;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.index.query.TermsQueryBuilder;
import org.elasticsearch.index.query.functionscore.ScriptScoreQueryBuilder;
import org.elasticsearch.index.reindex.BulkByScrollResponse;
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
......@@ -187,12 +190,19 @@ public class PersonService {
Pool pool = new Pool();
pool.setPersonPoolId(id);
if (poolService.existPool(id)) {
//根据mallId判断特征池是否存在该mall的数据
boolean hasData = hasData(id, requestVo.getPerson().getMallId());
if (hasData) {
pool.setStatus(0);
List<Person> face = matchPerson(rid, id, requestVo.getPerson(), 0, size, agg);
matchFaces.addAll(face);
List<Person> body = matchPerson(rid, id, requestVo.getPerson(), 1, size, agg);
matchBodies.addAll(body);
} else {
pool.setStatus(2);
}
} else {
pool.setStatus(1);
}
poolStatus.add(pool);
......@@ -253,6 +263,26 @@ public class PersonService {
return ResponseVo.success(rid);
}
public ResponseVo updateStaff(RequestVo requestVo) {
String rid = requestVo.getRid();
Person person = requestVo.getPerson();
String personId = person.getPersonId();
String poolId = requestVo.getPoolId();
log.info("店员修改操作开始,poolId:[{}],personId:[{}]", poolId, personId);
try {
if (!poolService.existPool(poolId)) {
poolService.createPool(requestVo, false);
}
BulkResponse bulkItemResponses = addPerson(poolId, Collections.singletonList(person));
} catch (Exception e) {
log.error("店员修改操作异常", e);
return ResponseVo.error(rid, "update failed");
}
log.info("店员修改操作完成,poolId:[{}],personId:[{}]", poolId, personId);
return ResponseVo.success(rid);
}
/**
* 添加人员
*
......@@ -273,6 +303,7 @@ public class PersonService {
String personId = person.getPersonId();
Date personCountTime = person.getCounttime();
String direction = person.getDirection();
Long mallId = person.getMallId();
//Long gateId = person.getGateId();
Integer bodyType = person.getBodyType();
String personChannelSerialNum = person.getChannelSerialNum();
......@@ -288,7 +319,7 @@ public class PersonService {
.source(XContentType.JSON, "personId", personId, "unid", unid,
"data", feature, "fid", fid, "age", age, "gender", gender, "body_type", bodyType,
"counttime", personCountTime == null ? null : Constant.DATE_FORMAT.get().format(personCountTime),
"channelSerialNum", personChannelSerialNum, "gateId", gateId, "direction", direction);
"channelSerialNum", personChannelSerialNum, "gateId", gateId, "direction", direction, "mallId", mallId);
bulkRequest.add(indexRequest);
}
}
......@@ -316,7 +347,7 @@ public class PersonService {
.source(XContentType.JSON, "personId", personId, "unid", unid,
"body", feature, "fid", fid, "age", age, "gender", gender, "body_type", bodyType,
"counttime", counttime == null ? null : Constant.DATE_FORMAT.get().format(counttime)
, "channelSerialNum", channelSerialNum, "gateId", gateId, "direction", direction);
, "channelSerialNum", channelSerialNum, "gateId", gateId, "direction", direction, "mallId", mallId);
bulkRequest.add(indexRequest);
}
}
......@@ -345,6 +376,21 @@ public class PersonService {
return client.deleteByQuery(deleteByQueryRequest, RequestOptions.DEFAULT);
}
public BulkByScrollResponse deletePersonByMallId(String poolId, Long mallId) throws IOException {
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(poolId)
.setQuery(new TermQueryBuilder("mallId", mallId))
.setRefresh(true);
return client.deleteByQuery(deleteByQueryRequest, RequestOptions.DEFAULT);
}
public BulkByScrollResponse deletePersonByFid(String poolId, List<String> fidList) throws IOException {
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(poolId)
.setQuery(new TermsQueryBuilder("fid", fidList))
.setRefresh(true);
return client.deleteByQuery(deleteByQueryRequest, RequestOptions.DEFAULT);
}
/**
* 人员匹配入口
*
......@@ -442,7 +488,10 @@ public class PersonService {
"(cosineSimilarity(params.body, 'body') + 1) / 2 * 100", Collections.singletonMap("body", feature));
boolQuery.filter(QueryBuilders.existsQuery("body"));
}
//根据mallId过滤
if (person.getMallId() != null) {
boolQuery.filter().add(QueryBuilders.termQuery("mallId", person.getMallId()));
}
// 根据通道号过滤
List<String> channelSerialNums = person.getChannelSerialNums();
if (CollectionUtils.isNotEmpty(channelSerialNums)) {
......@@ -558,4 +607,22 @@ public class PersonService {
}
public boolean hasData(String poolId, Long mallId) throws IOException {
log.info("判断特征池:{}是否存在mallId:{}的数据", poolId, mallId);
if (mallId == null || mallId == 0L) {
return true;
}
//店员库才需要判断是否有数据,并且重建库
if (!poolId.contains("staff")) {
return true;
}
BoolQueryBuilder builder = new BoolQueryBuilder();
builder.filter(QueryBuilders.termQuery("mallId", mallId));
CountRequest countRequest = new CountRequest(poolId);
countRequest.query(builder);
CountResponse response = client.count(countRequest, RequestOptions.DEFAULT);
log.info("特征池:{}中mallId:{}的数据量为:{}", poolId, mallId, response.getCount());
return response.getCount() > 0;
}
}
......@@ -146,6 +146,46 @@ public class PoolService {
}
}
public ResponseVo deletePoolData(RequestVo requestVo) throws Exception {
String rid = requestVo.getRid();
Integer flushPool = requestVo.getFlushPool();
String poolId = requestVo.getPoolId();
Long mallId = requestVo.getMallId();
log.info("特征池删除mallId:{}数据操作开始:[{}]", mallId,poolId);
try {
personService.deletePersonByMallId(poolId, mallId);
log.info("特征池删除mallId:{}操作完成:[{}]", mallId, poolId);
return ResponseVo.success(rid);
} catch (ElasticsearchStatusException e) {
if (e.status() == RestStatus.NOT_FOUND) {
return ResponseVo.poolIdNotExists(rid);
} else {
return ResponseVo.error(rid, e.getDetailedMessage());
}
}
}
public ResponseVo deleteStaffPoolData(RequestVo requestVo) throws Exception {
String rid = requestVo.getRid();
Integer flushPool = requestVo.getFlushPool();
String poolId = requestVo.getPoolId();
List<String> fidList = requestVo.getFidList();
log.info("店员特征池删除数据操作开始:[{}]",poolId);
try {
personService.deletePersonByFid(poolId, fidList);
log.info("店员特征池删除操作完成:[{}]",poolId);
return ResponseVo.success(rid);
} catch (ElasticsearchStatusException e) {
if (e.status() == RestStatus.NOT_FOUND) {
return ResponseVo.poolIdNotExists(rid);
} else {
return ResponseVo.error(rid, e.getDetailedMessage());
}
}
}
/**
* 修改特征池(添加人员)
*
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!