封装保存音视频样例配置的方法
This commit is contained in:
37
src/main/java/com/nis/domain/MaatXmlConfig.java
Normal file
37
src/main/java/com/nis/domain/MaatXmlConfig.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package com.nis.domain;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MaatXmlConfig implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private Integer service;
|
||||||
|
private List<MaatXmlSeq> sequenceList;
|
||||||
|
private List<MaatXmlExpr> expressionList;
|
||||||
|
|
||||||
|
public Integer getService() {
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setService(Integer service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MaatXmlSeq> getSequenceList() {
|
||||||
|
return sequenceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSequenceList(List<MaatXmlSeq> sequenceList) {
|
||||||
|
this.sequenceList = sequenceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MaatXmlExpr> getExpressionList() {
|
||||||
|
return expressionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExpressionList(List<MaatXmlExpr> expressionList) {
|
||||||
|
this.expressionList = expressionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
36
src/main/java/com/nis/domain/MaatXmlExpr.java
Normal file
36
src/main/java/com/nis/domain/MaatXmlExpr.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package com.nis.domain;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class MaatXmlExpr implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private String keyExpression;
|
||||||
|
private String valueExpression;
|
||||||
|
private Integer redisDB;
|
||||||
|
|
||||||
|
public String getKeyExpression() {
|
||||||
|
return keyExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeyExpression(String keyExpression) {
|
||||||
|
this.keyExpression = keyExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValueExpression() {
|
||||||
|
return valueExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValueExpression(String valueExpression) {
|
||||||
|
this.valueExpression = valueExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getRedisDB() {
|
||||||
|
return redisDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRedisDB(Integer redisDB) {
|
||||||
|
this.redisDB = redisDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
37
src/main/java/com/nis/domain/MaatXmlSeq.java
Normal file
37
src/main/java/com/nis/domain/MaatXmlSeq.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package com.nis.domain;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class MaatXmlSeq implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String sequenceKey;
|
||||||
|
private Integer operation;
|
||||||
|
private Integer redisDB;
|
||||||
|
|
||||||
|
public String getSequenceKey() {
|
||||||
|
return sequenceKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSequenceKey(String sequenceKey) {
|
||||||
|
this.sequenceKey = sequenceKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getOperation() {
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOperation(Integer operation) {
|
||||||
|
this.operation = operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getRedisDB() {
|
||||||
|
return redisDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRedisDB(Integer redisDB) {
|
||||||
|
this.redisDB = redisDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
5
src/main/java/com/nis/util/MaatXmlUtil.java
Normal file
5
src/main/java/com/nis/util/MaatXmlUtil.java
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package com.nis.util;
|
||||||
|
|
||||||
|
public class MaatXmlUtil {
|
||||||
|
|
||||||
|
}
|
||||||
171
src/main/java/com/nis/util/ReadMaatXmlUtil.java
Normal file
171
src/main/java/com/nis/util/ReadMaatXmlUtil.java
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
package com.nis.util;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.xml.transform.Source;
|
||||||
|
import javax.xml.transform.stream.StreamSource;
|
||||||
|
import javax.xml.validation.Schema;
|
||||||
|
import javax.xml.validation.SchemaFactory;
|
||||||
|
import javax.xml.validation.Validator;
|
||||||
|
|
||||||
|
import org.dom4j.Document;
|
||||||
|
import org.dom4j.Element;
|
||||||
|
import org.dom4j.io.OutputFormat;
|
||||||
|
import org.dom4j.io.SAXReader;
|
||||||
|
import org.dom4j.io.XMLWriter;
|
||||||
|
import org.dom4j.util.XMLErrorHandler;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.nis.domain.MaatXmlConfig;
|
||||||
|
import com.nis.domain.MaatXmlExpr;
|
||||||
|
import com.nis.domain.MaatXmlSeq;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* <p>Title: ReadMaatXmlUtil</p>
|
||||||
|
* <p>Description: 根据xml定义的规则来读取,目前每次加载都重新加载一次xml,后面稳定后会放到listener中,项目启动的时候加载一次</p>
|
||||||
|
* <p>Company: IIE</p>
|
||||||
|
* @author rkg
|
||||||
|
* @date 2018年5月17日
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ReadMaatXmlUtil {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(ReadMaatXmlUtil.class);
|
||||||
|
private static String XMLPATH = "/maatXml/maat.xml";
|
||||||
|
private static String XSDPATH = "/maatXml/maat.xsd";
|
||||||
|
public static Map<Integer, MaatXmlConfig> map = new HashMap<Integer, MaatXmlConfig>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
readXml();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<MaatXmlConfig> maatXmlConfigList = new ArrayList<MaatXmlConfig>();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
try {
|
||||||
|
// validateXmlByXSD();
|
||||||
|
readXml();
|
||||||
|
Set<Integer> keySet = map.keySet();
|
||||||
|
for (Integer key : keySet) {
|
||||||
|
MaatXmlConfig maatXmlConfig = map.get(key);
|
||||||
|
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||||
|
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||||
|
System.out.println("service=" + key + " redisDB=" + maatXmlExpr.getRedisDB() + " key="
|
||||||
|
+ maatXmlExpr.getKeyExpression() + " value=" + maatXmlExpr.getValueExpression());
|
||||||
|
}
|
||||||
|
List<MaatXmlSeq> sequenceList = maatXmlConfig.getSequenceList();
|
||||||
|
for (MaatXmlSeq maatXmlSeq : sequenceList) {
|
||||||
|
System.out.println("service=" + key + " redisDB=" + maatXmlSeq.getRedisDB() + " key="
|
||||||
|
+ maatXmlSeq.getSequenceKey() + " operation=" + maatXmlSeq.getOperation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void readXml() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
InputStream resourceAsStream = ReadMaatXmlUtil.class.getResourceAsStream(XMLPATH);
|
||||||
|
SAXReader reader = new SAXReader();
|
||||||
|
Document read = reader.read(resourceAsStream);
|
||||||
|
Element rootElement = read.getRootElement();
|
||||||
|
if (rootElement != null && rootElement.elements().size() > 0) {
|
||||||
|
List<Element> elements = rootElement.elements();
|
||||||
|
for (Element element : elements) {
|
||||||
|
String serviceStr = element.attribute("service").getValue();
|
||||||
|
if (serviceStr != null && !serviceStr.trim().equals("")) {
|
||||||
|
String[] split = serviceStr.split(";");
|
||||||
|
for (String service : split) {
|
||||||
|
if (serviceStr != null && !serviceStr.trim().equals("")) {
|
||||||
|
List<MaatXmlSeq> seqList = new ArrayList<MaatXmlSeq>();
|
||||||
|
List<Element> sequencesEle = element.elements("sequences");
|
||||||
|
for (Element seqEle : sequencesEle) {
|
||||||
|
MaatXmlSeq maatXmlSeq = new MaatXmlSeq();
|
||||||
|
List<Element> eleList = seqEle.elements();
|
||||||
|
for (Element ele : eleList) {
|
||||||
|
if (ele.getName().toLowerCase().equals("operation")) {
|
||||||
|
maatXmlSeq.setOperation(Integer.parseInt(ele.getTextTrim()));
|
||||||
|
}
|
||||||
|
if (ele.getName().toLowerCase().equals("redisdb")) {
|
||||||
|
maatXmlSeq.setRedisDB(Integer.parseInt(ele.getTextTrim()));
|
||||||
|
}
|
||||||
|
if (ele.getName().toLowerCase().equals("sequencekey")) {
|
||||||
|
maatXmlSeq.setSequenceKey(ele.getTextTrim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
seqList.add(maatXmlSeq);
|
||||||
|
}
|
||||||
|
List<MaatXmlExpr> exprList = new ArrayList<MaatXmlExpr>();
|
||||||
|
List<Element> expressionsEle = element.elements("expressions");
|
||||||
|
for (Element exprEle : expressionsEle) {
|
||||||
|
MaatXmlExpr maatXmlExpr = new MaatXmlExpr();
|
||||||
|
List<Element> eleList = exprEle.elements();
|
||||||
|
for (Element ele : eleList) {
|
||||||
|
if (ele.getName().toLowerCase().equals("keyexpression")) {
|
||||||
|
maatXmlExpr.setKeyExpression(ele.getTextTrim());
|
||||||
|
}
|
||||||
|
if (ele.getName().toLowerCase().equals("valueexpression")) {
|
||||||
|
maatXmlExpr.setValueExpression(ele.getTextTrim());
|
||||||
|
}
|
||||||
|
if (ele.getName().toLowerCase().equals("redisdb")) {
|
||||||
|
maatXmlExpr.setRedisDB(Integer.parseInt(ele.getTextTrim()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exprList.add(maatXmlExpr);
|
||||||
|
}
|
||||||
|
MaatXmlConfig maatXmlConfig = new MaatXmlConfig();
|
||||||
|
maatXmlConfig.setService(Integer.parseInt(service));
|
||||||
|
maatXmlConfig.setExpressionList(exprList);
|
||||||
|
maatXmlConfig.setSequenceList(seqList);
|
||||||
|
map.put(Integer.parseInt(service.trim()), maatXmlConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("加载maat.xml失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MaatXmlConfig getMaatConfigByService(int service) {
|
||||||
|
return map.get(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void validateXmlByXSD() throws Exception {
|
||||||
|
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
|
||||||
|
|
||||||
|
URL resource = ReadMaatXmlUtil.class.getResource(XSDPATH);
|
||||||
|
Schema xsdSchema = schemaFactory.newSchema(resource);
|
||||||
|
Validator newValidator = xsdSchema.newValidator();
|
||||||
|
|
||||||
|
XMLErrorHandler xmlErrorHandler = new XMLErrorHandler();
|
||||||
|
newValidator.setErrorHandler(xmlErrorHandler);
|
||||||
|
InputStream resourceAsStream = ReadMaatXmlUtil.class.getResourceAsStream(XMLPATH);
|
||||||
|
|
||||||
|
Source source = new StreamSource(resourceAsStream);
|
||||||
|
newValidator.validate(source);
|
||||||
|
XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint());
|
||||||
|
if (xmlErrorHandler.getErrors().hasContent()) {
|
||||||
|
System.out.println("校验xml失败");
|
||||||
|
writer.write(xmlErrorHandler.getErrors());
|
||||||
|
} else {
|
||||||
|
System.out.println("校验xml成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.nis.web.controller.restful;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ import com.nis.util.StringUtils;
|
|||||||
import com.nis.web.controller.BaseRestController;
|
import com.nis.web.controller.BaseRestController;
|
||||||
import com.nis.web.service.SaveRequestLogThread;
|
import com.nis.web.service.SaveRequestLogThread;
|
||||||
import com.nis.web.service.ServicesRequestLogService;
|
import com.nis.web.service.ServicesRequestLogService;
|
||||||
import com.nis.web.service.restful.TestRedisService;
|
import com.nis.web.service.restful.ConfigRedisService;
|
||||||
import com.nis.web.service.restful.ConfigSourcesService;
|
import com.nis.web.service.restful.ConfigSourcesService;
|
||||||
import com.wordnik.swagger.annotations.Api;
|
import com.wordnik.swagger.annotations.Api;
|
||||||
import com.wordnik.swagger.annotations.ApiOperation;
|
import com.wordnik.swagger.annotations.ApiOperation;
|
||||||
@@ -50,14 +51,22 @@ public class ConfigSourcesController extends BaseRestController {
|
|||||||
protected ServicesRequestLogService servicesRequestLogService;
|
protected ServicesRequestLogService servicesRequestLogService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
TestRedisService testRedisServiceimpl;
|
ConfigRedisService configRedisServiceimpl;
|
||||||
|
|
||||||
@RequestMapping(value = "/save", method = RequestMethod.GET)
|
@RequestMapping(value = "/save", method = RequestMethod.GET)
|
||||||
@ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller")
|
@ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller")
|
||||||
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
||||||
public String testRedis() {
|
public String testRedis(String id) {
|
||||||
try {
|
try {
|
||||||
testRedisServiceimpl.saveConfigCompile();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
|
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);
|
||||||
return "ok";
|
return "ok";
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.nis.web.service.restful;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* <p>Title: ConfigRedisService</p>
|
||||||
|
* <p>Description: 保存配置到redis中</p>
|
||||||
|
* <p>Company: IIE</p>
|
||||||
|
* @author rkg
|
||||||
|
* @date 2018年5月17日
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface ConfigRedisService {
|
||||||
|
public void saveConfigYSPDemoCompile(int service, Map<String, String> map);
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package com.nis.web.service.restful;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import com.nis.datasource.DynamicJedisDataBase;
|
||||||
|
import com.nis.domain.MaatXmlConfig;
|
||||||
|
import com.nis.domain.MaatXmlExpr;
|
||||||
|
import com.nis.domain.MaatXmlSeq;
|
||||||
|
import com.nis.util.ReadMaatXmlUtil;
|
||||||
|
import com.nis.web.dao.impl.BaseRedisDao;
|
||||||
|
|
||||||
|
@Service("configRedisServiceimpl")
|
||||||
|
public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> implements ConfigRedisService {
|
||||||
|
@Transactional
|
||||||
|
public void saveConfigYSPDemoCompile(int service, Map<String, String> map) {
|
||||||
|
if (map != null && map.size() > 0) {
|
||||||
|
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
|
||||||
|
if (maatXmlConfig != null) {
|
||||||
|
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||||
|
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||||
|
StringBuffer keyBF = new StringBuffer();
|
||||||
|
String[] keySplit = maatXmlExpr.getKeyExpression().split(";");
|
||||||
|
for (String keyStr : keySplit) {
|
||||||
|
if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("[")) {
|
||||||
|
keyStr = keyStr.trim().replace("[", "").replace("]", "");
|
||||||
|
keyBF.append(map.get(keyStr));
|
||||||
|
} else {
|
||||||
|
keyBF.append(keyStr.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StringBuffer valBF = new StringBuffer();
|
||||||
|
//valBF.append("\"");
|
||||||
|
String[] valSplit = maatXmlExpr.getValueExpression().split(";");
|
||||||
|
for (String valStr : valSplit) {
|
||||||
|
if (!StringUtils.isEmpty(valStr) && valStr.trim().startsWith("[")) {
|
||||||
|
valStr = valStr.trim().replace("[", "").replace("]", "");
|
||||||
|
valBF.append(map.get(valStr));
|
||||||
|
} else if (valStr.equals(" ")) {
|
||||||
|
valBF.append(" ");
|
||||||
|
} else {
|
||||||
|
valBF.append(valStr.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//valBF.append("\"");
|
||||||
|
DynamicJedisDataBase.setRedisDataBase(maatXmlExpr.getRedisDB(), redisTemplate);
|
||||||
|
// redisTemplate.boundValueOps(keyBF.toString()).append(valBF.toString());
|
||||||
|
System.out.println(keyBF.toString());
|
||||||
|
System.out.println(valBF.toString());
|
||||||
|
redisTemplate.opsForValue().set(keyBF.toString(), valBF.toString());
|
||||||
|
//redisTemplate.boundValueOps(keyBF.toString()).set(valBF.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
List<MaatXmlSeq> seqList = maatXmlConfig.getSequenceList();
|
||||||
|
for (MaatXmlSeq maatXmlSeq : seqList) {
|
||||||
|
DynamicJedisDataBase.setRedisDataBase(maatXmlSeq.getRedisDB(), redisTemplate);
|
||||||
|
String seqKey = maatXmlSeq.getSequenceKey();
|
||||||
|
Integer operation = maatXmlSeq.getOperation();
|
||||||
|
if (operation == 1) {
|
||||||
|
redisTemplate.boundValueOps(seqKey).increment(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("\\t");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void test() {
|
||||||
|
|
||||||
|
DynamicJedisDataBase.setRedisDataBase(2, redisTemplate);
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
redisTemplate.boundZSetOps("1").add("a" + i, i);
|
||||||
|
if (i == 5) {
|
||||||
|
// int a = 1 / 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 切换redis数据库
|
||||||
|
DynamicJedisDataBase.setRedisDataBase(3, redisTemplate);
|
||||||
|
for (int i = 10; i < 20; i++) {
|
||||||
|
redisTemplate.boundZSetOps("1").add("a" + i, i);
|
||||||
|
if (i == 5) {
|
||||||
|
// int a = 1 / 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DynamicJedisDataBase.setRedisDataBase(4, redisTemplate);
|
||||||
|
for (int i = 20; i < 30; i++) {
|
||||||
|
redisTemplate.boundZSetOps("1").add("a" + i, i);
|
||||||
|
if (i == 25) {
|
||||||
|
int a = 1 / 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.nis.web.service.restful;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* <p>Title: TestRedisService</p>
|
|
||||||
* <p>Description: 测试redis事务</p>
|
|
||||||
* <p>Company: IIE</p>
|
|
||||||
* @author rkg
|
|
||||||
* @date 2018年5月17日
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface TestRedisService {
|
|
||||||
public void saveConfigCompile();
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package com.nis.web.service.restful;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import com.nis.datasource.DynamicJedisDataBase;
|
|
||||||
import com.nis.web.dao.impl.BaseRedisDao;
|
|
||||||
|
|
||||||
@Service("testRedisServiceimpl")
|
|
||||||
public class TestRedisServiceimpl extends BaseRedisDao<String, String> implements TestRedisService {
|
|
||||||
@Transactional
|
|
||||||
public void saveConfigCompile() {
|
|
||||||
DynamicJedisDataBase.setRedisDataBase(2, redisTemplate);
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
redisTemplate.boundZSetOps("1").add("a" + i, i);
|
|
||||||
if (i == 5) {
|
|
||||||
// int a = 1 / 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 切换redis数据库
|
|
||||||
DynamicJedisDataBase.setRedisDataBase(3, redisTemplate);
|
|
||||||
for (int i = 10; i < 20; i++) {
|
|
||||||
redisTemplate.boundZSetOps("1").add("a" + i, i);
|
|
||||||
if (i == 5) {
|
|
||||||
// int a = 1 / 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DynamicJedisDataBase.setRedisDataBase(4, redisTemplate);
|
|
||||||
for (int i = 20; i < 30; i++) {
|
|
||||||
redisTemplate.boundZSetOps("1").add("a" + i, i);
|
|
||||||
if (i == 25) {
|
|
||||||
int a = 1 / 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,10 +3,11 @@
|
|||||||
xsi:schemaLocation="http://www.w3school.com.cn maat.xsd">
|
xsi:schemaLocation="http://www.w3school.com.cn maat.xsd">
|
||||||
|
|
||||||
|
|
||||||
<p:maatType service="96,97,98,99,100,101,160,161,162,163,164,165">
|
<p:maatType service="96;97;98;99;100;101;160;161;162;163;164;165">
|
||||||
<p:expressions>
|
<p:expressions>
|
||||||
<p:keyExpression>file_index_info,[cfg_id]</p:keyExpression>
|
<p:keyExpression>file_index_info;,;[cfg_id]</p:keyExpression>
|
||||||
<p:valueExpression>[cfg_id],\t,[is_valid],\t,[dst_file],\t,[dst_file_md5],\t,[time_stamp],$nbsp,[level],\t,[file_id]\n</p:valueExpression>
|
<p:valueExpression>[cfg_id];\t;[is_valid];\t;[dst_file];\t;[dst_file_md5];\t;[time_stamp];&nbsp;[level];\t;[file_id];\n</p:valueExpression>
|
||||||
|
<p:redisDB>2</p:redisDB>
|
||||||
</p:expressions>
|
</p:expressions>
|
||||||
</p:maatType>
|
</p:maatType>
|
||||||
|
|
||||||
|
|||||||
@@ -12,13 +12,6 @@
|
|||||||
</xs:documentation>
|
</xs:documentation>
|
||||||
</xs:annotation>
|
</xs:annotation>
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:attribute name="service" type="xs:string" use="required">
|
|
||||||
<xs:annotation>
|
|
||||||
<xs:documentation><![CDATA[业务类型,多个业务类型用逗号分隔]]>
|
|
||||||
</xs:documentation>
|
|
||||||
</xs:annotation>
|
|
||||||
|
|
||||||
</xs:attribute>
|
|
||||||
<xs:sequence>
|
<xs:sequence>
|
||||||
<xs:element name="sequences">
|
<xs:element name="sequences">
|
||||||
<xs:annotation>
|
<xs:annotation>
|
||||||
@@ -77,7 +70,7 @@
|
|||||||
<xs:documentation>
|
<xs:documentation>
|
||||||
<![CDATA[rediskey规则,以[]包围的代表可变项,
|
<![CDATA[rediskey规则,以[]包围的代表可变项,
|
||||||
需要从map中获取的值,直接写的代表是固定值,直接拼接即可,
|
需要从map中获取的值,直接写的代表是固定值,直接拼接即可,
|
||||||
每个属性间用逗号分隔,空格用&nbsp表示]]>
|
每个属性间用分号分隔,空格用&nbsp表示]]>
|
||||||
</xs:documentation>
|
</xs:documentation>
|
||||||
</xs:annotation>
|
</xs:annotation>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
@@ -86,7 +79,7 @@
|
|||||||
<xs:documentation>
|
<xs:documentation>
|
||||||
<![CDATA[redisvalue规则,以[]包围的代表可变项,
|
<![CDATA[redisvalue规则,以[]包围的代表可变项,
|
||||||
需要从map中获取的值,直接写的代表是固定值,直接拼接即可,
|
需要从map中获取的值,直接写的代表是固定值,直接拼接即可,
|
||||||
每个属性间用逗号分隔,空格用&nbsp表示]]>
|
每个属性间用分号分隔,空格用&nbsp表示]]>
|
||||||
</xs:documentation>
|
</xs:documentation>
|
||||||
</xs:annotation>
|
</xs:annotation>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
@@ -107,6 +100,15 @@
|
|||||||
</xs:element>
|
</xs:element>
|
||||||
|
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
|
|
||||||
|
|
||||||
|
<xs:attribute name="service" type="xs:string" use="required">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation><![CDATA[业务类型,多个业务类型用分号分隔]]>
|
||||||
|
</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
|
||||||
|
</xs:attribute>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
|
|
||||||
import com.nis.web.service.restful.TestRedisService;
|
import com.nis.web.service.restful.ConfigRedisService;
|
||||||
|
|
||||||
@WebAppConfiguration
|
@WebAppConfiguration
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@@ -21,11 +21,11 @@ import com.nis.web.service.restful.TestRedisService;
|
|||||||
public class RedisTest {
|
public class RedisTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
TestRedisService configService;
|
ConfigRedisService configService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTrans() {
|
public void testTrans() {
|
||||||
configService.saveConfigCompile();
|
//configService.saveConfigCompile();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user