Commit c8bf46a7 authored by chenhao's avatar chenhao

添加启动服务和手动对外的清空redis缓存方法

parent 0c28fb4d
...@@ -8,10 +8,11 @@ import java.util.List; ...@@ -8,10 +8,11 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import com.yeejoin.amos.boot.biz.common.dto.DataDictionaryDto;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -62,6 +63,9 @@ public class DataDictionaryController extends BaseController { ...@@ -62,6 +63,9 @@ public class DataDictionaryController extends BaseController {
@Autowired @Autowired
DataDictionaryMapper dataDictionaryMapper; DataDictionaryMapper dataDictionaryMapper;
@Autowired
private RedisTemplate redisTemplate;
/** /**
* 新增数据字典 * 新增数据字典
* *
...@@ -112,7 +116,6 @@ public class DataDictionaryController extends BaseController { ...@@ -112,7 +116,6 @@ public class DataDictionaryController extends BaseController {
return iDataDictionaryService.getById(id); return iDataDictionaryService.getById(id);
} }
/** /**
* 根据id查询 * 根据id查询
* *
...@@ -122,9 +125,10 @@ public class DataDictionaryController extends BaseController { ...@@ -122,9 +125,10 @@ public class DataDictionaryController extends BaseController {
@TycloudOperation(needAuth = true, ApiLevel = UserType.AGENCY) @TycloudOperation(needAuth = true, ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/code", method = RequestMethod.GET) @RequestMapping(value = "/code", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "根据code查询", notes = "根据code查询") @ApiOperation(httpMethod = "GET", value = "根据code查询", notes = "根据code查询")
public DataDictionary selectByCode(HttpServletRequest request,@RequestParam("code") String code,@RequestParam("type") String type) { public DataDictionary selectByCode(HttpServletRequest request, @RequestParam("code") String code,
@RequestParam("type") String type) {
return iDataDictionaryService.getByCode(code,type); return iDataDictionaryService.getByCode(code, type);
} }
/** /**
...@@ -179,7 +183,8 @@ public class DataDictionaryController extends BaseController { ...@@ -179,7 +183,8 @@ public class DataDictionaryController extends BaseController {
@RequestMapping(value = "/gwmcDataDictionary/{type}", method = RequestMethod.GET) @RequestMapping(value = "/gwmcDataDictionary/{type}", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "根据字典类型查询字典", notes = "根据字典类型查询字典") @ApiOperation(httpMethod = "GET", value = "根据字典类型查询字典", notes = "根据字典类型查询字典")
public ResponseModel<Object> gwmcDataDictionary(@PathVariable String type) throws Exception { public ResponseModel<Object> gwmcDataDictionary(@PathVariable String type) throws Exception {
// 数据字典生成树方法 原先通过getCode做主键 现修改为 getSequenceNbr 后期数据字典parent字段保存id 而不要保存code by kongfm 2021-09-08 // 数据字典生成树方法 原先通过getCode做主键 现修改为 getSequenceNbr 后期数据字典parent字段保存id 而不要保存code by
// kongfm 2021-09-08
// 数据字典还原 by kongfm 2021-09-09 // 数据字典还原 by kongfm 2021-09-09
QueryWrapper<DataDictionary> queryWrapper = new QueryWrapper<>(); QueryWrapper<DataDictionary> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("type", type); queryWrapper.eq("type", type);
...@@ -261,7 +266,8 @@ public class DataDictionaryController extends BaseController { ...@@ -261,7 +266,8 @@ public class DataDictionaryController extends BaseController {
} else { } else {
Collection<DataDictionary> list = iDataDictionaryService.list(queryWrapper); Collection<DataDictionary> list = iDataDictionaryService.list(queryWrapper);
List<MenuFrom> menus = null; List<MenuFrom> menus = null;
// 数据字典生成树方法 原先通过getCode做主键 现修改为 getSequenceNbr 后期数据字典parent字段保存id 而不要保存code by kongfm 2021-09-08 // 数据字典生成树方法 原先通过getCode做主键 现修改为 getSequenceNbr 后期数据字典parent字段保存id 而不要保存code by
// kongfm 2021-09-08
// 数据字典还原 by kongfm 2021-09-09 // 数据字典还原 by kongfm 2021-09-09
menus = TreeParser.getTreexin(null, list, DataDictionary.class.getName(), "getCode", 0, "getName", menus = TreeParser.getTreexin(null, list, DataDictionary.class.getName(), "getCode", 0, "getName",
"getParent", null); "getParent", null);
...@@ -286,16 +292,18 @@ public class DataDictionaryController extends BaseController { ...@@ -286,16 +292,18 @@ public class DataDictionaryController extends BaseController {
queryWrapper.eq("type", type); queryWrapper.eq("type", type);
queryWrapper.orderByAsc("sort_num"); queryWrapper.orderByAsc("sort_num");
Collection<DataDictionary> list = null; Collection<DataDictionary> list = null;
List<Menu> menus =null; List<Menu> menus = null;
if ("YJLDDW".equals(type)) { if ("YJLDDW".equals(type)) {
list = dataDictionaryMapper.getNoInLinkUnit(); list = dataDictionaryMapper.getNoInLinkUnit();
// 数据字典生成树方法 原先通过getCode做主键 现修改为 getSequenceNbr 后期数据字典parent字段保存id 而不要保存code by kongfm 2021-09-08 // 数据字典生成树方法 原先通过getCode做主键 现修改为 getSequenceNbr 后期数据字典parent字段保存id 而不要保存code by
// kongfm 2021-09-08
// 数据字典还原 by kongfm 2021-09-09 // 数据字典还原 by kongfm 2021-09-09
menus = TreeParser.getTree(null, list, DataDictionary.class.getName(), "getCode", 0, "getName", "getParent", menus = TreeParser.getTree(null, list, DataDictionary.class.getName(), "getCode", 0, "getName", "getParent",
null); null);
} else { } else {
list = iDataDictionaryService.list(queryWrapper); list = iDataDictionaryService.list(queryWrapper);
// 数据字典生成树方法 原先通过getCode做主键 现修改为 getSequenceNbr 后期数据字典parent字段保存id 而不要保存code by kongfm 2021-09-08 // 数据字典生成树方法 原先通过getCode做主键 现修改为 getSequenceNbr 后期数据字典parent字段保存id 而不要保存code by
// kongfm 2021-09-08
// 数据字典还原 by kongfm 2021-09-09 // 数据字典还原 by kongfm 2021-09-09
menus = TreeParser.getTree(null, list, DataDictionary.class.getName(), "getCode", 0, "getName", "getParent", menus = TreeParser.getTree(null, list, DataDictionary.class.getName(), "getCode", 0, "getName", "getParent",
null); null);
...@@ -311,32 +319,34 @@ public class DataDictionaryController extends BaseController { ...@@ -311,32 +319,34 @@ public class DataDictionaryController extends BaseController {
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY) @TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/cleanRedis", method = RequestMethod.GET) @RequestMapping(value = "/cleanRedis", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "清楚redis缓存", notes = "清楚redis缓存") @ApiOperation(httpMethod = "GET", value = "清楚redis缓存", notes = "清楚redis缓存")
public ResponseModel<Object> cleanRedis(@RequestParam String type) public ResponseModel<Object> cleanRedis(@RequestParam String type) throws Exception {
throws Exception { type = type.toLowerCase();
type=type.toLowerCase(); if ("all".equals(type)) {
if(RedisKey.FORM_CODE.startsWith(type)) { RedisConnection redisConnection = redisTemplate.getConnectionFactory().getConnection();
redisConnection.flushAll();
redisConnection.close();
} else if (RedisKey.FORM_CODE.startsWith(type)) {
redisUtils.del(RedisKey.FORM_CODE); redisUtils.del(RedisKey.FORM_CODE);
}else if(RedisKey.DATA_DICTIONARY_CODE.startsWith(type)) { } else if (RedisKey.DATA_DICTIONARY_CODE.startsWith(type)) {
redisUtils.del(RedisKey.DATA_DICTIONARY_CODE); redisUtils.del(RedisKey.DATA_DICTIONARY_CODE);
}else if(RedisKey.DATA_DICTIONARY_CODE_XIN.startsWith(type)) { } else if (RedisKey.DATA_DICTIONARY_CODE_XIN.startsWith(type)) {
redisUtils.del(RedisKey.DATA_DICTIONARY_CODE_XIN); redisUtils.del(RedisKey.DATA_DICTIONARY_CODE_XIN);
}else if(RedisKey.FIREFIGHTERS_ID.startsWith(type)) { } else if (RedisKey.FIREFIGHTERS_ID.startsWith(type)) {
redisUtils.del(RedisKey.FIREFIGHTERS_ID); redisUtils.del(RedisKey.FIREFIGHTERS_ID);
}else if(RedisKey.FIREFIGHTERS_LIST_ID.startsWith(type)) { } else if (RedisKey.FIREFIGHTERS_LIST_ID.startsWith(type)) {
redisUtils.del(RedisKey.FIREFIGHTERS_LIST_ID ); redisUtils.del(RedisKey.FIREFIGHTERS_LIST_ID);
}else if(RedisKey.EDUCATION_POST_EXPERIENCE_FIREFIGHTERS_ID.startsWith(type)) { } else if (RedisKey.EDUCATION_POST_EXPERIENCE_FIREFIGHTERS_ID.startsWith(type)) {
redisUtils.del(RedisKey.EDUCATION_POST_EXPERIENCE_FIREFIGHTERS_ID); redisUtils.del(RedisKey.EDUCATION_POST_EXPERIENCE_FIREFIGHTERS_ID);
}else if(RedisKey.CONTRACT_ID.startsWith(type)) { } else if (RedisKey.CONTRACT_ID.startsWith(type)) {
redisUtils.del(RedisKey.CONTRACT_ID ); redisUtils.del(RedisKey.CONTRACT_ID);
}else if(RedisKey.THOUGHT_ID.startsWith(type)) { } else if (RedisKey.THOUGHT_ID.startsWith(type)) {
redisUtils.del(RedisKey.THOUGHT_ID); redisUtils.del(RedisKey.THOUGHT_ID);
}else if(RedisKey.ALERTCALLED_ID.startsWith(type)) { } else if (RedisKey.ALERTCALLED_ID.startsWith(type)) {
redisUtils.del(RedisKey.ALERTCALLED_ID); redisUtils.del(RedisKey.ALERTCALLED_ID);
}else if(RedisKey.TZS_ALERTCALLED_ID.startsWith(type)) { } else if (RedisKey.TZS_ALERTCALLED_ID.startsWith(type)) {
redisUtils.del(RedisKey.TZS_ALERTCALLED_ID); redisUtils.del(RedisKey.TZS_ALERTCALLED_ID);
} }
return ResponseHelper.buildResponse(type); return ResponseHelper.buildResponse(type);
} }
} }
package com.yeejoin.amos; package com.yeejoin.amos;
import com.yeejoin.amos.boot.biz.common.utils.oConvertUtils; import java.net.InetAddress;
import java.net.UnknownHostException;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -14,12 +16,13 @@ import org.springframework.cloud.openfeign.EnableFeignClients; ...@@ -14,12 +16,13 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.typroject.tyboot.core.restful.exception.GlobalExceptionHandler; import org.typroject.tyboot.core.restful.exception.GlobalExceptionHandler;
import java.net.InetAddress; import com.yeejoin.amos.boot.biz.common.utils.oConvertUtils;
import java.net.UnknownHostException;
/** /**
* <pre> * <pre>
...@@ -35,28 +38,48 @@ import java.net.UnknownHostException; ...@@ -35,28 +38,48 @@ import java.net.UnknownHostException;
@EnableFeignClients @EnableFeignClients
@EnableAsync @EnableAsync
@EnableEurekaClient @EnableEurekaClient
@MapperScan({"org.typroject.tyboot.demo.face.orm.dao*", @MapperScan({ "org.typroject.tyboot.demo.face.orm.dao*", "org.typroject.tyboot.face.*.orm.dao*",
"org.typroject.tyboot.face.*.orm.dao*", "org.typroject.tyboot.core.auth.face.orm.dao*", "org.typroject.tyboot.component.*.face.orm.dao*",
"org.typroject.tyboot.core.auth.face.orm.dao*", "com.yeejoin.amos.boot.module.*.api.mapper", "com.yeejoin.amos.boot.biz.common.dao.mapper" })
"org.typroject.tyboot.component.*.face.orm.dao*",
"com.yeejoin.amos.boot.module.*.api.mapper",
"com.yeejoin.amos.boot.biz.common.dao.mapper" })
@ComponentScan(basePackages = { "org.typroject", "com.yeejoin.amos" }) @ComponentScan(basePackages = { "org.typroject", "com.yeejoin.amos" })
public class AmosJcsApplication public class AmosJcsApplication {
{
private static final Logger logger = LoggerFactory.getLogger(AmosJcsApplication.class); private static final Logger logger = LoggerFactory.getLogger(AmosJcsApplication.class);
public static void main( String[] args ) throws UnknownHostException public static void main(String[] args) throws UnknownHostException {
{
ConfigurableApplicationContext context = SpringApplication.run(AmosJcsApplication.class, args); ConfigurableApplicationContext context = SpringApplication.run(AmosJcsApplication.class, args);
Environment env = context.getEnvironment(); Environment env = context.getEnvironment();
delKey(env, context);// 添加全部清空redis缓存的方法 2021-09-09
String ip = InetAddress.getLocalHost().getHostAddress(); String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port"); String port = env.getProperty("server.port");
String path = oConvertUtils.getString(env.getProperty("server.servlet.context-path")); String path = oConvertUtils.getString(env.getProperty("server.servlet.context-path"));
GlobalExceptionHandler.setAlwaysOk(true); GlobalExceptionHandler.setAlwaysOk(true);
logger.info("\n----------------------------------------------------------\n\t" + logger.info("\n----------------------------------------------------------\n\t"
"Application Amos-Biz-Boot is running! Access URLs:\n\t" + + "Application Amos-Biz-Boot is running! Access URLs:\n\t" + "Swagger文档: \thttp://" + ip + ":" + port
"Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" + + path + "/doc.html\n" + "----------------------------------------------------------");
"----------------------------------------------------------");
} }
/**
* 清空redis缓存数据
*
* @author 陈浩
* @param env
* @param context
*/
public static void delKey(Environment env, ConfigurableApplicationContext context) {
if (Boolean.parseBoolean(env.getProperty("my.spring.redis.cache.isclean"))) {
@SuppressWarnings("rawtypes")
RedisTemplate redisTemplate = context.getBean("redisTemplate", RedisTemplate.class);
RedisConnection redisConnection = null;
try {
redisConnection = redisTemplate.getConnectionFactory().getConnection();
redisConnection.flushAll();
} catch (Exception e) {
logger.info("删除redis 缓存的key 失败");
} finally {
redisConnection.close();
}
}
}
} }
spring.application.name=JCS spring.application.name=JCS-chenhao
server.servlet.context-path=/jcs server.servlet.context-path=/jcs
server.port=11100 server.port=11100
spring.profiles.active=dev spring.profiles.active=dev
...@@ -7,10 +7,10 @@ spring.jackson.time-zone=GMT+8 ...@@ -7,10 +7,10 @@ spring.jackson.time-zone=GMT+8
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
logging.config=classpath:logback-${spring.profiles.active}.xml logging.config=classpath:logback-${spring.profiles.active}.xml
## mybatis-plus配置控制台打印完整带参数SQL语句 ## mybatis-plus配置控制台打印完整带参数SQL语句
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
## redis失效时间 ## redis失效时间
redis.cache.failure.time=10800 redis.cache.failure.time=10800
## unit(h) ## unit(h)
...@@ -50,14 +50,15 @@ spring.redis.lettuce.pool.max-wait=-1 ...@@ -50,14 +50,15 @@ spring.redis.lettuce.pool.max-wait=-1
spring.redis.lettuce.pool.max-idle=10 spring.redis.lettuce.pool.max-idle=10
spring.redis.lettuce.pool.min-idle=0 spring.redis.lettuce.pool.min-idle=0
spring.redis.expire.time=300 spring.redis.expire.time=300
#在重启服务的过程中是否清空缓存的标识符 --2021-09-09
## mqtt-警情初报消息主题 my.spring.redis.cache.isclean=false
## mqtt-警情初报消息主题
mqtt.topic.alert.reporting=alertReporting mqtt.topic.alert.reporting=alertReporting
## 实战指挥新警情�?�报主题 ## 实战指挥新警情�?�报主题
mqtt.topic.command.alert.notice=alertNotice mqtt.topic.command.alert.notice=alertNotice
## 跑马灯地震,天气预警信息 ## 跑马灯地震,天气预警信息
mqtt.topic.command.meteorological.notice=meteorological mqtt.topic.command.meteorological.notice=meteorological
mqtt.topic.command.power.deployment=power mqtt.topic.command.power.deployment=power
...@@ -71,8 +72,8 @@ iot.fegin.name=AMOS-API-IOT ...@@ -71,8 +72,8 @@ iot.fegin.name=AMOS-API-IOT
equip.fegin.name=AMOS-EQUIPMANAGE equip.fegin.name=AMOS-EQUIPMANAGE
## 设备联动服务(车库门、广播、警铃) ## 设备联动服务(车库门、广播、警铃)
control.fegin.name=JCS-API-CONTROL control.fegin.name=JCS-API-CONTROL
## 故障报修流程 ## 故障报修流程
failure.work.flow.processDefinitionKey=malfunction_repair failure.work.flow.processDefinitionKey=malfunction_repair
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment