Browse Source

扫码报警上报事件处理

develop
zhaoxianglong 10 months ago
parent
commit
4b154d0413
  1. 4
      ruoyi-admin/src/main/resources/application.yml
  2. 53
      ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
  3. 63
      zc-business/src/main/java/com/zc/business/controller/CodeScanningAlarmController.java

4
ruoyi-admin/src/main/resources/application.yml

@ -180,3 +180,7 @@ iot:
# #连接池最大阻塞等待时间(使用负值表示没有限制) # #连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1ms max-wait: -1ms
# 允许访问的ip地址
allowed:
ips: 10.0.81.202,10.168.73.54,10.168.71.194

53
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@ -1,6 +1,7 @@
package com.ruoyi.framework.config; package com.ruoyi.framework.config;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
@ -13,24 +14,26 @@ import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.LogoutFilter; import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.web.filter.CorsFilter; import org.springframework.web.filter.CorsFilter;
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter; import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl; import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl; import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
/** /**
* spring security配置 * spring security配置
*
*/ */
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter public class SecurityConfig extends WebSecurityConfigurerAdapter {
{
/** /**
* 自定义用户认证逻辑 * 自定义用户认证逻辑
*/ */
@Autowired @Autowired
private UserDetailsService userDetailsService; private UserDetailsService userDetailsService;
/** /**
* 认证失败处理类 * 认证失败处理类
*/ */
@ -48,13 +51,32 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
*/ */
@Autowired @Autowired
private JwtAuthenticationTokenFilter authenticationTokenFilter; private JwtAuthenticationTokenFilter authenticationTokenFilter;
/** /**
* 跨域过滤器 * 跨域过滤器
*/ */
@Autowired @Autowired
private CorsFilter corsFilter; private CorsFilter corsFilter;
/**
* 允许访问的ip地址
*/
@Value("${allowed.ips}")
private String allowedIPs;
// 定义一个RequestMatcher
RequestMatcher requestMatcher = new RequestMatcher() {
@Override
public boolean matches(HttpServletRequest request) {
// 获取请求的IP
String requestIP = request.getRemoteAddr();
// 将配置文件中的IP字符串分割为数组
String[] ips = allowedIPs.split(",");
// 检查请求的IP是否在允许的IP数组中
return Arrays.asList(ips).contains(requestIP);
}
};
/** /**
* 解决 无法直接注入 AuthenticationManager * 解决 无法直接注入 AuthenticationManager
* *
@ -63,8 +85,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
*/ */
@Bean @Bean
@Override @Override
public AuthenticationManager authenticationManagerBean() throws Exception public AuthenticationManager authenticationManagerBean() throws Exception {
{
return super.authenticationManagerBean(); return super.authenticationManagerBean();
} }
@ -84,8 +105,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
* authenticated | 用户登录后可访问 * authenticated | 用户登录后可访问
*/ */
@Override @Override
protected void configure(HttpSecurity httpSecurity) throws Exception protected void configure(HttpSecurity httpSecurity) throws Exception {
{
httpSecurity httpSecurity
// CSRF禁用,因为不使用session // CSRF禁用,因为不使用session
.csrf().disable() .csrf().disable()
@ -117,11 +137,14 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 添加统一支付 回调接口 // 添加统一支付 回调接口
.antMatchers("/payment/wxPay/notify").anonymous() .antMatchers("/payment/wxPay/notify").anonymous()
// 滑块验证码 // 滑块验证码
.antMatchers( "/captcha/get", "/captcha/check", "/captchaConfig").anonymous() .antMatchers("/captcha/get", "/captcha/check", "/captchaConfig").anonymous()
// license // license
.antMatchers("/license/identityCode", "/license/authentication").anonymous() .antMatchers("/license/identityCode", "/license/authentication").anonymous()
// 第三方、小程序、APP // 第三方、小程序、APP
.antMatchers("/api/**").anonymous() //.antMatchers("/api/**").anonymous()
// 对于满足requestMatcher的请求,允许所有用户访问。
.requestMatchers(requestMatcher).permitAll()
// 除上面外的所有请求全部需要鉴权认证 // 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated() .anyRequest().authenticated()
@ -139,8 +162,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
* 强散列哈希加密实现 * 强散列哈希加密实现
*/ */
@Bean @Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() public BCryptPasswordEncoder bCryptPasswordEncoder() {
{
return new BCryptPasswordEncoder(); return new BCryptPasswordEncoder();
} }
@ -148,8 +170,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
* 身份认证接口 * 身份认证接口
*/ */
@Override @Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception protected void configure(AuthenticationManagerBuilder auth) throws Exception {
{
auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder()); auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
} }
} }

63
zc-business/src/main/java/com/zc/business/controller/CodeScanningAlarmController.java

@ -0,0 +1,63 @@
package com.zc.business.controller;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.zc.business.domain.DcWarning;
import com.zc.business.service.IDcWarningService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Objects;
/**
* License
*
* @author Athena-xiepufeng
*/
@Api(tags = "扫码报警")
@RestController
@RequestMapping("/codeScanningAlarm")
public class CodeScanningAlarmController extends BaseController {
@Resource
private IDcWarningService dcWarningService;
/**
* 扫码报警事件回调函数
*
* @param returnParameters 事件回参
* @return 结果
*/
@PostMapping(value = "/event")
public AjaxResult codeScanningAlarmControllerEvent(@RequestBody Map<String, Object> returnParameters) {
DcWarning dcWarning = new DcWarning();
//设置事件Id UUID无下划线格式32
String uuid = IdUtils.fastSimpleUUID();
dcWarning.setId(uuid);
dcWarning.setStakeMark(String.valueOf(returnParameters.get("stakeNum")));
String roadCode = String.valueOf(returnParameters.get("roadCode"));
dcWarning.setDirection(Objects.equals(roadCode, "1") ? "3" : "1");
String createTime = String.valueOf(returnParameters.get("createTime"));
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmXXX");
try {
dcWarning.setWarningTime(format.parse(createTime));
} catch (ParseException e) {
dcWarning.setWarningTime(new Date());
}
dcWarning.setCreateTime(new Date());
int warningType = Integer.parseInt(String.valueOf(returnParameters.get("accidentType"))) >= 4 ? 10 : 11;
dcWarning.setWarningType(warningType);
String warningTitle = "济荷高速:" + (Objects.equals(roadCode, "1") ? "济南方向" : "菏泽方向") + "发生" + (warningType == 10 ? "交通事故事件" : "车辆故障事件");
dcWarning.setWarningTitle(warningTitle);
dcWarning.setOtherConfig(returnParameters.toString());
dcWarning.setWarningSource(5);
dcWarning.setWarningState(1);
return AjaxResult.success(dcWarningService.insertDcWarning(dcWarning));
}
}
Loading…
Cancel
Save