提交 6ebb1b9c authored 作者: 林业通's avatar 林业通

人脸锁修改

上级 315c90be
......@@ -186,7 +186,7 @@ public class FaceLockParse implements IParse {
long start = System.currentTimeMillis();
String tips = null;
//人脸比对
JSONObject res = baiduApiService.search(content, "facelock"+device.getId());//组名:facelock+设备ID
JSONObject res = baiduApiService.search(content, "glfacelock"+device.getId());//组名:facelock+设备ID
boolean check = false;
if(res != null && res.get("result") != null && !"null".equals(res.get("result").toString())) {
JSONObject result = res.getJSONObject("result");
......
......@@ -2,21 +2,23 @@ package tech.glinfo.enbao.modules.sh.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tech.glinfo.enbao.common.annotation.ApiLog;
import tech.glinfo.enbao.common.annotation.Login;
import tech.glinfo.enbao.common.utils.PageUtils;
import tech.glinfo.enbao.common.utils.Query;
import tech.glinfo.enbao.common.annotation.LoginUser;
import tech.glinfo.enbao.common.utils.ImageUtils;
import tech.glinfo.enbao.common.utils.R;
import tech.glinfo.enbao.common.utils.StringUtils;
import tech.glinfo.enbao.modules.appuser.entity.AppUserEntity;
import tech.glinfo.enbao.modules.appuser.service.AppUserService;
import tech.glinfo.enbao.modules.service.BaiduApiService;
import tech.glinfo.enbao.modules.sh.entity.ShLockUserEntity;
import tech.glinfo.enbao.modules.sh.service.ShLockUserService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -28,6 +30,53 @@ public class ShLockUserController {
@Autowired
private ShLockUserService shLockUserService;
@Autowired
private BaiduApiService baiduApiService;
private static final String GROUPID = "glfacelock";//
@Login
@PostMapping("addFaceLock")
@ApiOperation("添加人脸")
@ApiLog("添加人脸")
public R addFaceLock(@RequestBody Map<String, Object> params) {
Integer id = (Integer) params.get("id");
Integer deviceId = (Integer) params.get("deviceId");
String img = (String) params.get("img");
ShLockUserEntity lockUser = shLockUserService.getById(id);
if (lockUser == null) {
return R.error("用户不存在");
}
StringBuilder faceParam = new StringBuilder();
//添加人脸
JSONObject jsonObject = baiduApiService.addUser(ImageUtils.img2Base64(img), lockUser.getId().toString(), GROUPID + deviceId, lockUser.getUserName());
if (jsonObject != null && jsonObject.has("error_code") && jsonObject.getInt("error_code") == 0) {
JSONObject result = jsonObject.getJSONObject("result");
faceParam.append(lockUser.getId().toString()).append(",").append(GROUPID).append(deviceId).append(",").append(result.getString("face_token"));
//保存人脸参数
lockUser.setFaceParam(faceParam.toString());
shLockUserService.updateById(lockUser);
}
return R.ok();
}
@Login
@PostMapping("deleteFaceLock")
@ApiOperation("删除人脸")
@ApiLog("删除人脸")
public R deleteFaceLock(@RequestBody Map<String, Object> params) {
Integer id = (Integer) params.get("id");
ShLockUserEntity lockUser = shLockUserService.getById(id);
if (lockUser == null) {
return R.error("用户不存在");
}
if (lockUser.getFaceParam() != null) {
String[] faceParam = lockUser.getFaceParam().split(",");
baiduApiService.delUser(faceParam[0], faceParam[1], faceParam[2]);
}
return R.ok();
}
@Login
@PostMapping("save")
@ApiOperation("保存用户")
......
......@@ -36,6 +36,10 @@ public class ShLockUserEntity implements Serializable {
* 用户名称
*/
private String userName;
/**
* 锁人脸参数
*/
private String faceParam;
/**
* 创建时间
*/
......
......@@ -9,6 +9,7 @@
<result property="userId" column="user_id"/>
<result property="lockId" column="lock_id"/>
<result property="userName" column="user_name"/>
<result property="faceParam" column="face_param"/>
<result property="createDate" column="create_date"/>
</resultMap>
......
......@@ -322,3 +322,6 @@ CREATE TABLE `sh_lock_user` (
PRIMARY KEY (`id`) USING BTREE,
KEY `sh_lock_user_lock_id` (`lock_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='锁用户';
alter table sh_lock_user add `face_param` varchar(255) DEFAULT NULL COMMENT '锁人脸参数' after `user_name` ;
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论