修正头像
This commit is contained in:
parent
667ffdb9ea
commit
7f6dcd5061
@ -3,6 +3,8 @@ package com.example.caseData.request.CaseClinicalVideoRequest;
|
||||
import com.example.caseData.request.clinicalRequest.getClinicalArticleSearchPage;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import com.fasterxml.jackson.annotation.Nulls;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
import org.springframework.util.StringUtils;
|
||||
@ -45,11 +47,13 @@ public class addClinicalVideoApp {
|
||||
// 作者
|
||||
@JsonProperty("author")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonSetter(nulls = Nulls.SKIP)
|
||||
private List<Author> author;
|
||||
|
||||
// 标签
|
||||
@JsonProperty("label")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonSetter(nulls = Nulls.SKIP)
|
||||
private List<Label> label;
|
||||
|
||||
/**
|
||||
|
||||
@ -563,43 +563,18 @@ public class CaseClinicalVideoService {
|
||||
throw new BusinessException("-1", "内部错误,添加视频失败");
|
||||
}
|
||||
|
||||
// 新增标签
|
||||
for (addClinicalVideoApp.Label label : r.getLabel()){
|
||||
CaseClinicalVideoLabelModel caseClinicalVideoLabel = new CaseClinicalVideoLabelModel();
|
||||
caseClinicalVideoLabel.setVideoId(caseClinicalVideo.getVideoId());
|
||||
caseClinicalVideoLabel.setAppIden(label.getAppIden());
|
||||
caseClinicalVideoLabel.setLabelName(label.getLabelName());
|
||||
res = caseClinicalVideoLabelDao.insert(caseClinicalVideoLabel);
|
||||
if (res <= 0){
|
||||
throw new BusinessException("-1", "内部错误,添加视频标签失败");
|
||||
}
|
||||
|
||||
// 新增标签统计
|
||||
caseClinicalService.IncStatsCaseClinicalLabel(label.getAppIden(),label.getLabelName(),2,pushDate);
|
||||
}
|
||||
|
||||
// 新增作者
|
||||
if (r.getAuthor() != null && !r.getAuthor().isEmpty()) {
|
||||
for (addClinicalVideoApp.Author author : r.getAuthor()){
|
||||
// 获取app用户数据
|
||||
GetUserInfoResponse result = userInfo.getUserInfoByUuid(author.getDoctorIden());
|
||||
CaseClinicalDoctorModel caseClinicalDoctor = userService.GetCaseClinicalDoctor(result);
|
||||
|
||||
CaseClinicalVideoAuthorModel caseClinicalVideoAuthor = new CaseClinicalVideoAuthorModel();
|
||||
caseClinicalVideoAuthor.setVideoId(caseClinicalVideo.getVideoId());
|
||||
caseClinicalVideoAuthor.setDoctorId(String.valueOf(caseClinicalDoctor.getDoctorId()));
|
||||
caseClinicalVideoAuthorDao.insert(caseClinicalVideoAuthor);
|
||||
|
||||
// 新增作者统计
|
||||
caseClinicalService.IncStatsCaseClinicalDoctor(String.valueOf(caseClinicalDoctor.getDoctorId()),2,pushDate);
|
||||
|
||||
// 新增医院统计
|
||||
caseClinicalService.IncStatsCaseClinicalHospital(String.valueOf(caseClinicalDoctor.getHospitalId()),2,pushDate);
|
||||
}
|
||||
}
|
||||
|
||||
// 新增统计
|
||||
IncClinicalVideoStats(String.valueOf(caseClinicalVideo.getVideoId()),4,1);
|
||||
|
||||
// 作者处理
|
||||
if (r.getAuthor() != null) {
|
||||
AddClinicalVideoAppAuthor(caseClinicalVideo,r);
|
||||
}
|
||||
|
||||
// 标签处理
|
||||
if (r.getLabel() != null) {
|
||||
AddClinicalVideoAppLabel(caseClinicalVideo,r);
|
||||
}
|
||||
}
|
||||
|
||||
// 修改
|
||||
@ -624,12 +599,14 @@ public class CaseClinicalVideoService {
|
||||
caseClinicalVideoDao.updateById(caseClinicalVideo);
|
||||
|
||||
// 作者处理
|
||||
if (r.getAuthor() != null && !r.getAuthor().isEmpty()) {
|
||||
if (r.getAuthor() != null) {
|
||||
AddClinicalVideoAppAuthor(caseClinicalVideo,r);
|
||||
}
|
||||
|
||||
// 标签处理
|
||||
AddClinicalVideoAppLabel(caseClinicalVideo,r);
|
||||
if (r.getLabel() != null) {
|
||||
AddClinicalVideoAppLabel(caseClinicalVideo,r);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除
|
||||
@ -684,8 +661,6 @@ public class CaseClinicalVideoService {
|
||||
}
|
||||
|
||||
// 新增新的作者
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime pushDate = LocalDateTime.parse(r.getPushDate(), formatter);
|
||||
|
||||
// 获取app用户数据
|
||||
for (addClinicalVideoApp.Author author : r.getAuthor()){
|
||||
@ -709,11 +684,13 @@ public class CaseClinicalVideoService {
|
||||
caseClinicalVideoAuthor.setDoctorId(String.valueOf(caseClinicalDoctor.getDoctorId()));
|
||||
caseClinicalVideoAuthorDao.insert(caseClinicalVideoAuthor);
|
||||
|
||||
LocalDateTime lastPushDate = caseClinicalVideoDao.selectLastVideoPushDateByDoctorId(caseClinicalDoctor.getDoctorId());
|
||||
|
||||
// 新增作者统计
|
||||
caseClinicalService.IncStatsCaseClinicalDoctor(String.valueOf(caseClinicalDoctor.getDoctorId()),2,pushDate);
|
||||
caseClinicalService.IncStatsCaseClinicalDoctor(String.valueOf(caseClinicalDoctor.getDoctorId()),2,lastPushDate);
|
||||
|
||||
// 新增医院统计
|
||||
caseClinicalService.IncStatsCaseClinicalHospital(String.valueOf(caseClinicalDoctor.getHospitalId()),2,pushDate);
|
||||
caseClinicalService.IncStatsCaseClinicalHospital(String.valueOf(caseClinicalDoctor.getHospitalId()),2,lastPushDate);
|
||||
}
|
||||
}
|
||||
|
||||
@ -736,9 +713,6 @@ public class CaseClinicalVideoService {
|
||||
caseClinicalVideoLabelDao.deleteById(label.getVideoLabelId());
|
||||
}
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime pushDate = LocalDateTime.parse(r.getPushDate(), formatter);
|
||||
|
||||
for (addClinicalVideoApp.Label label : r.getLabel()){
|
||||
CaseClinicalVideoLabelModel caseClinicalVideoLabel = new CaseClinicalVideoLabelModel();
|
||||
caseClinicalVideoLabel.setVideoId(caseClinicalVideo.getVideoId());
|
||||
@ -746,8 +720,10 @@ public class CaseClinicalVideoService {
|
||||
caseClinicalVideoLabel.setLabelName(label.getLabelName());
|
||||
caseClinicalVideoLabelDao.insert(caseClinicalVideoLabel);
|
||||
|
||||
LocalDateTime lastPushDate = caseClinicalVideoDao.selectLastVideoPushDateByLabelId(label.getAppIden());
|
||||
|
||||
// 新增标签统计
|
||||
caseClinicalService.IncStatsCaseClinicalLabel(label.getAppIden(),caseClinicalVideoLabel.getLabelName(),2,pushDate);
|
||||
caseClinicalService.IncStatsCaseClinicalLabel(label.getAppIden(),caseClinicalVideoLabel.getLabelName(),2,lastPushDate);
|
||||
}
|
||||
}
|
||||
|
||||
@ -767,7 +743,7 @@ public class CaseClinicalVideoService {
|
||||
List<CaseClinicalVideoLabelModel> caseClinicalVideoLabels = caseClinicalVideoLabelDao.selectList(labelQueryWrapper);
|
||||
for (CaseClinicalVideoLabelModel label : caseClinicalVideoLabels){
|
||||
// 减少标签统计
|
||||
caseClinicalService.DecStatsCaseClinicalLabel(String.valueOf(caseClinicalVideo.getVideoId()),2);
|
||||
caseClinicalService.DecStatsCaseClinicalLabel(label.getAppIden(),2);
|
||||
}
|
||||
|
||||
// 获取视频作者数据
|
||||
|
||||
@ -9,6 +9,7 @@ import com.example.caseData.dao.CaseClinicalRecordScoreDao;
|
||||
import com.example.caseData.dao.UserDao;
|
||||
import com.example.caseData.dto.publicDto.LoginDto;
|
||||
import com.example.caseData.exception.BusinessException;
|
||||
import com.example.caseData.extend.aliyun.Oss;
|
||||
import com.example.caseData.extend.app.Hospital.GetHospitalByUuidResponse;
|
||||
import com.example.caseData.extend.app.Hospital.Hospital;
|
||||
import com.example.caseData.extend.app.Score.Score;
|
||||
@ -23,11 +24,23 @@ import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Random;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
import static com.baomidou.mybatisplus.extension.toolkit.Db.save;
|
||||
|
||||
@ -131,6 +144,7 @@ public class UserService {
|
||||
userModelWrapper.eq(UserModel::getUserIden, r.getData().getUuid());
|
||||
UserModel user = userDao.selectOne(userModelWrapper);
|
||||
if (user == null){
|
||||
|
||||
// 构造 UserModel 对象
|
||||
user = new UserModel();
|
||||
user.setUserIden(data.getUuid());
|
||||
@ -142,7 +156,13 @@ public class UserService {
|
||||
user.setOpenId("");
|
||||
user.setUnionId("");
|
||||
user.setSex(0);
|
||||
user.setAvatar(data.getPhoto());
|
||||
if (data.getPhoto() != null) {
|
||||
String ossPath = UserService.handleUserImage(data.getPhoto());
|
||||
user.setAvatar(ossPath);
|
||||
}else{
|
||||
user.setAvatar("");
|
||||
}
|
||||
|
||||
user.setDepartmentName(data.getOfficeName());
|
||||
user.setTitle(StringToInt.DoctorTitleToInt(data.getPositionName()));
|
||||
user.setAddress(data.getProvName());
|
||||
@ -172,6 +192,15 @@ public class UserService {
|
||||
user.setAddress(data.getProvName());
|
||||
}
|
||||
|
||||
if (data.getPhoto() != null) {
|
||||
String phone = Replace.removeOssDomain(data.getPhoto());
|
||||
|
||||
if (!Objects.equals(user.getAvatar(),phone )){
|
||||
String ossPath = UserService.handleUserImage(data.getPhoto());
|
||||
user.setAvatar(ossPath);
|
||||
}
|
||||
}
|
||||
|
||||
userDao.updateById(user);
|
||||
}
|
||||
|
||||
@ -257,12 +286,12 @@ public class UserService {
|
||||
caseClinicalDoctorWrapper.eq(CaseClinicalDoctorModel::getDoctorIden, data.getUuid());
|
||||
CaseClinicalDoctorModel caseClinicalDoctor = caseClinicalDoctorDao.selectOne(caseClinicalDoctorWrapper);
|
||||
if (caseClinicalDoctor == null){
|
||||
CaseClinicalDoctorModel c = new CaseClinicalDoctorModel();
|
||||
c.setDoctorName(data.getRealname());
|
||||
c.setDoctorIden(data.getUuid());
|
||||
c.setHospitalId(basicHospital.getHospitalId());
|
||||
c.setAvatar(data.getPhoto());
|
||||
int res = caseClinicalDoctorDao.insert(c);
|
||||
caseClinicalDoctor = new CaseClinicalDoctorModel();
|
||||
caseClinicalDoctor.setDoctorName(data.getRealname());
|
||||
caseClinicalDoctor.setDoctorIden(data.getUuid());
|
||||
caseClinicalDoctor.setHospitalId(basicHospital.getHospitalId());
|
||||
caseClinicalDoctor.setAvatar(data.getPhoto());
|
||||
int res = caseClinicalDoctorDao.insert(caseClinicalDoctor);
|
||||
if (res <= 0){
|
||||
throw new BusinessException("操作失败");
|
||||
}
|
||||
@ -319,4 +348,66 @@ public class UserService {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理用户头像:下载远程头像并上传至 OSS
|
||||
*
|
||||
* @param wxAvatarUrl 微信头像地址
|
||||
* @return OSS 路径(以 / 开头),如 /user/avatar/202507301530123456.png
|
||||
*/
|
||||
public static String handleUserImage(String wxAvatarUrl) {
|
||||
if (wxAvatarUrl == null || wxAvatarUrl.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
HttpURLConnection conn = null;
|
||||
try {
|
||||
// 1. 下载远程图片
|
||||
URL url = new URL(wxAvatarUrl);
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setConnectTimeout(5000);
|
||||
conn.setReadTimeout(10000);
|
||||
conn.setRequestMethod("GET");
|
||||
|
||||
if (conn.getResponseCode() != 200) {
|
||||
throw new BusinessException("图片处理失败");
|
||||
}
|
||||
|
||||
try (InputStream input = conn.getInputStream();
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int len;
|
||||
while ((len = input.read(buffer)) != -1) {
|
||||
output.write(buffer, 0, len);
|
||||
}
|
||||
|
||||
byte[] imageBytes = output.toByteArray();
|
||||
if (imageBytes.length == 0) {
|
||||
throw new BusinessException("图片处理失败");
|
||||
}
|
||||
|
||||
// 2. 生成 OSS 路径
|
||||
String dateTimeStr = LocalDateTime.now()
|
||||
.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
||||
int randomSuffix = new Random().nextInt(9000) + 1000;
|
||||
String ossPath = "user/avatar/" + dateTimeStr + randomSuffix + ".png";
|
||||
|
||||
// 3. 上传 OSS
|
||||
boolean success = Oss.putObject("/" + ossPath, imageBytes);
|
||||
if (!success) {
|
||||
throw new BusinessException("图片处理失败");
|
||||
}
|
||||
|
||||
return "/" + ossPath;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(e.getMessage());
|
||||
} finally {
|
||||
if (conn != null) {
|
||||
conn.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user