人脸转换

This commit is contained in:
zt
2025-09-20 15:08:44 +08:00
parent 7fcf5ef303
commit 40a8f0770a
3 changed files with 84 additions and 0 deletions

View File

@ -208,4 +208,11 @@ public class TransferDataController {
transferDataService.userTransfer();
}
@GetMapping("/handleUserFace")
private void handleUserFace() {
transferDataService.handleUserFace();
}
}

View File

@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.*;
import org.dromara.project.domain.BusAttendance;
import org.dromara.transferData.domain.*;
import java.util.Map;
import java.util.List;
@ -75,4 +76,14 @@ public interface TransferDataMapper {
"</foreach>" +
"</script>")
List<UserFile> getUserFileList(List<Long> goIds);
@Select("<script>" +
"SELECT id,pace_photo FROM sub_construction_user " +
"WHERE id IN " +
"<foreach collection='goIds' item='userId' open='(' separator=',' close=')'>" +
"#{userId}" +
"</foreach>" +
"</script>")
Map<Long, String> getUserFace(List<Long> goIds);
}

View File

@ -813,4 +813,70 @@ public class TransferDataService {
semaphore.release();
}
}
public void handleUserFace() {
// 只查询需要更新的用户,且只查询必要的字段
List<SubConstructionUser> usersWithoutFacePic = constructionUserService.list(
Wrappers.<SubConstructionUser>lambdaQuery()
.and(wrapper -> wrapper.isNull(SubConstructionUser::getFacePic)
.or()
.eq(SubConstructionUser::getFacePic, ""))
.isNotNull(SubConstructionUser::getGoId)
);
if (usersWithoutFacePic.isEmpty()) {
log.info("没有需要更新人脸照片的用户");
return;
}
List<Long> goIds = usersWithoutFacePic.stream()
.map(SubConstructionUser::getGoId)
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (goIds.isEmpty()) {
log.info("没有有效的goId列表");
return;
}
// 获取人脸照片路径映射
Map<Long, String> userFace = transferDataMapper.getUserFace(goIds);
List<SubConstructionUser> updateList = new ArrayList<>();
for (SubConstructionUser user : usersWithoutFacePic) {
String facePic = userFace.get(user.getGoId());
if (facePic != null && !facePic.isEmpty()) {
Long facePicId = handleSinglePhotoLimit(facePic);
if (facePicId != null) {
// 只设置需要更新的字段
SubConstructionUser updateUser = new SubConstructionUser();
updateUser.setId(user.getId());
updateUser.setFacePic(facePicId.toString());
updateList.add(updateUser);
}
}
}
if (!updateList.isEmpty()) {
boolean success = constructionUserService.updateBatchById(updateList);
log.info("更新用户人脸照片完成,成功更新 {} 条记录", updateList.size());
if (!success) {
log.error("批量更新用户人脸照片失败");
}
} else {
log.info("没有需要更新的人脸照片数据");
}
}
}