Merge branch 'develop' of http://10.0.6.99/common/maat_service.git into develop

This commit is contained in:
RenKaiGe-Office
2018-05-25 15:36:25 +08:00
11 changed files with 847 additions and 4 deletions

View File

@@ -618,6 +618,11 @@
<artifactId>httpclient</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.4</version>
</dependency>
<!-- spring-data-redis -->
<dependency>

View File

@@ -0,0 +1,105 @@
/**
*
*/
package com.nis.domain.restful;
/**
* @ClassName:CommonSourceCfg
* @Description:TODO(这里用一句话描述这个类的作用)
* @author (zdx)
* @date 2018年5月19日 下午8:00:45
* @version V1.0
*/
public class CommonSourceFieldCfg {
private String fieldType;
private String srcName;
private String dstName;
private String range;
private Boolean isRequired=false;
private String defaultVal;
private String regexp;
public CommonSourceFieldCfg() {
super();
// TODO Auto-generated constructor stub
}
/**
* @param fieldType
* @param srcName
* @param dstName
* @param range
* @param isRequired
* @param defauleVal
* @param regexp
*/
public CommonSourceFieldCfg(String fieldType, String srcName,
String dstName, String range, Boolean isRequired,
String defaultVal, String regexp) {
super();
this.fieldType = fieldType;
this.srcName = srcName;
this.dstName = dstName;
this.range = range;
this.isRequired = isRequired;
this.defaultVal = defaultVal;
this.regexp = regexp;
}
public String getSrcName() {
return srcName;
}
public void setSrcName(String srcName) {
this.srcName = srcName;
}
public String getDstName() {
return dstName;
}
public void setDstName(String dstName) {
this.dstName = dstName;
}
public Boolean getIsRequired() {
return isRequired;
}
public void setIsRequired(Boolean isRequired) {
this.isRequired = isRequired;
}
public String getDefaultVal() {
return defaultVal;
}
public void setDefaultVal(String defaultVal) {
this.defaultVal = defaultVal;
}
public String getFieldType() {
return fieldType;
}
public void setFieldType(String fieldType) {
this.fieldType = fieldType;
}
public String getRange() {
return range;
}
public void setRange(String range) {
this.range = range;
}
public String getRegexp() {
return regexp;
}
public void setRegexp(String regexp) {
this.regexp = regexp;
}
}

View File

@@ -0,0 +1,77 @@
/**
*
*/
package com.nis.domain.restful;
import java.util.Date;
/**
* @ClassName:FileDesc
* @Description:TODO(这里用一句话描述这个类的作用)
* @author (zdx)
* @date 2018年5月21日 下午8:09:06
* @version V1.0
*/
public class FileDesc {
private String filetype;
private Date createTime;
private String key;
private String fileName;
private String checksum;
/**
*
*/
public FileDesc() {
super();
// TODO Auto-generated constructor stub
}
/**
* @param filetype
* @param createTime
* @param key
* @param fileName
* @param checksum
*/
public FileDesc(String filetype, Date createTime, String key,
String fileName, String checksum) {
super();
this.filetype = filetype;
this.createTime = createTime;
this.key = key;
this.fileName = fileName;
this.checksum = checksum;
}
public String getFiletype() {
return filetype;
}
public void setFiletype(String filetype) {
this.filetype = filetype;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getChecksum() {
return checksum;
}
public void setChecksum(String checksum) {
this.checksum = checksum;
}
}

View File

@@ -0,0 +1,110 @@
/**
*
*/
package com.nis.util;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.nis.domain.restful.CommonSourceFieldCfg;
/**
* @ClassName:ReadCommSourceXmlUtil
* @Description:TODO(这里用一句话描述这个类的作用)
* @author (zdx)
* @date 2018年5月19日 下午7:57:52
* @version V1.0
*/
public class ReadCommSourceXmlUtil {
private static Logger logger = LoggerFactory.getLogger(ReadCommSourceXmlUtil.class);
private static String XMLPATH = "/commonSources/commonSources.xml";
public static Map<String, List<CommonSourceFieldCfg>> commonSourceCfgMap = new HashMap<String, List<CommonSourceFieldCfg>>();
static {
readCfgXml();
}
public static void main(String[] args) {
try {
readCfgXml();
Set<String> keySet = commonSourceCfgMap.keySet();
for (String key : keySet) {
List<CommonSourceFieldCfg> fieldCfgList = commonSourceCfgMap.get(key);
for (CommonSourceFieldCfg commonSourceFieldCfg : fieldCfgList) {
System.out.println("srcName:"+commonSourceFieldCfg.getSrcName()+",dstName:"+commonSourceFieldCfg.getDstName()+",val:"+commonSourceFieldCfg.getRegexp());
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static List<CommonSourceFieldCfg> getCommonSourceCfgByService(String service) {
return commonSourceCfgMap.get(service);
}
private static void readCfgXml() {
try {
InputStream resourceAsStream = ReadCommSourceXmlUtil.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 serviceIdsStr = element.attribute("serviceIds").getValue();
if (serviceIdsStr != null && !serviceIdsStr.trim().equals("")) {
String[] serviceIds = serviceIdsStr.split(",");
for (String serviceId : serviceIds) {
if (!StringUtil.isEmpty(serviceId.trim())) {
List<CommonSourceFieldCfg> cfgList = new ArrayList<CommonSourceFieldCfg>();
List<Element> fieldElmt = element.elements("field");
for (Element field : fieldElmt) {
CommonSourceFieldCfg fieldCfg = new CommonSourceFieldCfg();
fieldCfg.setFieldType(field.attribute("fieldType").getValue());
fieldCfg.setSrcName(field.attribute("srcName").getValue());
fieldCfg.setDstName(field.attribute("dstName").getValue());
if (!StringUtil.isEmpty(field.attribute("range"))) {
fieldCfg.setRange(field.attribute("range").getValue());
}
if (!StringUtil.isEmpty(field.attribute("isRequired"))) {
fieldCfg.setIsRequired(Boolean.valueOf(field.attribute("isRequired").getValue()));
}
if (!StringUtil.isEmpty(field.attribute("defaultVal"))) {
fieldCfg.setDefaultVal(field.attribute("defaultVal").getValue());
}
if (!StringUtil.isEmpty(field.attribute("regexp"))) {
fieldCfg.setRegexp(field.attribute("regexp").getValue());
}
cfgList.add(fieldCfg);
}
commonSourceCfgMap.put(serviceId.trim(), cfgList);
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
logger.error("加载commonSources.xml失败", e);
}
}
}

View File

@@ -43,7 +43,7 @@ import com.nis.web.service.ServicesRequestLogService;
*/
public class BaseRestController {
protected final Logger logger = Logger.getLogger(this.getClass());
private SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHssSSS");
private SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
/**
*
* @Title: serviceResponse

View File

@@ -1,5 +1,6 @@
package com.nis.web.controller.restful;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@@ -9,15 +10,20 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.nis.domain.restful.ConfigCompile;
import com.nis.domain.restful.ConfigSource;
import com.nis.domain.restful.FileDesc;
import com.nis.domain.restful.MaatConfig;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException;
@@ -28,6 +34,8 @@ import com.nis.util.StringUtils;
import com.nis.web.controller.BaseRestController;
import com.nis.web.service.SaveRequestLogThread;
import com.nis.web.service.ServicesRequestLogService;
import com.nis.web.service.fdfs.FastDFSFile;
import com.nis.web.service.fdfs.FileManager;
import com.nis.web.service.restful.ConfigRedisService;
import com.nis.web.service.restful.ConfigSourcesService;
import com.wordnik.swagger.annotations.Api;
@@ -460,6 +468,65 @@ public class ConfigSourcesController extends BaseRestController {
}
}
@RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.POST, produces=org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "回调配置存储", httpMethod = "POST", response = Map.class, notes = "回调配置存储服务")
//@ApiParam(value = "回调配置数据源", name = "JSONObject", requirerue)
public Map createCommonConfigSource(@RequestBody String jsonString , HttpServletRequest request,
HttpServletResponse response) {
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
long start = System.currentTimeMillis();
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,null);
StringBuffer sb = new StringBuffer();
configSourcesService.savaCommonSources(thread, start, jsonString, sb);
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
"配置数据插入成功" , Constants.IS_DEBUG ? jsonString : null);
}
@RequestMapping(value = "/cfg/v1/fileUploadSources", method = RequestMethod.POST)
@ApiOperation(value = "样例文件上传服务", httpMethod = "POST", response = Map.class, notes = "样例文件上传服务")
@ApiParam(value = "样例文件上传服务", name = "MultipartFile", required = true)
public Map fileUploadSource(@RequestBody MultipartFile file, HttpServletRequest request,
HttpServletResponse response) {
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
long start = System.currentTimeMillis();
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,null);
String filePath ="";
try {
FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),FileDesc.class);
if (!StringUtil.isEmpty(fileDesc.getChecksum())) {
//验证Md5
String md5 = DigestUtils.md5Hex(file.getBytes());
System.out.println("----------------------------MD5:'"+md5+"'==='"+fileDesc.getChecksum()+"'");
if (!md5.equals(fileDesc.getChecksum())) {
thread.setExceptionInfo("checksum与文件MD5值不一致");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "checksum与文件MD5值不一致",
RestBusinessCode.config_integrity_error.getValue());
}
String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
FastDFSFile fdsfile = new FastDFSFile(file.getBytes(),file.getOriginalFilename(), ext);
// NameValuePair[] meta_list = new NameValuePair[5];
// meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename());
// meta_list[1] = new NameValuePair("fileLength", String.valueOf(file.getSize()));
// meta_list[2] = new NameValuePair("fileExt", ext);
// meta_list[3] = new NameValuePair("fileAuthor", "rkg");
// meta_list[4] = new NameValuePair("fileMd5", md5);
filePath = FileManager.upload(fdsfile, null);
}else{
thread.setExceptionInfo("请求头信息中缺少checksum参数");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求头信息中缺少checksum参数",
RestBusinessCode.missing_args.getValue());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONObject jsonObj = new JSONObject();
jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group")));
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
"文件上传成功" ,jsonObj);
}
private boolean isBlank(Date datetime) {
if (null != datetime) {

View File

@@ -4,15 +4,19 @@
package com.nis.web.service.restful;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.nis.domain.restful.ConfigPzIdSource;
import com.nis.util.StringUtil;
import com.nis.web.dao.ConfigPzIdDao;
import com.nis.web.service.BaseLogService;
import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIConversion.Static;
/**
* @ClassName:ConfigPzIdService
@@ -31,11 +35,23 @@ public class ConfigPzIdService extends BaseLogService {
@Autowired
protected ConfigPzIdDao dao;
@Autowired
ConfigRedisService configRedisService;
private static Map<String, String> sourceNameMap = new HashMap<String, String>();
static {
sourceNameMap.put("CONFIG_COMPILE", "SEQ_COMPILEID");
sourceNameMap.put("CONFIG_GROUP", "SEQ_GROUPID");
sourceNameMap.put("CONFIG_REGION", "SEQ_REGIONID");
}
public ConfigPzIdSource getConfigPzIdList(ConfigPzIdSource entity){
List<Long> pzIdList = new ArrayList<Long>();
entity.setSourceName(entity.getSourceName().toUpperCase());
String seqName= StringUtil.isEmpty(sourceNameMap.get(entity.getSourceName()))?"SEQ_COMPILEID":sourceNameMap.get(entity.getSourceName());
for (int i = 0; i < entity.getNum(); i++) {
pzIdList.add(dao.getConfigPzIdList(entity));
//pzIdList.add(dao.getConfigPzIdList(entity)); //直接从数据库序列号获取
pzIdList.add(configRedisService.getIncrId(seqName));
}
entity.setPzIdList(pzIdList);
return entity;

View File

@@ -2,12 +2,20 @@ package com.nis.web.service.restful;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.CountDownLatch;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sf.json.JSONObject;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
@@ -16,7 +24,11 @@ import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.nis.domain.Page;
import com.nis.domain.restful.CommonSourceFieldCfg;
import com.nis.domain.restful.ConfigCompile;
import com.nis.domain.restful.ConfigCompileTest;
import com.nis.domain.restful.ConfigGroupRelation;
@@ -27,9 +39,11 @@ import com.nis.domain.restful.StrRegion;
import com.nis.restful.CompileJudgeCode;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException;
import com.nis.util.BasicProvingUtil;
import com.nis.util.CompileVal;
import com.nis.util.Configurations;
import com.nis.util.OracleErrorCodeUtil;
import com.nis.util.ReadCommSourceXmlUtil;
import com.nis.util.StringUtil;
import com.nis.util.StringUtils;
import com.nis.web.dao.ConfigCompileDao;
@@ -78,6 +92,11 @@ public class ConfigSourcesService extends BaseService {
@Autowired
private StrRegionDao strRegionDao;
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
@Autowired
ConfigRedisService configRedisService;
public static Map<Integer, Map<String, String>> getTableRelation() {
Map<Integer, Map<String, String>> tableMap = new HashMap<Integer, Map<String, String>>();
Map<String, String> typeMap = new HashMap<String, String>();
@@ -2077,6 +2096,135 @@ public class ConfigSourcesService extends BaseService {
return "ok";
}
public String savaCommonSources(SaveRequestLogThread thread, long start,String jsonString,
StringBuffer sb) {
JsonArray jsonObjectList = new JsonParser().parse(jsonString).getAsJsonArray();
Map<Integer,List<Map<String, String>>> dstMaps = new HashMap<Integer, List<Map<String,String>>>();
for (int i = 0; i < jsonObjectList.size(); i++) {
JsonObject jsonObj=(JsonObject) jsonObjectList.get(i);
Map<String, Object> srcMap = JSONObject.fromObject(JSONObject.fromObject((jsonObj.toString())));
if(srcMap.containsKey("service")){
Map<String,String> dstMap = new HashMap<String, String>();
List<CommonSourceFieldCfg> commonSourceFieldCfgList = ReadCommSourceXmlUtil.getCommonSourceCfgByService(srcMap.get("service").toString().trim());
if (StringUtil.isEmpty(commonSourceFieldCfgList)) {
logger.error("service请检查service配置是否正确");
thread.setExceptionInfo("请检查service配置是否正确");
throw new RestServiceException(thread, System.currentTimeMillis() - start,"请检查service配置是否正确",
RestBusinessCode.wrong_range.getValue());
}
for (CommonSourceFieldCfg commonSourceFieldCfg : commonSourceFieldCfgList) {
//是否必填
if(commonSourceFieldCfg.getIsRequired()&&!srcMap.containsKey(commonSourceFieldCfg.getSrcName())){
logger.error(commonSourceFieldCfg.getSrcName()+"参数不能为空");
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数不能为空");
throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能为空",
RestBusinessCode.missing_args.getValue());
}
//字段类型 String Number Date Ip Port
String dstStr = StringUtil.isEmpty(srcMap.get(commonSourceFieldCfg.getSrcName()))?commonSourceFieldCfg.getDefaultVal():srcMap.get(commonSourceFieldCfg.getSrcName()).toString();
if (!StringUtil.isEmpty(dstStr)&&dstStr.startsWith("[")&&dstStr.endsWith("]")) {
dstStr = srcMap.get(dstStr.substring(1, dstStr.length()-1)).toString();
}
switch (commonSourceFieldCfg.getFieldType()) {
case "Number":
if(!StringUtil.isNumeric(dstStr)){
logger.error(commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,必需是数值型");
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,必需是数值型");
throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能格式不正确",
RestBusinessCode.missing_args.getValue());
}
break;
case "Date":
try {
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = sdf.parse(dstStr);
dstStr = date.getTime()+"000";
} catch (ParseException e) {
// TODO Auto-generated catch block
logger.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确,必须是日期型");
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式不正确,必须是日期型");
throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,必须是日期型",
RestBusinessCode.missing_args.getValue());
}
break;
case "Ip":
if (!isIp(dstStr)) {
logger.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确不是合法的IP地址");
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式不正确不是合法的IP地址");
throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能格式不正确不是合法的IP地址",
RestBusinessCode.missing_args.getValue());
}
break;
case "Port":
if (!BasicProvingUtil.isPortOrPortMask(dstStr)) {
logger.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确不是合法的Port");
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式不正确不是合法的Port");
throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能格式不正确不是合法的Port",
RestBusinessCode.missing_args.getValue());
}
break;
}
//range取值范围验证
if(!StringUtil.isEmpty(commonSourceFieldCfg.getRange())){
String [] range= commonSourceFieldCfg.getRange().split("-");
if(!(Long.valueOf(range[0]).compareTo(Long.valueOf(dstStr))<=0&&Long.valueOf(range[1]).compareTo(Long.valueOf(dstStr))>=0)){
logger.error(commonSourceFieldCfg.getSrcName()+"参数不在有效范围");
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数不在有效范围");
throw new RestServiceException(thread, System.currentTimeMillis() - start, commonSourceFieldCfg.getSrcName()+"参数不在有效范围",
RestBusinessCode.wrong_range.getValue());
}
}
//regexp 特殊格式正则验证
Boolean valFlag = true;
if(!StringUtil.isEmpty(commonSourceFieldCfg.getRegexp())){
Pattern pattern = Pattern.compile(commonSourceFieldCfg.getRegexp());
Matcher matcher = pattern.matcher(dstStr);
valFlag = valFlag&matcher.matches();
}
if (valFlag) {
dstMap.put(commonSourceFieldCfg.getDstName(),dstStr);
}else{
logger.error(commonSourceFieldCfg.getSrcName()+"参数格式与正则不匹配");
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式与正则不匹配");
throw new RestServiceException(thread, System.currentTimeMillis() - start, commonSourceFieldCfg.getSrcName()+"参数格式不正确或数据不在有效范围",
RestBusinessCode.param_formate_error.getValue());
}
}
if (StringUtil.isEmpty(dstMaps.get(Integer.valueOf(srcMap.get("service").toString())))) {
List<Map<String, String>> list = new ArrayList<Map<String,String>>();
list.add(dstMap);
dstMaps.put(Integer.valueOf(srcMap.get("service").toString()), list);
}else{
List<Map<String, String>> list = dstMaps.get(Integer.valueOf(srcMap.get("service").toString()));
list.add(dstMap);
}
}else{
thread.setExceptionInfo("service参数不能为空");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "service参数不能为空",
RestBusinessCode.missing_args.getValue());
}
}
Iterator iterator =dstMaps.keySet().iterator();
while (iterator.hasNext()) {
Integer key = Integer.valueOf(iterator.next().toString());
configRedisService.saveUnMaatConfig(dstMaps.get(key),key);
// configRedisService.saveConfigYSPDemoCompile(key,);
}
return "ok";
}
private boolean isIp(String ipStr){
if (!(BasicProvingUtil.isIpOrIpMask(ipStr,4)||BasicProvingUtil.isIpOrIpMask(ipStr,6))) {
return false;
}
return true;
}
public String setCompileInvalid(ConfigCompile configCompile) throws Exception {
configCompileDao.setCompileInvalid(configCompile.getCompileId(), 0);
return "ok";

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<t:commonSources xmlns:t="http://www.w3school.com.cn"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3school.com.cn commonSourcesSchema.xsd">
<t:commonSource serviceIds="96,97,98,99,160,161,162,163">
<t:field fieldType="String" srcName="service" dstName="service" isRequired="true"/>
<t:field fieldType="Number" srcName="cfgId" dstName="cfg_id" isRequired="true" />
<t:field fieldType="String" srcName="dstFile" dstName="dst_file" isRequired="true"/>
<t:field fieldType="String" srcName="dstFileMd5" dstName="dst_file_md5" isRequired="true"/>
<t:field fieldType="Number" srcName="level" dstName="level" range="0-100" defaultVal="0"/>
<t:field fieldType="Number" srcName="isValid" dstName="is_valid" isRequired="true" range="0-1"/>
<t:field fieldType="Date" srcName="opTime" dstName="time_stamp" isRequired="true"/>
<t:field fieldType="Number" srcName="" dstName="file_id" defaultVal="[cfgId]"/>
</t:commonSource>
<t:commonSource serviceIds="100,101,164,165">
<t:field fieldType="String" srcName="service" dstName="service" isRequired="true"/>
<t:field fieldType="Number" srcName="cfgId" dstName="cfg_id" isRequired="true" />
<t:field fieldType="String" srcName="description" dstName="description" isRequired="true"/>
<t:field fieldType="Number" srcName="level" dstName="level" range="0-100" defaultVal="0"/>
<t:field fieldType="Number" srcName="isValid" dstName="is_valid" isRequired="true" range="0-1"/>
</t:commonSource>
</t:commonSources>

View File

@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3school.com.cn"
targetNamespace="http://www.w3school.com.cn" elementFormDefault="qualified">
<xs:element name="commonSources">
<xs:complexType>
<xs:sequence>
<xs:element name="commonSource">
<xs:complexType>
<xs:sequence>
<xs:element name="field" >
<xs:complexType>
<xs:attribute name="srcName" type="xs:string" use="required">
<xs:annotation>
<xs:documentation><![CDATA[源字段名]]>
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="dstName" type="xs:string" use="required">
<xs:annotation>
<xs:documentation><![CDATA[目的字段名]]>
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="fieldType" use="required">
<xs:annotation>
<xs:documentation><![CDATA[字段类型]]>
</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="String"></xs:enumeration>
<xs:enumeration value="Date"></xs:enumeration>
<xs:enumeration value="Number"></xs:enumeration>
<xs:enumeration value="IP"></xs:enumeration>
<xs:enumeration value="Port"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="range" type="xs:string">
<xs:annotation>
<xs:documentation><![CDATA[取值范围]]>
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="isRequired" type="xs:boolean">
<xs:annotation>
<xs:documentation><![CDATA[是否必填项]]>
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="defaultVal" type="xs:string">
<xs:annotation>
<xs:documentation><![CDATA[默认值]]>
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="regexp">
<xs:annotation>
<xs:documentation><![CDATA[其他类型字段格式验证,正则表达式]]>
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="serviceIds" type="xs:string" use="required">
<xs:annotation>
<xs:documentation><![CDATA[业务Id列表多个之间用","分隔]]>
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@@ -0,0 +1,214 @@
/**
*
*/
package com.nis.test;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import net.sf.json.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Test;
import com.nis.restful.RestConstants;
import com.nis.util.JsonMapper;
/**
* @ClassName:RestTest
* @Description:TODO(这里用一句话描述这个类的作用)
* @author (zdx)
* @date 2018年5月22日 上午10:38:50
* @version V1.0
*/
public class RestTest {
@Test
public void testFileUpload() {
CloseableHttpResponse response = null;
try {
File file = new File("C:/Users/dell/Desktop/Lighthouse.jpg");
// String md5 = DigestUtils.md5Hex(file);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("file", file);
HttpPost request = new HttpPost(
"http://10.0.6.104:8080/galaxy/service/cfg/v1/fileUploadSources");
//galaxy/service/cfg/v1/fileUploadSources
JSONObject jsonObject = new JSONObject();
jsonObject.put("filetype", "doc");
jsonObject.put("createTime", "2018-05-21 21:00:00");
jsonObject.put("key", "123456789");
jsonObject.put("fileName", "1.png");
//jsonObject.put("checksum", "d99f9aa4f3748fa48aa6e350c628c67f");
jsonObject.put("checksum", "8969288f4245120e7c3870287cce0ff3");
request.setHeader("File-Desc", jsonObject.toString());
HttpEntity entity = builder.build();
request.setEntity(entity);
CloseableHttpClient httpClient = HttpClients.createDefault();
response = httpClient.execute(request);
System.out.println(EntityUtils.toString(response.getEntity()));
System.out.println("aa");
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//@Test
public void testGetPzId() {
CloseableHttpResponse response = null;
try {
HttpGet request = new HttpGet(
"http://10.0.6.104:8080/galaxy/service/cfg/v1/configPzIdSources?sourceName=CONFIGCOMPILE");
//galaxy/service/cfg/v1/fileUploadSources
JSONObject jsonObject = new JSONObject();
jsonObject.put("sourceName", "CONFIGCOMPILE");
jsonObject.put("createTime", "2018-05-21 21:00:00");
jsonObject.put("key", "123456789");
jsonObject.put("fileName", "1.png");
jsonObject.put("checksum", "d99f9aa4f3748fa48aa6e350c628c67f");
// request.setHeader("File-Desc", jsonObject.toString());
CloseableHttpClient httpClient = HttpClients.createDefault();
response = httpClient.execute(request);
//HttpEntity httpEntity = response.getEntity();
String result = EntityUtils.toString(response.getEntity());
Map<String, Object> resultMap = (Map<String, Object>)JsonMapper.fromJsonString(result, Map.class);
Map<String, Object> dataMap = (Map<String, Object>)resultMap.get(RestConstants.REST_SERVICE_DATA);
List<?> idObject = (List<?>) dataMap.get("pzIdList");
for (Object object : idObject) {
if(object instanceof Integer){
System.out.println("Integer");
}else if(object instanceof Long){
System.out.println("Long");
}
}
System.out.println("aa");
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//@Test
public void test() {
Date date = new Date();
System.out.println(date.getTime());
Calendar calendar = Calendar.getInstance();
System.out.println(calendar.getTimeInMillis());
}
//@Test
public void testSdf() {
// TODO Auto-generated method stub
try {
SimpleDateFormat df1 = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
// Date t = new Date();
Date t = df1.parse("2018-05-23 13:48:11");
Long time = t.getTime();
System.out.println(df1.format(t));
System.out.println(time);
Long time2 = (time/1000)*1000;
System.out.println(time2+" "+df1.format(time2));
System.out.println(df1.getTimeZone().getID()+"----------------"+df1.format(t));
df1.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(df1.format(t));
System.out.println("-------------------------------------------------------------------");
SimpleDateFormat df2 = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS");
Date t2 = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
System.out.println(df2.getTimeZone().getID()+"----------------"+df2.format(calendar.getTime()));
df2.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(df2.getTimeZone().getID()+"----------------"+df2.format(calendar.getTime()));
df2.setTimeZone(TimeZone.getTimeZone("UTC-8"));
System.out.println(df2.getTimeZone().getID()+"----------------"+df2.format(calendar.getTime()));
df2.setTimeZone(TimeZone.getTimeZone("GMT+8"));
System.out.println(df2.getTimeZone().getID()+"----------------"+df2.format(calendar.getTime()));
df2.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println(df2.getTimeZone().getID()+"----------------"+df2.format(calendar.getTime()));
System.out.println("-----------------------------------------");
df2.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = df2.parse("2018-05-23T13:48:11.077");
System.out.println("2018-05-23 13:48:11"+"def:"+time+" "+date.getTime()+" 差:"+(time-date.getTime())/(60*60*1000));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// try {
// String date = "2000-10-01T10:10:10.123Z";
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'");
// SimpleDateFormat df2 = new SimpleDateFormat(
// "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
// df2.setTimeZone(TimeZone.getTimeZone("GMT+8"));
// //创建被转换的对象calendar有时区信息
// Calendar calendar = new GregorianCalendar();
// calendar.setTime(df2.parse(date));
// TimeZone timeZone = TimeZone.getTimeZone("GMT+8:00");
// calendar.setTimeZone(timeZone);
//
// User test = new User();
// test.setId("111");
// test.setDate(calendar.getTime());
// ObjectMapper objectMapper = new ObjectMapper();
// String json = objectMapper.writeValueAsString(test);
// System.out.println(json);
//
// User restore = objectMapper.readValue(json, User.class);
// //System.out.print(restore.getDate().getTimeZone().getDisplayName());
// }catch (Exception e) {
// e.printStackTrace(System.out);
// }
}
}