Commit c8bf46a7 authored by chenhao's avatar chenhao

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

parent 0c28fb4d
......@@ -8,10 +8,11 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.yeejoin.amos.boot.biz.common.dto.DataDictionaryDto;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -58,10 +59,13 @@ public class DataDictionaryController extends BaseController {
@Value("${redis.cache.failure.time}")
private long time;
@Autowired
DataDictionaryMapper dataDictionaryMapper;
@Autowired
private RedisTemplate redisTemplate;
/**
* 新增数据字典
*
......@@ -112,7 +116,6 @@ public class DataDictionaryController extends BaseController {
return iDataDictionaryService.getById(id);
}
/**
* 根据id查询
*
......@@ -122,9 +125,10 @@ public class DataDictionaryController extends BaseController {
@TycloudOperation(needAuth = true, ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/code", method = RequestMethod.GET)
@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 {
@RequestMapping(value = "/gwmcDataDictionary/{type}", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "根据字典类型查询字典", notes = "根据字典类型查询字典")
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
QueryWrapper<DataDictionary> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("type", type);
......@@ -261,7 +266,8 @@ public class DataDictionaryController extends BaseController {
} else {
Collection<DataDictionary> list = iDataDictionaryService.list(queryWrapper);
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
menus = TreeParser.getTreexin(null, list, DataDictionary.class.getName(), "getCode", 0, "getName",
"getParent", null);
......@@ -286,18 +292,20 @@ public class DataDictionaryController extends BaseController {
queryWrapper.eq("type", type);
queryWrapper.orderByAsc("sort_num");
Collection<DataDictionary> list = null;
List<Menu> menus =null;
List<Menu> menus = null;
if ("YJLDDW".equals(type)) {
list = dataDictionaryMapper.getNoInLinkUnit();
// 数据字典生成树方法 原先通过getCode做主键 现修改为 getSequenceNbr 后期数据字典parent字段保存id 而不要保存code by kongfm 2021-09-08
list = dataDictionaryMapper.getNoInLinkUnit();
// 数据字典生成树方法 原先通过getCode做主键 现修改为 getSequenceNbr 后期数据字典parent字段保存id 而不要保存code by
// kongfm 2021-09-08
// 数据字典还原 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);
} else {
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
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);
}
// 创建根节点
......@@ -311,32 +319,34 @@ public class DataDictionaryController extends BaseController {
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/cleanRedis", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "清楚redis缓存", notes = "清楚redis缓存")
public ResponseModel<Object> cleanRedis(@RequestParam String type)
throws Exception {
type=type.toLowerCase();
if(RedisKey.FORM_CODE.startsWith(type)) {
public ResponseModel<Object> cleanRedis(@RequestParam String type) throws Exception {
type = type.toLowerCase();
if ("all".equals(type)) {
RedisConnection redisConnection = redisTemplate.getConnectionFactory().getConnection();
redisConnection.flushAll();
redisConnection.close();
} else if (RedisKey.FORM_CODE.startsWith(type)) {
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);
}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);
}else if(RedisKey.FIREFIGHTERS_ID.startsWith(type)) {
} else if (RedisKey.FIREFIGHTERS_ID.startsWith(type)) {
redisUtils.del(RedisKey.FIREFIGHTERS_ID);
}else if(RedisKey.FIREFIGHTERS_LIST_ID.startsWith(type)) {
redisUtils.del(RedisKey.FIREFIGHTERS_LIST_ID );
}else if(RedisKey.EDUCATION_POST_EXPERIENCE_FIREFIGHTERS_ID.startsWith(type)) {
} else if (RedisKey.FIREFIGHTERS_LIST_ID.startsWith(type)) {
redisUtils.del(RedisKey.FIREFIGHTERS_LIST_ID);
} else if (RedisKey.EDUCATION_POST_EXPERIENCE_FIREFIGHTERS_ID.startsWith(type)) {
redisUtils.del(RedisKey.EDUCATION_POST_EXPERIENCE_FIREFIGHTERS_ID);
}else if(RedisKey.CONTRACT_ID.startsWith(type)) {
redisUtils.del(RedisKey.CONTRACT_ID );
}else if(RedisKey.THOUGHT_ID.startsWith(type)) {
} else if (RedisKey.CONTRACT_ID.startsWith(type)) {
redisUtils.del(RedisKey.CONTRACT_ID);
} else if (RedisKey.THOUGHT_ID.startsWith(type)) {
redisUtils.del(RedisKey.THOUGHT_ID);
}else if(RedisKey.ALERTCALLED_ID.startsWith(type)) {
} else if (RedisKey.ALERTCALLED_ID.startsWith(type)) {
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);
}
return ResponseHelper.buildResponse(type);
}
}
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -14,16 +16,17 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
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.transaction.annotation.EnableTransactionManagement;
import org.typroject.tyboot.core.restful.exception.GlobalExceptionHandler;
import java.net.InetAddress;
import java.net.UnknownHostException;
import com.yeejoin.amos.boot.biz.common.utils.oConvertUtils;
/**
* <pre>
* 机场服务启动类
* 机场服务启动类
* </pre>
*
*/
......@@ -35,28 +38,48 @@ import java.net.UnknownHostException;
@EnableFeignClients
@EnableAsync
@EnableEurekaClient
@MapperScan({"org.typroject.tyboot.demo.face.orm.dao*",
"org.typroject.tyboot.face.*.orm.dao*",
"org.typroject.tyboot.core.auth.face.orm.dao*",
"org.typroject.tyboot.component.*.face.orm.dao*",
"com.yeejoin.amos.boot.module.*.api.mapper",
"com.yeejoin.amos.boot.biz.common.dao.mapper" })
@MapperScan({ "org.typroject.tyboot.demo.face.orm.dao*", "org.typroject.tyboot.face.*.orm.dao*",
"org.typroject.tyboot.core.auth.face.orm.dao*", "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" })
public class AmosJcsApplication
{
private static final Logger logger = LoggerFactory.getLogger(AmosJcsApplication.class);
public static void main( String[] args ) throws UnknownHostException
{
ConfigurableApplicationContext context = SpringApplication.run(AmosJcsApplication.class, args);
Environment env = context.getEnvironment();
String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
String path = oConvertUtils.getString(env.getProperty("server.servlet.context-path"));
GlobalExceptionHandler.setAlwaysOk(true);
logger.info("\n----------------------------------------------------------\n\t" +
"Application Amos-Biz-Boot is running! Access URLs:\n\t" +
"Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
"----------------------------------------------------------");
}
public class AmosJcsApplication {
private static final Logger logger = LoggerFactory.getLogger(AmosJcsApplication.class);
public static void main(String[] args) throws UnknownHostException {
ConfigurableApplicationContext context = SpringApplication.run(AmosJcsApplication.class, args);
Environment env = context.getEnvironment();
delKey(env, context);// 添加全部清空redis缓存的方法 2021-09-09
String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
String path = oConvertUtils.getString(env.getProperty("server.servlet.context-path"));
GlobalExceptionHandler.setAlwaysOk(true);
logger.info("\n----------------------------------------------------------\n\t"
+ "Application Amos-Biz-Boot is running! Access URLs:\n\t" + "Swagger文档: \thttp://" + ip + ":" + port
+ 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.port=11100
spring.profiles.active=dev
......@@ -7,10 +7,10 @@ spring.jackson.time-zone=GMT+8
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
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
## redis失效时间
## redis失效时间
redis.cache.failure.time=10800
## unit(h)
......@@ -50,14 +50,15 @@ spring.redis.lettuce.pool.max-wait=-1
spring.redis.lettuce.pool.max-idle=10
spring.redis.lettuce.pool.min-idle=0
spring.redis.expire.time=300
## mqtt-警情初报消息主题
#在重启服务的过程中是否清空缓存的标识符 --2021-09-09
my.spring.redis.cache.isclean=false
## mqtt-警情初报消息主题
mqtt.topic.alert.reporting=alertReporting
## 实战指挥新警情�?�报主题
## 实战指挥新警情�?�报主题
mqtt.topic.command.alert.notice=alertNotice
## 跑马灯地震,天气预警信息
## 跑马灯地震,天气预警信息
mqtt.topic.command.meteorological.notice=meteorological
mqtt.topic.command.power.deployment=power
......@@ -71,8 +72,8 @@ iot.fegin.name=AMOS-API-IOT
equip.fegin.name=AMOS-EQUIPMANAGE
## 设备联动服务(车库门、广播、警铃)
## 设备联动服务(车库门、广播、警铃)
control.fegin.name=JCS-API-CONTROL
## 故障报修流程
## 故障报修流程
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