Forráskód Böngészése

提交图片上传

everydatestudy 3 éve
szülő
commit
01b8f0fd40

+ 2 - 2
eladmin-system/src/main/java/me/zhengjie/appapi/entity/SysUserEntity.java

@@ -142,7 +142,7 @@ public class SysUserEntity implements Serializable {
 	private String axqSealId;
 	@TableField("axq_is_auth")
 	private String axqIsAuth;
-	@TableField("sign_img_url")
-	private String signImgUrl;
+	@TableField("sign_img_id")
+	private String signImgId;
 
 }

+ 16 - 16
eladmin-system/src/main/java/me/zhengjie/appapi/service/impl/UserAXQInfoServiceImpl.java

@@ -72,22 +72,22 @@ public class UserAXQInfoServiceImpl extends ServiceImpl<IUserAXQInfoDao, UserAXQ
 			qw.eq("id_card", idCard);
 			qw.eq("user_status", "1");
 			UserAXQInfoEntity entity = userAXQDao.selectOne(qw);
-//            String ocrName = TencentServiceUtil.getHandwritingText(content);
-//            if(!ocrName.equals(entity.getUserName())){
-//                return ResponseDTO.error(ResultCode.HANDWRITING_FAIL);
-//            }
-//            // 上传/修改用户签章
-//            CFCACertUtil.proxySwitchOn = "dev".equals(systemEnv);
-//            if(StringUtils.isEmpty(entity.getAxqSealId())){
-//                String sealId = CFCACertUtil.addSealWithContent(entity.getAxqUserId(), content);
-//                entity.setAxqSealId(sealId);
-//                UserAXQInfoEntity saveEntiy = new UserAXQInfoEntity();
-//                saveEntiy.setId(entity.getId());
-//                saveEntiy.setAxqSealId(sealId);
-//                userAXQDao.updateById(saveEntiy);
-//            }else{
-//                CFCACertUtil.updateSealWithContent(entity.getAxqUserId(),entity.getAxqSealId(),content);
-//            }
+            String ocrName = TencentServiceUtil.getHandwritingText(content);
+            if(!ocrName.equals(entity.getUserName())){
+                return ResponseDTO.error(ResultCode.HANDWRITING_FAIL);
+            }
+            // 上传/修改用户签章
+            CFCACertUtil.proxySwitchOn = "dev".equals(systemEnv);
+            if(StringUtils.isEmpty(entity.getAxqSealId())){
+                String sealId = CFCACertUtil.addSealWithContent(entity.getAxqUserId(), content);
+                entity.setAxqSealId(sealId);
+                UserAXQInfoEntity saveEntiy = new UserAXQInfoEntity();
+                saveEntiy.setId(entity.getId());
+                saveEntiy.setAxqSealId(sealId);
+                userAXQDao.updateById(saveEntiy);
+            }else{
+                CFCACertUtil.updateSealWithContent(entity.getAxqUserId(),entity.getAxqSealId(),content);
+            }
 			// 文件签名
 			signContract(entity, contractId);
 		} catch (Exception e) {

+ 31 - 13
eladmin-system/src/main/java/me/zhengjie/appapi/util/FileUploadUtil.java

@@ -2,6 +2,7 @@ package me.zhengjie.appapi.util;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Iterator;
@@ -121,7 +122,7 @@ public class FileUploadUtil {
 			// FileUtils.writeByteArrayToFile(fullPath, b);
 			return imagePath;
 		} catch (Exception e) {
-			log.info("上传图片失败:" + e.getLocalizedMessage());
+			log.error("上传图片失败:" + e.getLocalizedMessage());
 			return null;
 		}
 	}
@@ -155,7 +156,7 @@ public class FileUploadUtil {
 			uploadFile(imagePath, contentType, partFile.getInputStream());
 			return imagePath;
 		} catch (Exception e) {
-			log.info("上传图片失败:" + e.getLocalizedMessage());
+			log.error("上传图片失败:" + e.getLocalizedMessage());
 			return null;
 		}
 
@@ -252,7 +253,7 @@ public class FileUploadUtil {
 			fileHandle.uploadFileStream(fileHandlevo);
 			return imagePath;
 		} catch (Exception e) {
-			log.info("上传图片失败:" + e.getLocalizedMessage());
+			log.error("上传图片失败:" + e.getLocalizedMessage());
 			return null;
 		}
 
@@ -294,7 +295,7 @@ public class FileUploadUtil {
 			bis.close();
 			return filePath;
 		} catch (Exception e) {
-			log.info("上传图片失败:" + e.getLocalizedMessage());
+			log.error("上传图片失败:" + e.getLocalizedMessage());
 			return null;
 		}
 	}
@@ -383,30 +384,34 @@ public class FileUploadUtil {
 		if (html == null) {
 			return null;
 		}
-
 		String uploadPath = AppConfigInfo.APP_UPLOAD_PATH;
 		// 拼接文件路径
 		String fileName = UUIDGenerator.uuid() + ".pdf";
 		String path = businessNo + "/" + StepStatusEnum.getType(orderId) + "/" + fileName;
-		String filePath = uploadPath + path;
+		String sourceFilePath = uploadPath + path;
+		InputStream inputStream = null;
 		try {
 			// File file, String data, Charset charset
-			HtmlConvertPdf.createPdfFile(html, filePath);
+			HtmlConvertPdf.createPdfFile(html, sourceFilePath);
+			inputStream = new FileInputStream(sourceFilePath);
 			// 这里需要把转换完成的删除掉
 			String contentType = "application/pdf";
 			// 通过流上传
 			// fileHandle.uploadFilePath(path, filePath, contentType);
 			FileHandleVo fileHandlevo = new FileHandleVo();
-			fileHandlevo.setFilePath(filePath);
-			fileHandlevo.setSourceFilePath(filePath);
+			fileHandlevo.setFilePath(path);
+			fileHandlevo.setSourceFilePath(sourceFilePath);
 			fileHandlevo.setContentType(contentType);
+			fileHandlevo.setInputStream(inputStream);
 			fileHandle.uploadFileStream(fileHandlevo);
 			// 这个删除文件留给具体的上传处理
-// 			FileUtils.deleteQuietly(new File(filePath));
+			FileUtils.deleteQuietly(new File(sourceFilePath));
 			return path;
 		} catch (Exception e) {
-			log.info("转换pdf失败:" + e.getLocalizedMessage());
+			log.error("转换pdf失败:" + e.getLocalizedMessage());
 			return null;
+		} finally {
+			IoUtil.close(inputStream);
 		}
 	}
 
@@ -436,12 +441,25 @@ public class FileUploadUtil {
 		try {
 			return fileHandle.getPreviewUrl(fileKey);
 		} catch (Exception e) {
-			log.info("图片预览失败:" + e.getLocalizedMessage());
+			log.error("图片预览失败:" + e.getLocalizedMessage());
 			return null;
 		}
 
 	}
-
+	/**
+	 * 通过文件id得到文件流
+	 * @param fileId
+	 * @return
+	 * @throws Exception
+	 */
+	public static byte[] getByte(String fileId) throws Exception{
+		try {
+			return fileHandle.getByte(fileId);
+		} catch (Exception e) {
+			log.error("得到文件流失败:" + e.getLocalizedMessage());
+			return null;
+		}
+	}
 	/**
 	 * 得到文件名称
 	 * 

+ 7 - 2
eladmin-system/src/main/java/me/zhengjie/modules/file/FileHandle.java

@@ -43,6 +43,11 @@ public interface FileHandle {
 	 */
 
 	public String getPreviewUrl(String fileKey) throws Exception ;
-
-	
+	/**
+	 * 通过文件id得到文件流
+	 * @param fileId
+	 * @return
+	 * @throws Exception
+	 */
+	public byte[] getByte(String fileId) throws Exception;
 }

+ 6 - 0
eladmin-system/src/main/java/me/zhengjie/modules/file/LocalFileHandle.java

@@ -34,4 +34,10 @@ public class LocalFileHandle extends AbstractFileHandle {
 		return null;
 	}
 
+	@Override
+	public byte[] getByte(String fileId) throws Exception {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
 }

+ 16 - 2
eladmin-system/src/main/java/me/zhengjie/modules/file/MinioFileHandle.java

@@ -5,13 +5,17 @@ import java.io.InputStream;
 
 import javax.annotation.PostConstruct;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Component;
 
+import cn.hutool.core.io.IoUtil;
 import io.minio.MinioClient;
 import io.minio.PutObjectOptions;
 import lombok.extern.slf4j.Slf4j;
+import me.zhengjie.appapi.entity.FileInfoEntity;
+import me.zhengjie.appapi.service.FileInfoService;
 
 @Slf4j
 @Primary
@@ -29,7 +33,10 @@ public class MinioFileHandle extends AbstractFileHandle {
 	// minio的连接secretkey
 	@Value("${app.minio.secretkey:minioadmin}")
 	public String appMinioSecretkey;
-
+	
+	@Autowired
+	public FileInfoService fileInfoService;
+	
 	private MinioClient minioClient;
 
 	@PostConstruct
@@ -104,5 +111,12 @@ public class MinioFileHandle extends AbstractFileHandle {
 	public String getObjectUrl(String keyName) throws Exception {
 		return minioClient.presignedGetObject(bucketName, keyName, 3600);
 	}
-
+	 
+	public byte[] getByte(String fileId) throws Exception {
+		FileInfoEntity fileInfo = fileInfoService.getById(fileId);
+		String path=fileInfo.getPath();
+		InputStream inputStream=this.getObject(path);
+		//这里已经关闭流,不需要手动关闭
+		return IoUtil.readBytes(inputStream);
+	}
 }

+ 3 - 0
eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthorizationController.java

@@ -143,6 +143,9 @@ public class AuthorizationController {
 			if (fileInfo != null) {
 				String signImgUrl = FileUploadUtil.getFileUrl(fileInfo.getPath());
 				cacheUser.setSignImgUrl(signImgUrl);
+			}else {
+				//这里需要设置图片的路径为空
+				cacheUser.setSignImgUrl("");
 			}
 
 		}

+ 3 - 3
eladmin-system/src/main/java/me/zhengjie/modules/system/domain/User.java

@@ -114,9 +114,9 @@ public class User extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "身份证") // 用户身份证
     private String idCard;
 
-    @Column(name = "sign_img_url")
-    @ApiModelProperty(value = "签名图片链接")
-    private String signImgUrl;
+    @Column(name = "sign_img_id")
+    @ApiModelProperty(value = "签名图片id")
+    private String signImgId;
 
     @Column(name = "axq_user_id")
     @ApiModelProperty(value = "安心签用户ID")

+ 10 - 10
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/NotaryOfficeController.java

@@ -57,7 +57,7 @@ public class NotaryOfficeController {
      * @return
      */
     @RequestMapping("/create")
-    public BaseResponse create(@RequestBody NotaryOfficeCreateReq req) {
+    public BaseResponse<?> create(@RequestBody NotaryOfficeCreateReq req) {
 
         return notaryOfficeService.create(req);
     }
@@ -68,7 +68,7 @@ public class NotaryOfficeController {
      * @return
      */
     @RequestMapping("/update")
-    public BaseResponse update(@RequestBody NotaryOfficeCreateReq req) {
+    public BaseResponse<?> update(@RequestBody NotaryOfficeCreateReq req) {
         return notaryOfficeService.update(req);
     }
 
@@ -78,7 +78,7 @@ public class NotaryOfficeController {
      * @return
      */
     @RequestMapping("/delete")
-    public BaseResponse delete(@RequestBody String[] ids) {
+    public BaseResponse<?> delete(@RequestBody String[] ids) {
         return notaryOfficeService.delete(ids);
     }
 
@@ -88,14 +88,14 @@ public class NotaryOfficeController {
      * @return
      */
     @RequestMapping("/sendAuthMessage")
-    public BaseResponse sendAuthMessage(@RequestParam String userId){
+    public BaseResponse<?> sendAuthMessage(@RequestParam String userId){
         return notaryOfficeService.sendAuthMessage(userId);
     }
     /**
      * 确认授权验证码,完成签名授权
      */
     @RequestMapping("/verifyAuthMessage")
-    public BaseResponse verifyAuthMessage(@RequestBody NotaryOfficeCreateReq req){
+    public BaseResponse<?> verifyAuthMessage(@RequestBody NotaryOfficeCreateReq req){
         return notaryOfficeService.verifyAuthMessage(req);
     }
 
@@ -105,7 +105,7 @@ public class NotaryOfficeController {
      * @return
      */
     @AnonymousPostMapping("/modifyAutoGenerate")
-    public BaseResponse modifyAutoGenerate(@RequestBody NotaryOfficeCreateReq req){
+    public BaseResponse<?> modifyAutoGenerate(@RequestBody NotaryOfficeCreateReq req){
         return notaryOfficeService.modifyAutoGenerate(req);
     }
 
@@ -115,7 +115,7 @@ public class NotaryOfficeController {
      * @return
      */
     @AnonymousPostMapping("/uploadSeal")
-    public BaseResponse uploadSeal(@RequestBody NotaryOfficeCreateReq req){
+    public BaseResponse<?> uploadSeal(@RequestBody NotaryOfficeCreateReq req){
         return notaryOfficeService.uploadSeal(req);
     }
 
@@ -125,7 +125,7 @@ public class NotaryOfficeController {
      * @return
      */
     @AnonymousPostMapping("/modifyAutoGenerateInfo")
-    public BaseResponse modifyAutoGenerateInfo(@RequestBody NotaryOfficeCreateReq req){
+    public BaseResponse<?> modifyAutoGenerateInfo(@RequestBody NotaryOfficeCreateReq req){
         return notaryOfficeService.modifyAutoGenerateInfo(req);
     }
 
@@ -135,7 +135,7 @@ public class NotaryOfficeController {
      * @return
      */
     @AnonymousPostMapping("/queryCertificate")
-    public BaseResponse queryCertificate(@RequestBody NotaryOfficeCreateReq req){
+    public BaseResponse<?> queryCertificate(@RequestBody NotaryOfficeCreateReq req){
         return notaryOfficeService.queryCertificate(req);
     }
 
@@ -145,7 +145,7 @@ public class NotaryOfficeController {
      * @return
      */
     @AnonymousPostMapping("/getAuthStatus")
-    public BaseResponse getAuthStatus(@RequestBody NotaryOfficeCreateReq req){
+    public BaseResponse<?> getAuthStatus(@RequestBody NotaryOfficeCreateReq req){
         return notaryOfficeService.getAuthStatus(req);
     }
 }

+ 2 - 0
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDto.java

@@ -79,4 +79,6 @@ public class UserDto extends BaseDTO implements Serializable {
     private String axqIsAuth;
     private String signImgUrl;
     private String autoGenerate;
+    //图片的id值
+    private String signImgId;
 }

+ 6 - 5
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/NotaryOfficeServiceImpl.java

@@ -365,13 +365,14 @@ public class NotaryOfficeServiceImpl extends ServiceImpl<NotaryOfficeMapper, Not
 				CFCACertUtil.proxySwitchOn = "dev".equals(systemEnv);
 				if (me.zhengjie.utils.StringUtils.isEmpty(entity.getAxqSealId())) {
 					// 上传公证处签章
-					String path = req.getSealImg().replaceAll(imageURL, uplaodPath);
-					String sealId = CFCACertUtil.addSeal(entity.getAxqUserId(), path);
+					byte[] b = FileUploadUtil.getByte(req.getSealImg());
+					String sealId = CFCACertUtil.addSeal(entity.getAxqUserId(), b);
 					saveEntity.setAxqSealId(sealId);
 				} else {
 					// 修改公证员签章
-					String path = req.getSealImg().replaceAll(imageURL, uplaodPath);
-					CFCACertUtil.updateSeal(entity.getAxqUserId(), entity.getAxqSealId(), path);
+					byte[] b = FileUploadUtil.getByte(req.getSealImg());
+				
+					CFCACertUtil.updateSeal(entity.getAxqUserId(), entity.getAxqSealId(), b);
 				}
 				saveEntity.setId(req.getId());
 				saveEntity.setSealImg(req.getImageId());
@@ -428,7 +429,7 @@ public class NotaryOfficeServiceImpl extends ServiceImpl<NotaryOfficeMapper, Not
 	public BaseResponse getAuthStatus(NotaryOfficeCreateReq req) {
 		BaseResponse response = new BaseResponse();
 		NotaryOfficeEntity notaryOffice = notaryOfficeMapper.selectById(req.getId());
-		String authStatus = notaryOffice.getAxqIsAuth() == null ? "0" : notaryOffice.getAxqIsAuth();
+		String authStatus = StringUtils.isEmpty(notaryOffice.getAxqIsAuth())  ? "0" : notaryOffice.getAxqIsAuth();
 		if ("0".equals(authStatus)) {
 			CFCACertUtil.proxySwitchOn = "dev".equals(systemEnv);
 			try {

+ 8 - 7
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java

@@ -27,6 +27,7 @@ import me.zhengjie.appapi.entity.response.ResultData;
 import me.zhengjie.appapi.mapper.*;
 import me.zhengjie.appapi.service.SysRoleService;
 import me.zhengjie.appapi.util.BeanCopyUtils;
+import me.zhengjie.appapi.util.FileUploadUtil;
 import me.zhengjie.base.ResultCode;
 import me.zhengjie.config.FileProperties;
 import me.zhengjie.exception.BadRequestException;
@@ -325,17 +326,17 @@ public class UserServiceImpl implements UserService {
                     SysUserEntity saveEntity = new SysUserEntity();
                     CFCACertUtil.proxySwitchOn = "dev".equals(systemEnv);
                     if(StringUtils.isEmpty(user.getAxqSealId())) {
-                        // 上传公证员签章
-                        String path = resources.getSignImgUrl();
-                        String sealId = CFCACertUtil.addSeal(user.getAxqUserId(), path);
+                        // 上传公证员签章,修改通过统一方式得到文件的流
+                        byte[] b = FileUploadUtil.getByte(resources.getImageId());
+                        String sealId = CFCACertUtil.addSeal(user.getAxqUserId(), b);
                         saveEntity.setAxqSealId(sealId);
                     } else {
                         // 修改公证员签章
-                        String path = resources.getSignImgUrl();
-                        CFCACertUtil.updateSeal(user.getAxqUserId(), user.getAxqSealId(), path);
+                    	byte[] b = FileUploadUtil.getByte(resources.getImageId());  
+                        CFCACertUtil.updateSeal(user.getAxqUserId(), user.getAxqSealId(), b);
                     }
                     saveEntity.setUserId(user.getUserId());
-                    saveEntity.setSignImgUrl(resources.getImageId());
+                    saveEntity.setSignImgId(resources.getImageId());
                     userDao.updateById(saveEntity);
                 } catch (Exception e) {
                     e.printStackTrace();
@@ -395,7 +396,7 @@ public class UserServiceImpl implements UserService {
         user.setPhone(resources.getPhone());
         user.setGender(resources.getGender());
         user.setOrgId(resources.getOrgId());
-        user.setSignImgUrl(resources.getImageId());
+        user.setImageId(resources.getImageId());
         userRepository.save(user);
         // 清除缓存
         delCaches(user.getId(), user.getUsername());

+ 4 - 4
eladmin-system/src/main/java/me/zhengjie/util/CFCACertUtil.java

@@ -132,9 +132,9 @@ public class CFCACertUtil {
      * @param filePath
      * @throws Exception
      */
-    public static void updateSeal(String userId, String sealId, String filePath) throws Exception {
+    public static void updateSeal(String userId, String sealId, byte[] b) throws Exception {
     	//这里将图片的路径下载文件
-    	byte[] b=DownloadUtils.downloadFile(filePath);
+//    	byte[] b=DownloadUtils.downloadFile(filePath);
         String content = Base64.toBase64String(b);
         updateSealWithContent(userId, sealId, content);
     }
@@ -179,8 +179,8 @@ public class CFCACertUtil {
      * @return 返回印章ID
      * @throws Exception
      */
-    public static String addSeal(String userId, String filePath) throws Exception {
-        String content = Base64.toBase64String(Files.readAllBytes(Paths.get(filePath)));
+    public static String addSeal(String userId, byte[] b) throws Exception {
+        String content = Base64.toBase64String(b);
         return addSealWithContent(userId, content);
     }