diff --git a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java index a4bd2a1..61f5042 100644 --- a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java +++ b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java @@ -51,24 +51,36 @@ public class ConfigSourcesController extends BaseRestController { protected ServicesRequestLogService servicesRequestLogService; @Autowired - ConfigRedisService configRedisServiceimpl; + ConfigRedisService configRedisService; @RequestMapping(value = "/save", method = RequestMethod.GET) @ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller") @ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true) - public String testRedis() { + public String testRedis(Integer type) { try { - Map map = new HashMap(); - - long id=configRedisServiceimpl.getIncrId("seq_compileid"); - map.put("cfg_id", id+""); - map.put("is_valid", "1"); - map.put("dst_file", "/home/1234/"); - map.put("dst_file_md5", "fasdfdasfsdafdsafadsf"); - map.put("time_stamp", new Date().getTime() + ""); - map.put("level", "20"); - map.put("file_id",id+""); - configRedisServiceimpl.saveConfigYSPDemoCompile(96,map); + if(type==1) { + Map map = new HashMap(); + long id=configRedisService.getIncrId("seq_compileid"); + //int id=2; + map.put("cfg_id", id+""); + map.put("is_valid", "1"); + map.put("dst_file", "home"); + map.put("dst_file_md5", "fasdfdasfsdafdsafadsf"); + map.put("time_stamp", new Date().getTime() + ""); + map.put("level", "20"); + map.put("file_id",id+""); + configRedisService.saveConfigYSPDemoCompile(96,map); + }else { + Map map = new HashMap(); + long id=configRedisService.getIncrId("seq_compileid"); + //int id=2; + map.put("cfg_id", id+""); + map.put("is_valid", "1"); + map.put("service", "100"); + map.put("description", "123"+id); + map.put("level", "20"); + configRedisService.saveConfigYSPDemoCompile(100,map); + } return "ok"; } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java b/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java index dccd905..73244af 100644 --- a/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java +++ b/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java @@ -2,6 +2,7 @@ package com.nis.web.dao.impl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.stereotype.Repository; @Repository @@ -9,5 +10,12 @@ public abstract class BaseRedisDao { @Autowired protected RedisTemplate redisTemplate; - + +// public void setRedisTemplate(RedisTemplate redisTemplate) { +// StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); +// redisTemplate.setKeySerializer(stringRedisSerializer); +// redisTemplate.setValueSerializer(stringRedisSerializer); +// this.redisTemplate = redisTemplate; +// } + } diff --git a/src/main/java/com/nis/web/service/restful/ConfigRedisService.java b/src/main/java/com/nis/web/service/restful/ConfigRedisService.java index df4dec1..ce70bf0 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigRedisService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigRedisService.java @@ -12,8 +12,20 @@ import java.util.Map; * */ public interface ConfigRedisService { + /** + * 保存ysp样例配置接口 + * @param service 业务类型 + * @param map + */ public void saveConfigYSPDemoCompile(int service, Map map); + /** + * 保存ysp配置接口 + * @param service + * @param map + */ + public void saveConfigYSPCompile(int service, Map map); + /** * 获取指定key的自增长值 * @param key 需要自增的key diff --git a/src/main/java/com/nis/web/service/restful/ConfigRedisServiceimpl.java b/src/main/java/com/nis/web/service/restful/ConfigRedisServiceimpl.java index 23e4b85..8804698 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigRedisServiceimpl.java +++ b/src/main/java/com/nis/web/service/restful/ConfigRedisServiceimpl.java @@ -2,9 +2,7 @@ package com.nis.web.service.restful; import java.util.List; import java.util.Map; -import java.util.concurrent.TimeUnit; -import org.springframework.data.redis.support.atomic.RedisAtomicLong; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; @@ -43,18 +41,17 @@ public class ConfigRedisServiceimpl extends BaseRedisDao impleme valBF.append(map.get(valStr)); } else if (valStr.equals(" ")) { valBF.append(" "); - } else { - valBF.append(valStr.trim()); + } else if (valStr.equals("\\t")) {// xml中是字符串的\t这里判断的时候需要转义为\\t,但是添加的时候需要添加\t不是\\t + valBF.append("\t"); + } else if (valStr.equals("\\n")) { + valBF.append("\n"); } } + DynamicJedisDataBase.setRedisDataBase(maatXmlExpr.getRedisDB(), redisTemplate); + System.out.println(keyBF.toString()); + System.out.println(valBF.toString()); - // DynamicJedisDataBase.setRedisDataBase(maatXmlExpr.getRedisDB(), - // redisTemplate); - // System.out.println(keyBF.toString()); - // System.out.println(valBF.toString()); - //redisTemplate.boundValueOps(keyBF.toString()). - - redisTemplate.opsForValue().set(keyBF.toString(), valBF.toString()); + redisTemplate.opsForValue().set(keyBF.toString(), new String(valBF)); // redisTemplate.boundValueOps(keyBF.toString()).set(valBF.toString()); } @@ -101,9 +98,8 @@ public class ConfigRedisServiceimpl extends BaseRedisDao impleme } } - @Override public Long getIncrId(String key) { - DynamicJedisDataBase.setRedisDataBase(2, redisTemplate); + DynamicJedisDataBase.setRedisDataBase(2, redisTemplate); // RedisAtomicLong atomicLong = new RedisAtomicLong(key, // redisTemplate.getConnectionFactory()); // @@ -112,8 +108,12 @@ public class ConfigRedisServiceimpl extends BaseRedisDao impleme // atomicLong.expire(liveTime, TimeUnit.SECONDS); // } // return id; - return redisTemplate.boundValueOps(key).increment(1l); } + @Transactional + public void saveConfigYSPCompile(int service, Map map) { + + } + } diff --git a/src/main/resources/applicationContext-redis.xml b/src/main/resources/applicationContext-redis.xml index 0c2e5a9..faf7f3a 100644 --- a/src/main/resources/applicationContext-redis.xml +++ b/src/main/resources/applicationContext-redis.xml @@ -13,8 +13,7 @@ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd - http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd" - default-lazy-init="true"> + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd"> @@ -29,8 +28,8 @@ - + p:database="0" /> + - - - - diff --git a/src/main/resources/jdbc.properties b/src/main/resources/jdbc.properties index 7c501e3..73fa10a 100644 --- a/src/main/resources/jdbc.properties +++ b/src/main/resources/jdbc.properties @@ -127,6 +127,7 @@ jdbc.test.password=OrTu/cLwlduYPW/tmxqNgQ== ##redis连接 ##################################################################################################################################### redis.host=10.0.6.228 +#redis.host=10.0.6.32 redis.port=6379 redis.pass= redis.maxIdle=10 diff --git a/src/main/resources/maatXml/maat.xml b/src/main/resources/maatXml/maat.xml index 1e73f1f..f854335 100644 --- a/src/main/resources/maatXml/maat.xml +++ b/src/main/resources/maatXml/maat.xml @@ -3,14 +3,24 @@ xsi:schemaLocation="http://www.w3school.com.cn maat.xsd"> - + - file_index_info;,;[cfg_id] + EFFECTIVE_RULE;:;FILE_INDEX_INFO;,;[cfg_id] [cfg_id];\t;[is_valid];\t;[dst_file];\t;[dst_file_md5];\t;[time_stamp]; [level];\t;[file_id];\n 2 + + + EFFECTIVE_RULE;:;mark_sample;,;[cfg_id] + [cfg_id];\t;[service];\t;[level];\t;[description];\t;[is_valid] + 2 + + + + +