|
|
@@ -3,32 +3,40 @@ package com.zhongshu.card.server.core.service.projectAbout;
|
|
|
import com.github.microservice.auth.client.model.UserFaceConfidenceModel;
|
|
|
import com.github.microservice.auth.client.model.UserFaceUploadModel;
|
|
|
import com.github.microservice.auth.client.service.UserFaceService;
|
|
|
+import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
+import com.github.microservice.net.ResultMessage;
|
|
|
import com.google.common.collect.Lists;
|
|
|
-import com.zhongshu.card.client.model.projectAbout.OrgUserFaceModel;
|
|
|
-import com.zhongshu.card.client.model.projectAbout.OrgUserFaceParam;
|
|
|
+import com.zhongshu.card.client.model.projectAbout.orgFace.OrgUserFaceAuditParam;
|
|
|
+import com.zhongshu.card.client.model.projectAbout.orgFace.OrgUserFaceModel;
|
|
|
+import com.zhongshu.card.client.model.projectAbout.orgFace.OrgUserFaceParam;
|
|
|
+import com.zhongshu.card.client.model.projectAbout.orgFace.OrgUserFaceSearch;
|
|
|
import com.zhongshu.card.client.model.projectAbout.projectCommon.ProjectCommonConfigModel;
|
|
|
+import com.zhongshu.card.client.type.common.AuditState;
|
|
|
import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
import com.zhongshu.card.server.core.dao.projectAbout.OrgUserFaceDao;
|
|
|
+import com.zhongshu.card.server.core.domain.org.OrganizationUser;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
import com.zhongshu.card.server.core.domain.projectAbout.OrgUserFace;
|
|
|
import com.zhongshu.card.server.core.service.base.CommonService;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.service.devices.permiss.DevicePermissEventService;
|
|
|
+import com.zhongshu.card.server.core.service.org.OrganizationUserServiceImpl;
|
|
|
+import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
-import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 项目人脸管理
|
|
|
@@ -64,6 +72,12 @@ public class OrgUserFaceService extends SuperService {
|
|
|
@Autowired
|
|
|
private ProjectCommonConfigService projectCommonConfigService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OrganizationUserServiceImpl organizationUserServiceImpl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserAccountServiceImpl userAccountService;
|
|
|
+
|
|
|
/**
|
|
|
* 保存用户人脸信息
|
|
|
*
|
|
|
@@ -82,25 +96,132 @@ public class OrgUserFaceService extends SuperService {
|
|
|
if (StringUtils.isEmpty(userId)) {
|
|
|
userId = getCurrentUserId();
|
|
|
}
|
|
|
+ String img = param.getImg();
|
|
|
+ // 判断人脸可信度
|
|
|
+ ResultContent<ProjectCommonConfigModel> configContent = conformFace(img, projectOid);
|
|
|
+ if (configContent.isFailed()) {
|
|
|
+ return ResultContent.buildFail(configContent.getMsg());
|
|
|
+ }
|
|
|
+ ProjectCommonConfigModel configModel = configContent.getContent();
|
|
|
+ // 是否允许管理人脸信息
|
|
|
+ Boolean isAllowUpdateFace = configModel.getIsAllowUpdateFace();
|
|
|
+ if (isAllowUpdateFace == null || !isAllowUpdateFace) {
|
|
|
+ return ResultContent.buildFail("系统不允许管理人脸信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 人脸是否需要审核
|
|
|
+ Boolean isExamineFace = configModel.getIsExamineFace();
|
|
|
+
|
|
|
+ int maxFaceNumber = configModel.getMaxFaceNumber();
|
|
|
+ int number = orgUserFaceDao.countByUserIdAndProjectOid(userId, projectOid);
|
|
|
+ if (number >= maxFaceNumber) {
|
|
|
+ return ResultContent.buildFail("");
|
|
|
+ }
|
|
|
+ // 所属用户userId
|
|
|
+ UserAccount userAccount = userCountDao.findTopByUserId(userId);
|
|
|
+ OrganizationUser organizationUser = organizationUserServiceImpl.getUserTopInProjectBindOrgUserInfo(projectOid, userAccount);
|
|
|
+ if (organizationUser == null) {
|
|
|
+ return ResultContent.buildFail("用户未加入项目");
|
|
|
+ }
|
|
|
+
|
|
|
String updateFaceFileId = "";
|
|
|
- OrgUserFace orgUserFace = orgUserFaceDao.findTopByUserIdAndProjectOid(userId, projectOid);
|
|
|
- if (ObjectUtils.isEmpty(orgUserFace)) {
|
|
|
- orgUserFace = new OrgUserFace();
|
|
|
- initEntityNoCheckOid(orgUserFace);
|
|
|
- } else {
|
|
|
+ OrgUserFace orgUserFace = null;
|
|
|
+ if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
+ orgUserFace = orgUserFaceDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(orgUserFace)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
initUpdateEntity(orgUserFace);
|
|
|
updateFaceFileId = orgUserFace.getUpdateFaceFileId();
|
|
|
+ } else {
|
|
|
+ orgUserFace = new OrgUserFace();
|
|
|
+ initEntityNoCheckOid(orgUserFace);
|
|
|
}
|
|
|
BeanUtils.copyProperties(param, orgUserFace, "id");
|
|
|
orgUserFace.setProjectOid(projectOid);
|
|
|
-
|
|
|
- // 所属用户userId
|
|
|
- UserAccount userAccount = userCountDao.findTopByUserId(userId);
|
|
|
+ orgUserFace.setOrganizationUser(organizationUser);
|
|
|
+ orgUserFace.setUpdateFaceFileId(updateFaceFileId);
|
|
|
orgUserFace.setUserId(userId);
|
|
|
if (ObjectUtils.isNotEmpty(userAccount)) {
|
|
|
orgUserFace.setUserAccount(userAccount);
|
|
|
+ orgUserFace.setUserName(userAccount.getName());
|
|
|
+ orgUserFace.setPhone(userAccount.getPhone());
|
|
|
+ }
|
|
|
+ if (isExamineFace != null && isExamineFace) {
|
|
|
+ // 需要审核
|
|
|
+ orgUserFace.setIsCanUsed(Boolean.FALSE);
|
|
|
+ orgUserFace.setAuditState(AuditState.WaitAudit);
|
|
|
+ } else {
|
|
|
+ // 不需要审核
|
|
|
+ ResultContent<String> resultContent = syncFace(orgUserFace);
|
|
|
+ if (resultContent.isFailed()) {
|
|
|
+ return ResultContent.buildFail(resultContent.getMsg());
|
|
|
+ }
|
|
|
+ updateFaceFileId = resultContent.getContent();
|
|
|
+ orgUserFace.setUpdateFaceFileId(updateFaceFileId);
|
|
|
+ orgUserFace.setIsCanUsed(Boolean.TRUE);
|
|
|
+ orgUserFace.setAuditState(AuditState.Audited);
|
|
|
+ orgUserFace.setAuditUserId(getCurrentUserId());
|
|
|
+ orgUserFace.setAuditRemark("自动通过");
|
|
|
+ orgUserFace.setAuditTime(System.currentTimeMillis());
|
|
|
+ }
|
|
|
+ orgUserFaceDao.save(orgUserFace);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent deleteFace(String id) {
|
|
|
+ OrgUserFace orgUserFace = orgUserFaceDao.findTopById(id);
|
|
|
+ if (orgUserFace == null) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ ResultContent<ProjectCommonConfigModel> content = projectCommonConfigService.getConfigInfoAndCheck(orgUserFace.getProjectOid());
|
|
|
+ if (content.isFailed()) {
|
|
|
+ return ResultContent.buildFail(content.getMsg());
|
|
|
+ }
|
|
|
+ ProjectCommonConfigModel configModel = content.getContent();
|
|
|
+ Boolean isAllowUpdateFace = configModel.getIsAllowUpdateFace();
|
|
|
+ if (isAllowUpdateFace == null || !isAllowUpdateFace) {
|
|
|
+ return ResultContent.buildFail("系统不允许删除人脸信息");
|
|
|
}
|
|
|
- String faceBase64 = commonService.getUrlFileBase64(param.getImg());
|
|
|
+ if (StringUtils.isNotEmpty(orgUserFace.getUpdateFaceFileId())) {
|
|
|
+ com.github.microservice.auth.client.content.ResultContent resultContent = userFaceService.delete(orgUserFace.getUserId(), orgUserFace.getUpdateFaceFileId());
|
|
|
+ if (resultContent.isFailed()) {
|
|
|
+ return ResultContent.buildFail(resultContent.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ orgUserFaceDao.delete(orgUserFace);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<Page<OrgUserFaceModel>> page(OrgUserFaceSearch param, Pageable pageable) {
|
|
|
+ Page<OrgUserFace> page = orgUserFaceDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审核
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent auditFace(OrgUserFaceAuditParam param) {
|
|
|
+ OrgUserFace orgUserFace = orgUserFaceDao.findTopById(param.getId());
|
|
|
+ if (orgUserFace == null) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ if (param.getAuditState() != AuditState.WaitAudit) {
|
|
|
+ return ResultContent.buildFail("数据已审核");
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(param, orgUserFace, "id");
|
|
|
+ orgUserFace.setAuditTime(System.currentTimeMillis());
|
|
|
+ orgUserFaceDao.save(orgUserFace);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResultContent<String> syncFace(OrgUserFace orgUserFace) {
|
|
|
+ String updateFaceFileId = orgUserFace.getUpdateFaceFileId();
|
|
|
+ String userId = orgUserFace.getUserId();
|
|
|
+ String faceBase64 = commonService.getUrlFileBase64(orgUserFace.getImg());
|
|
|
// 维护管理权限中心用户的头像信息
|
|
|
UserFaceUploadModel userFaceUploadModel = new UserFaceUploadModel();
|
|
|
userFaceUploadModel.setUserId(userId);
|
|
|
@@ -111,48 +232,39 @@ public class OrgUserFaceService extends SuperService {
|
|
|
return ResultContent.buildFail(content.getMsg());
|
|
|
}
|
|
|
updateFaceFileId = content.getContent();
|
|
|
-
|
|
|
- orgUserFace.setUpdateFaceFileId(updateFaceFileId);
|
|
|
- orgUserFaceDao.save(orgUserFace);
|
|
|
-
|
|
|
- String groupId = CommonUtil.UUID();
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("groupId", groupId);
|
|
|
- // 通知人脸信息发送变化
|
|
|
- devicePermissEventService.sendUserInfoChangeEvent(orgUserFace.getUserId(), orgUserFace.getProjectOid(), map);
|
|
|
- return ResultContent.buildSuccess();
|
|
|
+// String groupId = CommonUtil.UUID();
|
|
|
+// Map<String, Object> map = new HashMap<>();
|
|
|
+// map.put("groupId", groupId);
|
|
|
+// // 通知人脸信息发送变化
|
|
|
+// devicePermissEventService.sendUserInfoChangeEvent(orgUserFace.getUserId(), orgUserFace.getProjectOid(), map);
|
|
|
+ return ResultContent.buildSuccess(updateFaceFileId);
|
|
|
}
|
|
|
|
|
|
- public List<OrgUserFace> getUserFaces(String userId, String oid) {
|
|
|
- List<OrgUserFace> list = new ArrayList<>();
|
|
|
+ public OrgUserFace getUserFace(String userId, String oid) {
|
|
|
if (StringUtils.isNotEmpty(userId) && StringUtils.isNotEmpty(oid)) {
|
|
|
- list = orgUserFaceDao.findByUserIdAndProjectOid(userId, oid);
|
|
|
+ return orgUserFaceDao.findTopByUserIdAndProjectOidOrderByCreateTimeDesc(userId, oid);
|
|
|
}
|
|
|
- return list;
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
- public ResultContent<OrgUserFaceModel> getUserFaceModel(String userId, String projectOid) {
|
|
|
- if (StringUtils.isEmpty(userId)) {
|
|
|
- // 得到当前用户的userId
|
|
|
- userId = getCurrentUserId();
|
|
|
- }
|
|
|
+ public ResultContent<List<OrgUserFaceModel>> getCurrentUserAllFace(String projectOid) {
|
|
|
+ String userId = getCurrentUserId();
|
|
|
if (StringUtils.isEmpty(projectOid)) {
|
|
|
- // 得到header里面的项目oid
|
|
|
projectOid = getCurrentProjectOid();
|
|
|
}
|
|
|
if (StringUtils.isEmpty(projectOid)) {
|
|
|
- return ResultContent.buildFail("projectOid为空");
|
|
|
+ return ResultContent.buildFail("项目oid不能为空");
|
|
|
}
|
|
|
-
|
|
|
- OrgUserFace entity = getUserFace(userId, projectOid);
|
|
|
- return ResultContent.buildSuccess(toModel(entity));
|
|
|
+ return getUserAllFace(userId, projectOid);
|
|
|
}
|
|
|
|
|
|
- public OrgUserFace getUserFace(String userId, String oid) {
|
|
|
- if (StringUtils.isNotEmpty(userId) && StringUtils.isNotEmpty(oid)) {
|
|
|
- return orgUserFaceDao.findTopByUserIdAndProjectOid(userId, oid);
|
|
|
+ public ResultContent<List<OrgUserFaceModel>> getUserAllFace(String userId, String projectOid) {
|
|
|
+ List<OrgUserFace> list = orgUserFaceDao.findByUserIdAndProjectOidOrderByCreateTimeDesc(userId, projectOid);
|
|
|
+ List<OrgUserFaceModel> models = new ArrayList<>();
|
|
|
+ if (ObjectUtils.isNotEmpty(list)) {
|
|
|
+ models = list.stream().map(this::toModel).collect(Collectors.toList());
|
|
|
}
|
|
|
- return null;
|
|
|
+ return ResultContent.buildSuccess(models);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -183,11 +295,11 @@ public class OrgUserFaceService extends SuperService {
|
|
|
if (StringUtils.isEmpty(projectOid)) {
|
|
|
return ResultContent.buildFail("项目oid信息为空");
|
|
|
}
|
|
|
- ProjectCommonConfigModel projectCommonConfig = projectCommonConfigService.getInfoByOid(projectOid);
|
|
|
- if (ObjectUtils.isEmpty(projectCommonConfig)) {
|
|
|
- return ResultContent.buildFail("项目为配置人脸可信度");
|
|
|
+ ResultContent<ProjectCommonConfigModel> content = projectCommonConfigService.getConfigInfoAndCheck(projectOid);
|
|
|
+ if (content.isFailed()) {
|
|
|
+ return ResultContent.buildFail(content.getMsg());
|
|
|
}
|
|
|
- return conformFace(url, projectCommonConfig);
|
|
|
+ return conformFace(url, content.getContent());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -224,6 +336,8 @@ public class OrgUserFaceService extends SuperService {
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
model = new OrgUserFaceModel();
|
|
|
BeanUtils.copyProperties(entity, model);
|
|
|
+ model.setUserAccount(userAccountService.toSimpleModel(entity.getUserAccount()));
|
|
|
+ model.setOrganizationUser(organizationUserServiceImpl.toModel(entity.getOrganizationUser()));
|
|
|
}
|
|
|
return model;
|
|
|
}
|