From 7a60125f71610575ec400ac3d7fd4a42e17503be Mon Sep 17 00:00:00 2001 From: gaoben Date: Tue, 30 Jul 2024 18:15:04 +0800 Subject: [PATCH] =?UTF-8?q?http=E5=8D=8F=E8=AE=AE=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=8E=A5=E5=8F=A3=E5=85=81=E8=AE=B8=E7=85=A7?= =?UTF-8?q?=E7=89=87=E5=92=8C=E5=8E=8B=E7=BC=A9=E5=8C=85=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../httpapi/controler/HttpApiController.java | 141 ++++++++++-------- 1 file changed, 77 insertions(+), 64 deletions(-) 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 facab4e..73a905e 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 @@ -350,9 +350,11 @@ public class HttpApiController { // puser.setActive_end_time(0); puser.setLast_update_stamp(p.getLastUpdateTime().getTime()); - puser.setFace_pic_download_url(globalValue.getMinioEndpoint()+"/" - + globalValue.getMinioBucketName()+"/" - + p.getOrgImage()); + if(p.getOrgImage()!=null && p.getOrgImage().length()>0){ + puser.setFace_pic_download_url(globalValue.getMinioEndpoint()+"/" + + globalValue.getMinioBucketName()+"/" + + p.getOrgImage()); + } puser.setFace_pic_base64(""); @@ -846,7 +848,7 @@ public class HttpApiController { @ApiImplicitParam(name = "timestamp", value = "timestamp", paramType = "query", dataType = "String", required = true), @ApiImplicitParam(name = "sign", value = "sign", paramType = "query", dataType = "String", required = true), }) - public R addPerson(@RequestParam("jsonString") String jsonString, @RequestParam("orgImage") MultipartFile orgImage, @RequestParam("sourceFile") MultipartFile sourceFile,@RequestParam("thdFeature") String thdFeature) { + public R addPerson(@RequestParam("jsonString") String jsonString, @RequestParam(value="orgImage",required = false) MultipartFile orgImage, @RequestParam(value="sourceFile",required = false) MultipartFile sourceFile,@RequestParam("thdFeature") String thdFeature) { JSONObject jsonContent = JSONObject.parseObject(jsonString); String sn = jsonContent.getString("dev_id"); String appKey = jsonContent.getString("appKey"); @@ -871,7 +873,9 @@ public class HttpApiController { TenPersonEntity tenPerson = JSONObject.toJavaObject(personJson,TenPersonEntity.class); - tenPerson.setThdFeature(thdFeature); + if(thdFeature!=null && thdFeature.length()>0){ + tenPerson.setThdFeature(thdFeature); + } if(tenPerson.getIdCard()!=null){ if(tenPerson.getIdCard().length() == 15){ @@ -939,68 +943,75 @@ public class HttpApiController { tenPerson.setCellId(deviceEntity.getCellId()); - if (orgImage.isEmpty() || orgImage.getSize() == 0 || sourceFile.isEmpty() || sourceFile.getSize() == 0) { - return R.error("文件不能为空"); - } - try { - //保存原始图片 - String userFileUrl = globalValue.getImagesDir() + "/" + - tenPerson.getCellId().toString() + "/" + - tenPerson.getPersonId().toString() + "/"; - String orgImageFileName = userFileUrl + "o_" + UUIDUtil.uuid() + ".jpg"; +// if (orgImage.isEmpty() || orgImage.getSize() == 0 || sourceFile.isEmpty() || sourceFile.getSize() == 0) { +// return R.error("文件不能为空"); +// } + if (orgImage!=null && orgImage.getSize() != 0) { + try { + //保存原始图片 + String userFileUrl = globalValue.getImagesDir() + "/" + + tenPerson.getCellId().toString() + "/" + + tenPerson.getPersonId().toString() + "/"; + String orgImageFileName = userFileUrl + "o_" + UUIDUtil.uuid() + ".jpg"; - InputStream inputStream = orgImage.getInputStream(); - PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1); - putObjectOptions.setContentType(orgImage.getContentType()); - minioClient.putObject( - minioConfig.getBucketName(), orgImageFileName, inputStream, putObjectOptions); - inputStream.close(); - - tenPerson.setOrgImage(orgImageFileName); - tenPerson.setFaceImage(orgImageFileName); - - } catch (Exception e) { - return R.error(e.getMessage()); - } - - - try { - //保存sourceFiile - String userFileUrl = globalValue.getImagesDir() + "/" + - tenPerson.getCellId().toString() + "/" + - tenPerson.getPersonId().toString() + "/"; - String sourceFileName = userFileUrl + "p_" + UUIDUtil.uuid() + ".zip"; - - InputStream inputStream = sourceFile.getInputStream(); - PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1); - putObjectOptions.setContentType(sourceFile.getContentType()); - minioClient.putObject( - minioConfig.getBucketName(), sourceFileName, inputStream, putObjectOptions); - inputStream.close(); - - 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"; + InputStream inputStream = orgImage.getInputStream(); + PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1); + putObjectOptions.setContentType(orgImage.getContentType()); minioClient.putObject( - minioConfig.getBucketName(), gifFileName, gifInputStream, gifputObjectOptions); - gifInputStream.close(); - tenPerson.setFaceModel(gifFileName); - File dirFile = gifFile.getParentFile(); - gifFile.delete(); - dirFile.delete(); + minioConfig.getBucketName(), orgImageFileName, inputStream, putObjectOptions); + inputStream.close(); + + tenPerson.setOrgImage(orgImageFileName); + tenPerson.setFaceImage(orgImageFileName); + + } catch (Exception e) { + return R.error(e.getMessage()); } - } catch (Exception e) { - return R.error(e.getMessage()); } + + if (sourceFile!=null && sourceFile.getSize() != 0) { + try { + //保存sourceFiile + String userFileUrl = globalValue.getImagesDir() + "/" + + tenPerson.getCellId().toString() + "/" + + tenPerson.getPersonId().toString() + "/"; + String sourceFileName = userFileUrl + "p_" + UUIDUtil.uuid() + ".zip"; + + InputStream inputStream = sourceFile.getInputStream(); + PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1); + putObjectOptions.setContentType(sourceFile.getContentType()); + minioClient.putObject( + minioConfig.getBucketName(), sourceFileName, inputStream, putObjectOptions); + inputStream.close(); + + 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()); + } + } + + + + //处理类型: //1. 不是固定类型,给一个默认的家属类型 if(tenPerson.getPersonType()>10000){ @@ -1304,7 +1315,9 @@ public class HttpApiController { //----------------------------------------以下业务----------------------------------------------------- JSONObject personJson = jsonContent.getJSONObject("data"); TenPersonEntity tenPerson = JSONObject.toJavaObject(personJson,TenPersonEntity.class); - tenPerson.setThdFeature(thdFeature); + if(thdFeature!=null && thdFeature.length()>0){ + tenPerson.setThdFeature(thdFeature); + } tenPerson.setPersonId(personJson.getLong("uid")); if(tenPerson.getIdCard()!=null){