From 2a57b759c92381d7878996a74d772d6b46255964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=95=B8=E9=9D=9E?= <8153694@qq.com> Date: Wed, 6 Sep 2023 13:47:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../task/SyncRegisterUserPicTaskImpl.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncRegisterUserPicTaskImpl.java diff --git a/attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncRegisterUserPicTaskImpl.java b/attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncRegisterUserPicTaskImpl.java new file mode 100644 index 00000000..26803368 --- /dev/null +++ b/attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncRegisterUserPicTaskImpl.java @@ -0,0 +1,86 @@ +package com.mortals.xhx.daemon.task; + +import cn.hutool.http.HttpUtil; +import com.mortals.framework.exception.AppException; +import com.mortals.framework.service.ITask; +import com.mortals.framework.service.ITaskExcuteService; +import com.mortals.framework.utils.ServletUtils; +import com.mortals.xhx.base.system.upload.service.UploadService; +import com.mortals.xhx.module.hik.face.model.req.img.ImgReq; +import com.mortals.xhx.module.hik.face.service.IHikFaceService; +import com.mortals.xhx.module.staff.model.StaffEntity; +import com.mortals.xhx.module.staff.model.StaffQuery; +import com.mortals.xhx.module.staff.service.StaffService; +import lombok.extern.slf4j.Slf4j; +import org.checkerframework.checker.units.qual.A; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; +import org.springframework.web.multipart.MultipartFile; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 鍚屾鍛樺伐鐨勮瘉浠剁収鐗囥€� + */ +@Slf4j +@Service("SyncRegisterUserPicTask") +public class SyncRegisterUserPicTaskImpl implements ITaskExcuteService { + + @Autowired + private UploadService uploadService; + @Autowired + private IHikFaceService hikFaceService; + @Autowired + private StaffService staffService; + + + @Value("${php.host:''}") + private String host; + + + @Override + public void excuteTask(ITask task) throws AppException { + log.info("鍚屾鍛樺伐鐓х墖浠诲姟"); + syncRegisterUsersPhotos(); + log.info("鍚屾鍛樺伐浠诲姟鐓х墖瀹屾垚"); + + } + + + private void syncRegisterUsersPhotos() { + List<StaffEntity> staffList = staffService.find(new StaffQuery().source(1)).stream() + .filter(item -> ObjectUtils.isEmpty(item.getPhotoPath())) + .filter(item -> !ObjectUtils.isEmpty(item.getPicUri())).collect(Collectors.toList()); + + + for (StaffEntity staff : staffList) { + ImgReq imgReq = new ImgReq(); + imgReq.setServerIndexCode(staff.getServerIndexCode()); + imgReq.setPicUri(staff.getPicUri()); + try { + InputStream inputStream = hikFaceService.callPostImgs(imgReq); + if (!ObjectUtils.isEmpty(inputStream)) { + MultipartFile file = ServletUtils.getMultipartFile(inputStream, "photo.jpg"); + String filePath = uploadService.saveFileUpload(file, "file/fileupload/staff", null); + staff.setPhotoPath(filePath); + staffService.update(staff); + } else { + log.error("鑾峰彇鍥剧墖寮傚父锛�"); + } + } catch (Exception e) { + log.error("涓嬭浇鍥剧墖寮傚父", e.getMessage()); + } + } + } + + + @Override + public void stopTask(ITask task) throws AppException { + + } +} -- 2.24.3