2024年9月8日 新增从数据库读取配置(人脸识别)功能
This commit is contained in:
parent
2026c4e06e
commit
c36903bcd2
|
@ -12,6 +12,9 @@ import java.util.Map;
|
|||
* @Version: V1.0
|
||||
*/
|
||||
public interface ICommonConfigService extends IService<CommonConfig> {
|
||||
|
||||
Map<String, CommonConfig> getAllConfigMap();
|
||||
|
||||
Map<String, CommonConfig> getConfigMapByOrgCode(String sysOrgCode);
|
||||
|
||||
CommonConfig getConfigMapByCode(String code);
|
||||
|
|
|
@ -22,16 +22,34 @@ import java.util.Map;
|
|||
*/
|
||||
@Service
|
||||
public class CommonConfigServiceImpl extends ServiceImpl<CommonConfigMapper, CommonConfig> implements ICommonConfigService {
|
||||
|
||||
@Autowired
|
||||
private CommonConfigMapper commonConfigMapper;
|
||||
|
||||
/**
|
||||
* 根据机构查询配置信息
|
||||
* @return
|
||||
*/
|
||||
public Map<String,CommonConfig> getAllConfigMap(){
|
||||
QueryWrapper<CommonConfig> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(CommonConfig::getParamStatus, "1");
|
||||
List<CommonConfig> configList = list(queryWrapper);
|
||||
|
||||
Map<String,CommonConfig> returnMap = new HashMap<>();
|
||||
if(configList!=null && !configList.isEmpty()){
|
||||
configList.forEach(x -> returnMap.put(x.getParamCode(),x));
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据机构查询配置信息
|
||||
* @return
|
||||
*/
|
||||
public Map<String,CommonConfig> getConfigMapByOrgCode(String sysOrgCode){
|
||||
QueryWrapper<CommonConfig> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("sys_org_code",sysOrgCode);
|
||||
queryWrapper.eq("status","1");
|
||||
queryWrapper.lambda().eq(CommonConfig::getSysOrgCode, sysOrgCode);
|
||||
queryWrapper.lambda().eq(CommonConfig::getParamStatus, "1");
|
||||
List<CommonConfig> configList = list(queryWrapper);
|
||||
|
||||
Map<String,CommonConfig> returnMap = new HashMap<>();
|
||||
|
|
|
@ -5,8 +5,12 @@ import com.baidu.aip.face.AipFace;
|
|||
import com.baidu.aip.face.MatchRequest;
|
||||
import io.swagger.models.auth.In;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.modules.common.commonConfig.entity.CommonConfig;
|
||||
import org.jeecg.modules.common.commonConfig.service.ICommonConfigService;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
@ -14,6 +18,7 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class FaceMain {
|
||||
|
@ -21,11 +26,19 @@ public class FaceMain {
|
|||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Autowired
|
||||
private ICommonConfigService qnCommonConfigService;
|
||||
|
||||
//设置APPID/AK/SK
|
||||
// public static final String APP_ID = "21388583";
|
||||
// public static final String API_KEY = "K3bfbZRl7ttZp656n7Z8wSQCy";
|
||||
// public static final String SECRET_KEY = "xEHt1sRGWlVtsNU10DiNhBMpWUqlTHNQ";
|
||||
|
||||
//是否灵活配置,不配置为从配置文件读取,配置为true则开启从表读取key模式
|
||||
@Value(value = "${baidu.face.flexibleConfiguration}")
|
||||
// public static final String APP_ID = "37872563";
|
||||
public boolean FLEXIBLE_CONFIGURATION;
|
||||
|
||||
@Value(value = "${baidu.face.appid}")
|
||||
// public static final String APP_ID = "37872563";
|
||||
public String APP_ID;
|
||||
|
@ -40,7 +53,14 @@ public class FaceMain {
|
|||
|
||||
@Value(value = "${baidu.face.sleepTime}")
|
||||
// public static final Long SLEEP_TIME = 1000L;
|
||||
public Long SLEEP_TIME;
|
||||
public Long FACE_SLEEP_TIME;
|
||||
|
||||
public Long SLEEP_TIME = FACE_SLEEP_TIME;
|
||||
|
||||
public Long getSleepTime(){
|
||||
creatApiClent();
|
||||
return SLEEP_TIME;
|
||||
}
|
||||
|
||||
public AipFace creatApiClent(){
|
||||
// 可选:设置网络连接参数
|
||||
|
@ -62,6 +82,19 @@ public class FaceMain {
|
|||
// main.setConnectionTimeoutInMillis(90000);
|
||||
// main.setSocketTimeoutInMillis(90000);
|
||||
// return main;
|
||||
//加上开关
|
||||
if(FLEXIBLE_CONFIGURATION){
|
||||
//查找数据库里的key
|
||||
Map<String, CommonConfig> configMap = qnCommonConfigService.getAllConfigMap();
|
||||
if(!configMap.isEmpty()){
|
||||
CommonConfig baiduFaceAppIdConfig = configMap.get("baiduFaceAppId");
|
||||
CommonConfig baiduFaceApiKeyConfig = configMap.get("baiduFaceApiKey");
|
||||
CommonConfig baiduFaceSecretKeyConfig = configMap.get("baiduFaceSecretKey");
|
||||
CommonConfig baiduFaceSleepTimeConfig = configMap.get("baiduFaceSleepTime");
|
||||
SLEEP_TIME = Long.parseLong(baiduFaceSleepTimeConfig.getParamValue());
|
||||
return new AipFace(baiduFaceAppIdConfig.getParamValue(), baiduFaceApiKeyConfig.getParamValue(), baiduFaceSecretKeyConfig.getParamValue());
|
||||
}
|
||||
}
|
||||
return new AipFace(APP_ID, API_KEY, SECRET_KEY);
|
||||
|
||||
}
|
||||
|
@ -84,7 +117,7 @@ public class FaceMain {
|
|||
* @return
|
||||
*/
|
||||
public JSONObject matchBySystemFileUrl(String img1, String img2, boolean isSleep) {
|
||||
return matchBySystemFileUrl(img1, img2, isSleep, SLEEP_TIME);
|
||||
return matchBySystemFileUrl(img1, img2, isSleep, getSleepTime());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,12 +203,12 @@ public class FaceMain {
|
|||
}
|
||||
//正在执行数
|
||||
public void addRunSize(Integer num) {
|
||||
redisUtil.set("calcAllFaceDataIsRunSize",num,SLEEP_TIME * 60 * 5);
|
||||
redisUtil.set("calcAllFaceDataIsRunSize",num,getSleepTime() * 60 * 5);
|
||||
}
|
||||
|
||||
//执行总数
|
||||
public void addRunAllSize(Integer num) {
|
||||
redisUtil.set("calcAllFaceDataIsRunAllSize",num,SLEEP_TIME * 60 * 5);
|
||||
redisUtil.set("calcAllFaceDataIsRunAllSize",num,getSleepTime() * 60 * 5);
|
||||
}
|
||||
|
||||
public String getPromptStr(){
|
||||
|
@ -202,7 +235,7 @@ public class FaceMain {
|
|||
}
|
||||
|
||||
public void runFlag() {
|
||||
redisUtil.set("calcAllFaceDataIsRun",true,SLEEP_TIME * 60 * 5);
|
||||
redisUtil.set("calcAllFaceDataIsRun",true,getSleepTime() * 60 * 5);
|
||||
}
|
||||
|
||||
public void delRunFlag() {
|
||||
|
@ -212,7 +245,7 @@ public class FaceMain {
|
|||
}
|
||||
|
||||
public void addStopFlag() {
|
||||
redisUtil.set("calcAllFaceDataIsRunStop",true,SLEEP_TIME * 60 * 5);
|
||||
redisUtil.set("calcAllFaceDataIsRunStop",true,getSleepTime() * 60 * 5);
|
||||
}
|
||||
public boolean isStop(){
|
||||
Boolean isRun = (Boolean)redisUtil.get("calcAllFaceDataIsRunStop");
|
||||
|
|
|
@ -325,6 +325,8 @@ ffmpeg:
|
|||
extensionFilter: png,jpg,jpeg
|
||||
baidu:
|
||||
face:
|
||||
#是否灵活配置,不配置为从配置文件读取,配置为true则开启从表读取key模式
|
||||
flexibleConfiguration: true
|
||||
# 测试账号 1千/月
|
||||
# 批量比对时延时多少毫秒
|
||||
sleepTime: 1000
|
||||
|
|
|
@ -334,6 +334,8 @@ ffmpeg:
|
|||
extensionFilter: png,jpg,jpeg
|
||||
baidu:
|
||||
face:
|
||||
#是否灵活配置,不配置为从配置文件读取,配置为true则开启从表读取key模式
|
||||
flexibleConfiguration: true
|
||||
# 测试账号 1千/月
|
||||
# 批量比对时延时多少毫秒
|
||||
# sleepTime: 1000
|
||||
|
|
Loading…
Reference in New Issue