脸模版:增加脸模解压,页面选择显示

This commit is contained in:
gaoben 2024-04-19 13:41:25 +08:00
parent 20eb02695d
commit 5fce9374b2
6 changed files with 170 additions and 0 deletions

View File

@ -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();
// }
// }
}

View File

@ -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());
}

View File

@ -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);
}
}
}

View File

@ -130,4 +130,7 @@ public class TenCheckEntity implements Serializable {
@JsonSerialize(using = ToStringSerializer.class)
private Long cellId;
@TableField(exist = false)
private String faceModel;
}

View File

@ -115,6 +115,10 @@ public class TenCheckServiceImpl extends ServiceImpl<TenCheckDao, TenCheckEntity
}
// checkEntity.setRgb(globalValue.getFileUrl()+checkEntity.getRgb());
checkEntity.setRgb(checkEntity.getRgb());
TenPersonEntity personEntity = tenPersonService.getByIdWithDelete(checkEntity.getMemberId());
if(personEntity!=null){
checkEntity.setFaceModel(personEntity.getFaceModel());
}
}
return new PageUtils(page);
}
@ -200,6 +204,7 @@ public class TenCheckServiceImpl extends ServiceImpl<TenCheckDao, TenCheckEntity
vo.setDutyOffEarlyCount(dutyOnEarlyCount);
vo.setRgb(vo.getRgb());
vo.setFaceModel(memberEntity.getFaceModel());
}
return new PageUtils(page);
}

View File

@ -70,6 +70,9 @@ public class TenCheckMemberCountVo implements Serializable {
@ApiModelProperty("迟到次数")
private Integer dutyOnLateCount;
@ApiModelProperty("脸模")
private String faceModel;
/**
* 正常签退次数
*/