修改头像网络地址改成base64

This commit is contained in:
lxd 2025-04-01 10:40:50 +08:00
parent 3b27b67712
commit b97dfcb6ff
3 changed files with 35 additions and 4 deletions

View File

@ -13,6 +13,7 @@ import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.Map;
@ -206,4 +207,16 @@ public class HttpUtils {
return response.body();
}
}
/*
* 转换base64
* */
public static String getImageAsBase64(String imageUrl) throws IOException {
HttpResponse response = HttpRequest.get(imageUrl).execute();
if (response.isOk()) {
byte[] imageBytes = response.bodyBytes();
return Base64.encode(imageBytes);
} else {
throw new IOException("Failed to fetch image, HTTP status code: " + response.getStatus());
}
}
}

View File

@ -455,10 +455,11 @@ public class InspectPatientController {
updateReqVO.setNcgcode(checkBarCode2);
updateReqVO.setXcgcode(checkBarCode1);
updateReqVO.setShqx(checkBarCode3);
if(headurl!=null||headurl!="")
{
updateReqVO.setHeadPicUrl(headurl+"?certificatenumber="+patientDO.getCardId());
}
//采用转base64
// if(headurl!=null||headurl!="")
// {
// updateReqVO.setHeadPicUrl(headurl+"?certificatenumber="+patientDO.getCardId());
// }
patientService.updatePatientInfo(updateReqVO);
}
@ -938,6 +939,19 @@ public class InspectPatientController {
}
list.add(inspectPatientitemsSaveReqVO);
patientitemsService.updatePatientitemInfo(list);
if(dataMap.get("personimg") != null|| dataMap.get("personimg") != "")
{
String headurl = dataMap.get("personimg").toString();
String base64 = HttpUtils.getImageAsBase64(headurl);
if(base64!=null|| base64!="")
{
InspectPatientSaveReqVO updateReqVO = new InspectPatientSaveReqVO();
updateReqVO.setMedicalSn(medicalSn);
updateReqVO.setHeadPicUrl(base64);
patientService.updatePatientInfo(updateReqVO);
}
}
}
} catch (IOException e) {

View File

@ -143,6 +143,10 @@ public class InspectPatientServiceImpl implements InspectPatientService {
.set(InspectPatientDO::getXcgcode, updateReqVO.getXcgcode())
.set(InspectPatientDO::getNcgcode, updateReqVO.getNcgcode())
.set(InspectPatientDO::getShqx, updateReqVO.getShqx());
if(updateReqVO.getHeadPicUrl()!=null)
{
updateWrapper.set(InspectPatientDO::getHeadPicUrl, updateReqVO.getHeadPicUrl());
}
return patientMapper.update(null, updateWrapper);
}