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

Merge remote-tracking branch 'origin/dev' into dev

july 4 éve
szülő
commit
9fe4007a0a

+ 1 - 2
ldt-core/src/main/java/org/springblade/common/filter/DecryptFilter.java

@@ -26,7 +26,6 @@ public class DecryptFilter  implements Filter {
 	@SneakyThrows
 	@Override
 	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
-		filterChain.doFilter(servletRequest, servletResponse);
-//		httpUtil.modifyHttpData(servletRequest,servletResponse,filterChain);
+		httpUtil.modifyHttpData(servletRequest,servletResponse,filterChain);
 	}
 }

+ 7 - 61
ldt-core/src/main/java/org/springblade/common/filter/utils/HttpUtil.java

@@ -1,5 +1,7 @@
 package org.springblade.common.filter.utils;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.crypto.SecureUtil;
 import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
@@ -24,6 +26,7 @@ import javax.crypto.SecretKey;
 import javax.servlet.*;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.Part;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.sql.Struct;
@@ -39,23 +42,14 @@ import static cn.hutool.core.util.StrUtil.*;
 @Component
 public class HttpUtil {
 
-	@Value("${crypto.charset}")
-	private String cryptoCharset = "UTF-8";
 	@Value("${crypto.key}")
 	private String cryptoKey;
-	@Value("${crypto.signKey}")
-	private String signKey;
 
 	public void modifyHttpData(ServletRequest request, ServletResponse response, FilterChain chain) throws Exception {
 		HttpServletRequest originalRequest = (HttpServletRequest) request;
 		String url = originalRequest.getRequestURI();
-		if (url.indexOf("put-file") > 0) {
-			chain.doFilter(request,response);
-			return;
-		}
-
-		if (HttpMethod.POST.matches(originalRequest.getMethod())) {
-			//只处理post请求
+		if (HttpMethod.POST.matches(originalRequest.getMethod()) && url.indexOf("put-file") < 0) {
+			//只处理不是上传文件的post请求
 			this.handelPost(request,response,chain,originalRequest);
 		}else{
 			//其他请求直接通过
@@ -88,59 +82,11 @@ public class HttpUtil {
 	private void handelPost(ServletRequest request, ServletResponse response, FilterChain chain,HttpServletRequest originalRequest) throws Exception {
 		//密文
 		String originalRequestBody = ServletUtil.getBody(request);
-		String modifyRequestBody = "{}";
-		if (!isBlank(originalRequestBody)) {
-			//报文不为空,解密,再验签
-			modifyRequestBody = SecureUtil.aes(cryptoKey.getBytes(cryptoCharset)).decryptStr(originalRequestBody);
-		}
-		Boolean flag = this.handelSign(originalRequest, modifyRequestBody);
-		if (!flag) {
-			throw new RuntimeException("签名异常");
-		}
-		//验签通过
-		if (!isBlank(originalRequestBody)) {
+		if (StrUtil.isNotBlank(originalRequestBody)) {
 			//报文不为空,解密
+			String modifyRequestBody = SecureUtil.aes(cryptoKey.getBytes()).decryptStr(originalRequestBody);
 			request = this.modifyRequestBodyAndContentType(originalRequest, modifyRequestBody, null);
 		}
 		chain.doFilter(request, response);
 	}
-
-	/**
-	 * 校验签名
-	 * @param originalRequest
-	 * @param modifyRequestBody
-	 * @return
-	 */
-	private Boolean handelSign(HttpServletRequest originalRequest,String modifyRequestBody){
-		try {
-			//请求头签名
-			String sign = ServletUtil.getHeader(originalRequest, "sign", cryptoCharset);
-			if (isBlank(sign)) {
-				return false;
-			}
-			//后端签名校验
-			TreeMap<String,Object> signMap = JSON.parseObject(modifyRequestBody, TreeMap.class);
-			signMap.put("signKey", signKey);
-			String valStr = "";
-			for (String key : signMap.keySet()) {
-				valStr = valStr + signMap.get(key);
-			}
-			return DigestUtil.md5Hex(valStr).equals(sign);
-		} catch (Exception e) {
-			return false;
-		}
-	}
-
-	public static void main(String[] args) {
-		String keyStr = "cyzh-ldt";
-		byte[] keys;
-		try {
-			keys = keyStr.getBytes("UTF-8");
-			System.out.println(Base64Utils.encodeToString(Arrays.copyOf(keys, 16)));
-		} catch (UnsupportedEncodingException e) {
-			e.printStackTrace();
-		}
-
-	}
-
 }

+ 17 - 18
ldt-core/src/main/java/org/springblade/gateway/common_gateway/controller/AppNoticeManagementController.java

@@ -35,7 +35,9 @@ import org.springblade.ldt.notice.wrapper.NoticeManagementWrapper;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 通知表 控制器
@@ -52,16 +54,22 @@ public class AppNoticeManagementController extends BladeController {
 	private final INoticeManagementService noticeService;
 
 	/**
-	 * 未读
+	 * 未读消息id列表
 	 */
-	@GetMapping("/notReadCount")
+	@GetMapping("/notReadIdList")
 	@ApiOperationSupport(order = 1)
-	@ApiOperation(value = "未读", notes = "传入notice")
-	public R notReadCount(NoticeManagement notice) {
-		int count = noticeService.count(Condition.getQueryWrapper(new NoticeManagement()).lambda()
+	@ApiOperation(value = "未读消息id列表", notes = "传入notice")
+	public R notReadList(NoticeManagement notice) {
+		List<NoticeManagement> list = noticeService.list(Condition.getQueryWrapper(new NoticeManagement()).lambda()
 			.eq(NoticeManagement::getReceiverId, notice.getReceiverId())
-			.eq(NoticeManagement::getIsRead, false));
-		return R.data(count);
+			.eq(NoticeManagement::getIsRead, false)
+			.eq(notice.getSenderType()!=null,NoticeManagement::getSenderType,notice.getSenderType())
+			.select(NoticeManagement::getId));
+		if (CollUtil.isNotEmpty(list)) {
+			List<Long> ids = list.stream().map(NoticeManagement::getId).collect(Collectors.toList());
+			return R.data(ids);
+		}
+		return R.data(null);
 	}
 
 	/**
@@ -70,15 +78,8 @@ public class AppNoticeManagementController extends BladeController {
 	@PostMapping("/isRead")
 	@ApiOperationSupport(order = 5)
 	@ApiOperation(value = "修改", notes = "传入notice")
-	public R update(@Valid @RequestBody NoticeManagement notice) {
-		List<NoticeManagement> list = noticeService.list(Condition.getQueryWrapper(new NoticeManagement()).lambda()
-			.eq(NoticeManagement::getReceiverId, notice.getReceiverId())
-			.eq(NoticeManagement::getIsRead, false));
-		if (CollUtil.isNotEmpty(list)) {
-			list.stream().forEach(item -> item.setIsRead(true));
-			return R.status(noticeService.updateBatchById(list));
-		}
-		return R.status(true);
+	public R update(@Valid @RequestBody List<NoticeManagement> noticeManagements) {
+		return R.status(noticeService.updateBatchById(noticeManagements));
 	}
 
 	/**
@@ -91,6 +92,4 @@ public class AppNoticeManagementController extends BladeController {
 		IPage<NoticeManagement> pages = noticeService.page(Condition.getPage(query), Condition.getQueryWrapper(notice).lambda().orderByDesc(NoticeManagement::getCreateTime));
 		return R.data(NoticeManagementWrapper.build().pageVO(pages));
 	}
-
-
 }

+ 0 - 2
ldt-core/src/main/resources/application.yml

@@ -254,6 +254,4 @@ social:
       - ldt_join_record
 
 crypto:
-  signKey: uRJW6a2Qofpa3pGIdILc
   key: uAY9ugkHQpvozZeA
-  charset: UTF-8