From 76b053e21f5eb7cffdc13f5a17bf298e0cbf5ea8 Mon Sep 17 00:00:00 2001 From: shijie <648688341@qq.com> Date: Thu, 18 Feb 2021 14:59:48 +0800 Subject: [PATCH] =?UTF-8?q?TOKEN=E8=BF=87=E6=9C=9F=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=BC=96=E7=A0=81=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DgApplyAmountInfoServiceImpl.java | 13 ++++++++ .../hrauth/filter/MyAuthenticationFilter.java | 30 +++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/service/impl/DgApplyAmountInfoServiceImpl.java b/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/service/impl/DgApplyAmountInfoServiceImpl.java index 98831544..16dcb7c2 100644 --- a/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/service/impl/DgApplyAmountInfoServiceImpl.java +++ b/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/service/impl/DgApplyAmountInfoServiceImpl.java @@ -237,11 +237,15 @@ public class DgApplyAmountInfoServiceImpl extends ServiceImpl().eq("business_id",businessApplication.getBusinessId())); + //根据企业id查询企业详情 + DgApplyAmountInfoRequest applyAmountInfo = new DgApplyAmountInfoRequest(); + applyAmountInfo.setCompanyId(dgApplyAmountInfo.getCompanyId()); + ResponseResult result = crmsFeignService.queryCustomerInfoById(applyAmountInfo); + LinkedHashMap linkedList = (LinkedHashMap)result.getData(); + Object o1 = linkedList.get("linkman"); + Object o2 = linkedList.get("linkPhone"); //修改备份企业信息 DgBusinessCompany dgBusinessCompany = new DgBusinessCompany(); BeanUtils.copyProperties(businessApplication,dgBusinessCompany); + dgBusinessCompany.setLinkPhone(String.valueOf(o2)); + dgBusinessCompany.setLinkman(String.valueOf(o1)); System.out.println("dgBusinessCompany============="+dgBusinessCompany); dgBusinessCompanyMapper.update(dgBusinessCompany,new QueryWrapper() .eq("business_id",businessApplication.getBusinessId())); diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/filter/MyAuthenticationFilter.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/filter/MyAuthenticationFilter.java index e1f78677..a8f95267 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/filter/MyAuthenticationFilter.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/filter/MyAuthenticationFilter.java @@ -1,10 +1,12 @@ package com.daqing.financial.hrauth.filter; +import com.alibaba.fastjson.JSON; import com.daqing.financial.hrauth.enums.Constants; import com.daqing.financial.hrauth.handle.SecurityUser; import com.daqing.financial.hrauth.service.impl.UserDetailsServiceImpl; import com.daqing.financial.hrauth.util.MultiReadHttpServletRequest; import com.daqing.financial.hrauth.util.MultiReadHttpServletResponse; +import com.daqing.framework.model.response.ResponseResult; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.security.access.AccessDeniedException; @@ -19,6 +21,7 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.PrintWriter; import java.io.UnsupportedEncodingException; /** @@ -38,6 +41,25 @@ public class MyAuthenticationFilter extends OncePerRequestFilter { this.userDetailsService = userDetailsService; } + private static void printJson(HttpServletResponse response) { + ResponseResult responseResult = new ResponseResult(false,401,"TOKEN已过期,请重新登录","TOKEN已过期,请重新登录"); + String content = JSON.toJSONString(responseResult); + printContent(response, content); + } + private static void printContent(HttpServletResponse response, String content) { + try { + response.reset(); + response.setContentType("application/json"); + response.setHeader("Cache-Control", "no-store"); + response.setCharacterEncoding("UTF-8"); + PrintWriter pw = response.getWriter(); + pw.write(content); + pw.flush(); + } catch (Exception e) { + e.printStackTrace(); + } + } + @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { System.out.println("请求头类型: " + request.getContentType()); @@ -70,15 +92,17 @@ public class MyAuthenticationFilter extends OncePerRequestFilter { // 检查token SecurityUser securityUser = userDetailsService.getUserByToken(token); if (securityUser == null || securityUser.getCurrentUserInfo() == null) { - throw new AccessDeniedException("TOKEN已过期,请重新登录!"); + //throw new AccessDeniedException("TOKEN已过期,请重新登录!"); + printJson(response); + return; } UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(securityUser, null, securityUser.getAuthorities()); // 全局注入角色权限信息和登录用户基本信息 SecurityContextHolder.getContext().setAuthentication(authentication); } -/* else { + else { throw new AccessDeniedException("TOKEN不存在,请重新登录!"); - }*/ + } filterChain.doFilter(wrappedRequest, wrappedResponse); } finally { stopWatch.stop();