2017-12-19 14:55:52 +08:00
|
|
|
|
package com.nis.web.service.restful;
|
|
|
|
|
|
|
2018-05-25 19:37:05 +08:00
|
|
|
|
import java.beans.IntrospectionException;
|
|
|
|
|
|
import java.beans.PropertyDescriptor;
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
|
import java.lang.reflect.Method;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import java.sql.Connection;
|
|
|
|
|
|
import java.sql.SQLException;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.HashMap;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import java.util.Iterator;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Map;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import java.util.TimeZone;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import java.util.concurrent.CountDownLatch;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
import net.sf.json.JSONObject;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
|
|
|
|
|
|
import org.apache.ibatis.session.ExecutorType;
|
|
|
|
|
|
import org.apache.ibatis.session.SqlSession;
|
|
|
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import com.google.gson.JsonArray;
|
|
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
|
|
import com.google.gson.JsonParser;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.domain.Page;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import com.nis.domain.restful.CommonSourceFieldCfg;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.domain.restful.ConfigCompile;
|
|
|
|
|
|
import com.nis.domain.restful.ConfigCompileTest;
|
|
|
|
|
|
import com.nis.domain.restful.ConfigGroupRelation;
|
2018-02-28 10:13:39 +08:00
|
|
|
|
import com.nis.domain.restful.DigestRegion;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.domain.restful.IpRegion;
|
2018-05-25 19:37:05 +08:00
|
|
|
|
import com.nis.domain.restful.MaatConfig;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.domain.restful.NumRegion;
|
|
|
|
|
|
import com.nis.domain.restful.StrRegion;
|
|
|
|
|
|
import com.nis.restful.CompileJudgeCode;
|
|
|
|
|
|
import com.nis.restful.RestBusinessCode;
|
|
|
|
|
|
import com.nis.restful.RestServiceException;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import com.nis.util.BasicProvingUtil;
|
2018-05-25 19:37:05 +08:00
|
|
|
|
import com.nis.util.CamelUnderlineUtil;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.util.CompileVal;
|
|
|
|
|
|
import com.nis.util.Configurations;
|
2018-06-01 10:27:03 +08:00
|
|
|
|
import com.nis.util.Constants;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.util.OracleErrorCodeUtil;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import com.nis.util.ReadCommSourceXmlUtil;
|
2018-06-01 10:27:03 +08:00
|
|
|
|
import com.nis.util.ServiceAndRDBIndexReal;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.util.StringUtil;
|
|
|
|
|
|
import com.nis.util.StringUtils;
|
|
|
|
|
|
import com.nis.web.dao.ConfigCompileDao;
|
|
|
|
|
|
import com.nis.web.dao.ConfigGroupRelationDao;
|
|
|
|
|
|
import com.nis.web.dao.IpRegionDao;
|
|
|
|
|
|
import com.nis.web.dao.NumRegionDao;
|
|
|
|
|
|
import com.nis.web.dao.StrRegionDao;
|
|
|
|
|
|
import com.nis.web.service.BaseService;
|
|
|
|
|
|
import com.nis.web.service.SaveRequestLogThread;
|
|
|
|
|
|
import com.nis.web.service.SpringContextHolder;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @ClassName: ControlService
|
|
|
|
|
|
* @Description: TODO(编译配置持久化)
|
|
|
|
|
|
* @author (zx)
|
|
|
|
|
|
* @date 2016年9月6日 下午1:08:12
|
|
|
|
|
|
* @version V1.0
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class ConfigSourcesService extends BaseService {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 存放多线程异常信息
|
|
|
|
|
|
*/
|
|
|
|
|
|
private static List<Exception> msgList = new ArrayList<Exception>();
|
|
|
|
|
|
|
|
|
|
|
|
public static List<Exception> getMsgList() {
|
|
|
|
|
|
return msgList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void setMsgList(List<Exception> msgList) {
|
|
|
|
|
|
ConfigSourcesService.msgList = msgList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected final Logger logger1 = Logger.getLogger(this.getClass());
|
|
|
|
|
|
private Map<Integer, Map<String, String>> map;
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ConfigCompileDao configCompileDao;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private IpRegionDao ipRegionDao;
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private NumRegionDao numRegionDao;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ConfigGroupRelationDao configGroupRelationDao;
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private StrRegionDao strRegionDao;
|
|
|
|
|
|
|
2018-05-24 17:22:38 +08:00
|
|
|
|
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
ConfigRedisService configRedisService;
|
|
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
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>();
|
2018-06-01 10:27:03 +08:00
|
|
|
|
typeMap.put("MM_AV_IP", "ip");
|
2018-05-25 19:37:05 +08:00
|
|
|
|
tableMap.put(80, typeMap);
|
|
|
|
|
|
tableMap.put(144, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
2018-06-01 10:27:03 +08:00
|
|
|
|
typeMap.put("MM_AV_URL", "str");
|
2018-05-25 19:37:05 +08:00
|
|
|
|
tableMap.put(81, typeMap);
|
|
|
|
|
|
tableMap.put(145, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
2018-06-01 10:27:03 +08:00
|
|
|
|
typeMap.put("MM_PIC_IP", "ip");
|
2018-05-25 19:37:05 +08:00
|
|
|
|
tableMap.put(82, typeMap);
|
|
|
|
|
|
tableMap.put(146, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
2018-06-01 10:27:03 +08:00
|
|
|
|
typeMap.put("MM_PIC_URL", "str");
|
2018-05-25 19:37:05 +08:00
|
|
|
|
tableMap.put(83, typeMap);
|
|
|
|
|
|
tableMap.put(147, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
2018-06-01 10:27:03 +08:00
|
|
|
|
typeMap.put("MM_VOIP_IP", "ip");
|
2018-05-25 19:37:05 +08:00
|
|
|
|
tableMap.put(84, typeMap);
|
|
|
|
|
|
tableMap.put(148, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
2018-06-01 10:27:03 +08:00
|
|
|
|
typeMap.put("MM_VOIP_ACCOUNT", "str");
|
2018-05-25 19:37:05 +08:00
|
|
|
|
tableMap.put(85, typeMap);
|
|
|
|
|
|
tableMap.put(149, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
2018-02-09 17:49:14 +08:00
|
|
|
|
typeMap.put("REUSE_IP", "ip");
|
|
|
|
|
|
typeMap.put("HID_CONTENT", "ip");
|
|
|
|
|
|
typeMap.put("GSB_PZ_IP", "ip");
|
|
|
|
|
|
typeMap.put("FAKE_REGION_EXTEND", "str");
|
2018-03-29 10:34:23 +08:00
|
|
|
|
typeMap.put("KEYWORD_RANDOM_REGION", "str");
|
2018-02-28 10:13:39 +08:00
|
|
|
|
typeMap.put("CTRL_URL_REGION", "str");
|
|
|
|
|
|
typeMap.put("CTRL_VOIP_BLACKACCOUNT_REGION", "str");
|
|
|
|
|
|
typeMap.put("CTRL_MEDIA_FILE_FP", "digest");
|
2018-02-09 17:49:14 +08:00
|
|
|
|
tableMap.put(0, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
2017-12-19 14:55:52 +08:00
|
|
|
|
typeMap.put("DF_IP_PORT", "ip");
|
2018-02-28 10:13:39 +08:00
|
|
|
|
typeMap.put("GSB_PZ_IP", "ip");//IP复用
|
2018-03-29 10:34:23 +08:00
|
|
|
|
typeMap.put("CTRL_MEDIA_FILE_FP", "digest");
|
2017-12-19 14:55:52 +08:00
|
|
|
|
tableMap.put(1, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("FX_IP_PORT", "ip");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
2018-02-28 10:13:39 +08:00
|
|
|
|
typeMap.put("GSB_PZ_IP", "ip");//网站伪造
|
2017-12-19 14:55:52 +08:00
|
|
|
|
tableMap.put(2, typeMap);
|
|
|
|
|
|
|
2018-03-29 10:34:23 +08:00
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("CTRL_VOIP_BLACKACCOUNT_REGION", "str");
|
|
|
|
|
|
tableMap.put(118, typeMap);
|
|
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DF_HTTP_REQ_HDR", "str");
|
|
|
|
|
|
typeMap.put("DF_HTTP_URL", "str");
|
2018-02-28 10:13:39 +08:00
|
|
|
|
typeMap.put("GSB_PZ_IP", "ip");//内容篡改
|
2017-12-19 14:55:52 +08:00
|
|
|
|
tableMap.put(3, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DF_HTTP_RES_HDR", "str");
|
2018-02-28 10:13:39 +08:00
|
|
|
|
typeMap.put("GSB_PZ_IP", "ip");//随机丢包
|
2018-03-29 10:34:23 +08:00
|
|
|
|
typeMap.put("CTRL_URL_REGION", "str");
|
2017-12-19 14:55:52 +08:00
|
|
|
|
tableMap.put(4, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DF_HTTP_REQ_BODY", "str");
|
|
|
|
|
|
typeMap.put("DF_HTTP_RES_BODY", "str");
|
|
|
|
|
|
tableMap.put(5, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DF_MAIL_HDR", "str");
|
|
|
|
|
|
typeMap.put("DF_MAIL_BODY", "str");
|
|
|
|
|
|
tableMap.put(13, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DF_DNS_REGION", "str");
|
|
|
|
|
|
tableMap.put(6, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DF_FTP_URL", "str");
|
|
|
|
|
|
tableMap.put(14, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
tableMap.put(7, typeMap);
|
|
|
|
|
|
tableMap.put(8, typeMap);
|
|
|
|
|
|
tableMap.put(9, typeMap);
|
|
|
|
|
|
tableMap.put(10, typeMap);
|
|
|
|
|
|
tableMap.put(11, typeMap);
|
|
|
|
|
|
typeMap.put("DF_SSL_REGION", "str");
|
|
|
|
|
|
tableMap.put(12, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("FX_HTTP_REQ_HDR", "str");
|
|
|
|
|
|
typeMap.put("FX_HTTP_URL", "str");
|
2018-06-01 10:27:03 +08:00
|
|
|
|
|
|
|
|
|
|
typeMap.put("WHITE_LIST_IP", "ip");
|
2017-12-19 14:55:52 +08:00
|
|
|
|
tableMap.put(15, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("FX_DNS_REGION", "str");
|
|
|
|
|
|
tableMap.put(16, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("DJ_IP_PORT", "ip");
|
|
|
|
|
|
typeMap.put("DJ_IP_PKT_BIN", "str");
|
|
|
|
|
|
tableMap.put(48, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DJ_HTTP_REQ_HDR", "str");
|
|
|
|
|
|
typeMap.put("DJ_HTTP_URL", "str");
|
|
|
|
|
|
tableMap.put(49, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DJ_HTTP_RES_HDR", "str");
|
|
|
|
|
|
tableMap.put(50, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DJ_HTTP_REQ_BODY", "str");
|
|
|
|
|
|
typeMap.put("DJ_HTTP_RES_BODY", "str");
|
|
|
|
|
|
tableMap.put(51, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DJ_MAIL_HDR", "str");
|
|
|
|
|
|
typeMap.put("DJ_MAIL_BODY", "str");
|
|
|
|
|
|
tableMap.put(60, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DJ_DNS_RES_REGION", "str");
|
|
|
|
|
|
typeMap.put("DJ_DNS_REQ_REGION", "str");
|
|
|
|
|
|
tableMap.put(52, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DJ_FTP_URL", "str");
|
|
|
|
|
|
tableMap.put(53, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
tableMap.put(54, typeMap);
|
|
|
|
|
|
tableMap.put(55, typeMap);
|
|
|
|
|
|
tableMap.put(56, typeMap);
|
|
|
|
|
|
tableMap.put(57, typeMap);
|
|
|
|
|
|
tableMap.put(58, typeMap);
|
|
|
|
|
|
typeMap.put("DJ_SSL_REGION", "str");
|
|
|
|
|
|
tableMap.put(59, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DF_L2TP_URL", "str");
|
|
|
|
|
|
tableMap.put(32, typeMap);
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DF_PPTP_URL", "str");
|
|
|
|
|
|
tableMap.put(33, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
// 20161109新增业务类型
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DF_HTTP_REQ_HDR", "str");
|
|
|
|
|
|
typeMap.put("DF_HTTP_REQ_BODY", "str");
|
|
|
|
|
|
typeMap.put("DF_HTTP_URL", "str");
|
|
|
|
|
|
tableMap.put(17, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DF_HTTP_RES_HDR", "str");
|
|
|
|
|
|
typeMap.put("DF_HTTP_RES_BODY", "str");
|
|
|
|
|
|
typeMap.put("DF_HTTP_URL", "str");
|
|
|
|
|
|
tableMap.put(18, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DJ_HTTP_REQ_HDR", "str");
|
|
|
|
|
|
typeMap.put("DJ_HTTP_REQ_BODY", "str");
|
|
|
|
|
|
typeMap.put("DJ_HTTP_URL", "str");
|
|
|
|
|
|
tableMap.put(61, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
typeMap.put("DJ_HTTP_RES_HDR", "str");
|
|
|
|
|
|
typeMap.put("DJ_HTTP_RES_BODY", "str");
|
|
|
|
|
|
typeMap.put("DJ_HTTP_URL", "str");
|
|
|
|
|
|
tableMap.put(62, typeMap);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typeMap = new HashMap<String, String>();
|
|
|
|
|
|
typeMap.put("UNIVERSAL_PROTO_TYPE", "num");
|
|
|
|
|
|
typeMap.put("UNIVERSAL_IP", "ip");
|
|
|
|
|
|
tableMap.put(35, typeMap);
|
|
|
|
|
|
tableMap.put(36, typeMap);
|
|
|
|
|
|
tableMap.put(37, typeMap);
|
|
|
|
|
|
return tableMap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 批量(mybatis方式)修改配置业务逻辑-->1:先进行基础配置验证传过来的json串是否符合格式(配置分组关系前端不能设置为无效,程序会根据传过来的编译配置和域配置等信息自动设置为无效).
|
|
|
|
|
|
* 符合要求调用updateConfigCompile方法继续验证
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param thread
|
|
|
|
|
|
* 保存异常信息入库对象
|
|
|
|
|
|
* @param start
|
|
|
|
|
|
* 进入controller的时间
|
|
|
|
|
|
* @param compileList
|
|
|
|
|
|
* 编译配置集合
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void updateConfigSource(SaveRequestLogThread thread, long start, List<ConfigCompile> configSource,
|
|
|
|
|
|
Date opTime, StringBuffer sb) {
|
|
|
|
|
|
SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class);
|
|
|
|
|
|
SqlSession batchSqlSession = null;
|
|
|
|
|
|
try {
|
|
|
|
|
|
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
|
|
|
|
|
if (null != configSource && configSource.size() > 0) {
|
|
|
|
|
|
for (ConfigCompile config : configSource) {
|
|
|
|
|
|
String msg = CompileVal.compileIsOk(config, true, sb);
|
|
|
|
|
|
if (msg != CompileJudgeCode.CompileIsOk.getErrorReason()) {
|
|
|
|
|
|
thread.setExceptionInfo(msg + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
updateConfigCompile(thread, start, config, batchSqlSession, opTime, sb);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
thread.setExceptionInfo("编译配置不能为空" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
logger1.info("数据保存到数据库提交事务开始");
|
|
|
|
|
|
batchSqlSession.commit();
|
|
|
|
|
|
logger1.info("数据保存到数据库成功");
|
|
|
|
|
|
} catch (RestServiceException e) {
|
|
|
|
|
|
logger1.error(e);
|
|
|
|
|
|
thread.setExceptionInfo(e.getMessage() + " " + e.getCause() + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, e.getMessage() + sb.toString(),
|
|
|
|
|
|
e.getErrorCode());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
|
|
logger1.error(e);
|
|
|
|
|
|
String errorCode = OracleErrorCodeUtil.getOraCode(e);
|
|
|
|
|
|
if (!StringUtils.isEmpty(errorCode)) {
|
|
|
|
|
|
logger1.error("数据更新发生异常!");
|
|
|
|
|
|
thread.setExceptionInfo(e.getMessage() + " " + e.getCause() + sb.toString());
|
|
|
|
|
|
OracleErrorCodeUtil.throwExceptionInfo(thread, System.currentTimeMillis() - start, errorCode);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
thread.setExceptionInfo("数据更新发生异常" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "数据更新发生异常" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.unknow_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
if (batchSqlSession != null) {
|
|
|
|
|
|
batchSqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 批量(mybatis方式)修改配置业务逻辑-->2:判断配置在数据库中是否已经是无效了如果是无效则提示不能修改无效的配置为有效(因为如果数据库中的编译配置与配置分组关系以及域配置均是无效,传过来的数据是编译配置和配置分组关系是有效,域配置是无效,这样会将数据库中无效的编译配置置为有效,这是不允许的)
|
|
|
|
|
|
* 3:如果编译配置置为无效将所有的配置分组关系置为无效,不修改域配置状态(分组复用考虑,域可能被其他的组引用)
|
|
|
|
|
|
* 4:如果编译配置为有效,域配置为无效,则先获取该编译配置下各个配置分组关系下的所有有效的域配置信息和所有无效的域配置信息,如果数据库中有效的域配置信息和前端传过来置为无效的的域配置信息个数,id都相等,则将对应域配置,配置分组关系,编译配置均置为无效
|
|
|
|
|
|
*
|
|
|
|
|
|
* 20161124讨论暂时先去掉2步骤,因为界面目前传过来的数据编译配置,配置分组关系,域配置均是无效,所以就不执行第2步骤了影响性能(方法内注释的代码,如果以后业务需要调整打开下面代码即可)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param thread
|
|
|
|
|
|
* 保存异常信息入库对象
|
|
|
|
|
|
* @param start
|
|
|
|
|
|
* 进入controller的时间
|
|
|
|
|
|
* @param compileList
|
|
|
|
|
|
* 编译配置集合
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
public void updateConfigCompile(SaveRequestLogThread thread, long start, ConfigCompile config,
|
|
|
|
|
|
SqlSession batchSqlSession, Date opTime, StringBuffer sb) throws Exception {
|
|
|
|
|
|
List<IpRegion> ipRegionList = config.getIpRegionList();
|
|
|
|
|
|
List<StrRegion> strRegionList = config.getStrRegionList();
|
|
|
|
|
|
List<NumRegion> numRegionList = config.getNumRegionList();
|
|
|
|
|
|
List<ConfigGroupRelation> groupRelationList = config.getGroupRelationList();
|
|
|
|
|
|
if (config.getIsValid() == 1) {
|
|
|
|
|
|
if (groupRelationList == null || groupRelationList.size() == 0) {
|
|
|
|
|
|
thread.setExceptionInfo("配置分组数量不能为空" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "配置分组数量不能为空" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
if ((ipRegionList == null || ipRegionList.size() == 0)
|
|
|
|
|
|
&& (strRegionList == null || strRegionList.size() == 0)
|
|
|
|
|
|
&& (numRegionList == null || numRegionList.size() == 0)) {
|
|
|
|
|
|
thread.setExceptionInfo("域配置数量不能全部为空" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"域配置数量不能全部为空" + sb.toString(), RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ConfigCompile configCompile =
|
|
|
|
|
|
// configCompileDao.queryConfigCompileById(config.getCompileId());//
|
|
|
|
|
|
// 先判断该条编译配置数据库中状态是否为无效,如果无效则提示用户不能将无效状态改为有效状态
|
|
|
|
|
|
// if (configCompile.getIsValid() == 1) {// 数据库中编译配置为有效状态才可以进行修改操作
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 1:编译配置置为无效,需要将其下所有配置分组置为无效,如果数据中将域配置置为了无效则将域配置置为无效,否则不修改域配置是否生效标志
|
|
|
|
|
|
* 2:编译配置置为有效,不修改编译配置状态(编译配置不能从无效变有效,只能从有效变无效)仅修改编译配置其他属性,
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
List<ConfigGroupRelation> queryCompileGroupByPID = configGroupRelationDao
|
|
|
|
|
|
.queryCompileGroupByPID(config.getCompileId());
|
|
|
|
|
|
|
|
|
|
|
|
if (null == queryCompileGroupByPID || queryCompileGroupByPID.size() == 0) {
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"配置id为" + config.getCompileId() + "的配置在数据库中找不到对应的配置分组关系,请检查json串是否正确" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (config.getIsValid() == 0) {// 编译配置修改为无效,需要将所有的配置分组置为无效
|
|
|
|
|
|
if (null != queryCompileGroupByPID && queryCompileGroupByPID.size() > 0) {
|
|
|
|
|
|
for (ConfigGroupRelation configGroupRelation : queryCompileGroupByPID) {
|
|
|
|
|
|
configGroupRelation.setIsValid(0);
|
|
|
|
|
|
configGroupRelation.setOpTime(opTime);
|
|
|
|
|
|
|
|
|
|
|
|
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
|
|
|
|
|
batchSqlSession.getMapper(ConfigGroupRelationDao.class)
|
|
|
|
|
|
.updateConfigGroupRelation(configGroupRelation);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-06-01 10:27:03 +08:00
|
|
|
|
// config.setLastUpdate(new Date());
|
2017-12-19 14:55:52 +08:00
|
|
|
|
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
|
|
|
|
|
batchSqlSession.getMapper(ConfigCompileDao.class).updateConfigCompile(config);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
regionUpdate(thread, start, config, queryCompileGroupByPID, batchSqlSession, opTime, sb);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// } else {// 数据库中编译配置为无效状态不能进行操作
|
|
|
|
|
|
// throw new RestServiceException(thread, System.currentTimeMillis() -
|
|
|
|
|
|
// start, "不能修改无效的编译配置信息",
|
|
|
|
|
|
// RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取编译配置下所有的配置分组关系对应的有效,无效域配置id
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param thread
|
|
|
|
|
|
* 保存异常信息入库对象
|
|
|
|
|
|
* @param start
|
|
|
|
|
|
* 进入controller的时间
|
|
|
|
|
|
* @param config
|
|
|
|
|
|
* 编译配置对象
|
|
|
|
|
|
* @param queryCompileGroupByPID
|
|
|
|
|
|
* 当前编译下所有的配置分组关系
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void regionUpdate(SaveRequestLogThread thread, long start, ConfigCompile config,
|
|
|
|
|
|
List<ConfigGroupRelation> queryCompileGroupByPID, SqlSession batchSqlSession, Date opTime, StringBuffer sb)
|
|
|
|
|
|
throws Exception {
|
|
|
|
|
|
Map<String, Map<Long, List<Long>>> regionMap = getRegionList(thread, System.currentTimeMillis() - start, config,
|
|
|
|
|
|
queryCompileGroupByPID, batchSqlSession, sb);
|
|
|
|
|
|
Map<Long, List<Long>> validMap = regionMap.get("validMap");// 获取该编译配置下所有的配置分组关系及组下有效的域配置id
|
|
|
|
|
|
Map<Long, List<Long>> noValidMap = regionMap.get("noValidMap");// 获取该编译配置下所有的配置分组关系及组下无效的域配置id
|
|
|
|
|
|
List<IpRegion> ipRegionList = config.getIpRegionList();// 获取编译下所有ip类域配置(要修改的数据)
|
|
|
|
|
|
List<StrRegion> strRegionList = config.getStrRegionList();// 获取编译下所有字符串类域配置(要修改的数据
|
|
|
|
|
|
List<NumRegion> numRegionList = config.getNumRegionList();// 获取编译下所有数值类域配置(要修改的数据
|
|
|
|
|
|
int num = 0;
|
|
|
|
|
|
for (Long regionId : validMap.keySet()) {// 遍历配置分组
|
|
|
|
|
|
List<Long> validList = validMap.get(regionId);// 获取配置分组下有效的域配置id
|
|
|
|
|
|
List<Long> noValidList = noValidMap.get(regionId);// 获取配置分组下无效的域配置id
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
if (null != ipRegionList && ipRegionList.size() > 0) {
|
|
|
|
|
|
List<String> tableList = new ArrayList<String>();
|
|
|
|
|
|
for (IpRegion ipRegion : ipRegionList) {
|
|
|
|
|
|
if (ipRegion.getGroupId().equals(regionId)) {
|
|
|
|
|
|
if (null != validList && validList.contains(ipRegion.getRegionId())) {
|
|
|
|
|
|
if (ipRegion.getIsValid() == 0) {
|
|
|
|
|
|
ipRegion.setOpTime(opTime);
|
|
|
|
|
|
ipRegion.setLastUpdate(new Date());
|
|
|
|
|
|
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
|
|
|
|
|
batchSqlSession.getMapper(IpRegionDao.class).updateIpRegion(ipRegion);
|
|
|
|
|
|
}
|
|
|
|
|
|
count++;
|
|
|
|
|
|
if (!tableList.contains(ipRegion.getTableName())) {
|
|
|
|
|
|
tableList.add(ipRegion.getTableName());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (null != noValidList && noValidList.contains(ipRegion.getRegionId())) {
|
|
|
|
|
|
String msg = "不能修改无效的ip类域配置compile为" + config.getCompileId() + "regionid为"
|
|
|
|
|
|
+ ipRegion.getRegionId() + sb.toString();
|
|
|
|
|
|
thread.setExceptionInfo(msg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
String msg = "找不到对应的的ip类域配置compile为" + config.getCompileId() + "regionid为"
|
|
|
|
|
|
+ ipRegion.getRegionId() + sb.toString();
|
|
|
|
|
|
thread.setExceptionInfo(msg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (null != strRegionList && strRegionList.size() > 0) {
|
|
|
|
|
|
List<String> tableList = new ArrayList<String>();
|
|
|
|
|
|
for (StrRegion strRegion : strRegionList) {
|
|
|
|
|
|
if (strRegion.getGroupId().equals(regionId)) {
|
|
|
|
|
|
if (null != validList && validList.contains(strRegion.getRegionId())) {
|
|
|
|
|
|
if (strRegion.getIsValid() == 0) {
|
|
|
|
|
|
strRegion.setOpTime(opTime);
|
|
|
|
|
|
strRegion.setLastUpdate(new Date());
|
|
|
|
|
|
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
|
|
|
|
|
batchSqlSession.getMapper(StrRegionDao.class).updateStrRegion(strRegion);
|
|
|
|
|
|
}
|
|
|
|
|
|
count++;
|
|
|
|
|
|
if (!tableList.contains(strRegion.getTableName())) {
|
|
|
|
|
|
tableList.add(strRegion.getTableName());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (null != noValidList && noValidList.contains(strRegion.getRegionId())) {
|
|
|
|
|
|
String msg = "不能修改无效的字符串类域配置compile为" + config.getCompileId() + "regionid为"
|
|
|
|
|
|
+ strRegion.getRegionId() + sb.toString();
|
|
|
|
|
|
thread.setExceptionInfo(msg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
String msg = "找不到对应的的字符串类域配置compile为" + config.getCompileId() + "regionid为"
|
|
|
|
|
|
+ strRegion.getRegionId() + sb.toString();
|
|
|
|
|
|
thread.setExceptionInfo(msg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != numRegionList && numRegionList.size() > 0) {
|
|
|
|
|
|
List<String> tableList = new ArrayList<String>();
|
|
|
|
|
|
for (NumRegion numRegion : numRegionList) {
|
|
|
|
|
|
if (numRegion.getGroupId().equals(regionId)) {
|
|
|
|
|
|
if (null != validList && validList.contains(numRegion.getRegionId())) {
|
|
|
|
|
|
if (numRegion.getIsValid() == 0) {
|
|
|
|
|
|
numRegion.setOpTime(opTime);
|
|
|
|
|
|
numRegion.setLastUpdate(new Date());
|
|
|
|
|
|
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
|
|
|
|
|
batchSqlSession.getMapper(NumRegionDao.class).updateNumRegion(numRegion);
|
|
|
|
|
|
}
|
|
|
|
|
|
count++;
|
|
|
|
|
|
if (!tableList.contains(numRegion.getTableName())) {
|
|
|
|
|
|
tableList.add(numRegion.getTableName());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (null != noValidList && noValidList.contains(numRegion.getRegionId())) {
|
|
|
|
|
|
String msg = "不能修改无效的数值类域配置compile为" + config.getCompileId() + "regionid为"
|
|
|
|
|
|
+ numRegion.getRegionId() + sb.toString();
|
|
|
|
|
|
thread.setExceptionInfo(msg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
String msg = "找不到对应的的数值类域配置compile为" + config.getCompileId() + "regionid为"
|
|
|
|
|
|
+ numRegion.getRegionId() + sb.toString();
|
|
|
|
|
|
thread.setExceptionInfo(msg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (count == validList.size()) {// 数据库中当前配置分组下有效的域配置,均被修改为无效,所以要将该配置分组置为无效
|
|
|
|
|
|
List<ConfigGroupRelation> groupRelationList = config.getGroupRelationList();
|
|
|
|
|
|
for (ConfigGroupRelation configGroupRelation : groupRelationList) {
|
|
|
|
|
|
if (configGroupRelation.getGroupId().equals(regionId)) {
|
|
|
|
|
|
num++;
|
|
|
|
|
|
configGroupRelation.setIsValid(0);
|
|
|
|
|
|
configGroupRelation.setOpTime(opTime);
|
|
|
|
|
|
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
|
|
|
|
|
batchSqlSession.getMapper(ConfigGroupRelationDao.class)
|
|
|
|
|
|
.updateConfigGroupRelation(configGroupRelation);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (num == validMap.size()) {// 所有的域均是无效的所有的组均是无效,需要将编译配置置为无效
|
|
|
|
|
|
config.setIsValid(0);
|
|
|
|
|
|
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
|
|
|
|
|
batchSqlSession.getMapper(ConfigCompileDao.class).updateConfigCompile(config);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Map<Long, List<Long>>> getRegionList(SaveRequestLogThread thread, long start,
|
|
|
|
|
|
ConfigCompile config, List<ConfigGroupRelation> queryCompileGroupByPID, SqlSession batchSqlSession,
|
|
|
|
|
|
StringBuffer sb) {
|
|
|
|
|
|
Map<String, Map<Long, List<Long>>> map = new HashMap<String, Map<Long, List<Long>>>();
|
|
|
|
|
|
Map<Integer, Map<String, String>> tableRelationMap = getTableRelation();
|
|
|
|
|
|
Map<String, String> updateTableMap = tableRelationMap.get(config.getService().intValue());// 根据service获取需要操作的域配置表
|
|
|
|
|
|
if (null == updateTableMap) {
|
|
|
|
|
|
thread.setExceptionInfo("找不到编译对应的service" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"找不到编译对应的service" + sb.toString(), RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Long[] groupId = new Long[queryCompileGroupByPID.size()];
|
|
|
|
|
|
for (int i = 0; i < queryCompileGroupByPID.size(); i++) {
|
|
|
|
|
|
groupId[i] = queryCompileGroupByPID.get(i).getGroupId();
|
|
|
|
|
|
}
|
|
|
|
|
|
// 获取当前编译下所有的域配置信息
|
|
|
|
|
|
List<IpRegion> ipRegionExistList = new ArrayList<IpRegion>();
|
|
|
|
|
|
List<StrRegion> strRegionExistList = new ArrayList<StrRegion>();
|
|
|
|
|
|
List<NumRegion> numRegionExistList = new ArrayList<NumRegion>();
|
|
|
|
|
|
for (String tableName : updateTableMap.keySet()) {
|
|
|
|
|
|
if (updateTableMap.get(tableName).equals("ip")) {
|
|
|
|
|
|
List<IpRegion> queryIpRegionByGroupId = ipRegionDao.queryIpRegionByGroupId(tableName, groupId);
|
|
|
|
|
|
ipRegionExistList.addAll(queryIpRegionByGroupId);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (updateTableMap.get(tableName).equals("num")) {
|
|
|
|
|
|
numRegionExistList.addAll(numRegionDao.queryNumRegionByGroupId(tableName, groupId));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (updateTableMap.get(tableName).equals("str")) {
|
|
|
|
|
|
strRegionExistList.addAll(strRegionDao.queryStrRegionByGroupId(tableName, groupId));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Map<Long, List<Long>> validMap = new HashMap<Long, List<Long>>();// 获取当前编译下所有的组,及每个组下面的有效域配置
|
|
|
|
|
|
Map<Long, List<Long>> noValidMap = new HashMap<Long, List<Long>>();// 获取当前编译下所有的组,及每个组下面的无效域配置
|
|
|
|
|
|
for (IpRegion ipRegion : ipRegionExistList) {
|
|
|
|
|
|
if (ipRegion.getIsValid() == 1) {
|
|
|
|
|
|
List<Long> validRegionList = null;
|
|
|
|
|
|
if (validMap.get(ipRegion.getGroupId()) == null) {
|
|
|
|
|
|
validRegionList = new ArrayList<Long>();
|
|
|
|
|
|
validRegionList.add(ipRegion.getRegionId());
|
|
|
|
|
|
validMap.put(ipRegion.getGroupId(), validRegionList);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
validRegionList = validMap.get(ipRegion.getGroupId());
|
|
|
|
|
|
// if (!validRegionList.contains(ipRegion.getRegionId())) {
|
|
|
|
|
|
validRegionList.add(ipRegion.getRegionId());
|
|
|
|
|
|
validMap.put(ipRegion.getGroupId(), validRegionList);
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ipRegion.getIsValid() == 0) {
|
|
|
|
|
|
List<Long> noValidRegionList = null;
|
|
|
|
|
|
if (noValidMap.get(ipRegion.getGroupId()) == null) {
|
|
|
|
|
|
noValidRegionList = new ArrayList<Long>();
|
|
|
|
|
|
noValidRegionList.add(ipRegion.getRegionId());
|
|
|
|
|
|
noValidMap.put(ipRegion.getGroupId(), noValidRegionList);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
noValidRegionList = noValidMap.get(ipRegion.getGroupId());
|
|
|
|
|
|
// if (!noValidRegionList.contains(ipRegion.getRegionId()))
|
|
|
|
|
|
// {
|
|
|
|
|
|
noValidRegionList.add(ipRegion.getRegionId());
|
|
|
|
|
|
noValidMap.put(ipRegion.getGroupId(), noValidRegionList);
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (StrRegion strRegion : strRegionExistList) {
|
|
|
|
|
|
if (strRegion.getIsValid() == 1) {
|
|
|
|
|
|
List<Long> validRegionList = null;
|
|
|
|
|
|
if (validMap.get(strRegion.getGroupId()) == null) {
|
|
|
|
|
|
validRegionList = new ArrayList<Long>();
|
|
|
|
|
|
|
|
|
|
|
|
validRegionList.add(strRegion.getRegionId());
|
|
|
|
|
|
|
|
|
|
|
|
validMap.put(strRegion.getGroupId(), validRegionList);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
validRegionList = validMap.get(strRegion.getGroupId());
|
|
|
|
|
|
// if (!validRegionList.contains(strRegion.getRegionId())) {
|
|
|
|
|
|
validRegionList.add(strRegion.getRegionId());
|
|
|
|
|
|
validMap.put(strRegion.getGroupId(), validRegionList);
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (strRegion.getIsValid() == 0) {
|
|
|
|
|
|
List<Long> noValidRegionList = null;
|
|
|
|
|
|
if (noValidMap.get(strRegion.getGroupId()) == null) {
|
|
|
|
|
|
noValidRegionList = new ArrayList<Long>();
|
|
|
|
|
|
noValidRegionList.add(strRegion.getRegionId());
|
|
|
|
|
|
noValidMap.put(strRegion.getGroupId(), noValidRegionList);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
noValidRegionList = noValidMap.get(strRegion.getGroupId());
|
|
|
|
|
|
// if (!noValidRegionList.contains(strRegion.getRegionId()))
|
|
|
|
|
|
// {
|
|
|
|
|
|
noValidRegionList.add(strRegion.getRegionId());
|
|
|
|
|
|
noValidMap.put(strRegion.getGroupId(), noValidRegionList);
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (NumRegion numRegion : numRegionExistList) {
|
|
|
|
|
|
if (numRegion.getIsValid() == 1) {
|
|
|
|
|
|
List<Long> validRegionList = null;
|
|
|
|
|
|
if (validMap.get(numRegion.getGroupId()) == null) {
|
|
|
|
|
|
validRegionList = new ArrayList<Long>();
|
|
|
|
|
|
validRegionList.add(numRegion.getRegionId());
|
|
|
|
|
|
validMap.put(numRegion.getGroupId(), validRegionList);
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
validRegionList = validMap.get(numRegion.getGroupId());
|
|
|
|
|
|
// if (!validRegionList.contains(numRegion.getRegionId())) {
|
|
|
|
|
|
validRegionList.add(numRegion.getRegionId());
|
|
|
|
|
|
validMap.put(numRegion.getGroupId(), validRegionList);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (numRegion.getIsValid() == 0) {
|
|
|
|
|
|
List<Long> noValidRegionList = null;
|
|
|
|
|
|
if (noValidMap.get(numRegion.getGroupId()) == null) {
|
|
|
|
|
|
noValidRegionList = new ArrayList<Long>();
|
|
|
|
|
|
noValidRegionList.add(numRegion.getRegionId());
|
|
|
|
|
|
noValidMap.put(numRegion.getGroupId(), noValidRegionList);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
noValidRegionList = noValidMap.get(numRegion.getGroupId());
|
|
|
|
|
|
// if (!noValidRegionList.contains(numRegion.getRegionId()))
|
|
|
|
|
|
// {
|
|
|
|
|
|
noValidRegionList.add(numRegion.getRegionId());
|
|
|
|
|
|
noValidMap.put(numRegion.getGroupId(), noValidRegionList);
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
map.put("noValidMap", noValidMap);
|
|
|
|
|
|
map.put("validMap", validMap);
|
|
|
|
|
|
return map;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 批量插入配置编译数据在数据库中循环
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param configSource
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void insertConfigSourceData(SaveRequestLogThread thread, long _start, List<ConfigCompile> configSource,
|
|
|
|
|
|
StringBuffer sb) {
|
|
|
|
|
|
SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class);
|
|
|
|
|
|
SqlSession batchSqlSession = null;
|
|
|
|
|
|
try {
|
|
|
|
|
|
// batchSqlSession =
|
|
|
|
|
|
// sqlSessionFactory.openSession(ExecutorType.SIMPLE, false);
|
|
|
|
|
|
batchSqlSession = sqlSessionFactory.openSession();
|
|
|
|
|
|
int index = 150;
|
|
|
|
|
|
int count = configSource.size() % index == 0 ? configSource.size() / index
|
|
|
|
|
|
: configSource.size() / index + 1;
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
|
int start = i * index;
|
|
|
|
|
|
int end = i * index + index;
|
|
|
|
|
|
if (end > configSource.size()) {
|
|
|
|
|
|
end = configSource.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
List<ConfigCompile> compileList = configSource.subList(start, end);
|
|
|
|
|
|
insertConfigComLileData(thread, _start, compileList, sb);
|
|
|
|
|
|
// logger1.info(insertConfigComLile);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
logger1.info("数据保存到数据库提交事务开始");
|
|
|
|
|
|
batchSqlSession.commit();
|
|
|
|
|
|
logger1.info("数据保存到数据库成功");
|
|
|
|
|
|
|
|
|
|
|
|
} catch (RestServiceException e) {
|
|
|
|
|
|
logger1.error(e);
|
|
|
|
|
|
thread.setExceptionInfo(e.getMessage() + " " + e.getCause() + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - _start, e.getMessage() + sb.toString(),
|
|
|
|
|
|
e.getErrorCode());
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger1.error(e);
|
|
|
|
|
|
String errorCode = OracleErrorCodeUtil.getOraCode(e);
|
|
|
|
|
|
if (!StringUtils.isEmpty(errorCode)) {
|
|
|
|
|
|
thread.setExceptionInfo("数据保存发生异常" + sb.toString());
|
|
|
|
|
|
OracleErrorCodeUtil.throwExceptionInfo(thread, System.currentTimeMillis() - _start, errorCode);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
thread.setExceptionInfo("数据保存发生异常" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - _start, "数据保存发生异常" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.unknow_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
if (batchSqlSession != null) {
|
|
|
|
|
|
batchSqlSession.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 验证数据是否符合要求 插入编译配置数据 验证分组配置数据 验证域配置数据 方法二 数据库中循环
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param configCompileList
|
|
|
|
|
|
* @param batchSqlSession
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
private String insertConfigComLileData(SaveRequestLogThread thread, long start,
|
|
|
|
|
|
List<ConfigCompile> configCompileList, StringBuffer sb) throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
List<ConfigGroupRelation> groupRelationList = new ArrayList<ConfigGroupRelation>();
|
|
|
|
|
|
Map<String, List<StrRegion>> strRegionMap = new HashMap<String, List<StrRegion>>();
|
|
|
|
|
|
Map<String, List<StrRegion>> strStongRegionMap = new HashMap<String, List<StrRegion>>();
|
|
|
|
|
|
Map<String, List<IpRegion>> ipRegionMap = new HashMap<String, List<IpRegion>>();
|
|
|
|
|
|
Map<String, List<NumRegion>> numRegionMap = new HashMap<String, List<NumRegion>>();
|
|
|
|
|
|
|
|
|
|
|
|
for (ConfigCompile configCompile : configCompileList) {
|
|
|
|
|
|
String msg = CompileVal.compileIsOk(configCompile, false, sb);
|
|
|
|
|
|
if (msg != CompileJudgeCode.CompileIsOk.getErrorReason()) {
|
|
|
|
|
|
logger1.error(msg);
|
|
|
|
|
|
thread.setExceptionInfo(msg + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != configCompile.getGroupRelationList() && configCompile.getGroupRelationList().size() > 0) {
|
|
|
|
|
|
groupRelationList.addAll(configCompile.getGroupRelationList());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
logger1.error("配置分组数量不能为空" + sb.toString());
|
|
|
|
|
|
thread.setExceptionInfo("配置分组数量不能为空" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "配置分组数量不能为空" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != configCompile.getStrRegionList() && configCompile.getStrRegionList().size() > 0) {
|
|
|
|
|
|
for (StrRegion strRegion : configCompile.getStrRegionList()) {
|
|
|
|
|
|
if (!isStrStrongRegion(strRegion.getTableName())) {
|
|
|
|
|
|
if (strRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (strRegionMap.containsKey(strRegion.getTableName())) {
|
|
|
|
|
|
strRegionMap.get(strRegion.getTableName()).add(strRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<StrRegion> strRegionList = new ArrayList<StrRegion>();
|
|
|
|
|
|
strRegionList.add(strRegion);
|
|
|
|
|
|
strRegionMap.put(strRegion.getTableName(), strRegionList);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (strRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "增强字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (strStongRegionMap.containsKey(strRegion.getTableName())) {
|
|
|
|
|
|
strStongRegionMap.get(strRegion.getTableName()).add(strRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<StrRegion> strStrongRegionList = new ArrayList<StrRegion>();
|
|
|
|
|
|
strStrongRegionList.add(strRegion);
|
|
|
|
|
|
strStongRegionMap.put(strRegion.getTableName(), strStrongRegionList);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (null != configCompile.getIpRegionList() && configCompile.getIpRegionList().size() > 0) {
|
|
|
|
|
|
for (IpRegion ipRegion : configCompile.getIpRegionList()) {
|
|
|
|
|
|
if (!ipRegion.getTableName().toUpperCase().equals("DJ_IP_PORT")) {
|
|
|
|
|
|
ipRegion.setProtocol(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ipRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "ip类域配置id不能为空 ,表名---" + ipRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ipRegionMap.containsKey(ipRegion.getTableName())) {
|
|
|
|
|
|
ipRegionMap.get(ipRegion.getTableName()).add(ipRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<IpRegion> ipRegionList = new ArrayList<IpRegion>();
|
|
|
|
|
|
ipRegionList.add(ipRegion);
|
|
|
|
|
|
ipRegionMap.put(ipRegion.getTableName(), ipRegionList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (null != configCompile.getNumRegionList() && configCompile.getNumRegionList().size() > 0) {
|
|
|
|
|
|
for (NumRegion numRegion : configCompile.getNumRegionList()) {
|
|
|
|
|
|
if (numRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "数值类域配置id不能为空 ,表名---" + numRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (numRegionMap.containsKey(numRegion.getTableName())) {
|
|
|
|
|
|
numRegionMap.get(numRegion.getTableName()).add(numRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<NumRegion> numRegionList = new ArrayList<NumRegion>();
|
|
|
|
|
|
numRegionList.add(numRegion);
|
|
|
|
|
|
numRegionMap.put(numRegion.getTableName(), numRegionList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
|
|
|
|
|
configCompileDao.saveCompileBatch(configCompileList);
|
|
|
|
|
|
if (groupRelationList.size() > 0) {
|
|
|
|
|
|
for (ConfigGroupRelation group : groupRelationList) {
|
|
|
|
|
|
configGroupRelationDao.saveConfigGroupRelation(group);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (String str : strRegionMap.keySet()) {
|
|
|
|
|
|
strRegionDao.saveStrRegionBatch(strRegionMap.get(str).get(0).getTableName(), strRegionMap.get(str));
|
|
|
|
|
|
}
|
|
|
|
|
|
for (String strStrong : strStongRegionMap.keySet()) {
|
|
|
|
|
|
strRegionDao.saveStrStrongRegionBatch(strStongRegionMap.get(strStrong).get(0).getTableName(),
|
|
|
|
|
|
strStongRegionMap.get(strStrong));
|
|
|
|
|
|
}
|
|
|
|
|
|
for (String ip : ipRegionMap.keySet()) {
|
|
|
|
|
|
ipRegionDao.saveIpRegionBatch(ipRegionMap.get(ip).get(0).getTableName(), ipRegionMap.get(ip));
|
|
|
|
|
|
}
|
|
|
|
|
|
for (String num : numRegionMap.keySet()) {
|
|
|
|
|
|
numRegionDao.saveNumRegionBatch(numRegionMap.get(num).get(0).getTableName(), numRegionMap.get(num));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return "编译配置数据验证成功";
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
public Page<ConfigCompileTest> queryAllCompile(Page<ConfigCompileTest> page, ConfigCompileTest entity)
|
|
|
|
|
|
throws SQLException {
|
|
|
|
|
|
entity.setPage(page);
|
|
|
|
|
|
page.setList(configCompileDao.queryAllCompile(entity.getSearchEndTime(), entity.getSearchStartTime(),
|
|
|
|
|
|
entity.getService(), entity.getCompileId()));
|
|
|
|
|
|
return page;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<ConfigCompileTest> queryAllCompile(ConfigCompileTest entity) {
|
|
|
|
|
|
return configCompileDao.queryAllCompile(entity.getSearchEndTime(), entity.getSearchStartTime(),
|
|
|
|
|
|
entity.getService(), entity.getCompileId());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<ConfigCompileTest> queryConfigCompileByIdArr(String compileIdArr) {
|
|
|
|
|
|
return configCompileDao.queryConfigCompileByIdArr(compileIdArr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<ConfigGroupRelation> getGroupByCompile(long compileId) {
|
|
|
|
|
|
return configGroupRelationDao.queryCompileGroupByPID(compileId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<StrRegion> getStrRegionByGId(List<String> tableList, Long[] groupId) {
|
|
|
|
|
|
List<StrRegion> strRegionList = new ArrayList<StrRegion>();
|
|
|
|
|
|
if (null != tableList && tableList.size() > 0) {
|
|
|
|
|
|
for (String tableName : tableList) {
|
|
|
|
|
|
List<StrRegion> queryStrRegionByGroupId = null;
|
|
|
|
|
|
if (isStrStrongRegion(tableName)) {
|
|
|
|
|
|
queryStrRegionByGroupId = strRegionDao.queryStrStrongRegionByGroupId(tableName, groupId);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
queryStrRegionByGroupId = strRegionDao.queryStrRegionByGroupId(tableName, groupId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (null != queryStrRegionByGroupId && queryStrRegionByGroupId.size() > 0) {
|
|
|
|
|
|
for (StrRegion strRegion : queryStrRegionByGroupId) {
|
|
|
|
|
|
strRegion.setTableName(tableName);
|
|
|
|
|
|
strRegionList.add(strRegion);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return strRegionList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<IpRegion> getIpRegionByGId(String table, Long[] groupId) {
|
|
|
|
|
|
List<IpRegion> queryIpRegionByGroupId = ipRegionDao.queryIpRegionByGroupId(table, groupId);
|
|
|
|
|
|
for (IpRegion ipRegion : queryIpRegionByGroupId) {
|
|
|
|
|
|
ipRegion.setTableName(table);
|
|
|
|
|
|
}
|
|
|
|
|
|
return queryIpRegionByGroupId;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<NumRegion> getNumRegionByGId(String table, Long[] groupId) {
|
|
|
|
|
|
List<NumRegion> queryNumRegionByGroupId = numRegionDao.queryNumRegionByGroupId(table, groupId);
|
|
|
|
|
|
for (NumRegion numRegion : queryNumRegionByGroupId) {
|
|
|
|
|
|
numRegion.setTableName(table);
|
|
|
|
|
|
}
|
|
|
|
|
|
return queryNumRegionByGroupId;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean isStrStrongRegion(String tableName) {
|
|
|
|
|
|
if (null != tableName && !tableName.equals("")) {
|
|
|
|
|
|
tableName = tableName.toUpperCase();
|
|
|
|
|
|
List<String> tableList = new ArrayList<String>();
|
|
|
|
|
|
tableList.add("DF_HTTP_REQ_HDR");
|
|
|
|
|
|
tableList.add("FX_HTTP_REQ_HDR");
|
|
|
|
|
|
tableList.add("DF_HTTP_RES_HDR");
|
|
|
|
|
|
tableList.add("DF_DNS_REGION");
|
|
|
|
|
|
tableList.add("FX_DNS_REGION");
|
|
|
|
|
|
tableList.add("DF_SSL_REGION");
|
|
|
|
|
|
tableList.add("DF_MAIL_HDR");
|
|
|
|
|
|
tableList.add("DF_MAIL_BODY");
|
|
|
|
|
|
|
|
|
|
|
|
tableList.add("DJ_HTTP_REQ_HDR");
|
|
|
|
|
|
tableList.add("DJ_HTTP_RES_HDR");
|
|
|
|
|
|
tableList.add("DJ_DNS_REQ_REGION");
|
|
|
|
|
|
tableList.add("DJ_DNS_RES_REGION");
|
|
|
|
|
|
tableList.add("DJ_SSL_REGION");
|
|
|
|
|
|
tableList.add("DJ_MAIL_HDR");
|
|
|
|
|
|
tableList.add("DJ_MAIL_BODY");
|
|
|
|
|
|
// tableList.add("DF_L2TP_URL");//20161021数据库中该表改为普通字符串表
|
|
|
|
|
|
// tableList.add("DF_PPTP_URL");//20161021数据库中该表改为普通字符串表
|
|
|
|
|
|
if (tableList.contains(tableName)) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, String> getTableMap(Integer service) {
|
|
|
|
|
|
if (map == null || map.size() == 0) {
|
|
|
|
|
|
map = getTableRelation();
|
|
|
|
|
|
}
|
|
|
|
|
|
return map.get(service);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<Integer, Map<String, String>> getMap() {
|
|
|
|
|
|
return map;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setMap(Map<Integer, Map<String, String>> map) {
|
|
|
|
|
|
this.map = map;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-05-25 19:37:05 +08:00
|
|
|
|
*
|
|
|
|
|
|
* @Description:
|
|
|
|
|
|
* @author (zdx)
|
|
|
|
|
|
* @date 2018年5月25日 下午3:49:46
|
|
|
|
|
|
* @param thread
|
|
|
|
|
|
* @param start
|
|
|
|
|
|
* @param configCompileList
|
|
|
|
|
|
* @param sb
|
|
|
|
|
|
* @return
|
2017-12-19 14:55:52 +08:00
|
|
|
|
*/
|
2018-05-25 19:37:05 +08:00
|
|
|
|
public String saveMaatConfig(SaveRequestLogThread thread, long start, List<ConfigCompile> configCompileList,
|
|
|
|
|
|
StringBuffer sb) {
|
2018-06-01 10:27:03 +08:00
|
|
|
|
// List<MaatConfig> maatConfigList = new ArrayList<MaatConfig>();
|
|
|
|
|
|
// List<Integer> serviceList = new ArrayList<Integer>();
|
|
|
|
|
|
Map<Integer, List<MaatConfig>> maatMap = new HashMap<Integer, List<MaatConfig>>();
|
2018-05-25 19:37:05 +08:00
|
|
|
|
|
|
|
|
|
|
for (ConfigCompile configCompile : configCompileList) {
|
2018-06-01 10:27:03 +08:00
|
|
|
|
Integer service = Integer.valueOf(configCompile.getService().toString());
|
2018-05-25 19:37:05 +08:00
|
|
|
|
MaatConfig maatConfig = new MaatConfig();
|
|
|
|
|
|
String msg = CompileVal.compileIsOk(configCompile, false, sb);
|
|
|
|
|
|
if (msg != CompileJudgeCode.CompileIsOk.getErrorReason()) {
|
|
|
|
|
|
logger1.error(msg);
|
|
|
|
|
|
thread.setExceptionInfo(msg + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-01 10:27:03 +08:00
|
|
|
|
if (!(null != configCompile.getGroupRelationList() && configCompile.getGroupRelationList().size() > 0)) {
|
2018-05-25 19:37:05 +08:00
|
|
|
|
logger1.error("配置分组数量不能为空" + sb.toString());
|
|
|
|
|
|
thread.setExceptionInfo("配置分组数量不能为空" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "配置分组数量不能为空" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != configCompile.getStrRegionList() && configCompile.getStrRegionList().size() > 0) {
|
|
|
|
|
|
for (StrRegion strRegion : configCompile.getStrRegionList()) {
|
2018-06-01 10:27:03 +08:00
|
|
|
|
if (strRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
2018-05-25 19:37:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (null != configCompile.getIpRegionList() && configCompile.getIpRegionList().size() > 0) {
|
|
|
|
|
|
for (IpRegion ipRegion : configCompile.getIpRegionList()) {
|
|
|
|
|
|
if (ipRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "ip类域配置id不能为空 ,表名---" + ipRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (null != configCompile.getNumRegionList() && configCompile.getNumRegionList().size() > 0) {
|
|
|
|
|
|
for (NumRegion numRegion : configCompile.getNumRegionList()) {
|
|
|
|
|
|
if (numRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "数值类域配置id不能为空 ,表名---" + numRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != configCompile.getDigestRegionList() && configCompile.getDigestRegionList().size() > 0) {
|
|
|
|
|
|
for (DigestRegion digestRegion : configCompile.getDigestRegionList()) {
|
|
|
|
|
|
if (digestRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "摘要类域配置id不能为空 ,表名---" + digestRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-01 10:27:03 +08:00
|
|
|
|
if (null != configCompile.getIpClientRangeList() && configCompile.getIpClientRangeList().size() > 0) {
|
|
|
|
|
|
for (IpRegion ipRegion : configCompile.getIpClientRangeList()) {
|
|
|
|
|
|
if (ipRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "生效范围IP域类域配置id不能为空 ,表名---" + ipRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
maatConfig.setService(service);
|
2018-05-25 19:37:05 +08:00
|
|
|
|
//编译
|
|
|
|
|
|
maatConfig.setCompileMap(convertObjectToMap(configCompile, ConfigCompile.class));
|
|
|
|
|
|
//分组
|
|
|
|
|
|
List<Map<String, String>> dstMaplList = null;
|
2018-06-01 10:27:03 +08:00
|
|
|
|
if (!StringUtil.isEmpty(configCompile.getGroupRelationList())) {
|
2018-05-25 19:37:05 +08:00
|
|
|
|
dstMaplList = new ArrayList<Map<String,String>>();
|
2018-06-01 10:27:03 +08:00
|
|
|
|
for (ConfigGroupRelation group : configCompile.getGroupRelationList()) {
|
2018-05-25 19:37:05 +08:00
|
|
|
|
dstMaplList.add(convertObjectToMap(group, ConfigGroupRelation.class));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
maatConfig.setGroupMapList(dstMaplList);
|
|
|
|
|
|
//字符串域
|
|
|
|
|
|
dstMaplList = null;
|
2018-06-01 10:27:03 +08:00
|
|
|
|
if (!StringUtil.isEmpty(configCompile.getStrRegionList())) {
|
2018-05-25 19:37:05 +08:00
|
|
|
|
dstMaplList = new ArrayList<Map<String,String>>();
|
2018-06-01 10:27:03 +08:00
|
|
|
|
for (StrRegion region : configCompile.getStrRegionList()) {
|
2018-05-25 19:37:05 +08:00
|
|
|
|
dstMaplList.add(convertObjectToMap(region, StrRegion.class));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
maatConfig.setStrRegionMapList(dstMaplList);
|
2018-06-01 10:27:03 +08:00
|
|
|
|
// //增强字符串域
|
|
|
|
|
|
// dstMaplList = null;
|
|
|
|
|
|
// if (!StringUtil.isEmpty(strStrongRegionList)) {
|
|
|
|
|
|
// dstMaplList = new ArrayList<Map<String,String>>();
|
|
|
|
|
|
// for (StrRegion region : strStrongRegionList) {
|
|
|
|
|
|
// dstMaplList.add(convertObjectToMap(region, StrRegion.class));
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// maatConfig.setStrStrRegionMapList((dstMaplList));
|
2018-05-25 19:37:05 +08:00
|
|
|
|
//数值域
|
|
|
|
|
|
dstMaplList = null;
|
2018-06-01 10:27:03 +08:00
|
|
|
|
if (!StringUtil.isEmpty(configCompile.getNumRegionList())) {
|
2018-05-25 19:37:05 +08:00
|
|
|
|
dstMaplList = new ArrayList<Map<String,String>>();
|
2018-06-01 10:27:03 +08:00
|
|
|
|
for (NumRegion region : configCompile.getNumRegionList()) {
|
2018-05-25 19:37:05 +08:00
|
|
|
|
dstMaplList.add(convertObjectToMap(region, NumRegion.class));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
maatConfig.setNumRegionMapList(dstMaplList);
|
|
|
|
|
|
|
|
|
|
|
|
//Ip域
|
|
|
|
|
|
dstMaplList = null;
|
2018-06-01 10:27:03 +08:00
|
|
|
|
if (!StringUtil.isEmpty(configCompile.getIpRegionList())) {
|
2018-05-25 19:37:05 +08:00
|
|
|
|
dstMaplList = new ArrayList<Map<String,String>>();
|
2018-06-01 10:27:03 +08:00
|
|
|
|
for (IpRegion region : configCompile.getIpRegionList()) {
|
2018-05-25 19:37:05 +08:00
|
|
|
|
dstMaplList.add(convertObjectToMap(region, IpRegion.class));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
maatConfig.setIpRegionMapList(dstMaplList);
|
|
|
|
|
|
|
|
|
|
|
|
//摘要类域
|
|
|
|
|
|
dstMaplList = null;
|
2018-06-01 10:27:03 +08:00
|
|
|
|
if (!StringUtil.isEmpty(configCompile.getDigestRegionList())) {
|
2018-05-25 19:37:05 +08:00
|
|
|
|
dstMaplList = new ArrayList<Map<String,String>>();
|
2018-06-01 10:27:03 +08:00
|
|
|
|
for (DigestRegion region : configCompile.getDigestRegionList()) {
|
2018-05-25 19:37:05 +08:00
|
|
|
|
dstMaplList.add(convertObjectToMap(region, DigestRegion.class));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
maatConfig.setFileDigestRegionMapList(dstMaplList);
|
2018-06-01 10:27:03 +08:00
|
|
|
|
|
2018-05-25 19:37:05 +08:00
|
|
|
|
//文本相似性域
|
2018-06-01 10:27:03 +08:00
|
|
|
|
// dstMaplList = null;
|
|
|
|
|
|
// maatConfig.setFileLikeRegionMapList(dstMaplList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生效范围IP域
|
|
|
|
|
|
dstMaplList = null;
|
|
|
|
|
|
if (!StringUtil.isEmpty(configCompile.getIpClientRangeList())) {
|
|
|
|
|
|
dstMaplList = new ArrayList<Map<String,String>>();
|
|
|
|
|
|
for (IpRegion region : configCompile.getIpClientRangeList()) {
|
|
|
|
|
|
dstMaplList.add(convertObjectToMap(region, IpRegion.class));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
maatConfig.setIpClientRangeMapList(dstMaplList);
|
|
|
|
|
|
|
|
|
|
|
|
if (maatMap.containsKey(service)) {
|
|
|
|
|
|
maatMap.get(service).add(maatConfig);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
List<MaatConfig> maatCfgList = new ArrayList<MaatConfig>();
|
|
|
|
|
|
maatCfgList.add(maatConfig);
|
|
|
|
|
|
maatMap.put(service, maatCfgList);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-05-25 19:37:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//调用接口入redis
|
2018-06-01 10:27:03 +08:00
|
|
|
|
Map<Integer, List<MaatConfig>> configMap = new HashMap<Integer, List<MaatConfig>>();
|
|
|
|
|
|
Iterator serviceIterator = maatMap.keySet().iterator();
|
|
|
|
|
|
while (serviceIterator.hasNext()) {
|
|
|
|
|
|
Integer service =Integer.valueOf(serviceIterator.next().toString());
|
|
|
|
|
|
List<Integer> dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service);
|
|
|
|
|
|
for (Integer dbIndex : dbIndexList) {
|
|
|
|
|
|
if (configMap.containsKey(dbIndex)) {
|
|
|
|
|
|
configMap.get(dbIndex).addAll(maatMap.get(service));
|
|
|
|
|
|
}else{
|
|
|
|
|
|
configMap.put(dbIndex, maatMap.get(service));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
configRedisService.saveMaatConfig(configMap);
|
|
|
|
|
|
logger1.info("---------------调用maat配置新增接口---------------------");
|
2018-05-25 19:37:05 +08:00
|
|
|
|
|
|
|
|
|
|
return "ok";
|
|
|
|
|
|
}
|
|
|
|
|
|
private Map<String, String> convertObjectToMap(Object obj,Class clazz){
|
|
|
|
|
|
Map<String,String> dstMap = new HashMap<String, String>();
|
|
|
|
|
|
try {
|
|
|
|
|
|
Field[] fields= obj.getClass().getDeclaredFields();
|
|
|
|
|
|
for (Field field : fields) {
|
|
|
|
|
|
if("serialVersionUID".equals(field.getName()))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
String dstName = CamelUnderlineUtil.camelToUnderline(field.getName());
|
|
|
|
|
|
PropertyDescriptor pd;
|
|
|
|
|
|
pd = new PropertyDescriptor(field.getName(), clazz);
|
|
|
|
|
|
Method method = pd.getReadMethod();
|
|
|
|
|
|
Object dstObject = method.invoke(obj);
|
|
|
|
|
|
if (dstObject instanceof Date) {
|
|
|
|
|
|
dstObject = convertToTimeStamp16((Date)dstObject);
|
|
|
|
|
|
}if(dstObject instanceof ArrayList){
|
|
|
|
|
|
dstObject = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
dstMap.put(dstName, StringUtil.isEmpty(dstObject)?"":dstObject.toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger1.error(e.getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
return dstMap;
|
|
|
|
|
|
}
|
2018-06-01 10:27:03 +08:00
|
|
|
|
|
|
|
|
|
|
public String cancleConfigSources(SaveRequestLogThread thread, long start, List<ConfigCompile> compileList,
|
|
|
|
|
|
Date opTime, StringBuffer sb) {
|
|
|
|
|
|
List<ConfigCompile> compileAllList = new ArrayList<ConfigCompile>();
|
|
|
|
|
|
if (null != compileList && compileList.size() > 0) {
|
|
|
|
|
|
for (ConfigCompile config : compileList) {
|
|
|
|
|
|
String msg = checkCompileOptForUpdate(config);
|
|
|
|
|
|
if (config.getOpTime()==null) {
|
|
|
|
|
|
config.setOpTime(opTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!msg.equals("ok")) {
|
|
|
|
|
|
thread.setExceptionInfo(msg + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
compileAllList.add(config);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
thread.setExceptionInfo("编译配置不能为空" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
public String saveByJDBCThread(SaveRequestLogThread thread, long start, List<ConfigCompile> configCompileList,
|
|
|
|
|
|
StringBuffer sb) {
|
|
|
|
|
|
List<ConfigGroupRelation> groupRelationList = new ArrayList<ConfigGroupRelation>();
|
|
|
|
|
|
Map<String, List<StrRegion>> strRegionMap = new HashMap<String, List<StrRegion>>();
|
|
|
|
|
|
Map<String, List<StrRegion>> strStongRegionMap = new HashMap<String, List<StrRegion>>();
|
|
|
|
|
|
Map<String, List<IpRegion>> ipRegionMap = new HashMap<String, List<IpRegion>>();
|
|
|
|
|
|
Map<String, List<NumRegion>> numRegionMap = new HashMap<String, List<NumRegion>>();
|
2018-02-28 10:13:39 +08:00
|
|
|
|
Map<String, List<DigestRegion>> digestRegionMap = new HashMap<String, List<DigestRegion>>();
|
2017-12-19 14:55:52 +08:00
|
|
|
|
for (ConfigCompile configCompile : configCompileList) {
|
|
|
|
|
|
String msg = CompileVal.compileIsOk(configCompile, false, sb);
|
|
|
|
|
|
if (msg != CompileJudgeCode.CompileIsOk.getErrorReason()) {
|
|
|
|
|
|
logger1.error(msg);
|
|
|
|
|
|
thread.setExceptionInfo(msg + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != configCompile.getGroupRelationList() && configCompile.getGroupRelationList().size() > 0) {
|
|
|
|
|
|
groupRelationList.addAll(configCompile.getGroupRelationList());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
logger1.error("配置分组数量不能为空" + sb.toString());
|
|
|
|
|
|
thread.setExceptionInfo("配置分组数量不能为空" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "配置分组数量不能为空" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != configCompile.getStrRegionList() && configCompile.getStrRegionList().size() > 0) {
|
|
|
|
|
|
for (StrRegion strRegion : configCompile.getStrRegionList()) {
|
|
|
|
|
|
if (!isStrStrongRegion(strRegion.getTableName())) {
|
|
|
|
|
|
if (strRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (strRegionMap.containsKey(strRegion.getTableName())) {
|
|
|
|
|
|
strRegionMap.get(strRegion.getTableName()).add(strRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<StrRegion> strRegionList = new ArrayList<StrRegion>();
|
|
|
|
|
|
strRegionList.add(strRegion);
|
|
|
|
|
|
strRegionMap.put(strRegion.getTableName(), strRegionList);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (strRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "增强字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (strStongRegionMap.containsKey(strRegion.getTableName())) {
|
|
|
|
|
|
strStongRegionMap.get(strRegion.getTableName()).add(strRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<StrRegion> strStrongRegionList = new ArrayList<StrRegion>();
|
|
|
|
|
|
strStrongRegionList.add(strRegion);
|
|
|
|
|
|
strStongRegionMap.put(strRegion.getTableName(), strStrongRegionList);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (null != configCompile.getIpRegionList() && configCompile.getIpRegionList().size() > 0) {
|
|
|
|
|
|
for (IpRegion ipRegion : configCompile.getIpRegionList()) {
|
|
|
|
|
|
if (!ipRegion.getTableName().toUpperCase().equals("DJ_IP_PORT")) {
|
|
|
|
|
|
ipRegion.setProtocol(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ipRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "ip类域配置id不能为空 ,表名---" + ipRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ipRegionMap.containsKey(ipRegion.getTableName())) {
|
|
|
|
|
|
ipRegionMap.get(ipRegion.getTableName()).add(ipRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<IpRegion> ipRegionList = new ArrayList<IpRegion>();
|
|
|
|
|
|
ipRegionList.add(ipRegion);
|
|
|
|
|
|
ipRegionMap.put(ipRegion.getTableName(), ipRegionList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (null != configCompile.getNumRegionList() && configCompile.getNumRegionList().size() > 0) {
|
|
|
|
|
|
for (NumRegion numRegion : configCompile.getNumRegionList()) {
|
|
|
|
|
|
if (numRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "数值类域配置id不能为空 ,表名---" + numRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (numRegionMap.containsKey(numRegion.getTableName())) {
|
|
|
|
|
|
numRegionMap.get(numRegion.getTableName()).add(numRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<NumRegion> numRegionList = new ArrayList<NumRegion>();
|
|
|
|
|
|
numRegionList.add(numRegion);
|
|
|
|
|
|
numRegionMap.put(numRegion.getTableName(), numRegionList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-02-28 10:13:39 +08:00
|
|
|
|
|
|
|
|
|
|
if (null != configCompile.getDigestRegionList() && configCompile.getDigestRegionList().size() > 0) {
|
|
|
|
|
|
for (DigestRegion digestRegion : configCompile.getDigestRegionList()) {
|
|
|
|
|
|
if (digestRegion.getRegionId() == null) {
|
|
|
|
|
|
String errorMsg = "摘要类域配置id不能为空 ,表名---" + digestRegion.getTableName() + "" + sb.toString();
|
|
|
|
|
|
logger1.error(errorMsg);
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (digestRegionMap.containsKey(digestRegion.getTableName())) {
|
|
|
|
|
|
digestRegionMap.get(digestRegion.getTableName()).add(digestRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<DigestRegion> digestRegionList = new ArrayList<DigestRegion>();
|
|
|
|
|
|
digestRegionList.add(digestRegion);
|
|
|
|
|
|
digestRegionMap.put(digestRegion.getTableName(), digestRegionList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
2018-05-25 19:37:05 +08:00
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
if (null != configCompileList && configCompileList.size() > 0) {
|
|
|
|
|
|
count += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != groupRelationList && groupRelationList.size() > 0) {
|
|
|
|
|
|
count += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != strRegionMap && strRegionMap.size() > 0) {
|
|
|
|
|
|
count += strRegionMap.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != strStongRegionMap && strStongRegionMap.size() > 0) {
|
|
|
|
|
|
count += strStongRegionMap.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != ipRegionMap && ipRegionMap.size() > 0) {
|
|
|
|
|
|
count += ipRegionMap.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != numRegionMap && numRegionMap.size() > 0) {
|
|
|
|
|
|
count += numRegionMap.size();
|
|
|
|
|
|
}
|
2018-02-28 10:13:39 +08:00
|
|
|
|
|
|
|
|
|
|
if (null != digestRegionMap && digestRegionMap.size() > 0) {
|
|
|
|
|
|
count += digestRegionMap.size();
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
|
|
|
|
|
|
SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class);
|
|
|
|
|
|
Connection conn = sqlSessionFactory.openSession().getConnection();
|
|
|
|
|
|
|
|
|
|
|
|
CountDownLatch latch = new CountDownLatch(count);
|
|
|
|
|
|
SaveCompileByJDBCThread compile = new SaveCompileByJDBCThread(conn, latch, start);
|
|
|
|
|
|
compile.setCompileList(configCompileList);
|
|
|
|
|
|
Thread compileThread = new Thread(compile);
|
|
|
|
|
|
compileThread.start();
|
|
|
|
|
|
if (groupRelationList.size() > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
SaveCompileByJDBCThread group = new SaveCompileByJDBCThread(conn, latch, start);
|
|
|
|
|
|
group.setGroupList(groupRelationList);
|
|
|
|
|
|
|
|
|
|
|
|
Thread groupThread = new Thread(group);
|
|
|
|
|
|
groupThread.start();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (strRegionMap.size() > 0) {
|
|
|
|
|
|
for (String str : strRegionMap.keySet()) {
|
|
|
|
|
|
|
|
|
|
|
|
SaveCompileByJDBCThread strRegion = new SaveCompileByJDBCThread(false, str, conn, latch, start);
|
|
|
|
|
|
strRegion.setStrRegionList(strRegionMap.get(str));
|
|
|
|
|
|
Thread strThread = new Thread(strRegion);
|
|
|
|
|
|
strThread.start();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (strStongRegionMap.size() > 0) {
|
|
|
|
|
|
for (String strStrong : strStongRegionMap.keySet()) {
|
|
|
|
|
|
SaveCompileByJDBCThread strongRegion = new SaveCompileByJDBCThread(true, strStrong, conn, latch,
|
|
|
|
|
|
start);
|
|
|
|
|
|
strongRegion.setStrRegionList(strStongRegionMap.get(strStrong));
|
|
|
|
|
|
Thread strongStrThread = new Thread(strongRegion);
|
|
|
|
|
|
strongStrThread.start();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ipRegionMap.size() > 0) {
|
|
|
|
|
|
for (String ip : ipRegionMap.keySet()) {
|
|
|
|
|
|
SaveCompileByJDBCThread ipRegion = new SaveCompileByJDBCThread(ip, conn, latch, start);
|
|
|
|
|
|
ipRegion.setIpRegionList(ipRegionMap.get(ip));
|
|
|
|
|
|
Thread ipThread = new Thread(ipRegion);
|
|
|
|
|
|
ipThread.start();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (numRegionMap.size() > 0) {
|
|
|
|
|
|
for (String num : numRegionMap.keySet()) {
|
|
|
|
|
|
SaveCompileByJDBCThread numRegion = new SaveCompileByJDBCThread(num, conn, latch, start);
|
|
|
|
|
|
numRegion.setNumRegionList(numRegionMap.get(num));
|
|
|
|
|
|
Thread numThread = new Thread(numRegion);
|
|
|
|
|
|
numThread.start();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-02-28 10:13:39 +08:00
|
|
|
|
if (digestRegionMap.size() > 0) {
|
|
|
|
|
|
for (String digest : digestRegionMap.keySet()) {
|
|
|
|
|
|
SaveCompileByJDBCThread digestRegion = new SaveCompileByJDBCThread(digest, conn, latch, start);
|
|
|
|
|
|
digestRegion.setDigestRegionList(digestRegionMap.get(digest));
|
|
|
|
|
|
Thread digestThread = new Thread(digestRegion);
|
|
|
|
|
|
digestThread.start();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
try {
|
|
|
|
|
|
latch.await();
|
|
|
|
|
|
if (msgList.size() > 0) {
|
|
|
|
|
|
conn.rollback();
|
|
|
|
|
|
return "error";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
conn.commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
thread.setExceptionInfo(e.toString());
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger1.error(e);
|
|
|
|
|
|
if (!(e instanceof RestServiceException)) {
|
|
|
|
|
|
e = new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置数据插入失败",
|
|
|
|
|
|
RestBusinessCode.unknow_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
throw ((RestServiceException) e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return "ok";
|
|
|
|
|
|
}
|
2018-05-25 19:37:05 +08:00
|
|
|
|
|
|
|
|
|
|
private String convertToTimeStamp16(Date date){
|
|
|
|
|
|
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
|
|
|
|
return date.getTime()+"000";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 批量(jdbc多线程方式)修改配置业务逻辑-->1:先进行基础配置验证传过来的json串是否符合格式(配置分组关系前端不能设置为无效,程序会根据传过来的编译配置和域配置等信息自动设置为无效).
|
|
|
|
|
|
* 2:判断配置在数据库中是否已经是无效了如果是无效则提示不能修改无效的配置为有效(因为如果数据库中的编译配置与配置分组关系以及域配置均是无效,传过来的数据是编译配置和配置分组关系是有效,域配置是无效,这样会将数据库中无效的编译配置置为有效,这是不允许的)
|
|
|
|
|
|
* 3:如果编译配置置为无效将所有的配置分组关系置为无效,不修改域配置状态(分组复用考虑,域可能被其他的组引用)
|
|
|
|
|
|
* 4:如果编译配置为有效,域配置为无效,则先获取该编译配置下各个配置分组关系下的所有有效的域配置信息和所有无效的域配置信息,如果数据库中有效的域配置信息和前端传过来置为无效的的域配置信息个数,id都相等,则将对应域配置,配置分组关系,编译配置均置为无效
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
* 20161124讨论暂时先去掉2步骤,因为界面目前传过来的数据编译配置,配置分组关系,域配置均是无效,所以就不执行第2步骤了影响性能(方法内注释的代码,如果以后业务需要调整打开下面代码即可)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param thread
|
|
|
|
|
|
* 保存异常信息入库对象
|
|
|
|
|
|
* @param start
|
|
|
|
|
|
* 进入controller的时间
|
|
|
|
|
|
* @param compileList
|
|
|
|
|
|
* 编译配置集合
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
public String updateByJDBCThread(SaveRequestLogThread thread, long start, List<ConfigCompile> compileList,
|
|
|
|
|
|
Date opTime, StringBuffer sb) {
|
|
|
|
|
|
List<ConfigCompile> compileAllList = new ArrayList<ConfigCompile>();
|
|
|
|
|
|
List<ConfigGroupRelation> groupRelationAllList = new ArrayList<ConfigGroupRelation>();
|
|
|
|
|
|
Map<String, List<StrRegion>> strRegionMap = new HashMap<String, List<StrRegion>>();
|
|
|
|
|
|
Map<String, List<IpRegion>> ipRegionMap = new HashMap<String, List<IpRegion>>();
|
|
|
|
|
|
Map<String, List<NumRegion>> numRegionMap = new HashMap<String, List<NumRegion>>();
|
|
|
|
|
|
if (null != compileList && compileList.size() > 0) {
|
|
|
|
|
|
for (ConfigCompile config : compileList) {
|
|
|
|
|
|
String msg = CompileVal.compileIsOk(config, true, sb);
|
|
|
|
|
|
if (msg != CompileJudgeCode.CompileIsOk.getErrorReason()) {
|
|
|
|
|
|
thread.setExceptionInfo(msg + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
List<IpRegion> ipRegionList = config.getIpRegionList();// 获取编译下所有ip类域配置(要修改的数据)
|
|
|
|
|
|
List<StrRegion> strRegionList = config.getStrRegionList();// 获取编译下所有字符串类域配置(要修改的数据
|
|
|
|
|
|
List<NumRegion> numRegionList = config.getNumRegionList();// 获取编译下所有数值类域配置(要修改的数据
|
|
|
|
|
|
List<ConfigGroupRelation> groupRelationList = config.getGroupRelationList();
|
|
|
|
|
|
if (config.getIsValid() == 1) {
|
|
|
|
|
|
if (groupRelationList == null || groupRelationList.size() == 0) {
|
|
|
|
|
|
thread.setExceptionInfo("配置分组数量不能为空" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"配置分组数量不能为空" + sb.toString(), RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
if ((ipRegionList == null || ipRegionList.size() == 0)
|
|
|
|
|
|
&& (strRegionList == null || strRegionList.size() == 0)
|
|
|
|
|
|
&& (numRegionList == null || numRegionList.size() == 0)) {
|
|
|
|
|
|
thread.setExceptionInfo("域配置数量不能全部为空" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"域配置数量不能全部为空" + sb.toString(), RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ConfigCompile configCompile =
|
|
|
|
|
|
// configCompileDao.queryConfigCompileById(config.getCompileId());//
|
|
|
|
|
|
// 先判断该条编译配置数据库中状态是否为无效,如果无效则提示用户不能将无效状态改为有效状态
|
|
|
|
|
|
// if (configCompile.getIsValid() == 1) {//
|
|
|
|
|
|
// 数据库中编译配置为有效状态才可以进行修改操作
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 1:编译配置置为无效,需要将其下所有配置分组置为无效,如果数据中将域配置置为了无效则将域配置置为无效,否则不修改域配置是否生效标志
|
|
|
|
|
|
* 2:编译配置置为有效,不修改编译配置状态(编译配置不能从无效变有效,只能从有效变无效)仅修改编译配置其他属性,
|
|
|
|
|
|
*/
|
|
|
|
|
|
List<ConfigGroupRelation> queryCompileGroupByPID = configGroupRelationDao
|
|
|
|
|
|
.queryCompileGroupByPID(config.getCompileId());
|
|
|
|
|
|
|
|
|
|
|
|
if (null == queryCompileGroupByPID || queryCompileGroupByPID.size() == 0) {
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"配置id为" + config.getCompileId() + "的配置在数据库中找不到对应的配置分组关系,请检查json串是否正确" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (config.getIsValid() == 0) {// 编译配置修改为无效,需要将所有的配置分组置为无效
|
|
|
|
|
|
if (null != queryCompileGroupByPID && queryCompileGroupByPID.size() > 0) {
|
|
|
|
|
|
for (ConfigGroupRelation configGroupRelation : queryCompileGroupByPID) {
|
|
|
|
|
|
configGroupRelation.setIsValid(0);
|
|
|
|
|
|
|
|
|
|
|
|
groupRelationAllList.add(configGroupRelation);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Map<Long, List<Long>>> regionMap = getRegionList(thread,
|
|
|
|
|
|
System.currentTimeMillis() - start, config, queryCompileGroupByPID, sb);
|
|
|
|
|
|
Map<Long, List<Long>> validMap = regionMap.get("validMap");// 获取该编译配置下所有的配置分组关系及组下有效的域配置id
|
|
|
|
|
|
Map<Long, List<Long>> noValidMap = regionMap.get("noValidMap");// 获取该编译配置下所有的配置分组关系及组下无效的域配置id
|
|
|
|
|
|
|
|
|
|
|
|
int num = 0;
|
|
|
|
|
|
for (Long regionId : validMap.keySet()) {// 遍历配置分组
|
|
|
|
|
|
List<Long> validList = validMap.get(regionId);// 获取配置分组下有效的域配置id
|
|
|
|
|
|
List<Long> noValidList = noValidMap.get(regionId);// 获取配置分组下无效的域配置id
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
if (null != ipRegionList && ipRegionList.size() > 0) {
|
|
|
|
|
|
for (IpRegion ipRegion : ipRegionList) {
|
|
|
|
|
|
if (ipRegion.getGroupId().equals(regionId)) {
|
|
|
|
|
|
if (null != validList && validList.contains(ipRegion.getRegionId())) {
|
|
|
|
|
|
if (ipRegion.getIsValid() == 0) {
|
|
|
|
|
|
ipRegion.setLastUpdate(new Date());
|
|
|
|
|
|
if (ipRegionMap.containsKey(ipRegion.getTableName())) {
|
|
|
|
|
|
ipRegionMap.get(ipRegion.getTableName()).add(ipRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<IpRegion> ipList = new ArrayList<IpRegion>();
|
|
|
|
|
|
ipList.add(ipRegion);
|
|
|
|
|
|
ipRegionMap.put(ipRegion.getTableName(), ipList);
|
|
|
|
|
|
}
|
|
|
|
|
|
count++;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (null != noValidList && noValidList.contains(ipRegion.getRegionId())) {
|
|
|
|
|
|
String errorMsg = "不能修改无效的ip类域配置compile为" + config.getCompileId() + "regionid为"
|
|
|
|
|
|
+ ipRegion.getRegionId() + sb.toString();
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
errorMsg, RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
String errorMsg = "找不到对应的的ip类域配置compile为" + config.getCompileId() + "regionid为"
|
|
|
|
|
|
+ ipRegion.getRegionId() + sb.toString();
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
errorMsg, RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (null != strRegionList && strRegionList.size() > 0) {
|
|
|
|
|
|
for (StrRegion strRegion : strRegionList) {
|
|
|
|
|
|
if (strRegion.getGroupId().equals(regionId)) {
|
|
|
|
|
|
if (null != validList && validList.contains(strRegion.getRegionId())) {
|
|
|
|
|
|
if (strRegion.getIsValid() == 0) {
|
|
|
|
|
|
|
|
|
|
|
|
strRegion.setLastUpdate(new Date());
|
|
|
|
|
|
if (strRegionMap.containsKey(strRegion.getTableName())) {
|
|
|
|
|
|
strRegionMap.get(strRegion.getTableName()).add(strRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<StrRegion> strList = new ArrayList<StrRegion>();
|
|
|
|
|
|
strList.add(strRegion);
|
|
|
|
|
|
strRegionMap.put(strRegion.getTableName(), strList);
|
|
|
|
|
|
}
|
|
|
|
|
|
count++;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (null != noValidList && noValidList.contains(strRegion.getRegionId())) {
|
|
|
|
|
|
String errorMsg = "不能修改无效的字符串类域配置compile为" + config.getCompileId() + "regionid为"
|
|
|
|
|
|
+ strRegion.getRegionId() + sb.toString();
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
errorMsg, RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
String errorMsg = "找不到对应的的字符串类域配置compile为" + config.getCompileId() + "regionid为"
|
|
|
|
|
|
+ strRegion.getRegionId() + sb.toString();
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
errorMsg, RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != numRegionList && numRegionList.size() > 0) {
|
|
|
|
|
|
for (NumRegion numRegion : numRegionList) {
|
|
|
|
|
|
if (numRegion.getGroupId().equals(regionId)) {
|
|
|
|
|
|
if (null != validList && validList.contains(numRegion.getRegionId())) {
|
|
|
|
|
|
if (numRegion.getIsValid() == 0) {
|
|
|
|
|
|
|
|
|
|
|
|
numRegion.setLastUpdate(new Date());
|
|
|
|
|
|
if (numRegionMap.containsKey(numRegion.getTableName())) {
|
|
|
|
|
|
numRegionMap.get(numRegion.getTableName()).add(numRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<NumRegion> numList = new ArrayList<NumRegion>();
|
|
|
|
|
|
numList.add(numRegion);
|
|
|
|
|
|
numRegionMap.put(numRegion.getTableName(), numList);
|
|
|
|
|
|
}
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (null != noValidList && noValidList.contains(numRegion.getRegionId())) {
|
|
|
|
|
|
String errorMsg = "不能修改无效的数值类域配置compile为" + config.getCompileId() + "regionid为"
|
|
|
|
|
|
+ numRegion.getRegionId() + sb.toString();
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
errorMsg, RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
String errorMsg = "找不到对应的的数值类域配置compile为" + config.getCompileId() + "regionid为"
|
|
|
|
|
|
+ numRegion.getRegionId() + sb.toString();
|
|
|
|
|
|
thread.setExceptionInfo(errorMsg);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
errorMsg, RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (count == validList.size()) {// 数据库中当前配置分组下有效的域配置,均被修改为无效,所以要将该配置分组置为无效
|
|
|
|
|
|
for (ConfigGroupRelation configGroupRelation : groupRelationList) {
|
|
|
|
|
|
if (configGroupRelation.getGroupId().equals(regionId)) {
|
|
|
|
|
|
num++;
|
|
|
|
|
|
configGroupRelation.setIsValid(0);
|
|
|
|
|
|
|
|
|
|
|
|
groupRelationAllList.add(configGroupRelation);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (num == validMap.size()) {// 所有的域均是无效的所有的组均是无效,需要将编译配置置为无效
|
|
|
|
|
|
config.setIsValid(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// } else {// 数据库中编译配置为无效状态不能进行操作
|
|
|
|
|
|
// throw new RestServiceException(thread,
|
|
|
|
|
|
// System.currentTimeMillis() - start,"不能修改无效的编译配置信息,配置id为" +
|
|
|
|
|
|
// configCompile.getCompileId(),RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
// }
|
|
|
|
|
|
compileAllList.add(config);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
thread.setExceptionInfo("编译配置不能为空" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
// 程序是否入库,测试分析数据的时间
|
|
|
|
|
|
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
if (null != compileAllList && compileAllList.size() > 0) {
|
|
|
|
|
|
count += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != groupRelationAllList && groupRelationAllList.size() > 0) {
|
|
|
|
|
|
count += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != strRegionMap && strRegionMap.size() > 0) {
|
|
|
|
|
|
count += strRegionMap.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != ipRegionMap && ipRegionMap.size() > 0) {
|
|
|
|
|
|
count += ipRegionMap.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != numRegionMap && numRegionMap.size() > 0) {
|
|
|
|
|
|
count += numRegionMap.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class);
|
|
|
|
|
|
Connection conn = sqlSessionFactory.openSession().getConnection();
|
|
|
|
|
|
CountDownLatch latch = new CountDownLatch(count);
|
|
|
|
|
|
UpdateCompileByJDBCThread compileThread = new UpdateCompileByJDBCThread(conn, latch, start, opTime);
|
|
|
|
|
|
compileThread.setCompileList(compileAllList);
|
|
|
|
|
|
Thread compile = new Thread(compileThread);
|
|
|
|
|
|
compile.start();
|
|
|
|
|
|
|
|
|
|
|
|
if (null != groupRelationAllList && groupRelationAllList.size() > 0) {
|
|
|
|
|
|
UpdateCompileByJDBCThread groupThread = new UpdateCompileByJDBCThread(conn, latch, start, opTime);
|
|
|
|
|
|
groupThread.setGroupList(groupRelationAllList);
|
|
|
|
|
|
Thread group = new Thread(groupThread);
|
|
|
|
|
|
group.start();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != strRegionMap && strRegionMap.size() > 0) {
|
|
|
|
|
|
for (String str : strRegionMap.keySet()) {
|
|
|
|
|
|
UpdateCompileByJDBCThread strRegion = new UpdateCompileByJDBCThread(str, conn, latch, start,
|
|
|
|
|
|
opTime);
|
|
|
|
|
|
strRegion.setStrRegionList(strRegionMap.get(str));
|
|
|
|
|
|
Thread strThread = new Thread(strRegion);
|
|
|
|
|
|
strThread.start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (null != ipRegionMap && ipRegionMap.size() > 0) {
|
|
|
|
|
|
for (String ip : ipRegionMap.keySet()) {
|
|
|
|
|
|
UpdateCompileByJDBCThread ipRegion = new UpdateCompileByJDBCThread(ip, conn, latch, start, opTime);
|
|
|
|
|
|
ipRegion.setIpRegionList(ipRegionMap.get(ip));
|
|
|
|
|
|
Thread ipThread = new Thread(ipRegion);
|
|
|
|
|
|
ipThread.start();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != numRegionMap && numRegionMap.size() > 0) {
|
|
|
|
|
|
for (String num : numRegionMap.keySet()) {
|
|
|
|
|
|
UpdateCompileByJDBCThread numRegion = new UpdateCompileByJDBCThread(num, conn, latch, start,
|
|
|
|
|
|
opTime);
|
|
|
|
|
|
numRegion.setNumRegionList(numRegionMap.get(num));
|
|
|
|
|
|
Thread numThread = new Thread(numRegion);
|
|
|
|
|
|
numThread.start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
latch.await();
|
|
|
|
|
|
if (msgList.size() > 0) {
|
|
|
|
|
|
conn.rollback();
|
|
|
|
|
|
return "error";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
conn.commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
thread.setExceptionInfo(e.toString());
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger1.error(e);
|
|
|
|
|
|
if (!(e instanceof RestServiceException)) {
|
|
|
|
|
|
e = new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置数据修改失败",
|
|
|
|
|
|
RestBusinessCode.unknow_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
throw ((RestServiceException) e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
return "ok";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 批量(jdbc多线程方式)修改配置业务逻辑-->1:先进行基础配置验证传过来的json串是否符合格式(配置分组关系前端不能设置为无效,程序会根据传过来的编译配置和域配置等信息自动设置为无效).
|
|
|
|
|
|
* 2:判断配置在数据库中是否已经是无效了如果是无效则提示不能修改无效的配置为有效(因为如果数据库中的编译配置与配置分组关系以及域配置均是无效,传过来的数据是编译配置和配置分组关系是有效,域配置是无效,这样会将数据库中无效的编译配置置为有效,这是不允许的)
|
|
|
|
|
|
* 3:如果编译配置置为无效将所有的配置分组关系置为无效,不修改域配置状态(分组复用考虑,域可能被其他的组引用)
|
|
|
|
|
|
* 4:如果编译配置为有效,域配置为无效,则先获取该编译配置下各个配置分组关系下的所有有效的域配置信息和所有无效的域配置信息,如果数据库中有效的域配置信息和前端传过来置为无效的的域配置信息个数,id都相等,则将对应域配置,配置分组关系,编译配置均置为无效
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
* 20161124讨论暂时先去掉2步骤,因为界面目前传过来的数据编译配置,配置分组关系,域配置均是无效,所以就不执行第2步骤了影响性能(方法内注释的代码,如果以后业务需要调整打开下面代码即可)
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
* 20161215讨论确定修改时前端发过来的配置都是无效的不会存在即有无效又有有效的情况,且配置中的个数与添加时保持一致,即添加时插入了1条编译配置2条配置分组关系3条域配置,在修改时也会传过来1条编译配置2条配置分组关系3条域配置,不会多或者少配置
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
* 2017-1-16:和杨老师讨论确定存在分组复用情况,当编译配置置为无效,需要将其下所有配置分组置为无效,如果数据中将域配置置为了无效则将域配置置为无效,否则不修改域配置是否生效标志
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param thread
|
|
|
|
|
|
* 保存异常信息入库对象
|
|
|
|
|
|
* @param start
|
|
|
|
|
|
* 进入controller的时间
|
|
|
|
|
|
* @param compileList
|
|
|
|
|
|
* 编译配置集合
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
public String updateByJDBCThread12(SaveRequestLogThread thread, long start, List<ConfigCompile> compileList,
|
|
|
|
|
|
Date opTime, StringBuffer sb) {
|
|
|
|
|
|
List<ConfigCompile> compileAllList = new ArrayList<ConfigCompile>();
|
|
|
|
|
|
List<ConfigGroupRelation> groupRelationAllList = new ArrayList<ConfigGroupRelation>();
|
|
|
|
|
|
Map<String, List<StrRegion>> strRegionMap = new HashMap<String, List<StrRegion>>();
|
|
|
|
|
|
Map<String, List<IpRegion>> ipRegionMap = new HashMap<String, List<IpRegion>>();
|
|
|
|
|
|
Map<String, List<NumRegion>> numRegionMap = new HashMap<String, List<NumRegion>>();
|
2018-02-28 10:13:39 +08:00
|
|
|
|
Map<String, List<DigestRegion>> digestRegionMap = new HashMap<String, List<DigestRegion>>();
|
2017-12-19 14:55:52 +08:00
|
|
|
|
if (null != compileList && compileList.size() > 0) {
|
|
|
|
|
|
for (ConfigCompile config : compileList) {
|
|
|
|
|
|
String msg = CompileVal.compileIsOk(config, true, sb);
|
|
|
|
|
|
if (msg != CompileJudgeCode.CompileIsOk.getErrorReason()) {
|
|
|
|
|
|
thread.setExceptionInfo(msg + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 1:编译配置置为无效,需要将其下所有配置分组置为无效,如果数据中将域配置置为了无效则将域配置置为无效,否则不修改域配置是否生效标志
|
|
|
|
|
|
* 2:编译配置置为有效,不修改编译配置状态(编译配置不能从无效变有效,只能从有效变无效)仅修改编译配置其他属性,
|
|
|
|
|
|
*/
|
|
|
|
|
|
List<ConfigGroupRelation> groupRelationList = config.getGroupRelationList();
|
|
|
|
|
|
if (config.getIsValid() == 0) {// 编译配置修改为无效,需要将所有的配置分组置为无效
|
|
|
|
|
|
if (null != groupRelationList && groupRelationList.size() > 0) {
|
|
|
|
|
|
for (ConfigGroupRelation configGroupRelation : groupRelationList) {
|
|
|
|
|
|
configGroupRelation.setIsValid(0);
|
|
|
|
|
|
groupRelationAllList.add(configGroupRelation);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
List<IpRegion> ipRegionList = config.getIpRegionList();// 获取编译下所有ip类域配置(要修改的数据)
|
|
|
|
|
|
if (null != ipRegionList && ipRegionList.size() > 0) {
|
|
|
|
|
|
for (IpRegion ipRegion : ipRegionList) {
|
|
|
|
|
|
if (ipRegion.getIsValid() == 0) {
|
|
|
|
|
|
if (ipRegionMap.containsKey(ipRegion.getTableName())) {
|
|
|
|
|
|
ipRegionMap.get(ipRegion.getTableName()).add(ipRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<IpRegion> ipList = new ArrayList<IpRegion>();
|
|
|
|
|
|
ipList.add(ipRegion);
|
|
|
|
|
|
ipRegionMap.put(ipRegion.getTableName(), ipList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
List<StrRegion> strRegionList = config.getStrRegionList();// 获取编译下所有字符串类域配置(要修改的数据
|
|
|
|
|
|
if (null != strRegionList && strRegionList.size() > 0) {
|
|
|
|
|
|
for (StrRegion strRegion : strRegionList) {
|
|
|
|
|
|
if (strRegion.getIsValid() == 0) {
|
|
|
|
|
|
if (strRegionMap.containsKey(strRegion.getTableName())) {
|
|
|
|
|
|
strRegionMap.get(strRegion.getTableName()).add(strRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<StrRegion> strList = new ArrayList<StrRegion>();
|
|
|
|
|
|
strList.add(strRegion);
|
|
|
|
|
|
strRegionMap.put(strRegion.getTableName(), strList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
List<NumRegion> numRegionList = config.getNumRegionList();// 获取编译下所有数值类域配置(要修改的数据
|
|
|
|
|
|
if (null != numRegionList && numRegionList.size() > 0) {
|
|
|
|
|
|
for (NumRegion numRegion : numRegionList) {
|
|
|
|
|
|
if (numRegion.getIsValid() == 0) {
|
|
|
|
|
|
if (numRegionMap.containsKey(numRegion.getTableName())) {
|
|
|
|
|
|
numRegionMap.get(numRegion.getTableName()).add(numRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<NumRegion> numList = new ArrayList<NumRegion>();
|
|
|
|
|
|
numList.add(numRegion);
|
|
|
|
|
|
numRegionMap.put(numRegion.getTableName(), numList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-02-28 10:13:39 +08:00
|
|
|
|
|
|
|
|
|
|
List<DigestRegion> digestRegionList = config.getDigestRegionList();// 获取编译下所有摘要类域配置(要修改的数据
|
|
|
|
|
|
if (null != digestRegionList && digestRegionList.size() > 0) {
|
|
|
|
|
|
for (DigestRegion digestRegion : digestRegionList) {
|
|
|
|
|
|
if (digestRegion.getIsValid() == 0) {
|
|
|
|
|
|
if (digestRegionMap.containsKey(digestRegion.getTableName())) {
|
|
|
|
|
|
digestRegionMap.get(digestRegion.getTableName()).add(digestRegion);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<DigestRegion> digestList = new ArrayList<DigestRegion>();
|
|
|
|
|
|
digestList.add(digestRegion);
|
|
|
|
|
|
digestRegionMap.put(digestRegion.getTableName(), digestList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
compileAllList.add(config);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
thread.setExceptionInfo("编译配置不能为空" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
// 程序是否入库,测试分析数据的时间
|
|
|
|
|
|
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
if (null != compileAllList && compileAllList.size() > 0) {
|
|
|
|
|
|
count += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != groupRelationAllList && groupRelationAllList.size() > 0) {
|
|
|
|
|
|
count += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != strRegionMap && strRegionMap.size() > 0) {
|
|
|
|
|
|
count += strRegionMap.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != ipRegionMap && ipRegionMap.size() > 0) {
|
|
|
|
|
|
count += ipRegionMap.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != numRegionMap && numRegionMap.size() > 0) {
|
|
|
|
|
|
count += numRegionMap.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class);
|
|
|
|
|
|
Connection conn = sqlSessionFactory.openSession().getConnection();
|
|
|
|
|
|
CountDownLatch latch = new CountDownLatch(count);
|
|
|
|
|
|
UpdateCompileByJDBCThread compileThread = new UpdateCompileByJDBCThread(conn, latch, start, opTime);
|
|
|
|
|
|
compileThread.setCompileList(compileAllList);
|
|
|
|
|
|
Thread compile = new Thread(compileThread);
|
|
|
|
|
|
compile.start();
|
|
|
|
|
|
|
|
|
|
|
|
if (null != groupRelationAllList && groupRelationAllList.size() > 0) {
|
|
|
|
|
|
UpdateCompileByJDBCThread groupThread = new UpdateCompileByJDBCThread(conn, latch, start, opTime);
|
|
|
|
|
|
groupThread.setGroupList(groupRelationAllList);
|
|
|
|
|
|
Thread group = new Thread(groupThread);
|
|
|
|
|
|
group.start();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != strRegionMap && strRegionMap.size() > 0) {
|
|
|
|
|
|
for (String str : strRegionMap.keySet()) {
|
|
|
|
|
|
UpdateCompileByJDBCThread strRegion = new UpdateCompileByJDBCThread(str, conn, latch, start,
|
|
|
|
|
|
opTime);
|
|
|
|
|
|
strRegion.setStrRegionList(strRegionMap.get(str));
|
|
|
|
|
|
Thread strThread = new Thread(strRegion);
|
|
|
|
|
|
strThread.start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (null != ipRegionMap && ipRegionMap.size() > 0) {
|
|
|
|
|
|
for (String ip : ipRegionMap.keySet()) {
|
|
|
|
|
|
UpdateCompileByJDBCThread ipRegion = new UpdateCompileByJDBCThread(ip, conn, latch, start, opTime);
|
|
|
|
|
|
ipRegion.setIpRegionList(ipRegionMap.get(ip));
|
|
|
|
|
|
Thread ipThread = new Thread(ipRegion);
|
|
|
|
|
|
ipThread.start();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != numRegionMap && numRegionMap.size() > 0) {
|
|
|
|
|
|
for (String num : numRegionMap.keySet()) {
|
|
|
|
|
|
UpdateCompileByJDBCThread numRegion = new UpdateCompileByJDBCThread(num, conn, latch, start,
|
|
|
|
|
|
opTime);
|
|
|
|
|
|
numRegion.setNumRegionList(numRegionMap.get(num));
|
|
|
|
|
|
Thread numThread = new Thread(numRegion);
|
|
|
|
|
|
numThread.start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-02-28 10:13:39 +08:00
|
|
|
|
if (null != digestRegionMap && digestRegionMap.size() > 0) {
|
|
|
|
|
|
for (String num : digestRegionMap.keySet()) {
|
|
|
|
|
|
UpdateCompileByJDBCThread digestRegion = new UpdateCompileByJDBCThread(num, conn, latch, start,
|
|
|
|
|
|
opTime);
|
|
|
|
|
|
digestRegion.setDigestRegionList(digestRegionMap.get(num));
|
|
|
|
|
|
Thread digestThread = new Thread(digestRegion);
|
|
|
|
|
|
digestThread.start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
try {
|
|
|
|
|
|
latch.await();
|
|
|
|
|
|
if (msgList.size() > 0) {
|
|
|
|
|
|
conn.rollback();
|
|
|
|
|
|
return "error";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
conn.commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
thread.setExceptionInfo(e.toString());
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger1.error(e);
|
|
|
|
|
|
if (!(e instanceof RestServiceException)) {
|
|
|
|
|
|
e = new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置数据修改失败",
|
|
|
|
|
|
RestBusinessCode.unknow_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
throw ((RestServiceException) e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
return "ok";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* @Description:只填写compile信息,根据compileId对compile以及与Group的对应关系进行配置状态更新操作
|
|
|
|
|
|
* @author (zdx)
|
|
|
|
|
|
* @date 2017年8月16日 上午11:21:53
|
|
|
|
|
|
* @param thread
|
|
|
|
|
|
* @param start
|
|
|
|
|
|
* @param compileList
|
|
|
|
|
|
* @param opTime
|
|
|
|
|
|
* @param sb
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public String updateByJDBCThread3(SaveRequestLogThread thread, long start, List<ConfigCompile> compileList,
|
|
|
|
|
|
Date opTime, StringBuffer sb) {
|
|
|
|
|
|
List<ConfigCompile> compileAllList = new ArrayList<ConfigCompile>();
|
|
|
|
|
|
if (null != compileList && compileList.size() > 0) {
|
|
|
|
|
|
for (ConfigCompile config : compileList) {
|
|
|
|
|
|
String msg = checkCompileOptForUpdate(config);
|
2017-12-22 15:22:11 +08:00
|
|
|
|
if (config.getOpTime()==null) {
|
|
|
|
|
|
config.setOpTime(opTime);
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
if (!msg.equals("ok")) {
|
|
|
|
|
|
thread.setExceptionInfo(msg + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
compileAllList.add(config);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
thread.setExceptionInfo("编译配置不能为空" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.config_integrity_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
// 程序是否入库,测试分析数据的时间
|
|
|
|
|
|
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
if (null != compileAllList && compileAllList.size() > 0) {
|
|
|
|
|
|
count += 1;
|
|
|
|
|
|
count += 1; //将所有compile与Group的对应关系都置为失效 zdx20170814
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class);
|
|
|
|
|
|
Connection conn = sqlSessionFactory.openSession().getConnection();
|
|
|
|
|
|
CountDownLatch latch = new CountDownLatch(count);
|
|
|
|
|
|
|
|
|
|
|
|
UpdateCompileByJDBCThread compileThread = new UpdateCompileByJDBCThread(conn, latch, start, opTime);
|
|
|
|
|
|
compileThread.setCompileList(compileAllList);
|
|
|
|
|
|
Thread compile = new Thread(compileThread);
|
|
|
|
|
|
compile.start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UpdateCompileByJDBCThread groupThread = new UpdateCompileByJDBCThread(conn, latch, start, opTime);
|
|
|
|
|
|
groupThread.setCompileList(compileAllList);
|
|
|
|
|
|
//仅用做判定线程执行时选择执行方法 zdx20170816
|
|
|
|
|
|
groupThread.setGroupList(new ArrayList<ConfigGroupRelation>());
|
|
|
|
|
|
Thread group = new Thread(groupThread);
|
|
|
|
|
|
group.start();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
latch.await();
|
|
|
|
|
|
if (msgList.size() > 0) {
|
|
|
|
|
|
conn.rollback();
|
|
|
|
|
|
return "error";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
conn.commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
thread.setExceptionInfo(e.toString());
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
logger1.error(e);
|
|
|
|
|
|
if (!(e instanceof RestServiceException)) {
|
|
|
|
|
|
e = new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置数据修改失败",
|
|
|
|
|
|
RestBusinessCode.unknow_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
throw ((RestServiceException) e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
return "ok";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* @Description:验证compileId+isValid
|
|
|
|
|
|
* @author (zdx)
|
|
|
|
|
|
* @date 2017年8月16日 上午11:48:46
|
|
|
|
|
|
* @param config
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
private String checkCompileOptForUpdate(ConfigCompile config) {
|
|
|
|
|
|
if (StringUtil.isEmpty(config.getCompileId())) {
|
|
|
|
|
|
return "compileId字段不能为空";
|
|
|
|
|
|
}
|
2018-06-01 10:27:03 +08:00
|
|
|
|
|
|
|
|
|
|
if (StringUtil.isEmpty(config.getService())) {
|
|
|
|
|
|
return "service字段不能为空";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
if (StringUtil.isEmpty(config.getIsValid())) {
|
|
|
|
|
|
return "编译配置id为" + config.getCompileId()+"的IsValid字段不能为空";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (config.getIsValid() != 0) {
|
|
|
|
|
|
return "编译配置id为" + config.getCompileId() + "的配置在修改时不能为有效";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return "ok";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取编译配置下所有的配置分组关系对应的有效,无效域配置id
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param thread
|
|
|
|
|
|
* 保存异常信息入库对象
|
|
|
|
|
|
* @param start
|
|
|
|
|
|
* 进入controller的时间
|
|
|
|
|
|
* @param config
|
|
|
|
|
|
* 编译配置对象
|
|
|
|
|
|
* @param queryCompileGroupByPID
|
|
|
|
|
|
* 当前编译下所有的配置分组关系
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public Map<String, Map<Long, List<Long>>> getRegionList(SaveRequestLogThread thread, long start,
|
|
|
|
|
|
ConfigCompile config, List<ConfigGroupRelation> queryCompileGroupByPID, StringBuffer sb) {
|
|
|
|
|
|
Map<String, Map<Long, List<Long>>> map = new HashMap<String, Map<Long, List<Long>>>();
|
|
|
|
|
|
Map<Integer, Map<String, String>> tableRelationMap = getTableRelation();
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> updateTableMap = tableRelationMap.get(config.getService().intValue());// 根据service获取需要操作的域配置表
|
|
|
|
|
|
if (null == updateTableMap || updateTableMap.size() == 0) {
|
|
|
|
|
|
thread.setExceptionInfo("找不到编译对应的service" + sb.toString());
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"找不到编译对应的service" + sb.toString(), RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Long[] groupId = new Long[queryCompileGroupByPID.size()];
|
|
|
|
|
|
for (int i = 0; i < queryCompileGroupByPID.size(); i++) {
|
|
|
|
|
|
groupId[i] = queryCompileGroupByPID.get(i).getGroupId();
|
|
|
|
|
|
}
|
|
|
|
|
|
// 获取当前编译下所有的域配置信息
|
|
|
|
|
|
List<IpRegion> ipRegionExistList = new ArrayList<IpRegion>();
|
|
|
|
|
|
List<StrRegion> strRegionExistList = new ArrayList<StrRegion>();
|
|
|
|
|
|
List<NumRegion> numRegionExistList = new ArrayList<NumRegion>();
|
|
|
|
|
|
for (String tableName : updateTableMap.keySet()) {
|
|
|
|
|
|
if (updateTableMap.get(tableName).equals("ip")) {
|
|
|
|
|
|
ipRegionExistList.addAll(ipRegionDao.queryIpRegionByGroupId(tableName, groupId));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (updateTableMap.get(tableName).equals("num")) {
|
|
|
|
|
|
numRegionExistList.addAll(numRegionDao.queryNumRegionByGroupId(tableName, groupId));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (updateTableMap.get(tableName).equals("str")) {
|
|
|
|
|
|
strRegionExistList.addAll(strRegionDao.queryStrRegionByGroupId(tableName, groupId));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Map<Long, List<Long>> validMap = new HashMap<Long, List<Long>>();// 获取当前编译下所有的组,及每个组下面的有效域配置
|
|
|
|
|
|
Map<Long, List<Long>> noValidMap = new HashMap<Long, List<Long>>();// 获取当前编译下所有的组,及每个组下面的无效域配置
|
|
|
|
|
|
for (IpRegion ipRegion : ipRegionExistList) {
|
|
|
|
|
|
if (ipRegion.getIsValid() == 1) {
|
|
|
|
|
|
List<Long> validRegionList = null;
|
|
|
|
|
|
if (validMap.get(ipRegion.getGroupId()) == null) {
|
|
|
|
|
|
validRegionList = new ArrayList<Long>();
|
|
|
|
|
|
validRegionList.add(ipRegion.getRegionId());
|
|
|
|
|
|
validMap.put(ipRegion.getGroupId(), validRegionList);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
validRegionList = validMap.get(ipRegion.getGroupId());
|
|
|
|
|
|
// if (!validRegionList.contains(ipRegion.getRegionId())) {
|
|
|
|
|
|
validRegionList.add(ipRegion.getRegionId());
|
|
|
|
|
|
validMap.put(ipRegion.getGroupId(), validRegionList);
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ipRegion.getIsValid() == 0) {
|
|
|
|
|
|
List<Long> noValidRegionList = null;
|
|
|
|
|
|
if (noValidMap.get(ipRegion.getGroupId()) == null) {
|
|
|
|
|
|
noValidRegionList = new ArrayList<Long>();
|
|
|
|
|
|
noValidRegionList.add(ipRegion.getRegionId());
|
|
|
|
|
|
noValidMap.put(ipRegion.getGroupId(), noValidRegionList);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
noValidRegionList = noValidMap.get(ipRegion.getGroupId());
|
|
|
|
|
|
// if (!noValidRegionList.contains(ipRegion.getRegionId()))
|
|
|
|
|
|
// {
|
|
|
|
|
|
noValidRegionList.add(ipRegion.getRegionId());
|
|
|
|
|
|
noValidMap.put(ipRegion.getGroupId(), noValidRegionList);
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (StrRegion strRegion : strRegionExistList) {
|
|
|
|
|
|
if (strRegion.getIsValid() == 1) {
|
|
|
|
|
|
List<Long> validRegionList = null;
|
|
|
|
|
|
if (validMap.get(strRegion.getGroupId()) == null) {
|
|
|
|
|
|
validRegionList = new ArrayList<Long>();
|
|
|
|
|
|
|
|
|
|
|
|
validRegionList.add(strRegion.getRegionId());
|
|
|
|
|
|
|
|
|
|
|
|
validMap.put(strRegion.getGroupId(), validRegionList);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
validRegionList = validMap.get(strRegion.getGroupId());
|
|
|
|
|
|
// if (!validRegionList.contains(strRegion.getRegionId())) {
|
|
|
|
|
|
validRegionList.add(strRegion.getRegionId());
|
|
|
|
|
|
validMap.put(strRegion.getGroupId(), validRegionList);
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (strRegion.getIsValid() == 0) {
|
|
|
|
|
|
List<Long> noValidRegionList = null;
|
|
|
|
|
|
if (noValidMap.get(strRegion.getGroupId()) == null) {
|
|
|
|
|
|
noValidRegionList = new ArrayList<Long>();
|
|
|
|
|
|
noValidRegionList.add(strRegion.getRegionId());
|
|
|
|
|
|
noValidMap.put(strRegion.getGroupId(), noValidRegionList);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
noValidRegionList = noValidMap.get(strRegion.getGroupId());
|
|
|
|
|
|
// if (!noValidRegionList.contains(strRegion.getRegionId()))
|
|
|
|
|
|
// {
|
|
|
|
|
|
noValidRegionList.add(strRegion.getRegionId());
|
|
|
|
|
|
noValidMap.put(strRegion.getGroupId(), noValidRegionList);
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (NumRegion numRegion : numRegionExistList) {
|
|
|
|
|
|
if (numRegion.getIsValid() == 1) {
|
|
|
|
|
|
List<Long> validRegionList = null;
|
|
|
|
|
|
if (validMap.get(numRegion.getGroupId()) == null) {
|
|
|
|
|
|
validRegionList = new ArrayList<Long>();
|
|
|
|
|
|
validRegionList.add(numRegion.getRegionId());
|
|
|
|
|
|
validMap.put(numRegion.getGroupId(), validRegionList);
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
validRegionList = validMap.get(numRegion.getGroupId());
|
|
|
|
|
|
// if (!validRegionList.contains(numRegion.getRegionId())) {
|
|
|
|
|
|
validRegionList.add(numRegion.getRegionId());
|
|
|
|
|
|
validMap.put(numRegion.getGroupId(), validRegionList);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (numRegion.getIsValid() == 0) {
|
|
|
|
|
|
List<Long> noValidRegionList = null;
|
|
|
|
|
|
if (noValidMap.get(numRegion.getGroupId()) == null) {
|
|
|
|
|
|
noValidRegionList = new ArrayList<Long>();
|
|
|
|
|
|
noValidRegionList.add(numRegion.getRegionId());
|
|
|
|
|
|
noValidMap.put(numRegion.getGroupId(), noValidRegionList);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
noValidRegionList = noValidMap.get(numRegion.getGroupId());
|
|
|
|
|
|
// if (!noValidRegionList.contains(numRegion.getRegionId()))
|
|
|
|
|
|
// {
|
|
|
|
|
|
noValidRegionList.add(numRegion.getRegionId());
|
|
|
|
|
|
noValidMap.put(numRegion.getGroupId(), noValidRegionList);
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
map.put("noValidMap", noValidMap);
|
|
|
|
|
|
map.put("validMap", validMap);
|
|
|
|
|
|
return map;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
public String configModifySources(List<ConfigCompile> configCompileList) throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
for (ConfigCompile configCompile : configCompileList) {
|
|
|
|
|
|
Long compileId = configCompile.getCompileId();
|
|
|
|
|
|
if (null != compileId) {
|
|
|
|
|
|
configCompileDao.updateConfigCompile(configCompile);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return "idIsNull";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return "ok";
|
|
|
|
|
|
}
|
2018-05-24 17:22:38 +08:00
|
|
|
|
|
2018-06-01 10:27:03 +08:00
|
|
|
|
public String saveCommonSources(SaveRequestLogThread thread, long start,String jsonString,
|
2018-05-24 17:22:38 +08:00
|
|
|
|
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)) {
|
2018-06-01 10:27:03 +08:00
|
|
|
|
logger1.error("service请检查service配置是否正确");
|
2018-05-24 17:22:38 +08:00
|
|
|
|
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())){
|
2018-06-01 10:27:03 +08:00
|
|
|
|
logger1.error(commonSourceFieldCfg.getSrcName()+"参数不能为空");
|
2018-05-24 17:22:38 +08:00
|
|
|
|
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)){
|
2018-06-01 10:27:03 +08:00
|
|
|
|
logger1.error(commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,必需是数值型");
|
2018-05-24 17:22:38 +08:00
|
|
|
|
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"));
|
2018-06-01 10:27:03 +08:00
|
|
|
|
System.out.println("--------------------TimeZone:"+sdf.getTimeZone());
|
2018-05-24 17:22:38 +08:00
|
|
|
|
Date date = sdf.parse(dstStr);
|
|
|
|
|
|
dstStr = date.getTime()+"000";
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
// TODO Auto-generated catch block
|
2018-06-01 10:27:03 +08:00
|
|
|
|
logger1.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确,必须是日期型");
|
2018-05-24 17:22:38 +08:00
|
|
|
|
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式不正确,必须是日期型");
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,必须是日期型",
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Ip":
|
|
|
|
|
|
if (!isIp(dstStr)) {
|
2018-06-01 10:27:03 +08:00
|
|
|
|
logger1.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确,不是合法的IP地址");
|
2018-05-24 17:22:38 +08:00
|
|
|
|
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)) {
|
2018-06-01 10:27:03 +08:00
|
|
|
|
logger1.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确,不是合法的Port");
|
2018-05-24 17:22:38 +08:00
|
|
|
|
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)){
|
2018-06-01 10:27:03 +08:00
|
|
|
|
logger1.error(commonSourceFieldCfg.getSrcName()+"参数不在有效范围");
|
2018-05-24 17:22:38 +08:00
|
|
|
|
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{
|
2018-06-01 10:27:03 +08:00
|
|
|
|
logger1.error(commonSourceFieldCfg.getSrcName()+"参数格式与正则不匹配");
|
2018-05-24 17:22:38 +08:00
|
|
|
|
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());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-06-01 10:27:03 +08:00
|
|
|
|
logger1.info("------------------调用非maat配置新增接口-------------------");
|
|
|
|
|
|
//按service分库
|
|
|
|
|
|
Map<Integer, List<Map<String, String>>> configMap = new HashMap<Integer, List<Map<String, String>>>();
|
|
|
|
|
|
Iterator serviceIterator = dstMaps.keySet().iterator();
|
|
|
|
|
|
while (serviceIterator.hasNext()) {
|
|
|
|
|
|
Integer service =Integer.valueOf(serviceIterator.next().toString());
|
|
|
|
|
|
List<Integer> dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service);
|
|
|
|
|
|
for (Integer dbIndex : dbIndexList) {
|
|
|
|
|
|
if (configMap.containsKey(dbIndex)) {
|
|
|
|
|
|
configMap.get(dbIndex).addAll(dstMaps.get(service));
|
|
|
|
|
|
}else{
|
|
|
|
|
|
configMap.put(dbIndex, dstMaps.get(service));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
2018-06-01 10:27:03 +08:00
|
|
|
|
configRedisService.saveUnMaatConfig(configMap);
|
2018-05-24 17:22:38 +08:00
|
|
|
|
|
|
|
|
|
|
return "ok";
|
|
|
|
|
|
}
|
|
|
|
|
|
private boolean isIp(String ipStr){
|
|
|
|
|
|
if (!(BasicProvingUtil.isIpOrIpMask(ipStr,4)||BasicProvingUtil.isIpOrIpMask(ipStr,6))) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
public String setCompileInvalid(ConfigCompile configCompile) throws Exception {
|
|
|
|
|
|
configCompileDao.setCompileInvalid(configCompile.getCompileId(), 0);
|
|
|
|
|
|
return "ok";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String setCompileValid(ConfigCompile configCompile) throws Exception {
|
|
|
|
|
|
configCompileDao.setCompileInvalid(configCompile.getCompileId(), 1);
|
|
|
|
|
|
return "ok";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-01 10:27:03 +08:00
|
|
|
|
public String getDigestGen(String realPath,String filePath)throws Exception{
|
|
|
|
|
|
System.out.println("----------------getDigestGen");
|
|
|
|
|
|
String content="";
|
|
|
|
|
|
String digestGenToolPath=Constants.DIGEST_GEN_TOOL_PATH;
|
|
|
|
|
|
String chmodCommond="chmod +x "+realPath+digestGenToolPath;//执行权限命令
|
|
|
|
|
|
System.out.println("----------------chmodCommod:"+chmodCommond);
|
|
|
|
|
|
String commondStr=realPath+digestGenToolPath+" -f "+filePath; //执行
|
|
|
|
|
|
//执行摘要获取命令 digest -f /home/aa.txt
|
|
|
|
|
|
System.out.println("------------commondStr:"+commondStr);
|
|
|
|
|
|
Runtime.getRuntime().exec(chmodCommond);
|
|
|
|
|
|
Process p=Runtime.getRuntime().exec(commondStr);
|
|
|
|
|
|
byte[] b=new byte[1024];
|
|
|
|
|
|
StringBuffer sb=new StringBuffer();
|
|
|
|
|
|
while (p.getInputStream().read(b) != -1) {
|
|
|
|
|
|
sb.append(new String(b, "UTF-8"));
|
|
|
|
|
|
}
|
|
|
|
|
|
content=sb.toString();
|
|
|
|
|
|
if (!StringUtil.isBlank(content)) {
|
|
|
|
|
|
content = StringUtil.stripAll(content);
|
|
|
|
|
|
}
|
|
|
|
|
|
System.out.println("-------------------->>"+content);
|
|
|
|
|
|
String[] digestGenReslt=content.split(" ");
|
|
|
|
|
|
if(digestGenReslt.length >=4 && !StringUtil.isEmpty(digestGenReslt[3])){
|
|
|
|
|
|
return digestGenReslt[3];
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|