refactor(sis): base64指定格式JPG
This commit is contained in:
parent
9217befba8
commit
20f6cc8541
@ -1,10 +1,10 @@
|
||||
package org.dromara.sis.service.impl;
|
||||
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
@ -30,11 +30,10 @@ import org.dromara.sis.sdk.unview.model.UvModel;
|
||||
import org.dromara.sis.service.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 授权记录Service业务层处理
|
||||
@ -182,7 +181,7 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
|
||||
// 宇视添加人像
|
||||
UvModel.AddPersonParams addPersonParams = new UvModel.AddPersonParams();
|
||||
addPersonParams.setPerson_name(imgVo.getImgName());
|
||||
addPersonParams.setImage_base64(Base64.getEncoder().encodeToString(imageByte));
|
||||
addPersonParams.setImage_base64(base64Helper(imageByte));
|
||||
addPersonParams.setLib_id(Math.toIntExact(eqp_lib_id));
|
||||
addPersonParams.setSex(imgVo.getSex());
|
||||
addPersonParams.setEmail(imgVo.getEmail());
|
||||
@ -195,7 +194,7 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
|
||||
eqp_lib_img_id = addResult.getPerson_id();
|
||||
|
||||
} else {
|
||||
UvModel.WorkClothesInfo addResult = unViewAiBoxApi.addWorkClothes(systemInfo, Math.toIntExact(eqp_lib_id), Base64.getEncoder().encodeToString(imageByte));
|
||||
UvModel.WorkClothesInfo addResult = unViewAiBoxApi.addWorkClothes(systemInfo, Math.toIntExact(eqp_lib_id), base64Helper(imageByte));
|
||||
eqp_lib_img_id = addResult.getWorkclothes_id();
|
||||
}
|
||||
Assert.notNull(eqp_lib_img_id, "图片上传宇视盒子失败");
|
||||
@ -295,6 +294,21 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String base64Helper(byte[] imageByte) throws IOException {
|
||||
// 1. 将字节数组解码为BufferedImage对象
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
|
||||
|
||||
// 2. 将图片重新编码为JPG格式的字节数组
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
||||
ImgUtil.convert(bis, "jpg", bos);
|
||||
|
||||
byte[] jpgBytes = bos.toByteArray();
|
||||
|
||||
// 3. 将JPG字节数组转为Base64字符串
|
||||
return Base64.getEncoder().encodeToString(jpgBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean singleAuth(SingleAuthRecordBo bo) {
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user