diff --git a/shapelight-admin/src/main/java/net/shapelight/common/utils/UploadZipUtil.java b/shapelight-admin/src/main/java/net/shapelight/common/utils/UploadZipUtil.java index 66ea3a7..efc3cf4 100644 --- a/shapelight-admin/src/main/java/net/shapelight/common/utils/UploadZipUtil.java +++ b/shapelight-admin/src/main/java/net/shapelight/common/utils/UploadZipUtil.java @@ -75,4 +75,107 @@ public class UploadZipUtil { // } return saveFileName; } + + + + public static String unZipGifFromSourceFile(MultipartFile file, String path) throws Exception { + + /* 截取后缀名 */ + if (file.isEmpty()) { + throw new Exception("文件不能为空"); + } + String fileName = file.getOriginalFilename(); + int pos = fileName.lastIndexOf("."); + String extName = fileName.substring(pos+1).toLowerCase(); + //判断上传文件必须是zip或者是rar否则不允许上传 + //if (!extName.equals("zip")&&!extName.equals("rar")) { + if (!extName.equals("zip")) { + throw new Exception("上传文件格式错误,仅支持zip压缩文件"); + } + // UUID后缀名保存 + //时间保存 + String saveName = UUIDUtil.uuid()+ "."+extName; + //String saveName = DateUtil.date2String(new Date(),"yyyyMMddHHmmss")+ "."+extName; + //文件名 + String saveFileName = saveName.substring(0, saveName.lastIndexOf(".")); + // 根据服务器的文件保存地址和原文件名创建目录文件全路径 + File pushFile = new File(path + "/" +saveFileName+"/"+ saveName); + + File descFile = new File(path+"/"+saveFileName); + if (!descFile.exists()) { + descFile.mkdirs(); + } + //解压目的文件 + //String descDir = path +"/"+saveFileName+"/"; + String descDir = path +"/"; + String unZipDir = path +"/"+saveFileName+"/"; + + file.transferTo(pushFile); + + //开始解压zip + if (extName.equals("zip")) { + //CompressZipUtils.unZipFiles(pushFile, descDir); + CompressZipUtils.unZipFiles(pushFile, unZipDir); + + } + else { + throw new Exception("文件格式不正确不能解压"); + } + String resFileName = ""; + //遍历文件夹 + for (File fileGif : new File(unZipDir).listFiles()) { + String gifname = fileGif.getName(); + if(gifname.equals("head.gif")){ + resFileName = fileGif.getAbsolutePath(); + System.out.println("GIF:"+resFileName); + }else{ + fileGif.delete(); + } + } + return resFileName; + } + + +// public static void unzip(String zipFilePath, String destDir) { +// File dir = new File(destDir); +// +// // 创建输出目录如果它不存在 +// if (!dir.exists()) dir.mkdirs(); +// +// byte[] buffer = new byte[1024]; +// try { +// FileInputStream fis = new FileInputStream(zipFilePath); +// ZipInputStream zis = new ZipInputStream(fis); +// ZipEntry ze = zis.getNextEntry(); +// +// while (ze != null) { +// String fileName = ze.getName(); +// File newFile = new File(destDir + File.separator + fileName); +// +// // 创建所有非存在的父目录 +// new File(newFile.getParent()).mkdirs(); +// +// FileOutputStream fos = new FileOutputStream(newFile); +// +// int len; +// while ((len = zis.read(buffer)) > 0) { +// fos.write(buffer, 0, len); +// } +// +// fos.close(); +// // 关闭当前ZipEntry并移至下一个 +// zis.closeEntry(); +// ze = zis.getNextEntry(); +// } +// +// // 关闭最后一个ZipEntry +// zis.closeEntry(); +// zis.close(); +// fis.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } + + } 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 1306560..2398487 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 @@ -39,6 +39,8 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; import java.io.InputStream; import java.util.*; @@ -736,6 +738,24 @@ public class HttpApiController { minioConfig.getBucketName(), fileName, inputStream, putObjectOptions); inputStream.close(); record.setSourceFile(fileName); + + //解压文件,获取gif文件,保存到文件服务器,添加到人员字段face_model字段 +// String tempUnzipFilePath = globalValue.getStaticLocations()+ File.separator+globalValue.getTempDir(); +// String gifStr = UploadZipUtil.unZipGifFromSourceFile(sourceFile,tempUnzipFilePath); +// File gifFile = new File(gifStr); +// if (gifStr.length()>0) { +// InputStream gifInputStream = new FileInputStream(new File(gifStr)); +// PutObjectOptions gifputObjectOptions = new PutObjectOptions(gifInputStream.available(), -1); +// gifputObjectOptions.setContentType("image/gif"); +// String gifFileName = userFileUrl + "g_" + UUIDUtil.uuid() + ".gif"; +// minioClient.putObject( +// minioConfig.getBucketName(), gifFileName, gifInputStream, gifputObjectOptions); +// gifInputStream.close(); +// record.setDepth(gifFileName); +// File dirFile = gifFile.getParentFile(); +// gifFile.delete(); +// dirFile.delete(); +// } } } catch (Exception e) { @@ -950,6 +970,24 @@ public class HttpApiController { tenPerson.setSourceFile(sourceFileName); + String tempUnzipFilePath = globalValue.getStaticLocations()+ File.separator+globalValue.getTempDir(); + + //解压文件,获取gif文件,保存到文件服务器,添加到人员字段face_model字段 + String gifStr = UploadZipUtil.unZipGifFromSourceFile(sourceFile,tempUnzipFilePath); + File gifFile = new File(gifStr); + if (gifStr.length()>0) { + InputStream gifInputStream = new FileInputStream(new File(gifStr)); + PutObjectOptions gifputObjectOptions = new PutObjectOptions(gifInputStream.available(), -1); + gifputObjectOptions.setContentType("image/gif"); + String gifFileName = userFileUrl + "g_" + UUIDUtil.uuid() + ".gif"; + minioClient.putObject( + minioConfig.getBucketName(), gifFileName, gifInputStream, gifputObjectOptions); + gifInputStream.close(); + tenPerson.setFaceModel(gifFileName); + File dirFile = gifFile.getParentFile(); + gifFile.delete(); + dirFile.delete(); + } } catch (Exception e) { return R.error(e.getMessage()); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenUserController.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenUserController.java index ed3a1c4..f2a57a1 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenUserController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenUserController.java @@ -310,4 +310,22 @@ public class TenUserController extends AbstractController { return R.ok(); } + + + /** + * 显示脸模或者照片 + * 1. 显示照片 + * 2. 显示GIF + */ + @SysLog("显示脸模或者照片") + @GetMapping("/displayFaceFlag") + @ApiOperation("显示脸模或者照片1显示照片2显示GIF") + public R displayFaceFlag(){ + SysUserEntity user = sysUserService.getById(getUser().getTenantId()); + if (user.getPoliceNumber()!=null && user.getPoliceNumber().equals("2")) { + return R.ok().put("data",2); + }else{ + return R.ok().put("data",1); + } + } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenCheckEntity.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenCheckEntity.java index 93b5e52..4fe0da6 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenCheckEntity.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenCheckEntity.java @@ -130,4 +130,7 @@ public class TenCheckEntity implements Serializable { @JsonSerialize(using = ToStringSerializer.class) private Long cellId; + @TableField(exist = false) + private String faceModel; + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenCheckServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenCheckServiceImpl.java index 418fc38..682d64c 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenCheckServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenCheckServiceImpl.java @@ -115,6 +115,10 @@ public class TenCheckServiceImpl extends ServiceImpl