Browse Source

fix: 查重逻辑

shc 3 years ago
parent
commit
7156f392b0

+ 16 - 7
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/ApiController.java

@@ -60,6 +60,7 @@ import com.qunzhixinxi.hnqz.common.taxhelper.entity.request.TaxHelperAddMemberRe
 import com.qunzhixinxi.hnqz.common.taxhelper.entity.response.TaxHelperResponse;
 import com.qunzhixinxi.hnqz.common.taxhelper.enums.TaxHelperCertStatus;
 import com.qunzhixinxi.hnqz.common.taxhelper.service.TaxHelperService;
+import com.sun.org.apache.bcel.internal.generic.RETURN;
 import io.opentracing.log.Fields;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -827,6 +828,7 @@ public class ApiController {
 	public R saveTaskContent(@RequestBody WmTaskContent wmTaskContent) {
 		Set<String> errorHash = new HashSet<>();
 		List<String> ducImgUrl = new ArrayList<>();
+		List<String> all = null;
 
 		String draftKey = wmTaskContent.getDraftKey();
 		String taskTypeId = wmTaskContent.getTemp30();
@@ -840,14 +842,18 @@ public class ApiController {
 			try {
 				String fieldVal = (String) field.get(wmTaskContent);
 
-				log.info("key:{}, val:{}", field.getName() , fieldVal);
-				duplicateImage(fieldVal, id, errorHash, ducImgUrl);
+				log.info("key:{}, val:{}", field.getName(), fieldVal);
+				all = duplicateImage(fieldVal, id, errorHash, ducImgUrl);
 			} catch (Exception ignored) {
 			}
 
 		}
 
 		if (CollUtil.isNotEmpty(ducImgUrl)) {
+			// 保存图片
+			if (CollUtil.isNotEmpty(all)){
+				all.forEach(hash -> redisTemplate.delete(String.format("%s:%s", id, hash)));
+			}
 			return R.failed(ducImgUrl, "提交重复的图片");
 		}
 
@@ -865,7 +871,9 @@ public class ApiController {
 		return r;
 	}
 
-	private void duplicateImage(String contentValue, Integer userId, Set<String> errorHash, List<String> duplicateImageUrl) {
+	private List<String> duplicateImage(String contentValue, Integer userId, Set<String> errorHash, List<String> duplicateImageUrl) {
+
+		List<String> all = new ArrayList<>();
 
 		if (contentValue.startsWith("/admin/sys-file/wmkj")) {
 
@@ -886,13 +894,14 @@ public class ApiController {
 						byte[] digest = md5.digest(bytes);
 						String hash = new BigInteger(1, digest).toString(16);
 						log.info("图片md5:{}", hash);
-						Boolean aBoolean = redisTemplate.opsForValue().setIfAbsent(String.format("%s:%s", userId, hash), item, 7, TimeUnit.DAYS);
-						if (aBoolean != null && !aBoolean) {
+						Boolean aBoolean = redisTemplate.opsForValue().setIfAbsent(String.format("%s:%s", userId, hash), item);
+						if (!aBoolean) {
 							log.error("上传了重复的图片");
 							errorHash.add(hash);
 							duplicateImageUrl.add(upmsConfig.getClientUrl() + item);
+						} else {
+							all.add(hash);
 						}
-
 					} catch (IOException | URISyntaxException | NoSuchAlgorithmException e) {
 						e.printStackTrace();
 					}
@@ -904,7 +913,7 @@ public class ApiController {
 
 
 		}
-
+		return all;
 	}
 
 	/**