Browse Source

修改进出记录附表的图片塞入方式

王鑫刚 3 months ago
parent
commit
33466af846

+ 4 - 0
src/main/java/com/yx/face/boot/uitls/Base64Util.java

@@ -6,6 +6,7 @@ package com.yx.face.boot.uitls;
  * @Author WXG
  * @Date 2021/12/2 14:06
  */
+import cn.hutool.core.util.StrUtil;
 import sun.misc.BASE64Decoder;
 import sun.misc.BASE64Encoder;
 
@@ -27,6 +28,9 @@ public class Base64Util {
      * Base64字符串 转换为 byte数组
      */
     public static byte[] decode(String base64) {
+        if(StrUtil.isBlank(base64)){
+            return null;
+        }
         try {
             return new BASE64Decoder().decodeBuffer(base64);
         } catch (IOException e) {

+ 85 - 85
src/main/java/com/yx/face/service/Aspect/FaceLogDaoAspect.java

@@ -1,85 +1,85 @@
-package com.yx.face.service.Aspect;
-
-import com.yx.face.boot.restful.ServiceException;
-import com.yx.face.boot.uitls.Base64Util;
-import com.yx.face.boot.uitls.ThumbnailsUtil;
-import com.yx.face.dao.FaceLogFromDao;
-import com.yx.face.model.entity.FaceLog;
-import com.yx.face.model.entity.FaceLogFrom;
-import org.apache.tomcat.util.codec.binary.Base64;
-import org.aspectj.lang.JoinPoint;
-import org.aspectj.lang.annotation.After;
-import org.aspectj.lang.annotation.Aspect;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-
-/**
- * @description:
- * @ClassName FaceLogDaoAspect
- * @Author WXG
- * @Date 2021/12/2 15:09
- */
-@Component
-@Aspect
-public class FaceLogDaoAspect {
-
-    @Resource
-    FaceLogFromDao faceLogFromDao;
-
-    @After("execution( public * com.yx.face.dao.FaceLogDao.delete*(*))")
-    public void deleteAfter(JoinPoint joinPoint) {
-        String name = joinPoint.getSignature().getName();
-        Object[] args = joinPoint.getArgs();
-        if (name.equals("deleteByPrimaryKey")) {
-            faceLogFromDao.delteByForgeinId((Long) args[0]);
-        }
-    }
-
-    @After("execution( public * com.yx.face.dao.FaceLogDao.insert*(*))")
-    public void insertAfter(JoinPoint joinPoint) {
-        String name = joinPoint.getSignature().getName();
-        Object[] args = joinPoint.getArgs();
-        FaceLogFrom ublf = new FaceLogFrom();
-        if (name.equals("insert") || name.equals("insertSelective")) {
-            FaceLog ubl = (FaceLog) args[0];
-            boolean photo = ubl.getPhoto() != null && !ubl.getPhoto().equals("") && ubl.getPhoto().indexOf("请求失败") == -1 && ubl.getId() != null;
-            boolean sfzPhoto = ubl.getSfzPhoto() != null && !ubl.getSfzPhoto().equals("") && ubl.getSfzPhoto().indexOf("请求失败") == -1 && ubl.getId() != null;
-            if (photo) {
-                ublf.setFaceLogId(ubl.getId());
-                ublf.setImgBase(this.picForScale(Base64Util.getByteArrayFromUrl(ubl.getPhoto())));
-                if(sfzPhoto) {
-                    ublf.setSfzImgBase(this.picForScale((Base64Util.getByteArrayFromUrl(ubl.getSfzPhoto()))));
-                }
-                faceLogFromDao.insertSelective(ublf);
-            }
-        }
-    }
-
-    @After("execution( public * com.yx.face.dao.FaceLogDao.update*(*))")
-    public void updateAfter(JoinPoint joinPoint) {
-        String name = joinPoint.getSignature().getName();
-        Object[] args = joinPoint.getArgs();
-        FaceLogFrom ublf = new FaceLogFrom();
-        if (name.equals("updateByPrimaryKey") || name.equals("updateByPrimaryKeySelective")) {
-            FaceLog ubl = (FaceLog) args[0];
-            boolean photo = ubl.getPhoto() != null && !ubl.getPhoto().equals("") && ubl.getPhoto().indexOf("请求失败") == -1 && ubl.getId() != null;
-            boolean sfzPhoto = ubl.getSfzPhoto() != null && !ubl.getSfzPhoto().equals("") && ubl.getSfzPhoto().indexOf("请求失败") == -1 && ubl.getId() != null;
-            if (photo && sfzPhoto) {
-                ublf.setFaceLogId(ubl.getId());
-                ublf.setImgBase(this.picForScale(Base64Util.getByteArrayFromUrl(ubl.getPhoto())));
-                ublf.setSfzImgBase(this.picForScale(Base64Util.getByteArrayFromUrl(ubl.getSfzPhoto())));
-                faceLogFromDao.updateByForgeinId(ublf);
-            }
-        }
-    }
-    private byte[] picForScale(byte[] bytes) {
-        try {
-            bytes = ThumbnailsUtil.compressPicForScale(bytes, 40);// 图片小于40kb
-            return bytes;
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-}
+//package com.yx.face.service.Aspect;
+//
+//import com.yx.face.boot.restful.ServiceException;
+//import com.yx.face.boot.uitls.Base64Util;
+//import com.yx.face.boot.uitls.ThumbnailsUtil;
+//import com.yx.face.dao.FaceLogFromDao;
+//import com.yx.face.model.entity.FaceLog;
+//import com.yx.face.model.entity.FaceLogFrom;
+//import org.apache.tomcat.util.codec.binary.Base64;
+//import org.aspectj.lang.JoinPoint;
+//import org.aspectj.lang.annotation.After;
+//import org.aspectj.lang.annotation.Aspect;
+//import org.springframework.stereotype.Component;
+//
+//import javax.annotation.Resource;
+//
+///**
+// * @description:
+// * @ClassName FaceLogDaoAspect
+// * @Author WXG
+// * @Date 2021/12/2 15:09
+// */
+//@Component
+//@Aspect
+//public class FaceLogDaoAspect {
+//
+//    @Resource
+//    FaceLogFromDao faceLogFromDao;
+//
+//    @After("execution( public * com.yx.face.dao.FaceLogDao.delete*(*))")
+//    public void deleteAfter(JoinPoint joinPoint) {
+//        String name = joinPoint.getSignature().getName();
+//        Object[] args = joinPoint.getArgs();
+//        if (name.equals("deleteByPrimaryKey")) {
+//            faceLogFromDao.delteByForgeinId((Long) args[0]);
+//        }
+//    }
+//
+//    @After("execution( public * com.yx.face.dao.FaceLogDao.insert*(*))")
+//    public void insertAfter(JoinPoint joinPoint) {
+//        String name = joinPoint.getSignature().getName();
+//        Object[] args = joinPoint.getArgs();
+//        FaceLogFrom ublf = new FaceLogFrom();
+//        if (name.equals("insert") || name.equals("insertSelective")) {
+//            FaceLog ubl = (FaceLog) args[0];
+//            boolean photo = ubl.getPhoto() != null && !ubl.getPhoto().equals("") && ubl.getPhoto().indexOf("请求失败") == -1 && ubl.getId() != null;
+//            boolean sfzPhoto = ubl.getSfzPhoto() != null && !ubl.getSfzPhoto().equals("") && ubl.getSfzPhoto().indexOf("请求失败") == -1 && ubl.getId() != null;
+//            if (photo) {
+//                ublf.setFaceLogId(ubl.getId());
+//                ublf.setImgBase(this.picForScale(Base64Util.getByteArrayFromUrl(ubl.getPhoto())));
+//                if(sfzPhoto) {
+//                    ublf.setSfzImgBase(this.picForScale((Base64Util.getByteArrayFromUrl(ubl.getSfzPhoto()))));
+//                }
+//                faceLogFromDao.insertSelective(ublf);
+//            }
+//        }
+//    }
+//
+//    @After("execution( public * com.yx.face.dao.FaceLogDao.update*(*))")
+//    public void updateAfter(JoinPoint joinPoint) {
+//        String name = joinPoint.getSignature().getName();
+//        Object[] args = joinPoint.getArgs();
+//        FaceLogFrom ublf = new FaceLogFrom();
+//        if (name.equals("updateByPrimaryKey") || name.equals("updateByPrimaryKeySelective")) {
+//            FaceLog ubl = (FaceLog) args[0];
+//            boolean photo = ubl.getPhoto() != null && !ubl.getPhoto().equals("") && ubl.getPhoto().indexOf("请求失败") == -1 && ubl.getId() != null;
+//            boolean sfzPhoto = ubl.getSfzPhoto() != null && !ubl.getSfzPhoto().equals("") && ubl.getSfzPhoto().indexOf("请求失败") == -1 && ubl.getId() != null;
+//            if (photo && sfzPhoto) {
+//                ublf.setFaceLogId(ubl.getId());
+//                ublf.setImgBase(this.picForScale(Base64Util.getByteArrayFromUrl(ubl.getPhoto())));
+//                ublf.setSfzImgBase(this.picForScale(Base64Util.getByteArrayFromUrl(ubl.getSfzPhoto())));
+//                faceLogFromDao.updateByForgeinId(ublf);
+//            }
+//        }
+//    }
+//    private byte[] picForScale(byte[] bytes) {
+//        try {
+//            bytes = ThumbnailsUtil.compressPicForScale(bytes, 40);// 图片小于40kb
+//            return bytes;
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//        return null;
+//    }
+//}

+ 2 - 1
src/main/java/com/yx/face/service/impl/FaceServiceImpl.java

@@ -709,7 +709,8 @@ public class FaceServiceImpl implements FaceService {
 //                            time = sdf1.format(date);
 //                        }
 //                        String d = "D:\\4\\"+name+"-"+idNumber+"-"+time+".jpg";
-                        String name = uploadExcel.getName().concat("-").concat(uploadExcel.getDate());
+//                        String name = uploadExcel.getName().concat("-").concat(uploadExcel.getDate());
+                        String name = uploadExcel.getIdNumber();
                         String d = "D:\\4\\"+name+".jpg";
                         file = new File(d);
                         if(file.exists()){

+ 18 - 4
src/main/java/com/yx/face/service/impl/FaceTBServiceImpl.java

@@ -12,9 +12,7 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.yx.face.boot.component.aop.MyAnnotation;
 import com.yx.face.boot.core.SnowflakeIdWorker;
-import com.yx.face.boot.uitls.DateUtils;
-import com.yx.face.boot.uitls.FileUploadUtil;
-import com.yx.face.boot.uitls.RedisUtil;
+import com.yx.face.boot.uitls.*;
 import com.yx.face.dao.*;
 import com.yx.face.model.dto.AlcoholTestDto;
 import com.yx.face.model.dto.DownFaceNew;
@@ -55,6 +53,8 @@ public class FaceTBServiceImpl implements FaceTBService {
     @Resource
     private FaceLogDao faceLogDao;
     @Resource
+    private FaceLogFromDao faceLogFromDao;
+    @Resource
     private ShortTermFaceLogDao shortTermFaceLogDao;
     @Resource
     private SystemLongTermDocumentsDao systemLongTermDocumentsDao;
@@ -619,6 +619,8 @@ public class FaceTBServiceImpl implements FaceTBService {
                 }
             }
 
+            String base64Photo = photo;
+
             if (StringUtils.hasText(photo)) {
                 photo = buildImage(photo, sn + pin);
             }
@@ -689,6 +691,10 @@ public class FaceTBServiceImpl implements FaceTBService {
             if (verifytype == 0 || verifytype == 2 || verifytype == 3) {
                 //长期通行记录
                 faceLogDao.insertSelective(faceLog);
+                FaceLogFrom faceLogFrom = new FaceLogFrom();
+                faceLogFrom.setFaceLogId(faceLog.getId());
+                faceLogFrom.setImgBase(this.picForScale(Base64Util.decode(base64Photo)));
+                faceLogFromDao.insertSelective(faceLogFrom);
 
                 //短期通行记录
                 shortTermFaceLogDao.insertSelective(BeanUtil.copyProperties(faceLog, ShortTermFaceLog.class));
@@ -727,7 +733,15 @@ public class FaceTBServiceImpl implements FaceTBService {
         }
         return result;
     }
-
+    private byte[] picForScale(byte[] bytes) {
+        try {
+            bytes = ThumbnailsUtil.compressPicForScale(bytes, 40);// 图片小于40kb
+            return bytes;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
     @Override
     public Map<String, Object> pushUsers(Map<String, Object> dto) {
         Map<String, Object> result = Maps.newHashMapWithExpectedSize(1);