Commit 3c7e4391 authored by zhangyanduan's avatar zhangyanduan

fix: 修复捷顺接口中新增用户的头像数据转换为base64字符串上传

parent 3e887912
......@@ -32,7 +32,10 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
/**
......@@ -288,7 +291,14 @@ public class JieLinkServiceImpl implements IJieLinkService {
pushData.setPersonNo(userData.getUsername());//人员编号
pushData.setPersonName(userData.getName());//姓名 必填
pushData.setPersonGender(StringUtils.equals("0",userData.getSex())?1:StringUtils.equals("1",userData.getSex())?0:null);//性别
pushData.setPersonPhoto(userData.getFaceAddress());
//此处需要将头像信息转换成BASE64数据存储
if(StringUtils.isNotBlank(userData.getFaceAddress())){
//读取文件将文件转换为base64字符串
String picBase64Str = encryptToBase64(userData.getFaceAddress());
if(StringUtils.isNotBlank(picBase64Str)){
pushData.setPersonPhoto(picBase64Str);
}
}
//身份证处理
if(StringUtils.isNotBlank(userData.getIdNumber())){
if(userData.getIdNumber().trim().length()==15){
......@@ -764,5 +774,23 @@ public class JieLinkServiceImpl implements IJieLinkService {
}
}
/**
* 将文件转换为base64字符串
* @param filePath
* @return
*/
public String encryptToBase64(String filePath) {
if (filePath == null) {
return null;
}
try {
byte[] b = Files.readAllBytes(Paths.get(filePath));
return Base64.getEncoder().encodeToString(b);
} catch (IOException e) {
log.error("读取用户头像文件失败:"+e.getMessage(),e);
}
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment