feat(sis): 1
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
package org.dromara.sis.service.impl;
|
package org.dromara.sis.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
|
import org.dromara.common.core.constant.CodePrefixConstants;
|
||||||
import org.dromara.common.core.utils.MapstructUtils;
|
import org.dromara.common.core.utils.MapstructUtils;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
@@ -17,10 +19,12 @@ import org.dromara.sis.domain.bo.SisPersonLibImgBo;
|
|||||||
import org.dromara.sis.domain.vo.*;
|
import org.dromara.sis.domain.vo.*;
|
||||||
import org.dromara.sis.mapper.SisPersonLibImgMapper;
|
import org.dromara.sis.mapper.SisPersonLibImgMapper;
|
||||||
import org.dromara.sis.sdk.huawei.HuaWeiBoxApi;
|
import org.dromara.sis.sdk.huawei.HuaWeiBoxApi;
|
||||||
|
import org.dromara.sis.sdk.huawei.domain.AddHWPersonReq;
|
||||||
import org.dromara.sis.service.*;
|
import org.dromara.sis.service.*;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.security.MessageDigest;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,9 +113,71 @@ public class SisPersonLibImgServiceImpl implements ISisPersonLibImgService {
|
|||||||
Assert.notNull(add, "数据处理失败");
|
Assert.notNull(add, "数据处理失败");
|
||||||
boolean flag = baseMapper.insert(add) > 0;
|
boolean flag = baseMapper.insert(add) > 0;
|
||||||
Assert.isTrue(flag, "新增数据失败");
|
Assert.isTrue(flag, "新增数据失败");
|
||||||
|
|
||||||
|
if (bo.getResidentPersonId() == null){
|
||||||
|
try {
|
||||||
|
bo.setId(add.getId());
|
||||||
|
// 记录图片md5值
|
||||||
|
byte[] imgByte = remoteFileService.downloadToByteArray(bo.getImgOssId());
|
||||||
|
String md5 = calculateMD5(imgByte);
|
||||||
|
bo.setImgMd5Value(md5);
|
||||||
|
|
||||||
|
AddHWPersonReq req = new AddHWPersonReq();
|
||||||
|
req.setIndex(CodePrefixConstants.PERSON_LIB_IMAGE_CODE_PREFIX + IdUtil.getSnowflakeNextIdStr());
|
||||||
|
req.setName(bo.getImgName());
|
||||||
|
req.setCredentialType("5");
|
||||||
|
req.setCredentialNumber(add.getId().toString());
|
||||||
|
req.setGender(bo.getSex() == 1 ? "0" : bo.getSex() == 2 ? "1" : "-1");
|
||||||
|
|
||||||
|
ArrayList<String> pictures = new ArrayList<>();
|
||||||
|
pictures.add(Base64.getEncoder().encodeToString(imgByte));
|
||||||
|
req.setPictures(pictures);
|
||||||
|
Long pId = huaWeiBoxApi.addPerson(List.of(req));
|
||||||
|
Assert.notNull(pId, "调用华为盒子新增图片失败");
|
||||||
|
bo.setRemoteHwId(pId);
|
||||||
|
this.updateByBo(bo);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 直接计算字节数组的MD5值
|
||||||
|
*
|
||||||
|
* @param data 图片的字节数组
|
||||||
|
* @return 32位小写MD5字符串
|
||||||
|
*/
|
||||||
|
private String calculateMD5(byte[] data) throws Exception {
|
||||||
|
if (data == null) {
|
||||||
|
throw new IllegalArgumentException("输入数据不能为null");
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||||
|
md.update(data);
|
||||||
|
return bytesToHex(md.digest());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字节数组转十六进制字符串
|
||||||
|
*
|
||||||
|
* @param bytes 字节数组
|
||||||
|
* @return 32位十六进制字符串
|
||||||
|
*/
|
||||||
|
private String bytesToHex(byte[] bytes) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (byte b : bytes) {
|
||||||
|
// %02x 表示两位小写十六进制,不足两位补0
|
||||||
|
sb.append(String.format("%02x", b));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改人像信息
|
* 修改人像信息
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user