修改配置文件;

添加算法平台数据库获取数据接口;
添加预警时间平台推送接口;
master
吴顺杰 2 years ago
parent becef3054e
commit 9579ffb31f

@ -30,12 +30,17 @@
<poi.version>4.1.2</poi.version>
<velocity.version>2.3</velocity.version>
<jwt.version>0.9.1</jwt.version>
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
</properties>
<!-- 依赖声明 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<!-- SpringBoot的依赖配置-->
<dependency>
<groupId>org.springframework.boot</groupId>

@ -25,7 +25,13 @@
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.23</version>
</dependency>
@ -39,7 +45,7 @@
<!-- swagger3-->
<!-- Mysql驱动包 -->
<!-- Mysql驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
@ -86,15 +92,15 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>

@ -0,0 +1,106 @@
package com.ruoyi.pt.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.pt.domain.Events;
import com.ruoyi.pt.service.EventsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
/**
* (Events)
*
* @author wu
* @since 2023-12-15 23:19:46
*/
@RestController
@RequestMapping("remoteCall/events")
@Api(tags = "事件集合表")
@Transactional(rollbackFor = Exception.class)
public class EventsController extends BaseController {
/**
*
*/
@Resource
private EventsService eventsService;
/**
*
*
* @param page
* @param events
* @return
*/
@GetMapping
@ApiOperation(value = "分页条件查询事件集合表", response = Events.class)
public AjaxResult page(Page<Events> page, Events events) {
return success(eventsService.page(page, new QueryWrapper<>(events)));
}
/**
*
*
* @param id
* @return
*/
@GetMapping("{id}")
@ApiOperation(value = "通过主键查询单条事件集合表", response = Events.class)
public AjaxResult getById(@PathVariable Serializable id) {
return success(eventsService.getById(id));
}
/**
*
*
* @param events
* @return
*/
@PostMapping
@ApiOperation(value = "新增事件集合表", response = Events.class)
public AjaxResult insert(@RequestBody Events events) {
return success(eventsService.save(events));
}
/**
*
*
* @param events
* @return
*/
@PutMapping
@ApiOperation(value = "修改事件集合表")
public AjaxResult update(@RequestBody Events events) {
return success(eventsService.updateById(events));
}
/**
*
*
* @param idList
* @return
*/
@DeleteMapping
@ApiOperation(value = "删除事件集合表")
public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
return success(eventsService.removeByIds(idList));
}
}

@ -0,0 +1,54 @@
package com.ruoyi.pt.controller;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.pt.service.RemoteCallsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
*
*
* @author wu
* @since 2023/12/15 13:41
*/
@Api(tags = "远程推送算法平台数据⼊")
@RestController
@RequestMapping("/remoteCall")
public class RemoteCallsController extends BaseController {
@Resource
private RemoteCallsService remoteCallsService;
/**
* accessToken
*
* @return
*/
@ApiOperation(value = "获取公共accessToken")
@GetMapping("/getAccessToken")
public AjaxResult getAccessToken() {
return success(remoteCallsService.getAccessToken());
}
/**
*
*
* @return
*/
@ApiOperation(value = "事件进度推送接口")
@PostMapping("/imports")
public AjaxResult imports() {
remoteCallsService.imports();
return success();
}
}

@ -0,0 +1,102 @@
package com.ruoyi.pt.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* (Events)
*
* @author wu
* @since 2023-12-15 22:58:42
*/
@Data
@ApiModel("事件集合表实体类")
@TableName(value = "Events")
public class Events implements Serializable {
private static final long serialVersionUID = -80395930488019068L;
/**
*
*/
@ApiModelProperty(value = "事件集合编号(主键)")
@TableField(value = "innerEventId")
private String innerEventId;
/**
*
*/
@ApiModelProperty(value = "事件消息标题")
private String title;
/**
*
*/
@ApiModelProperty(value = "事件类型编码")
@TableField(value = "msgType")
private String msgType;
/**
*
*/
@ApiModelProperty(value = "事件类型名称")
@TableField(value = "msgTypeName")
private String msgTypeName;
/**
*
*/
@ApiModelProperty(value = "案件类型编码")
@TableField(value = "scenceType")
private Integer scenceType;
/**
*
*/
@ApiModelProperty(value = "案件类型名称")
@TableField(value = "scenceTypeName")
private String scenceTypename;
/**
*
*/
@ApiModelProperty(value = "第一次预警时间")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(value = "firstWarnTime")
private Date firstWarnTimeDate;
/**
*
*/
@ApiModelProperty(value = "事件发生时间")
@TableField(value = "eventTime")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date eventTimeDate;
/**
*
*/
@ApiModelProperty(value = "预警因素")
@TableField(value = "warnFactor")
private String warnFactor;
/**
*
*/
@ApiModelProperty(value = "预警关联的事件单号")
@TableField(value = "relationNums")
private String relationNums;
}

@ -0,0 +1,118 @@
package com.ruoyi.pt.domain.dto;
import cn.hutool.core.annotation.Alias;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
*
*
* @author wu
* @since 2023/12/15 16:35
*/
@Data
public class RemoteCallsDTO implements Serializable {
/**
*
*/
private String innerEventId;
/**
* 15
* 320505000000000
*/
private String areaCode = "320505000000000";
/**
*
*
* : sjsffx
*/
private String scence = "sjsffx";
/**
*
*/
private String title;
/**
*
*/
@Alias("title")
private String content;
/**
* yyyy-MM-dd HH:mm:ss
*/
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date eventTimeDate;
private String eventTime;
private String firstWarnTime;
/**
*
*/
private String msgType;
/**
*
*/
private String msgTypeName;
/**
* 1 2
* 3
*
*/
private Integer executeType = 2;
/**
* :
* 1
* 0
*/
private Integer remindStatus = 0;
/**
* 1234
* 56诿7
*
*
*/
private String eventLabel = "1";
/**
*
*/
private String scenceType;
/**
*
*/
private String scenceTypename;
/**
* ()
*/
private String relationNums;
/**
*
*/
private String warnFactor;
/**
* yyyy-MM-dd HH:mm:ss
*/
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date firstWarnTimeDate;
}

@ -0,0 +1,26 @@
package com.ruoyi.pt.domain.response;
import lombok.Data;
import java.io.Serializable;
/**
*
*
* @author wu
* @since 2023/12/15 23:49
*/
@Data
public class RemoteCallsAccessTokenResponse implements Serializable {
private String accessToken;
private String tokenType;
private Integer expiresIn;
private String scope;
}

@ -0,0 +1,27 @@
package com.ruoyi.pt.domain.response;
import lombok.Data;
import java.io.Serializable;
/**
*
*
* @author wu
* @since 2023/12/15 23:49
*/
@Data
public class RemoteCallsResponse implements Serializable {
private Boolean success;
private String errorCode;
private String errorMsg;
private RemoteCallsAccessTokenResponse data;
private String requestId;
}

@ -0,0 +1,15 @@
package com.ruoyi.pt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.pt.domain.Events;
/**
* (Events)访
*
* @author wu
* @since 2023-12-15 22:58:42
*/
public interface EventsMapper extends BaseMapper<Events> {
}

@ -0,0 +1,15 @@
package com.ruoyi.pt.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.pt.domain.Events;
/**
* (Events)
*
* @author wu
* @since 2023-12-15 22:58:42
*/
public interface EventsService extends IService<Events> {
}

@ -0,0 +1,22 @@
package com.ruoyi.pt.service;
/**
*
*
* @author wu
* @since 2023/12/15 16:02
*/
public interface RemoteCallsService {
/**
* accessToken
*
* @return accessToken
*/
String getAccessToken();
/**
*
*/
void imports();
}

@ -0,0 +1,19 @@
package com.ruoyi.pt.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.pt.mapper.EventsMapper;
import com.ruoyi.pt.domain.Events;
import com.ruoyi.pt.service.EventsService;
import org.springframework.stereotype.Service;
/**
* (Events)
*
* @author wu
* @since 2023-12-15 22:58:42
*/
@Service("eventsService")
public class EventsServiceImpl extends ServiceImpl<EventsMapper, Events> implements EventsService {
}

@ -0,0 +1,119 @@
package com.ruoyi.pt.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.pt.domain.Events;
import com.ruoyi.pt.domain.dto.RemoteCallsDTO;
import com.ruoyi.pt.domain.response.RemoteCallsResponse;
import com.ruoyi.pt.service.EventsService;
import com.ruoyi.pt.service.RemoteCallsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author wu
* @since 2023/12/15 16:03
*/
@Service(value = "RemoteCallsService")
public class RemoteCallsServiceImpl implements RemoteCallsService {
public static final Logger log = LoggerFactory.getLogger(RemoteCallsServiceImpl.class);
@Value("${remote.url}")
private String url;
@Value("${remote.appKey}")
private String appKey;
@Value("${remote.appSecret}")
private String appSecret;
@Value("${remote.grantType}")
private String grantType;
@Resource
private EventsService eventsService;
/**
* map
*
* @return map
*/
private Map<String, Object> getMapValue() {
Map<String, Object> map = new HashMap<>();
map.put("appKey", appKey);
map.put("appSecret", appSecret);
map.put("grantType", grantType);
return map;
}
/**
* accessToken
*
* @return accessToken
*/
@Override
public String getAccessToken() {
Map<String, Object> form = getMapValue();
String body = HttpRequest.post(url + "/auth/oauth/token").form(form).execute().body();
RemoteCallsResponse res = JSONUtil.toBean(body, RemoteCallsResponse.class);
log.info(body);
return res.getData().getAccessToken();
}
/**
*
*/
@Override
public void imports() {
// String accessToken = this.getAccessToken();
// 初始化MyBatis-Plus的分页对象 查询第1页每页100条
Page<Events> page = new Page<>(1, 100);
// 创建查询条件
QueryWrapper<Events> queryWrapper = new QueryWrapper<>();
// 创建SimpleDateFormat对象指定日期格式为yyyy-MM-dd HH:mm:ss
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 循环获取所有数据
while (true) {
IPage<Events> dataPage = eventsService.page(page, queryWrapper);
List<Events> data = dataPage.getRecords();
List<RemoteCallsDTO> dtos = BeanUtil.copyToList(data, RemoteCallsDTO.class);
dtos.forEach(x -> {
x.setContent(x.getTitle());
// 使用SimpleDateFormat对象将Date对象格式化为字符串
String firstWarnTime = sdf.format(x.getFirstWarnTimeDate());
String eventTime = sdf.format(x.getEventTimeDate());
x.setContent(x.getTitle());
x.setFirstWarnTime(firstWarnTime);
x.setEventTime(eventTime);
});
String jsonStr = JSONUtil.toJsonStr(dtos);
String body = HttpRequest.post(url + "/gateway/event/event/eventProgress/imports")
// .header("Authorization", "Bearer " + accessToken)
.body(jsonStr)
.execute().body();
log.info(body);
// 判断是否还有下一页
if (dataPage.getPages() > dataPage.getCurrent()) {
// 设置下一页的页码
page.setCurrent(page.getCurrent() + 1);
} else {
break; // 已经获取完所有数据,结束循环
}
}
}
}

@ -0,0 +1,65 @@
# 数据源配置
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
druid:
# 主库数据源
master:
url: jdbc:mysql://localhost:3306/public_platform?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: 123456
# 从库数据源
slave:
# 从数据源开关/默认关闭
enabled: false
url:
username:
password:
# 初始连接数
initialSize: 5
# 最小连接池数量
minIdle: 10
# 最大连接池数量
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置连接超时时间
connectTimeout: 30000
# 配置网络超时时间
socketTimeout: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
# 配置一个连接在池中最大生存的时间,单位是毫秒
maxEvictableIdleTimeMillis: 900000
# 配置检测连接是否有效
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
webStatFilter:
enabled: true
statViewServlet:
enabled: true
# 设置白名单,不填则允许所有访问
allow:
url-pattern: /druid/*
# 控制台管理用户名和密码
login-username: ruoyi
login-password: 123456
filter:
stat:
enabled: true
# 慢SQL记录
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: true
wall:
config:
multi-statement-allow: true
# 开发环境配置
server:
# 服务器的HTTP端口默认为8080
port: 9002

@ -58,4 +58,8 @@ spring:
merge-sql: true
wall:
config:
multi-statement-allow: true
multi-statement-allow: true
# 开发环境配置
server:
# 服务器的HTTP端口默认为8080
port: 9102

@ -17,8 +17,6 @@ ruoyi:
# 开发环境配置
server:
# 服务器的HTTP端口默认为8080
port: 9102
servlet:
# 应用的访问路径
context-path: /api
@ -54,7 +52,7 @@ spring:
# 国际化资源文件路径
basename: i18n/messages
profiles:
active: druid
active: prod
# 文件上传
servlet:
multipart:
@ -128,3 +126,9 @@ xss:
excludes: /system/notice
# 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/*
remote:
url: http://4.15.24.101:10443
appKey: 7ae6c089a348b3565af38313f5610968
appSecret: 633e549c5b382cb8da14e36d9eeca3bc
grantType: client_credentials

@ -2,16 +2,20 @@ package com.ruoyi.common.constant;
/**
* key
*
*
* @author ruoyi
*/
public class CacheConstants
{
public class CacheConstants {
/**
* redis key
*/
public static final String LOGIN_TOKEN_KEY = "login_tokens:";
/**
* redis key
*/
public static final String REMOTE_TOKEN_KEY = "remote_token:";
/**
* redis key
*/

@ -1,11 +1,5 @@
package com.ruoyi.common.core.redis;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundSetOperations;
import org.springframework.data.redis.core.HashOperations;
@ -13,64 +7,66 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* spring redis
*
* @author ruoyi
**/
@SuppressWarnings(value = { "unchecked", "rawtypes" })
@SuppressWarnings(value = {"unchecked", "rawtypes"})
@Component
public class RedisCache
{
public class RedisCache {
@Autowired
public RedisTemplate redisTemplate;
/**
* IntegerString
*
* @param key
* @param key
* @param value
*/
public <T> void setCacheObject(final String key, final T value)
{
public <T> void setCacheObject(final String key, final T value) {
redisTemplate.opsForValue().set(key, value);
}
/**
* IntegerString
*
* @param key
* @param value
* @param timeout
* @param key
* @param value
* @param timeout
* @param timeUnit
*/
public <T> void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit)
{
public <T> void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit) {
redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
}
/**
*
*
* @param key Redis
* @param key Redis
* @param timeout
* @return true=false=
*/
public boolean expire(final String key, final long timeout)
{
public boolean expire(final String key, final long timeout) {
return expire(key, timeout, TimeUnit.SECONDS);
}
/**
*
*
* @param key Redis
* @param key Redis
* @param timeout
* @param unit
* @param unit
* @return true=false=
*/
public boolean expire(final String key, final long timeout, final TimeUnit unit)
{
public boolean expire(final String key, final long timeout, final TimeUnit unit) {
return redisTemplate.expire(key, timeout, unit);
}
@ -80,8 +76,7 @@ public class RedisCache
* @param key Redis
* @return
*/
public long getExpire(final String key)
{
public long getExpire(final String key) {
return redisTemplate.getExpire(key);
}
@ -91,8 +86,7 @@ public class RedisCache
* @param key
* @return true false
*/
public Boolean hasKey(String key)
{
public Boolean hasKey(String key) {
return redisTemplate.hasKey(key);
}
@ -102,8 +96,7 @@ public class RedisCache
* @param key
* @return
*/
public <T> T getCacheObject(final String key)
{
public <T> T getCacheObject(final String key) {
ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(key);
}
@ -113,8 +106,7 @@ public class RedisCache
*
* @param key
*/
public boolean deleteObject(final String key)
{
public boolean deleteObject(final String key) {
return redisTemplate.delete(key);
}
@ -124,20 +116,18 @@ public class RedisCache
* @param collection
* @return
*/
public boolean deleteObject(final Collection collection)
{
public boolean deleteObject(final Collection collection) {
return redisTemplate.delete(collection) > 0;
}
/**
* List
*
* @param key
* @param key
* @param dataList List
* @return
*/
public <T> long setCacheList(final String key, final List<T> dataList)
{
public <T> long setCacheList(final String key, final List<T> dataList) {
Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
return count == null ? 0 : count;
}
@ -148,24 +138,21 @@ public class RedisCache
* @param key
* @return
*/
public <T> List<T> getCacheList(final String key)
{
public <T> List<T> getCacheList(final String key) {
return redisTemplate.opsForList().range(key, 0, -1);
}
/**
* Set
*
* @param key
* @param key
* @param dataSet
* @return
*/
public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet)
{
public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet) {
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
Iterator<T> it = dataSet.iterator();
while (it.hasNext())
{
while (it.hasNext()) {
setOperation.add(it.next());
}
return setOperation;
@ -177,8 +164,7 @@ public class RedisCache
* @param key
* @return
*/
public <T> Set<T> getCacheSet(final String key)
{
public <T> Set<T> getCacheSet(final String key) {
return redisTemplate.opsForSet().members(key);
}
@ -188,8 +174,7 @@ public class RedisCache
* @param key
* @param dataMap
*/
public <T> void setCacheMap(final String key, final Map<String, T> dataMap)
{
public <T> void setCacheMap(final String key, final Map<String, T> dataMap) {
if (dataMap != null) {
redisTemplate.opsForHash().putAll(key, dataMap);
}
@ -201,32 +186,29 @@ public class RedisCache
* @param key
* @return
*/
public <T> Map<String, T> getCacheMap(final String key)
{
public <T> Map<String, T> getCacheMap(final String key) {
return redisTemplate.opsForHash().entries(key);
}
/**
* Hash
*
* @param key Redis
* @param hKey Hash
* @param key Redis
* @param hKey Hash
* @param value
*/
public <T> void setCacheMapValue(final String key, final String hKey, final T value)
{
public <T> void setCacheMapValue(final String key, final String hKey, final T value) {
redisTemplate.opsForHash().put(key, hKey, value);
}
/**
* Hash
*
* @param key Redis
* @param key Redis
* @param hKey Hash
* @return Hash
*/
public <T> T getCacheMapValue(final String key, final String hKey)
{
public <T> T getCacheMapValue(final String key, final String hKey) {
HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
return opsForHash.get(key, hKey);
}
@ -234,24 +216,22 @@ public class RedisCache
/**
* Hash
*
* @param key Redis
* @param key Redis
* @param hKeys Hash
* @return Hash
*/
public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys)
{
public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys) {
return redisTemplate.opsForHash().multiGet(key, hKeys);
}
/**
* Hash
*
* @param key Redis
* @param key Redis
* @param hKey Hash
* @return
*/
public boolean deleteCacheMapValue(final String key, final String hKey)
{
public boolean deleteCacheMapValue(final String key, final String hKey) {
return redisTemplate.opsForHash().delete(key, hKey) > 0;
}
@ -261,8 +241,7 @@ public class RedisCache
* @param pattern
* @return
*/
public Collection<String> keys(final String pattern)
{
public Collection<String> keys(final String pattern) {
return redisTemplate.keys(pattern);
}
}

@ -17,6 +17,11 @@
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<!-- SpringBoot Web容器 -->
<dependency>
<groupId>org.springframework.boot</groupId>

@ -1,8 +1,11 @@
package com.ruoyi.framework.config;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
@ -25,21 +28,18 @@ import java.util.List;
@Configuration
public class MyBatisConfig {
static final String DEFAULT_RESOURCE_PATTERN = "**/*.class";
@Autowired
private Environment env;
public static String setTypeAliasesPackage(String typeAliasesPackage) {
ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
List<String> allResult = new ArrayList<String>();
List<String> allResult = new ArrayList<>();
try {
for (String aliasesPackage : typeAliasesPackage.split(",")) {
List<String> result = new ArrayList<String>();
aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
+ ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN;
List<String> result = new ArrayList<>();
aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN;
Resource[] resources = resolver.getResources(aliasesPackage);
if (resources != null && resources.length > 0) {
MetadataReader metadataReader = null;
MetadataReader metadataReader;
for (Resource resource : resources) {
if (resource.isReadable()) {
metadataReader = metadataReaderFactory.getMetadataReader(resource);
@ -51,13 +51,13 @@ public class MyBatisConfig {
}
}
}
if (result.size() > 0) {
HashSet<String> hashResult = new HashSet<String>(result);
if (!result.isEmpty()) {
HashSet<String> hashResult = new HashSet<>(result);
allResult.addAll(hashResult);
}
}
if (allResult.size() > 0) {
typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0]));
typeAliasesPackage = String.join(",", allResult.toArray(new String[0]));
} else {
throw new RuntimeException("mybatis typeAliasesPackage 路径扫描错误,参数typeAliasesPackage:" + typeAliasesPackage + "未找到任何包");
}
@ -69,7 +69,7 @@ public class MyBatisConfig {
public Resource[] resolveMapperLocations(String[] mapperLocations) {
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
List<Resource> resources = new ArrayList<Resource>();
List<Resource> resources = new ArrayList<>();
if (mapperLocations != null) {
for (String mapperLocation : mapperLocations) {
try {
@ -82,4 +82,13 @@ public class MyBatisConfig {
}
return resources.toArray(new Resource[resources.size()]);
}
}
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
return interceptor;
}
}

@ -115,6 +115,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 静态资源,可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**","/pt/info/**","/gateway/event/event/eventData/**","/gateway/event/event/eventData/eventProgress/**").permitAll()
.antMatchers("/remoteCall/**").anonymous()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated()
.and()

Loading…
Cancel
Save