Merge remote-tracking branch 'origin/master'
| | |
| | | @ApiModelProperty(value = "上架状态(0=否,1=是)") |
| | | @TableField("status") |
| | | private Integer status; |
| | | |
| | | |
| | | @ApiModelProperty(value = "小程序id") |
| | | @TableField("applet_id") |
| | | private String appletId; |
| | | @ApiModelProperty(value = "小程序名称") |
| | | @TableField("applet_name") |
| | | private String appletName; |
| | | |
| | | @ApiModelProperty(value = "广告状态 1未开始 2已开始 3已结束") |
| | | @TableField(exist = false) |
| | |
| | | " | | \\ / \\ / \n" + |
| | | " ''-' `'-' `-..-' "); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.ruoyi.gateway.filter; |
| | | |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.model.TAppUser; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cloud.gateway.filter.GatewayFilterChain; |
| | | import org.springframework.cloud.gateway.filter.GlobalFilter; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.core.Ordered; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.server.reactive.ServerHttpRequest; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.server.ServerWebExchange; |
| | |
| | | import io.jsonwebtoken.Claims; |
| | | import reactor.core.publisher.Mono; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | @Lazy |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | |
| | | @Lazy |
| | | @Resource |
| | | private SysUserClient sysUserClient; |
| | | |
| | | |
| | | |
| | | @Override |
| | |
| | | return chain.filter(exchange); |
| | | } |
| | | //防抖校验 |
| | | // try { |
| | | // antiShake(request); |
| | | // }catch (Exception e){ |
| | | // log.error("[重复提交]请求路径:{}", exchange.getRequest().getPath()); |
| | | // return ServletUtils.webFluxResponseWriter(exchange.getResponse(), e.getMessage(), HttpStatus.SUCCESS); |
| | | // } |
| | | try { |
| | | antiShake(request); |
| | | }catch (Exception e){ |
| | | log.error("[重复提交]请求路径:{}", exchange.getRequest().getPath()); |
| | | return ServletUtils.webFluxResponseWriter(exchange.getResponse(), e.getMessage(), HttpStatus.SUCCESS); |
| | | } |
| | | |
| | | //校验账户是否有效 |
| | | // try { |
| | | // verifyToken(request); |
| | | // verifyAccount(request); |
| | | // }catch (Exception e){ |
| | | // return unauthorizedResponse(exchange, e.getMessage()); |
| | | // } |
| | | try { |
| | | verifyToken(request); |
| | | }catch (Exception e){ |
| | | return unauthorizedResponse(exchange, e.getMessage()); |
| | | } |
| | | String token = getToken(request); |
| | | Claims claims = JwtUtils.parseToken(token); |
| | | String userkey = JwtUtils.getUserKey(claims); |
| | | String userid = JwtUtils.getUserId(claims); |
| | | String username = JwtUtils.getUserName(claims); |
| | | String userType = JwtUtils.getUserType(claims); |
| | | |
| | | // 设置用户信息到请求 |
| | | addHeader(mutate, SecurityConstants.USER_KEY, userkey); |
| | | addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid); |
| | | addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username); |
| | | addHeader(mutate, SecurityConstants.USER_TYPE, userType); |
| | | // 内部请求来源参数清除 |
| | | removeHeader(mutate, SecurityConstants.FROM_SOURCE); |
| | | return chain.filter(exchange.mutate().request(mutate.build()).build()); |
| | |
| | | * 防抖处理 |
| | | */ |
| | | public void antiShake(ServerHttpRequest request) throws Exception{ |
| | | HttpMethod method = request.getMethod(); |
| | | if(HttpMethod.OPTIONS == method){ |
| | | return; |
| | | } |
| | | HttpHeaders headers = request.getHeaders(); |
| | | String client = headers.getFirst("client"); |
| | | String timestamp = headers.getFirst("timestamp"); |
| | | if(StringUtils.isEmpty(client)){ |
| | | throw new RuntimeException("参数异常"); |
| | | } |
| | | if(StringUtils.isEmpty(timestamp)){ |
| | | throw new RuntimeException("参数异常"); |
| | | } |
| | | String url = request.getURI().getPath(); |
| | | Map<String, Object> cacheMap = redisService.getCacheMap(client); |
| | | if(null == cacheMap){ |
| | |
| | | if (claims == null) { |
| | | throw new RuntimeException("令牌已过期或验证不正确!"); |
| | | } |
| | | String userkey = JwtUtils.getUserKey(claims); |
| | | boolean islogin = redisService.hasKey(getTokenKey(userkey)); |
| | | if (!islogin) { |
| | | throw new RuntimeException("登录状态已过期"); |
| | | } |
| | | // String userkey = JwtUtils.getUserKey(claims); |
| | | // boolean islogin = redisService.hasKey(getTokenKey(userkey)); |
| | | // if (!islogin) { |
| | | // throw new RuntimeException("登录状态已过期"); |
| | | // } |
| | | String userid = JwtUtils.getUserId(claims); |
| | | String username = JwtUtils.getUserName(claims); |
| | | if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) { |
| | | throw new RuntimeException("令牌验证失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 校验账户是否有效 |
| | | * @param request |
| | | * @throws Exception |
| | | */ |
| | | public void verifyAccount(ServerHttpRequest request) throws Exception{ |
| | | String token = getToken(request); |
| | | Claims claims = JwtUtils.parseToken(token); |
| | | String userid = JwtUtils.getUserId(claims); |
| | | String userType = JwtUtils.getUserType(claims); |
| | | //管理后台用户 |
| | | if ("system".equals(userType)) { |
| | | SysUser sysUser = sysUserClient.getSysUser(Long.valueOf(userid)).getData(); |
| | | if(null == sysUser || "2".equals(sysUser.getDelFlag())){ |
| | | throw new RuntimeException("无效的账户"); |
| | | } |
| | | if("1".equals(sysUser.getStatus())){ |
| | | throw new RuntimeException("账户已被停用,请联系系统管理员!"); |
| | | } |
| | | } |
| | | //小程序用户 |
| | | if ("applet".equals(userType)) { |
| | | TAppUser appUser = appUserClient.getUserById(Long.valueOf(userid)).getData(); |
| | | if(null == appUser || appUser.getDelFlag() || 3 == appUser.getStatus()){ |
| | | throw new RuntimeException("无效的账户"); |
| | | } |
| | | if(2 == appUser.getStatus()){ |
| | | throw new RuntimeException("账户已被冻结,请联系系统管理员!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | userService.resetPwd(user); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/getSysUserById") |
| | | public SysUser getSysUserById(@RequestParam("userId") Long userId){ |
| | | return userService.getById(userId); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.system.filter; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.model.TAppUser; |
| | | import com.ruoyi.common.core.constant.TokenConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import org.apache.logging.log4j.core.config.Order; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.*; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @Date 2024/8/23 11:22 |
| | | */ |
| | | @Order(-200) |
| | | @Component |
| | | public class AuthFilter implements Filter { |
| | | private static final Logger log = LoggerFactory.getLogger(AuthFilter.class); |
| | | |
| | | @Lazy |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | |
| | | @Lazy |
| | | @Resource |
| | | private ISysUserService sysUserService; |
| | | |
| | | |
| | | @Override |
| | | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { |
| | | HttpServletRequest request = (HttpServletRequest) servletRequest; |
| | | HttpServletResponse response = (HttpServletResponse) servletResponse; |
| | | String userid = request.getHeader("user_id"); |
| | | if(StringUtils.isEmpty(userid)){ |
| | | filterChain.doFilter(request, response); |
| | | return; |
| | | } |
| | | String userType = request.getHeader("user_type"); |
| | | //管理后台用户 |
| | | if ("system".equals(userType)) { |
| | | SysUser sysUser = sysUserService.getById(userid); |
| | | if(null == sysUser || "2".equals(sysUser.getDelFlag())){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"无效的账户"); |
| | | return; |
| | | } |
| | | if("1".equals(sysUser.getStatus())){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"账户已被停用,请联系系统管理员!"); |
| | | return; |
| | | } |
| | | } |
| | | //小程序用户 |
| | | if ("applet".equals(userType)) { |
| | | TAppUser appUser = appUserClient.getUserById(Long.valueOf(userid)).getData(); |
| | | if(null == appUser || appUser.getDelFlag() || 3 == appUser.getStatus()){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"无效的账户"); |
| | | return; |
| | | } |
| | | if(2 == appUser.getStatus()){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"账户已被冻结,请联系系统管理员!"); |
| | | return; |
| | | } |
| | | } |
| | | filterChain.doFilter(request, response); |
| | | } |
| | | |
| | | |
| | | |
| | | private void unauthorizedResponse(HttpServletResponse response, String msg) { |
| | | response.setStatus(HttpStatus.OK.value()); |
| | | response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE); |
| | | PrintWriter writer = null; |
| | | try { |
| | | writer = response.getWriter(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | writer.println(JSON.toJSONString(R.fail(msg))); |
| | | writer.flush(); |
| | | writer.close(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取请求token |
| | | */ |
| | | private String getToken(HttpServletRequest request) { |
| | | String token = request.getHeader(TokenConstants.AUTHENTICATION); |
| | | // 如果前端设置了令牌前缀,则裁剪掉前缀 |
| | | if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX)) { |
| | | token = token.replaceFirst(TokenConstants.PREFIX, StringUtils.EMPTY); |
| | | } |
| | | return token; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | <groupId>com.alibaba.cloud</groupId> |
| | | <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.alibaba.cloud</groupId> |
| | | <artifactId>spring-cloud-starter-alibaba-seata</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- SpringBoot Actuator --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-actuator</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- SpringCloud Loadbalancer --> |
| | | <dependency> |
| | | <groupId>org.springframework.cloud</groupId> |
| | | <artifactId>spring-cloud-loadbalancer</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Swagger UI --> |
| | | <dependency> |
| | |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.boot.web.servlet.ServletComponentScan; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.transaction.annotation.EnableTransactionManagement; |
| | | |
| | |
| | | @EnableRyFeignClients |
| | | @SpringBootApplication |
| | | @EnableScheduling//开启定时任务 |
| | | @ServletComponentScan |
| | | @EnableTransactionManagement//开启事务 |
| | | public class RuoYiAccountApplication { |
| | | public static void main(String[] args) { |
| | |
| | | package com.ruoyi.account.controller; |
| | | |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | |
| | | //签到加积分记录 |
| | | R<TIntegralRule> set = integralRuleClient.getSet(); |
| | | TIntegralRule data = set.getData(); |
| | | JSONObject jsonObject = JSON.parseObject(data.getAddVehiclesEarnsPoints()); |
| | | JSONObject jsonObject = JSON.parseObject(data.getSignInForPoints()); |
| | | //增加每日积分 |
| | | Integer points = 0; |
| | | Integer point = jsonObject.getInteger("num1"); |
| | |
| | | appUserService.updateById(byId); |
| | | return R.ok(); |
| | | } |
| | | //已签到日期 |
| | | @ApiOperation(value = "本月已签到日期", tags = {"小程序-个人中心-签到"}) |
| | | @GetMapping(value = "/user/has/sign") |
| | | public R<List<TAppUserSign>> hasSign() { |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | DateTime startOfMonth = DateUtil.beginOfMonth(new Date()); |
| | | DateTime endOfMonth = DateUtil.endOfMonth(new Date()); |
| | | // 获取用户的所有签到记录 |
| | | List<TAppUserSign> signRecords = signService.lambdaQuery() |
| | | .between(TAppUserSign::getSignDay, startOfMonth, endOfMonth) |
| | | .eq(TAppUserSign::getAppUserId, userId) |
| | | .orderByDesc(TAppUserSign::getSignDay) |
| | | .list(); |
| | | return R.ok(signRecords); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | //已连续签到多少天 |
| | | |
| | | @ApiOperation(value = "本月已连续签到天数", tags = {"小程序-个人中心-签到"}) |
| | | @GetMapping(value = "/user/continue/sign") |
| | | public R continueSign() { |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | int days = signDayUtil.calculateContinuousSignDays(userId); |
| | | return R.ok(days); |
| | | } |
| | | |
| | | |
| | | |
| | | //积分变化记录用 |
New file |
| | |
| | | package com.ruoyi.account.filter; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.model.TAppUser; |
| | | import com.ruoyi.account.service.TAppUserService; |
| | | import com.ruoyi.common.core.constant.TokenConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.JwtUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import io.jsonwebtoken.Claims; |
| | | import org.apache.logging.log4j.core.config.Order; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.*; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @Date 2024/8/23 11:22 |
| | | */ |
| | | @Order(-200) |
| | | @Component |
| | | public class AuthFilter implements Filter { |
| | | private static final Logger log = LoggerFactory.getLogger(AuthFilter.class); |
| | | |
| | | @Lazy |
| | | @Resource |
| | | private TAppUserService appUserService; |
| | | |
| | | @Lazy |
| | | @Resource |
| | | private SysUserClient sysUserClient; |
| | | |
| | | |
| | | @Override |
| | | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { |
| | | HttpServletRequest request = (HttpServletRequest) servletRequest; |
| | | HttpServletResponse response = (HttpServletResponse) servletResponse; |
| | | String userid = request.getHeader("user_id"); |
| | | if(StringUtils.isEmpty(userid)){ |
| | | filterChain.doFilter(request, response); |
| | | return; |
| | | } |
| | | String userType = request.getHeader("user_type"); |
| | | //管理后台用户 |
| | | if ("system".equals(userType)) { |
| | | SysUser sysUser = sysUserClient.getSysUser(Long.valueOf(userid)).getData(); |
| | | if(null == sysUser || "2".equals(sysUser.getDelFlag())){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"无效的账户"); |
| | | return; |
| | | } |
| | | if("1".equals(sysUser.getStatus())){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"账户已被停用,请联系系统管理员!"); |
| | | return; |
| | | } |
| | | } |
| | | //小程序用户 |
| | | if ("applet".equals(userType)) { |
| | | TAppUser appUser = appUserService.getById(userid); |
| | | if(null == appUser || appUser.getDelFlag() || 3 == appUser.getStatus()){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"无效的账户"); |
| | | return; |
| | | } |
| | | if(2 == appUser.getStatus()){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"账户已被冻结,请联系系统管理员!"); |
| | | return; |
| | | } |
| | | } |
| | | filterChain.doFilter(request, response); |
| | | } |
| | | |
| | | |
| | | |
| | | private void unauthorizedResponse(HttpServletResponse response, String msg) { |
| | | response.setStatus(HttpStatus.OK.value()); |
| | | response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE); |
| | | PrintWriter writer = null; |
| | | try { |
| | | writer = response.getWriter(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | writer.println(JSON.toJSONString(R.fail(msg))); |
| | | writer.flush(); |
| | | writer.close(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取请求token |
| | | */ |
| | | private String getToken(HttpServletRequest request) { |
| | | String token = request.getHeader(TokenConstants.AUTHENTICATION); |
| | | // 如果前端设置了令牌前缀,则裁剪掉前缀 |
| | | if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX)) { |
| | | token = token.replaceFirst(TokenConstants.PREFIX, StringUtils.EMPTY); |
| | | } |
| | | return token; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-actuator</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- SpringCloud Loadbalancer --> |
| | | <dependency> |
| | | <groupId>org.springframework.cloud</groupId> |
| | | <artifactId>spring-cloud-loadbalancer</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Swagger UI --> |
| | | <dependency> |
| | |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.boot.web.servlet.ServletComponentScan; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.transaction.annotation.EnableTransactionManagement; |
| | | |
| | |
| | | @EnableRyFeignClients |
| | | @SpringBootApplication |
| | | @EnableScheduling//开启定时任务 |
| | | @ServletComponentScan |
| | | @EnableTransactionManagement//开启事务 |
| | | public class RuoYiChargingPileApplication { |
| | | public static void main(String[] args) { |
New file |
| | |
| | | package com.ruoyi.chargingPile.filter; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.model.TAppUser; |
| | | import com.ruoyi.common.core.constant.TokenConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.JwtUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import io.jsonwebtoken.Claims; |
| | | import org.apache.logging.log4j.core.config.Order; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.*; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | import java.io.UnsupportedEncodingException; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @Date 2024/8/23 11:22 |
| | | */ |
| | | @Order(-200) |
| | | @Component |
| | | public class AuthFilter implements Filter { |
| | | private static final Logger log = LoggerFactory.getLogger(AuthFilter.class); |
| | | |
| | | @Lazy |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | |
| | | @Lazy |
| | | @Resource |
| | | private SysUserClient sysUserClient; |
| | | |
| | | |
| | | @Override |
| | | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { |
| | | HttpServletRequest request = (HttpServletRequest) servletRequest; |
| | | HttpServletResponse response = (HttpServletResponse) servletResponse; |
| | | String userid = request.getHeader("user_id"); |
| | | if(StringUtils.isEmpty(userid)){ |
| | | filterChain.doFilter(request, response); |
| | | return; |
| | | } |
| | | String userType = request.getHeader("user_type"); |
| | | //管理后台用户 |
| | | if ("system".equals(userType)) { |
| | | SysUser sysUser = sysUserClient.getSysUser(Long.valueOf(userid)).getData(); |
| | | if(null == sysUser || "2".equals(sysUser.getDelFlag())){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"无效的账户"); |
| | | return; |
| | | } |
| | | if("1".equals(sysUser.getStatus())){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"账户已被停用,请联系系统管理员!"); |
| | | return; |
| | | } |
| | | } |
| | | //小程序用户 |
| | | if ("applet".equals(userType)) { |
| | | TAppUser appUser = appUserClient.getUserById(Long.valueOf(userid)).getData(); |
| | | if(null == appUser || appUser.getDelFlag() || 3 == appUser.getStatus()){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"无效的账户"); |
| | | return; |
| | | } |
| | | if(2 == appUser.getStatus()){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"账户已被冻结,请联系系统管理员!"); |
| | | return; |
| | | } |
| | | } |
| | | filterChain.doFilter(request, response); |
| | | } |
| | | |
| | | |
| | | |
| | | private void unauthorizedResponse(HttpServletResponse response, String msg) { |
| | | response.setStatus(HttpStatus.OK.value()); |
| | | response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE); |
| | | PrintWriter writer = null; |
| | | try { |
| | | writer = response.getWriter(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | writer.println(JSON.toJSONString(R.fail(msg))); |
| | | writer.flush(); |
| | | writer.close(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取请求token |
| | | */ |
| | | private String getToken(HttpServletRequest request) { |
| | | String token = request.getHeader(TokenConstants.AUTHENTICATION); |
| | | // 如果前端设置了令牌前缀,则裁剪掉前缀 |
| | | if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX)) { |
| | | token = token.replaceFirst(TokenConstants.PREFIX, StringUtils.EMPTY); |
| | | } |
| | | return token; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | <groupId>com.alibaba.cloud</groupId> |
| | | <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.alibaba.cloud</groupId> |
| | | <artifactId>spring-cloud-starter-alibaba-seata</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- SpringBoot Actuator --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-actuator</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- SpringCloud Loadbalancer --> |
| | | <dependency> |
| | | <groupId>org.springframework.cloud</groupId> |
| | | <artifactId>spring-cloud-loadbalancer</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Swagger UI --> |
| | | <dependency> |
| | |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-actuator</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- SpringCloud Loadbalancer --> |
| | | <dependency> |
| | | <groupId>org.springframework.cloud</groupId> |
| | | <artifactId>spring-cloud-loadbalancer</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Swagger UI --> |
| | | <dependency> |
| | |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.boot.web.servlet.ServletComponentScan; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.transaction.annotation.EnableTransactionManagement; |
| | | |
| | |
| | | @EnableRyFeignClients |
| | | @SpringBootApplication |
| | | @EnableScheduling//开启定时任务 |
| | | @ServletComponentScan |
| | | @EnableTransactionManagement//开启事务 |
| | | public class RuoYiOrderApplication { |
| | | public static void main(String[] args) { |
| | |
| | | case 1: |
| | | for (int i = 0; i < split.length-1; i++) { |
| | | Integer reduce = tShoppingOrderService.list(new QueryWrapper<TShoppingOrder>() |
| | | .eq("order_type",1) |
| | | .eq("goods_id", split[i]) |
| | | .eq("payment_status", 2) |
| | | .ne("refund_status", 2)) |
| | |
| | | case 2: |
| | | for (int i = 0; i < split.length-1; i++) { |
| | | Integer reduce = exchangeOrderService.list(new QueryWrapper<TExchangeOrder>() |
| | | .eq("order_type",1) |
| | | .ne("status",4) |
| | | .eq("goods_id", split[i]) |
| | | ) |
| | | .stream().map(TExchangeOrder::getPurchaseQuantity).reduce(0, Integer::sum); |
New file |
| | |
| | | package com.ruoyi.order.filter; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.model.TAppUser; |
| | | import com.ruoyi.common.core.constant.TokenConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.JwtUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import io.jsonwebtoken.Claims; |
| | | import org.apache.logging.log4j.core.config.Order; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.*; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @Date 2024/8/23 11:22 |
| | | */ |
| | | @Order(-200) |
| | | @Component |
| | | public class AuthFilter implements Filter { |
| | | private static final Logger log = LoggerFactory.getLogger(AuthFilter.class); |
| | | |
| | | @Lazy |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | |
| | | @Lazy |
| | | @Resource |
| | | private SysUserClient sysUserClient; |
| | | |
| | | |
| | | @Override |
| | | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { |
| | | HttpServletRequest request = (HttpServletRequest) servletRequest; |
| | | HttpServletResponse response = (HttpServletResponse) servletResponse; |
| | | String userid = request.getHeader("user_id"); |
| | | if(StringUtils.isEmpty(userid)){ |
| | | filterChain.doFilter(request, response); |
| | | return; |
| | | } |
| | | String userType = request.getHeader("user_type"); |
| | | //管理后台用户 |
| | | if ("system".equals(userType)) { |
| | | SysUser sysUser = sysUserClient.getSysUser(Long.valueOf(userid)).getData(); |
| | | if(null == sysUser || "2".equals(sysUser.getDelFlag())){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"无效的账户"); |
| | | return; |
| | | } |
| | | if("1".equals(sysUser.getStatus())){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"账户已被停用,请联系系统管理员!"); |
| | | return; |
| | | } |
| | | } |
| | | //小程序用户 |
| | | if ("applet".equals(userType)) { |
| | | TAppUser appUser = appUserClient.getUserById(Long.valueOf(userid)).getData(); |
| | | if(null == appUser || appUser.getDelFlag() || 3 == appUser.getStatus()){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"无效的账户"); |
| | | return; |
| | | } |
| | | if(2 == appUser.getStatus()){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"账户已被冻结,请联系系统管理员!"); |
| | | return; |
| | | } |
| | | } |
| | | filterChain.doFilter(request, response); |
| | | } |
| | | |
| | | |
| | | |
| | | private void unauthorizedResponse(HttpServletResponse response, String msg) { |
| | | response.setStatus(HttpStatus.OK.value()); |
| | | response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE); |
| | | PrintWriter writer = null; |
| | | try { |
| | | writer = response.getWriter(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | writer.println(JSON.toJSONString(R.fail(msg))); |
| | | writer.flush(); |
| | | writer.close(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取请求token |
| | | */ |
| | | private String getToken(HttpServletRequest request) { |
| | | String token = request.getHeader(TokenConstants.AUTHENTICATION); |
| | | // 如果前端设置了令牌前缀,则裁剪掉前缀 |
| | | if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX)) { |
| | | token = token.replaceFirst(TokenConstants.PREFIX, StringUtils.EMPTY); |
| | | } |
| | | return token; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-actuator</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- SpringCloud Loadbalancer --> |
| | | <dependency> |
| | | <groupId>org.springframework.cloud</groupId> |
| | | <artifactId>spring-cloud-loadbalancer</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Swagger UI --> |
| | | <dependency> |
| | |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.boot.web.servlet.ServletComponentScan; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.transaction.annotation.EnableTransactionManagement; |
| | | |
| | |
| | | @EnableRyFeignClients |
| | | @SpringBootApplication |
| | | @EnableScheduling//开启定时任务 |
| | | @ServletComponentScan |
| | | @EnableTransactionManagement//开启事务 |
| | | public class RuoYiOtherApplication { |
| | | public static void main(String[] args) { |
| | |
| | | |
| | | |
| | | @GetMapping("/getSet") |
| | | @ApiOperation(tags = {"管理后台-积分管理"},value = "获取积分设置") |
| | | @ApiOperation(tags = {"管理后台-积分管理","小程序-个人中心-签到"},value = "获取积分设置") |
| | | public R<TIntegralRule> getSet() { |
| | | TIntegralRule res = integralRuleService.getOne(new QueryWrapper<>()); |
| | | return R.ok(res); |
New file |
| | |
| | | package com.ruoyi.other.filter; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.model.TAppUser; |
| | | import com.ruoyi.common.core.constant.TokenConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.JwtUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import io.jsonwebtoken.Claims; |
| | | import org.apache.logging.log4j.core.config.Order; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.*; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @Date 2024/8/23 11:22 |
| | | */ |
| | | @Order(-200) |
| | | @Component |
| | | public class AuthFilter implements Filter { |
| | | private static final Logger log = LoggerFactory.getLogger(AuthFilter.class); |
| | | |
| | | @Lazy |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | |
| | | @Lazy |
| | | @Resource |
| | | private SysUserClient sysUserClient; |
| | | |
| | | |
| | | @Override |
| | | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { |
| | | HttpServletRequest request = (HttpServletRequest) servletRequest; |
| | | HttpServletResponse response = (HttpServletResponse) servletResponse; |
| | | String userid = request.getHeader("user_id"); |
| | | if(StringUtils.isEmpty(userid)){ |
| | | filterChain.doFilter(request, response); |
| | | return; |
| | | } |
| | | String userType = request.getHeader("user_type"); |
| | | //管理后台用户 |
| | | if ("system".equals(userType)) { |
| | | SysUser sysUser = sysUserClient.getSysUser(Long.valueOf(userid)).getData(); |
| | | if(null == sysUser || "2".equals(sysUser.getDelFlag())){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"无效的账户"); |
| | | return; |
| | | } |
| | | if("1".equals(sysUser.getStatus())){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"账户已被停用,请联系系统管理员!"); |
| | | return; |
| | | } |
| | | } |
| | | //小程序用户 |
| | | if ("applet".equals(userType)) { |
| | | TAppUser appUser = appUserClient.getUserById(Long.valueOf(userid)).getData(); |
| | | if(null == appUser || appUser.getDelFlag() || 3 == appUser.getStatus()){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"无效的账户"); |
| | | return; |
| | | } |
| | | if(2 == appUser.getStatus()){ |
| | | log.error("[账户异常处理]请求账户id:{}", userid); |
| | | unauthorizedResponse(response,"账户已被冻结,请联系系统管理员!"); |
| | | return; |
| | | } |
| | | } |
| | | filterChain.doFilter(request, response); |
| | | } |
| | | |
| | | |
| | | |
| | | private void unauthorizedResponse(HttpServletResponse response, String msg) { |
| | | response.setStatus(HttpStatus.OK.value()); |
| | | response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE); |
| | | PrintWriter writer = null; |
| | | try { |
| | | writer = response.getWriter(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | writer.println(JSON.toJSONString(R.fail(msg))); |
| | | writer.flush(); |
| | | writer.close(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取请求token |
| | | */ |
| | | private String getToken(HttpServletRequest request) { |
| | | String token = request.getHeader(TokenConstants.AUTHENTICATION); |
| | | // 如果前端设置了令牌前缀,则裁剪掉前缀 |
| | | if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX)) { |
| | | token = token.replaceFirst(TokenConstants.PREFIX, StringUtils.EMPTY); |
| | | } |
| | | return token; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import com.ruoyi.other.mapper.TVipMapper; |
| | | import com.ruoyi.other.service.TVipService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.poi.util.StringUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.util.List; |
| | | |
| | |
| | | |
| | | for (TVip tVip : list) { |
| | | String coupon = tVip.getCoupon(); |
| | | JSONArray jsonArray = JSONObject.parseArray(coupon); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | JSONObject jsonObject = jsonArray.getJSONObject(i); |
| | | Integer id = jsonObject.getInteger("id"); |
| | | Integer number = jsonObject.getInteger("number"); |
| | | TCoupon tCoupon = tCouponMapper.selectById(id); |
| | | if (tCoupon!=null){ |
| | | stringBuilder.append(tCoupon.getName()).append("*").append(number).append(";"); |
| | | if (StringUtils.hasLength(coupon)){ |
| | | JSONArray jsonArray = JSONObject.parseArray(coupon); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | JSONObject jsonObject = jsonArray.getJSONObject(i); |
| | | Integer id = jsonObject.getInteger("id"); |
| | | Integer number = jsonObject.getInteger("number"); |
| | | TCoupon tCoupon = tCouponMapper.selectById(id); |
| | | if (tCoupon!=null){ |
| | | stringBuilder.append(tCoupon.getName()).append("*").append(number).append(";"); |
| | | } |
| | | } |
| | | tVip.setCouponName(stringBuilder.toString()); |
| | | } |
| | | tVip.setCouponName(stringBuilder.toString()); |
| | | } |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | |
| | | <result column="status" property="status" /> |
| | | <result column="create_time" property="createTime" /> |
| | | <result column="del_flag" property="delFlag" /> |
| | | <result column="applet_id" property="appletId" /> |
| | | <result column="applet_name" property="appletName" /> |
| | | </resultMap> |
| | | |
| | | <!-- 通用查询结果列 --> |
| | | <sql id="Base_Column_List"> |
| | | id, name, img, start_time, end_time, position, jump_type, jump_url, status, create_time, del_flag |
| | | id, name, img, start_time, end_time, position, jump_type, jump_url, status, create_time, del_flag, |
| | | applet_id, applet_name |
| | | </sql> |
| | | <select id="pageList" resultType="com.ruoyi.other.api.domain.TAdvertising"> |
| | | select * from t_advertising |
| | |
| | | <groupId>com.alibaba.cloud</groupId> |
| | | <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.alibaba.cloud</groupId> |
| | | <artifactId>spring-cloud-starter-alibaba-seata</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- SpringBoot Actuator --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-actuator</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- SpringCloud Loadbalancer --> |
| | | <dependency> |
| | | <groupId>org.springframework.cloud</groupId> |
| | | <artifactId>spring-cloud-loadbalancer</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- Swagger UI --> |
| | | <dependency> |