diff --git a/.gitignore b/.gitignore index 151918b6..9b5353fd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ # Log file *.log /log +/logs # BlueJ files *.ctxt diff --git a/ad-platform-common/.gitignore b/ad-platform-common/.gitignore deleted file mode 100644 index efb4aab2..00000000 --- a/ad-platform-common/.gitignore +++ /dev/null @@ -1,46 +0,0 @@ -### Java template -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -### Maven template -target/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next -release.properties -dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties -# https://github.com/takari/maven-wrapper#usage-without-binary-jar -.mvn/wrapper/maven-wrapper.jar - -### Example user template template -### Example user template - -# IntelliJ project files -.idea -*.iml -out -gen diff --git a/ad-platform-common/ad-platform-common-auth/pom.xml b/ad-platform-common/ad-platform-common-auth/pom.xml new file mode 100644 index 00000000..f7340e7e --- /dev/null +++ b/ad-platform-common/ad-platform-common-auth/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + ad-platform + com.baiye + 1.0-SNAPSHOT + ../../pom.xml + + com.baiye + ad-platform-common-auth + 1.0-SNAPSHOT + ad-platform-common-auth + ad-platform-common-auth + + 1.8 + + + + + com.baiye + ad-platform-common-core + 1.0-SNAPSHOT + + + + com.baiye + ad-platform-pojo + 1.0-SNAPSHOT + + + + + io.jsonwebtoken + jjwt-api + + + + io.jsonwebtoken + jjwt-impl + + + + io.jsonwebtoken + jjwt-jackson + + + + com.github.whvcse + easy-captcha + + + + + org.springframework.boot + spring-boot-starter-websocket + + + + + + + diff --git a/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/aspect/SecurityInnerAspect.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/aspect/SecurityInnerAspect.java new file mode 100644 index 00000000..1090ce70 --- /dev/null +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/aspect/SecurityInnerAspect.java @@ -0,0 +1,49 @@ +package com.baiye.aspect; + +import cn.hutool.core.util.StrUtil; +import com.baiye.annotation.Inner; +import com.baiye.constant.SecurityConstants; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.security.access.AccessDeniedException; + +import javax.servlet.http.HttpServletRequest; + +/** + * @author Enzo + * @date : 2022/1/11 + */ +@Slf4j +@Aspect +@RequiredArgsConstructor +public class SecurityInnerAspect implements Ordered { + + private final HttpServletRequest request; + + @SneakyThrows + @Around("@within(inner) || @annotation(inner)") + public Object around(ProceedingJoinPoint point, Inner inner) { + // 实际注入的inner实体由表达式后一个注解决定,即是方法上的@Inner注解实体,若方法上无@Inner注解,则获取类上的 + if (inner == null) { + Class clazz = point.getTarget().getClass(); + inner = AnnotationUtils.findAnnotation(clazz, Inner.class); + } + String header = request.getHeader(SecurityConstants.FROM); + if (inner.value() && !StrUtil.equals(SecurityConstants.FROM_IN, header)) { + log.warn("访问接口 {} 没有权限", point.getSignature().getName()); + throw new AccessDeniedException("Access is denied"); + } + return point.proceed(); + } + + @Override + public int getOrder() { + return Ordered.HIGHEST_PRECEDENCE + 1; + } +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/ConfigBeanConfiguration.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/ConfigBeanConfiguration.java similarity index 77% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/ConfigBeanConfiguration.java rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/ConfigBeanConfiguration.java index 4bd8e7cd..aafb822a 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/ConfigBeanConfiguration.java +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/ConfigBeanConfiguration.java @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baiye.modules.security.config; +package com.baiye.config; -import com.baiye.modules.security.config.bean.LoginProperties; -import com.baiye.modules.security.config.bean.SecurityProperties; +import com.baiye.properties.bean.LoginProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -35,9 +34,5 @@ public class ConfigBeanConfiguration { return new LoginProperties(); } - @Bean - @ConfigurationProperties(prefix = "jwt") - public SecurityProperties securityProperties() { - return new SecurityProperties(); - } + } diff --git a/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/CustomAuthorityDeserializer.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/CustomAuthorityDeserializer.java new file mode 100644 index 00000000..173c43e6 --- /dev/null +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/CustomAuthorityDeserializer.java @@ -0,0 +1,35 @@ +package com.baiye.config; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; + +import java.io.IOException; +import java.util.Iterator; +import java.util.LinkedList; + +/** + * @author Enzo + * @date : 2022/1/11 + */ +public class CustomAuthorityDeserializer extends JsonDeserializer { + @Override + public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + ObjectMapper mapper = (ObjectMapper) p.getCodec(); + JsonNode jsonNode = mapper.readTree(p); + LinkedList grantedAuthorities = new LinkedList<>(); + Iterator elements = jsonNode.elements(); + while (elements.hasNext()) { + JsonNode next = elements.next(); + JsonNode authority = next.get("authority"); + //将得到的值放入链表 最终返回该链表 + grantedAuthorities.add(new SimpleGrantedAuthority(authority.asText())); + } + return grantedAuthorities; + } +} diff --git a/ad-platform-common/src/main/java/com/baiye/config/ElPermissionConfig.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/ElPermissionConfig.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/config/ElPermissionConfig.java rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/ElPermissionConfig.java diff --git a/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/feign/RemoteUserService.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/feign/RemoteUserService.java new file mode 100644 index 00000000..1b7a16f5 --- /dev/null +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/feign/RemoteUserService.java @@ -0,0 +1,43 @@ +package com.baiye.feign; + +import com.baiye.model.dto.UserDto; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; +import java.util.Set; + +/** + * @author Enzo + * @date : 2022/1/11 + */ +@FeignClient(contextId = "remoteUserService", value = "ad-platform-management") +public interface RemoteUserService { + + /** + * 用户名查找名称 + * @param username + * @return + */ + @GetMapping("/api/users/info/findByName") + UserDto findByName(@RequestParam("username") String username); + + /** + * 查找组长 + * @param user + * @return + */ + @PostMapping("/api/users/info/deptIds") + List getDeptIds(@RequestBody UserDto user); + + /** + * 账号权限 + * @param user + * @return + */ + @PostMapping("/api/roles/user/authority") + Set mapToGrantedAuthorities(@RequestBody UserDto user); +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/SecurityProperties.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/SecurityProperties.java similarity index 85% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/SecurityProperties.java rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/SecurityProperties.java index 06c3dded..46964738 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/SecurityProperties.java +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/SecurityProperties.java @@ -13,9 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baiye.modules.security.config.bean; +package com.baiye.properties; -import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; /** * Jwt参数配置 @@ -23,7 +26,10 @@ import lombok.Data; * @author Zheng Jie * @date 2019年11月28日 */ -@Data +@Getter +@Setter +@Component +@ConfigurationProperties(prefix = "jwt") public class SecurityProperties { /** diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginCode.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginCode.java similarity index 96% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginCode.java rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginCode.java index ea1b9bd6..c4613b82 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginCode.java +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginCode.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baiye.modules.security.config.bean; +package com.baiye.properties.bean; import lombok.Data; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginCodeEnum.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginCodeEnum.java similarity index 95% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginCodeEnum.java rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginCodeEnum.java index 8e886c75..57c63eb6 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginCodeEnum.java +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginCodeEnum.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baiye.modules.security.config.bean; +package com.baiye.properties.bean; /** * 验证码配置枚举 diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginProperties.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginProperties.java similarity index 84% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginProperties.java rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginProperties.java index f85699a9..6d3b06e1 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginProperties.java +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginProperties.java @@ -1,19 +1,4 @@ -/* - * Copyright 2019-2020 the original author or authors. - * - * Licensed under the Apache License, Version loginCode.length.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-loginCode.length.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baiye.modules.security.config.bean; +package com.baiye.properties.bean; import com.baiye.exception.BadConfigurationException; import com.wf.captcha.*; diff --git a/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/DefaultHandshakeHandler.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/DefaultHandshakeHandler.java new file mode 100644 index 00000000..7f4a06a6 --- /dev/null +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/DefaultHandshakeHandler.java @@ -0,0 +1,49 @@ +package com.baiye.security; + +import com.baiye.constant.SecurityConstants; +import com.baiye.security.TokenProvider; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.http.server.ServerHttpRequest; +import org.springframework.http.server.ServerHttpResponse; +import org.springframework.http.server.ServletServerHttpRequest; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; +import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.server.HandshakeInterceptor; + +import java.util.Map; + +/** + * @author Enzo + * @date : 2022/1/12 + */ +@Slf4j +@Component +@RequiredArgsConstructor +class PrincipalHandshakeHandler implements HandshakeInterceptor { + private final TokenProvider tokenProvider; + + + @Override + public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map attributes) throws Exception { + ServletServerHttpRequest serverHttpRequest = (ServletServerHttpRequest) request; + + //获取参数 + String token = serverHttpRequest.getServletRequest().getParameter(SecurityConstants.AUTHORIZATION); + attributes.put("token", token); + if (StringUtils.isNotBlank(token)) { + Authentication authentication = tokenProvider.getAuthentication(token); + SecurityContextHolder.getContext().setAuthentication(authentication); + return Boolean.TRUE; + } + return Boolean.FALSE; + } + + @Override + public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) { + + } +} diff --git a/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/SocketTokenFilter.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/SocketTokenFilter.java new file mode 100644 index 00000000..c34835bb --- /dev/null +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/SocketTokenFilter.java @@ -0,0 +1,108 @@ +package com.baiye.security; + +import com.baiye.properties.SecurityProperties; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; +import reactor.util.annotation.NonNull; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.*; + +/** + * @author Enzo + * @date : 2022/1/11 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class SocketTokenFilter extends OncePerRequestFilter { + + private final SecurityProperties securityProperties; + + private final TokenProvider tokenProvider; + + + @Override + protected void doFilterInternal(HttpServletRequest request, @NonNull HttpServletResponse httpServletResponse, @NonNull FilterChain filterChain) + throws ServletException, IOException { + // http连接时,客户端应该是在头信息中携带令牌 + String authorizationHeader = request.getHeader(securityProperties.getHeader()); + if (StringUtils.isBlank(authorizationHeader)) { + // websocket连接时,令牌放在url参数上,以后重构 + authorizationHeader = request.getParameter(securityProperties.getHeader()); + } + + + String token = null; + if (!StringUtils.isEmpty(authorizationHeader) && authorizationHeader.startsWith(securityProperties.getTokenStartWith())) { + token = authorizationHeader.replace(securityProperties.getTokenStartWith(), ""); + } + //验证token + if (StringUtils.isNotBlank(token)) { + Authentication authentication = tokenProvider.getAuthentication(token); + SecurityContextHolder.getContext().setAuthentication(authentication); + // TODO 修改权限传递token + /* TokenFilter.ModifyParametersWrapper mParametersWrapper = new TokenFilter.ModifyParametersWrapper((HttpServletRequest) request); + mParametersWrapper.putHeader(SecurityConstants.AUTHORIZATION, authorizationHeader); + filterChain.doFilter(mParametersWrapper, httpServletResponse);*/ + log.debug("set Authentication to security context for '{}', uri: {}", authentication.getName(), request.getRequestURI()); + } + filterChain.doFilter(request, httpServletResponse); + } + + + /** + * 继承HttpServletRequestWrapper,创建装饰类,以达到修改HttpServletRequest参数的目的 + */ + private static class ModifyParametersWrapper extends HttpServletRequestWrapper { + private final Map customHeaders; + + ModifyParametersWrapper(HttpServletRequest request) { + super(request); + this.customHeaders = new HashMap<>(); + } + + void putHeader(String name, String value) { + this.customHeaders.put(name, value); + } + + @Override + public String getHeader(String name) { + // check the custom headers first + String headerValue = customHeaders.get(name); + + if (headerValue != null) { + return headerValue; + } + // else return from into the original wrapped object + return ((HttpServletRequest) getRequest()).getHeader(name); + } + + @Override + public Enumeration getHeaderNames() { + // create a set of the custom header names + Set set = new HashSet<>(customHeaders.keySet()); + + // now add the headers from the wrapped request object + Enumeration e = ((HttpServletRequest) getRequest()).getHeaderNames(); + while (e.hasMoreElements()) { + // add the names of the request headers into the list + String n = e.nextElement(); + set.add(n); + } + + // create an enumeration from the set and return + return Collections.enumeration(set); + } + } +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenProvider.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/TokenProvider.java similarity index 94% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenProvider.java rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/TokenProvider.java index b03ba6c5..66386913 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenProvider.java +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/TokenProvider.java @@ -13,18 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baiye.modules.security.security; +package com.baiye.security; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; -import com.baiye.modules.security.config.bean.SecurityProperties; +import com.baiye.properties.SecurityProperties; import com.baiye.util.RedisUtils; import io.jsonwebtoken.*; import io.jsonwebtoken.io.Decoders; import io.jsonwebtoken.security.Keys; import lombok.extern.slf4j.Slf4j; - import org.springframework.beans.factory.InitializingBean; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; @@ -88,7 +87,7 @@ public class TokenProvider implements InitializingBean { * @param token / * @return / */ - Authentication getAuthentication(String token) { + public Authentication getAuthentication(String token) { Claims claims = getClaims(token); User principal = new User(claims.getSubject(), "******", new ArrayList<>()); return new UsernamePasswordAuthenticationToken(principal, token, new ArrayList<>()); @@ -103,7 +102,7 @@ public class TokenProvider implements InitializingBean { /** * @param token 需要检查的token */ - public void checkRenewal(String token) { + public boolean checkRenewal(String token) { // 判断是否续期token,计算token的过期时间 long time = redisUtils.getExpire(properties.getOnlineKey() + token) * 1000; Date expireDate = DateUtil.offset(new Date(), DateField.MILLISECOND, (int) time); @@ -113,7 +112,9 @@ public class TokenProvider implements InitializingBean { if (differ <= properties.getDetect()) { long renew = time + properties.getRenew(); redisUtils.expire(properties.getOnlineKey() + token, renew, TimeUnit.MILLISECONDS); + return true; } + return false; } public String getToken(HttpServletRequest request) { diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/UserCacheClean.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/service/UserCacheClean.java similarity index 97% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/UserCacheClean.java rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/service/UserCacheClean.java index 57d8d720..68a1397d 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/UserCacheClean.java +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/service/UserCacheClean.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.baiye.modules.security.service; +package com.baiye.service; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/UserDetailsServiceImpl.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/service/UserDetailsServiceImpl.java similarity index 81% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/UserDetailsServiceImpl.java rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/service/UserDetailsServiceImpl.java index 36550e55..16c3060c 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/UserDetailsServiceImpl.java +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/service/UserDetailsServiceImpl.java @@ -13,16 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baiye.modules.security.service; +package com.baiye.service; import com.baiye.exception.BadRequestException; -import com.baiye.modules.security.config.bean.LoginProperties; -import com.baiye.modules.security.service.dto.JwtUserDto; -import com.baiye.modules.system.service.DataService; -import com.baiye.modules.system.service.RoleService; -import com.baiye.modules.system.service.UserService; -import com.baiye.modules.system.service.dto.UserDto; +import com.baiye.feign.RemoteUserService; +import com.baiye.model.dto.JwtUserDto; +import com.baiye.model.dto.UserDto; +import com.baiye.properties.bean.LoginProperties; import lombok.RequiredArgsConstructor; +import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; @@ -30,8 +29,10 @@ import org.springframework.stereotype.Service; import javax.persistence.EntityNotFoundException; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; /** * @author Zheng Jie @@ -40,9 +41,10 @@ import java.util.concurrent.atomic.AtomicInteger; @RequiredArgsConstructor @Service("userDetailsService") public class UserDetailsServiceImpl implements UserDetailsService { - private final UserService userService; - private final RoleService roleService; - private final DataService dataService; + + + private final RemoteUserService remoteUserService; + private final LoginProperties loginProperties; public void setEnableCache(boolean enableCache) { @@ -51,10 +53,7 @@ public class UserDetailsServiceImpl implements UserDetailsService { /** * 用户信息缓存 - * - * @see {@link UserCacheClean} */ - static final Map> USER_DTO_CACHE = new ConcurrentHashMap<>(); public static ExecutorService executor = newThreadPool(); @@ -66,7 +65,7 @@ public class UserDetailsServiceImpl implements UserDetailsService { if (!loginProperties.isCacheEnable()) { UserDto user; try { - user = userService.findByName(username); + user = remoteUserService.findByName(username); } catch (EntityNotFoundException e) { // SpringSecurity会自动转换UsernameNotFoundException为BadCredentialsException throw new UsernameNotFoundException("", e); @@ -77,10 +76,13 @@ public class UserDetailsServiceImpl implements UserDetailsService { if (!user.getEnabled()) { throw new BadRequestException("账号未激活!"); } + Set strings = remoteUserService.mapToGrantedAuthorities(user); + jwtUserDto = new JwtUserDto( user, - dataService.getDeptIds(user), - roleService.mapToGrantedAuthorities(user) + remoteUserService.getDeptIds(user), + strings.stream().map(SimpleGrantedAuthority::new) + .collect(Collectors.toList()) ); } return jwtUserDto; @@ -110,7 +112,7 @@ public class UserDetailsServiceImpl implements UserDetailsService { // 检查dataScope是否修改 List dataScopes = jwtUserDto.getDataScopes(); dataScopes.clear(); - dataScopes.addAll(dataService.getDeptIds(jwtUserDto.getUser())); + dataScopes.addAll(remoteUserService.getDeptIds(jwtUserDto.getUser())); } return jwtUserDto; @@ -120,7 +122,7 @@ public class UserDetailsServiceImpl implements UserDetailsService { private JwtUserDto getJwtBySearchDb(String username) { UserDto user; try { - user = userService.findByName(username); + user = remoteUserService.findByName(username); } catch (EntityNotFoundException e) { // SpringSecurity会自动转换UsernameNotFoundException为BadCredentialsException throw new UsernameNotFoundException("", e); @@ -131,13 +133,13 @@ public class UserDetailsServiceImpl implements UserDetailsService { if (!user.getEnabled()) { throw new BadRequestException("账号未激活!"); } + Set strings = remoteUserService.mapToGrantedAuthorities(user); return new JwtUserDto( - user, - dataService.getDeptIds(user), - roleService.mapToGrantedAuthorities(user) + user, remoteUserService.getDeptIds(user), + strings.stream().map(SimpleGrantedAuthority::new) + .collect(Collectors.toList()) ); } - } public static ExecutorService newThreadPool() { diff --git a/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/util/AdUser.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/util/AdUser.java new file mode 100644 index 00000000..cf3aef73 --- /dev/null +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/util/AdUser.java @@ -0,0 +1,57 @@ +package com.baiye.util; + +import lombok.Getter; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.User; + +import java.util.Collection; + +/** + * @author Enzo + * @date : 2022/1/11 + */ +public class AdUser extends User { + + private static final long serialVersionUID = -66600042157219036L; + /** + * 用户ID + */ + @Getter + private final Integer id; + + /** + * 部门ID + */ + @Getter + private final Integer deptId; + + + /** + * Construct the User with the details required by + * {@link DaoAuthenticationProvider}. + * @param id 用户ID + * @param deptId 部门ID + * @param username the username presented to the + * DaoAuthenticationProvider + * @param password the password that should be presented to the + * DaoAuthenticationProvider + * @param enabled set to true if the user is enabled + * @param accountNonExpired set to true if the account has not expired + * @param credentialsNonExpired set to true if the credentials have not + * expired + * @param accountNonLocked set to true if the account is not locked + * @param authorities the authorities that should be granted to the caller if they + * presented the correct username and password and the user is enabled. Not null. + * @throws IllegalArgumentException if a null value was passed either as + * a parameter or as an element in the GrantedAuthority collection + */ + public AdUser(Integer id, Integer deptId, String username, String password, boolean enabled, + boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, + Collection authorities) { + super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); + this.id = id; + this.deptId = deptId; + } + + +} diff --git a/ad-platform-common/src/main/java/com/baiye/util/SecurityUtils.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/util/SecurityUtils.java similarity index 92% rename from ad-platform-common/src/main/java/com/baiye/util/SecurityUtils.java rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/util/SecurityUtils.java index 51d5068e..afe25220 100644 --- a/ad-platform-common/src/main/java/com/baiye/util/SecurityUtils.java +++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/util/SecurityUtils.java @@ -20,6 +20,7 @@ import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.baiye.exception.BadRequestException; +import com.baiye.model.dto.JwtUserDto; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.security.core.Authentication; @@ -31,14 +32,19 @@ import java.util.List; /** * 获取当前登录的用户 + * * @author Zheng Jie * @date 2019-01-17 */ @Slf4j public class SecurityUtils { + private SecurityUtils() { + } + /** * 获取当前登录的用户 + * * @return UserDetails */ public static UserDetails getCurrentUser() { @@ -70,6 +76,7 @@ public class SecurityUtils { /** * 获取系统用户ID + * * @return 系统用户ID */ public static Long getCurrentUserId() { @@ -79,20 +86,23 @@ public class SecurityUtils { /** * 获取当前用户的数据权限 + * * @return / */ - public static List getCurrentUserDataScope(){ + public static List getCurrentUserDataScope() { UserDetails userDetails = getCurrentUser(); JSONArray array = JSONUtil.parseArray(new JSONObject(userDetails).get("dataScopes")); - return JSONUtil.toList(array,Long.class); + return JSONUtil.toList(array, Long.class); } + /** * 获取数据权限级别 + * * @return 级别 */ public static String getDataScopeType() { List dataScopes = getCurrentUserDataScope(); - if(dataScopes.size() != 0){ + if (dataScopes.size() != 0) { return ""; } return "全部的数据权限"; @@ -100,9 +110,10 @@ public class SecurityUtils { /** * 获取用户 + * * @return 用户 */ - public static JSONObject getUser(){ + public static JSONObject getUser() { UserDetails userDetails = getCurrentUser(); return new JSONObject(new JSONObject(userDetails).get("user")); } diff --git a/ad-platform-common/ad-platform-common-auth/src/main/resources/bootstrap.yml b/ad-platform-common/ad-platform-common-auth/src/main/resources/bootstrap.yml new file mode 100644 index 00000000..2c37c29b --- /dev/null +++ b/ad-platform-common/ad-platform-common-auth/src/main/resources/bootstrap.yml @@ -0,0 +1,17 @@ +#jwt +jwt: + header: Authorization + # 令牌前缀 + token-start-with: Bearer + # 必须使用最少88位的Base64对该令牌进行编码 + base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI= + # 令牌过期时间 此处单位/毫秒 ,默认2小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html + token-validity-in-seconds: 7200000 + # 在线用户key + online-key: online-token- + # 验证码 + code-key: code-key- + # token 续期检查时间范围(默认30分钟,单位默认毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期 + detect: 1800000 + # 续期时间范围,默认 1小时,这里单位毫秒 + renew: 3600000 diff --git a/ad-platform-common/pom.xml b/ad-platform-common/ad-platform-common-core/pom.xml similarity index 74% rename from ad-platform-common/pom.xml rename to ad-platform-common/ad-platform-common-core/pom.xml index b53c3293..3e3c6442 100644 --- a/ad-platform-common/pom.xml +++ b/ad-platform-common/ad-platform-common-core/pom.xml @@ -1,22 +1,21 @@ - + + ad-platform com.baiye 1.0-SNAPSHOT - ../pom.xml + ../../pom.xml 4.0.0 - - ad-platform-common - + ad-platform-common-core + ad-platform-comm-core + ad-platform-common-core 8 8 - com.dangdang @@ -29,33 +28,13 @@ + org.springframework.boot spring-boot-starter-web - - - - org.projectlombok lombok @@ -122,8 +101,8 @@ org.springframework.security spring-security-web + - diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/AnonymousAccess.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/AnonymousAccess.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/annotation/AnonymousAccess.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/AnonymousAccess.java diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/DataPermission.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/DataPermission.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/annotation/DataPermission.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/DataPermission.java diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/Inner.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/Inner.java new file mode 100644 index 00000000..22c0e640 --- /dev/null +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/Inner.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 pig4cloud Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.baiye.annotation; + +import java.lang.annotation.*; + +/** + * 服务调用不鉴权注解 + * + * @author lengleng + * @date 2020-06-14 + */ +@Target({ ElementType.METHOD, ElementType.TYPE }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface Inner { + + /** + * 是否AOP统一处理 + * @return false, true + */ + boolean value() default true; + + /** + * 需要特殊判空的字段(预留) + * @return {} + */ + String[] field() default {}; + +} diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/Query.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/Query.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/annotation/Query.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/Query.java diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousDeleteMapping.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousDeleteMapping.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousDeleteMapping.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousDeleteMapping.java diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousGetMapping.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousGetMapping.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousGetMapping.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousGetMapping.java diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousPatchMapping.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousPatchMapping.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousPatchMapping.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousPatchMapping.java diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousPostMapping.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousPostMapping.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousPostMapping.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousPostMapping.java diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousPutMapping.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousPutMapping.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousPutMapping.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousPutMapping.java diff --git a/ad-platform-common/src/main/java/com/baiye/config/RedisCacheConfig.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/config/RedisCacheConfig.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/config/RedisCacheConfig.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/config/RedisCacheConfig.java diff --git a/ad-platform-common/src/main/java/com/baiye/config/SimpleGrantedAuthorityDeserializer.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/config/SimpleGrantedAuthorityDeserializer.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/config/SimpleGrantedAuthorityDeserializer.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/config/SimpleGrantedAuthorityDeserializer.java diff --git a/ad-platform-common/src/main/java/com/baiye/constant/DefaultNumberConstants.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java similarity index 96% rename from ad-platform-common/src/main/java/com/baiye/constant/DefaultNumberConstants.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java index 6927e7e9..6486ccad 100644 --- a/ad-platform-common/src/main/java/com/baiye/constant/DefaultNumberConstants.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java @@ -11,6 +11,10 @@ public class DefaultNumberConstants { private DefaultNumberConstants() { } + /** + * -2 + */ + public static final int MINUS_TWO_NUMBER = -2; /** * -1 diff --git a/ad-platform-common/src/main/java/com/baiye/constant/ElAdminConstant.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/ElAdminConstant.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/constant/ElAdminConstant.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/ElAdminConstant.java diff --git a/ad-platform-common/src/main/java/com/baiye/constant/RoleNumberConstants.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/RoleNumberConstants.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/constant/RoleNumberConstants.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/RoleNumberConstants.java diff --git a/ad-platform-common/src/main/java/com/baiye/constant/SecurityConstants.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/SecurityConstants.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/constant/SecurityConstants.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/SecurityConstants.java diff --git a/ad-platform-common/src/main/java/com/baiye/exception/BadConfigurationException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/BadConfigurationException.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/exception/BadConfigurationException.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/BadConfigurationException.java diff --git a/ad-platform-common/src/main/java/com/baiye/exception/BadRequestException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/BadRequestException.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/exception/BadRequestException.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/BadRequestException.java diff --git a/ad-platform-common/src/main/java/com/baiye/exception/CallException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/CallException.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/exception/CallException.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/CallException.java diff --git a/ad-platform-common/src/main/java/com/baiye/exception/CheckedException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/CheckedException.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/exception/CheckedException.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/CheckedException.java diff --git a/ad-platform-common/src/main/java/com/baiye/exception/ElasticException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/ElasticException.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/exception/ElasticException.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/ElasticException.java diff --git a/ad-platform-common/src/main/java/com/baiye/exception/EntityExistException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/EntityExistException.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/exception/EntityExistException.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/EntityExistException.java diff --git a/ad-platform-common/src/main/java/com/baiye/exception/EntityNotFoundException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/EntityNotFoundException.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/exception/EntityNotFoundException.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/EntityNotFoundException.java diff --git a/ad-platform-common/src/main/java/com/baiye/exception/handler/ApiError.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/handler/ApiError.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/exception/handler/ApiError.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/handler/ApiError.java diff --git a/ad-platform-common/src/main/java/com/baiye/exception/handler/GlobalExceptionHandler.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/handler/GlobalExceptionHandler.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/exception/handler/GlobalExceptionHandler.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/handler/GlobalExceptionHandler.java diff --git a/ad-platform-common/src/main/java/com/baiye/http/CommonResponse.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CommonResponse.java similarity index 98% rename from ad-platform-common/src/main/java/com/baiye/http/CommonResponse.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CommonResponse.java index b959e42f..74687ead 100644 --- a/ad-platform-common/src/main/java/com/baiye/http/CommonResponse.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CommonResponse.java @@ -1,5 +1,6 @@ package com.baiye.http; +import cn.hutool.http.HttpStatus; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import lombok.Getter; diff --git a/ad-platform-common/src/main/java/com/baiye/http/ResponseCode.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/ResponseCode.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/http/ResponseCode.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/ResponseCode.java diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/WebSocketResponse.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/WebSocketResponse.java new file mode 100644 index 00000000..039c33de --- /dev/null +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/WebSocketResponse.java @@ -0,0 +1,119 @@ +package com.baiye.http; + +import cn.hutool.http.HttpStatus; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + + +/** + * @author + * 属性为 空("") 或者为 NULL 都不序列化,则返回的json是没有这个字段的。这样对移动端会更省流量 + * @param + */ +@JsonSerialize +@Getter +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@NoArgsConstructor +public class WebSocketResponse implements Serializable { + + + private static final long serialVersionUID = -7237947628886320124L; + + /** + * 成功还是失败的状态标识 0,成功 1,失败 + */ + private int code; + + /** + * 返回信息 + */ + private String type; + + /** + * 返回的结果数据 + */ + private T data; + + + /* + 封装所有的构造器为私有的 + */ + + private WebSocketResponse(String type) { + this.type = type; + } + + private WebSocketResponse(String type, T data) { // ps: 当调用T为String类型时候,会默认调用下面的ServerResponse(int status, String msg)类型的构造器 + this.type = type; + this.data = data; + } + + private WebSocketResponse(String type, Integer code, T data) { + this.type = type; + this.code = code; + this.data = data; + } + + private WebSocketResponse(String type, Integer code) { + this.type = type; + this.code = code; + } + + /* + 对外开放调用的静态方法,用来调用私有构造器,来返回成功结果给前台 + */ + + /** + * 返回成功码和默认的成功信息 + */ + public static WebSocketResponse createBySuccess() { + return new WebSocketResponse<>(ResponseCode.SUCCESS.getDesc(),HttpStatus.HTTP_OK); + } + + /** + * 返回成功码和默认的成功信息 + */ + public static WebSocketResponse createBySuccess(String type) { + return new WebSocketResponse<>(type,HttpStatus.HTTP_OK); + } + + + + /** + * 返回成功码和数据 + */ + public static WebSocketResponse createBySuccess(String type,T data) { + return new WebSocketResponse<>(type, HttpStatus.HTTP_OK, data); + } + + /** + * 返回成功码和成功信息和数据 + */ + public static WebSocketResponse createBySuccess(String type,Integer code, T data) { + return new WebSocketResponse<>(type, code, data); + } + + /* + 对外开放调用的静态方法,用来调用私有构造器,来返回失败结果给前台 + */ + + + + /** + * 返回错误码和错误信息(传入) + */ + public static WebSocketResponse createByErrorMessage(String errorMessage){ + return new WebSocketResponse<>(errorMessage, ResponseCode.ERROR.getCode()); + } + + /** + * 返回错误码(传入)和错误信息(传入) + */ + public static WebSocketResponse createByErrorCodeMessage(String type, Integer code){ + return new WebSocketResponse<>(type, code); + } +} diff --git a/ad-platform-common/src/main/java/com/baiye/feign/FeignConfiguration.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/socket/filter/FeignConfiguration.java similarity index 77% rename from ad-platform-common/src/main/java/com/baiye/feign/FeignConfiguration.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/socket/filter/FeignConfiguration.java index e2adab58..d3a83a29 100644 --- a/ad-platform-common/src/main/java/com/baiye/feign/FeignConfiguration.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/socket/filter/FeignConfiguration.java @@ -1,8 +1,6 @@ -package com.baiye.feign; +package com.baiye.socket.filter; import com.baiye.constant.SecurityConstants; -import com.baiye.exception.CallException; -import com.baiye.http.ResponseCode; import feign.RequestInterceptor; import feign.RequestTemplate; import lombok.extern.slf4j.Slf4j; @@ -24,11 +22,10 @@ public class FeignConfiguration implements RequestInterceptor { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); if (attributes != null) { HttpServletRequest request = attributes.getRequest(); - String uri = request.getRequestURI(); // HeaderConstants.TOKEN_HEADER_NAME 替换为自己的请求头名称,下同 String token = request.getHeader(SecurityConstants.AUTHORIZATION); - if (token == null && !FeignProvider.getDefaultSkipUrl().contains(uri)) { - throw new CallException(ResponseCode.ILLEGAL_ARGUMENT.getDesc()); + if (token == null) { + token = request.getParameter(SecurityConstants.AUTHORIZATION); } requestTemplate.header(SecurityConstants.AUTHORIZATION, token); } diff --git a/ad-platform-common/src/main/java/com/baiye/feign/FeignProvider.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/socket/filter/FeignProvider.java similarity index 66% rename from ad-platform-common/src/main/java/com/baiye/feign/FeignProvider.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/socket/filter/FeignProvider.java index 02ac8fa6..b6e01cda 100644 --- a/ad-platform-common/src/main/java/com/baiye/feign/FeignProvider.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/socket/filter/FeignProvider.java @@ -1,4 +1,4 @@ -package com.baiye.feign; +package com.baiye.socket.filter; import java.util.ArrayList; @@ -15,6 +15,9 @@ public class FeignProvider { static { DEFAULT_SKIP_URL.add("/swagger/**"); + DEFAULT_SKIP_URL.add("/api/users/user/findByName"); + DEFAULT_SKIP_URL.add("/api/users/user/findByName"); + DEFAULT_SKIP_URL.add("/api/roles/user/authority"); } diff --git a/ad-platform-common/src/main/java/com/baiye/util/AESUtils.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/AESUtils.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/util/AESUtils.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/AESUtils.java diff --git a/ad-platform-common/src/main/java/com/baiye/util/CacheKey.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/CacheKey.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/util/CacheKey.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/CacheKey.java diff --git a/ad-platform-common/src/main/java/com/baiye/util/CallBack.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/CallBack.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/util/CallBack.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/CallBack.java diff --git a/ad-platform-common/src/main/java/com/baiye/util/ClassUtils.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/ClassUtils.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/util/ClassUtils.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/ClassUtils.java diff --git a/ad-platform-common/src/main/java/com/baiye/util/EncryptUtils.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/EncryptUtils.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/util/EncryptUtils.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/EncryptUtils.java diff --git a/ad-platform-common/src/main/java/com/baiye/util/FileUtil.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/FileUtil.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/util/FileUtil.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/FileUtil.java diff --git a/ad-platform-common/src/main/java/com/baiye/util/JpaConverterAes.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/JpaConverterAes.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/util/JpaConverterAes.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/JpaConverterAes.java diff --git a/ad-platform-common/src/main/java/com/baiye/util/JpaConverterListJson.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/JpaConverterListJson.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/util/JpaConverterListJson.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/JpaConverterListJson.java diff --git a/ad-platform-common/src/main/java/com/baiye/util/PageUtil.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/PageUtil.java similarity index 91% rename from ad-platform-common/src/main/java/com/baiye/util/PageUtil.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/PageUtil.java index 31ba5a50..d636769a 100644 --- a/ad-platform-common/src/main/java/com/baiye/util/PageUtil.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/PageUtil.java @@ -32,11 +32,11 @@ public class PageUtil extends cn.hutool.core.util.PageUtil { /** * List 分页 */ - public static List toPage(int page, int size , List list) { + public static List toPage(int page, int size , List list) { int fromIndex = page * size; int toIndex = page * size + size; if(fromIndex > list.size()){ - return new ArrayList(); + return new ArrayList<>(); } else if(toIndex >= list.size()) { return list.subList(fromIndex,list.size()); } else { @@ -47,7 +47,7 @@ public class PageUtil extends cn.hutool.core.util.PageUtil { /** * Page 数据处理,预防redis反序列化报错 */ - public static Map toPage(Page page) { + public static Map toPage(Page page) { Map map = new LinkedHashMap<>(2); map.put("content",page.getContent()); map.put("totalElements",page.getTotalElements()); diff --git a/ad-platform-common/src/main/java/com/baiye/util/RedisUtils.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/RedisUtils.java similarity index 99% rename from ad-platform-common/src/main/java/com/baiye/util/RedisUtils.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/RedisUtils.java index 258e19a8..6256c3e5 100644 --- a/ad-platform-common/src/main/java/com/baiye/util/RedisUtils.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/RedisUtils.java @@ -43,8 +43,6 @@ public class RedisUtils { private RedisTemplate redisTemplate; - - private String onlineKey = "online-token-"; diff --git a/ad-platform-common/src/main/java/com/baiye/util/RsaUtils.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/RsaUtils.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/util/RsaUtils.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/RsaUtils.java diff --git a/ad-platform-common/src/main/java/com/baiye/util/SpringContextHolder.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/SpringContextHolder.java similarity index 96% rename from ad-platform-common/src/main/java/com/baiye/util/SpringContextHolder.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/SpringContextHolder.java index 0b67cca6..d889526d 100644 --- a/ad-platform-common/src/main/java/com/baiye/util/SpringContextHolder.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/SpringContextHolder.java @@ -20,7 +20,9 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.DisposableBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Lazy; import org.springframework.core.env.Environment; +import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; @@ -30,6 +32,8 @@ import java.util.List; * @date 2019-01-07 */ @Slf4j +@Service +@Lazy(false) public class SpringContextHolder implements ApplicationContextAware, DisposableBean { private static ApplicationContext applicationContext = null; @@ -42,7 +46,7 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB * * @param callBack 回调函数 */ - public synchronized static void addCallBacks(CallBack callBack) { + public static synchronized void addCallBacks(CallBack callBack) { if (addCallback) { SpringContextHolder.CALL_BACKS.add(callBack); } else { diff --git a/ad-platform-common/src/main/java/com/baiye/util/ValidationUtil.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/ValidationUtil.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/util/ValidationUtil.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/ValidationUtil.java diff --git a/ad-platform-common/src/main/java/com/baiye/util/WebUtils.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/WebUtils.java similarity index 100% rename from ad-platform-common/src/main/java/com/baiye/util/WebUtils.java rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/WebUtils.java diff --git a/ad-platform-common/file/log4j2-spring.xml b/ad-platform-common/file/log4j2-spring.xml deleted file mode 100644 index 2bb0f34d..00000000 --- a/ad-platform-common/file/log4j2-spring.xml +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ad-platform-gateway/pom.xml b/ad-platform-gateway/pom.xml index b1bf9b2b..6b739734 100644 --- a/ad-platform-gateway/pom.xml +++ b/ad-platform-gateway/pom.xml @@ -21,7 +21,7 @@ com.baiye - ad-platform-common + ad-platform-common-core 1.0-SNAPSHOT diff --git a/ad-platform-gateway/src/main/java/com/baiye/config/GatewayConfiguration.java b/ad-platform-gateway/src/main/java/com/baiye/config/GatewayConfiguration.java index fded1e0f..350b860a 100644 --- a/ad-platform-gateway/src/main/java/com/baiye/config/GatewayConfiguration.java +++ b/ad-platform-gateway/src/main/java/com/baiye/config/GatewayConfiguration.java @@ -1,7 +1,7 @@ package com.baiye.config; -import com.baiye.filter.PasswordDecoderFilter; -import com.baiye.filter.ValidateCodeGatewayFilter; +import com.baiye.socket.filter.PasswordDecoderFilter; +import com.baiye.socket.filter.ValidateCodeGatewayFilter; import com.baiye.handler.GlobalGateWayExceptionHandler; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.boot.context.properties.EnableConfigurationProperties; diff --git a/ad-platform-gateway/src/main/java/com/baiye/filter/ApiLoggingFilter.java b/ad-platform-gateway/src/main/java/com/baiye/socket/filter/ApiLoggingFilter.java similarity index 98% rename from ad-platform-gateway/src/main/java/com/baiye/filter/ApiLoggingFilter.java rename to ad-platform-gateway/src/main/java/com/baiye/socket/filter/ApiLoggingFilter.java index e40b28c4..756cb343 100644 --- a/ad-platform-gateway/src/main/java/com/baiye/filter/ApiLoggingFilter.java +++ b/ad-platform-gateway/src/main/java/com/baiye/socket/filter/ApiLoggingFilter.java @@ -1,4 +1,4 @@ -package com.baiye.filter; +package com.baiye.socket.filter; import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.gateway.filter.GatewayFilterChain; diff --git a/ad-platform-gateway/src/main/java/com/baiye/filter/PasswordDecoderFilter.java b/ad-platform-gateway/src/main/java/com/baiye/socket/filter/PasswordDecoderFilter.java similarity index 99% rename from ad-platform-gateway/src/main/java/com/baiye/filter/PasswordDecoderFilter.java rename to ad-platform-gateway/src/main/java/com/baiye/socket/filter/PasswordDecoderFilter.java index 070d957a..db69ef51 100644 --- a/ad-platform-gateway/src/main/java/com/baiye/filter/PasswordDecoderFilter.java +++ b/ad-platform-gateway/src/main/java/com/baiye/socket/filter/PasswordDecoderFilter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.baiye.filter; +package com.baiye.socket.filter; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.StrUtil; diff --git a/ad-platform-gateway/src/main/java/com/baiye/filter/ValidateCodeGatewayFilter.java b/ad-platform-gateway/src/main/java/com/baiye/socket/filter/ValidateCodeGatewayFilter.java similarity index 99% rename from ad-platform-gateway/src/main/java/com/baiye/filter/ValidateCodeGatewayFilter.java rename to ad-platform-gateway/src/main/java/com/baiye/socket/filter/ValidateCodeGatewayFilter.java index 7e698288..39758da7 100644 --- a/ad-platform-gateway/src/main/java/com/baiye/filter/ValidateCodeGatewayFilter.java +++ b/ad-platform-gateway/src/main/java/com/baiye/socket/filter/ValidateCodeGatewayFilter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.baiye.filter; +package com.baiye.socket.filter; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.util.StrUtil; diff --git a/ad-platform-gateway/src/main/resources/application.yml b/ad-platform-gateway/src/main/resources/application.yml index f98e09f2..f9dfadf7 100644 --- a/ad-platform-gateway/src/main/resources/application.yml +++ b/ad-platform-gateway/src/main/resources/application.yml @@ -45,3 +45,4 @@ hystrix: isolation: thread: timeoutInMilliseconds: 1000 + diff --git a/ad-platform-pojo/pom.xml b/ad-platform-pojo/pom.xml index 6e899e1a..46135343 100644 --- a/ad-platform-pojo/pom.xml +++ b/ad-platform-pojo/pom.xml @@ -20,7 +20,7 @@ com.baiye - ad-platform-common + ad-platform-common-core 1.0-SNAPSHOT @@ -56,12 +56,6 @@ spring-cloud-starter-alibaba-nacos-discovery - - - com.baiye - ad-platform-common - 1.0-SNAPSHOT - diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/DeptSmallDto.java b/ad-platform-pojo/src/main/java/com/baiye/model/dto/DeptSmallDto.java similarity index 94% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/DeptSmallDto.java rename to ad-platform-pojo/src/main/java/com/baiye/model/dto/DeptSmallDto.java index f1bd3d66..6addb6ec 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/DeptSmallDto.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/dto/DeptSmallDto.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baiye.modules.system.service.dto; +package com.baiye.model.dto; import lombok.Data; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/JobSmallDto.java b/ad-platform-pojo/src/main/java/com/baiye/model/dto/JobSmallDto.java similarity index 94% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/JobSmallDto.java rename to ad-platform-pojo/src/main/java/com/baiye/model/dto/JobSmallDto.java index 3b75e892..328c53d4 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/JobSmallDto.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/dto/JobSmallDto.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baiye.modules.system.service.dto; +package com.baiye.model.dto; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/dto/JwtUserDto.java b/ad-platform-pojo/src/main/java/com/baiye/model/dto/JwtUserDto.java similarity index 95% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/dto/JwtUserDto.java rename to ad-platform-pojo/src/main/java/com/baiye/model/dto/JwtUserDto.java index 2770a4e6..b1bf98fb 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/dto/JwtUserDto.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/dto/JwtUserDto.java @@ -14,14 +14,14 @@ * limitations under the License. */ -package com.baiye.modules.security.service.dto; +package com.baiye.model.dto; -import com.baiye.modules.system.service.dto.UserDto; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Getter; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; + import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -34,6 +34,8 @@ import java.util.stream.Collectors; @AllArgsConstructor public class JwtUserDto implements UserDetails { + private static final long serialVersionUID = -1054997179383048319L; + private final UserDto user; private final List dataScopes; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/dto/OnlineUserDto.java b/ad-platform-pojo/src/main/java/com/baiye/model/dto/OnlineUserDto.java similarity index 95% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/dto/OnlineUserDto.java rename to ad-platform-pojo/src/main/java/com/baiye/model/dto/OnlineUserDto.java index 863be4e5..5792cd18 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/dto/OnlineUserDto.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/dto/OnlineUserDto.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baiye.modules.security.service.dto; +package com.baiye.model.dto; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import java.io.Serializable; import java.util.Date; /** diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/RoleSmallDto.java b/ad-platform-pojo/src/main/java/com/baiye/model/dto/RoleSmallDto.java similarity index 94% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/RoleSmallDto.java rename to ad-platform-pojo/src/main/java/com/baiye/model/dto/RoleSmallDto.java index ef81f6d6..d939abad 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/RoleSmallDto.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/dto/RoleSmallDto.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baiye.modules.system.service.dto; +package com.baiye.model.dto; import lombok.Data; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserDto.java b/ad-platform-pojo/src/main/java/com/baiye/model/dto/UserDto.java similarity index 93% rename from manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserDto.java rename to ad-platform-pojo/src/main/java/com/baiye/model/dto/UserDto.java index a09dcb3d..4982cfa2 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserDto.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/dto/UserDto.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baiye.modules.system.service.dto; +package com.baiye.model.dto; import com.baiye.model.base.BaseDTO; import lombok.Getter; @@ -31,6 +31,8 @@ import java.util.Set; @Setter public class UserDto extends BaseDTO implements Serializable { + private static final long serialVersionUID = -8826058649124662423L; + private Long id; private Set roles; diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseClue.java b/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseClue.java index d8b62695..a8e3d1f6 100644 --- a/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseClue.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseClue.java @@ -1,7 +1,6 @@ package com.baiye.model.entity; import com.baiye.util.JpaConverterAes; -import com.baiye.util.JpaConverterListJson; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.hibernate.annotations.CreationTimestamp; @@ -10,7 +9,6 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; import java.io.Serializable; -import java.util.List; /** diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/enums/WebSocketEnums.java b/ad-platform-pojo/src/main/java/com/baiye/model/enums/WebSocketEnums.java index 7f7380b7..f199a15b 100644 --- a/ad-platform-pojo/src/main/java/com/baiye/model/enums/WebSocketEnums.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/enums/WebSocketEnums.java @@ -29,7 +29,7 @@ public enum WebSocketEnums { /** * 归档 */ - FILE(4, "file"), + FILE(4, "recovery"), /** * 新建 diff --git a/manage/ad-platform-management/pom.xml b/manage/ad-platform-management/pom.xml index e1e46956..14474459 100644 --- a/manage/ad-platform-management/pom.xml +++ b/manage/ad-platform-management/pom.xml @@ -27,9 +27,18 @@ com.baiye - ad-platform-common + ad-platform-common-core 1.0-SNAPSHOT + + + + + com.baiye + ad-platform-common-auth + 1.0-SNAPSHOT + + com.baiye ad-platform-pojo @@ -42,10 +51,7 @@ spring-boot-starter-websocket - - com.github.whvcse - easy-captcha - + @@ -53,21 +59,7 @@ spring-boot-starter-security - - - io.jsonwebtoken - jjwt-api - - - - io.jsonwebtoken - jjwt-impl - - - io.jsonwebtoken - jjwt-jackson - @@ -103,11 +95,7 @@ spring-cloud-starter-alibaba-nacos-discovery - - - org.springframework.cloud - spring-cloud-starter-openfeign - + com.spring4all swagger-spring-boot-starter diff --git a/manage/ad-platform-management/src/main/java/com/baiye/AdPlatformManagementApplication.java b/manage/ad-platform-management/src/main/java/com/baiye/AdPlatformManagementApplication.java index c90d40b7..a1088f79 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/AdPlatformManagementApplication.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/AdPlatformManagementApplication.java @@ -1,12 +1,10 @@ package com.baiye; -import com.baiye.util.SpringContextHolder; import com.spring4all.swagger.EnableSwagger2Doc; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; -import org.springframework.context.annotation.Bean; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; /** @@ -26,6 +24,6 @@ public class AdPlatformManagementApplication { SpringApplication.run(AdPlatformManagementApplication.class, args); } - @Bean - public SpringContextHolder springContextHolder() {return new SpringContextHolder();} + + } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/SpringSecurityConfig.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/SpringSecurityConfig.java index 7c7d1924..1577c88b 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/SpringSecurityConfig.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/SpringSecurityConfig.java @@ -17,13 +17,13 @@ package com.baiye.modules.security.config; import com.baiye.annotation.AnonymousAccess; import com.baiye.model.enums.RequestMethodEnum; -import com.baiye.modules.security.config.bean.SecurityProperties; import com.baiye.modules.security.security.JwtAccessDeniedHandler; import com.baiye.modules.security.security.JwtAuthenticationEntryPoint; import com.baiye.modules.security.security.TokenConfigurer; -import com.baiye.modules.security.security.TokenProvider; import com.baiye.modules.security.service.OnlineUserService; -import com.baiye.modules.security.service.UserCacheClean; +import com.baiye.service.UserCacheClean; +import com.baiye.properties.SecurityProperties; +import com.baiye.security.TokenProvider; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationContext; @@ -32,6 +32,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.core.GrantedAuthorityDefaults; @@ -122,14 +123,13 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers("/file/**").permitAll() // 阿里巴巴 druid .antMatchers("/druid/**").permitAll() - .antMatchers("/api/task/saveTask").permitAll() // 放行OPTIONS请求 .antMatchers(HttpMethod.OPTIONS, "/**").permitAll() // TODO 权限待测试 Enzo - .antMatchers("/api/task/saveTask").permitAll() - .antMatchers( "/api/users/admin").permitAll() - .antMatchers( "/api/task/query").permitAll() - .antMatchers( "/api/organize/queryAll").permitAll() + .antMatchers("/api/users/info/findByName").permitAll() + .antMatchers("/api/users/info/deptIds").permitAll() + .antMatchers("/api/roles/user/authority").permitAll() + .antMatchers( "/api/report/organize").permitAll() .antMatchers( "/api/download/task").permitAll() // 自定义匿名访问所有url放行:允许匿名和带Token访问,细腻化到每个 Request 类型 @@ -198,4 +198,11 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { anonymousUrls.put(RequestMethodEnum.ALL.getType(), all); return anonymousUrls; } + + @Override + public void configure(WebSecurity webSecurity){ + webSecurity.ignoring().antMatchers( + "/ws/**" + ); + } } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/rest/AuthorizationController.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/security/rest/AuthorizationController.java index fdcc465d..ce8dfc23 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/rest/AuthorizationController.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/security/rest/AuthorizationController.java @@ -21,13 +21,13 @@ import com.baiye.annotation.rest.AnonymousGetMapping; import com.baiye.annotation.rest.AnonymousPostMapping; import com.baiye.config.properties.RsaProperties; import com.baiye.exception.BadRequestException; -import com.baiye.modules.security.config.bean.LoginCodeEnum; -import com.baiye.modules.security.config.bean.LoginProperties; -import com.baiye.modules.security.config.bean.SecurityProperties; -import com.baiye.modules.security.security.TokenProvider; +import com.baiye.model.dto.JwtUserDto; import com.baiye.modules.security.service.OnlineUserService; import com.baiye.modules.security.service.dto.AuthUserDto; -import com.baiye.modules.security.service.dto.JwtUserDto; +import com.baiye.properties.SecurityProperties; +import com.baiye.properties.bean.LoginCodeEnum; +import com.baiye.properties.bean.LoginProperties; +import com.baiye.security.TokenProvider; import com.baiye.util.RedisUtils; import com.baiye.util.RsaUtils; import com.baiye.util.SecurityUtils; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenConfigurer.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenConfigurer.java index bc818fba..88f9850d 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenConfigurer.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenConfigurer.java @@ -15,9 +15,10 @@ */ package com.baiye.modules.security.security; -import com.baiye.modules.security.config.bean.SecurityProperties; import com.baiye.modules.security.service.OnlineUserService; -import com.baiye.modules.security.service.UserCacheClean; +import com.baiye.service.UserCacheClean; +import com.baiye.properties.SecurityProperties; +import com.baiye.security.TokenProvider; import lombok.RequiredArgsConstructor; import org.springframework.security.config.annotation.SecurityConfigurerAdapter; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenFilter.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenFilter.java index 1cdf4403..5fb50a38 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenFilter.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenFilter.java @@ -17,12 +17,12 @@ package com.baiye.modules.security.security; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.util.StrUtil; -import com.baiye.modules.security.config.bean.SecurityProperties; +import com.baiye.model.dto.OnlineUserDto; import com.baiye.modules.security.service.OnlineUserService; -import com.baiye.modules.security.service.UserCacheClean; -import com.baiye.modules.security.service.dto.OnlineUserDto; +import com.baiye.service.UserCacheClean; +import com.baiye.properties.SecurityProperties; +import com.baiye.security.TokenProvider; import io.jsonwebtoken.ExpiredJwtException; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.Authentication; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/OnlineUserService.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/OnlineUserService.java index 32a745aa..a185b497 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/OnlineUserService.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/OnlineUserService.java @@ -16,9 +16,9 @@ package com.baiye.modules.security.service; import cn.hutool.json.JSONUtil; -import com.baiye.modules.security.config.bean.SecurityProperties; -import com.baiye.modules.security.service.dto.JwtUserDto; -import com.baiye.modules.security.service.dto.OnlineUserDto; +import com.baiye.model.dto.JwtUserDto; +import com.baiye.model.dto.OnlineUserDto; +import com.baiye.properties.SecurityProperties; import com.baiye.util.*; import lombok.extern.slf4j.Slf4j; @@ -65,6 +65,7 @@ public class OnlineUserService { log.error(e.getMessage(),e); } redisUtils.set(properties.getOnlineKey() + token, onlineUserDto, properties.getTokenValidityInSeconds()/1000); + redisUtils.set(token, jwtUserDto.getUser().getId(), properties.getTokenValidityInSeconds()/1000); } /** diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/MessageNotification.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/MessageNotification.java index b8413021..bffaf52a 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/MessageNotification.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/MessageNotification.java @@ -22,6 +22,7 @@ import lombok.Data; import javax.persistence.*; import java.io.Serializable; +import java.sql.Date; import java.sql.Timestamp; /** @@ -68,13 +69,13 @@ public class MessageNotification implements Serializable { private Boolean isReuse; - @Column(name = "type") + @Column(name = "message_type") @ApiModelProperty(value = "类型 1公告 2自提醒") - private Integer type; + private Integer messageType; @Column(name = "point_time") @ApiModelProperty(value = "时间点") - private Integer pointTime; + private Date pointTime; @Column(name = "create_by") @ApiModelProperty(value = "创建者") diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/Organize.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/Organize.java index 3bd328b4..d709296f 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/Organize.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/Organize.java @@ -1,6 +1,6 @@ package com.baiye.modules.system.domain; -import com.baiye.modules.system.service.dto.UserDto; +import com.baiye.model.dto.UserDto; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import javax.persistence.*; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/UserMessage.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/UserMessage.java index 0b956f0c..53d36e28 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/UserMessage.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/UserMessage.java @@ -17,8 +17,14 @@ package com.baiye.modules.system.domain; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.copier.CopyOptions; +import cn.hutool.core.date.DatePattern; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; import java.io.Serializable; @@ -33,6 +39,7 @@ import java.sql.Timestamp; @Entity @Data @Table(name="tb_user_message") +@EntityListeners(AuditingEntityListener.class) public class UserMessage implements Serializable { private static final long serialVersionUID = -1582474376747148049L; @@ -47,13 +54,17 @@ public class UserMessage implements Serializable { @ApiModelProperty(value = "消息id") private Long messageId; - @Column(name = "type") + @Column(name = "message_type") + @ApiModelProperty(value = "消息类型") + private Integer messageType; + + @Column(name = "status") @ApiModelProperty(value = "消息状态") - private Integer type; + private Integer status; @Column(name = "is_read") @ApiModelProperty(value = "是否已读") - private Boolean isRead = Boolean.TRUE; + private Boolean isRead = Boolean.FALSE; @Column(name = "start_time") @ApiModelProperty(value = "开始时间") @@ -91,10 +102,13 @@ public class UserMessage implements Serializable { @ApiModelProperty(value = "更新者") private String updateBy; + @CreationTimestamp @Column(name = "create_time") @ApiModelProperty(value = "创建日期") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8") private Timestamp createTime; + @LastModifiedDate @Column(name = "update_time") @ApiModelProperty(value = "更新时间") private Timestamp updateTime; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/UserMessageRepository.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/UserMessageRepository.java index d75e67aa..83ae75f5 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/UserMessageRepository.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/UserMessageRepository.java @@ -16,6 +16,8 @@ package com.baiye.modules.system.repository; import com.baiye.modules.system.domain.UserMessage; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; @@ -36,8 +38,8 @@ public interface UserMessageRepository extends JpaRepository, * @return */ @Modifying - @Query(value = "update UserMessage set type = ?1 where messageId = ?2") - Boolean deleteUserMessageByMessageId(Integer num, Long messageId); + @Query(value = "update UserMessage set status = ?1 where messageId = ?2") + int deleteUserMessageByMessageId(Integer num, Long messageId); /** * 是否已读未读 @@ -47,5 +49,28 @@ public interface UserMessageRepository extends JpaRepository, */ @Modifying @Query(value = "update UserMessage set isRead = ?1 where id = ?2") - Boolean updateUserMessageIsReadById(Boolean aTrue, Long aLong); + int updateUserMessageIsReadById(Boolean aTrue, Long aLong); + + /** + * 修改是否置顶状态 + * @param isTop + * @param id + * @return + */ + @Modifying + @Query(value = "update UserMessage set isTop = ?1 where messageId = ?2") + int updateIsTopByMessageId(Boolean isTop, Long id); + + + /** + * 修改是否置顶状态 + * @param isTop + * @param id + * @return + */ + @Modifying + @Query(value = "update UserMessage set isTop = ?1 where id = ?2") + int changeMessageIsTop(Boolean isTop, Long id); + + } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/MessageNotificationController.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/MessageNotificationController.java index 28df3fb9..3c53ec6b 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/MessageNotificationController.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/MessageNotificationController.java @@ -16,7 +16,6 @@ package com.baiye.modules.system.rest; import com.baiye.modules.system.service.MessageNotificationService; -import com.baiye.modules.system.service.dto.MessageNotificationDto; import com.baiye.modules.system.service.dto.MessageNotificationQueryCriteria; import com.baiye.util.SecurityUtils; import io.swagger.annotations.Api; @@ -25,7 +24,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; @@ -59,13 +57,13 @@ public class MessageNotificationController { @PostMapping("/createMessage") @ApiOperation("新增message") - public ResponseEntity create(@RequestBody String body){ - return new ResponseEntity<>(messageNotificationService.create(body),HttpStatus.CREATED); + public ResponseEntity create(@RequestParam("body") String body,@RequestParam Long userId){ + return new ResponseEntity<>(messageNotificationService.create(body,userId), HttpStatus.CREATED); } - @PutMapping("changeMessage") + @PostMapping("changeMessage") @ApiOperation("修改message") public ResponseEntity update(@RequestBody String body){ messageNotificationService.update(body); diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/RoleController.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/RoleController.java index e87e9640..bf2a286b 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/RoleController.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/RoleController.java @@ -16,12 +16,14 @@ package com.baiye.modules.system.rest; import cn.hutool.core.lang.Dict; +import com.baiye.annotation.Inner; import com.baiye.exception.BadRequestException; +import com.baiye.model.dto.UserDto; import com.baiye.modules.system.domain.Role; import com.baiye.modules.system.service.RoleService; import com.baiye.modules.system.service.dto.RoleDto; import com.baiye.modules.system.service.dto.RoleQueryCriteria; -import com.baiye.modules.system.service.dto.RoleSmallDto; +import com.baiye.model.dto.RoleSmallDto; import com.baiye.util.SecurityUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -54,6 +56,15 @@ public class RoleController { private static final String ENTITY_NAME = "role"; + + @Inner + @ApiOperation("获取单个role") + @PostMapping(value = "/user/authority") + public Set authority(@RequestBody UserDto userDto){ + return roleService.getUserPermissions(userDto); + } + + @ApiOperation("获取单个role") @GetMapping(value = "/{id}") @PreAuthorize("@el.check('roles:list')") @@ -133,6 +144,8 @@ public class RoleController { return new ResponseEntity<>(HttpStatus.OK); } + + /** * 获取用户的角色级别 * @return / diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/UserController.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/UserController.java index 083a2934..366e7d3e 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/UserController.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/UserController.java @@ -20,9 +20,11 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; +import com.baiye.annotation.Inner; import com.baiye.config.properties.RsaProperties; import com.baiye.constant.RoleNumberConstants; import com.baiye.exception.BadRequestException; +import com.baiye.model.dto.UserDto; import com.baiye.model.dto.UserFavorOfExcel; import com.baiye.modules.system.domain.Dept; import com.baiye.modules.system.domain.User; @@ -31,8 +33,7 @@ import com.baiye.modules.system.service.DataService; import com.baiye.modules.system.service.DeptService; import com.baiye.modules.system.service.RoleService; import com.baiye.modules.system.service.UserService; -import com.baiye.modules.system.service.dto.RoleSmallDto; -import com.baiye.modules.system.service.dto.UserDto; +import com.baiye.model.dto.RoleSmallDto; import com.baiye.modules.system.service.dto.UserQueryCriteria; import com.baiye.util.PageUtil; import com.baiye.util.RsaUtils; @@ -211,6 +212,26 @@ public class UserController { } } + /** + * 获取指定用户全部信息 + * + * @return 用户信息 + */ + + @GetMapping("/info/findByName") + @ApiOperation("名称查询") + public UserDto info(@RequestParam("username") String username) { + return userService.findByName(username); + } + + @Inner + @PostMapping("/info/deptIds") + @ApiOperation("查找部门") + public List info(@RequestBody UserDto user) { + return dataService.getDeptIds(user); + } + + @ApiOperation("查询所有的管理员") @PostMapping(value = "/admin") public ResponseEntity getAdminInfo(@RequestBody List roleIds) { diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/UserMessageController.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/UserMessageController.java index 412b3573..9fb20f9e 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/UserMessageController.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/UserMessageController.java @@ -1,10 +1,8 @@ package com.baiye.modules.system.rest; import com.baiye.constant.DefaultNumberConstants; -import com.baiye.exception.BadRequestException; import com.baiye.http.CommonResponse; import com.baiye.http.ResponseCode; -import com.baiye.modules.system.domain.Role; import com.baiye.modules.system.domain.UserMessage; import com.baiye.modules.system.service.UserMessageService; import com.baiye.modules.system.service.dto.UserMessageQueryCriteria; @@ -13,6 +11,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; +import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -33,9 +32,8 @@ public class UserMessageController { @ApiOperation("查询任务(分页)") @GetMapping("/queryAll") public ResponseEntity queryAll(UserMessageQueryCriteria criteria) { - criteria.setType(DefaultNumberConstants.ONE_NUMBER); criteria.setUserId(SecurityUtils.getCurrentUserId()); - return new ResponseEntity<>(userMessageService.queryAll(criteria), HttpStatus.OK); + return new ResponseEntity<>(userMessageService.queryAll(criteria, criteria.getPage(), criteria.getSize()), HttpStatus.OK); } @@ -46,22 +44,26 @@ public class UserMessageController { return new ResponseEntity<>(HttpStatus.NO_CONTENT); } - @ApiOperation("创建小") - @PostMapping("/createMessage") - public CommonResponse create(String body) { + + + @ApiOperation("已读") + @PostMapping("/read") + public CommonResponse read(@RequestBody String body) { if (StringUtils.isEmpty(body)) { return CommonResponse.createByErrorMessage(ResponseCode.ERROR.getDesc()); } - return userMessageService.createUserMessage(body); + return userMessageService.read(body); } @ApiOperation("已读") - @PostMapping("/read") - public CommonResponse read(String body) { + @PostMapping("/top") + public CommonResponse messageTop(@RequestBody String body) { if (StringUtils.isEmpty(body)) { return CommonResponse.createByErrorMessage(ResponseCode.ERROR.getDesc()); } - return userMessageService.read(body); + userMessageService.messageTop(body); + return CommonResponse.createBySuccess(); } + } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/DataService.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/DataService.java index 0d0dae72..d7821f2c 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/DataService.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/DataService.java @@ -16,7 +16,7 @@ package com.baiye.modules.system.service; -import com.baiye.modules.system.service.dto.UserDto; +import com.baiye.model.dto.UserDto; import java.util.List; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/MessageNotificationService.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/MessageNotificationService.java index f31f3cbe..34e56bcd 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/MessageNotificationService.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/MessageNotificationService.java @@ -55,11 +55,14 @@ public interface MessageNotificationService { MessageNotificationDto findById(Long id); /** - * 创建 - * @param resources / - * @return MessageNotificationDto - */ - MessageNotificationDto create(String resources); + * 创建 + * + * @param resources \ + * @param userId \ + * + * @return MessageNotificationDto + */ + MessageNotificationDto create(String resources, Long userId); /** * 编辑 @@ -81,11 +84,4 @@ public interface MessageNotificationService { */ void download(List all, HttpServletResponse response) throws IOException; - /** - * body - * @param body - * @return - */ - Boolean withdrawMessage(String body); - } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/OrganizeService.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/OrganizeService.java index e6623c8a..96ba2fb8 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/OrganizeService.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/OrganizeService.java @@ -1,6 +1,7 @@ package com.baiye.modules.system.service; import com.baiye.model.dto.OrganizeQueryCriteria; +import com.baiye.model.dto.UserDto; import com.baiye.modules.system.domain.Organize; import com.baiye.modules.system.domain.OrganizeUser; import com.baiye.modules.system.domain.TaskOrganize; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/RoleService.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/RoleService.java index 8006996d..d9e8277b 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/RoleService.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/RoleService.java @@ -18,8 +18,8 @@ package com.baiye.modules.system.service; import com.baiye.modules.system.domain.Role; import com.baiye.modules.system.service.dto.RoleDto; import com.baiye.modules.system.service.dto.RoleQueryCriteria; -import com.baiye.modules.system.service.dto.RoleSmallDto; -import com.baiye.modules.system.service.dto.UserDto; +import com.baiye.model.dto.RoleSmallDto; +import com.baiye.model.dto.UserDto; import org.springframework.data.domain.Pageable; import org.springframework.security.core.GrantedAuthority; @@ -134,4 +134,11 @@ public interface RoleService { * @return / */ List findInMenuId(List menuIds); + + /** + * 获取权限 + * @param userDto + * @return + */ + Set getUserPermissions(UserDto userDto); } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserMessageService.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserMessageService.java index 1e278be0..10b97d72 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserMessageService.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserMessageService.java @@ -46,9 +46,11 @@ public interface UserMessageService { /** * 查询所有数据不分页 * @param criteria 条件参数 - * @return List + * @param page + * @param size + * @return List */ - List queryAll(UserMessageQueryCriteria criteria); + Map queryAll(UserMessageQueryCriteria criteria, Integer page, Integer size); /** * 根据ID查询 @@ -94,24 +96,43 @@ public interface UserMessageService { /** * 删除消息 - * * @param num * @param messageId * @return */ - Boolean deleteAllByMessageId(Integer num, Long messageId); + Boolean deleteAllByMessageId(Integer num,Long messageId); + + /** - * 创建消息 + * 已读消息 * @param body * @return */ - CommonResponse createUserMessage(String body); + CommonResponse read(String body); /** - * 已读消息 + * 修改置顶状态 + * @param isTop + * @param id + * @return + */ + Boolean updateIsTopByMessage(Boolean isTop, Long id); + + /** + * 消息置顶 * @param body * @return */ - CommonResponse read(String body); + UserMessageDto messageTop(String body); + + /** + * 修改对象 + * @param message + * @param num + * @return + */ + UserMessageDto changeUserMessage(String message, int num); + + } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserService.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserService.java index aeb5b1ed..eb1aae98 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserService.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserService.java @@ -16,7 +16,7 @@ package com.baiye.modules.system.service; import com.baiye.modules.system.domain.User; -import com.baiye.modules.system.service.dto.UserDto; +import com.baiye.model.dto.UserDto; import com.baiye.modules.system.service.dto.UserQueryCriteria; import org.springframework.data.domain.Pageable; import org.springframework.web.multipart.MultipartFile; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/MessageNotificationDto.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/MessageNotificationDto.java index ddd77e1b..839129d5 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/MessageNotificationDto.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/MessageNotificationDto.java @@ -19,6 +19,7 @@ import lombok.Data; import java.io.Serializable; import java.sql.Timestamp; +import java.util.Date; /** * @website https://el-admin.vip @@ -43,7 +44,7 @@ public class MessageNotificationDto implements Serializable { private Integer level; /** 1公告 2提醒 */ - private Integer type; + private Integer messageType; /** 是否使用 */ private Boolean isEnable; @@ -52,7 +53,7 @@ public class MessageNotificationDto implements Serializable { private Boolean isTop; /** 时间点 */ - private Integer pointTime; + private Date pointTime; /** 创建者 */ private String createBy; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/OrganizeDto.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/OrganizeDto.java index 6a8b0513..fddcfb29 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/OrganizeDto.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/OrganizeDto.java @@ -1,5 +1,6 @@ package com.baiye.modules.system.service.dto; +import com.baiye.model.dto.UserDto; import com.baiye.modules.system.domain.Task; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserMessageDto.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserMessageDto.java index 82d34704..084cd02b 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserMessageDto.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserMessageDto.java @@ -17,6 +17,7 @@ package com.baiye.modules.system.service.dto; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; @@ -40,6 +41,9 @@ public class UserMessageDto implements Serializable { /** 是否已读 */ private Boolean isRead; + /** 是否置顶 */ + private Boolean isTop; + /** 开始时间 */ private Timestamp startTime; @@ -55,6 +59,12 @@ public class UserMessageDto implements Serializable { /** 消息等级 */ private Integer level; + /** 消息类型 */ + private Integer messageType; + + /**消息状态*/ + private Integer status; + /** 用户id */ private Long userId; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserMessageQueryCriteria.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserMessageQueryCriteria.java index 311e0bfe..dfbd9af1 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserMessageQueryCriteria.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/UserMessageQueryCriteria.java @@ -30,5 +30,9 @@ public class UserMessageQueryCriteria{ private Long userId; @Query - private Integer type; + private Integer status; + + private Integer page; + + private Integer size; } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/DataServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/DataServiceImpl.java index 65c88f3a..5c5f05e7 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/DataServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/DataServiceImpl.java @@ -20,8 +20,8 @@ import com.baiye.modules.system.domain.Dept; import com.baiye.modules.system.service.DataService; import com.baiye.modules.system.service.DeptService; import com.baiye.modules.system.service.RoleService; -import com.baiye.modules.system.service.dto.RoleSmallDto; -import com.baiye.modules.system.service.dto.UserDto; +import com.baiye.model.dto.RoleSmallDto; +import com.baiye.model.dto.UserDto; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheConfig; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/LabelServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/LabelServiceImpl.java index 5b848053..22c33c5a 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/LabelServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/LabelServiceImpl.java @@ -1,7 +1,5 @@ package com.baiye.modules.system.service.impl; -import cn.hutool.core.lang.Snowflake; -import cn.hutool.core.util.IdUtil; import com.baiye.modules.system.domain.Label; import com.baiye.modules.system.repository.LabelRepository; import com.baiye.modules.system.service.LabelService; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/MenuServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/MenuServiceImpl.java index f888af57..e7d3860e 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/MenuServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/MenuServiceImpl.java @@ -30,7 +30,7 @@ import com.baiye.modules.system.service.MenuService; import com.baiye.modules.system.service.RoleService; import com.baiye.modules.system.service.dto.MenuDto; import com.baiye.modules.system.service.dto.MenuQueryCriteria; -import com.baiye.modules.system.service.dto.RoleSmallDto; +import com.baiye.model.dto.RoleSmallDto; import com.baiye.modules.system.service.mapstruct.MenuMapper; import com.baiye.util.*; import lombok.RequiredArgsConstructor; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/MessageNotificationServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/MessageNotificationServiceImpl.java index 60d1d272..ca2fbf17 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/MessageNotificationServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/MessageNotificationServiceImpl.java @@ -29,7 +29,7 @@ import com.baiye.modules.system.service.UserMessageService; import com.baiye.modules.system.service.UserService; import com.baiye.modules.system.service.dto.MessageNotificationDto; import com.baiye.modules.system.service.dto.MessageNotificationQueryCriteria; -import com.baiye.modules.system.service.dto.UserDto; +import com.baiye.model.dto.UserDto; import com.baiye.modules.system.service.mapstruct.MessageNotificationMapper; import com.baiye.util.*; import lombok.RequiredArgsConstructor; @@ -90,15 +90,13 @@ public class MessageNotificationServiceImpl implements MessageNotificationServic } @Override - @Transactional(rollbackFor = Exception.class) - public MessageNotificationDto create(String resource) { + public MessageNotificationDto create(String resource,Long userId) { List longList = new ArrayList<>(); MessageNotificationDto messageNotificationDto = JSONUtil.toBean(resource, MessageNotificationDto.class); - Long userId = SecurityUtils.getCurrentUserId(); - UserDto userDto = JSONUtil.toBean(SecurityUtils.getUser(), UserDto.class); - messageNotificationDto.setUserId(userId); + UserDto userDto = userService.findById(userId); longList.add(userId); + messageNotificationDto.setUserId(userId); messageNotificationDto.setLevel(DefaultNumberConstants.FOUR_NUMBER); // 级别进行排序 if (Boolean.TRUE.equals(userDto.getIsGroup())) { @@ -112,7 +110,7 @@ public class MessageNotificationServiceImpl implements MessageNotificationServic } messageNotificationDto.setLevel(DefaultNumberConstants.TWO_NUMBER); } - if (SecurityUtils.getCurrentUserId() == DefaultNumberConstants.ONE_NUMBER) { + if (userId == DefaultNumberConstants.ONE_NUMBER) { longList = userService.queryAllUserIds(); messageNotificationDto.setLevel(DefaultNumberConstants.ONE_NUMBER); } @@ -135,15 +133,18 @@ public class MessageNotificationServiceImpl implements MessageNotificationServic ValidationUtil.isNull(messageNotification.getId(), "MessageNotification", "id", messageNotificationDto.getId()); messageNotificationRepository.save(Convert.convert(MessageNotification.class, resources)); if (messageNotification.getIsEnable() != null && !messageNotification.getIsEnable()) { - userMessageService.deleteAllByMessageId(DefaultNumberConstants.MINUS_ONE_NUMBER, messageNotificationDto.getId()); + userMessageService.deleteAllByMessageId(DefaultNumberConstants.MINUS_ONE_NUMBER,messageNotificationDto.getId()); } - if (messageNotification.getType() != null && messageNotification.getType() == DefaultNumberConstants.ONE_NUMBER) { + if (messageNotification.getIsTop() != null) { + userMessageService.updateIsTopByMessage(messageNotificationDto.getIsTop(), messageNotificationDto.getId()); + } + if (messageNotification.getMessageType() != null && messageNotification.getMessageType() == DefaultNumberConstants.ONE_NUMBER) { BaseTimeTask baseTimeTask = new BaseTimeTask(); - // TODO 增加消息id + baseTimeTask.setMessageId(messageNotification.getId()); baseTimeTask.setMessage(messageNotification.getMessageContext()); baseTimeTask.setUserId(SecurityUtils.getCurrentUserId()); - baseTimeTask.setIsRepeat(messageNotification.getIsReuse() ? - DefaultNumberConstants.ONE_NUMBER : DefaultNumberConstants.ZERO_NUMBER); + baseTimeTask.setIsRepeat(messageNotification.getIsReuse() != null && messageNotification.getIsReuse() + ? DefaultNumberConstants.ONE_NUMBER : DefaultNumberConstants.ZERO_NUMBER); sendMessageClient.changeTaskTime(baseTimeTask); } @@ -176,19 +177,5 @@ public class MessageNotificationServiceImpl implements MessageNotificationServic FileUtil.downloadExcel(list, response); } - @Override - @Transactional(rollbackFor = Exception.class) - public Boolean withdrawMessage(String body) { - ChangeMessageDTO changeMessageDTO = JSONUtil.toBean(body, ChangeMessageDTO.class); - if (changeMessageDTO == null) { - return Boolean.FALSE; - } - Boolean flag = changeMessageDTO.getFlag(); - messageNotificationRepository - .updateMessageEnableByMessage(flag == null ? Boolean.FALSE : flag, changeMessageDTO.getMessageId()); - - return userMessageService.deleteAllByMessageId(Boolean.TRUE.equals(flag) - ? DefaultNumberConstants.ONE_NUMBER : DefaultNumberConstants.MINUS_ONE_NUMBER, changeMessageDTO.getMessageId()); - } } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/OrganizeServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/OrganizeServiceImpl.java index e9b37d62..ebfb7829 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/OrganizeServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/OrganizeServiceImpl.java @@ -6,10 +6,7 @@ import com.baiye.feign.AssignDataClient; import com.baiye.feign.SourceClueClient; import com.baiye.http.CommonResponse; import com.baiye.http.ResponseCode; -import com.baiye.model.dto.ClueQueryCriteria; -import com.baiye.model.dto.DistributeDTO; -import com.baiye.model.dto.DistributeResponseDTO; -import com.baiye.model.dto.OrganizeQueryCriteria; +import com.baiye.model.dto.*; import com.baiye.modules.system.domain.*; import com.baiye.modules.system.repository.*; import com.baiye.modules.system.service.OrganizeService; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/OrganizeUserServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/OrganizeUserServiceImpl.java index 2c769407..038d333a 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/OrganizeUserServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/OrganizeUserServiceImpl.java @@ -2,7 +2,6 @@ package com.baiye.modules.system.service.impl; import com.baiye.modules.system.repository.OrganizeUserRepository; import com.baiye.modules.system.service.OrganizeUserService; -import com.baiye.modules.system.service.mapstruct.MessageNotificationMapper; import com.baiye.modules.system.service.mapstruct.OrganizeUserMapper; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/RoleServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/RoleServiceImpl.java index d3221864..878184be 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/RoleServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/RoleServiceImpl.java @@ -16,9 +16,10 @@ package com.baiye.modules.system.service.impl; import cn.hutool.core.collection.CollectionUtil; +import com.baiye.config.CustomAuthorityDeserializer; import com.baiye.exception.BadRequestException; import com.baiye.exception.EntityExistException; -import com.baiye.modules.security.service.UserCacheClean; +import com.baiye.service.UserCacheClean; import com.baiye.modules.system.domain.Menu; import com.baiye.modules.system.domain.Role; import com.baiye.modules.system.domain.User; @@ -27,11 +28,12 @@ import com.baiye.modules.system.repository.UserRepository; import com.baiye.modules.system.service.RoleService; import com.baiye.modules.system.service.dto.RoleDto; import com.baiye.modules.system.service.dto.RoleQueryCriteria; -import com.baiye.modules.system.service.dto.RoleSmallDto; -import com.baiye.modules.system.service.dto.UserDto; +import com.baiye.model.dto.RoleSmallDto; +import com.baiye.model.dto.UserDto; import com.baiye.modules.system.service.mapstruct.RoleMapper; import com.baiye.modules.system.service.mapstruct.RoleSmallMapper; import com.baiye.util.*; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheConfig; @@ -167,6 +169,7 @@ public class RoleServiceImpl implements RoleService { @Override @Cacheable(key = "'auth:' + #p0.id") + @JsonDeserialize(using = CustomAuthorityDeserializer.class) public List mapToGrantedAuthorities(UserDto user) { Set permissions = new HashSet<>(); // 如果是管理员直接返回 @@ -209,8 +212,27 @@ public class RoleServiceImpl implements RoleService { return roleRepository.findInMenuId(menuIds); } + @Override + public Set getUserPermissions(UserDto userDto) { + Set permissions = new HashSet<>(); + // 如果是管理员直接返回 + if (userDto.getIsAdmin()) { + permissions.add("admin"); + return permissions; + } + Set roles = roleRepository.findByUserId(userDto.getId()); + return roles.stream().flatMap + (role -> role.getMenus().stream()) + .filter(menu -> + StringUtils.isNotBlank(menu.getPermission())) + .map(Menu::getPermission) + .collect(Collectors.toSet()); + + } + /** * 清理缓存 + * * @param id / */ public void delCaches(Long id, List users) { diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/TaskServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/TaskServiceImpl.java index d576fc50..df6f46ac 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/TaskServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/TaskServiceImpl.java @@ -14,7 +14,7 @@ import com.baiye.modules.system.repository.TaskRepository; import com.baiye.modules.system.service.TaskService; import com.baiye.modules.system.service.UserService; import com.baiye.modules.system.service.dto.TaskDto; -import com.baiye.modules.system.service.dto.UserDto; +import com.baiye.model.dto.UserDto; import com.baiye.modules.system.service.mapstruct.TaskMapper; import com.baiye.util.PageUtil; import com.baiye.util.QueryHelp; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserMessageServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserMessageServiceImpl.java index 7dd4f901..39eafdc6 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserMessageServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserMessageServiceImpl.java @@ -21,7 +21,6 @@ import cn.hutool.json.JSONUtil; import com.baiye.constant.DefaultNumberConstants; import com.baiye.feign.SendMessageClient; import com.baiye.http.CommonResponse; -import com.baiye.model.dto.SendWebSocketDTO; import com.baiye.model.entity.BaseTimeTask; import com.baiye.modules.system.domain.MessageNotification; import com.baiye.modules.system.domain.UserMessage; @@ -30,6 +29,7 @@ import com.baiye.modules.system.service.UserMessageService; import com.baiye.modules.system.service.dto.UserMessageDto; import com.baiye.modules.system.service.dto.UserMessageQueryCriteria; import com.baiye.modules.system.service.mapstruct.UserMessageMapper; +import com.baiye.socket.WebSocketServer; import com.baiye.util.FileUtil; import com.baiye.util.PageUtil; import com.baiye.util.QueryHelp; @@ -43,10 +43,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author Enzo @@ -58,6 +55,8 @@ import java.util.Map; @RequiredArgsConstructor public class UserMessageServiceImpl implements UserMessageService { + private final WebSocketServer webSocketServer; + private final UserMessageRepository userMessageRepository; private final UserMessageMapper userMessageMapper; @@ -67,21 +66,29 @@ public class UserMessageServiceImpl implements UserMessageService { @Override public Map queryAll(UserMessageQueryCriteria criteria, Pageable pageable) { + Page page = userMessageRepository.findAll( (root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable); return PageUtil.toPage(page.map(userMessageMapper::toDto)); } @Override - public List queryAll(UserMessageQueryCriteria criteria) { - Sort sort = Sort.by(Sort.Direction.ASC, "level"). + public Map queryAll(UserMessageQueryCriteria criteria, Integer page, Integer size) { + Sort sort = Sort.by(Sort.Direction.ASC, "messageType"). + and(Sort.by(Sort.Direction.ASC, "level")). and(Sort.by(Sort.Direction.DESC, "isTop")). - and(Sort.by(Sort.Direction.DESC, "isRead")). - and(Sort.by(Sort.Direction.DESC, "createTime")); - return userMessageMapper.toDto(userMessageRepository.findAll( - (root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), sort)); + and(Sort.by(Sort.Direction.ASC, "isRead")). + and(Sort.by(Sort.Direction.DESC, "updateTime")). + and(Sort.by(Sort.Direction.DESC, "id")); + List all = userMessageRepository.findAll( + (root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), sort); + return PageUtil.toPage(PageUtil.toPage + (page != null ? page : DefaultNumberConstants.ZERO_NUMBER, + size != null ? size : DefaultNumberConstants.TWENTY_NUMBER, + userMessageMapper.toDto(all)), all.size()); } + @Override @Transactional(rollbackFor = Exception.class) public UserMessageDto findById(Long id) { @@ -132,57 +139,109 @@ public class UserMessageServiceImpl implements UserMessageService { FileUtil.downloadExcel(list, response); } + @Override public Boolean createUserMessage(List longList, MessageNotification messageNotification) { + Map hashMap = new HashMap<>(DefaultNumberConstants.FIFTEEN_NUMBER); if (CollUtil.isNotEmpty(longList)) { UserMessage userMessage; + UserMessageDto userMessageDto; for (Long aLong : longList) { userMessage = new UserMessage(); - BeanUtil.copyProperties(messageNotification, userMessage); - userMessage.setMessageId(messageNotification.getId()); - userMessage.setType(DefaultNumberConstants.ONE_NUMBER); userMessage.setUserId(aLong); - userMessageRepository.save(userMessage); + userMessage.setLevel(messageNotification.getLevel()); + userMessage.setMessageId(messageNotification.getId()); + userMessage.setStatus(DefaultNumberConstants.ONE_NUMBER); + userMessage.setMessageTitle(messageNotification.getMessageTitle()); + userMessage.setMessageContext(messageNotification.getMessageContext()); + userMessage.setMessageType(messageNotification.getMessageType()); + userMessageDto = + userMessageMapper.toDto(userMessageRepository.save(userMessage)); + hashMap.put(aLong, userMessageDto); } } - if (messageNotification.getType() == DefaultNumberConstants.ONE_NUMBER) { - + if (messageNotification.getMessageType() == DefaultNumberConstants.ONE_NUMBER && + messageNotification.getIsReuse() != null && Boolean.TRUE.equals(messageNotification.getIsReuse())) { BaseTimeTask baseTimeTask = new BaseTimeTask(); - // TODO 增加消息id + baseTimeTask.setMessageId(messageNotification.getId()); + baseTimeTask.setExecuteTime(messageNotification.getPointTime()); baseTimeTask.setMessage(messageNotification.getMessageContext()); baseTimeTask.setUserId(longList.get(DefaultNumberConstants.ZERO_NUMBER)); - baseTimeTask.setIsRepeat(messageNotification.getIsReuse() ? - DefaultNumberConstants.ONE_NUMBER : DefaultNumberConstants.ZERO_NUMBER); + baseTimeTask.setIsRepeat(messageNotification.getIsReuse() != null && messageNotification.getIsReuse() + ? DefaultNumberConstants.ONE_NUMBER : DefaultNumberConstants.ZERO_NUMBER); sendMessageClient.createTimedMessages(baseTimeTask); return Boolean.TRUE; } - SendWebSocketDTO sendWebSocketDTO = new SendWebSocketDTO(); - sendWebSocketDTO.setUserIds(longList); - SendWebSocketDTO.SendMessage sendMessage = new SendWebSocketDTO.SendMessage(); - sendMessage.setType("userMessage"); - sendMessage.setCode(DefaultNumberConstants.TEN_NUMBER); - sendMessage.setMessage(messageNotification.getMessageContext()); - sendWebSocketDTO.setData(sendMessage); - sendMessageClient.saveMessage(sendWebSocketDTO); + webSocketServer.sendMessage(hashMap, longList); return Boolean.TRUE; } @Override public Boolean deleteAllByMessageId(Integer num, Long messageId) { - return userMessageRepository.deleteUserMessageByMessageId(num, messageId); + return userMessageRepository. + deleteUserMessageByMessageId(num, messageId) > + DefaultNumberConstants.ZERO_NUMBER; } - @Override - public CommonResponse createUserMessage(String body) { - return null; - } @Override @Transactional(rollbackFor = Exception.class) public CommonResponse read(String body) { - Long aLong = JSONUtil.toBean(body, Long.class); - userMessageRepository.updateUserMessageIsReadById(Boolean.TRUE,aLong); + Long aLong = JSONUtil.parseObj(body).get("id", Long.class); + userMessageRepository.updateUserMessageIsReadById(Boolean.TRUE, aLong); return CommonResponse.createBySuccess(); } + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean updateIsTopByMessage(Boolean isTop, Long id) { + return userMessageRepository.updateIsTopByMessageId(isTop, id) > DefaultNumberConstants.ZERO_NUMBER; + } + + @Override + public UserMessageDto messageTop(String body) { + UserMessage userMessage = new UserMessage(); + UserMessageDto userMessageDto = JSONUtil.toBean(body, UserMessageDto.class); + BeanUtil.copyProperties(userMessageDto, userMessage); + if (userMessage.getIsTop() != null && userMessage.getIsTop()) { + userMessage.setIsTop(Boolean.TRUE); + } + if (userMessage.getIsTop() != null && userMessage.getIsTop()) { + userMessage.setIsTop(Boolean.TRUE); + } + return userMessageMapper.toDto(userMessageRepository.save(userMessage)); + + } + + @Override + @Transactional(rollbackFor = Exception.class) + public UserMessageDto changeUserMessage(String message, int num) { + Long id = JSONUtil.parseObj(message).get("id", Long.class); + UserMessage userMessage; + if (id != null) { + userMessage = userMessageRepository.findById(id).orElseGet(UserMessage::new); + ValidationUtil.isNull(userMessage.getId(), "UserMessage", "id", userMessage); + switch (num) { + case DefaultNumberConstants.ONE_NUMBER: + userMessage.setIsTop(Boolean.TRUE); + break; + case DefaultNumberConstants.TWO_NUMBER: + userMessage.setStatus(DefaultNumberConstants.MINUS_ONE_NUMBER); + userMessageRepository.deleteUserMessageByMessageId + (DefaultNumberConstants.MINUS_TWO_NUMBER,userMessage.getMessageId()); + break; + case DefaultNumberConstants.THREE_NUMBER: + userMessage.setIsRead(Boolean.TRUE); + break; + case DefaultNumberConstants.FOUR_NUMBER: + userMessage.setStatus(DefaultNumberConstants.MINUS_ONE_NUMBER); + break; + default: + } + return userMessageMapper.toDto(userMessageRepository.save(userMessage)); + } + return userMessageMapper.toDto(new UserMessage()); + } + + } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java index 7ca36e26..7a6417d5 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java @@ -22,14 +22,12 @@ import com.baiye.exception.BadRequestException; import com.baiye.exception.EntityExistException; import com.baiye.exception.EntityNotFoundException; import com.baiye.modules.security.service.OnlineUserService; -import com.baiye.modules.security.service.UserCacheClean; +import com.baiye.service.UserCacheClean; import com.baiye.modules.system.domain.Role; import com.baiye.modules.system.domain.User; import com.baiye.modules.system.repository.UserRepository; import com.baiye.modules.system.service.UserService; -import com.baiye.modules.system.service.dto.JobSmallDto; -import com.baiye.modules.system.service.dto.RoleSmallDto; -import com.baiye.modules.system.service.dto.UserDto; +import com.baiye.model.dto.UserDto; import com.baiye.modules.system.service.dto.UserQueryCriteria; import com.baiye.modules.system.service.mapstruct.UserMapper; import com.baiye.util.*; @@ -48,7 +46,6 @@ import javax.validation.constraints.NotBlank; import java.io.File; import java.io.IOException; import java.util.*; -import java.util.stream.Collectors; /** * @author Zheng Jie @@ -85,7 +82,18 @@ public class UserServiceImpl implements UserService { public UserDto findById(long id) { User user = userRepository.findById(id).orElseGet(User::new); ValidationUtil.isNull(user.getId(), "User", "id", id); - return userMapper.toDto(user); + UserDto userDto = userMapper.toDto(user); + Set roles = user.getRoles(); + for (Role role : roles) { + // TODO 修改管理员id + if (role.getId() == DefaultNumberConstants.EIGHT_NUMBER) { + userDto.setIsManager(Boolean.TRUE); + } + if (role.getId() == DefaultNumberConstants.NINE_NUMBER) { + userDto.setIsGroup(Boolean.TRUE); + } + } + return userDto; } @Override @@ -263,12 +271,8 @@ public class UserServiceImpl implements UserService { public void download(List queryAll, HttpServletResponse response) throws IOException { List> list = new ArrayList<>(); for (UserDto userDTO : queryAll) { - List roles = userDTO.getRoles().stream().map(RoleSmallDto::getName).collect(Collectors.toList()); Map map = new LinkedHashMap<>(); map.put("用户名", userDTO.getUsername()); - map.put("角色", roles); - map.put("部门", userDTO.getDept().getName()); - map.put("岗位", userDTO.getJobs().stream().map(JobSmallDto::getName).collect(Collectors.toList())); map.put("邮箱", userDTO.getEmail()); map.put("状态", userDTO.getEnabled() ? "启用" : "禁用"); map.put("手机号码", userDTO.getPhone()); diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/DeptSmallMapper.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/DeptSmallMapper.java index 24dcf963..0553bbee 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/DeptSmallMapper.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/DeptSmallMapper.java @@ -17,7 +17,7 @@ package com.baiye.modules.system.service.mapstruct; import com.baiye.model.base.BaseMapper; import com.baiye.modules.system.domain.Dept; -import com.baiye.modules.system.service.dto.DeptSmallDto; +import com.baiye.model.dto.DeptSmallDto; import org.mapstruct.Mapper; import org.mapstruct.ReportingPolicy; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/JobSmallMapper.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/JobSmallMapper.java index 4392b21a..ee479123 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/JobSmallMapper.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/JobSmallMapper.java @@ -17,7 +17,7 @@ package com.baiye.modules.system.service.mapstruct; import com.baiye.model.base.BaseMapper; import com.baiye.modules.system.domain.Job; -import com.baiye.modules.system.service.dto.JobSmallDto; +import com.baiye.model.dto.JobSmallDto; import org.mapstruct.Mapper; import org.mapstruct.ReportingPolicy; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/RoleSmallMapper.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/RoleSmallMapper.java index 6599e27c..0fc4403a 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/RoleSmallMapper.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/RoleSmallMapper.java @@ -17,7 +17,7 @@ package com.baiye.modules.system.service.mapstruct; import com.baiye.model.base.BaseMapper; import com.baiye.modules.system.domain.Role; -import com.baiye.modules.system.service.dto.RoleSmallDto; +import com.baiye.model.dto.RoleSmallDto; import org.mapstruct.Mapper; import org.mapstruct.ReportingPolicy; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/UserMapper.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/UserMapper.java index 8b045af7..545b4a77 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/UserMapper.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/UserMapper.java @@ -17,7 +17,7 @@ package com.baiye.modules.system.service.mapstruct; import com.baiye.model.base.BaseMapper; import com.baiye.modules.system.domain.User; -import com.baiye.modules.system.service.dto.UserDto; +import com.baiye.model.dto.UserDto; import org.mapstruct.Mapper; import org.mapstruct.ReportingPolicy; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/api/DoubleCallController.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/api/DoubleCallController.java index 787d07a5..ab435dbe 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/api/DoubleCallController.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/api/DoubleCallController.java @@ -15,7 +15,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; /** * @author wjt diff --git a/manage/ad-platform-management/src/main/java/com/baiye/socket/WebSocketServer.java b/manage/ad-platform-management/src/main/java/com/baiye/socket/WebSocketServer.java new file mode 100644 index 00000000..1dcbdb06 --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/socket/WebSocketServer.java @@ -0,0 +1,255 @@ +package com.baiye.socket; + +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.baiye.constant.DefaultNumberConstants; +import com.baiye.http.WebSocketResponse; +import com.baiye.model.dto.SendWebSocketDTO; +import com.baiye.model.enums.WebSocketEnums; +import com.baiye.modules.system.service.MessageNotificationService; +import com.baiye.modules.system.service.UserMessageService; +import com.baiye.modules.system.service.dto.UserMessageDto; +import com.baiye.util.RedisUtils; +import com.baiye.util.SpringContextHolder; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.websocket.*; +import javax.websocket.server.ServerEndpoint; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author wjt + * @date 2021/12/13 + */ +@Slf4j +@Component +@ServerEndpoint(value = "/ws/prosperous") +public class WebSocketServer { + private Long onlineId; + + + @PostConstruct + public void init() { + log.info("websocket 加载"); + } + + private static final AtomicInteger ONLINE_COUNT = new AtomicInteger(0); + /** + * concurrent包的线程安全Set,用来存放每个客户端对应的Session对象。 + */ + private static final ConcurrentHashMap SESSIONS = new ConcurrentHashMap<>(); + + /** + * 连接建立成功调用的方法 + */ + @OnOpen + public void onOpen(Session session) { + Long userId = getUserId(session); + if (userId != null) { + SESSIONS.put(userId, session); + onlineId = userId; + // 在线数加1 + int cnt = ONLINE_COUNT.incrementAndGet(); + log.info("有连接加入,当前连接用户为 {},当前连接数为:{}", userId, cnt); + JSONObject jsonObject = new JSONObject(); + jsonObject.putOpt("message", "连接成功"); + jsonObject.putOpt("code", DefaultNumberConstants.TWO_HUNDRED); + sendMessage(session, JSONUtil.toJsonStr(jsonObject)); + } + } + + /** + * 连接关闭调用的方法 + */ + @OnClose + public void onClose(Session session) { + if (onlineId != null) { + SESSIONS.remove(onlineId); + int cnt = ONLINE_COUNT.decrementAndGet(); + log.info("有连接关闭,当前连接数为:{}", cnt); + } + } + + /** + * 收到客户端消息后调用的方法 + * + * @param message 客户端发送过来的消息 + */ + @OnMessage + public void onMessage(String message, Session session) { + log.info("来自客户端的消息:{}", message); + JSONObject jsonObject = JSONUtil.parseObj(message); + String type = "type"; + UserMessageService userMessageService = + SpringContextHolder.getBean(UserMessageService.class); + MessageNotificationService messageNotificationService = + SpringContextHolder.getBean(MessageNotificationService.class); + + switch (WebSocketEnums.find(jsonObject.getStr(type))) { + case DefaultNumberConstants.ONE_NUMBER: + UserMessageDto userMessageDto = + userMessageService.changeUserMessage(message, + DefaultNumberConstants.ONE_NUMBER); + sendMessage(session, + JSONUtil.toJsonStr + (WebSocketResponse.createBySuccess + (jsonObject.getStr(type), + userMessageDto))); + break; + case DefaultNumberConstants.TWO_NUMBER: + userMessageDto = + userMessageService. + changeUserMessage(message, + DefaultNumberConstants.TWO_NUMBER); + sendMessage(session, + JSONUtil.toJsonStr + (WebSocketResponse.createBySuccess + (jsonObject.getStr(type), + userMessageDto))); + break; + case DefaultNumberConstants.THREE_NUMBER: + userMessageService. + changeUserMessage(message, + DefaultNumberConstants.THREE_NUMBER); + sendMessage(session, + JSONUtil.toJsonStr + (WebSocketResponse.createBySuccess + (jsonObject.getStr(type)))); + break; + case DefaultNumberConstants.FOUR_NUMBER: + userMessageDto = userMessageService. + changeUserMessage(message, + DefaultNumberConstants.FOUR_NUMBER); + sendMessage(session, + JSONUtil.toJsonStr + (WebSocketResponse.createBySuccess + (jsonObject.getStr(type), + userMessageDto))); + break; + case DefaultNumberConstants.FIVE_NUMBER: + Long userId = getUserId(session); + if (userId != null) { + messageNotificationService.create + (message, userId); + sendMessage(session, + JSONUtil.toJsonStr + (WebSocketResponse.createBySuccess + (jsonObject.getStr(type)))); + } + break; + default: + break; + } + } + + /** + * 出现错误 + * + * @param session session + * @param error error + */ + @OnError + public void onError(Session session, Throwable error) { + log.error("发生错误:{},Session ID: {}", error.getMessage(), session.getId()); + error.printStackTrace(); + } + + /** + * 发送消息,实践表明,每次浏览器刷新,session会发生变化。 + * + * @param session + * @param message + */ + public static void sendMessage(Session session, String message) { + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + log.error("发送消息出错:{}", e.getMessage()); + e.printStackTrace(); + } + } + + /** + * 群发消息 + * + * @param message + * @throws IOException + */ + public void broadCastInfo(String message) { + for (Session session : SESSIONS.values()) { + sendMessage(session, message); + } + } + + /** + * 指定Session发送消息 + * + * @param message + * @param sessionId + * @throws IOException + */ + public void sendMessage(String message, String sessionId) throws IOException { + log.info("发送web信息 {}", message); + Session session = null; + if (SESSIONS.get(sessionId) != null) { + session = SESSIONS.get(sessionId); + } + if (session != null) { + sendMessage(session, message); + } else { + log.warn("没有找到你指定ID的会话:{}", sessionId); + } + } + + + public static Long getUserId(Session session) { + String queryString = session.getQueryString(); + if (queryString != null) { + String token = queryString.substring + (DefaultNumberConstants.TWENTY_THREE); + RedisUtils redisUtils = + SpringContextHolder.getBean(RedisUtils.class); + Object object = redisUtils.get(token); + if (object != null) { + return Long.parseLong(object.toString()); + } + } + return null; + } + + public void sendMessage(SendWebSocketDTO.SendMessage data, List ids) throws IOException { + for (long id : ids) { + if (SESSIONS.containsKey(id)) { + Session session = SESSIONS.get(id); + data.setCode(DefaultNumberConstants.TWO_HUNDRED); + session.getBasicRemote().sendText(JSONUtil.toJsonStr(data)); + } else { + log.warn("没有找到你指定ID的会话:{}", id); + } + } + } + + public void sendMessage(Map hashMap, List longList) { + try { + for (Long id : longList) { + if (SESSIONS.containsKey(id)) { + Session session = SESSIONS.get(id); + session.getBasicRemote().sendText(JSONUtil.toJsonStr + (WebSocketResponse.createBySuccess("userMessage", hashMap.get(id)))); + } else { + log.warn("没有找到你指定ID的会话:{}", id); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/manage/ad-platform-management/src/main/resources/config/application-dev.yml b/manage/ad-platform-management/src/main/resources/config/application-dev.yml index fe540a78..b8b6cf6f 100644 --- a/manage/ad-platform-management/src/main/resources/config/application-dev.yml +++ b/manage/ad-platform-management/src/main/resources/config/application-dev.yml @@ -80,23 +80,7 @@ login: # 字体大小 font-size: 25 -#jwt -jwt: - header: Authorization - # 令牌前缀 - token-start-with: Bearer - # 必须使用最少88位的Base64对该令牌进行编码 - base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI= - # 令牌过期时间 此处单位/毫秒 ,默认4小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html - token-validity-in-seconds: 14400000 - # 在线用户key - online-key: online-token- - # 验证码 - code-key: code-key- - # token 续期检查时间范围(默认30分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期 - detect: 1800000 - # 续期时间范围,默认1小时,单位毫秒 - renew: 3600000 + #是否允许生成代码,生产环境设置为false generator: diff --git a/manage/ad-platform-management/src/main/resources/config/application-prod.yml b/manage/ad-platform-management/src/main/resources/config/application-prod.yml index c673e9be..ac514af3 100644 --- a/manage/ad-platform-management/src/main/resources/config/application-prod.yml +++ b/manage/ad-platform-management/src/main/resources/config/application-prod.yml @@ -3,30 +3,28 @@ spring: cloud: nacos: discovery: - server-addr: ${NACOS_HOST:118.178.137.129}:${NACOS_PORT:8848} + server-addr: ${NACOS_HOST:172.16.190.245}:${NACOS_PORT:8848} redis: - #数据库索引 - database: 0 + database: 2 host: 127.0.0.1 - port: 6379 - password: - #连接超时时间 timeout: 5000 datasource: druid: db-type: com.alibaba.druid.pool.DruidDataSource - driverClassName: com.mysql.jdbc.Driver - url: jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:eladmin}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false - username: ${DB_USER:root} - password: ${DB_PWD:123456} + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://172.16.190.245:3306/ad_platform?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull + username: root + password: baiye@RDS2022 # 初始连接数 initial-size: 5 # 最小连接数 min-idle: 15 # 最大连接数 max-active: 30 + # 超时时间(以秒数为单位) + remove-abandoned-timeout: 180 # 获取连接超时时间 - max-wait: 5000 + max-wait: 3000 # 连接有效性检测时间 time-between-eviction-runs-millis: 60000 # 连接在池中最小生存的时间 @@ -46,11 +44,8 @@ spring: enabled: true stat-view-servlet: enabled: true - # 控制台管理用户名和密码 url-pattern: /druid/* reset-enable: false - login-username: admin - login-password: 123456 filter: stat: enabled: true @@ -80,47 +75,24 @@ login: height: 36 # 内容长度 length: 2 - # 字体名称,为空则使用默认字体,如遇到线上乱码,设置其他字体即可 + # 字体名称,为空则使用默认字体 font-name: # 字体大小 font-size: 25 -#jwt -jwt: - header: Authorization - # 令牌前缀 - token-start-with: Bearer - # 必须使用最少88位的Base64对该令牌进行编码 - base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI= - # 令牌过期时间 此处单位/毫秒 ,默认2小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html - token-validity-in-seconds: 7200000 - # 在线用户key - online-key: online-token- - # 验证码 - code-key: code-key- - # token 续期检查时间范围(默认30分钟,单位默认毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期 - detect: 1800000 - # 续期时间范围,默认 1小时,这里单位毫秒 - renew: 3600000 -# IP 本地解析 -ip: - local-parsing: false #是否允许生成代码,生产环境设置为false generator: - enabled: false - -#如果生产环境要开启swagger,需要配置请求地址 -#springfox: -# documentation: -# swagger: -# v2: -# host: # 接口域名或外网ip + enabled: true #是否开启 swagger-ui swagger: - enabled: false + enabled: true + +# IP 本地解析 +ip: + local-parsing: true # 文件存储路径 file: @@ -136,3 +108,10 @@ file: # 文件大小 /M maxSize: 100 avatarMaxSize: 5 + + +#ribbon: +# #建立连接超时时间 +# ConnectTimeout: 50000 +# #建立连接之后,读取响应资源超时时间 +# ReadTimeout: 50000 diff --git a/manage/ad-platform-management/src/main/resources/config/application.yml b/manage/ad-platform-management/src/main/resources/config/application.yml index 55bc6341..f8be715f 100644 --- a/manage/ad-platform-management/src/main/resources/config/application.yml +++ b/manage/ad-platform-management/src/main/resources/config/application.yml @@ -2,6 +2,8 @@ server: port: 8866 spring: + main: + allow-bean-definition-overriding: true application: name: @artifactId@ freemarker: diff --git a/manage/ad-platform-task/pom.xml b/manage/ad-platform-task/pom.xml index 57f18866..2cc94fdd 100644 --- a/manage/ad-platform-task/pom.xml +++ b/manage/ad-platform-task/pom.xml @@ -22,7 +22,14 @@ com.baiye - ad-platform-common + ad-platform-common-core + 1.0-SNAPSHOT + + + + + com.baiye + ad-platform-common-auth 1.0-SNAPSHOT @@ -30,40 +37,42 @@ ad-platform-pojo 1.0-SNAPSHOT - - - - - - - - - - - + + + + + + + + + + + + + org.springframework.boot spring-boot-configuration-processor 2.3.2.RELEASE true + mysql mysql-connector-java + org.springframework.boot spring-boot-starter-jdbc - - cn.hutool - hutool-all - 5.7.13 - + + com.alibaba druid-spring-boot-starter + org.apache.curator curator-framework @@ -94,15 +103,6 @@ com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - - org.springframework.boot - spring-boot-starter-websocket - + - \ No newline at end of file + diff --git a/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeign.java b/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeign.java index 5ea41091..08e6935a 100644 --- a/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeign.java +++ b/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeign.java @@ -38,12 +38,13 @@ public interface ConnectManageFeign { /** * 新增消息服务 + * * @param body * @return */ @ApiOperation("新增消息模板") @PostMapping(API_PREFIX + "/messageNotification/createMessage") - ResponseEntity createMessage(@RequestBody String body); + ResponseEntity createMessage(@RequestParam("body") String body); /** @@ -62,6 +63,15 @@ public interface ConnectManageFeign { * @return */ @ApiOperation("修改消息服务") - @PostMapping(API_PREFIX + "/userMessage/changeMessage") + @PostMapping(API_PREFIX + "/userMessage/read") ResponseEntity userMessageRead(@RequestBody String message); + + /** + * 修改消息服务 + * @param message + * @return + */ + @ApiOperation("修改消息服务") + @PostMapping(API_PREFIX + "/userMessage/top") + ResponseEntity messageTop(String message); } diff --git a/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeignFallBack.java b/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeignFallBack.java index 949c6eaf..d8c2a169 100644 --- a/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeignFallBack.java +++ b/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeignFallBack.java @@ -39,5 +39,10 @@ public class ConnectManageFeignFallBack implements ConnectManageFeign { return null; } + @Override + public ResponseEntity messageTop(String message) { + return null; + } + } diff --git a/manage/ad-platform-task/src/main/java/com/baiye/filter/WebsocketFilter.java b/manage/ad-platform-task/src/main/java/com/baiye/filter/WebsocketFilter.java deleted file mode 100644 index ffa57208..00000000 --- a/manage/ad-platform-task/src/main/java/com/baiye/filter/WebsocketFilter.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baiye.filter; - -import com.baiye.constant.SecurityConstants; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; - -import javax.servlet.*; -import javax.servlet.annotation.WebFilter; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -/** - * @author Enzo - * @date : 2022/1/9 - */ -@Order(1) -@Component -@WebFilter(filterName = "WebsocketFilter",urlPatterns = "/task/prosperous") -public class WebsocketFilter implements Filter { - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - Filter.super.init(filterConfig); - } - - @Override - public void doFilter(ServletRequest request, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { - HttpServletResponse response = (HttpServletResponse) servletResponse; - String token = ((HttpServletRequest) request).getHeader("Sec-WebSocket-Protocol"); - response.setHeader("Sec-WebSocket-Protocol",token); - if (token != null) { - request.setAttribute(SecurityConstants.AUTHORIZATION,token); - } - chain.doFilter(request, servletResponse); - } - - @Override - public void destroy() { - - } -} diff --git a/manage/ad-platform-task/src/main/java/com/baiye/job/WebSocketHeartbeat.java b/manage/ad-platform-task/src/main/java/com/baiye/job/WebSocketHeartbeat.java index fdc2b00c..a2050047 100644 --- a/manage/ad-platform-task/src/main/java/com/baiye/job/WebSocketHeartbeat.java +++ b/manage/ad-platform-task/src/main/java/com/baiye/job/WebSocketHeartbeat.java @@ -1,17 +1,14 @@ package com.baiye.job; import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; import com.baiye.constant.DefaultNumberConstants; import com.baiye.modules.timetask.entity.jobInstance.ElasticSimpleJob; -import com.baiye.socket.WebSocketServer; import com.dangdang.ddframe.job.api.ShardingContext; import com.dangdang.ddframe.job.api.simple.SimpleJob; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; -import javax.annotation.Resource; /** * @author wujingtao @@ -22,8 +19,7 @@ import javax.annotation.Resource; @Component @ElasticSimpleJob(jobName = "WebSocketHeartbeat", cron = "0 0/1 * * * ?") public class WebSocketHeartbeat implements SimpleJob { - @Resource - private WebSocketServer webSocketServer; + private static WebSocketHeartbeat WebSocketHeartbeat; @PostConstruct @@ -36,6 +32,6 @@ public class WebSocketHeartbeat implements SimpleJob { JSONObject jsonObject = new JSONObject(); jsonObject.putOpt("message", "心跳检查"); jsonObject.putOpt("code", DefaultNumberConstants.ONE_NUMBER); - WebSocketHeartbeat.webSocketServer.broadCastInfo(JSONUtil.toJsonStr(jsonObject)); + // WebSocketHeartbeat.webSocketServer.broadCastInfo(JSONUtil.toJsonStr(jsonObject)); } } diff --git a/manage/ad-platform-task/src/main/java/com/baiye/modules/timetask/service/impl/AutoReminderServiceImpl.java b/manage/ad-platform-task/src/main/java/com/baiye/modules/timetask/service/impl/AutoReminderServiceImpl.java index cea440d9..51b2ca9d 100644 --- a/manage/ad-platform-task/src/main/java/com/baiye/modules/timetask/service/impl/AutoReminderServiceImpl.java +++ b/manage/ad-platform-task/src/main/java/com/baiye/modules/timetask/service/impl/AutoReminderServiceImpl.java @@ -4,7 +4,6 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.json.JSONArray; @@ -16,16 +15,11 @@ import com.baiye.http.CommonResponse; import com.baiye.modules.timetask.dao.AutoReminderRepository; import com.baiye.modules.timetask.entity.AutoReminder; import com.baiye.modules.timetask.service.AutoReminderService; -import com.baiye.socket.WebSocketServer; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Repository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.sql.Connection; -import java.util.ArrayList; import java.util.List; /** @@ -38,8 +32,6 @@ public class AutoReminderServiceImpl implements AutoReminderService { @Resource private AutoReminderRepository timeTaskRepository; @Resource - private WebSocketServer webSocketServer; - @Resource private ConnectManageFeign connectManageFeign; @Override @@ -83,7 +75,7 @@ public class AutoReminderServiceImpl implements AutoReminderService { JSONObject jsonObject = forwardMessage(info.getMessage()); webSocketData.putOpt("data", jsonObject); try { - webSocketServer.sendMessage(JSONUtil.toJsonStr(webSocketData), String.valueOf(info.getUserId())); + // webSocketServer.sendMessage(JSONUtil.toJsonStr(webSocketData), String.valueOf(info.getUserId())); } catch (Exception e) { log.info("执行自提醒任务 id:{} 发送websocket失败 {}", info.getId(), e.getMessage()); continue; diff --git a/manage/ad-platform-task/src/main/java/com/baiye/modules/websocket/service/impl/WebSocketServiceImpl.java b/manage/ad-platform-task/src/main/java/com/baiye/modules/websocket/service/impl/WebSocketServiceImpl.java index 79bf25d5..2c9d20be 100644 --- a/manage/ad-platform-task/src/main/java/com/baiye/modules/websocket/service/impl/WebSocketServiceImpl.java +++ b/manage/ad-platform-task/src/main/java/com/baiye/modules/websocket/service/impl/WebSocketServiceImpl.java @@ -1,17 +1,13 @@ package com.baiye.modules.websocket.service.impl; import cn.hutool.core.collection.CollUtil; -import cn.hutool.json.JSONUtil; import com.baiye.constant.DefaultNumberConstants; import com.baiye.http.CommonResponse; import com.baiye.model.dto.SendWebSocketDTO; import com.baiye.modules.websocket.service.WebSocketService; -import com.baiye.socket.WebSocketServer; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import javax.annotation.Resource; - /** * @author wujingtao * @date 2021/12/30 @@ -19,8 +15,8 @@ import javax.annotation.Resource; @Service @Slf4j public class WebSocketServiceImpl implements WebSocketService { - @Resource - private WebSocketServer webSocketServer; + /* @Resource + private WebSocketServer webSocketServer;*/ @Override public CommonResponse sendWebSocket(SendWebSocketDTO sendWebSocketDTO) { @@ -28,9 +24,9 @@ public class WebSocketServiceImpl implements WebSocketService { if (CollUtil.isEmpty(sendWebSocketDTO.getUserIds())) { SendWebSocketDTO.SendMessage data = sendWebSocketDTO.getData(); data.setCode(DefaultNumberConstants.TWO_HUNDRED); - webSocketServer.broadCastInfo(JSONUtil.toJsonStr(data)); + //webSocketServer.broadCastInfo(JSONUtil.toJsonStr(data)); } else { - webSocketServer.sendMessage(sendWebSocketDTO.getData(), sendWebSocketDTO.getUserIds()); + // webSocketServer.sendMessage(sendWebSocketDTO.getData(), sendWebSocketDTO.getUserIds()); } } catch (Exception e) { log.error("Method 【sendWebSocket】发送 websocket 错误 :{}", e.getMessage()); diff --git a/manage/ad-platform-task/src/main/java/com/baiye/socket/WebSocketServer.java b/manage/ad-platform-task/src/main/java/com/baiye/socket/WebSocketServer.java deleted file mode 100644 index 83cbc920..00000000 --- a/manage/ad-platform-task/src/main/java/com/baiye/socket/WebSocketServer.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.baiye.socket; - -import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; -import com.baiye.constant.DefaultNumberConstants; -import com.baiye.model.dto.SendWebSocketDTO; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import javax.websocket.*; -import javax.websocket.server.PathParam; -import javax.websocket.server.ServerEndpoint; -import java.io.IOException; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author wjt - * @date 2021/12/13 - */ -@Slf4j -@Component -@ServerEndpoint(value = "/task/prosperous/{userId}") -public class WebSocketServer { - private static String user; - - @PostConstruct - public void init() { - log.info("websocket 加载"); - } - - private static final AtomicInteger ONLINE_COUNT = new AtomicInteger(0); - /** - * concurrent包的线程安全Set,用来存放每个客户端对应的Session对象。 - */ -// private static final CopyOnWriteArraySet SESSIONS = new CopyOnWriteArraySet<>(); - - private static ConcurrentHashMap SESSIONS = new ConcurrentHashMap(); - - /** - * 连接建立成功调用的方法 - */ - @OnOpen - public void onOpen(@PathParam(value = "userId") String userId, Session session) { - SESSIONS.put(userId, session); - user = userId; - // 在线数加1 - int cnt = ONLINE_COUNT.incrementAndGet(); - log.info("有连接加入,当前连接用户为 {},当前连接数为:{}", userId, cnt); - JSONObject jsonObject = new JSONObject(); - jsonObject.putOpt("message", "连接成功"); - jsonObject.putOpt("code", DefaultNumberConstants.TWO_HUNDRED); - sendMessage(session, JSONUtil.toJsonStr(jsonObject)); - } - - /** - * 连接关闭调用的方法 - */ - @OnClose - public void onClose(Session session) { - if (user != null) { - SESSIONS.remove(user); - int cnt = ONLINE_COUNT.decrementAndGet(); - log.info("有连接关闭,当前连接数为:{}", cnt); - } - } - - /** - * 收到客户端消息后调用的方法 - * - * @param message 客户端发送过来的消息 - */ - @OnMessage - public void onMessage(String message, Session session) { - log.info("来自客户端的消息:{}", message); - } - - /** - * 出现错误 - * - * @param session - * @param error - */ - @OnError - public void onError(Session session, Throwable error) { - log.error("发生错误:{},Session ID: {}", error.getMessage(), session.getId()); - error.printStackTrace(); - } - - /** - * 发送消息,实践表明,每次浏览器刷新,session会发生变化。 - * - * @param session - * @param message - */ - public static void sendMessage(Session session, String message) { - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - log.error("发送消息出错:{}", e.getMessage()); - e.printStackTrace(); - } - } - - /** - * 群发消息 - * - * @param message - * @throws IOException - */ - public void broadCastInfo(String message) { - for (Session session : SESSIONS.values()) { - sendMessage(session, message); - } - } - - /** - * 指定Session发送消息 - * - * @param message - * @param sessionId - * @throws IOException - */ - public void sendMessage(String message, String sessionId) throws IOException { - log.info("发送web信息 {}", message); - Session session = null; - if (SESSIONS.get(sessionId) != null) { - session = SESSIONS.get(sessionId); - } - if (session != null) { - sendMessage(session, message); - } else { - log.warn("没有找到你指定ID的会话:{}", sessionId); - } - } - - public void sendMessage(SendWebSocketDTO.SendMessage data, List ids) throws IOException { - for (long id : ids) { - if (SESSIONS.containsKey(String.valueOf(id))) { - Session session = SESSIONS.get(String.valueOf(id)); - data.setCode(DefaultNumberConstants.TWO_HUNDRED); - log.info(" 发送给 id:{} 的websocket 信息为:{}", id, data); - session.getBasicRemote().sendText(JSONUtil.toJsonStr(data)); - } else { - log.warn("没有找到你指定ID的会话:{}", id); - } - } - } -} diff --git a/manage/ad-platform-task/src/main/java/com/baiye/socket/filter/WebsocketFilter.java b/manage/ad-platform-task/src/main/java/com/baiye/socket/filter/WebsocketFilter.java new file mode 100644 index 00000000..7f6fda97 --- /dev/null +++ b/manage/ad-platform-task/src/main/java/com/baiye/socket/filter/WebsocketFilter.java @@ -0,0 +1,97 @@ +package com.baiye.socket.filter; + +import com.baiye.constant.SecurityConstants; +import com.baiye.util.RedisUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.*; + +/** + * @author Enzo + * @date : 2022/1/9 + * 该过滤器暂不生效 + */ +@Order(1) +@Component +@WebFilter(filterName = "WebsocketFilter", urlPatterns = "/task/prosperous") +@RequiredArgsConstructor +public class WebsocketFilter implements Filter { + + private final RedisUtils redisUtils; + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + Filter.super.init(filterConfig); + } + + @Override + public void doFilter(ServletRequest request, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { + HttpServletResponse response = (HttpServletResponse) servletResponse; + String token = ((HttpServletRequest) request).getHeader("Sec-WebSocket-Protocol"); + response.setHeader("Sec-WebSocket-Protocol", token); + if (token != null) { + ModifyParametersWrapper mParametersWrapper = new ModifyParametersWrapper((HttpServletRequest) request); + mParametersWrapper.putHeader(SecurityConstants.AUTHORIZATION, token); + chain.doFilter(mParametersWrapper, response); + } + chain.doFilter(request, servletResponse); + } + + @Override + public void destroy() { + // no need to do + } + + /** + * 继承HttpServletRequestWrapper,创建装饰类,以达到修改HttpServletRequest参数的目的 + */ + private static class ModifyParametersWrapper extends HttpServletRequestWrapper { + private final Map customHeaders; + + ModifyParametersWrapper(HttpServletRequest request) { + super(request); + this.customHeaders = new HashMap<>(); + } + + void putHeader(String name, String value) { + this.customHeaders.put(name, value); + } + + @Override + public String getHeader(String name) { + // check the custom headers first + String headerValue = customHeaders.get(name); + + if (headerValue != null) { + return headerValue; + } + // else return from into the original wrapped object + return ((HttpServletRequest) getRequest()).getHeader(name); + } + + @Override + public Enumeration getHeaderNames() { + // create a set of the custom header names + Set set = new HashSet<>(customHeaders.keySet()); + + // now add the headers from the wrapped request object + Enumeration e = ((HttpServletRequest) getRequest()).getHeaderNames(); + while (e.hasMoreElements()) { + // add the names of the request headers into the list + String n = e.nextElement(); + set.add(n); + } + + // create an enumeration from the set and return + return Collections.enumeration(set); + } + } +} diff --git a/manage/ad-platform-task/src/main/resources/application-dev.yml b/manage/ad-platform-task/src/main/resources/application-dev.yml index 49b27f95..df8e9c92 100644 --- a/manage/ad-platform-task/src/main/resources/application-dev.yml +++ b/manage/ad-platform-task/src/main/resources/application-dev.yml @@ -86,23 +86,7 @@ login: # 字体大小 font-size: 25 -#jwt -jwt: - header: Authorization - # 令牌前缀 - token-start-with: Bearer - # 必须使用最少88位的Base64对该令牌进行编码 - base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI= - # 令牌过期时间 此处单位/毫秒 ,默认4小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html - token-validity-in-seconds: 14400000 - # 在线用户key - online-key: online-token- - # 验证码 - code-key: code-key- - # token 续期检查时间范围(默认30分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期 - detect: 1800000 - # 续期时间范围,默认1小时,单位毫秒 - renew: 3600000 + #是否允许生成代码,生产环境设置为false generator: diff --git a/manage/ad-platform-task/src/main/resources/application.yml b/manage/ad-platform-task/src/main/resources/application.yml index db686217..ce0443d0 100644 --- a/manage/ad-platform-task/src/main/resources/application.yml +++ b/manage/ad-platform-task/src/main/resources/application.yml @@ -21,4 +21,5 @@ rsa: ribbon: ReadTimeout: 3000 - ConnectTimeout: 3000 \ No newline at end of file + ConnectTimeout: 3000 + diff --git a/pom.xml b/pom.xml index 8fa49e1a..cbcfe4f1 100644 --- a/pom.xml +++ b/pom.xml @@ -13,10 +13,15 @@ services/ad-platform-callback services/ad-platform-service services/ad-platform-search + - ad-platform-common + ad-platform-common/ad-platform-common-core + ad-platform-common/ad-platform-common-auth + + ad-platform-gateway ad-platform-pojo + manage/ad-platform-management manage/ad-platform-openapi diff --git a/services/ad-platform-service/pom.xml b/services/ad-platform-service/pom.xml index 6b4a18aa..1f9cbf03 100644 --- a/services/ad-platform-service/pom.xml +++ b/services/ad-platform-service/pom.xml @@ -21,7 +21,7 @@ com.baiye - ad-platform-common + ad-platform-common-core 1.0-SNAPSHOT diff --git a/services/ad-platform-service/src/main/java/com/baiye/api/AssignDataController.java b/services/ad-platform-service/src/main/java/com/baiye/api/AssignDataController.java index 30629827..4f71db8f 100644 --- a/services/ad-platform-service/src/main/java/com/baiye/api/AssignDataController.java +++ b/services/ad-platform-service/src/main/java/com/baiye/api/AssignDataController.java @@ -1,12 +1,9 @@ package com.baiye.api; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; import com.baiye.http.CommonResponse; import com.baiye.model.dto.DistributeDTO; import com.baiye.model.dto.DistributeResponseDTO; -import com.baiye.model.enums.ResponseCode; import com.baiye.service.AssignDataService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/services/ad-platform-source/pom.xml b/services/ad-platform-source/pom.xml index f5d5b342..42b3eee5 100644 --- a/services/ad-platform-source/pom.xml +++ b/services/ad-platform-source/pom.xml @@ -21,7 +21,14 @@ com.baiye - ad-platform-common + ad-platform-common-core + 1.0-SNAPSHOT + + + + + com.baiye + ad-platform-common-auth 1.0-SNAPSHOT