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

人脸锁图片删除

上级 5d261d0a
...@@ -9,15 +9,13 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -9,15 +9,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import tech.glinfo.enbao.common.annotation.ApiLog; import tech.glinfo.enbao.common.annotation.ApiLog;
import tech.glinfo.enbao.common.annotation.Login; import tech.glinfo.enbao.common.annotation.Login;
import tech.glinfo.enbao.common.annotation.LoginUser;
import tech.glinfo.enbao.common.utils.ImageUtils; import tech.glinfo.enbao.common.utils.ImageUtils;
import tech.glinfo.enbao.common.utils.R; import tech.glinfo.enbao.common.utils.R;
import tech.glinfo.enbao.common.utils.StringUtils; import tech.glinfo.enbao.common.utils.StringUtils;
import tech.glinfo.enbao.modules.appuser.entity.AppUserEntity; import tech.glinfo.enbao.modules.oss.cloud.OSSFactory;
import tech.glinfo.enbao.modules.appuser.service.AppUserService;
import tech.glinfo.enbao.modules.service.BaiduApiService; import tech.glinfo.enbao.modules.service.BaiduApiService;
import tech.glinfo.enbao.modules.sh.entity.ShLockUserEntity; import tech.glinfo.enbao.modules.sh.entity.ShLockUserEntity;
import tech.glinfo.enbao.modules.sh.service.ShLockUserService; import tech.glinfo.enbao.modules.sh.service.OtherShLockUserService;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -28,7 +26,7 @@ import java.util.Map; ...@@ -28,7 +26,7 @@ import java.util.Map;
public class ShLockUserController { public class ShLockUserController {
@Autowired @Autowired
private ShLockUserService shLockUserService; private OtherShLockUserService otherShLockUserService;
@Autowired @Autowired
private BaiduApiService baiduApiService; private BaiduApiService baiduApiService;
...@@ -43,7 +41,7 @@ public class ShLockUserController { ...@@ -43,7 +41,7 @@ public class ShLockUserController {
Integer id = (Integer) params.get("id"); Integer id = (Integer) params.get("id");
Integer deviceId = (Integer) params.get("deviceId"); Integer deviceId = (Integer) params.get("deviceId");
String img = (String) params.get("img"); String img = (String) params.get("img");
ShLockUserEntity lockUser = shLockUserService.getById(id); ShLockUserEntity lockUser = otherShLockUserService.getById(id);
if (lockUser == null) { if (lockUser == null) {
return R.error("用户不存在"); return R.error("用户不存在");
} }
...@@ -56,7 +54,9 @@ public class ShLockUserController { ...@@ -56,7 +54,9 @@ public class ShLockUserController {
//保存人脸参数 //保存人脸参数
lockUser.setFaceImg(img); lockUser.setFaceImg(img);
lockUser.setFaceParam(faceParam.toString()); lockUser.setFaceParam(faceParam.toString());
shLockUserService.updateById(lockUser); otherShLockUserService.updateById(lockUser);
} else {
return R.error("添加失败");
} }
return R.ok(); return R.ok();
} }
...@@ -67,13 +67,19 @@ public class ShLockUserController { ...@@ -67,13 +67,19 @@ public class ShLockUserController {
@ApiLog("删除人脸") @ApiLog("删除人脸")
public R deleteFaceLock(@RequestBody Map<String, Object> params) { public R deleteFaceLock(@RequestBody Map<String, Object> params) {
Integer id = (Integer) params.get("id"); Integer id = (Integer) params.get("id");
ShLockUserEntity lockUser = shLockUserService.getById(id); ShLockUserEntity lockUser = otherShLockUserService.getById(id);
if (lockUser == null) { if (lockUser == null) {
return R.error("用户不存在"); return R.error("用户不存在");
} }
if (lockUser.getFaceParam() != null) { if (lockUser.getFaceParam() != null) {
String[] faceParam = lockUser.getFaceParam().split(","); String[] faceParam = lockUser.getFaceParam().split(",");
baiduApiService.delUser(faceParam[0], faceParam[1], faceParam[2]); JSONObject jsonObject = baiduApiService.delUser(faceParam[0], faceParam[1], faceParam[2]);
if (jsonObject != null && jsonObject.has("error_code") && jsonObject.getInt("error_code") == 0) {
otherShLockUserService.deleteFaceLock(id);
OSSFactory.build().delete(lockUser.getFaceImg());
} else {
return R.error("添加失败");
}
} }
return R.ok(); return R.ok();
} }
...@@ -89,7 +95,7 @@ public class ShLockUserController { ...@@ -89,7 +95,7 @@ public class ShLockUserController {
if (StringUtils.isBlank(lockId, userId, userName)) { if (StringUtils.isBlank(lockId, userId, userName)) {
return R.error("参数为空!"); return R.error("参数为空!");
} }
ShLockUserEntity lockUserEntity = shLockUserService.getOne(new QueryWrapper<ShLockUserEntity>().eq("lock_id", lockId).eq("user_id", userId)); ShLockUserEntity lockUserEntity = otherShLockUserService.getOne(new QueryWrapper<ShLockUserEntity>().eq("lock_id", lockId).eq("user_id", userId));
if (lockUserEntity != null) { if (lockUserEntity != null) {
return R.error("用户ID不能重复!"); return R.error("用户ID不能重复!");
} }
...@@ -97,7 +103,7 @@ public class ShLockUserController { ...@@ -97,7 +103,7 @@ public class ShLockUserController {
entity.setLockId(lockId); entity.setLockId(lockId);
entity.setUserId(userId); entity.setUserId(userId);
entity.setUserName(userName); entity.setUserName(userName);
boolean flag = shLockUserService.save(entity); boolean flag = otherShLockUserService.save(entity);
return flag ? R.ok() : R.error("新增失败!"); return flag ? R.ok() : R.error("新增失败!");
} }
...@@ -113,7 +119,7 @@ public class ShLockUserController { ...@@ -113,7 +119,7 @@ public class ShLockUserController {
if (StringUtils.isBlank(id, userId, userName)) { if (StringUtils.isBlank(id, userId, userName)) {
return R.error("参数为空!"); return R.error("参数为空!");
} }
ShLockUserEntity lockUserEntity = shLockUserService.getOne(new QueryWrapper<ShLockUserEntity>().eq("lock_id", lockId).eq("user_id", userId)); ShLockUserEntity lockUserEntity = otherShLockUserService.getOne(new QueryWrapper<ShLockUserEntity>().eq("lock_id", lockId).eq("user_id", userId));
if (!lockUserEntity.getId().equals(id)) { if (!lockUserEntity.getId().equals(id)) {
return R.error("用户ID不能重复!"); return R.error("用户ID不能重复!");
} }
...@@ -121,7 +127,7 @@ public class ShLockUserController { ...@@ -121,7 +127,7 @@ public class ShLockUserController {
entity.setId(id); entity.setId(id);
entity.setUserId(userId); entity.setUserId(userId);
entity.setUserName(userName); entity.setUserName(userName);
boolean flag = shLockUserService.updateById(entity); boolean flag = otherShLockUserService.updateById(entity);
return flag ? R.ok() : R.error("修改失败!"); return flag ? R.ok() : R.error("修改失败!");
} }
...@@ -134,7 +140,7 @@ public class ShLockUserController { ...@@ -134,7 +140,7 @@ public class ShLockUserController {
if (StringUtils.isBlank(id)) { if (StringUtils.isBlank(id)) {
return R.error("参数为空!"); return R.error("参数为空!");
} }
boolean flag = shLockUserService.removeById(id); boolean flag = otherShLockUserService.removeById(id);
return flag ? R.ok() : R.error("删除失败!"); return flag ? R.ok() : R.error("删除失败!");
} }
...@@ -144,7 +150,7 @@ public class ShLockUserController { ...@@ -144,7 +150,7 @@ public class ShLockUserController {
@ApiLog("锁用户列表") @ApiLog("锁用户列表")
public R list(@RequestParam Map<String, Object> params) { public R list(@RequestParam Map<String, Object> params) {
Integer lockId = Integer.parseInt((String) params.get("lockId")); Integer lockId = Integer.parseInt((String) params.get("lockId"));
List<ShLockUserEntity> list = shLockUserService.list(new QueryWrapper<ShLockUserEntity>().eq("lock_id", lockId)); List<ShLockUserEntity> list = otherShLockUserService.list(new QueryWrapper<ShLockUserEntity>().eq("lock_id", lockId));
return R.ok().put("list", list); return R.ok().put("list", list);
} }
......
package tech.glinfo.enbao.modules.sh.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import tech.glinfo.enbao.modules.sh.entity.ShLockUserEntity;
/**
* @author lyt
* @date 2022/3/1 10:57
*/
@Mapper
public interface OtherShLockUserDao extends BaseMapper<ShLockUserEntity> {
@Update("<script>" +
" UPDATE sh_lock_user SET face_param = NULL, face_img = NULL WHERE id = ${id}"
+
" </script>")
void deleteFaceLock(Integer id);
}
package tech.glinfo.enbao.modules.sh.service;
import com.baomidou.mybatisplus.extension.service.IService;
import tech.glinfo.enbao.modules.sh.entity.ShLockUserEntity;
/**
* @author lyt
* @date 2022/3/1 10:56
*/
public interface OtherShLockUserService extends IService<ShLockUserEntity> {
void deleteFaceLock(Integer id);
}
package tech.glinfo.enbao.modules.sh.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import tech.glinfo.enbao.modules.sh.dao.OtherShLockUserDao;
import tech.glinfo.enbao.modules.sh.entity.ShLockUserEntity;
import tech.glinfo.enbao.modules.sh.service.OtherShLockUserService;
/**
* @author lyt
* @date 2022/3/1 10:56
*/@Service("otherShLockUserService")
public class OtherShLockUserServiceImpl extends ServiceImpl<OtherShLockUserDao, ShLockUserEntity> implements OtherShLockUserService {
@Override
public void deleteFaceLock(Integer id) {
this.baseMapper.deleteFaceLock(id);
}
}
...@@ -50,4 +50,9 @@ public class AliyunCloudStorageService extends CloudStorageService { ...@@ -50,4 +50,9 @@ public class AliyunCloudStorageService extends CloudStorageService {
public String uploadSuffix(InputStream inputStream, String suffix) { public String uploadSuffix(InputStream inputStream, String suffix) {
return upload(inputStream, getPath(config.getAliyunPrefix(), suffix)); return upload(inputStream, getPath(config.getAliyunPrefix(), suffix));
} }
@Override
public Boolean delete(String fileName) {
return null;
}
} }
...@@ -67,4 +67,8 @@ public abstract class CloudStorageService { ...@@ -67,4 +67,8 @@ public abstract class CloudStorageService {
*/ */
public abstract String uploadSuffix(InputStream inputStream, String suffix); public abstract String uploadSuffix(InputStream inputStream, String suffix);
/**
*/
public abstract Boolean delete(String fileName);
} }
...@@ -85,4 +85,9 @@ public class QcloudCloudStorageService extends CloudStorageService { ...@@ -85,4 +85,9 @@ public class QcloudCloudStorageService extends CloudStorageService {
public String uploadSuffix(InputStream inputStream, String suffix) { public String uploadSuffix(InputStream inputStream, String suffix) {
return upload(inputStream, getPath(config.getQcloudPrefix(), suffix)); return upload(inputStream, getPath(config.getQcloudPrefix(), suffix));
} }
@Override
public Boolean delete(String fileName) {
return null;
}
} }
package tech.glinfo.enbao.modules.oss.cloud; package tech.glinfo.enbao.modules.oss.cloud;
import com.qiniu.storage.BucketManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tech.glinfo.enbao.common.exception.RRException; import tech.glinfo.enbao.common.exception.RRException;
import com.qiniu.common.Zone; import com.qiniu.common.Zone;
import com.qiniu.http.Response; import com.qiniu.http.Response;
...@@ -19,6 +22,7 @@ import java.io.InputStream; ...@@ -19,6 +22,7 @@ import java.io.InputStream;
* @author Mark sunlightcs@gmail.com * @author Mark sunlightcs@gmail.com
*/ */
public class QiniuCloudStorageService extends CloudStorageService { public class QiniuCloudStorageService extends CloudStorageService {
private final static Logger logger = LoggerFactory.getLogger(QiniuCloudStorageService.class);
private UploadManager uploadManager; private UploadManager uploadManager;
private String token; private String token;
private String key; private String key;
...@@ -76,6 +80,22 @@ public class QiniuCloudStorageService extends CloudStorageService { ...@@ -76,6 +80,22 @@ public class QiniuCloudStorageService extends CloudStorageService {
return upload(inputStream, getPath(config.getQiniuPrefix(), suffix)); return upload(inputStream, getPath(config.getQiniuPrefix(), suffix));
} }
@Override
public Boolean delete(String fileName) {
BucketManager bucketManager = new BucketManager(Auth.create(config.getQiniuAccessKey(), config.getQiniuSecretKey()), new Configuration(Zone.autoZone()));
try {
Response res = bucketManager.delete(config.getQiniuBucketName(), fileName);
if (!res.isOK()) {
logger.error("删除图片七牛出错:" + res.toString());
return false;
}
} catch (Exception e) {
logger.error("删除图片七牛出错", e);
return false;
}
return true;
}
public String getToken() { public String getToken() {
return token; return token;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论