Commit 3dd43c87 by 毛树良

<chg>:升级springboot2.5.1至3.4.1

1 parent 97494f0c
......@@ -4,7 +4,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.1</version>
<version>3.4.1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.viontech</groupId>
......@@ -14,7 +14,8 @@
<packaging>jar</packaging>
<properties>
<java.version>1.8</java.version>
<java.version>21</java.version>
<logback.version>1.5.15</logback.version>
<skipTests>true</skipTests>
</properties>
......@@ -22,7 +23,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -43,12 +43,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency>-->
......@@ -92,43 +86,24 @@
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.15.0</version>
<version>8.15.5</version>
<exclusions>
<exclusion>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
</exclusion>
<exclusion>
<artifactId>elasticsearch-rest-client</artifactId>
<groupId>org.elasticsearch.client</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.3</version>
</dependency>
<dependency>
<artifactId>elasticsearch-rest-client</artifactId>
<groupId>org.elasticsearch.client</groupId>
<version>8.15.0</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.0.1</version>
<version>8.15.5</version>
</dependency>
<dependency>
<groupId>com.viontech.keliu</groupId>
<artifactId>AlgApiClient</artifactId>
<version>6.1.0-SNAPSHOT</version>
<version>6.2.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>javax</groupId>
......@@ -169,6 +144,18 @@
<finalName>VVAS-Match</finalName>
<plugins>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>11.1.1</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
......@@ -184,8 +171,8 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>21</source>
<target>21</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
......
......@@ -35,7 +35,7 @@ import java.security.cert.X509Certificate;
public class ElasticsearchConfiguration {
@Bean
@ConfigurationProperties(prefix = "spring.elasticsearch.rest")
@ConfigurationProperties(prefix = "spring.elasticsearch")
public CustomElasticsearchProperties Properties() {
return new CustomElasticsearchProperties();
}
......
......@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import jakarta.annotation.Resource;
import java.io.IOException;
/**
......
package com.viontech.match.service;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.FieldValue;
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
import co.elastic.clients.elasticsearch._types.query_dsl.TermsQueryField;
import co.elastic.clients.elasticsearch.core.BulkRequest;
import co.elastic.clients.elasticsearch.core.BulkResponse;
import co.elastic.clients.elasticsearch.core.DeleteByQueryRequest;
import co.elastic.clients.elasticsearch.core.DeleteByQueryResponse;
import co.elastic.clients.elasticsearch.core.bulk.BulkOperation;
import co.elastic.clients.elasticsearch.core.bulk.IndexOperation;
import com.viontech.keliu.model.BodyFeature;
import com.viontech.keliu.model.FaceFeature;
import com.viontech.keliu.model.Person;
import com.viontech.match.config.Constant;
import com.viontech.match.entity.PersonInfo;
import com.viontech.match.util.Utils;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Service
@Slf4j
public class PersonPoolService {
@Resource
private ElasticsearchClient client;
/**
* 添加人员
*
* @param poolId 特征池Id
* @param personPool 要添加的人员列表
*
* @return 批量添加的结果
* @throws IOException elasticsearch 所产生的异常
*/
public BulkResponse addPerson(String poolId, List<Person> personPool) throws IOException {
// BulkRequest bulkRequest = new BulkRequest.Builder().index(poolId).build();
List<BulkOperation> operationList = new ArrayList<>();
for (Person person : personPool) {
if (person == null) {
continue;
}
Integer age = person.getAge();
String gender = person.getGender();
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();
List<FaceFeature> faceFeatures = person.getFaceFeatures();
if (CollectionUtils.isNotEmpty(faceFeatures)) {
for (FaceFeature faceFeature : faceFeatures) {
Double[] feature = faceFeature.getFeature();
if (feature != null && feature.length == Constant.FACE_FEATURE_DIMS) {
String fid = faceFeature.getFid();
String unid = faceFeature.getUnid();
Long gateId = faceFeature.getGateId();
operationList.add(new BulkOperation.Builder().index(new IndexOperation.Builder<PersonInfo>().index(poolId).document(new PersonInfo(unid, personId, null, feature, age, gender, bodyType, personCountTime, fid, personChannelSerialNum, gateId, direction, mallId)).build()).build());
}
}
}
List<BodyFeature> bodyFeatures = person.getBodyFeatures();
if (CollectionUtils.isNotEmpty(bodyFeatures)) {
for (BodyFeature bodyFeature : bodyFeatures) {
Double[] feature = bodyFeature.getFeature();
if (feature == null || feature.length < Constant.BODY_FEATURE_DIMS_2048) {
continue;
} else if (feature.length == Constant.BODY_FEATURE_DIMS_2110) {
feature = Utils.transferBodyFeature(feature);
}
if (feature.length > Constant.BODY_FEATURE_DIMS_2048) {
feature = Arrays.copyOfRange(feature, 3, Constant.BODY_FEATURE_DIMS_2048 + 3);
}
String fid = bodyFeature.getBid();
String unid = bodyFeature.getUnid();
Long gateId = bodyFeature.getGateId();
Date counttime = bodyFeature.getCounttime() == null ? personCountTime : bodyFeature.getCounttime();
String channelSerialNum = bodyFeature.getChannelSerialNum() == null ? personChannelSerialNum : person.getChannelSerialNum();
operationList.add(new BulkOperation.Builder().index(new IndexOperation.Builder<PersonInfo>().index(poolId).document(new PersonInfo(unid, personId, feature, null, age, gender, bodyType, counttime, fid, personChannelSerialNum, gateId, direction, mallId)).build()).build());
}
}
}
if (operationList.size() == 0) {
return null;
}
BulkResponse bulk = client.bulk(new BulkRequest.Builder().index(poolId).operations(operationList).build());
// poolService.refreshPool(poolId);
return bulk;
}
/**
* 删除人员
*
* @param poolId 特征池Id
* @param personId 人员Id,对应数据库personUnid
*
* @return 删除结果
* @throws IOException elasticsearch 所产生的异常
*/
public DeleteByQueryResponse deletePerson(String poolId, String personId) throws IOException {
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest.Builder().index(poolId)
.query(q -> q.match(m -> m.field("personId").query(personId)))
.refresh(true).build();
return client.deleteByQuery(deleteByQueryRequest);
}
public DeleteByQueryResponse deletePersonByMallId(String poolId, Long mallId) throws IOException {
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest.Builder().index(poolId)
.query(q -> q.match(m -> m.field("mallId").query(mallId)))
.refresh(true)
.build();
return client.deleteByQuery(deleteByQueryRequest);
}
public DeleteByQueryResponse deletePersonByFid(String poolId, List<String> fidList) throws IOException {
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest.Builder().index(poolId)
.query(QueryBuilders.terms().field("fid").terms(new TermsQueryField.Builder().value(fidList.stream().map(FieldValue::of).collect(Collectors.toList())).build()).build()._toQuery())
.refresh(true)
.build();
return client.deleteByQuery(deleteByQueryRequest);
}
}
......@@ -38,7 +38,7 @@ import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.client.RequestOptions;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import jakarta.annotation.Resource;
import java.io.IOException;
import java.text.ParseException;
import java.util.*;
......@@ -60,6 +60,8 @@ public class PersonService {
private ElasticsearchClient client;
@Resource
private PoolService poolService;
@Resource
private PersonPoolService personPoolService;
/**
* 符合条件的数量
......@@ -244,8 +246,8 @@ public class PersonService {
if (!poolService.existPool(poolId)) {
poolService.createPool(requestVo, false);
}
DeleteByQueryResponse bulkByScrollResponse = deletePerson(poolId, personId);
BulkResponse bulkItemResponses = addPerson(poolId, Collections.singletonList(person));
DeleteByQueryResponse bulkByScrollResponse = personPoolService.deletePerson(poolId, personId);
BulkResponse bulkItemResponses = personPoolService.addPerson(poolId, Collections.singletonList(person));
} catch (Exception e) {
log.error("人员修改操作异常", e);
return ResponseVo.error(rid, "update failed");
......@@ -264,7 +266,7 @@ public class PersonService {
if (!poolService.existPool(poolId)) {
poolService.createPool(requestVo, false);
}
BulkResponse bulkItemResponses = addPerson(poolId, Collections.singletonList(person));
BulkResponse bulkItemResponses = personPoolService.addPerson(poolId, Collections.singletonList(person));
} catch (Exception e) {
log.error("店员修改操作异常", e);
return ResponseVo.error(rid, "update failed");
......@@ -273,106 +275,13 @@ public class PersonService {
return ResponseVo.success(rid);
}
/**
* 添加人员
*
* @param poolId 特征池Id
* @param personPool 要添加的人员列表
*
* @return 批量添加的结果
* @throws IOException elasticsearch 所产生的异常
*/
public BulkResponse addPerson(String poolId, List<Person> personPool) throws IOException {
// BulkRequest bulkRequest = new BulkRequest.Builder().index(poolId).build();
List<BulkOperation> operationList = new ArrayList<>();
for (Person person : personPool) {
if (person == null) {
continue;
}
Integer age = person.getAge();
String gender = person.getGender();
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();
List<FaceFeature> faceFeatures = person.getFaceFeatures();
if (CollectionUtils.isNotEmpty(faceFeatures)) {
for (FaceFeature faceFeature : faceFeatures) {
Double[] feature = faceFeature.getFeature();
if (feature != null && feature.length == Constant.FACE_FEATURE_DIMS) {
String fid = faceFeature.getFid();
String unid = faceFeature.getUnid();
Long gateId = faceFeature.getGateId();
operationList.add(new BulkOperation.Builder().index(new IndexOperation.Builder<PersonInfo>().index(poolId).document(new PersonInfo(unid, personId, null, feature, age, gender, bodyType, personCountTime, fid, personChannelSerialNum, gateId, direction, mallId)).build()).build());
}
}
}
List<BodyFeature> bodyFeatures = person.getBodyFeatures();
if (CollectionUtils.isNotEmpty(bodyFeatures)) {
for (BodyFeature bodyFeature : bodyFeatures) {
Double[] feature = bodyFeature.getFeature();
if (feature == null || feature.length < Constant.BODY_FEATURE_DIMS_2048) {
continue;
} else if (feature.length == Constant.BODY_FEATURE_DIMS_2110) {
feature = Utils.transferBodyFeature(feature);
}
if (feature.length > Constant.BODY_FEATURE_DIMS_2048) {
feature = Arrays.copyOfRange(feature, 3, Constant.BODY_FEATURE_DIMS_2048 + 3);
}
String fid = bodyFeature.getBid();
String unid = bodyFeature.getUnid();
Long gateId = bodyFeature.getGateId();
Date counttime = bodyFeature.getCounttime() == null ? personCountTime : bodyFeature.getCounttime();
String channelSerialNum = bodyFeature.getChannelSerialNum() == null ? personChannelSerialNum : person.getChannelSerialNum();
operationList.add(new BulkOperation.Builder().index(new IndexOperation.Builder<PersonInfo>().index(poolId).document(new PersonInfo(unid, personId, feature, null, age, gender, bodyType, counttime, fid, personChannelSerialNum, gateId, direction, mallId)).build()).build());
}
}
}
if (operationList.size() == 0) {
return null;
}
BulkResponse bulk = client.bulk(new BulkRequest.Builder().index(poolId).operations(operationList).build());
// poolService.refreshPool(poolId);
return bulk;
}
/**
* 删除人员
*
* @param poolId 特征池Id
* @param personId 人员Id,对应数据库personUnid
*
* @return 删除结果
* @throws IOException elasticsearch 所产生的异常
*/
public DeleteByQueryResponse deletePerson(String poolId, String personId) throws IOException {
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest.Builder().index(poolId)
.query(q -> q.match(m -> m.field("personId").query(personId)))
.refresh(true).build();
return client.deleteByQuery(deleteByQueryRequest);
}
public DeleteByQueryResponse deletePersonByMallId(String poolId, Long mallId) throws IOException {
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest.Builder().index(poolId)
.query(q -> q.match(m -> m.field("mallId").query(mallId)))
.refresh(true)
.build();
return client.deleteByQuery(deleteByQueryRequest);
}
public DeleteByQueryResponse deletePersonByFid(String poolId, List<String> fidList) throws IOException {
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest.Builder().index(poolId)
.query(QueryBuilders.terms().field("fid").terms(new TermsQueryField.Builder().value(fidList.stream().map(FieldValue::of).collect(Collectors.toList())).build()).build()._toQuery())
.refresh(true)
.build();
return client.deleteByQuery(deleteByQueryRequest);
}
// public DeleteByQueryResponse deletePersonByMallId(String poolId, Long mallId) throws IOException {
// DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(poolId)
......
......@@ -29,7 +29,7 @@ import org.elasticsearch.client.RestClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import jakarta.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
......@@ -45,7 +45,7 @@ import java.util.*;
@Slf4j
public class PoolService {
@Resource
private PersonService personService;
private PersonPoolService personPoolService;
@Resource
private ElasticsearchClient client;
// @Resource
......@@ -106,7 +106,7 @@ public class PoolService {
if (addPerson) {
List<Person> personPool = requestVo.getPersonPool();
if (CollectionUtils.isNotEmpty(personPool)) {
BulkResponse bulkItemResponses = personService.addPerson(poolId, personPool);
BulkResponse bulkItemResponses = personPoolService.addPerson(poolId, personPool);
if (bulkItemResponses != null) {
log.info(bulkItemResponses.toString());
}
......@@ -144,7 +144,7 @@ public class PoolService {
for (HashMap<String, String> item : personIds) {
String personId = item.get("personId");
if (personId != null) {
personService.deletePerson(poolId, personId);
personPoolService.deletePerson(poolId, personId);
}
}
} else if (flushPool == 1) {
......@@ -169,7 +169,7 @@ public class PoolService {
Long mallId = requestVo.getMallId();
log.info("特征池删除mallId:{}数据操作开始:[{}]", mallId,poolId);
try {
personService.deletePersonByMallId(poolId, mallId);
personPoolService.deletePersonByMallId(poolId, mallId);
log.info("特征池删除mallId:{}操作完成:[{}]", mallId, poolId);
return ResponseVo.success(rid);
} catch (ElasticsearchException e) {
......@@ -189,7 +189,7 @@ public class PoolService {
List<String> fidList = requestVo.getFidList();
log.info("店员特征池删除数据操作开始:[{}]",poolId);
try {
personService.deletePersonByFid(poolId, fidList);
personPoolService.deletePersonByFid(poolId, fidList);
log.info("店员特征池删除操作完成:[{}]",poolId);
return ResponseVo.success(rid);
} catch (ElasticsearchException e) {
......@@ -242,7 +242,7 @@ public class PoolService {
return ResponseVo.poolIdNotExists(rid);
}
try {
BulkResponse bulkItemResponses = personService.addPerson(poolId, personPool);
BulkResponse bulkItemResponses = personPoolService.addPerson(poolId, personPool);
if (bulkItemResponses != null && bulkItemResponses.errors()) {
log.info(bulkItemResponses.items().toString());
return ResponseVo.error(rid, bulkItemResponses.items().toString());
......
......@@ -4,13 +4,13 @@ spring.jackson.time-zone=GMT+8
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
#es
#spring.elasticsearch.rest.uris=http://182.92.184.40:9200
spring.elasticsearch.rest.uris=http://127.0.0.1:9200
spring.elasticsearch.rest.username=elastic
spring.elasticsearch.rest.password=vion2021
spring.elasticsearch.rest.socketTimeout=5000
spring.elasticsearch.rest.ioThreadCount=20
spring.elasticsearch.rest.maxConnTotal=100
spring.elasticsearch.rest.maxConnPerRoute=20
spring.elasticsearch.uris=http://39.155.171.242:9201
spring.elasticsearch.username=elastic
spring.elasticsearch.password=vion2021
spring.elasticsearch.socketTimeout=5000
spring.elasticsearch.ioThreadCount=20
spring.elasticsearch.maxConnTotal=100
spring.elasticsearch.maxConnPerRoute=20
#\u5206\u7247\u6570\u91CF
vion.index.number_of_shards=1
#\u526F\u672C\u6570\u91CF
......
......@@ -38,14 +38,13 @@
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- 日志归档 -->
<fileNamePattern>${log.path}/debug/log-debug-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
<!-- 日志文件的最大大小 -->
<maxFileSize>100MB</maxFileSize>
</rollingPolicy>
<!-- 此日志文件只记录debug级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
......@@ -65,14 +64,13 @@
<charset>UTF-8</charset>
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- 每天日志归档路径以及格式 -->
<fileNamePattern>${log.path}/info/log-info-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
<!-- 日志文件的最大大小 -->
<maxFileSize>100MB</maxFileSize>
</rollingPolicy>
<!-- 此日志文件只记录info级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
......@@ -97,13 +95,12 @@
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${log.path}/warn/log-warn-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>5</maxHistory>
<!-- 日志文件的最大大小 -->
<maxFileSize>100MB</maxFileSize>
</rollingPolicy>
<!-- 此日志文件只记录warn级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
......@@ -124,13 +121,12 @@
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${log.path}/error/log-error-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
<!-- 日志文件的最大大小 -->
<maxFileSize>100MB</maxFileSize>
</rollingPolicy>
<!-- 此日志文件只记录ERROR级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!