| | |
| | | package com.kidgrow.zuul.filter; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.kidgrow.common.constant.CommonConstant; |
| | | import com.kidgrow.common.constant.SecurityConstants; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.net.URLEncoder; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | @Component |
| | | public class UserInfoHeaderFilter extends ZuulFilter { |
| | | @Autowired |
| | | SysDoctorService sysDoctorService; |
| | | private SysDoctorService sysDoctorService; |
| | | @Override |
| | | public String filterType() { |
| | | return FilterConstants.PRE_TYPE; |
| | |
| | | |
| | | List<SysDoctor> sysDoctors = JSON.parseArray(JSON.toJSONString(listByMap.getData()), SysDoctor.class); |
| | | String str=""; |
| | | Long hospital=-1L; |
| | | if(sysDoctors!=null&&sysDoctors.size()>0){ |
| | | str= sysDoctors.get(0).getDoctorName(); |
| | | hospital=sysDoctors.get(0).getHospitalId(); |
| | | } |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_ID_HEADER, String.valueOf(user.getId())); |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_HEADER, user.getUsername()); |
| | | |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_REAL_NAME,str);//待完善 |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_REAL_NAME,URLEncoder.encode(str,"UTF-8"));//待完善 |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_HOSPITAL_ID_HEADER,hospital.toString()); |
| | | tenantId=hospital.toString(); |
| | | List<SysOrganization> organizations = (List<SysOrganization>) user.getOrganizations(); |
| | | //将组织数据 存到header 里面 |
| | | organizations.sort((e1,e2)->e1.getOrgLevel().compareTo(e2.getOrgLevel())); |
| | |
| | | } |
| | | //将角色放到header |
| | | ctx.addZuulRequestHeader(SecurityConstants.ROLE_HEADER, JSON.toJSONString(user.getRoles())); |
| | | tenantId=String.valueOf(organizations.get(0).getId()); |
| | | |
| | | } |
| | | |
| | | |