From b08a36222b67202d0efcecef712bc0498f9c7b06 Mon Sep 17 00:00:00 2001 From: ovo Date: Wed, 6 Nov 2024 10:08:43 +0800 Subject: [PATCH] =?UTF-8?q?=E9=95=BF=E5=BA=86=E9=A1=B9=E7=9B=AE11.06?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shapelight-admin/pom.xml | 34 +++++ .../java/net/shapelight/AdminApplication.java | 8 +- .../face/factory/FaceEngineFactory.java | 4 +- .../modules/face/rtsp/RtspFrameGrabber.java | 11 +- .../httpapi/controler/HttpApiController.java | 25 +++- .../controller/{ => demo}/DemoController.java | 126 +++++++++++++++-- .../iCq/controller/demo/vo/DrawVo.java | 21 +++ .../video/CqSafeVideoController.java | 129 ++++++++++++++++-- .../iCq/controller/video/vo/FaceVideoVo.java | 5 + .../personTemp/TenPersonSyncTempEntity.java | 4 + .../personTemp/TenPersonSyncTempMapper.java | 24 ++++ .../modules/iCq/utils/DrawUtils.java | 90 ++++++++++++ .../modules/job/task/DbBakTask.java | 4 + .../job/task/PersonSynchronousTask.java | 100 ++++++++++++-- .../ten/controller/TenPersonController.java | 13 +- .../modules/ten/dao/TenPersonDao.java | 2 + .../modules/ten/service/TenPersonService.java | 3 + .../service/impl/TenPersonServiceImpl.java | 52 +++++++ .../resources/mapper/ten/TenPersonDao.xml | 6 + 19 files changed, 607 insertions(+), 54 deletions(-) rename shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/{ => demo}/DemoController.java (64%) create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/demo/vo/DrawVo.java create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/iCq/dal/dataobject/personTemp/TenPersonSyncTempEntity.java create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/iCq/dal/mysql/personTemp/TenPersonSyncTempMapper.java create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/iCq/utils/DrawUtils.java diff --git a/shapelight-admin/pom.xml b/shapelight-admin/pom.xml index 1721552..3c2d332 100644 --- a/shapelight-admin/pom.xml +++ b/shapelight-admin/pom.xml @@ -320,6 +320,37 @@ org.springframework.boot spring-boot-maven-plugin + + + + net.roseboy + classfinal-maven-plugin + 1.2.1 + + # + org.spring + net.shapelight + application.yml,application-dev.yml + hutool-all.jar + + + + + package + + classFinal + + + + + org.apache.maven.plugins @@ -345,6 +376,9 @@ + + + diff --git a/shapelight-admin/src/main/java/net/shapelight/AdminApplication.java b/shapelight-admin/src/main/java/net/shapelight/AdminApplication.java index 14464b9..2523566 100644 --- a/shapelight-admin/src/main/java/net/shapelight/AdminApplication.java +++ b/shapelight-admin/src/main/java/net/shapelight/AdminApplication.java @@ -32,8 +32,8 @@ import javax.annotation.PostConstruct; @EnableFeignClients //@MapperScan("net.shapelight.modules.sys.dao") public class AdminApplication { -/* @Autowired - CxFeignClient cxFeignClient;*/ + @Autowired + CxFeignClient cxFeignClient; public static void main(String[] args) { SpringApplication.run(AdminApplication.class, args); @@ -61,11 +61,11 @@ public class AdminApplication { // }); } - /*@PostConstruct + @PostConstruct void init() throws Exception { SslUtils.ignoreSsl(); String res = cxFeignClient.getToken("5bb50ad0cc40e10565089c35aa61e7f3","k9?8bCqaQ*R1e2Wx0f65AzY4^]LDp@_Z"); CxFeignConfig.token = res; - }*/ + } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/face/factory/FaceEngineFactory.java b/shapelight-admin/src/main/java/net/shapelight/modules/face/factory/FaceEngineFactory.java index bc90db4..13fe7f8 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/face/factory/FaceEngineFactory.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/face/factory/FaceEngineFactory.java @@ -33,10 +33,8 @@ public class FaceEngineFactory extends BasePooledObjectFactory { @Override public FaceEngine create() { - - FaceEngine faceEngine = new FaceEngine(ArcFaceAutoConfiguration.CACHE_LIB_FOLDER); - + /* FaceEngine faceEngine = new FaceEngine("/softTemp/jar/82K111TPM121XK4H.dat");*/ // FaceEngine faceEngine = new FaceEngine("/home/huangyifang/gb/咸阳师范/ArcSoft_ArcFacePro_linux_java_V4.1/libs/LINUX64/"); int activeCode; if (StringUtils.isNotEmpty(activeFile)) { diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/face/rtsp/RtspFrameGrabber.java b/shapelight-admin/src/main/java/net/shapelight/modules/face/rtsp/RtspFrameGrabber.java index c4e9c0c..64d2db0 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/face/rtsp/RtspFrameGrabber.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/face/rtsp/RtspFrameGrabber.java @@ -331,25 +331,28 @@ public class RtspFrameGrabber { params.put("personnelId", tenPerson.getOpenId()); params.put("personnelCardId", tenPerson.getIdCard()); params.put("personnelType", personnelTypeMap.get(tenPerson.getPersonType())); - params.put("dictSex", tenPerson.getGender() == 0 ? "女" : "男"); + params.put("dictSex", tenPerson.getGender() == 0 ? "男" : "女"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); params.put("watchVideoTime", sdf.format(System.currentTimeMillis())); + if(tenPerson.getIsWatchSafeVideo() != 1){ + tenPerson.setIsWatchSafeVideo(faceVideoVo.getIsHeadOnView() == 0 ? 2 : 1); + } - tenPerson.setIsWatchSafeVideo(faceVideoVo.getIsHeadOnView() == 0 ? 2 : 1); + //tenPerson.setIsWatchSafeVideo(); tenPersonService.updateById(tenPerson); System.out.println("params = " + params); if(faceVideoVo.getIsHeadOnView() == 1){ - /* JSONObject jsonObject = feignClient.savePmWatchVideoRecord(params); + JSONObject jsonObject = feignClient.savePmWatchVideoRecord(params); if (jsonObject.getBool("success") != null && jsonObject.getBool("success")) { personService.update(new LambdaUpdateWrapper() .set(TenPersonEntity::getIsWatchSafeVideo, 1) .eq(TenPersonEntity::getPersonId, userCompareInfo.getFaceId())); - }*/ + } } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/httpapi/controler/HttpApiController.java b/shapelight-admin/src/main/java/net/shapelight/modules/httpapi/controler/HttpApiController.java index 87b1c1c..478a1a5 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/httpapi/controler/HttpApiController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/httpapi/controler/HttpApiController.java @@ -340,6 +340,8 @@ public class HttpApiController { JSONObject dataJson = jsonContent.getJSONObject("data"); Long uid = dataJson.getLong("uid"); + System.out.println("uid = " + uid); + TenCellEntity cellEntity = tenCellService.getById(deviceEntity.getCellId()); TenPersonEntity p = tenPersonService.getById(uid,cellEntity.getCellId()); @@ -877,9 +879,24 @@ public class HttpApiController { params.put("personnelCardId", memberEntity.getIdCard()); - params.put("personnelType",memberEntity.getPersonType()); + Integer type = null; - params.put("entryOrExit",(deviceEntity.getGateFlag()+1) == 1); //1进2出 + if (memberEntity.getPersonType() == 5001){ + type = 1; + } + if (memberEntity.getPersonType() == 5000){ + type = 2; + } + if (memberEntity.getPersonType() == 5002){ + type = 3; + } + if (memberEntity.getPersonType() == 5005){ + type = 4; + } + + params.put("personnelType",type); + + params.put("entryOrExit", deviceEntity.getGateFlag() + 1); //1进2出 SimpleDateFormat sfm = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); @@ -890,12 +907,12 @@ public class HttpApiController { System.out.println("params = " + params); - /* cn.hutool.json.JSONObject jsonObject = cxFeignClient.savePmEntryExitRecord(params); + cn.hutool.json.JSONObject jsonObject = cxFeignClient.savePmEntryExitRecord(params); if(jsonObject.getBool("success")!=null && jsonObject.getBool("success")){ log.debug("同步进出场记录成功"); }else { log.debug("同步进出场记录失败"+"姓名:"+memberEntity.getName()+",errorMessage"+jsonObject.getStr("message")); - }*/ + } return R.ok(); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/DemoController.java b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/demo/DemoController.java similarity index 64% rename from shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/DemoController.java rename to shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/demo/DemoController.java index 362cb3a..0661017 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/DemoController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/demo/DemoController.java @@ -1,28 +1,36 @@ -package net.shapelight.modules.iCq.controller; +package net.shapelight.modules.iCq.controller.demo; -import cn.hutool.json.JSONObject; import com.arcsoft.face.ActiveDeviceInfo; import com.arcsoft.face.FaceEngine; -import com.arcsoft.face.enums.ErrorInfo; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.arcsoft.face.Rect; import io.minio.MinioClient; +import io.minio.PutObjectOptions; import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import net.shapelight.common.config.GlobalValue; +import net.shapelight.common.config.MinioConfig; import net.shapelight.common.utils.R; -import net.shapelight.modules.iCq.dal.mysql.enter.CqEnterConfigCellMapper; -import net.shapelight.modules.iCq.dal.mysql.enter.CqEnterConfigMapper; -import net.shapelight.modules.iCq.dal.mysql.enter.CqEnterConfigTypeMapper; +import net.shapelight.common.utils.UUIDUtil; +import net.shapelight.modules.face.rtsp.RtspFrameGrabber; +import net.shapelight.modules.iCq.controller.video.vo.FaceVideoVo; import net.shapelight.modules.iCq.service.enter.CqEnterServiceImpl; +import net.shapelight.modules.iCq.utils.DemoUtil; import net.shapelight.modules.job.task.PersonSynchronousTask; import net.shapelight.modules.ten.dao.TenCellDao; -import net.shapelight.modules.ten.entity.TenCellEntity; +import net.shapelight.modules.ten.dao.TenPersonDao; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; -import net.shapelight.modules.face.factory.FaceEngineFactory; - +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Pattern; @RestController @@ -33,6 +41,8 @@ public class DemoController { private final CqEnterServiceImpl cqEnterService; + private final TenPersonDao tenPersonDao; + @Autowired private PersonSynchronousTask task; @@ -43,6 +53,13 @@ public class DemoController { @Autowired private GlobalValue globalValue; + @Autowired + private RtspFrameGrabber rtspFrameGrabber; + + private final MinioConfig minioConfig; + + private final MinioClient minioClient; + @GetMapping("/save1") public void saveSupplier(String type){ /* System.out.println("测试开始"); @@ -178,6 +195,93 @@ public class DemoController { } + /* @PostMapping("/drawRectangleOnImage") + public R DrawRectangleOnImage(@RequestParam("image") MultipartFile image, @RequestParam String cellId) { + + List recognition = rtspFrameGrabber.recognition(image, cellId); + + List rects = new ArrayList<>(); + + for (FaceVideoVo faceVideoVo : recognition) { + + rects.add(faceVideoVo.getRect()); + + } + draw(recognition.get(0).getImageUrl(), rects); + + System.out.println("recognition = " + recognition); + + return R.ok(); + }*/ + + + + /* private String draw(String imageUrl, List rectList) { + + try { + // 从 URL 读取图片 + BufferedImage image = ImageIO.read(new URL(globalValue.getMinioEndpoint() + "/" + + globalValue.getMinioBucketName() + "/" + imageUrl)); + + // 获取绘图上下文 + Graphics2D g2d = image.createGraphics(); + g2d.setColor(Color.RED); // 设置框的颜色 + g2d.setStroke(new BasicStroke(3)); // 设置框的线条宽度 + + + // 遍历每个矩形框并绘制 + for (Rect rect : rectList) { + int left = rect.left; + int top = rect.top; + int width = rect.right - rect.left; + int height = rect.bottom - rect.top; + + g2d.drawRect(left, top, width, height); + } + + // 释放资源 + g2d.dispose(); + + // 将 BufferedImage 转换为 InputStream 以便上传 + ByteArrayOutputStream os = new ByteArrayOutputStream(); + ImageIO.write(image, "jpg", os); + InputStream inputStream = new ByteArrayInputStream(os.toByteArray()); + + // 设置文件目录和名称 + String catalogue = "temp/"; + String extension = "jpg"; // 假设是 JPG 格式 + String fileName = catalogue + "t_" + UUIDUtil.uuid() + "." + extension; + + // 上传文件到 MinIO + PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1); + putObjectOptions.setContentType("image/jpeg"); + minioClient.putObject( + minioConfig.getBucketName(), fileName, inputStream, putObjectOptions); + inputStream.close(); + + System.out.println("矩形框已绘制并上传到 MinIO,文件路径:" + globalValue.getMinioEndpoint() + "/" + + globalValue.getMinioBucketName() + "/" + fileName); + + return fileName; + + } catch (Exception e) { + e.printStackTrace(); + } + return "error"; + }*/ + + + /*@GetMapping("/testUtil") + public R testUtil(){ + return R.ok().put("data", DemoUtil.demo()); + }*/ + + @GetMapping("/temp") + public R temp(){ + tenPersonDao.insertTemp("111"); + return R.ok(); + } + } \ No newline at end of file diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/demo/vo/DrawVo.java b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/demo/vo/DrawVo.java new file mode 100644 index 0000000..afaf3d6 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/demo/vo/DrawVo.java @@ -0,0 +1,21 @@ +package net.shapelight.modules.iCq.controller.demo.vo; + +import com.arcsoft.face.Rect; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Accessors(chain = true) +public class DrawVo { + + private String imageUrl; + + private List rectList; + +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/video/CqSafeVideoController.java b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/video/CqSafeVideoController.java index d647558..c5c8990 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/video/CqSafeVideoController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/video/CqSafeVideoController.java @@ -1,25 +1,33 @@ package net.shapelight.modules.iCq.controller.video; +import com.arcsoft.face.Rect; +import io.minio.MinioClient; +import io.minio.PutObjectOptions; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; +import net.shapelight.common.config.GlobalValue; +import net.shapelight.common.config.MinioConfig; import net.shapelight.common.utils.R; -import net.shapelight.modules.face.dto.FaceRecognitionResDTO; -import net.shapelight.modules.face.entity.UserCompareInfo; +import net.shapelight.common.utils.UUIDUtil; import net.shapelight.modules.face.rtsp.RtspFrameGrabber; import net.shapelight.modules.iCq.controller.video.dto.UpdateVideoDto; import net.shapelight.modules.iCq.controller.video.dto.UploadVideoDto; import net.shapelight.modules.iCq.controller.video.vo.FaceVideoVo; -import net.shapelight.modules.iCq.dal.dataobject.video.TenSafeVideoEntity; -import net.shapelight.modules.iCq.dal.mysql.video.CqFileMapper; -import net.shapelight.modules.iCq.dal.mysql.video.CqSafeVideoMapper; import net.shapelight.modules.iCq.service.video.CqSafeVideoServiceImpl; -import net.shapelight.modules.ten.dao.TenCellDao; +import net.shapelight.modules.iCq.utils.DrawUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -38,6 +46,14 @@ public class CqSafeVideoController { @Autowired private RtspFrameGrabber rtspFrameGrabber; + @Autowired + private GlobalValue globalValue; + + private final MinioConfig minioConfig; + + private final MinioClient minioClient; + + private final List list = new ArrayList<>(); @@ -84,7 +100,7 @@ public class CqSafeVideoController { } } - @PutMapping("/update") + @PostMapping("/update") @ApiOperation(value = "更新视频接口") public R update(@RequestBody UpdateVideoDto updateVideoDto, @RequestHeader(value = "X-HTTP-Method-Override", required = false) String methodOverride) { @@ -122,27 +138,112 @@ public class CqSafeVideoController { } System.out.println("list = " + list); + List rects = new ArrayList<>(); + for (FaceVideoVo faceVideoVo : faceVideoVos) { + rects.add(faceVideoVo.getRect()); + } + + String drawUrl = null; + try { + drawUrl = DrawUtils.draw(faceVideoVos.get(0).getImageUrl(), rects); + } catch (IndexOutOfBoundsException e) { + System.out.println(e); + } + + if (isEnd == 1){ List listTemp = new ArrayList<>(list); list.clear(); - return R.ok().put("data", listTemp); + return R.ok().put("data", listTemp).put("drawUrl", drawUrl); } - return R.ok().put("data", list); + return R.ok().put("data", list).put("drawUrl", drawUrl); } - - - - @PostMapping("/face/recognition") public R aWatchStart(@RequestParam("image") MultipartFile image, @RequestParam String cellId) { List recognition = rtspFrameGrabber.recognition(image, cellId); for (FaceVideoVo faceVideoVo : recognition) { System.out.println(faceVideoVo.getImageUrl()); } - return R.ok().put("data", recognition); + List rects = new ArrayList<>(); + for (FaceVideoVo faceVideoVo : recognition) { + rects.add(faceVideoVo.getRect()); + } + + String drawUrl = null; + try { + drawUrl = DrawUtils.draw(recognition.get(0).getImageUrl(), rects); + } catch (IndexOutOfBoundsException e) { + System.out.println(e); + } + + + return R.ok().put("data", recognition).put("drawUrl", drawUrl); } + + + /*private String draw(String imageUrl, List rectList) { + + try { + // 从 URL 读取图片 + BufferedImage image = ImageIO.read(new URL(globalValue.getMinioEndpoint() + "/" + + globalValue.getMinioBucketName() + "/" + imageUrl)); + + // 获取绘图上下文 + Graphics2D g2d = image.createGraphics(); + g2d.setColor(Color.RED); // 设置框的颜色 + g2d.setStroke(new BasicStroke(3)); // 设置框的线条宽度 + + + // 遍历每个矩形框并绘制 + for (Rect rect : rectList) { + int left = rect.left; + int top = rect.top; + int width = rect.right - rect.left; + int height = rect.bottom - rect.top; + + g2d.drawRect(left, top, width, height); + } + + // 释放资源 + g2d.dispose(); + + // 将 BufferedImage 转换为 InputStream 以便上传 + ByteArrayOutputStream os = new ByteArrayOutputStream(); + ImageIO.write(image, "jpg", os); + InputStream inputStream = new ByteArrayInputStream(os.toByteArray()); + + // 设置文件目录和名称 + String catalogue = "temp/"; + String extension = "jpg"; // 假设是 JPG 格式 + String fileName = catalogue + "t_" + UUIDUtil.uuid() + "." + extension; + + // 上传文件到 MinIO + PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1); + putObjectOptions.setContentType("image/jpeg"); + minioClient.putObject( + minioConfig.getBucketName(), fileName, inputStream, putObjectOptions); + inputStream.close(); + + System.out.println("矩形框已绘制并上传到 MinIO,文件路径:" + globalValue.getMinioEndpoint() + "/" + + globalValue.getMinioBucketName() + "/" + fileName); + + return fileName; + + } catch (Exception e) { + e.printStackTrace(); + } + return "error"; + }*/ + + + + + + + + } \ No newline at end of file diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/video/vo/FaceVideoVo.java b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/video/vo/FaceVideoVo.java index e0f2a12..87bd2d0 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/video/vo/FaceVideoVo.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/controller/video/vo/FaceVideoVo.java @@ -36,6 +36,11 @@ public class FaceVideoVo { */ private Rect rect; + /** + * 绘制后图片url + */ + + private String imageWithRectangle; } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/iCq/dal/dataobject/personTemp/TenPersonSyncTempEntity.java b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/dal/dataobject/personTemp/TenPersonSyncTempEntity.java new file mode 100644 index 0000000..2f8ef80 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/dal/dataobject/personTemp/TenPersonSyncTempEntity.java @@ -0,0 +1,4 @@ +package net.shapelight.modules.iCq.dal.dataobject.personTemp; + +public class TenPersonSyncTempEntity { +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/iCq/dal/mysql/personTemp/TenPersonSyncTempMapper.java b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/dal/mysql/personTemp/TenPersonSyncTempMapper.java new file mode 100644 index 0000000..a51e478 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/dal/mysql/personTemp/TenPersonSyncTempMapper.java @@ -0,0 +1,24 @@ +package net.shapelight.modules.iCq.dal.mysql.personTemp; + +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface TenPersonSyncTempMapper { + + @Insert("INSERT INTO ten_person_sync_temp (open_id) VALUES (#{openId});") + public void insertTemp(String openId); + + @Delete("DELETE FROM ten_person_sync_temp;") + void removeAll(); + + @Delete("DELETE FROM ten_person WHERE open_id NOT IN (SELECT open_id FROM ten_person_sync_temp);") + void removeDeletedPerson(); + + + @Delete("DELETE FROM ten_person_sync_836266616957173761 WHERE person_id NOT IN (SELECT person_id from ten_person WHERE open_id in (SELECT open_id FROM ten_person_sync_temp));") + void removeDeletedPersonSync(); + +} + diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/iCq/utils/DrawUtils.java b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/utils/DrawUtils.java new file mode 100644 index 0000000..dd936ea --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/iCq/utils/DrawUtils.java @@ -0,0 +1,90 @@ +package net.shapelight.modules.iCq.utils; + +import com.arcsoft.face.Rect; +import io.minio.MinioClient; +import io.minio.PutObjectOptions; +import net.shapelight.common.config.GlobalValue; +import net.shapelight.common.config.MinioConfig; +import net.shapelight.common.utils.UUIDUtil; +import org.springframework.stereotype.Component; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.net.URL; +import java.util.List; + +@Component +public class DrawUtils { + + + private static GlobalValue globalValue; + + private static MinioClient minioClient; + + private static MinioConfig minioConfig; + + public DrawUtils(GlobalValue globalValue, MinioClient minioClient, MinioConfig minioConfig) { + DrawUtils.globalValue = globalValue; + DrawUtils.minioClient = minioClient; + DrawUtils.minioConfig = minioConfig; + } + + public static String draw(String imageUrl, List rectList) { + + try { + // 从 URL 读取图片 + BufferedImage image = ImageIO.read(new URL(globalValue.getMinioEndpoint() + "/" + + globalValue.getMinioBucketName() + "/" + imageUrl)); + + // 获取绘图上下文 + Graphics2D g2d = image.createGraphics(); + g2d.setColor(Color.RED); // 设置框的颜色 + g2d.setStroke(new BasicStroke(3)); // 设置框的线条宽度 + + + // 遍历每个矩形框并绘制 + for (Rect rect : rectList) { + int left = rect.left; + int top = rect.top; + int width = rect.right - rect.left; + int height = rect.bottom - rect.top; + + g2d.drawRect(left, top, width, height); + } + + // 释放资源 + g2d.dispose(); + + // 将 BufferedImage 转换为 InputStream 以便上传 + ByteArrayOutputStream os = new ByteArrayOutputStream(); + ImageIO.write(image, "jpg", os); + InputStream inputStream = new ByteArrayInputStream(os.toByteArray()); + + // 设置文件目录和名称 + String catalogue = "temp/"; + String extension = "jpg"; // 假设是 JPG 格式 + String fileName = catalogue + "t_" + UUIDUtil.uuid() + "." + extension; + + // 上传文件到 MinIO + PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1); + putObjectOptions.setContentType("image/jpeg"); + minioClient.putObject( + minioConfig.getBucketName(), fileName, inputStream, putObjectOptions); + inputStream.close(); + + System.out.println("矩形框已绘制并上传到 MinIO,文件路径:" + globalValue.getMinioEndpoint() + "/" + + globalValue.getMinioBucketName() + "/" + fileName); + + return fileName; + + } catch (Exception e) { + e.printStackTrace(); + } + return "error"; + } + +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/DbBakTask.java b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/DbBakTask.java index 4638794..91a996a 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/DbBakTask.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/DbBakTask.java @@ -56,9 +56,13 @@ public class DbBakTask implements ITask { fileDir.setWritable(true,false); } + + String mysqlLocation = "SHOW VARIABLES LIKE 'basedir';"; + //String cmd = "mysqldump -u"+ dbUsername +" -p"+dbPassword +" "+ dbName + " -r " + path; //mysqldump -h172.17.0.1 -P3306 -ugb -pgb site_db_docker -r /opt/sl-site/db_bak/13.sql String cmd = "mysqldump -h"+dbHost+" -P"+dbPort+" -u"+ dbUsername +" -p"+dbPassword +" --set-charset=UTF8 "+ dbName; + /*cmd = cmd + mysqlLocation + "\bin";*/ PrintWriter printWriter = null; BufferedReader bufferedReader = null; try { diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonSynchronousTask.java b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonSynchronousTask.java index 5ebdcc2..bea3b22 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonSynchronousTask.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonSynchronousTask.java @@ -23,6 +23,7 @@ import net.shapelight.modules.face.service.FaceEngineService; import net.shapelight.modules.face.util.UserInfo; import net.shapelight.modules.face.util.UserRamGroup; import net.shapelight.modules.feignClient.CxFeignClient; +import net.shapelight.modules.iCq.dal.mysql.personTemp.TenPersonSyncTempMapper; import net.shapelight.modules.nettyapi.service.ServerApiService; import net.shapelight.modules.sys.controller.AbstractController; import net.shapelight.modules.ten.entity.*; @@ -70,6 +71,9 @@ public class PersonSynchronousTask extends AbstractController implements ITask { @Autowired private ServerApiService serverApiService; + @Autowired + private TenPersonSyncTempMapper tenPersonSyncTempMapper; + @Override public void run(String params) { @@ -78,6 +82,8 @@ public class PersonSynchronousTask extends AbstractController implements ITask { //getPmInternalPersonnelList("Contractor"); + tenPersonSyncTempMapper.removeAll(); + try { getPmInternalPersonnelList("Person"); } catch (Exception e) { @@ -99,6 +105,12 @@ public class PersonSynchronousTask extends AbstractController implements ITask { System.err.println("Error while fetching personnel list for Supplier: " + e.getMessage()); } + tenPersonSyncTempMapper.removeDeletedPerson(); + tenPersonSyncTempMapper.removeDeletedPersonSync(); + + + + } private void getPmInternalPersonnelList(String type) { @@ -107,7 +119,7 @@ public class PersonSynchronousTask extends AbstractController implements ITask { int pageIndex = 1; Map params = new HashMap<>(); params.put("pageIndex", pageIndex); - params.put("pageSize", 1000); + params.put("pageSize", 20); /* params.put("orgName", item.getName());*/ /*params.put("orgId", item.getCellId());*/ params.put("orgId", item.getOrgId()); @@ -148,7 +160,7 @@ public class PersonSynchronousTask extends AbstractController implements ITask { } if (json.getBool("success") != null && json.getBool("success")) { JSONObject data = json.getJSONObject("data"); - System.out.println("cssssssssssssssssssssss" + data); + /*System.out.println("cssssssssssssssssssssss" + data);*/ JSONArray dataList = data.getJSONArray("list"); List list1 = dataList.toList(JSONObject.class); @@ -191,6 +203,10 @@ public class PersonSynchronousTask extends AbstractController implements ITask { } } + + + + }); } @@ -438,8 +454,8 @@ public class PersonSynchronousTask extends AbstractController implements ITask { TenPersonEntity tenPerson = new TenPersonEntity(); Date now = new Date(); - long id = new SnowflakeIdWorker().nextId(); - tenPerson.setPersonId(id); + /* long id = new SnowflakeIdWorker().nextId(); + tenPerson.setPersonId(id);*/ tenPerson.setUuid(UUIDUtil.uuid()); //tenPerson.setTenantId(cellEntity.getTenantId()); tenPerson.setCreateBy("sync"); @@ -478,14 +494,20 @@ public class PersonSynchronousTask extends AbstractController implements ITask { tenPerson.setName(person.getStr("contractorName")); } if (person.getStr("personnelName") != null){ - - tenPerson.setName(person.getStr("personnelName")); } tenPerson.setGender(person.getInt("dictSex") != null ? person.getInt("dictSex") : 0); tenPerson.setMobile(person.getStr("mobile") != null ? person.getStr("mobile") : null); - tenPerson.setIdCard(person.getStr("personnelCardId") != null ? person.getStr("personnelCardId") : null); + if (person.getStr("personnelCardId") != null) { + tenPerson.setIdCard(person.getStr("personnelCardId")); + } + if (person.getStr("contractorCardId") != null) { + tenPerson.setIdCard(person.getStr("contractorCardId")); + } + if (person.getStr("supplierCardId") != null) { + tenPerson.setIdCard(person.getStr("supplierCardId")); + } tenPerson.setNation(person.getStr("dictNation") != null ? Integer.parseInt(person.getStr("dictNation")) : 1); tenPerson.setCellId(cellEntity.getCellId()); @@ -514,15 +536,29 @@ public class PersonSynchronousTask extends AbstractController implements ITask { tenPerson.setLiveStart(sfm.parse(person.getStr("enterValidPeriod"))); } else if (person.getStr("validPeriodSta") != null) { tenPerson.setLiveStart(sfm.parse(person.getStr("validPeriodSta"))); + } else if(person.getStr("enterValidPeriod") == null){ + tenPerson.setLiveStart(sfm.parse("1900-01-01 00:00:00")); + } else if (person.getStr("validPeriodSta") == null){ + tenPerson.setLiveStart(sfm.parse("1900-01-01 00:00:00")); } + if (person.getStr("enterValidPeriodEnd") != null) { tenPerson.setLiveEnd(sfm.parse(person.getStr("enterValidPeriodEnd"))); } else if (person.getStr("validPeriodEnd") != null) { tenPerson.setLiveEnd(sfm.parse(person.getStr("validPeriodEnd"))); + } else if (person.getStr("enterValidPeriodEnd") == null){ + tenPerson.setLiveEnd(sfm.parse("2200-01-01 00:00:00")); + } else if (person.getStr("validPeriodEnd") == null){ + tenPerson.setLiveEnd(sfm.parse("2200-01-01 00:00:00")); } + } catch (ParseException e) { throw new RuntimeException(e); } + + + + if (person.getStr("isEnterSulfurArea") != null) { tenPerson.setIsEnterSulfurArea(person.getStr("isEnterSulfurArea").equals("是") ? 1 : 0); } @@ -669,6 +705,8 @@ public class PersonSynchronousTask extends AbstractController implements ITask { personTrain.setIsQualified(contractorTrain.getStr("isQualified").equals("是") ? 1 : 0); } + + if (contractorTrain.getStr("trainStartDate") != null) { try { personTrain.setTrainStartDate(sfm1.parse(contractorTrain.getStr("trainStartDate"))); @@ -730,6 +768,31 @@ public class PersonSynchronousTask extends AbstractController implements ITask { tenPerson.setIsWatchSafeVideo(0); } + long id; + if(tenPersonService.getOne(new QueryWrapper() + .eq("open_id", tenPerson.getOpenId())) != null) { + //MyBatis-Plus会优先使用 personId 作为主键,因为它更具体地定义了主键的生成策略。 + /*tenPersonService.removeById(tenPersonService.getOne(new QueryWrapper() + .eq("open_id", tenPerson.getOpenId())).getPersonId());*/ + + id = tenPersonService.getOne(new QueryWrapper() + .eq("open_id", tenPerson.getOpenId())).getPersonId(); + + + tenPerson.setPersonId(id); + + //tenPersonService.updateTenPersonByOpenId(tenPerson); + + //System.out.println("更新成功" + tenPerson); + }else { + id = new SnowflakeIdWorker().nextId(); + tenPerson.setPersonId(id); + //tenPersonService.saveTenPerson(tenPerson); + // System.out.println("新增成功" + tenPerson); + } + + + if (person.getStr("attachment") != null) { try { //保存原始图片 @@ -784,6 +847,11 @@ public class PersonSynchronousTask extends AbstractController implements ITask { } } }*/ + + + + + UserInfo userInfo = new UserInfo(); userInfo.setFaceId(tenPerson.getPersonId().toString()); userInfo.setName(tenPerson.getName()); @@ -802,14 +870,20 @@ public class PersonSynchronousTask extends AbstractController implements ITask { } } - if(tenPersonService.getOne(new QueryWrapper() + if(tenPersonService.getOne(new QueryWrapper() .eq("open_id", tenPerson.getOpenId())) != null) { - //MyBatis-Plus会优先使用 personId 作为主键,因为它更具体地定义了主键的生成策略。 - tenPersonService.removeById(tenPersonService.getOne(new QueryWrapper() - .eq("open_id", tenPerson.getOpenId())).getPersonId()); + + tenPersonService.updateTenPersonByOpenId(tenPerson); + + System.out.println("更新成功" + tenPerson); + }else { + tenPersonService.saveTenPerson(tenPerson); + System.out.println("新增成功" + tenPerson); } - tenPersonService.saveTenPerson(tenPerson); - System.out.println("新增成功" + tenPerson); + + + tenPersonSyncTempMapper.insertTemp(tenPerson.getOpenId()); + return ""; } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonController.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonController.java index f4c3263..5b4c538 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonController.java @@ -10,10 +10,12 @@ import java.text.SimpleDateFormat; import java.util.*; import java.util.zip.ZipOutputStream; +import cn.hutool.json.JSONObject; import com.alibaba.excel.EasyExcelFactory; import com.alibaba.excel.write.metadata.style.WriteCellStyle; import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import io.minio.MinioClient; import io.minio.PutObjectOptions; import io.swagger.annotations.Api; @@ -586,7 +588,16 @@ public class TenPersonController extends AbstractController { params.put("attachment", "data:image/jpeg;base64," + base64); System.out.println("params = " + params); - // cxFeignClient.savePmVisitorPersonnel(params); + JSONObject jsonObject = cxFeignClient.savePmVisitorPersonnel(params); + if(jsonObject.getStr("data") != null){ + String openId = jsonObject.getStr("data"); + // id + tenPerson.setOpenId(openId); + + tenPersonService.update(tenPerson, + new UpdateWrapper().eq("person_id", id)); + //tenPersonService.updateTenPersonById(tenPerson); + } } return R.ok(); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonDao.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonDao.java index 5a9c8f4..aaf2f91 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonDao.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonDao.java @@ -137,4 +137,6 @@ public interface TenPersonDao extends BaseMapper{ List findDeptCount(@Param("tenantId")String tenantId); int updateWatchSafeVideo(@Param("personId")Long personId,@Param("cellId")Long cellId); + + void insertTemp(String openId); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonService.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonService.java index c846fe6..a6b6730 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonService.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonService.java @@ -165,5 +165,8 @@ public interface TenPersonService extends IService { String saveOrUpdateByField(TenPersonEntity entity,String fieldName); + void updateTenPersonByOpenId(TenPersonEntity tenPerson); + + void insertTemp(String openId); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonServiceImpl.java index a9849ca..4515b74 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonServiceImpl.java @@ -7,6 +7,7 @@ import com.arcsoft.face.FaceInfo; import com.arcsoft.face.enums.ExtractType; import com.arcsoft.face.toolkit.ImageFactory; import com.arcsoft.face.toolkit.ImageInfo; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.minio.MinioClient; import io.minio.PutObjectOptions; @@ -29,6 +30,7 @@ import net.shapelight.modules.face.service.FaceEngineService; import net.shapelight.modules.face.util.Base64Util; import net.shapelight.modules.face.util.UserInfo; import net.shapelight.modules.face.util.UserRamGroup; +import net.shapelight.modules.iCq.dal.mysql.personTemp.TenPersonSyncTempMapper; import net.shapelight.modules.nettyapi.service.ServerApiService; import net.shapelight.modules.ten.controller.TenUserController; import net.shapelight.modules.ten.entity.*; @@ -111,6 +113,9 @@ public class TenPersonServiceImpl extends ServiceImpl params) { @@ -395,6 +400,9 @@ public class TenPersonServiceImpl extends ServiceImpl updateWrapper = new UpdateWrapper<>(); +// 根据某个字段设置更新条件,比如根据 id 更新 + updateWrapper.eq("open_id", tenPerson.getOrgId()); + + tenPersonDao.update(tenPerson, updateWrapper); + + //发送设备通知 + List devList = tenDeviceService.findByCellId(tenPerson.getCellId()); + //状态是0正常,发送推送 + if (tenPerson.getStatus() == Constant.PESON_SUATUS_NOMOR) { + for (TenDeviceVo dev : devList) { + //添加到同步表,下发设备通知 + TenPersonSyncEntity syncEntity = new TenPersonSyncEntity(); + syncEntity.setPersonId(tenPerson.getPersonId()); + syncEntity.setTenantId(tenPerson.getTenantId()); + syncEntity.setDeviceSn(dev.getSn()); + syncEntity.setDeviceId(dev.getDeviceId()); + syncEntity.setState(1); + syncEntity.setLastUpdateTime(tenPerson.getLastUpdateTime()); + tenPersonSyncService.insert(syncEntity); + + //下发通知 + List list = new ArrayList<>(); + TenPersonOperationVo vo = new TenPersonOperationVo(); + vo.setUid(syncEntity.getPersonId()); + vo.setOperation(1); + vo.setLast_update_stamp(syncEntity.getLastUpdateTime()); + list.add(vo); + serverApiService.personOperation(dev.getSn(), list); + } + } + + + + } + + @Override + public void insertTemp(String openId) { + tenPersonSyncTempMapper.insertTemp(openId); + } } diff --git a/shapelight-admin/src/main/resources/mapper/ten/TenPersonDao.xml b/shapelight-admin/src/main/resources/mapper/ten/TenPersonDao.xml index 68abe14..65f044f 100644 --- a/shapelight-admin/src/main/resources/mapper/ten/TenPersonDao.xml +++ b/shapelight-admin/src/main/resources/mapper/ten/TenPersonDao.xml @@ -539,6 +539,12 @@ + + + INSERT INTO ten_person_sync_temp (open_id) VALUES (#{openId}); + + + update ten_person