调整上传照片流关闭的问题
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
# url: jdbc:mysql://yingdiandian.mysql.rds.aliyuncs.com:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true
|
url: jdbc:mysql://yingdiandian.mysql.rds.aliyuncs.com:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true
|
||||||
# username: yingdd
|
username: yingdd
|
||||||
# password: Yingdd2015
|
password: Yingdd2015
|
||||||
url: jdbc:mysql://127.0.01:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true
|
# url: jdbc:mysql://127.0.01:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true
|
||||||
username: root
|
# username: root
|
||||||
password: 123456
|
# password: 123456
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
password: 123456
|
password:
|
||||||
timeout: 6000
|
timeout: 6000
|
||||||
port: 6379
|
port: 6379
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ spring:
|
|||||||
password: Yingdd2015
|
password: Yingdd2015
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
password: 123456
|
password:
|
||||||
timeout: 6000
|
timeout: 6000
|
||||||
port: 6379
|
port: 6379
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@@ -494,16 +496,22 @@ public class MemberService extends BaseServiceImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
synchronized (("face" + memberId).intern()) {
|
synchronized (("face" + memberId).intern()) {
|
||||||
|
InputStream inputStream = null;
|
||||||
try {
|
try {
|
||||||
byte[] byt = new byte[file.getInputStream().available()];
|
inputStream = file.getInputStream();
|
||||||
file.getInputStream().read(byt);
|
byte[] byt = new byte[inputStream.available()];
|
||||||
|
inputStream.read(byt);
|
||||||
Member member = memberMapper.findById(memberId);
|
Member member = memberMapper.findById(memberId);
|
||||||
if (member != null) {
|
if (member != null) {
|
||||||
String imgUrl = ossClientUtil.uploadImg(new ByteArrayInputStream(byt), file.getOriginalFilename());
|
String imgUrl = ossClientUtil.uploadImg(new ByteArrayInputStream(byt), file.getOriginalFilename());
|
||||||
faceService.login();
|
logger.info(memberId + "上传oss文件成功." + imgUrl);
|
||||||
Integer faceId = faceService.uploadFace(new ByteArrayInputStream(byt));
|
Integer subjectId = null;
|
||||||
Integer subjectId = faceService.addSubject(faceId, member);
|
if (faceService.login()){
|
||||||
logger.info(faceId + "&&" + subjectId);
|
Integer faceId = faceService.uploadFace(new ByteArrayInputStream(byt));
|
||||||
|
byt = null;
|
||||||
|
subjectId = faceService.addSubject(faceId, member);
|
||||||
|
logger.info(faceId + "&&" + subjectId);
|
||||||
|
}
|
||||||
if (memberFaceInfo != null) {
|
if (memberFaceInfo != null) {
|
||||||
//删除原有的subject
|
//删除原有的subject
|
||||||
faceService.deleteSubject(memberFaceInfo.getFaceId());
|
faceService.deleteSubject(memberFaceInfo.getFaceId());
|
||||||
@@ -516,6 +524,12 @@ public class MemberService extends BaseServiceImpl {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.info("unknown error",e);
|
logger.info("unknown error",e);
|
||||||
throw new ServiceException("设置人脸失败,请稍后再试");
|
throw new ServiceException("设置人脸失败,请稍后再试");
|
||||||
|
}finally {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class FaceService {
|
|||||||
/**
|
/**
|
||||||
* face++登录
|
* face++登录
|
||||||
*/
|
*/
|
||||||
public void login() throws IOException {
|
public boolean login() throws IOException {
|
||||||
JsonObject param = new JsonObject();
|
JsonObject param = new JsonObject();
|
||||||
param.addProperty("username", account);
|
param.addProperty("username", account);
|
||||||
param.addProperty("password", pwd);
|
param.addProperty("password", pwd);
|
||||||
@@ -63,7 +63,7 @@ public class FaceService {
|
|||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
LoginResponse loginResponse = JsonMapper.nonNullMapper().fromJson(response.getEntity().getContent(), LoginResponse.class);
|
LoginResponse loginResponse = JsonMapper.nonNullMapper().fromJson(response.getEntity().getContent(), LoginResponse.class);
|
||||||
logger.info("登录成功" + ToStringBuilder.reflectionToString(loginResponse));
|
logger.info("登录成功" + ToStringBuilder.reflectionToString(loginResponse));
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
logger.error("face++登陆失败!");
|
logger.error("face++登陆失败!");
|
||||||
throw new FaceServiceException("登录失败");
|
throw new FaceServiceException("登录失败");
|
||||||
@@ -150,6 +150,7 @@ public class FaceService {
|
|||||||
HttpEntity httpEntity = multipartEntityBuilder.build();
|
HttpEntity httpEntity = multipartEntityBuilder.build();
|
||||||
httpPost.setEntity(httpEntity);
|
httpPost.setEntity(httpEntity);
|
||||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||||
|
face.close();
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
AddFaceResponse addFaceResponse = JsonMapper.nonNullMapper().fromJson(response.getEntity().getContent(), AddFaceResponse.class);
|
AddFaceResponse addFaceResponse = JsonMapper.nonNullMapper().fromJson(response.getEntity().getContent(), AddFaceResponse.class);
|
||||||
if (addFaceResponse.getCode() == 0) {
|
if (addFaceResponse.getCode() == 0) {
|
||||||
@@ -168,6 +169,11 @@ public class FaceService {
|
|||||||
public void deleteSubject(Integer subjectId) throws IOException {
|
public void deleteSubject(Integer subjectId) throws IOException {
|
||||||
HttpDelete httpDelete = new HttpDelete("http://" + faceUrl + "/subject/" + subjectId);
|
HttpDelete httpDelete = new HttpDelete("http://" + faceUrl + "/subject/" + subjectId);
|
||||||
CloseableHttpResponse response = httpClient.execute(httpDelete);
|
CloseableHttpResponse response = httpClient.execute(httpDelete);
|
||||||
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
|
logger.info("删除头像成功 subjectId" + subjectId);
|
||||||
|
} else {
|
||||||
|
logger.info("删除头像失败 subjectId" + subjectId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user