|
|
@ -2,6 +2,16 @@ package org.jeecg.modules.api.service.Impl; |
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
|
import com.tencentcloudapi.common.AbstractModel; |
|
|
|
|
|
import com.tencentcloudapi.common.Credential; |
|
|
|
|
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException; |
|
|
|
|
|
import com.tencentcloudapi.common.profile.ClientProfile; |
|
|
|
|
|
import com.tencentcloudapi.common.profile.HttpProfile; |
|
|
|
|
|
import com.tencentcloudapi.iai.v20180301.IaiClient; |
|
|
|
|
|
import com.tencentcloudapi.iai.v20180301.models.CompareFaceRequest; |
|
|
|
|
|
import com.tencentcloudapi.iai.v20180301.models.CompareFaceResponse; |
|
|
|
|
|
import com.tencentcloudapi.iai.v20180301.models.DetectFaceRequest; |
|
|
|
|
|
import com.tencentcloudapi.iai.v20180301.models.DetectFaceResponse; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.lang.StringUtils; |
|
|
import org.apache.commons.lang.StringUtils; |
|
|
import org.jeecg.common.api.vo.Result; |
|
|
import org.jeecg.common.api.vo.Result; |
|
|
@ -9,10 +19,12 @@ import org.jeecg.config.shiro.ShiroRealm; |
|
|
import org.jeecg.modules.api.bean.PageBean; |
|
|
import org.jeecg.modules.api.bean.PageBean; |
|
|
import org.jeecg.modules.api.service.ImageService; |
|
|
import org.jeecg.modules.api.service.ImageService; |
|
|
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember; |
|
|
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember; |
|
|
|
|
|
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService; |
|
|
import org.jeecg.modules.studytourImage.entity.StudytourImage; |
|
|
import org.jeecg.modules.studytourImage.entity.StudytourImage; |
|
|
import org.jeecg.modules.studytourImage.entity.StudytourImageContent; |
|
|
import org.jeecg.modules.studytourImage.entity.StudytourImageContent; |
|
|
import org.jeecg.modules.studytourImage.service.IStudytourImageContentService; |
|
|
import org.jeecg.modules.studytourImage.service.IStudytourImageContentService; |
|
|
import org.jeecg.modules.studytourImage.service.IStudytourImageService; |
|
|
import org.jeecg.modules.studytourImage.service.IStudytourImageService; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
@ -24,9 +36,19 @@ import java.util.List; |
|
|
public class ImageServiceImpl implements ImageService { |
|
|
public class ImageServiceImpl implements ImageService { |
|
|
|
|
|
|
|
|
/******************************************************************************************************************/ |
|
|
/******************************************************************************************************************/ |
|
|
|
|
|
//腾讯云API密钥id |
|
|
|
|
|
@Value("${tencent.miniapp.secretId}") |
|
|
|
|
|
private String secretId; |
|
|
|
|
|
//腾讯云API密钥key |
|
|
|
|
|
@Value("${tencent.miniapp.secretKey}") |
|
|
|
|
|
private String secretKey; |
|
|
|
|
|
|
|
|
//权限验证 |
|
|
//权限验证 |
|
|
@Resource |
|
|
@Resource |
|
|
private ShiroRealm shiroRealm; |
|
|
private ShiroRealm shiroRealm; |
|
|
|
|
|
//图片直播内容信息 |
|
|
|
|
|
@Resource |
|
|
|
|
|
private IHanHaiMemberService hanHaiMemberService; |
|
|
//图片直播信息 |
|
|
//图片直播信息 |
|
|
@Resource |
|
|
@Resource |
|
|
private IStudytourImageService studytourImageService; |
|
|
private IStudytourImageService studytourImageService; |
|
|
@ -127,9 +149,8 @@ public class ImageServiceImpl implements ImageService { |
|
|
query.eq(StudytourImageContent::getImageId, content.getImageId()); |
|
|
query.eq(StudytourImageContent::getImageId, content.getImageId()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(StringUtils.isNotEmpty(content.getActivityId())){ |
|
|
|
|
|
query.eq(StudytourImageContent::getActivityId, content.getActivityId()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//审核状态为已通过 |
|
|
|
|
|
query.eq(StudytourImageContent::getStatus, "1"); |
|
|
|
|
|
|
|
|
//按照创建时间降序排列 |
|
|
//按照创建时间降序排列 |
|
|
query.orderByDesc(StudytourImageContent::getCreateTime); |
|
|
query.orderByDesc(StudytourImageContent::getCreateTime); |
|
|
@ -137,6 +158,11 @@ public class ImageServiceImpl implements ImageService { |
|
|
//获取图片直播信息列表 |
|
|
//获取图片直播信息列表 |
|
|
pageList = query.page(page); |
|
|
pageList = query.page(page); |
|
|
|
|
|
|
|
|
|
|
|
for (StudytourImageContent record : pageList.getRecords()) { |
|
|
|
|
|
HanHaiMember member = hanHaiMemberService.getById(record.getUserId()); |
|
|
|
|
|
record.setUser(member); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
log.info("图片直播内容信息列表查询结束"); |
|
|
log.info("图片直播内容信息列表查询结束"); |
|
|
return Result.OK("图片直播内容信息列表", pageList); |
|
|
return Result.OK("图片直播内容信息列表", pageList); |
|
|
}catch (Exception e){ |
|
|
}catch (Exception e){ |
|
|
@ -179,29 +205,97 @@ public class ImageServiceImpl implements ImageService { |
|
|
|
|
|
|
|
|
//图片直播-标记有我 |
|
|
//图片直播-标记有我 |
|
|
@Override |
|
|
@Override |
|
|
public Result<?> queryMarkmeList(String token, String imageId, String imagePath) { |
|
|
|
|
|
|
|
|
public Result<?> queryMarkmeList(String token, String activityId, String imagePath) { |
|
|
|
|
|
|
|
|
//返回信息 |
|
|
//返回信息 |
|
|
List<String> imageList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
List<String> images = new ArrayList<>(); |
|
|
|
|
|
|
|
|
try{ |
|
|
try{ |
|
|
|
|
|
//图片直播所有图片 |
|
|
List<StudytourImageContent> contentList = studytourImageContentService |
|
|
List<StudytourImageContent> contentList = studytourImageContentService |
|
|
.lambdaQuery() |
|
|
.lambdaQuery() |
|
|
.eq(StudytourImageContent::getImageId, imageId) |
|
|
|
|
|
|
|
|
.eq(StudytourImageContent::getActivityId, activityId) |
|
|
.list(); |
|
|
.list(); |
|
|
|
|
|
|
|
|
//对比图片相似度 |
|
|
//对比图片相似度 |
|
|
for (StudytourImageContent studytourImageContent : contentList) { |
|
|
for (StudytourImageContent studytourImageContent : contentList) { |
|
|
String[] split = studytourImageContent.getImage().split(","); |
|
|
String[] split = studytourImageContent.getImage().split(","); |
|
|
for (String s : split) { |
|
|
|
|
|
imageList.add(s); |
|
|
|
|
|
|
|
|
for (String image : split) { |
|
|
|
|
|
boolean flag = checkFace(image);//判断图片是否包含人脸 |
|
|
|
|
|
if(flag){ |
|
|
|
|
|
images.add(image); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//标记后的图片 |
|
|
|
|
|
List<String> imageList = new ArrayList<>(); |
|
|
|
|
|
for (String image : images) { |
|
|
|
|
|
// 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY |
|
|
|
|
|
// 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性 |
|
|
|
|
|
// 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等 |
|
|
|
|
|
// 请参见:https://cloud.tencent.com/document/product/1278/85305 |
|
|
|
|
|
// 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 |
|
|
|
|
|
Credential cred = new Credential(secretId, secretKey); |
|
|
|
|
|
// 使用临时密钥示例 |
|
|
|
|
|
// Credential cred = new Credential("SecretId", "SecretKey", "Token"); |
|
|
|
|
|
// 实例化一个http选项,可选的,没有特殊需求可以跳过 |
|
|
|
|
|
HttpProfile httpProfile = new HttpProfile(); |
|
|
|
|
|
httpProfile.setEndpoint("iai.tencentcloudapi.com"); |
|
|
|
|
|
// 实例化一个client选项,可选的,没有特殊需求可以跳过 |
|
|
|
|
|
ClientProfile clientProfile = new ClientProfile(); |
|
|
|
|
|
clientProfile.setHttpProfile(httpProfile); |
|
|
|
|
|
// 实例化要请求产品的client对象,clientProfile是可选的 |
|
|
|
|
|
IaiClient client = new IaiClient(cred, "ap-beijing", clientProfile); |
|
|
|
|
|
// 实例化一个请求对象,每个接口都会对应一个request对象 |
|
|
|
|
|
CompareFaceRequest req = new CompareFaceRequest(); |
|
|
|
|
|
req.setUrlA(imagePath); |
|
|
|
|
|
req.setUrlB(image); |
|
|
|
|
|
// 返回的resp是一个CompareFaceResponse的实例,与请求对象对应 |
|
|
|
|
|
CompareFaceResponse resp = client.CompareFace(req); |
|
|
|
|
|
// 输出json格式的字符串回包 |
|
|
|
|
|
if(resp.getScore() > 50){ |
|
|
|
|
|
imageList.add(image); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return Result.OK("标记有我图片信息", imageList); |
|
|
return Result.OK("标记有我图片信息", imageList); |
|
|
}catch (Exception e){ |
|
|
}catch (Exception e){ |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|
return Result.error("标记有我图片信息获取失败"); |
|
|
return Result.error("标记有我图片信息获取失败"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//判断图片是否存在人脸 |
|
|
|
|
|
public boolean checkFace(String image){ |
|
|
|
|
|
try{ |
|
|
|
|
|
// 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY |
|
|
|
|
|
// 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性 |
|
|
|
|
|
// 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等 |
|
|
|
|
|
// 请参见:https://cloud.tencent.com/document/product/1278/85305 |
|
|
|
|
|
// 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 |
|
|
|
|
|
Credential cred = new Credential(secretId, secretKey); |
|
|
|
|
|
// 使用临时密钥示例 |
|
|
|
|
|
// Credential cred = new Credential("SecretId", "SecretKey", "Token"); |
|
|
|
|
|
// 实例化一个http选项,可选的,没有特殊需求可以跳过 |
|
|
|
|
|
HttpProfile httpProfile = new HttpProfile(); |
|
|
|
|
|
httpProfile.setEndpoint("iai.tencentcloudapi.com"); |
|
|
|
|
|
// 实例化一个client选项,可选的,没有特殊需求可以跳过 |
|
|
|
|
|
ClientProfile clientProfile = new ClientProfile(); |
|
|
|
|
|
clientProfile.setHttpProfile(httpProfile); |
|
|
|
|
|
// 实例化要请求产品的client对象,clientProfile是可选的 |
|
|
|
|
|
IaiClient client = new IaiClient(cred, "ap-beijing", clientProfile); |
|
|
|
|
|
// 实例化一个请求对象,每个接口都会对应一个request对象 |
|
|
|
|
|
DetectFaceRequest req = new DetectFaceRequest(); |
|
|
|
|
|
req.setUrl(image); |
|
|
|
|
|
// 返回的resp是一个DetectFaceResponse的实例,与请求对象对应 |
|
|
|
|
|
DetectFaceResponse resp = client.DetectFace(req); |
|
|
|
|
|
// 输出json格式的字符串回包 |
|
|
|
|
|
return true; |
|
|
|
|
|
//System.out.println(AbstractModel.toJsonString(resp)); |
|
|
|
|
|
} catch (TencentCloudSDKException e) { |
|
|
|
|
|
return false; |
|
|
|
|
|
//System.out.println(e.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |