|
|
|
@ -35,208 +35,258 @@ import com.utils.BaiduUtil;
|
|
|
|
|
import com.utils.FileUtil;
|
|
|
|
|
import com.utils.R;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通用接口控制器
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
public class CommonController{
|
|
|
|
|
public class CommonController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CommonService commonService; // 注入通用服务
|
|
|
|
|
|
|
|
|
|
private static AipFace client = null; // 百度人脸API客户端实例
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CommonService commonService;
|
|
|
|
|
private ConfigService configService; // 注入配置服务
|
|
|
|
|
|
|
|
|
|
private static AipFace client = null;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ConfigService configService;
|
|
|
|
|
/**
|
|
|
|
|
* 获取table表中的column列表(联动接口)
|
|
|
|
|
* @param tableName 表名
|
|
|
|
|
* @param columnName 列名
|
|
|
|
|
* @param level 层级(可选)
|
|
|
|
|
* @param parent 父节点(可选)
|
|
|
|
|
* @return 返回联动数据
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping("/option/{tableName}/{columnName}")
|
|
|
|
|
public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,String level,String parent) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
params.put("table", tableName);
|
|
|
|
|
params.put("column", columnName);
|
|
|
|
|
if(StringUtils.isNotBlank(level)) {
|
|
|
|
|
params.put("level", level);
|
|
|
|
|
public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,
|
|
|
|
|
String level, String parent) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>(); // 参数封装
|
|
|
|
|
params.put("table", tableName); // 添加表名
|
|
|
|
|
params.put("column", columnName); // 添加列名
|
|
|
|
|
if (StringUtils.isNotBlank(level)) { // 如果层级不为空
|
|
|
|
|
params.put("level", level); // 添加层级
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isNotBlank(parent)) {
|
|
|
|
|
params.put("parent", parent);
|
|
|
|
|
if (StringUtils.isNotBlank(parent)) { // 如果父节点不为空
|
|
|
|
|
params.put("parent", parent); // 添加父节点
|
|
|
|
|
}
|
|
|
|
|
List<String> data = commonService.getOption(params);
|
|
|
|
|
return R.ok().put("data", data);
|
|
|
|
|
List<String> data = commonService.getOption(params); // 调用服务获取数据
|
|
|
|
|
return R.ok().put("data", data); // 返回成功结果
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据table中的column获取单条记录
|
|
|
|
|
* @param tableName 表名
|
|
|
|
|
* @param columnName 列名
|
|
|
|
|
* @param columnValue 列值
|
|
|
|
|
* @return 返回单条记录
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping("/follow/{tableName}/{columnName}")
|
|
|
|
|
public R getFollowByOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, @RequestParam String columnValue) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
params.put("table", tableName);
|
|
|
|
|
params.put("column", columnName);
|
|
|
|
|
params.put("columnValue", columnValue);
|
|
|
|
|
Map<String, Object> result = commonService.getFollowByOption(params);
|
|
|
|
|
return R.ok().put("data", result);
|
|
|
|
|
public R getFollowByOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,
|
|
|
|
|
@RequestParam String columnValue) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>(); // 参数封装
|
|
|
|
|
params.put("table", tableName); // 添加表名
|
|
|
|
|
params.put("column", columnName); // 添加列名
|
|
|
|
|
params.put("columnValue", columnValue); // 添加列值
|
|
|
|
|
Map<String, Object> result = commonService.getFollowByOption(params); // 调用服务获取结果
|
|
|
|
|
return R.ok().put("data", result); // 返回成功结果
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改table表的sfsh状态
|
|
|
|
|
* @param tableName 表名
|
|
|
|
|
* @param map 请求参数
|
|
|
|
|
* @return 返回操作结果
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/sh/{tableName}")
|
|
|
|
|
public R sh(@PathVariable("tableName") String tableName, @RequestBody Map<String, Object> map) {
|
|
|
|
|
map.put("table", tableName);
|
|
|
|
|
commonService.sh(map);
|
|
|
|
|
return R.ok();
|
|
|
|
|
map.put("table", tableName); // 添加表名
|
|
|
|
|
commonService.sh(map); // 调用服务修改状态
|
|
|
|
|
return R.ok(); // 返回成功结果
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取需要提醒的记录数
|
|
|
|
|
* @param tableName 表名
|
|
|
|
|
* @param columnName 列名
|
|
|
|
|
* @param type 提醒类型(1:数字, 2:日期)
|
|
|
|
|
* @param map 请求参数
|
|
|
|
|
* @return 返回提醒记录数
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping("/remind/{tableName}/{columnName}/{type}")
|
|
|
|
|
public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,
|
|
|
|
|
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
|
|
|
|
|
map.put("table", tableName);
|
|
|
|
|
map.put("column", columnName);
|
|
|
|
|
map.put("type", type);
|
|
|
|
|
|
|
|
|
|
if(type.equals("2")) {
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
|
Date remindStartDate = null;
|
|
|
|
|
Date remindEndDate = null;
|
|
|
|
|
if(map.get("remindstart")!=null) {
|
|
|
|
|
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
|
|
|
|
|
c.setTime(new Date());
|
|
|
|
|
c.add(Calendar.DAY_OF_MONTH,remindStart);
|
|
|
|
|
remindStartDate = c.getTime();
|
|
|
|
|
map.put("remindstart", sdf.format(remindStartDate));
|
|
|
|
|
public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,
|
|
|
|
|
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
|
|
|
|
|
map.put("table", tableName); // 添加表名
|
|
|
|
|
map.put("column", columnName); // 添加列名
|
|
|
|
|
map.put("type", type); // 添加提醒类型
|
|
|
|
|
if ("2".equals(type)) { // 如果类型为日期
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 日期格式化工具
|
|
|
|
|
Calendar c = Calendar.getInstance(); // 日历实例
|
|
|
|
|
Date remindStartDate = null; // 提醒开始日期
|
|
|
|
|
Date remindEndDate = null; // 提醒结束日期
|
|
|
|
|
if (map.get("remindstart") != null) { // 如果有提醒开始时间
|
|
|
|
|
Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 转换为整数
|
|
|
|
|
c.setTime(new Date()); // 设置当前时间为基准
|
|
|
|
|
c.add(Calendar.DAY_OF_MONTH, remindStart); // 增加天数
|
|
|
|
|
remindStartDate = c.getTime(); // 获取新的日期
|
|
|
|
|
map.put("remindstart", sdf.format(remindStartDate)); // 格式化并更新参数
|
|
|
|
|
}
|
|
|
|
|
if(map.get("remindend")!=null) {
|
|
|
|
|
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
|
|
|
|
|
c.setTime(new Date());
|
|
|
|
|
c.add(Calendar.DAY_OF_MONTH,remindEnd);
|
|
|
|
|
remindEndDate = c.getTime();
|
|
|
|
|
map.put("remindend", sdf.format(remindEndDate));
|
|
|
|
|
if (map.get("remindend") != null) { // 如果有提醒结束时间
|
|
|
|
|
Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 转换为整数
|
|
|
|
|
c.setTime(new Date()); // 设置当前时间为基准
|
|
|
|
|
c.add(Calendar.DAY_OF_MONTH, remindEnd); // 增加天数
|
|
|
|
|
remindEndDate = c.getTime(); // 获取新的日期
|
|
|
|
|
map.put("remindend", sdf.format(remindEndDate)); // 格式化并更新参数
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int count = commonService.remindCount(map);
|
|
|
|
|
return R.ok().put("count", count);
|
|
|
|
|
int count = commonService.remindCount(map); // 调用服务获取提醒记录数
|
|
|
|
|
return R.ok().put("count", count); // 返回成功结果
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 单列求和
|
|
|
|
|
* @param tableName 表名
|
|
|
|
|
* @param columnName 列名
|
|
|
|
|
* @return 返回求和结果
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping("/cal/{tableName}/{columnName}")
|
|
|
|
|
public R cal(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
params.put("table", tableName);
|
|
|
|
|
params.put("column", columnName);
|
|
|
|
|
Map<String, Object> result = commonService.selectCal(params);
|
|
|
|
|
return R.ok().put("data", result);
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>(); // 参数封装
|
|
|
|
|
params.put("table", tableName); // 添加表名
|
|
|
|
|
params.put("column", columnName); // 添加列名
|
|
|
|
|
Map<String, Object> result = commonService.selectCal(params); // 调用服务获取求和结果
|
|
|
|
|
return R.ok().put("data", result); // 返回成功结果
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分组统计
|
|
|
|
|
* @param tableName 表名
|
|
|
|
|
* @param columnName 列名
|
|
|
|
|
* @return 返回分组统计结果
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping("/group/{tableName}/{columnName}")
|
|
|
|
|
public R group(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
params.put("table", tableName);
|
|
|
|
|
params.put("column", columnName);
|
|
|
|
|
List<Map<String, Object>> result = commonService.selectGroup(params);
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
for(Map<String, Object> m : result) {
|
|
|
|
|
for(String k : m.keySet()) {
|
|
|
|
|
if(m.get(k) instanceof Date) {
|
|
|
|
|
m.put(k, sdf.format((Date)m.get(k)));
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>(); // 参数封装
|
|
|
|
|
params.put("table", tableName); // 添加表名
|
|
|
|
|
params.put("column", columnName); // 添加列名
|
|
|
|
|
List<Map<String, Object>> result = commonService.selectGroup(params); // 调用服务获取分组统计结果
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 日期格式化工具
|
|
|
|
|
for (Map<String, Object> m : result) { // 遍历结果
|
|
|
|
|
for (String k : m.keySet()) { // 遍历键
|
|
|
|
|
if (m.get(k) instanceof Date) { // 如果值是日期类型
|
|
|
|
|
m.put(k, sdf.format((Date) m.get(k))); // 格式化日期
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return R.ok().put("data", result);
|
|
|
|
|
return R.ok().put("data", result); // 返回成功结果
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* (按值统计)
|
|
|
|
|
* @param tableName 表名
|
|
|
|
|
* @param yColumnName Y轴列名
|
|
|
|
|
* @param xColumnName X轴列名
|
|
|
|
|
* @return 返回按值统计结果
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}")
|
|
|
|
|
public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
params.put("table", tableName);
|
|
|
|
|
params.put("xColumn", xColumnName);
|
|
|
|
|
params.put("yColumn", yColumnName);
|
|
|
|
|
List<Map<String, Object>> result = commonService.selectValue(params);
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
for(Map<String, Object> m : result) {
|
|
|
|
|
for(String k : m.keySet()) {
|
|
|
|
|
if(m.get(k) instanceof Date) {
|
|
|
|
|
m.put(k, sdf.format((Date)m.get(k)));
|
|
|
|
|
public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName,
|
|
|
|
|
@PathVariable("xColumnName") String xColumnName) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>(); // 参数封装
|
|
|
|
|
params.put("table", tableName); // 添加表名
|
|
|
|
|
params.put("xColumn", xColumnName); // 添加X轴列名
|
|
|
|
|
params.put("yColumn", yColumnName); // 添加Y轴列名
|
|
|
|
|
List<Map<String, Object>> result = commonService.selectValue(params); // 调用服务获取按值统计结果
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 日期格式化工具
|
|
|
|
|
for (Map<String, Object> m : result) { // 遍历结果
|
|
|
|
|
for (String k : m.keySet()) { // 遍历键
|
|
|
|
|
if (m.get(k) instanceof Date) { // 如果值是日期类型
|
|
|
|
|
m.put(k, sdf.format((Date) m.get(k))); // 格式化日期
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return R.ok().put("data", result);
|
|
|
|
|
return R.ok().put("data", result); // 返回成功结果
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* (按值统计)时间统计类型
|
|
|
|
|
* (按值统计)时间统计类型
|
|
|
|
|
* @param tableName 表名
|
|
|
|
|
* @param xColumnName X轴列名
|
|
|
|
|
* @param yColumnName Y轴列名
|
|
|
|
|
* @param timeStatType 时间统计类型
|
|
|
|
|
* @return 返回按值统计结果
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}/{timeStatType}")
|
|
|
|
|
public R valueDay(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
params.put("table", tableName);
|
|
|
|
|
params.put("xColumn", xColumnName);
|
|
|
|
|
params.put("yColumn", yColumnName);
|
|
|
|
|
params.put("timeStatType", timeStatType);
|
|
|
|
|
List<Map<String, Object>> result = commonService.selectTimeStatValue(params);
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
for(Map<String, Object> m : result) {
|
|
|
|
|
for(String k : m.keySet()) {
|
|
|
|
|
if(m.get(k) instanceof Date) {
|
|
|
|
|
m.put(k, sdf.format((Date)m.get(k)));
|
|
|
|
|
public R valueDay(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName,
|
|
|
|
|
@PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>(); // 参数封装
|
|
|
|
|
params.put("table", tableName); // 添加表名
|
|
|
|
|
params.put("xColumn", xColumnName); // 添加X轴列名
|
|
|
|
|
params.put("yColumn", yColumnName); // 添加Y轴列名
|
|
|
|
|
params.put("timeStatType", timeStatType); // 添加时间统计类型
|
|
|
|
|
List<Map<String, Object>> result = commonService.selectTimeStatValue(params); // 调用服务获取按值统计结果
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 日期格式化工具
|
|
|
|
|
for (Map<String, Object> m : result) { // 遍历结果
|
|
|
|
|
for (String k : m.keySet()) { // 遍历键
|
|
|
|
|
if (m.get(k) instanceof Date) { // 如果值是日期类型
|
|
|
|
|
m.put(k, sdf.format((Date) m.get(k))); // 格式化日期
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return R.ok().put("data", result);
|
|
|
|
|
return R.ok().put("data", result); // 返回成功结果
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 人脸比对
|
|
|
|
|
* @param face1 人脸1
|
|
|
|
|
* @param face2 人脸2
|
|
|
|
|
* @param request HTTP请求对象
|
|
|
|
|
* @return 返回比对分数
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/matchFace")
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
public R matchFace(String face1, String face2, HttpServletRequest request) {
|
|
|
|
|
if (client == null) { // 如果客户端未初始化
|
|
|
|
|
/*String AppID = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "AppID")).getValue();*/
|
|
|
|
|
String APIKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "APIKey")).getValue(); // 获取API Key
|
|
|
|
|
String SecretKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "SecretKey")).getValue(); // 获取Secret Key
|
|
|
|
|
String token = BaiduUtil.getAuth(APIKey, SecretKey); // 获取访问令牌
|
|
|
|
|
if (token == null) { // 如果令牌为空
|
|
|
|
|
return R.error("请在配置管理中正确配置APIKey和SecretKey"); // 返回错误信息
|
|
|
|
|
}
|
|
|
|
|
client = new AipFace(null, APIKey, SecretKey); // 初始化客户端
|
|
|
|
|
client.setConnectionTimeoutInMillis(2000); // 设置连接超时时间
|
|
|
|
|
client.setSocketTimeoutInMillis(60000); // 设置套接字超时时间
|
|
|
|
|
}
|
|
|
|
|
JSONObject res = null; // 响应结果
|
|
|
|
|
try {
|
|
|
|
|
File path = new File(ResourceUtils.getURL("classpath:static").getPath()); // 获取静态资源路径
|
|
|
|
|
if (!path.exists()) { // 如果路径不存在
|
|
|
|
|
path = new File(""); // 使用当前目录
|
|
|
|
|
}
|
|
|
|
|
File upload = new File(path.getAbsolutePath(), "/upload/"); // 创建上传目录
|
|
|
|
|
File file1 = new File(upload.getAbsolutePath(), face1); // 文件1
|
|
|
|
|
File file2 = new File(upload.getAbsolutePath(), face2); // 文件2
|
|
|
|
|
String img1 = Base64Util.encode(FileUtil.FileToByte(file1)); // 将文件1转换为Base64
|
|
|
|
|
String img2 = Base64Util.encode(FileUtil.FileToByte(file2)); // 将文件2转换为Base64
|
|
|
|
|
MatchRequest req1 = new MatchRequest(img1, "BASE64"); // 第一个人脸请求
|
|
|
|
|
MatchRequest req2 = new MatchRequest(img2, "BASE64"); // 第二个人脸请求
|
|
|
|
|
ArrayList<MatchRequest> requests = new ArrayList<MatchRequest>(); // 请求列表
|
|
|
|
|
requests.add(req1); // 添加第一个请求
|
|
|
|
|
requests.add(req2); // 添加第二个请求
|
|
|
|
|
res = client.match(requests); // 调用人脸比对接口
|
|
|
|
|
System.out.println(res.get("result")); // 打印比对结果
|
|
|
|
|
} catch (FileNotFoundException e) { // 文件未找到异常
|
|
|
|
|
e.printStackTrace(); // 打印堆栈信息
|
|
|
|
|
return R.error("文件不存在"); // 返回错误信息
|
|
|
|
|
} catch (IOException e) { // IO异常
|
|
|
|
|
e.printStackTrace(); // 打印堆栈信息
|
|
|
|
|
}
|
|
|
|
|
return R.ok().put("score", com.alibaba.fastjson.JSONObject.parse(res.getJSONObject("result").get("score").toString())); // 返回比对分数
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 人脸比对
|
|
|
|
|
*
|
|
|
|
|
* @param face1 人脸1
|
|
|
|
|
* @param face2 人脸2
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/matchFace")
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
public R matchFace(String face1, String face2,HttpServletRequest request) {
|
|
|
|
|
if(client==null) {
|
|
|
|
|
/*String AppID = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "AppID")).getValue();*/
|
|
|
|
|
String APIKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "APIKey")).getValue();
|
|
|
|
|
String SecretKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "SecretKey")).getValue();
|
|
|
|
|
String token = BaiduUtil.getAuth(APIKey, SecretKey);
|
|
|
|
|
if(token==null) {
|
|
|
|
|
return R.error("请在配置管理中正确配置APIKey和SecretKey");
|
|
|
|
|
}
|
|
|
|
|
client = new AipFace(null, APIKey, SecretKey);
|
|
|
|
|
client.setConnectionTimeoutInMillis(2000);
|
|
|
|
|
client.setSocketTimeoutInMillis(60000);
|
|
|
|
|
}
|
|
|
|
|
JSONObject res = null;
|
|
|
|
|
try {
|
|
|
|
|
File path = new File(ResourceUtils.getURL("classpath:static").getPath());
|
|
|
|
|
if(!path.exists()) {
|
|
|
|
|
path = new File("");
|
|
|
|
|
}
|
|
|
|
|
File upload = new File(path.getAbsolutePath(),"/upload/");
|
|
|
|
|
File file1 = new File(upload.getAbsolutePath()+"/"+face1);
|
|
|
|
|
File file2 = new File(upload.getAbsolutePath()+"/"+face2);
|
|
|
|
|
String img1 = Base64Util.encode(FileUtil.FileToByte(file1));
|
|
|
|
|
String img2 = Base64Util.encode(FileUtil.FileToByte(file2));
|
|
|
|
|
MatchRequest req1 = new MatchRequest(img1, "BASE64");
|
|
|
|
|
MatchRequest req2 = new MatchRequest(img2, "BASE64");
|
|
|
|
|
ArrayList<MatchRequest> requests = new ArrayList<MatchRequest>();
|
|
|
|
|
requests.add(req1);
|
|
|
|
|
requests.add(req2);
|
|
|
|
|
res = client.match(requests);
|
|
|
|
|
System.out.println(res.get("result"));
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return R.error("文件不存在");
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return R.ok().put("score", com.alibaba.fastjson.JSONObject.parse(res.getJSONObject("result").get("score").toString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|