From 9234c98ef22cbb173b2e3c63c7c72dbeddf4faee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=8D=E7=BC=96=E8=AF=91=E5=B7=A5=E4=BD=9C=E5=8C=BA?= Date: Wed, 6 May 2026 00:34:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20replace=20PersonAuditServiceImpl=20with?= =?UTF-8?q?=20cleaned=20alt=20version=20(38=E2=86=9216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Alt version preserves generics (0 raw List, 0 Object casts). Pre-cleaned: lambda fixes + computeIfAbsent fix + array comma removal. Total: 200→122 (-78, -39%) --- .../service/PersonAuditServiceImpl.java | 1544 +++++++++-------- 1 file changed, 775 insertions(+), 769 deletions(-) diff --git a/maven-ninca-common-component-organization/cwos-component-organization-service/src/main/java/cn/cloudwalk/service/organization/service/PersonAuditServiceImpl.java b/maven-ninca-common-component-organization/cwos-component-organization-service/src/main/java/cn/cloudwalk/service/organization/service/PersonAuditServiceImpl.java index 3498943d..4ac36d86 100644 --- a/maven-ninca-common-component-organization/cwos-component-organization-service/src/main/java/cn/cloudwalk/service/organization/service/PersonAuditServiceImpl.java +++ b/maven-ninca-common-component-organization/cwos-component-organization-service/src/main/java/cn/cloudwalk/service/organization/service/PersonAuditServiceImpl.java @@ -1,7 +1,6 @@ package cn.cloudwalk.service.organization.service; // 业务服务 import cn.cloudwalk.client.account.verify.param.CheckCaptchaParam; -import cn.cloudwalk.client.account.verify.service.AcCaptchaService; import cn.cloudwalk.client.aggregate.group.param.AgFeatureExtractParam; import cn.cloudwalk.client.aggregate.group.result.AgFeatureExtractResult; import cn.cloudwalk.client.organization.common.constant.ImageStoreConstants; @@ -36,10 +35,11 @@ import cn.cloudwalk.client.organization.service.PersonZoneRefService; import cn.cloudwalk.client.organization.service.store.param.CpFaceDetectParam; import cn.cloudwalk.client.organization.service.store.param.QueryPersonRegistryParam; import cn.cloudwalk.client.organization.service.store.result.DeviceResult; +import cn.cloudwalk.client.organization.service.store.result.LabelResult; +import cn.cloudwalk.client.organization.service.store.result.OrganizationResult; import cn.cloudwalk.client.organization.service.store.result.PersonPropertiesResult; import cn.cloudwalk.client.organization.service.store.result.PersonRegistryResult; import cn.cloudwalk.client.organization.service.store.service.CpImageStoreToolService; -import cn.cloudwalk.client.organization.service.store.service.PersonRegistryService; import cn.cloudwalk.cloud.annotation.CloudwalkParamsValidate; import cn.cloudwalk.cloud.context.CloudwalkCallContext; import cn.cloudwalk.cloud.exception.ServiceException; @@ -47,6 +47,7 @@ import cn.cloudwalk.cloud.page.CloudwalkPageAble; import cn.cloudwalk.cloud.page.CloudwalkPageInfo; import cn.cloudwalk.cloud.result.CloudwalkResult; import cn.cloudwalk.cloud.serial.UUIDSerial; +import cn.cloudwalk.cloud.utils.BeanCopyUtils; import cn.cloudwalk.data.organization.dto.ImageInfoDto; import cn.cloudwalk.data.organization.dto.ImgStoreAuditUserQueryDto; import cn.cloudwalk.data.organization.dto.ImgStorePersonAuditQueryDto; @@ -59,9 +60,6 @@ import cn.cloudwalk.data.organization.mapper.ImgStorePersonPropertiesMapper; import cn.cloudwalk.service.organization.common.Base64Utils; import cn.cloudwalk.service.organization.common.OpenCvUtils; import cn.cloudwalk.service.organization.common.ToolUtil; -import cn.cloudwalk.service.organization.service.CpImageStorePersonSynManager; -import cn.cloudwalk.service.organization.service.ImgPersonHandler; -import cn.cloudwalk.service.organization.service.PersonFileServiceImpl; import cn.cloudwalk.service.organization.service.feign.PineappleEngineClient; import cn.cloudwalk.service.organization.service.feign.ZoneFeignClient; import cn.cloudwalk.service.organization.utils.BeanCopyUtils; @@ -79,8 +77,6 @@ import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; -import java.util.Base64; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; @@ -103,768 +99,778 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.ReflectionUtils; import org.springside.modules.utils.Collections3; - @Service -public class PersonAuditServiceImpl -implements IPersonAuditServcie { - protected final Logger logger = LoggerFactory.getLogger(this.getClass()); - @Autowired - private MessageSource messageSource; - @Value(value="${imageQualityScore}") - private Double imgQualityScore; - @Value(value="${ocr.card.face.score:0.65}") - private Double faceCompareScore; - @Autowired - private ImgStorePersonAuditMapper imgStorePersonAuditMapper; - @Resource - private ImgStorePersonPropertiesMapper imgStorePersonPropertiesMapper; - @Autowired - private PersonFileService personFileService; - @Autowired - private ImgStorePersonService imgStorePersonService; - @Autowired - private ImgPersonHandler imgPersonHandler; - @Autowired - private PersonRegistryService personRegistryService; - @Autowired - private AcCaptchaService captchaService; - @Autowired - private CpImageStoreToolService cpImageStoreToolService; - @Autowired - private CpImageStorePersonSynManager cpImageStorePersonSynManager; - @Autowired - private OpenCvUtils openCvUtils; - @Autowired - private UUIDSerial uuidSerial; - @Resource - private PineappleEngineClient pineappleClient; - @Autowired - private PersonZoneRefService personZoneRefService; - @Autowired - private ZoneFeignClient zoneFeignClient; - - @CloudwalkParamsValidate - public CloudwalkResult add(AddPersonAuditParam param, CloudwalkCallContext context) throws ServiceException { - boolean syncAccount; - this.logger.debug("添加注册记录,请求参数:[{}]", (Object)JSON.toJSONString((Object)param)); - this.checkSource(param); - String businessId = StringUtils.isEmpty((CharSequence)param.getBusinessId()) ? context.getCompany().getCompanyId() : param.getBusinessId(); - boolean bl = syncAccount = param.getCreateSysAccount() != null && param.getCreateSysAccount().intValue() == 1; - if (syncAccount && StringUtils.isBlank((CharSequence)param.getSysAccountId())) { - String errorMessage = this.messageSource.getMessage("53014027", null, LocaleContextHolder.getLocale()); - throw new ServiceException("53014027", errorMessage); - } - String auditId = ToolUtil.generateUUID(); - Integer settingType = RegistryTypeEnum.SELF_REGISTRY.getValue(); - if (CpPersonSourceEnum.CERT.getCode().shortValue() == param.getSource().shortValue()) { - settingType = RegistryTypeEnum.CERT_REGISTRY.getValue(); - } - try { - PersonRegistryResult registrySetting; - String frontIdentityImage = param.getFrontIdentityImage(); - String comparePicture = param.getComparePicture(); - this.checkCard(frontIdentityImage, comparePicture); - this.checkNameByOcrCard(frontIdentityImage, param.getName()); - QueryPersonRegistryParam settingParam = new QueryPersonRegistryParam(); - settingParam.setBusinessId(businessId); - settingParam.setType(settingType); - CloudwalkResult settingResult = this.personRegistryService.detail(settingParam, context); - PersonRegistryResult personRegistryResult = registrySetting = settingResult != null ? (PersonRegistryResult)settingResult.getData() : null; - if (registrySetting == null) { - throw new ServiceException("53060541", this.messageSource.getMessage("53060541", null, LocaleContextHolder.getLocale())); - } - boolean needAudit = this.checkAudit(param.getSource(), param.getDeviceCode(), registrySetting); - this.checkPicture(param); - this.processParam(registrySetting, param); - if (!needAudit) { - return this.imgStorePersonService.add((AddImgPersonParam)param, context); - } - Pair, List> codeNamePair = this.checkProperties(registrySetting.getPropertyList(), param); - this.checkUniqueProperty(param, context); - ImgStorePersonAudit personAudit = (ImgStorePersonAudit)cn.cloudwalk.cloud.utils.BeanCopyUtils.copyProperties((Object)param, ImgStorePersonAudit.class); - personAudit.setDeviceName(this.getDeviceName(param.getDeviceCode(), registrySetting.getDeviceList())); - personAudit.setBusinessId(businessId); - personAudit.setId(auditId); - long time = System.currentTimeMillis(); - personAudit.setCreateTime(Long.valueOf(time)); - personAudit.setLastUpdateTime(Long.valueOf(time)); - personAudit.setOrganizationIds(this.listToString(param.getOrganizationIds())); - personAudit.setOrganizationNames(this.listToString(param.getOrganizationNames())); - personAudit.setLabelIds(this.listToString(param.getLabelIds())); - personAudit.setLabelNames(this.listToString(param.getLabelNames())); - personAudit.setAuditStatus(CpPersonAuditEnum.INIT.getCode()); - personAudit.setUserProperties(JSONObject.toJSONString((Object)codeNamePair.getKey())); - personAudit.setUserPropertiesName(JSONObject.toJSONString((Object)codeNamePair.getValue())); - DateTime now = DateTime.now(); - personAudit.setExpiryBeginDate(Long.valueOf(now.getTime())); - now.setMutable(false); - DateTime end = now.offset(DateField.YEAR, 1); - personAudit.setExpiryEndDate(Long.valueOf(end.getTime())); - ArrayList zoneIdList = new ArrayList(); - for (String organizationId : param.getOrganizationIds()) { - List zoneIdResultList = this.getZoneIdByUnitId(organizationId); - if (CollectionUtils.isEmpty(zoneIdResultList)) continue; - zoneIdList.addAll(zoneIdResultList); - } - this.personZoneRefService.add(personAudit.getId(), zoneIdList, personAudit.getCreateUserId()); - this.imgStorePersonAuditMapper.insert(personAudit); - } - catch (ServiceException e) { - this.logger.error("人员注册新增失败,原因:{}", (Object)e.getMessage()); - throw e; - } - catch (Exception e) { - this.logger.error("人员注册新增失败,原因:{}", (Object)e.getMessage()); - throw new ServiceException("53060535", this.messageSource.getMessage("53060535", null, LocaleContextHolder.getLocale())); - } - return (CloudwalkResult) CloudwalkResult.success(results); - } - - private List getZoneIdByUnitId(String unitId) { - QueryZoneUnitParam queryZoneUnitParam = new QueryZoneUnitParam(); - queryZoneUnitParam.setUnitId(unitId); - CloudwalkResult zoneIdResult = this.zoneFeignClient.findZoneIdByUnitId(queryZoneUnitParam); - if (zoneIdResult == null) { - return null; - } - QueryZoneByUnitResultDTO data = (QueryZoneByUnitResultDTO)zoneIdResult.getData(); - if (data == null) { - return null; - } - return data.getZoneIdList(); - } - - private void checkCard(String frontIdentityImage, String comparePicture) throws ServiceException { - if (StringUtils.isBlank((CharSequence)frontIdentityImage)) { - return; - } - FaceDetectResult.FaceData faceData = this.detectFace(frontIdentityImage); - if (faceData == null) { - throw new ServiceException("获取人脸数据失败"); - } - BufferedImage bufferedImage = this.base64ToBufferedImage(frontIdentityImage); - if (bufferedImage == null) { - throw new ServiceException("获取图片大小失败"); - } - int x = PersonFileServiceImpl.getX(faceData); - int y = PersonFileServiceImpl.getY(faceData); - int width = PersonFileServiceImpl.getWidth(faceData, bufferedImage, x); - int height = PersonFileServiceImpl.getHeight(faceData, bufferedImage, y); - String cropBase64 = this.openCvUtils.cropImgBase64(frontIdentityImage, x, y, width, height); - ExtractFeatureResult extractFeatureResult = this.pineappleClient.extractFeature(ExtractFeatureParam.builder().img(cropBase64).build()); - if (extractFeatureResult == null) { - throw new ServiceException("获取身份证正面人脸特征失败"); - } - String featureOne = extractFeatureResult.getFeature(); - ExtractFeatureResult extractFeatureResultTwo = this.pineappleClient.extractFeature(ExtractFeatureParam.builder().img(comparePicture).build()); - if (extractFeatureResultTwo == null) { - throw new ServiceException("获取人脸特征失败"); - } - String featureTwo = extractFeatureResultTwo.getFeature(); - ImgCompareParam imgCompareParam = ImgCompareParam.builder().featureA(featureOne).featureB(featureTwo).build(); - ImgCompareResult imgCompareResult = this.pineappleClient.imgCompare(imgCompareParam); - if (imgCompareResult == null) { - this.logger.error("证件识别失败,未返回响应"); - throw new ServiceException("证件识别失败"); - } - String score = imgCompareResult.getScore(); - if (StringUtils.isBlank((CharSequence)score)) { - this.logger.error("证件识别失败,可信分未返回"); - throw new ServiceException("证件识别失败"); - } - double scoreDouble = Double.parseDouble(score); - if (scoreDouble < this.faceCompareScore) { - this.logger.error("证件比对失败,未达到可信分"); - throw new ServiceException("证件比对失败"); - } - } - - private BufferedImage base64ToBufferedImage(String imgBase64) { - byte[] image = Base64.getDecoder().decode(imgBase64); - BufferedImage bufferedImage = null; - try (ByteArrayInputStream bais = new ByteArrayInputStream(image);){ - bufferedImage = ImageIO.read(bais); - } - catch (IOException e) { - this.logger.error("获取图片大小异常:{}", (Object)e.getMessage()); - } - return bufferedImage; - } - - private FaceDetectResult.FaceData detectFace(String imgBase64) throws ServiceException { - CpFaceDetectParam faceDetectParam = new CpFaceDetectParam(); - faceDetectParam.setImageBase64(imgBase64); - CloudwalkResult result = this.cpImageStoreToolService.faceDetect(faceDetectParam); - if (CollectionUtils.isEmpty((Collection)((FaceDetectResult)result.getData()).getFaces())) { - throw new ServiceException("53060432", this.messageSource.getMessage("53060432", null, LocaleContextHolder.getLocale())); - } - if (((FaceDetectResult)result.getData()).getFaces().size() > 1) { - throw new ServiceException("53060433", this.messageSource.getMessage("53060433", null, LocaleContextHolder.getLocale())); - } - return (FaceDetectResult.FaceData)((FaceDetectResult)result.getData()).getFaces().get(0); - } - - private void checkNameByOcrCard(String frontIdentityImage, String paramName) throws ServiceException { - OcrCardParam cardParam = OcrCardParam.builder().app_id("").app_secret("").img(frontIdentityImage).build(); - OcrCardResult ocrCardResult = this.pineappleClient.ocrCard(cardParam); - if (ocrCardResult == null) { - this.logger.error("根据身份证获取姓名失败,未正常响应"); - throw new ServiceException("员工姓名与身份证姓名校验失败"); - } - String name = ocrCardResult.getName(); - if (StringUtils.isBlank((CharSequence)name)) { - this.logger.error("根据身份证获取姓名失败,引擎未返回姓名"); - throw new ServiceException("员工姓名与身份证姓名校验失败"); - } - if (!name.equals(paramName)) { - throw new ServiceException("员工姓名与身份证姓名不匹配"); - } - } - - public CloudwalkResult edit(AddPersonAuditParam param, CloudwalkCallContext context) throws ServiceException { - boolean syncAccount; - if (StringUtils.isBlank((CharSequence)param.getBusinessId())) { - param.setBusinessId(context.getCompany().getCompanyId()); - } - boolean bl = syncAccount = param.getCreateSysAccount() != null && param.getCreateSysAccount().intValue() == 1; - if (syncAccount && StringUtils.isBlank((CharSequence)param.getSysAccountId())) { - String errorMessage = this.messageSource.getMessage("53014027", null, LocaleContextHolder.getLocale()); - throw new ServiceException("53014027", errorMessage); - } - ImgStorePersonAudit personAudit = this.imgStorePersonAuditMapper.selectByPrimaryKey(param.getId(), null); - if (null == personAudit) { - throw new ServiceException("53060548", this.messageSource.getMessage("53060548", null, LocaleContextHolder.getLocale())); - } - if (Objects.equals(personAudit.getAuditStatus(), CpPersonAuditEnum.AGREE.getCode())) { - throw new ServiceException("53060549", this.messageSource.getMessage("53060549", null, LocaleContextHolder.getLocale())); - } - Integer settingType = RegistryTypeEnum.SELF_REGISTRY.getValue(); - if (CpPersonSourceEnum.CERT.getCode().shortValue() == personAudit.getSource().shortValue()) { - settingType = RegistryTypeEnum.CERT_REGISTRY.getValue(); - } - QueryPersonRegistryParam settingParam = new QueryPersonRegistryParam(); - settingParam.setBusinessId(personAudit.getBusinessId()); - settingParam.setType(settingType); - CloudwalkResult settingResult = this.personRegistryService.detail(settingParam, context); - if (!settingResult.isSuccess() || null == settingResult.getData()) { - throw new ServiceException("53060541", this.messageSource.getMessage("53060541", null, LocaleContextHolder.getLocale())); - } - PersonRegistryResult personRegistry = (PersonRegistryResult)settingResult.getData(); - boolean needAudit = this.checkAudit(param.getSource(), param.getDeviceCode(), personRegistry); - this.checkPicture(param); - this.processParam(personRegistry, param); - if (!needAudit) { - try { - return this.imgStorePersonService.add((AddImgPersonParam)param, context); - } - catch (Exception e) { - this.logger.error("exception:{}", (Object)e.getMessage()); - } - } - this.checkProperties(personRegistry.getPropertyList(), param); - this.checkUniqueProperty(param, context); - try { - List codes = JSONObject.parseArray((String)personAudit.getUserProperties(), String.class); - for (String code : codes) { - if ("organizationIds".contains(code)) { - personAudit.setOrganizationIds(this.listToString(param.getOrganizationIds())); - personAudit.setOrganizationNames(this.listToString(param.getOrganizationNames())); - continue; - } - if ("labelIds".equals(code)) { - personAudit.setLabelIds(this.listToString(param.getLabelIds())); - personAudit.setLabelNames(this.listToString(param.getLabelNames())); - continue; - } - Field sourceField = ReflectionUtils.findField(AddPersonAuditParam.class, (String)code); - Field targetField = ReflectionUtils.findField(ImgStorePersonAudit.class, (String)code); - if (null == sourceField || null == targetField) { - throw new ServiceException("53014016", this.messageSource.getMessage("53014016", null, LocaleContextHolder.getLocale())); - } - sourceField.setAccessible(true); - targetField.setAccessible(true); - Object fieldValue = ReflectionUtils.getField((Field)sourceField, (Object)param); - ReflectionUtils.setField((Field)targetField, (Object)personAudit, (Object)fieldValue); - } - personAudit.setAuditStatus(CpPersonAuditEnum.INIT.getCode()); - this.imgStorePersonAuditMapper.updateByPrimaryKey(personAudit); - } - catch (Exception e) { - this.logger.error("人员注册修改失败,原因:{}", e); - throw new ServiceException("53060535", this.messageSource.getMessage("53060535", null, LocaleContextHolder.getLocale())); - } - return (CloudwalkResult) CloudwalkResult.success(results); - } - - private String getDeviceName(String deviceCode, List deviceResultList) { - if (!CollectionUtils.isEmpty(deviceResultList)) { - for (DeviceResult item : deviceResultList) { - if (!Objects.equals(item.getDeviceCode(), deviceCode)) continue; - return item.getDeviceName(); - } - } - return null; - } - - private Pair, List> checkProperties(List propertyList, T param) throws ServiceException { - if (propertyList == null) { - throw new ServiceException("53014018", this.messageSource.getMessage("53014018", null, LocaleContextHolder.getLocale())); - } - ArrayList codeList = new ArrayList(); - ArrayList nameList = new ArrayList(); - for (PersonPropertiesResult item : propertyList) { - if (item.getHasChecked() != 1) continue; - String code = item.getCode(); - String name = item.getName(); - codeList.add(code); - nameList.add(name); - if (item.getHasRequired() != 1) continue; - Field field = ReflectionUtils.findField(param.getClass(), (String)code); - if (field == null) { - throw new ServiceException("53014016", this.messageSource.getMessage("53014016", null, LocaleContextHolder.getLocale())); - } - field.setAccessible(true); - Object fieldValue = ReflectionUtils.getField((Field)field, param); - if (fieldValue != null && !StringUtils.isEmpty((CharSequence)String.valueOf(fieldValue))) continue; - throw new ServiceException("53014017", item.getReminder()); - } - return new Pair(codeList, nameList); - } - - private void checkUniqueProperty(AddPersonAuditParam param, CloudwalkCallContext context) throws ServiceException { - CloudwalkResult uniqueResult; - ImgStorePersonAudit conditionAudit; - ImgStorePersonUniqueDto queryDto; - if (StringUtils.isNotEmpty((CharSequence)param.getUserName())) { - queryDto = new ImgStorePersonUniqueDto(); - queryDto.setId(param.getId()); - queryDto.setBusinessId(param.getBusinessId()); - queryDto.setAuditStatus(CpPersonAuditEnum.INIT.getCode()); - queryDto.setUserName(param.getUserName()); - conditionAudit = this.imgStorePersonAuditMapper.findByCondition(queryDto); - if (conditionAudit != null) { - throw new ServiceException("53014013", this.messageSource.getMessage("53014013", null, LocaleContextHolder.getLocale())); - } - } - if (StringUtils.isNotEmpty((CharSequence)param.getPersonCode())) { - queryDto = new ImgStorePersonUniqueDto(); - queryDto.setId(param.getId()); - queryDto.setBusinessId(param.getBusinessId()); - queryDto.setAuditStatus(CpPersonAuditEnum.INIT.getCode()); - queryDto.setPersonCode(param.getPersonCode()); - conditionAudit = this.imgStorePersonAuditMapper.findByCondition(queryDto); - if (conditionAudit != null) { - throw new ServiceException("53014012", this.messageSource.getMessage("53014012", null, LocaleContextHolder.getLocale())); - } - } - if (CpPersonSourceEnum.CERT.getCode().shortValue() == param.getSource().shortValue()) { - QueryPersonRegistryParam registryParam = new QueryPersonRegistryParam(); - registryParam.setBusinessId(param.getBusinessId()); - registryParam.setType(RegistryTypeEnum.CERT_REGISTRY.getValue()); - registryParam.setBindPropertyCode(CertPropertyEnum.CARD_ID.getValue()); - CloudwalkResult personPropertiesResult = this.personRegistryService.getBindProperty(registryParam, context); - if (personPropertiesResult.isSuccess() && personPropertiesResult.getData() != null) { - PersonPropertiesResult personProperties = (PersonPropertiesResult)personPropertiesResult.getData(); - ImgStorePersonAudit auditParam = new ImgStorePersonAudit(); - auditParam.setBusinessId(param.getBusinessId()); - auditParam.setAuditStatus(CpPersonAuditEnum.INIT.getCode()); - Field paramField = ReflectionUtils.findField(param.getClass(), (String)personProperties.getCode()); - paramField.setAccessible(true); - Object value = ReflectionUtils.getField((Field)paramField, (Object)param); - Field personParamField = ReflectionUtils.findField(auditParam.getClass(), (String)personProperties.getCode()); - personParamField.setAccessible(true); - ReflectionUtils.setField((Field)personParamField, (Object)auditParam, (Object)value); - List queryList = this.imgStorePersonAuditMapper.queryMore(auditParam); - if (!CollectionUtil.isEmpty((Collection)queryList)) { - throw new ServiceException("53014023", this.messageSource.getMessage("53014023", null, LocaleContextHolder.getLocale())); - } - } else { - throw new ServiceException("53014022", this.messageSource.getMessage("53014022", null, LocaleContextHolder.getLocale())); - } - } - if (!(uniqueResult = this.imgPersonHandler.checkUniqueProperty((AddImgPersonParam)param, context)).isSuccess()) { - throw new ServiceException(uniqueResult.getCode(), uniqueResult.getMessage()); - } - } - - private void checkPicture(AddPersonAuditParam param) throws ServiceException { - boolean isBase64 = Objects.equals(param.getIsBase64(), 1); - this.checkPicQuality(param.getComparePicture(), isBase64); - this.checkPicQuality(param.getFrontIdentityImage(), isBase64); - this.checkPicQuality(param.getReverseIdentityImage(), isBase64); - if (isBase64) { - String comparePicPath = this.uploadImg(param.getComparePicture()); - String showPicPath = Objects.equals(param.getShowPicture(), param.getComparePicture()) ? comparePicPath : this.uploadImg(param.getShowPicture()); - param.setShowPicture(showPicPath); - param.setComparePicture(comparePicPath); - param.setFrontIdentityPicture(this.uploadImg(param.getFrontIdentityImage())); - param.setReverseIdentityPicture(this.uploadImg(param.getReverseIdentityImage())); - } - } - - private void checkSource(AddPersonAuditParam param) throws ServiceException { - if (!param.isValidSource()) { - throw new ServiceException("53060533", this.messageSource.getMessage("53060533", null, LocaleContextHolder.getLocale())); - } - } - - private boolean isPropAllChecked(PersonRegistryResult registrySetting, String ... propName) { - List propList = Arrays.asList(propName); - long count = registrySetting.getPropertyList().stream().filter(item -> propList.contains(item.getCode()) && Objects.equals(item.getHasChecked(), StatusEnum.CHECKED.getValue())).count(); - return count == (long)propName.length; - } - - private void processParam(PersonRegistryResult registrySetting, AddPersonAuditParam param) throws ServiceException { - if (CollectionUtils.isEmpty((Collection)param.getOrganizationIds()) && CollectionUtils.isEmpty((Collection)registrySetting.getOrganizationList()) && CollectionUtils.isEmpty((Collection)param.getLabelIds()) && CollectionUtils.isEmpty((Collection)registrySetting.getLabelList()) && this.isPropAllChecked(registrySetting, "labelIds", "organizationIds")) { - throw new ServiceException("53014020", this.messageSource.getMessage("53014020", null, LocaleContextHolder.getLocale())); - } - if (CollectionUtils.isEmpty((Collection)param.getOrganizationIds()) && !CollectionUtils.isEmpty((Collection)registrySetting.getOrganizationList())) { - ArrayList organizationIds = new ArrayList(); - ArrayList organizationNames = new ArrayList(); - registrySetting.getOrganizationList().forEach(item -> { - organizationIds.add(item.getId()); - organizationNames.add(item.getName()); - }); - param.setOrganizationIds(organizationIds); - param.setOrganizationNames(organizationNames); - } - if (CollectionUtils.isEmpty((Collection)param.getLabelIds()) && !CollectionUtils.isEmpty((Collection)registrySetting.getLabelList())) { - ArrayList labelIds = new ArrayList(); - ArrayList labelNames = new ArrayList(); - registrySetting.getLabelList().forEach(item -> { - labelIds.add(item.getId()); - labelNames.add(item.getName()); - }); - param.setLabelIds(labelIds); - param.setLabelNames(labelNames); - } - } - - private String listToString(List list) { - if (CollectionUtils.isEmpty(list)) { - return null; - } - StringBuilder sb = new StringBuilder(); - list.stream().filter(item -> !StringUtils.isEmpty((CharSequence)item)).forEach(item -> sb.append((String)item).append(",")); - if (sb.length() > 0) { - sb.deleteCharAt(sb.length() - 1); - } - return sb.toString(); - } - - private boolean checkAudit(Short source, String deviceCode, PersonRegistryResult registrySetting) throws ServiceException { - if (Objects.equals(CpPersonSourceEnum.DEVICE.getCode(), source) || Objects.equals(CpPersonSourceEnum.CERT.getCode(), source)) { - if (StringUtils.isEmpty((CharSequence)deviceCode)) { - throw new ServiceException("53060542", this.messageSource.getMessage("53060542", null, LocaleContextHolder.getLocale())); - } - if (!Objects.equals(registrySetting.getStatus(), 1)) { - throw new ServiceException("53060534", this.messageSource.getMessage("53060534", null, LocaleContextHolder.getLocale())); - } - if (!this.isDeviceValid(deviceCode, registrySetting.getDeviceList())) { - throw new ServiceException("53060543", this.messageSource.getMessage("53060543", null, LocaleContextHolder.getLocale())); - } - return Objects.equals(registrySetting.getDeviceStatus(), 1); - } - return Objects.equals(registrySetting.getCodeStatus(), 1); - } - - private void checkPicQuality(String data, boolean isBase64) throws ServiceException { - if (StringUtils.isEmpty((CharSequence)data)) { - return; - } - AgFeatureExtractParam featureExtractParam = new AgFeatureExtractParam(); - if (isBase64) { - featureExtractParam.setImageBase64(data); - } else { - featureExtractParam.setImageUrl(data); - } - CloudwalkResult result = this.cpImageStoreToolService.extractFeature(featureExtractParam); - this.logger.info("scoreResult:{}", (Object)JSONObject.toJSONString((Object)result)); - if (result.isSuccess() && result.getData() != null) { - AgFeatureExtractResult featureExtractResult = (AgFeatureExtractResult)result.getData(); - Double score = featureExtractResult.getScore(); - this.logger.info("score:{}", (Object)score); - if (this.imgQualityScore > score) { - throw new ServiceException("53003820", this.messageSource.getMessage("53003820", null, LocaleContextHolder.getLocale())); - } - } else { - throw new ServiceException(result.getCode(), result.getMessage()); - } - } - - private String uploadImg(String base64) throws ServiceException { - if (StringUtils.isEmpty((CharSequence)base64)) { - return null; - } - ImageInfoDto compressInfoDto = Optional.ofNullable(this.openCvUtils.getGraphicsCompressBase64(base64)).orElse(new ImageInfoDto()); - if (StringUtils.isEmpty((CharSequence)compressInfoDto.getBase64Compress())) { - this.logger.error("图片压缩失败"); - return null; - } - String compressBase64 = compressInfoDto.getBase64Compress(); - byte[] bytes = Base64Utils.getBytes(compressBase64); - if (bytes.length > ImageStoreConstants.MAX_FILE) { - throw new ServiceException("53060428", this.messageSource.getMessage("53060428", null, LocaleContextHolder.getLocale())); - } - String fileName = ToolUtil.generateUUID(); - this.logger.info("上传文件:{},size={}", (Object)fileName, (Object)bytes.length); - CloudwalkResult storeResult = this.personFileService.upload(fileName, bytes); - if (storeResult != null && storeResult.isSuccess() && StringUtils.isNotBlank((CharSequence)((CharSequence)storeResult.getData()))) { - return (String)storeResult.getData(); - } - throw new ServiceException("80014013", this.messageSource.getMessage("80014013", null, LocaleContextHolder.getLocale())); - } - - private boolean isDeviceValid(String deviceCode, List deviceList) { - if (CollectionUtils.isEmpty(deviceList)) { - return false; - } - return deviceList.stream().anyMatch(device -> StringUtils.equals((CharSequence)deviceCode, (CharSequence)device.getDeviceCode())); - } - - @CloudwalkParamsValidate - public CloudwalkResult auditAgree(AddPersonAuditParam param, CloudwalkCallContext context) throws ServiceException { - param.setCreateSysAccount(Short.valueOf((short)0)); - ImgStorePersonAudit personAudit = this.getAuditById(param.getId()); - try { - this.checkPicture(param); - BeanCopyUtils.copyPropertiesIgnoreNull(personAudit, param); - if (CollectionUtils.isEmpty((Collection)param.getOrganizationIds()) && StringUtils.isNotEmpty((CharSequence)personAudit.getOrganizationIds())) { - param.setOrganizationIds(Arrays.asList(personAudit.getOrganizationIds().split(","))); - } - if (CollectionUtils.isEmpty((Collection)param.getLabelIds()) && StringUtils.isNotEmpty((CharSequence)personAudit.getLabelIds())) { - param.setLabelIds(Arrays.asList(personAudit.getLabelIds().split(","))); - } - String personId = this.uuidSerial.uuid(); - PersonAuditServiceImpl proxyObj = (PersonAuditServiceImpl)AopContext.currentProxy(); - List imageIdResultList = proxyObj.auditAgreeTransactional(param, context, personAudit, personId); - if (Collections3.isNotEmpty(imageIdResultList)) { - imageIdResultList.parallelStream().forEach(imageId -> this.cpImageStorePersonSynManager.handleGroupPersonSynTask((String)imageId)); - } - return (CloudwalkResult) CloudwalkResult.success(results); - } - catch (ServiceException e) { - this.logger.error("人员注册审核通过失败,原因:{}", (Object)e.getMessage()); - throw e; - } - catch (Exception e) { - this.logger.error("人员注册审核通过失败,原因:{}", e); - throw new ServiceException("53060539", this.messageSource.getMessage("53060539", null, LocaleContextHolder.getLocale())); - } - } - - @Transactional(propagation=Propagation.REQUIRED, rollbackFor={Exception.class}, value="transactionManager") - public List auditAgreeTransactional(AddPersonAuditParam param, CloudwalkCallContext context, ImgStorePersonAudit personAudit, String personId) throws ServiceException, ImageStoreException { - List result = this.imgPersonHandler.addTransactional((AddImgPersonParam)param, context, personId); - BeanCopyUtils.copyPropertiesIgnoreNull(param, personAudit); - if (!CollectionUtils.isEmpty((Collection)param.getOrganizationIds())) { - personAudit.setOrganizationIds(this.listToString(param.getOrganizationIds())); - } - if (!CollectionUtils.isEmpty((Collection)param.getOrganizationNames())) { - personAudit.setOrganizationNames(this.listToString(param.getOrganizationNames())); - } - if (!CollectionUtils.isEmpty((Collection)param.getLabelIds())) { - personAudit.setLabelIds(this.listToString(param.getLabelIds())); - } - if (!CollectionUtils.isEmpty((Collection)param.getLabelNames())) { - personAudit.setLabelNames(this.listToString(param.getLabelNames())); - } - personAudit.setLastUpdateTime(Long.valueOf(System.currentTimeMillis())); - personAudit.setLastUpdateUserId(context.getUser().getCaller()); - personAudit.setAuditStatus(CpPersonAuditEnum.AGREE.getCode()); - this.imgStorePersonAuditMapper.update(personAudit); - return result; - } - - private ImgStorePersonAudit getAuditById(String id) throws ServiceException { - if (StringUtils.isEmpty((CharSequence)id)) { - throw new ServiceException("53060537", this.messageSource.getMessage("53060537", null, LocaleContextHolder.getLocale())); - } - ImgStorePersonAudit personAudit = this.imgStorePersonAuditMapper.selectByPrimaryKey(id, CpPersonAuditEnum.INIT.getCode()); - if (personAudit == null) { - throw new ServiceException("53060538", this.messageSource.getMessage("53060538", null, LocaleContextHolder.getLocale())); - } - return personAudit; - } - - @Transactional(propagation=Propagation.REQUIRED, rollbackFor={Exception.class}, value="transactionManager") - @CloudwalkParamsValidate - public CloudwalkResult auditRefuse(String id, CloudwalkCallContext context) throws ServiceException { - ImgStorePersonAudit personAudit = this.getAuditById(id); - personAudit.setId(id); - personAudit.setLastUpdateTime(Long.valueOf(System.currentTimeMillis())); - personAudit.setLastUpdateUserId(context.getUser().getCaller()); - personAudit.setAuditStatus(CpPersonAuditEnum.REFUSE.getCode()); - try { - this.imgStorePersonAuditMapper.update(personAudit); - } - catch (Exception e) { - this.logger.error("人员注册审核拒绝失败,原因:", e); - throw new ServiceException("53060539", this.messageSource.getMessage("53060539", null, LocaleContextHolder.getLocale())); - } - return (CloudwalkResult) CloudwalkResult.success(results); - } - - @CloudwalkParamsValidate - public CloudwalkResult batchAgree(List ids, CloudwalkCallContext context) throws ServiceException { - if (CollectionUtils.isEmpty(ids)) { - throw new ServiceException("53060537", this.messageSource.getMessage("53060537", null, LocaleContextHolder.getLocale())); - } - try { - List auditList = this.imgStorePersonAuditMapper.queryByIds(ids, CpPersonAuditEnum.INIT.getCode()); - if (CollectionUtils.isEmpty((Collection)auditList)) { - return (CloudwalkResult) CloudwalkResult.fail(results); - } - String updateUserId = context.getUser().getCaller(); - List imageIdResultList = this.imgPersonHandler.batchAgreeTransactional(context, auditList, updateUserId); - if (Collections3.isNotEmpty(imageIdResultList)) { - imageIdResultList.parallelStream().forEach(imageId -> this.cpImageStorePersonSynManager.handleGroupPersonSynTask((String)imageId)); - } - } - catch (ServiceException e) { - this.logger.error("人员注册批量同构失败,原因:{}", (Object)e.getMessage()); - throw e; - } - catch (Exception e) { - this.logger.error("人员注册批量同构失败,原因:{}", e); - throw new ServiceException("53060539", this.messageSource.getMessage("53060539", null, LocaleContextHolder.getLocale())); - } - return (CloudwalkResult) CloudwalkResult.success(results); - } - - @Transactional(propagation=Propagation.REQUIRED, rollbackFor={Exception.class}, value="transactionManager") - @CloudwalkParamsValidate - public CloudwalkResult batchRefuse(List ids, CloudwalkCallContext context) throws ServiceException { - if (CollectionUtils.isEmpty(ids)) { - throw new ServiceException("53060537", this.messageSource.getMessage("53060537", null, LocaleContextHolder.getLocale())); - } - long time = System.currentTimeMillis(); - String updateUserId = context.getUser().getCaller(); - List applyList = ids.stream().map(id -> new ImgStorePersonAuditApply(id, Long.valueOf(time), updateUserId, CpPersonAuditEnum.REFUSE.getCode())).collect(Collectors.toList()); - try { - this.imgStorePersonAuditMapper.batchUpdate(applyList, CpPersonAuditEnum.INIT.getCode()); - } - catch (Exception e) { - this.logger.error("人员注册批量拒绝失败,原因:", e); - throw new ServiceException("53060539", this.messageSource.getMessage("53060539", null, LocaleContextHolder.getLocale())); - } - return (CloudwalkResult) CloudwalkResult.success(results); - } - - public CloudwalkResult> page(PersonAuditQueryParam param, CloudwalkPageInfo page, CloudwalkCallContext context) throws ServiceException { - CloudwalkPageAble pageAble; - String businessId = StringUtils.isEmpty((CharSequence)param.getBusinessId()) ? context.getCompany().getCompanyId() : param.getBusinessId(); - ImgStorePersonAuditQueryDto dto = (ImgStorePersonAuditQueryDto)cn.cloudwalk.cloud.utils.BeanCopyUtils.copyProperties((Object)param, (Object)new ImgStorePersonAuditQueryDto()); - dto.setBusinessId(businessId); - try { - PageHelper.startPage((int)page.getCurrentPage(), (int)page.getPageSize()); - Page pageData = (Page)this.imgStorePersonAuditMapper.query(dto); - List result = Optional.ofNullable(pageData.getResult()).orElse(Collections.emptyList()); - List propertyList = this.imgStorePersonPropertiesMapper.selectByIds(businessId, null); - Map propertyMap = propertyList.stream().collect(Collectors.toMap(ImgStorePersonProperties::getCode, pro -> pro)); - List collect = result.stream().map(item -> { - PersonAuditGetResult auditGetResult = (PersonAuditGetResult)cn.cloudwalk.cloud.utils.BeanCopyUtils.copyProperties((Object)item, PersonAuditGetResult.class); - auditGetResult.setUserPropertiesList(this.getUserProperties((ImgStorePersonAudit)item, propertyMap)); - return auditGetResult; - }).collect(Collectors.toList()); - pageAble = new CloudwalkPageAble(collect, page, pageData.getTotal()); - } - catch (Exception e) { - this.logger.error("分页查询人员注册信息失败,原因:", e); - throw new ServiceException("53060540", this.messageSource.getMessage("53060540", null, LocaleContextHolder.getLocale())); - } - return (CloudwalkResult) CloudwalkResult.success(results); - } - - private List getUserProperties(ImgStorePersonAudit audit, Map propertyMap) { - ArrayList result = new ArrayList(); - if (audit == null) { - return result; - } - List codes = JSONObject.parseArray((String)audit.getUserProperties(), String.class); - List names = JSONObject.parseArray((String)audit.getUserPropertiesName(), String.class); - if (!CollectionUtils.isEmpty((Collection)codes) && !CollectionUtils.isEmpty((Collection)names) && codes.size() == names.size()) { - for (int i = 0; i < codes.size(); ++i) { - Object fieldValue; - UserProperties properties = new UserProperties(); - String code = (String)codes.get(i); - properties.setCode(code); - properties.setLabel((String)names.get(i)); - properties.setType((int)propertyMap.get(code).getType().shortValue()); - if (Objects.equals(code, "organizationIds")) { - fieldValue = audit.getOrganizationNames(); - } else if (Objects.equals(code, "labelIds")) { - fieldValue = audit.getLabelNames(); - } else { - Field field = ReflectionUtils.findField(audit.getClass(), (String)code); - if (field == null) continue; - field.setAccessible(true); - fieldValue = ReflectionUtils.getField((Field)field, (Object)audit); - } - properties.setValue(fieldValue); - result.add(properties); - } - } - if (Objects.equals(audit.getSource(), CpPersonSourceEnum.DEVICE.getCode())) { - UserProperties properties = new UserProperties(); - properties.setCode("deviceName"); - properties.setLabel("设备名称"); - properties.setValue((Object)audit.getDeviceName()); - result.add(properties); - } - return result; - } - - public CloudwalkResult userCheck(PersonAuditCheckParam param, CloudwalkCallContext context) throws ServiceException { - ImgStorePersonAudit personAudit; - CloudwalkResult checkCaptcha = this.captchaService.checkCaptcha((CheckCaptchaParam)param); - if (!checkCaptcha.isSuccess()) { - throw new ServiceException("53060546", this.messageSource.getMessage("53060546", null, LocaleContextHolder.getLocale())); - } - String businessId = StringUtils.isEmpty((CharSequence)param.getBusinessId()) ? context.getCompany().getCompanyId() : param.getBusinessId(); - param.setBusinessId(businessId); - String column = CpPersonAuditUniqueEnum.getMessage((String)param.getCheckName()); - if (column == null) { - throw new ServiceException("53060547", this.messageSource.getMessage("53060547", null, LocaleContextHolder.getLocale())); - } - ImgStoreAuditUserQueryDto queryDto = new ImgStoreAuditUserQueryDto(); - queryDto.setBusinessId(businessId); - Field targetField = ReflectionUtils.findField(queryDto.getClass(), (String)param.getCheckName()); - if (targetField == null) { - throw new ServiceException("53060547", this.messageSource.getMessage("53060547", null, LocaleContextHolder.getLocale())); - } - targetField.setAccessible(true); - ReflectionUtils.setField((Field)targetField, (Object)queryDto, (Object)param.getCheckNameValue()); - try { - personAudit = this.imgStorePersonAuditMapper.userQuery(queryDto); - } - catch (Exception e) { - this.logger.error("人员注册查询失败,原因:{}", (Object)e.getMessage()); - return (CloudwalkResult) CloudwalkResult.fail(results); - } - if (personAudit == null) { - return (CloudwalkResult) CloudwalkResult.fail(results); - } - Short auditStatus = personAudit.getAuditStatus(); - PersonAuditResult auditResult = new PersonAuditResult(); - auditResult.setAuditStatus(auditStatus); - auditResult.setAuditStatusStr(CpPersonAuditEnum.getMessage((Short)auditStatus)); - return (CloudwalkResult) CloudwalkResult.success(results); - } - - public CloudwalkResult checkById(PersonAuditParam param, CloudwalkCallContext context) throws ServiceException { - if (StringUtils.isBlank((CharSequence)param.getId())) { - return (CloudwalkResult) CloudwalkResult.fail(results); - } - ImgStorePersonAudit personAudit = this.imgStorePersonAuditMapper.selectByPrimaryKey(param.getId(), null); - if (null == personAudit) { - throw new ServiceException("53060548", this.messageSource.getMessage("53060548", null, LocaleContextHolder.getLocale())); - } - List propertyList = this.imgStorePersonPropertiesMapper.selectByIds(personAudit.getBusinessId(), null); - Map propertyMap = propertyList.stream().collect(Collectors.toMap(ImgStorePersonProperties::getCode, pro -> pro)); - PersonAuditGetResult result = (PersonAuditGetResult)cn.cloudwalk.cloud.utils.BeanCopyUtils.copyProperties((Object)personAudit, PersonAuditGetResult.class); - result.setUserPropertiesList(this.getUserProperties(personAudit, propertyMap)); - return (CloudwalkResult) CloudwalkResult.success(results); - } +public class PersonAuditServiceImpl implements IPersonAuditServcie { +protected final Logger logger = LoggerFactory.getLogger(getClass()); +@Autowired +private MessageSource messageSource; +@Value("${imageQualityScore}") +private Double imgQualityScore; +@Value("${ocr.card.face.score:0.65}") +private Double faceCompareScore; +@Autowired +private ImgStorePersonAuditMapper imgStorePersonAuditMapper; +@Resource +private ImgStorePersonPropertiesMapper imgStorePersonPropertiesMapper; +@Autowired +private PersonFileService personFileService; +@Autowired +private ImgStorePersonService imgStorePersonService; +@Autowired +private ImgPersonHandler imgPersonHandler; +@Autowired +private PersonRegistryService personRegistryService; +@Autowired +private AcCaptchaService captchaService; +@Autowired +private CpImageStoreToolService cpImageStoreToolService; +@Autowired +private CpImageStorePersonSynManager cpImageStorePersonSynManager; +@Autowired +private OpenCvUtils openCvUtils; +@Autowired +private UUIDSerial uuidSerial; +@Resource +private PineappleEngineClient pineappleClient; +@Autowired +private PersonZoneRefService personZoneRefService; +@Autowired +private ZoneFeignClient zoneFeignClient; +@CloudwalkParamsValidate +public CloudwalkResult add(AddPersonAuditParam param, CloudwalkCallContext context) throws ServiceException { +this.logger.debug("添加注册记录,请求参数:[{}]", JSON.toJSONString(param)); +checkSource(param); +String businessId = StringUtils.isEmpty(param.getBusinessId()) ? context.getCompany().getCompanyId() : param.getBusinessId(); +boolean syncAccount = (param.getCreateSysAccount() != null && param.getCreateSysAccount().intValue() == 1); +if (syncAccount && StringUtils.isBlank(param.getSysAccountId())) { +String errorMessage = this.messageSource.getMessage("53014027", null, LocaleContextHolder.getLocale()); +throw new ServiceException("53014027", errorMessage); +} +String auditId = ToolUtil.generateUUID(); +Integer settingType = RegistryTypeEnum.SELF_REGISTRY.getValue(); +if (CpPersonSourceEnum.CERT.getCode().shortValue() == param.getSource().shortValue()) { +settingType = RegistryTypeEnum.CERT_REGISTRY.getValue(); +} +try { +String frontIdentityImage = param.getFrontIdentityImage(); +String comparePicture = param.getComparePicture(); +checkCard(frontIdentityImage, comparePicture); +checkNameByOcrCard(frontIdentityImage, param.getName()); +QueryPersonRegistryParam settingParam = new QueryPersonRegistryParam(); +settingParam.setBusinessId(businessId); +settingParam.setType(settingType); +CloudwalkResult settingResult = this.personRegistryService.detail(settingParam, context); +PersonRegistryResult registrySetting = (settingResult != null) ? (PersonRegistryResult)settingResult.getData() : null; +if (registrySetting == null) { +throw new ServiceException("53060541", this.messageSource +.getMessage("53060541", null, LocaleContextHolder.getLocale())); +} +boolean needAudit = checkAudit(param.getSource(), param.getDeviceCode(), registrySetting); +checkPicture(param); +processParam(registrySetting, param); +if (!needAudit) { +return this.imgStorePersonService.add((AddImgPersonParam)param, context); +} +Pair, List> codeNamePair = checkProperties(registrySetting.getPropertyList(), param); +checkUniqueProperty(param, context); +ImgStorePersonAudit personAudit = (ImgStorePersonAudit)BeanCopyUtils.copyProperties(param, ImgStorePersonAudit.class); +personAudit.setDeviceName(getDeviceName(param.getDeviceCode(), registrySetting.getDeviceList())); +personAudit.setBusinessId(businessId); +personAudit.setId(auditId); +long time = System.currentTimeMillis(); +personAudit.setCreateTime(Long.valueOf(time)); +personAudit.setLastUpdateTime(Long.valueOf(time)); +personAudit.setOrganizationIds(listToString(param.getOrganizationIds())); +personAudit.setOrganizationNames(listToString(param.getOrganizationNames())); +personAudit.setLabelIds(listToString(param.getLabelIds())); +personAudit.setLabelNames(listToString(param.getLabelNames())); +personAudit.setAuditStatus(CpPersonAuditEnum.INIT.getCode()); +personAudit.setUserProperties(JSONObject.toJSONString(codeNamePair.getKey())); +personAudit.setUserPropertiesName(JSONObject.toJSONString(codeNamePair.getValue())); +DateTime now = DateTime.now(); +personAudit.setExpiryBeginDate(Long.valueOf(now.getTime())); +now.setMutable(false); +DateTime end = now.offset(DateField.YEAR, 1); +personAudit.setExpiryEndDate(Long.valueOf(end.getTime())); +List zoneIdList = new ArrayList<>(); +for (String organizationId : param.getOrganizationIds()) { +List zoneIdResultList = getZoneIdByUnitId(organizationId); +if (!CollectionUtils.isEmpty(zoneIdResultList)) { +zoneIdList.addAll(zoneIdResultList); +} +} +this.personZoneRefService.add(personAudit.getId(), zoneIdList, personAudit.getCreateUserId()); +this.imgStorePersonAuditMapper.insert(personAudit); +} catch (ServiceException e) { +this.logger.error("人员注册新增失败,原因:{}", e.getMessage()); +throw e; +} catch (Exception e) { +this.logger.error("人员注册新增失败,原因:{}", e.getMessage()); +throw new ServiceException("53060535", this.messageSource +.getMessage("53060535", null, LocaleContextHolder.getLocale())); +} +return CloudwalkResult.success(auditId); +} +private List getZoneIdByUnitId(String unitId) { +QueryZoneUnitParam queryZoneUnitParam = new QueryZoneUnitParam(); +queryZoneUnitParam.setUnitId(unitId); +CloudwalkResult zoneIdResult = this.zoneFeignClient.findZoneIdByUnitId(queryZoneUnitParam); +if (zoneIdResult == null) { +return null; +} +QueryZoneByUnitResultDTO data = (QueryZoneByUnitResultDTO)zoneIdResult.getData(); +if (data == null) { +return null; +} +return data.getZoneIdList(); +} +private void checkCard(String frontIdentityImage, String comparePicture) throws ServiceException { +if (StringUtils.isBlank(frontIdentityImage)) { +return; +} +FaceDetectResult.FaceData faceData = detectFace(frontIdentityImage); +if (faceData == null) { +throw new ServiceException("获取人脸数据失败"); +} +BufferedImage bufferedImage = base64ToBufferedImage(frontIdentityImage); +if (bufferedImage == null) { +throw new ServiceException("获取图片大小失败"); +} +int x = PersonFileServiceImpl.getX(faceData); +int y = PersonFileServiceImpl.getY(faceData); +int width = PersonFileServiceImpl.getWidth(faceData, bufferedImage, x); +int height = PersonFileServiceImpl.getHeight(faceData, bufferedImage, y); +String cropBase64 = this.openCvUtils.cropImgBase64(frontIdentityImage, x, y, width, height); +ExtractFeatureResult extractFeatureResult = this.pineappleClient.extractFeature(ExtractFeatureParam.builder() +.img(cropBase64) +.build()); +if (extractFeatureResult == null) { +throw new ServiceException("获取身份证正面人脸特征失败"); +} +String featureOne = extractFeatureResult.getFeature(); +ExtractFeatureResult extractFeatureResultTwo = this.pineappleClient.extractFeature(ExtractFeatureParam.builder() +.img(comparePicture) +.build()); +if (extractFeatureResultTwo == null) { +throw new ServiceException("获取人脸特征失败"); +} +String featureTwo = extractFeatureResultTwo.getFeature(); +ImgCompareParam imgCompareParam = ImgCompareParam.builder().featureA(featureOne).featureB(featureTwo).build(); +ImgCompareResult imgCompareResult = this.pineappleClient.imgCompare(imgCompareParam); +if (imgCompareResult == null) { +this.logger.error("证件识别失败,未返回响应"); +throw new ServiceException("证件识别失败"); +} +String score = imgCompareResult.getScore(); +if (StringUtils.isBlank(score)) { +this.logger.error("证件识别失败,可信分未返回"); +throw new ServiceException("证件识别失败"); +} +double scoreDouble = Double.parseDouble(score); +if (scoreDouble < this.faceCompareScore.doubleValue()) { +this.logger.error("证件比对失败,未达到可信分"); +throw new ServiceException("证件比对失败"); +} +} +private BufferedImage base64ToBufferedImage(String imgBase64) { +byte[] image = Base64.getDecoder().decode(imgBase64); +BufferedImage bufferedImage = null; +try (ByteArrayInputStream bais = new ByteArrayInputStream(image)) { +bufferedImage = ImageIO.read(bais); +} catch (IOException e) { +this.logger.error("获取图片大小异常:{}", e.getMessage()); +} +return bufferedImage; +} +private FaceDetectResult.FaceData detectFace(String imgBase64) throws ServiceException { +CpFaceDetectParam faceDetectParam = new CpFaceDetectParam(); +faceDetectParam.setImageBase64(imgBase64); +CloudwalkResult result = this.cpImageStoreToolService.faceDetect(faceDetectParam); +if (CollectionUtils.isEmpty(((FaceDetectResult)result.getData()).getFaces())) { +throw new ServiceException("53060432", this.messageSource +.getMessage("53060432", null, LocaleContextHolder.getLocale())); +} +if (((FaceDetectResult)result.getData()).getFaces().size() > 1) { +throw new ServiceException("53060433", this.messageSource +.getMessage("53060433", null, LocaleContextHolder.getLocale())); +} +return ((FaceDetectResult)result.getData()).getFaces().get(0); +} +private void checkNameByOcrCard(String frontIdentityImage, String paramName) throws ServiceException { +OcrCardParam cardParam = OcrCardParam.builder().app_id("").app_secret("").img(frontIdentityImage).build(); +OcrCardResult ocrCardResult = this.pineappleClient.ocrCard(cardParam); +if (ocrCardResult == null) { +this.logger.error("根据身份证获取姓名失败,未正常响应"); +throw new ServiceException("员工姓名与身份证姓名校验失败"); +} +String name = ocrCardResult.getName(); +if (StringUtils.isBlank(name)) { +this.logger.error("根据身份证获取姓名失败,引擎未返回姓名"); +throw new ServiceException("员工姓名与身份证姓名校验失败"); +} +if (!name.equals(paramName)) { +throw new ServiceException("员工姓名与身份证姓名不匹配"); +} +} +public CloudwalkResult edit(AddPersonAuditParam param, CloudwalkCallContext context) throws ServiceException { +if (StringUtils.isBlank(param.getBusinessId())) { +param.setBusinessId(context.getCompany().getCompanyId()); +} +boolean syncAccount = (param.getCreateSysAccount() != null && param.getCreateSysAccount().intValue() == 1); +if (syncAccount && StringUtils.isBlank(param.getSysAccountId())) { +String errorMessage = this.messageSource.getMessage("53014027", null, LocaleContextHolder.getLocale()); +throw new ServiceException("53014027", errorMessage); +} +ImgStorePersonAudit personAudit = this.imgStorePersonAuditMapper.selectByPrimaryKey(param.getId(), null); +if (null == personAudit) { +throw new ServiceException("53060548", this.messageSource.getMessage("53060548", null, LocaleContextHolder.getLocale())); +} +if (Objects.equals(personAudit.getAuditStatus(), CpPersonAuditEnum.AGREE.getCode())) { +throw new ServiceException("53060549", this.messageSource +.getMessage("53060549", null, LocaleContextHolder.getLocale())); +} +Integer settingType = RegistryTypeEnum.SELF_REGISTRY.getValue(); +if (CpPersonSourceEnum.CERT.getCode().shortValue() == personAudit.getSource().shortValue()) { +settingType = RegistryTypeEnum.CERT_REGISTRY.getValue(); +} +QueryPersonRegistryParam settingParam = new QueryPersonRegistryParam(); +settingParam.setBusinessId(personAudit.getBusinessId()); +settingParam.setType(settingType); +CloudwalkResult settingResult = this.personRegistryService.detail(settingParam, context); +if (!settingResult.isSuccess() || null == settingResult.getData()) { +throw new ServiceException("53060541", this.messageSource +.getMessage("53060541", null, LocaleContextHolder.getLocale())); +} +PersonRegistryResult personRegistry = (PersonRegistryResult)settingResult.getData(); +boolean needAudit = checkAudit(param.getSource(), param.getDeviceCode(), personRegistry); +checkPicture(param); +processParam(personRegistry, param); +if (!needAudit) { +try { +return this.imgStorePersonService.add((AddImgPersonParam)param, context); +} catch (Exception e) { +this.logger.error("exception:{}", e.getMessage()); +} +} +checkProperties(personRegistry.getPropertyList(), param); +checkUniqueProperty(param, context); +try { +List codes = JSONObject.parseArray(personAudit.getUserProperties(), String.class); +for (String code : codes) { +if ("organizationIds".contains(code)) { +personAudit.setOrganizationIds(listToString(param.getOrganizationIds())); +personAudit.setOrganizationNames(listToString(param.getOrganizationNames())); continue; +} if ("labelIds".equals(code)) { +personAudit.setLabelIds(listToString(param.getLabelIds())); +personAudit.setLabelNames(listToString(param.getLabelNames())); continue; +} +Field sourceField = ReflectionUtils.findField(AddPersonAuditParam.class, code); +Field targetField = ReflectionUtils.findField(ImgStorePersonAudit.class, code); +if (null == sourceField || null == targetField) { +throw new ServiceException("53014016", this.messageSource +.getMessage("53014016", null, LocaleContextHolder.getLocale())); +} +sourceField.setAccessible(true); +targetField.setAccessible(true); +Object fieldValue = ReflectionUtils.getField(sourceField, param); +ReflectionUtils.setField(targetField, personAudit, fieldValue); +} +personAudit.setAuditStatus(CpPersonAuditEnum.INIT.getCode()); +this.imgStorePersonAuditMapper.updateByPrimaryKey(personAudit); +} catch (Exception e) { +this.logger.error("人员注册修改失败,原因:{}", e); +throw new ServiceException("53060535", this.messageSource +.getMessage("53060535", null, LocaleContextHolder.getLocale())); +} +return CloudwalkResult.success(personAudit.getId()); +} +private String getDeviceName(String deviceCode, List deviceResultList) { +if (!CollectionUtils.isEmpty(deviceResultList)) { +for (DeviceResult item : deviceResultList) { +if (Objects.equals(item.getDeviceCode(), deviceCode)) { +return item.getDeviceName(); +} +} +} +return null; +} +private Pair, List> checkProperties(List propertyList, T param) throws ServiceException { +if (propertyList == null) { +throw new ServiceException("53014018", this.messageSource +.getMessage("53014018", null, LocaleContextHolder.getLocale())); +} +List codeList = new ArrayList<>(); +List nameList = new ArrayList<>(); +for (PersonPropertiesResult item : propertyList) { +if (item.getHasChecked().intValue() != 1) { +continue; +} +String code = item.getCode(); +String name = item.getName(); +codeList.add(code); +nameList.add(name); +if (item.getHasRequired().intValue() == 1) { +Field field = ReflectionUtils.findField(param.getClass(), code); +if (field == null) { +throw new ServiceException("53014016", this.messageSource +.getMessage("53014016", null, LocaleContextHolder.getLocale())); +} +field.setAccessible(true); +Object fieldValue = ReflectionUtils.getField(field, param); +if (fieldValue == null || StringUtils.isEmpty(String.valueOf(fieldValue))) { +throw new ServiceException("53014017", item.getReminder()); +} +} +} +return new Pair(codeList, nameList); +} +private void checkUniqueProperty(AddPersonAuditParam param, CloudwalkCallContext context) throws ServiceException { +if (StringUtils.isNotEmpty(param.getUserName())) { +ImgStorePersonUniqueDto queryDto = new ImgStorePersonUniqueDto(); +queryDto.setId(param.getId()); +queryDto.setBusinessId(param.getBusinessId()); +queryDto.setAuditStatus(CpPersonAuditEnum.INIT.getCode()); +queryDto.setUserName(param.getUserName()); +ImgStorePersonAudit conditionAudit = this.imgStorePersonAuditMapper.findByCondition(queryDto); +if (conditionAudit != null) { +throw new ServiceException("53014013", this.messageSource +.getMessage("53014013", null, LocaleContextHolder.getLocale())); +} +} +if (StringUtils.isNotEmpty(param.getPersonCode())) { +ImgStorePersonUniqueDto queryDto = new ImgStorePersonUniqueDto(); +queryDto.setId(param.getId()); +queryDto.setBusinessId(param.getBusinessId()); +queryDto.setAuditStatus(CpPersonAuditEnum.INIT.getCode()); +queryDto.setPersonCode(param.getPersonCode()); +ImgStorePersonAudit conditionAudit = this.imgStorePersonAuditMapper.findByCondition(queryDto); +if (conditionAudit != null) { +throw new ServiceException("53014012", this.messageSource +.getMessage("53014012", null, LocaleContextHolder.getLocale())); +} +} +if (CpPersonSourceEnum.CERT.getCode().shortValue() == param.getSource().shortValue()) { +QueryPersonRegistryParam registryParam = new QueryPersonRegistryParam(); +registryParam.setBusinessId(param.getBusinessId()); +registryParam.setType(RegistryTypeEnum.CERT_REGISTRY.getValue()); +registryParam.setBindPropertyCode(CertPropertyEnum.CARD_ID.getValue()); +CloudwalkResult personPropertiesResult = this.personRegistryService.getBindProperty(registryParam, context); +if (personPropertiesResult.isSuccess() && personPropertiesResult.getData() != null) { +PersonPropertiesResult personProperties = (PersonPropertiesResult)personPropertiesResult.getData(); +ImgStorePersonAudit auditParam = new ImgStorePersonAudit(); +auditParam.setBusinessId(param.getBusinessId()); +auditParam.setAuditStatus(CpPersonAuditEnum.INIT.getCode()); +Field paramField = ReflectionUtils.findField(param.getClass(), personProperties.getCode()); +paramField.setAccessible(true); +Object value = ReflectionUtils.getField(paramField, param); +Field personParamField = ReflectionUtils.findField(auditParam.getClass(), personProperties.getCode()); +personParamField.setAccessible(true); +ReflectionUtils.setField(personParamField, auditParam, value); +List queryList = this.imgStorePersonAuditMapper.queryMore(auditParam); +if (!CollectionUtil.isEmpty(queryList)) { +throw new ServiceException("53014023", this.messageSource +.getMessage("53014023", null, LocaleContextHolder.getLocale())); +} +} else { +throw new ServiceException("53014022", this.messageSource +.getMessage("53014022", null, LocaleContextHolder.getLocale())); +} +} +CloudwalkResult uniqueResult = this.imgPersonHandler.checkUniqueProperty((AddImgPersonParam)param, context); +if (!uniqueResult.isSuccess()) { +throw new ServiceException(uniqueResult.getCode(), uniqueResult.getMessage()); +} +} +private void checkPicture(AddPersonAuditParam param) throws ServiceException { +boolean isBase64 = Objects.equals(param.getIsBase64(), Integer.valueOf(1)); +checkPicQuality(param.getComparePicture(), isBase64); +checkPicQuality(param.getFrontIdentityImage(), isBase64); +checkPicQuality(param.getReverseIdentityImage(), isBase64); +if (isBase64) { +String showPicPath, comparePicPath = uploadImg(param.getComparePicture()); +if (Objects.equals(param.getShowPicture(), param.getComparePicture())) { +showPicPath = comparePicPath; +} else { +showPicPath = uploadImg(param.getShowPicture()); +} +param.setShowPicture(showPicPath); +param.setComparePicture(comparePicPath); +param.setFrontIdentityPicture(uploadImg(param.getFrontIdentityImage())); +param.setReverseIdentityPicture(uploadImg(param.getReverseIdentityImage())); +} +} +private void checkSource(AddPersonAuditParam param) throws ServiceException { +if (!param.isValidSource()) { +throw new ServiceException("53060533", this.messageSource +.getMessage("53060533", null, LocaleContextHolder.getLocale())); +} +} +private boolean isPropAllChecked(PersonRegistryResult registrySetting, String... propName) { +List propList = Arrays.asList(propName); +long count = registrySetting.getPropertyList().stream().filter(item -> (propList.contains(item.getCode()) && Objects.equals(item.getHasChecked(), StatusEnum.CHECKED.getValue()))).count(); +return (count == propName.length); +} +private void processParam(PersonRegistryResult registrySetting, AddPersonAuditParam param) throws ServiceException { +if (CollectionUtils.isEmpty(param.getOrganizationIds()) && CollectionUtils.isEmpty(registrySetting.getOrganizationList()) && +CollectionUtils.isEmpty(param.getLabelIds()) && CollectionUtils.isEmpty(registrySetting.getLabelList()) && +isPropAllChecked(registrySetting, new String[] { "labelIds", "organizationIds" })) { +throw new ServiceException("53014020", this.messageSource +.getMessage("53014020", null, +LocaleContextHolder.getLocale())); +} +if (CollectionUtils.isEmpty(param.getOrganizationIds()) && +!CollectionUtils.isEmpty(registrySetting.getOrganizationList())) { +List organizationIds = new ArrayList<>(); +List organizationNames = new ArrayList<>(); +registrySetting.getOrganizationList().forEach(item -> { +organizationIds.add(item.getId()); +organizationNames.add(item.getName()); +}); +param.setOrganizationIds(organizationIds); +param.setOrganizationNames(organizationNames); +} +if (CollectionUtils.isEmpty(param.getLabelIds()) && !CollectionUtils.isEmpty(registrySetting.getLabelList())) { +List labelIds = new ArrayList<>(); +List labelNames = new ArrayList<>(); +registrySetting.getLabelList().forEach(item -> { +labelIds.add(item.getId()); +labelNames.add(item.getName()); +}); +param.setLabelIds(labelIds); +param.setLabelNames(labelNames); +} +} +private String listToString(List list) { +if (CollectionUtils.isEmpty(list)) { +return null; +} +StringBuilder sb = new StringBuilder(); +list.stream().filter(item -> !StringUtils.isEmpty(item)).forEach(item -> sb.append(item).append(",")); +if (sb.length() > 0) { +sb.deleteCharAt(sb.length() - 1); +} +return sb.toString(); +} +private boolean checkAudit(Short source, String deviceCode, PersonRegistryResult registrySetting) throws ServiceException { +if (Objects.equals(CpPersonSourceEnum.DEVICE.getCode(), source) || Objects.equals(CpPersonSourceEnum.CERT.getCode(), source)) { +if (StringUtils.isEmpty(deviceCode)) { +throw new ServiceException("53060542", this.messageSource +.getMessage("53060542", null, LocaleContextHolder.getLocale())); +} +if (!Objects.equals(registrySetting.getStatus(), Integer.valueOf(1))) { +throw new ServiceException("53060534", this.messageSource +.getMessage("53060534", null, LocaleContextHolder.getLocale())); +} +if (!isDeviceValid(deviceCode, registrySetting.getDeviceList())) { +throw new ServiceException("53060543", this.messageSource +.getMessage("53060543", null, LocaleContextHolder.getLocale())); +} +return Objects.equals(registrySetting.getDeviceStatus(), Integer.valueOf(1)); +} +return Objects.equals(registrySetting.getCodeStatus(), Integer.valueOf(1)); +} +private void checkPicQuality(String data, boolean isBase64) throws ServiceException { +if (StringUtils.isEmpty(data)) { +return; +} +AgFeatureExtractParam featureExtractParam = new AgFeatureExtractParam(); +if (isBase64) { +featureExtractParam.setImageBase64(data); +} else { +featureExtractParam.setImageUrl(data); +} +CloudwalkResult result = this.cpImageStoreToolService.extractFeature(featureExtractParam); +this.logger.info("scoreResult:{}", JSONObject.toJSONString(result)); +if (result.isSuccess() && result.getData() != null) { +AgFeatureExtractResult featureExtractResult = (AgFeatureExtractResult)result.getData(); +Double score = featureExtractResult.getScore(); +this.logger.info("score:{}", score); +if (this.imgQualityScore.doubleValue() > score.doubleValue()) +{ +throw new ServiceException("53003820", this.messageSource +.getMessage("53003820", null, LocaleContextHolder.getLocale())); +} +} else { +throw new ServiceException(result.getCode(), result.getMessage()); +} +} +private String uploadImg(String base64) throws ServiceException { +if (StringUtils.isEmpty(base64)) { +return null; +} +ImageInfoDto compressInfoDto = Optional.ofNullable(this.openCvUtils.getGraphicsCompressBase64(base64)).orElse(new ImageInfoDto()); +if (StringUtils.isEmpty(compressInfoDto.getBase64Compress())) { +this.logger.error("图片压缩失败"); +return null; +} +String compressBase64 = compressInfoDto.getBase64Compress(); +byte[] bytes = Base64Utils.getBytes(compressBase64); +if (bytes.length > ImageStoreConstants.MAX_FILE.intValue()) { +throw new ServiceException("53060428", this.messageSource +.getMessage("53060428", null, LocaleContextHolder.getLocale())); +} +String fileName = ToolUtil.generateUUID(); +this.logger.info("上传文件:{},size={}", fileName, Integer.valueOf(bytes.length)); +CloudwalkResult storeResult = this.personFileService.upload(fileName, bytes); +if (storeResult != null && storeResult.isSuccess() && StringUtils.isNotBlank((CharSequence)storeResult.getData())) { +return (String)storeResult.getData(); +} +throw new ServiceException("80014013", this.messageSource +.getMessage("80014013", null, LocaleContextHolder.getLocale())); +} +private boolean isDeviceValid(String deviceCode, List deviceList) { +if (CollectionUtils.isEmpty(deviceList)) { +return false; +} +return deviceList.stream().anyMatch(device -> StringUtils.equals(deviceCode, device.getDeviceCode())); +} +@CloudwalkParamsValidate +public CloudwalkResult auditAgree(AddPersonAuditParam param, CloudwalkCallContext context) throws ServiceException { +param.setCreateSysAccount(Short.valueOf((short)0)); +ImgStorePersonAudit personAudit = getAuditById(param.getId()); +try { +checkPicture(param); +BeanCopyUtils.copyPropertiesIgnoreNull(personAudit, param); +if (CollectionUtils.isEmpty(param.getOrganizationIds()) && +StringUtils.isNotEmpty(personAudit.getOrganizationIds())) { +param.setOrganizationIds(Arrays.asList(personAudit.getOrganizationIds().split(","))); +} +if (CollectionUtils.isEmpty(param.getLabelIds()) && StringUtils.isNotEmpty(personAudit.getLabelIds())) { +param.setLabelIds(Arrays.asList(personAudit.getLabelIds().split(","))); +} +String personId = this.uuidSerial.uuid(); +PersonAuditServiceImpl proxyObj = (PersonAuditServiceImpl)AopContext.currentProxy(); +List imageIdResultList = proxyObj.auditAgreeTransactional(param, context, personAudit, personId); +if (Collections3.isNotEmpty(imageIdResultList)) { +imageIdResultList.parallelStream() +.forEach(imageId -> this.cpImageStorePersonSynManager.handleGroupPersonSynTask(imageId)); +} +return CloudwalkResult.success(personId); +} catch (ServiceException e) { +this.logger.error("人员注册审核通过失败,原因:{}", e.getMessage()); +throw e; +} catch (Exception e) { +this.logger.error("人员注册审核通过失败,原因:{}", e); +throw new ServiceException("53060539", this.messageSource +.getMessage("53060539", null, LocaleContextHolder.getLocale())); +} +} +@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}, value = "transactionManager") +public List auditAgreeTransactional(AddPersonAuditParam param, CloudwalkCallContext context, ImgStorePersonAudit personAudit, String personId) throws ServiceException, ImageStoreException { +List result = this.imgPersonHandler.addTransactional((AddImgPersonParam)param, context, personId); +BeanCopyUtils.copyPropertiesIgnoreNull(param, personAudit); +if (!CollectionUtils.isEmpty(param.getOrganizationIds())) { +personAudit.setOrganizationIds(listToString(param.getOrganizationIds())); +} +if (!CollectionUtils.isEmpty(param.getOrganizationNames())) { +personAudit.setOrganizationNames(listToString(param.getOrganizationNames())); +} +if (!CollectionUtils.isEmpty(param.getLabelIds())) { +personAudit.setLabelIds(listToString(param.getLabelIds())); +} +if (!CollectionUtils.isEmpty(param.getLabelNames())) { +personAudit.setLabelNames(listToString(param.getLabelNames())); +} +personAudit.setLastUpdateTime(Long.valueOf(System.currentTimeMillis())); +personAudit.setLastUpdateUserId(context.getUser().getCaller()); +personAudit.setAuditStatus(CpPersonAuditEnum.AGREE.getCode()); +this.imgStorePersonAuditMapper.update(personAudit); +return result; +} +private ImgStorePersonAudit getAuditById(String id) throws ServiceException { +if (StringUtils.isEmpty(id)) { +throw new ServiceException("53060537", this.messageSource +.getMessage("53060537", null, LocaleContextHolder.getLocale())); +} +ImgStorePersonAudit personAudit = this.imgStorePersonAuditMapper.selectByPrimaryKey(id, CpPersonAuditEnum.INIT.getCode()); +if (personAudit == null) { +throw new ServiceException("53060538", this.messageSource +.getMessage("53060538", null, LocaleContextHolder.getLocale())); +} +return personAudit; +} +@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}, value = "transactionManager") +@CloudwalkParamsValidate +public CloudwalkResult auditRefuse(String id, CloudwalkCallContext context) throws ServiceException { +ImgStorePersonAudit personAudit = getAuditById(id); +personAudit.setId(id); +personAudit.setLastUpdateTime(Long.valueOf(System.currentTimeMillis())); +personAudit.setLastUpdateUserId(context.getUser().getCaller()); +personAudit.setAuditStatus(CpPersonAuditEnum.REFUSE.getCode()); +try { +this.imgStorePersonAuditMapper.update(personAudit); +} catch (Exception e) { +this.logger.error("人员注册审核拒绝失败,原因:", e); +throw new ServiceException("53060539", this.messageSource +.getMessage("53060539", null, LocaleContextHolder.getLocale())); +} +return CloudwalkResult.success(Boolean.valueOf(true)); +} +@CloudwalkParamsValidate +public CloudwalkResult batchAgree(List ids, CloudwalkCallContext context) throws ServiceException { +if (CollectionUtils.isEmpty(ids)) { +throw new ServiceException("53060537", this.messageSource +.getMessage("53060537", null, LocaleContextHolder.getLocale())); +} +try { +List auditList = this.imgStorePersonAuditMapper.queryByIds(ids, CpPersonAuditEnum.INIT.getCode()); +if (CollectionUtils.isEmpty(auditList)) { +return CloudwalkResult.fail("53060538", this.messageSource +.getMessage("53060538", null, LocaleContextHolder.getLocale())); +} +String updateUserId = context.getUser().getCaller(); +List imageIdResultList = this.imgPersonHandler.batchAgreeTransactional(context, auditList, updateUserId); +if (Collections3.isNotEmpty(imageIdResultList)) { +imageIdResultList.parallelStream() +.forEach(imageId -> this.cpImageStorePersonSynManager.handleGroupPersonSynTask(imageId)); +} +} catch (ServiceException e) { +this.logger.error("人员注册批量同构失败,原因:{}", e.getMessage()); +throw e; +} catch (Exception e) { +this.logger.error("人员注册批量同构失败,原因:{}", e); +throw new ServiceException("53060539", this.messageSource +.getMessage("53060539", null, LocaleContextHolder.getLocale())); +} +return CloudwalkResult.success(Boolean.valueOf(true)); +} +@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}, value = "transactionManager") +@CloudwalkParamsValidate +public CloudwalkResult batchRefuse(List ids, CloudwalkCallContext context) throws ServiceException { +if (CollectionUtils.isEmpty(ids)) { +throw new ServiceException("53060537", this.messageSource +.getMessage("53060537", null, LocaleContextHolder.getLocale())); +} +long time = System.currentTimeMillis(); +String updateUserId = context.getUser().getCaller(); +List applyList = (List)ids.stream().map(id -> new ImgStorePersonAuditApply(id, Long.valueOf(time), updateUserId, CpPersonAuditEnum.REFUSE.getCode())).collect(Collectors.toList()); +try { +this.imgStorePersonAuditMapper.batchUpdate(applyList, CpPersonAuditEnum.INIT.getCode()); +} catch (Exception e) { +this.logger.error("人员注册批量拒绝失败,原因:", e); +throw new ServiceException("53060539", this.messageSource +.getMessage("53060539", null, LocaleContextHolder.getLocale())); +} +return CloudwalkResult.success(Boolean.valueOf(true)); +} +public CloudwalkResult> page(PersonAuditQueryParam param, CloudwalkPageInfo page, CloudwalkCallContext context) throws ServiceException { +CloudwalkPageAble pageAble; +String businessId = StringUtils.isEmpty(param.getBusinessId()) ? context.getCompany().getCompanyId() : param.getBusinessId(); +ImgStorePersonAuditQueryDto dto = (ImgStorePersonAuditQueryDto)BeanCopyUtils.copyProperties(param, new ImgStorePersonAuditQueryDto()); +dto.setBusinessId(businessId); +try { +PageHelper.startPage(page.getCurrentPage(), page.getPageSize()); +Page pageData = (Page)this.imgStorePersonAuditMapper.query(dto); +List result = Optional.>ofNullable(pageData.getResult()).orElse(Collections.emptyList()); +List propertyList = this.imgStorePersonPropertiesMapper.selectByIds(businessId, null); +Map propertyMap = (Map)propertyList.stream().collect(Collectors.toMap(ImgStorePersonProperties::getCode, pro -> pro)); +List collect = (List)result.stream().map(item -> { PersonAuditGetResult auditGetResult = (PersonAuditGetResult)BeanCopyUtils.copyProperties(item, PersonAuditGetResult.class); auditGetResult.setUserPropertiesList(getUserProperties(item, propertyMap)); return auditGetResult; }).collect(Collectors.toList()); +pageAble = new CloudwalkPageAble(collect, page, pageData.getTotal()); +} catch (Exception e) { +this.logger.error("分页查询人员注册信息失败,原因:", e); +throw new ServiceException("53060540", this.messageSource +.getMessage("53060540", null, LocaleContextHolder.getLocale())); +} +return CloudwalkResult.success(pageAble); +} +private List getUserProperties(ImgStorePersonAudit audit, Map propertyMap) { +List result = new ArrayList<>(); +if (audit == null) { +return result; +} +List codes = JSONObject.parseArray(audit.getUserProperties(), String.class); +List names = JSONObject.parseArray(audit.getUserPropertiesName(), String.class); +if (!CollectionUtils.isEmpty(codes) && !CollectionUtils.isEmpty(names) && codes.size() == names.size()) { +for (int i = 0; i < codes.size(); i++) { +Object fieldValue; UserProperties properties = new UserProperties(); +String code = codes.get(i); +properties.setCode(code); +properties.setLabel(names.get(i)); +properties.setType(((ImgStorePersonProperties)propertyMap.get(code)).getType().shortValue()); +if (Objects.equals(code, "organizationIds")) { +fieldValue = audit.getOrganizationNames(); +} else if (Objects.equals(code, "labelIds")) { +fieldValue = audit.getLabelNames(); +} else { +Field field = ReflectionUtils.findField(audit.getClass(), code); +if (field == null) { +continue; +} +field.setAccessible(true); +fieldValue = ReflectionUtils.getField(field, audit); +} +properties.setValue(fieldValue); +result.add(properties); +continue; +} +} +if (Objects.equals(audit.getSource(), CpPersonSourceEnum.DEVICE.getCode())) { +UserProperties properties = new UserProperties(); +properties.setCode("deviceName"); +properties.setLabel("设备名称"); +properties.setValue(audit.getDeviceName()); +result.add(properties); +} +return result; +} +public CloudwalkResult userCheck(PersonAuditCheckParam param, CloudwalkCallContext context) throws ServiceException { +ImgStorePersonAudit personAudit; +CloudwalkResult checkCaptcha = this.captchaService.checkCaptcha((CheckCaptchaParam)param); +if (!checkCaptcha.isSuccess()) { +throw new ServiceException("53060546", this.messageSource +.getMessage("53060546", null, LocaleContextHolder.getLocale())); +} +String businessId = StringUtils.isEmpty(param.getBusinessId()) ? context.getCompany().getCompanyId() : param.getBusinessId(); +param.setBusinessId(businessId); +String column = CpPersonAuditUniqueEnum.getMessage(param.getCheckName()); +if (column == null) { +throw new ServiceException("53060547", this.messageSource +.getMessage("53060547", null, LocaleContextHolder.getLocale())); +} +ImgStoreAuditUserQueryDto queryDto = new ImgStoreAuditUserQueryDto(); +queryDto.setBusinessId(businessId); +Field targetField = ReflectionUtils.findField(queryDto.getClass(), param.getCheckName()); +if (targetField == null) { +throw new ServiceException("53060547", this.messageSource +.getMessage("53060547", null, LocaleContextHolder.getLocale())); +} +targetField.setAccessible(true); +ReflectionUtils.setField(targetField, queryDto, param.getCheckNameValue()); +try { +personAudit = this.imgStorePersonAuditMapper.userQuery(queryDto); +} catch (Exception e) { +this.logger.error("人员注册查询失败,原因:{}", e.getMessage()); +return CloudwalkResult.fail("53060548", this.messageSource +.getMessage("53060548", null, LocaleContextHolder.getLocale())); +} +if (personAudit == null) { +return CloudwalkResult.fail("53060548", this.messageSource +.getMessage("53060548", null, LocaleContextHolder.getLocale())); +} +Short auditStatus = personAudit.getAuditStatus(); +PersonAuditResult auditResult = new PersonAuditResult(); +auditResult.setAuditStatus(auditStatus); +auditResult.setAuditStatusStr(CpPersonAuditEnum.getMessage(auditStatus)); +return CloudwalkResult.success(auditResult); +} +public CloudwalkResult checkById(PersonAuditParam param, CloudwalkCallContext context) throws ServiceException { +if (StringUtils.isBlank(param.getId())) { +return CloudwalkResult.fail("53060545", this.messageSource.getMessage("53060545", null, LocaleContextHolder.getLocale())); +} +ImgStorePersonAudit personAudit = this.imgStorePersonAuditMapper.selectByPrimaryKey(param.getId(), null); +if (null == personAudit) { +throw new ServiceException("53060548", this.messageSource.getMessage("53060548", null, LocaleContextHolder.getLocale())); +} +List propertyList = this.imgStorePersonPropertiesMapper.selectByIds(personAudit.getBusinessId(), null); +Map propertyMap = (Map)propertyList.stream().collect(Collectors.toMap(ImgStorePersonProperties::getCode, pro -> pro)); +PersonAuditGetResult result = (PersonAuditGetResult)BeanCopyUtils.copyProperties(personAudit, PersonAuditGetResult.class); +result.setUserPropertiesList(getUserProperties(personAudit, propertyMap)); +return CloudwalkResult.success(result); +} } + +/* Location: /media/zebra/9e8fa357-7db6-4d70-88ed-d5de5a059a663/星河湾星中星/部署包/ninca_common_component_organization_01-ninca_common_component_organization/ninca-common-component-organization-V2.9.2_20210730/BOOT-INF/lib/cwos-component-organization-service-v2.9.2_xinghewan.jar!/cn/cloudwalk/service/organization/service/PersonAuditServiceImpl.class + * Java compiler version: 8 (52.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file