|
|
@ -66,13 +66,13 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
private String backFilePath;
|
|
|
|
private String backFilePath;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${API_KEY}")
|
|
|
|
@Value("${API_KEY}")
|
|
|
|
private String apiKey;
|
|
|
|
private String apiKey;
|
|
|
|
@Value("${API_SECRET}")
|
|
|
|
@Value("${API_SECRET}")
|
|
|
|
private String apiSecret;
|
|
|
|
private String apiSecret;
|
|
|
|
|
|
|
|
|
|
|
|
/*同步表,格式:同步设置表列名/同步设置表列名(子表时设置,主表不设置)/主表唯一列(多列逗号分隔)/主表关联列/子表关联列/数据库实际表/时间列/图片或文件列/数据条件/说明*/
|
|
|
|
/*同步表,格式:同步设置表列名/同步设置表列名(子表时设置,主表不设置)/主表唯一列(多列逗号分隔)/主表关联列/子表关联列/数据库实际表/时间列/图片或文件列/数据条件/说明*/
|
|
|
|
private final String[] SYNC_TABLES= {
|
|
|
|
private final String[] SYNC_TABLES= {
|
|
|
|
"entrustAction//basic_entrust_accept/id///updateTime///委托验收","basicProducts//basic_udirel/id///updateTime///耗材字典","/basicProducts/basic_products/id/uuid/uuid////耗材字典信息详情",
|
|
|
|
"entrustAction//basic_entrust_accept/id///updateTime///委托验收","basicProducts//basic_udirel/id///updateTime///耗材字典","/basicProducts/basic_products/id/uuid/uuid////耗材字典信息详情",
|
|
|
|
"/companyCert/company_product_relevance/id/customerId/unitFk/updateTime///供应商关联信息",
|
|
|
|
"/companyCert/company_product_relevance/id/customerId/unitFk/updateTime///供应商关联信息",
|
|
|
|
"basicCorp//basic_corp/id///updateTime///往来单位","typeThird//thr_bustype_origin/id///updateTime///第三方单据类型",
|
|
|
|
"basicCorp//basic_corp/id///updateTime///往来单位","typeThird//thr_bustype_origin/id///updateTime///第三方单据类型",
|
|
|
|
"basicThirdCorp//thr_corp/id///updateTime///第三方往来单位","//thr_dept/id///updateTime///第三方部门",
|
|
|
|
"basicThirdCorp//thr_corp/id///updateTime///第三方往来单位","//thr_dept/id///updateTime///第三方部门",
|
|
|
@ -85,14 +85,14 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
"/manufacturerCert/sup_cert/id/manufacturerId/manufacturerIdFk/updateTime/filePath/type=2/生产企业资质证书信息",
|
|
|
|
"/manufacturerCert/sup_cert/id/manufacturerId/manufacturerIdFk/updateTime/filePath/type=2/生产企业资质证书信息",
|
|
|
|
"/productCert/sup_cert/id/productId/productIdFk/updateTime/filePath/type=3/产品资质证书信息",
|
|
|
|
"/productCert/sup_cert/id/productId/productIdFk/updateTime/filePath/type=3/产品资质证书信息",
|
|
|
|
"//udicompany/id///updateTime///国际库医疗器械注册人信息"};
|
|
|
|
"//udicompany/id///updateTime///国际库医疗器械注册人信息"};
|
|
|
|
//"dbDiProducts//productinfo/id///updateTime///DI产品信息",
|
|
|
|
//"dbDiProducts//productinfo/id///updateTime///DI产品信息",
|
|
|
|
//"basicInv/////////仓库字典",
|
|
|
|
//"basicInv/////////仓库字典",
|
|
|
|
//"typeBus/////////业务单据类型",
|
|
|
|
//"typeBus/////////业务单据类型",
|
|
|
|
//"typeScan/////////扫码单据类型",
|
|
|
|
//"typeScan/////////扫码单据类型",
|
|
|
|
private int orderNum=0;
|
|
|
|
private int orderNum=0;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private SystemParamConfigService systemParamConfigService;
|
|
|
|
private SystemParamConfigService systemParamConfigService;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@ -101,7 +101,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
private DbDao dbDao;
|
|
|
|
private DbDao dbDao;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private ScheduledDao scheduledDao;
|
|
|
|
private ScheduledDao scheduledDao;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public BaseResponse taskList(HttpServletRequest request,Map<String,Object> params) {
|
|
|
|
public BaseResponse taskList(HttpServletRequest request,Map<String,Object> params) {
|
|
|
@ -119,7 +119,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
if(!FileUtils.isFileExist(map.get("cacheFilePath").toString()))
|
|
|
|
if(!FileUtils.isFileExist(map.get("cacheFilePath").toString()))
|
|
|
|
ResultVOUtils.error(9000, "下载文件不存在");
|
|
|
|
ResultVOUtils.error(9000, "下载文件不存在");
|
|
|
|
String json = FileUtils.readFileAll(map.get("cacheFilePath").toString());
|
|
|
|
String json = FileUtils.readFileAll(map.get("cacheFilePath").toString());
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject object = JSON.parseObject(json);
|
|
|
|
JSONObject object = JSON.parseObject(json);
|
|
|
|
if(object==null)
|
|
|
|
if(object==null)
|
|
|
|
ResultVOUtils.error(9000, "任务下载失败");
|
|
|
|
ResultVOUtils.error(9000, "任务下载失败");
|
|
|
@ -127,31 +127,31 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
BaseResponse response = JSON.parseObject(json,BaseResponse.class);
|
|
|
|
BaseResponse response = JSON.parseObject(json,BaseResponse.class);
|
|
|
|
return response;
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.success(object);
|
|
|
|
return ResultVOUtils.success(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*UDI系统上传自助平台*/
|
|
|
|
/*UDI系统上传自助平台*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void asyncUdiTask() {
|
|
|
|
public void asyncUdiTask() {
|
|
|
|
logger.info("UDI管理系统同步任务开始--------");
|
|
|
|
logger.info("UDI管理系统同步任务开始--------");
|
|
|
|
asyncDataTask(true);
|
|
|
|
asyncDataTask(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*自助平台生成任务,不上传*/
|
|
|
|
/*自助平台生成任务,不上传*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void asyncSpsTask() {
|
|
|
|
public void asyncSpsTask() {
|
|
|
|
logger.info("自助平台同步任务开始--------");
|
|
|
|
logger.info("自助平台同步任务开始--------");
|
|
|
|
asyncDataTask(false);
|
|
|
|
asyncDataTask(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*拉取前一级中继服务数据*/
|
|
|
|
/*拉取前一级中继服务数据*/
|
|
|
|
@Async
|
|
|
|
@Async
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void asyncFetchUdiTask() {
|
|
|
|
public void asyncFetchUdiTask() {
|
|
|
|
fetchTask(false);
|
|
|
|
fetchTask(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Async
|
|
|
|
@Async
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void asyncFetchTask() {
|
|
|
|
public void asyncFetchTask() {
|
|
|
|
initTable();
|
|
|
|
initTable();
|
|
|
@ -162,9 +162,9 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
fetchTask(true);
|
|
|
|
fetchTask(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void fetchTask(boolean isIdc) {
|
|
|
|
private void fetchTask(boolean isIdc) {
|
|
|
|
|
|
|
|
|
|
|
|
String host = getNextHost();
|
|
|
|
String host = getNextHost();
|
|
|
|
if(!isIdc) {
|
|
|
|
if(!isIdc) {
|
|
|
|
Map<String,Object> map = dbDao.get("select * from sync_data_set limit 1");
|
|
|
|
Map<String,Object> map = dbDao.get("select * from sync_data_set limit 1");
|
|
|
@ -174,14 +174,14 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
logger.info("fetch from ip:"+host);
|
|
|
|
logger.info("fetch from ip:"+host);
|
|
|
|
if(!StringUtils.isEmpty(host)) {
|
|
|
|
if(!StringUtils.isEmpty(host)) {
|
|
|
|
String result = post(host+"/spssync/common/list",null);
|
|
|
|
String result = post(host+"/spssync/common/list",null);
|
|
|
|
|
|
|
|
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
JSONObject json = JSON.parseObject(result);
|
|
|
|
JSONObject json = JSON.parseObject(result);
|
|
|
|
|
|
|
|
|
|
|
|
if(json!=null&&json.getInteger("code")==20000&&json.get("data")!=null) {
|
|
|
|
if(json!=null&&json.getInteger("code")==20000&&json.get("data")!=null) {
|
|
|
|
|
|
|
|
|
|
|
|
List<Map> list = JSON.parseArray(JSON.toJSONString(json.get("data")), Map.class);
|
|
|
|
List<Map> list = JSON.parseArray(JSON.toJSONString(json.get("data")), Map.class);
|
|
|
|
|
|
|
|
|
|
|
|
if(list!=null) {
|
|
|
|
if(list!=null) {
|
|
|
|
for(Map map:list) {
|
|
|
|
for(Map map:list) {
|
|
|
|
Map<String,Object> params = new HashMap<String,Object>();
|
|
|
|
Map<String,Object> params = new HashMap<String,Object>();
|
|
|
@ -193,17 +193,17 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Async
|
|
|
|
@Async
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void asyncIdcTask() {
|
|
|
|
public void asyncIdcTask() {
|
|
|
|
initTable();
|
|
|
|
initTable();
|
|
|
|
Map<String,Object> map = dbDao.get("select * from idc_var where code='system_type'");
|
|
|
|
Map<String,Object> map = dbDao.get("select * from idc_var where code='system_type'");
|
|
|
|
if(map==null) {
|
|
|
|
if(map==null) {
|
|
|
|
dbDao.save("insert into idc_var (code,content) values ('system_type','IDC')");
|
|
|
|
dbDao.save("insert into idc_var (code,content) values ('system_type','IDC')");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void asyncDataTask(boolean isUpload) {
|
|
|
|
private void asyncDataTask(boolean isUpload) {
|
|
|
|
initTable();
|
|
|
|
initTable();
|
|
|
@ -217,7 +217,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(int i=0;i<SYNC_TABLES.length;i++) {
|
|
|
|
for(int i=0;i<SYNC_TABLES.length;i++) {
|
|
|
|
String[] tnames = SYNC_TABLES[i].split("/");
|
|
|
|
String[] tnames = SYNC_TABLES[i].split("/");
|
|
|
|
boolean sync = StringUtils.isEmpty(tnames[0]) ||
|
|
|
|
boolean sync = StringUtils.isEmpty(tnames[0]) ||
|
|
|
|
(!StringUtils.isEmpty(tnames[0])&&map!=null&&map.get(tnames[0])!=null&&map.get(tnames[0]).toString().equals("1"));
|
|
|
|
(!StringUtils.isEmpty(tnames[0])&&map!=null&&map.get(tnames[0])!=null&&map.get(tnames[0]).toString().equals("1"));
|
|
|
|
saveIdcLog("---","",map.get(tnames[0])+SYNC_TABLES[i],0,0);
|
|
|
|
saveIdcLog("---","",map.get(tnames[0])+SYNC_TABLES[i],0,0);
|
|
|
|
if(sync) {
|
|
|
|
if(sync) {
|
|
|
@ -227,15 +227,15 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void syncData(String t,boolean isUpload,String syncIp) {
|
|
|
|
private void syncData(String t,boolean isUpload,String syncIp) {
|
|
|
|
boolean sync = true;
|
|
|
|
boolean sync = true;
|
|
|
|
String[] tnames = t.split("/");
|
|
|
|
String[] tnames = t.split("/");
|
|
|
|
|
|
|
|
|
|
|
|
String lastUpdateTime = getUpdateTime(tnames[2]+"."+tnames[0]);
|
|
|
|
String lastUpdateTime = getUpdateTime(tnames[2]+"."+tnames[0]);
|
|
|
|
Date nowUpdateTime = new Date();
|
|
|
|
Date nowUpdateTime = new Date();
|
|
|
|
if(!StringUtils.isEmpty(tnames[0])) {
|
|
|
|
if(!StringUtils.isEmpty(tnames[0])) {
|
|
|
|
|
|
|
|
|
|
|
|
List<Map<String, String>> keyList = dbDao.listKeyMysql(tnames[2]);
|
|
|
|
List<Map<String, String>> keyList = dbDao.listKeyMysql(tnames[2]);
|
|
|
|
String keyColumn = keyList!=null&&keyList.size()>0 ? keyList.get(0).get("columnName").toString() : "id";
|
|
|
|
String keyColumn = keyList!=null&&keyList.size()>0 ? keyList.get(0).get("columnName").toString() : "id";
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
@ -248,7 +248,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
map.put("isEnd", "1");
|
|
|
|
map.put("isEnd", "1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
map.put("sqlWhere", sqlWhere);
|
|
|
|
map.put("sqlWhere", sqlWhere);
|
|
|
|
|
|
|
|
|
|
|
|
map.put("tableKey", tnames[0]);
|
|
|
|
map.put("tableKey", tnames[0]);
|
|
|
|
map.put("tableName", tnames[2]);
|
|
|
|
map.put("tableName", tnames[2]);
|
|
|
|
map.put("uniqueColumn", tnames[3]);
|
|
|
|
map.put("uniqueColumn", tnames[3]);
|
|
|
@ -261,33 +261,33 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
ScheduledRequest scheduledRequest = new ScheduledRequest();
|
|
|
|
ScheduledRequest scheduledRequest = new ScheduledRequest();
|
|
|
|
scheduledRequest.setCronName("sync"+WordUtils.capitalizeFully(tnames[2], new char[]{'_'}).replace("_", ""));
|
|
|
|
scheduledRequest.setCronName("sync"+WordUtils.capitalizeFully(tnames[2], new char[]{'_'}).replace("_", ""));
|
|
|
|
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
|
|
|
|
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
|
|
|
|
String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "";
|
|
|
|
String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "";
|
|
|
|
|
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(cron)) {
|
|
|
|
if(!StringUtils.isEmpty(cron)) {
|
|
|
|
CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(cron);
|
|
|
|
CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(cron);
|
|
|
|
Date nextTimePoint = cronSequenceGenerator.next(DateUtil.parseDate(lastUpdateTime));
|
|
|
|
Date nextTimePoint = cronSequenceGenerator.next(DateUtil.parseDate(lastUpdateTime));
|
|
|
|
sync = nextTimePoint.before(nowUpdateTime);
|
|
|
|
sync = nextTimePoint.before(nowUpdateTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(sync) {
|
|
|
|
if(sync) {
|
|
|
|
if(syncMasterData(map,isUpload,syncIp)) {
|
|
|
|
if(syncMasterData(map,isUpload,syncIp)) {
|
|
|
|
setUpdateTime(tnames[2]+"."+tnames[0],DateUtil.formatDate(nowUpdateTime,"yyyy-MM-dd HH:mm:ss"));
|
|
|
|
setUpdateTime(tnames[2]+"."+tnames[0],DateUtil.formatDate(nowUpdateTime,"yyyy-MM-dd HH:mm:ss"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String fetchData(String host,Map<String,Object> params) {
|
|
|
|
private String fetchData(String host,Map<String,Object> params) {
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(params));
|
|
|
|
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(params));
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(host+"/spssync/common/download")
|
|
|
|
.url(host+"/spssync/common/download")
|
|
|
|
.method("POST", body)
|
|
|
|
.method("POST", body)
|
|
|
|
.addHeader("Content-Type", "application/json")
|
|
|
|
.addHeader("Content-Type", "application/json")
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
String result = "";
|
|
|
|
String result = "";
|
|
|
|
MultipartFile[] files = {};
|
|
|
|
MultipartFile[] files = {};
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -295,7 +295,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
result = response.body().string();
|
|
|
|
result = response.body().string();
|
|
|
|
JSONObject json = JSONObject.parseObject(result);
|
|
|
|
JSONObject json = JSONObject.parseObject(result);
|
|
|
|
|
|
|
|
|
|
|
|
if(isLastLevel()) {
|
|
|
|
if(isLastLevel()) {
|
|
|
|
if(json.get("code")!=null&&json.getInteger("code")==20000) {
|
|
|
|
if(json.get("code")!=null&&json.getInteger("code")==20000) {
|
|
|
|
success = analyMiddle(host,json.getJSONObject("data"),files,false,true);
|
|
|
|
success = analyMiddle(host,json.getJSONObject("data"),files,false,true);
|
|
|
@ -310,14 +310,14 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
logger.info("res1-->"+JSON.toJSONString(json));
|
|
|
|
logger.info("res1-->"+JSON.toJSONString(json));
|
|
|
|
syncAddTaskStatus(json.getJSONObject("data"),0,success);
|
|
|
|
syncAddTaskStatus(json.getJSONObject("data"),0,success);
|
|
|
|
analyMiddle(host,json.getJSONObject("data"),files,false,false);
|
|
|
|
analyMiddle(host,json.getJSONObject("data"),files,false,false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(success) {
|
|
|
|
if(success) {
|
|
|
|
String ret = post(host+"/spssync/common/success",params);
|
|
|
|
String ret = post(host+"/spssync/common/success",params);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -328,16 +328,16 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
|
|
private String post(String url,Map<String,Object> params) {
|
|
|
|
private String post(String url,Map<String,Object> params) {
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
RequestBody body = RequestBody.create(mediaType, "");
|
|
|
|
RequestBody body = RequestBody.create(mediaType, "");
|
|
|
|
if(params!=null)
|
|
|
|
if(params!=null)
|
|
|
|
body = RequestBody.create(mediaType,JSON.toJSONString(params));
|
|
|
|
body = RequestBody.create(mediaType,JSON.toJSONString(params));
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(url)
|
|
|
|
.url(url)
|
|
|
|
.method("POST", body)
|
|
|
|
.method("POST", body)
|
|
|
|
.addHeader("Content-Type", "application/json")
|
|
|
|
.addHeader("Content-Type", "application/json")
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
String result = "";
|
|
|
|
String result = "";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
@ -358,7 +358,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
/****/
|
|
|
|
/****/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public BaseResponse receive(HttpServletRequest request,
|
|
|
|
public BaseResponse receive(HttpServletRequest request,
|
|
|
|
String content,MultipartFile[] files) {
|
|
|
|
String content,MultipartFile[] files) {
|
|
|
|
/*授权检查,后续完善*/
|
|
|
|
/*授权检查,后续完善*/
|
|
|
|
String apiKey = request.getHeader("apiKey");
|
|
|
|
String apiKey = request.getHeader("apiKey");
|
|
|
|
String secretKey = request.getHeader("secretKey");
|
|
|
|
String secretKey = request.getHeader("secretKey");
|
|
|
@ -373,23 +373,23 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
IDCUtils.createDirectory(filePath +filePathSlash +datePath+"/");
|
|
|
|
IDCUtils.createDirectory(filePath +filePathSlash +datePath+"/");
|
|
|
|
if(!FileUtils.makeDirectory(backFilePath +backFileSlash +datePath))
|
|
|
|
if(!FileUtils.makeDirectory(backFilePath +backFileSlash +datePath))
|
|
|
|
IDCUtils.createDirectory(filePath +backFileSlash +datePath+"/");
|
|
|
|
IDCUtils.createDirectory(filePath +backFileSlash +datePath+"/");
|
|
|
|
|
|
|
|
|
|
|
|
FileUtils.SaveFileAs(content, fileName);
|
|
|
|
FileUtils.SaveFileAs(content, fileName);
|
|
|
|
FileUtils.SaveFileAs(content, backFileName);
|
|
|
|
FileUtils.SaveFileAs(content, backFileName);
|
|
|
|
ArrayList<String> saveFiles = new ArrayList<>();
|
|
|
|
ArrayList<String> saveFiles = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
if(files!=null) {
|
|
|
|
if(files!=null) {
|
|
|
|
|
|
|
|
|
|
|
|
int n=0;
|
|
|
|
int n=0;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
for(MultipartFile file:files) {
|
|
|
|
for(MultipartFile file:files) {
|
|
|
|
String imageName = filePath +filePathSlash+"register/file/image2/"+file.getOriginalFilename();
|
|
|
|
String imageName = filePath +filePathSlash+"register/file/image2/"+file.getOriginalFilename();
|
|
|
|
saveFiles.add(imageName);
|
|
|
|
saveFiles.add(imageName);
|
|
|
|
|
|
|
|
|
|
|
|
writeFile(file.getBytes(), filePath +filePathSlash+"register/file/image2/", file.getOriginalFilename());
|
|
|
|
writeFile(file.getBytes(), filePath +filePathSlash+"register/file/image2/", file.getOriginalFilename());
|
|
|
|
writeFile(file.getBytes(), backFilePath +backFileSlash+datePath+"register/file/image2/", file.getOriginalFilename());
|
|
|
|
writeFile(file.getBytes(), backFilePath +backFileSlash+datePath+"register/file/image2/", file.getOriginalFilename());
|
|
|
|
n++;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -398,33 +398,33 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*解析入库*/
|
|
|
|
/*解析入库*/
|
|
|
|
boolean success = false;
|
|
|
|
boolean success = false;
|
|
|
|
if(isLastLevel()) {
|
|
|
|
if(isLastLevel()) {
|
|
|
|
success = analyMiddle("",json,files,true,true);
|
|
|
|
success = analyMiddle("",json,files,true,true);
|
|
|
|
syncAddTaskStatus(json,2,success);
|
|
|
|
syncAddTaskStatus(json,2,success);
|
|
|
|
if(!success) {
|
|
|
|
if(!success) {
|
|
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.error(9000, "解析失败");
|
|
|
|
return ResultVOUtils.error(9000, "解析失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
//需要转发
|
|
|
|
//需要转发
|
|
|
|
if(isRelay()) {
|
|
|
|
if(isRelay()) {
|
|
|
|
String host = getNextHost();
|
|
|
|
String host = getNextHost();
|
|
|
|
String result = relay(request.getHeader("reqNo"),content,saveFiles,host);
|
|
|
|
String result = relay(request.getHeader("reqNo"),content,saveFiles,host);
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
syncAddTaskStatus(json,1,true);
|
|
|
|
syncAddTaskStatus(json,1,true);
|
|
|
|
BaseResponse object = JSON.parseObject(result,BaseResponse.class);
|
|
|
|
BaseResponse object = JSON.parseObject(result,BaseResponse.class);
|
|
|
|
return object;
|
|
|
|
return object;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
syncAddTaskStatus(json,1,false);
|
|
|
|
syncAddTaskStatus(json,1,false);
|
|
|
|
return ResultVOUtils.error(9000, "转发失败");
|
|
|
|
return ResultVOUtils.error(9000, "转发失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -432,18 +432,18 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
/*数据同步,从数据库获取数据下发或上传下级中继服务*/
|
|
|
|
/*数据同步,从数据库获取数据下发或上传下级中继服务*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public BaseResponse send(Map<String,Object> params) {
|
|
|
|
public BaseResponse send(Map<String,Object> params) {
|
|
|
|
|
|
|
|
|
|
|
|
return send(params.get("messageType").toString(),params.get("tableName").toString(),params);
|
|
|
|
return send(params.get("messageType").toString(),params.get("tableName").toString(),params);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public BaseResponse send(String messageType,String tableName,Map<String,Object> params) {
|
|
|
|
public BaseResponse send(String messageType,String tableName,Map<String,Object> params) {
|
|
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.error(9999, "");
|
|
|
|
return ResultVOUtils.error(9999, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void downloadFile(String fileName,HttpServletResponse response) {
|
|
|
|
public void downloadFile(String fileName,HttpServletResponse response) {
|
|
|
|
OutputStream os;
|
|
|
|
OutputStream os;
|
|
|
@ -456,8 +456,8 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
byte[] bytes = FileUtils.readFileByBytes(filePath+filePathSlash+fileName);
|
|
|
|
byte[] bytes = FileUtils.readFileByBytes(filePath+filePathSlash+fileName);
|
|
|
|
os = response.getOutputStream();
|
|
|
|
os = response.getOutputStream();
|
|
|
|
os.write(bytes);
|
|
|
|
os.write(bytes);
|
|
|
|
os.flush();
|
|
|
|
os.flush();
|
|
|
|
os.close();
|
|
|
|
os.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// TODO Auto-generated catch block
|
|
|
@ -475,10 +475,10 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
dbDao.save(sql);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void saveExportStatus(Map<String,Object> params) {
|
|
|
|
private void saveExportStatus(Map<String,Object> params) {
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
|
|
|
|
|
|
|
map.putAll(params);
|
|
|
|
map.putAll(params);
|
|
|
|
map.put("receiveStatus", "0");
|
|
|
|
map.put("receiveStatus", "0");
|
|
|
|
map.put("id", CustomUtil.getId());
|
|
|
|
map.put("id", CustomUtil.getId());
|
|
|
@ -514,8 +514,8 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
dbDao.save(sql);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean syncMasterData(Map<String,Object> params,boolean isUpload,String syncIp) {
|
|
|
|
private boolean syncMasterData(Map<String,Object> params,boolean isUpload,String syncIp) {
|
|
|
|
boolean success=false;
|
|
|
|
boolean success=false;
|
|
|
|
String tableName = params.get("tableName").toString();
|
|
|
|
String tableName = params.get("tableName").toString();
|
|
|
@ -538,29 +538,29 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
Map<String,Object> whereParams = new HashMap<String,Object>();
|
|
|
|
Map<String,Object> whereParams = new HashMap<String,Object>();
|
|
|
|
whereParams.put("sqlWhere", params.get("sqlWhere"));
|
|
|
|
whereParams.put("sqlWhere", params.get("sqlWhere"));
|
|
|
|
whereParams.put("dataWhere", params.get("dataWhere"));
|
|
|
|
whereParams.put("dataWhere", params.get("dataWhere"));
|
|
|
|
|
|
|
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
String where = DBAUtils.convertWhere(column,whereParams,"");
|
|
|
|
String where = DBAUtils.convertWhere(column,whereParams,"");
|
|
|
|
sql+=!StringUtils.isEmpty(where) ? " where "+where : "";
|
|
|
|
sql+=!StringUtils.isEmpty(where) ? " where "+where : "";
|
|
|
|
map.put("sql", sql);
|
|
|
|
map.put("sql", sql);
|
|
|
|
int total = dbDao.count(map);
|
|
|
|
int total = dbDao.count(map);
|
|
|
|
|
|
|
|
|
|
|
|
String isEnd = params.get("isEnd")!=null ? params.get("isEnd").toString() : "0";
|
|
|
|
String isEnd = params.get("isEnd")!=null ? params.get("isEnd").toString() : "0";
|
|
|
|
int limit = 50;
|
|
|
|
int limit = 50;
|
|
|
|
ArrayList<String> files = new ArrayList<>();
|
|
|
|
ArrayList<String> files = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
String filePathColumn = params.get("filePathColumn")!=null ? params.get("filePathColumn").toString() : "";
|
|
|
|
String filePathColumn = params.get("filePathColumn")!=null ? params.get("filePathColumn").toString() : "";
|
|
|
|
orderNum++;
|
|
|
|
orderNum++;
|
|
|
|
String messageType = params.get("messageType").toString();
|
|
|
|
String messageType = params.get("messageType").toString();
|
|
|
|
saveIdcLog(messageType,"",tableName +">"+where,0,total);
|
|
|
|
saveIdcLog(messageType,"",tableName +">"+where,0,total);
|
|
|
|
String filePathSlash = filePath.substring(filePath.length() -1).equals("/") ? "" : "/";
|
|
|
|
String filePathSlash = filePath.substring(filePath.length() -1).equals("/") ? "" : "/";
|
|
|
|
|
|
|
|
|
|
|
|
if(total>0) {
|
|
|
|
if(total>0) {
|
|
|
|
success = true;
|
|
|
|
success = true;
|
|
|
|
|
|
|
|
|
|
|
|
whereParams.put("page", 0);
|
|
|
|
whereParams.put("page", 0);
|
|
|
|
whereParams.put("limit", limit);
|
|
|
|
whereParams.put("limit", limit);
|
|
|
|
|
|
|
|
|
|
|
|
List<Map<String, String>> keyList = dbDao.listKeyMysql(tableName);
|
|
|
|
List<Map<String, String>> keyList = dbDao.listKeyMysql(tableName);
|
|
|
|
String keyColumn = keyList!=null&&keyList.size()>0 ? keyList.get(0).get("columnName").toString() : "id";
|
|
|
|
String keyColumn = keyList!=null&&keyList.size()>0 ? keyList.get(0).get("columnName").toString() : "id";
|
|
|
|
for(int i=0;i<Math.ceil(total/limit)+1;i++) {
|
|
|
|
for(int i=0;i<Math.ceil(total/limit)+1;i++) {
|
|
|
@ -571,7 +571,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
orderNum++;
|
|
|
|
orderNum++;
|
|
|
|
saveIdcLog(messageType,"",tableName +">"+where,i *limit,total);
|
|
|
|
saveIdcLog(messageType,"",tableName +">"+where,i *limit,total);
|
|
|
|
if(data.get("data")!=null) {
|
|
|
|
if(data.get("data")!=null) {
|
|
|
|
|
|
|
|
|
|
|
|
List<Map> list = JSONObject.parseArray(JSON.toJSONString(data.get("data")), Map.class);
|
|
|
|
List<Map> list = JSONObject.parseArray(JSON.toJSONString(data.get("data")), Map.class);
|
|
|
|
if(list!=null&&list.size()>0) {
|
|
|
|
if(list!=null&&list.size()>0) {
|
|
|
|
for(int m=0;m<list.size();m++) {
|
|
|
|
for(int m=0;m<list.size();m++) {
|
|
|
@ -612,13 +612,13 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data.replace("data", list);
|
|
|
|
data.replace("data", list);
|
|
|
|
orderNum++;
|
|
|
|
orderNum++;
|
|
|
|
|
|
|
|
|
|
|
|
if(isUpload) {
|
|
|
|
if(isUpload) {
|
|
|
|
String result = "";
|
|
|
|
String result = "";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
result = relay("",JSON.toJSONString(data),files,syncIp);
|
|
|
|
result = relay("",JSON.toJSONString(data),files,syncIp);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
JSONObject json = JSON.parseObject(result);
|
|
|
|
JSONObject json = JSON.parseObject(result);
|
|
|
@ -629,14 +629,14 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
saveIdcLog(messageType,"",tableName +">success",i *limit,total);
|
|
|
|
saveIdcLog(messageType,"",tableName +">success",i *limit,total);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
success = false;
|
|
|
|
success = false;
|
|
|
|
|
|
|
|
|
|
|
|
saveIdcLog(messageType,"",tableName +">"+result,i *limit,total);
|
|
|
|
saveIdcLog(messageType,"",tableName +">"+result,i *limit,total);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
success = false;
|
|
|
|
success = false;
|
|
|
|
saveIdcLog(messageType,"",syncIp+":"+tableName +">fail:上传地址未连通",i *limit,total);
|
|
|
|
saveIdcLog(messageType,"",syncIp+":"+tableName +">fail:上传地址未连通",i *limit,total);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if(!StringUtils.isEmpty(recordSql)) {
|
|
|
|
if(!StringUtils.isEmpty(recordSql)) {
|
|
|
|
dbDao.save("insert into idc_record (id,type,fkId,isEnd,createTime) values "+recordSql);
|
|
|
|
dbDao.save("insert into idc_record (id,type,fkId,isEnd,createTime) values "+recordSql);
|
|
|
@ -647,12 +647,12 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*增加同步任务状态*/
|
|
|
|
/*增加同步任务状态*/
|
|
|
|
private void syncAddTaskStatus(Map<String,Object> json,int scheduleType,boolean success) {
|
|
|
|
private void syncAddTaskStatus(Map<String,Object> json,int scheduleType,boolean success) {
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -665,31 +665,31 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
IDCUtils.createDirectory(filePath +datePath+"/");
|
|
|
|
IDCUtils.createDirectory(filePath +datePath+"/");
|
|
|
|
if(!FileUtils.makeDirectory(backFilePath +datePath))
|
|
|
|
if(!FileUtils.makeDirectory(backFilePath +datePath))
|
|
|
|
IDCUtils.createDirectory(filePath +datePath+"/");
|
|
|
|
IDCUtils.createDirectory(filePath +datePath+"/");
|
|
|
|
|
|
|
|
|
|
|
|
FileUtils.SaveFileAs(content, fileName);
|
|
|
|
FileUtils.SaveFileAs(content, fileName);
|
|
|
|
FileUtils.SaveFileAs(content, backFileName);
|
|
|
|
FileUtils.SaveFileAs(content, backFileName);
|
|
|
|
|
|
|
|
|
|
|
|
//type,transportType,superiorService,subordinateService,cacheFilePath
|
|
|
|
//type,transportType,superiorService,subordinateService,cacheFilePath
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
map.put("type", json.get("messageType"));
|
|
|
|
map.put("type", json.get("messageType"));
|
|
|
|
map.put("transportType", scheduleType == 0 ? "1" : "2");
|
|
|
|
map.put("transportType", scheduleType == 0 ? "1" : "2");
|
|
|
|
map.put("scheduleType", scheduleType);
|
|
|
|
map.put("scheduleType", scheduleType);
|
|
|
|
map.put("taskId", json.get("messageId"));
|
|
|
|
map.put("taskId", json.get("messageId"));
|
|
|
|
map.put("cacheFilePath", fileName);
|
|
|
|
map.put("cacheFilePath", fileName);
|
|
|
|
map.put("status", success ? "1" : "0");
|
|
|
|
map.put("status", success ? "1" : "0");
|
|
|
|
if(scheduleType==2) {
|
|
|
|
if(scheduleType==2) {
|
|
|
|
saveUploadStatus(map);
|
|
|
|
saveUploadStatus(map);
|
|
|
|
} else if (scheduleType==3) {
|
|
|
|
} else if (scheduleType==3) {
|
|
|
|
saveDownloadStatus(map);
|
|
|
|
saveDownloadStatus(map);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
saveExportStatus(map);
|
|
|
|
saveExportStatus(map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
logger.error(ex.getMessage());
|
|
|
|
logger.error(ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean analyMiddle(String host,JSONObject jsonObject,MultipartFile[] files,boolean isUpload,boolean isToDB) {
|
|
|
|
private boolean analyMiddle(String host,JSONObject jsonObject,MultipartFile[] files,boolean isUpload,boolean isToDB) {
|
|
|
|
if(jsonObject.get("data")!=null) {
|
|
|
|
if(jsonObject.get("data")!=null) {
|
|
|
|
String tableName = "";
|
|
|
|
String tableName = "";
|
|
|
@ -725,7 +725,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean analyToFile(String host,String filePathColumn,List<Map<String,Object>> list) {
|
|
|
|
private boolean analyToFile(String host,String filePathColumn,List<Map<String,Object>> list) {
|
|
|
|
|
|
|
|
|
|
|
|
if(list!=null&&list.size()>0) {
|
|
|
|
if(list!=null&&list.size()>0) {
|
|
|
|
String[] files = new String[list.size()];
|
|
|
|
String[] files = new String[list.size()];
|
|
|
|
//logger.info("filePathColumn-->"+filePathColumn);
|
|
|
|
//logger.info("filePathColumn-->"+filePathColumn);
|
|
|
@ -745,13 +745,13 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
batchDownloadFile(host,files);
|
|
|
|
batchDownloadFile(host,files);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*解析到数据库*/
|
|
|
|
/*解析到数据库*/
|
|
|
|
|
|
|
|
|
|
|
|
/*按表名解析数据到数据库,子表暂未处理*/
|
|
|
|
/*按表名解析数据到数据库,子表暂未处理*/
|
|
|
|
private boolean analyToDB(String host,String tableName,String uniqueColumn,String filePathColumn,List<Map<String,Object>> list,boolean isUpload) {
|
|
|
|
private boolean analyToDB(String host,String tableName,String uniqueColumn,String filePathColumn,List<Map<String,Object>> list,boolean isUpload) {
|
|
|
|
|
|
|
|
|
|
|
@ -777,7 +777,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
key++;
|
|
|
|
key++;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if(columnList.get(i).get("columnKey")!=null&&!StringUtils.isEmpty(columnList.get(i).get("columnKey").toString())&&
|
|
|
|
if(columnList.get(i).get("columnKey")!=null&&!StringUtils.isEmpty(columnList.get(i).get("columnKey").toString())&&
|
|
|
|
("PRI".contains(columnList.get(i).get("columnKey").toString()))) {
|
|
|
|
("PRI".contains(columnList.get(i).get("columnKey").toString()))) {
|
|
|
|
keyColumn[key] = columnList.get(i).get("columnName").toString();
|
|
|
|
keyColumn[key] = columnList.get(i).get("columnName").toString();
|
|
|
|
keyDataType[key]=columnList.get(i).get("dataType").toString().contains("char") ? "C" : columnList.get(i).get("dataType").toString().contains("date") ? "D" : "N";
|
|
|
|
keyDataType[key]=columnList.get(i).get("dataType").toString().contains("char") ? "C" : columnList.get(i).get("dataType").toString().contains("date") ? "D" : "N";
|
|
|
|
key++;
|
|
|
|
key++;
|
|
|
@ -797,7 +797,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
if(!StringUtils.isEmpty(filePathColumn)) {
|
|
|
|
if(!StringUtils.isEmpty(filePathColumn)) {
|
|
|
|
files[i] = list.get(i).get(filePathColumn) !=null ? list.get(i).get(filePathColumn).toString() : "";
|
|
|
|
files[i] = list.get(i).get(filePathColumn) !=null ? list.get(i).get(filePathColumn).toString() : "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if("A,D,U".contains(operateMode)) {
|
|
|
|
if("A,D,U".contains(operateMode)) {
|
|
|
|
for(int z=0;z<keyColumn.length;z++ ) {
|
|
|
|
for(int z=0;z<keyColumn.length;z++ ) {
|
|
|
|
if(list.get(i).get(keyColumn[z])!=null&&!StringUtils.isEmpty(list.get(i).get(keyColumn[z]).toString())) {
|
|
|
|
if(list.get(i).get(keyColumn[z])!=null&&!StringUtils.isEmpty(list.get(i).get(keyColumn[z]).toString())) {
|
|
|
@ -807,7 +807,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
updateWhere+=keyColumn[z]+" = "+(keyDataType[z].equals("C") ? "'" :"") +value +(keyDataType[z].equals("C") ? "'" :"");
|
|
|
|
updateWhere+=keyColumn[z]+" = "+(keyDataType[z].equals("C") ? "'" :"") +value +(keyDataType[z].equals("C") ? "'" :"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if("A,D".contains(operateMode)&&!StringUtils.isEmpty(updateWhere))
|
|
|
|
if("A,D".contains(operateMode)&&!StringUtils.isEmpty(updateWhere))
|
|
|
|
dbDao.delete(del+updateWhere);
|
|
|
|
dbDao.delete(del+updateWhere);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -823,40 +823,40 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
String value = list.get(i).get(attrName) !=null ? list.get(i).get(attrName).toString() : "";
|
|
|
|
String value = list.get(i).get(attrName) !=null ? list.get(i).get(attrName).toString() : "";
|
|
|
|
value = DBAUtils.escape(value);
|
|
|
|
value = DBAUtils.escape(value);
|
|
|
|
String dataType = columnList.get(k).get("dataType").toLowerCase().contains("char") || columnList.get(k).get("dataType").toLowerCase().contains("text") ?
|
|
|
|
String dataType = columnList.get(k).get("dataType").toLowerCase().contains("char") || columnList.get(k).get("dataType").toLowerCase().contains("text") ?
|
|
|
|
"C" : columnList.get(k).get("dataType").toLowerCase().contains("date") ? "D" : "N" ;
|
|
|
|
"C" : columnList.get(k).get("dataType").toLowerCase().contains("date") ? "D" : "N" ;
|
|
|
|
|
|
|
|
|
|
|
|
sql+=m>0 ? "," : "";
|
|
|
|
sql+=m>0 ? "," : "";
|
|
|
|
boolean ups = list.get(i).containsKey(attrName) ? true : false ;
|
|
|
|
boolean ups = list.get(i).containsKey(attrName) ? true : false ;
|
|
|
|
updateSet+=ups&&h>0 ? "," : "";
|
|
|
|
updateSet+=ups&&h>0 ? "," : "";
|
|
|
|
updateSet+=ups ? columnList.get(k).get("columnName")+"=" : "";
|
|
|
|
updateSet+=ups ? columnList.get(k).get("columnName")+"=" : "";
|
|
|
|
if(StringUtils.isEmpty(value)) {
|
|
|
|
if(StringUtils.isEmpty(value)) {
|
|
|
|
sql+="null";
|
|
|
|
sql+="null";
|
|
|
|
updateSet+=ups ? "null" : "";
|
|
|
|
updateSet+=ups ? "null" : "";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if(dataType.equals("C")) {
|
|
|
|
|
|
|
|
sql+="'"+value+"'";
|
|
|
|
|
|
|
|
updateSet+=ups ? "'"+value+"'" : "";
|
|
|
|
|
|
|
|
} else if (dataType.equals("N")) {
|
|
|
|
|
|
|
|
sql+=value;
|
|
|
|
|
|
|
|
updateSet+=ups ? value : "";
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if(dataType.equals("C")) {
|
|
|
|
Date date = new Date();
|
|
|
|
sql+="'"+value+"'";
|
|
|
|
date = StringUtils.isNumeric(value) ? new Date(Long.valueOf(value)) : IDCUtils.parseDate(value);
|
|
|
|
updateSet+=ups ? "'"+value+"'" : "";
|
|
|
|
String str = DateUtils.format(date, "yyyy-MM-dd HH:mm:ss");
|
|
|
|
} else if (dataType.equals("N")) {
|
|
|
|
sql+="cast('"+str+"' as datetime)";
|
|
|
|
sql+=value;
|
|
|
|
updateSet+=ups ? "cast('"+str+"' as datetime)" : "";
|
|
|
|
updateSet+=ups ? value : "";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
|
|
|
date = StringUtils.isNumeric(value) ? new Date(Long.valueOf(value)) : IDCUtils.parseDate(value);
|
|
|
|
|
|
|
|
String str = DateUtils.format(date, "yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
sql+="cast('"+str+"' as datetime)";
|
|
|
|
|
|
|
|
updateSet+=ups ? "cast('"+str+"' as datetime)" : "";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m++;
|
|
|
|
|
|
|
|
if(operateMode.equals("U")&&!StringUtils.isEmpty(updateSet)&&!StringUtils.isEmpty(updateWhere))
|
|
|
|
|
|
|
|
dbDao.update(upd + updateSet+" where "+updateWhere);
|
|
|
|
|
|
|
|
h+=ups ? 1 : 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m++;
|
|
|
|
|
|
|
|
if(operateMode.equals("U")&&!StringUtils.isEmpty(updateSet)&&!StringUtils.isEmpty(updateWhere))
|
|
|
|
|
|
|
|
dbDao.update(upd + updateSet+" where "+updateWhere);
|
|
|
|
|
|
|
|
h+=ups ? 1 : 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sql+=")";
|
|
|
|
sql+=")";
|
|
|
|
n++;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(int m=0;m<30;m++) {
|
|
|
|
for(int m=0;m<30;m++) {
|
|
|
|
if(list.get(i).get("tableName"+m)!=null&&list.get(i).get("data"+m)!=null) {
|
|
|
|
if(list.get(i).get("tableName"+m)!=null&&list.get(i).get("data"+m)!=null) {
|
|
|
|
Object obj = list.get(i).get("data"+m);
|
|
|
|
Object obj = list.get(i).get("data"+m);
|
|
|
@ -870,10 +870,10 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(n>0) {
|
|
|
|
if(n>0) {
|
|
|
|
|
|
|
|
|
|
|
|
result = (dbDao.save(sql)>0);
|
|
|
|
result = (dbDao.save(sql)>0);
|
|
|
|
if(!result)
|
|
|
|
if(!result)
|
|
|
|
logger.error(tableName+"-->fetchSave Fail");
|
|
|
|
logger.error(tableName+"-->fetchSave Fail");
|
|
|
@ -894,7 +894,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
host+="/spssync/common/upload" ;
|
|
|
|
host+="/spssync/common/upload" ;
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
.connectTimeout(30, TimeUnit.SECONDS)//设置连接超时时间
|
|
|
|
.connectTimeout(30, TimeUnit.SECONDS)//设置连接超时时间
|
|
|
|
.readTimeout(30, TimeUnit.SECONDS)//设置读取超时时间
|
|
|
|
.readTimeout(30, TimeUnit.SECONDS)//设置读取超时时间
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
|
|
|
|
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
|
|
|
|
|
|
|
|
|
|
|
@ -905,8 +905,8 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
for (int i = 0; i < files.size(); i++) {
|
|
|
|
for (int i = 0; i < files.size(); i++) {
|
|
|
|
if(!StringUtils.isEmpty(files.get(i))) {
|
|
|
|
if(!StringUtils.isEmpty(files.get(i))) {
|
|
|
|
File file = new File(files.get(i));
|
|
|
|
File file = new File(files.get(i));
|
|
|
|
builder.addFormDataPart("files",files.get(i),
|
|
|
|
builder.addFormDataPart("files",files.get(i),
|
|
|
|
RequestBody.create(MediaType.parse(fileType), file));
|
|
|
|
RequestBody.create(MediaType.parse(fileType), file));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -914,17 +914,17 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
RequestBody body = builder.build();
|
|
|
|
RequestBody body = builder.build();
|
|
|
|
|
|
|
|
|
|
|
|
Request req = new Request.Builder()
|
|
|
|
Request req = new Request.Builder()
|
|
|
|
.url(host)
|
|
|
|
.url(host)
|
|
|
|
.method("POST", body)
|
|
|
|
.method("POST", body)
|
|
|
|
.addHeader("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
.addHeader("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
.addHeader("format", "json")
|
|
|
|
.addHeader("format", "json")
|
|
|
|
.addHeader("apiKey", apiKey)
|
|
|
|
.addHeader("apiKey", apiKey)
|
|
|
|
.addHeader("secretKey", apiSecret)
|
|
|
|
.addHeader("secretKey", apiSecret)
|
|
|
|
.addHeader("reqNo", reqNo)
|
|
|
|
.addHeader("reqNo", reqNo)
|
|
|
|
.addHeader("timestamp",DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"))
|
|
|
|
.addHeader("timestamp",DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"))
|
|
|
|
.addHeader("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, Content-Type, Accept")
|
|
|
|
.addHeader("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, Content-Type, Accept")
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Response response = client.newCall(req).execute();
|
|
|
|
Response response = client.newCall(req).execute();
|
|
|
|
result=response.body().string();
|
|
|
|
result=response.body().string();
|
|
|
|
log.debug("result--->"+result);
|
|
|
|
log.debug("result--->"+result);
|
|
|
@ -947,7 +947,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
String[] str = fileName.split(",");
|
|
|
|
String[] str = fileName.split(",");
|
|
|
|
for(int i=0;i<str.length;i++) {
|
|
|
|
for(int i=0;i<str.length;i++) {
|
|
|
|
if(!StringUtils.isEmpty(str[i])) {
|
|
|
|
if(!StringUtils.isEmpty(str[i])) {
|
|
|
|
|
|
|
|
|
|
|
|
if(!signleDownloadFile(syncIp,str[i]))
|
|
|
|
if(!signleDownloadFile(syncIp,str[i]))
|
|
|
|
success = false;
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -958,11 +958,11 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private boolean signleDownloadFile(String syncIp,String fileName) {
|
|
|
|
private boolean signleDownloadFile(String syncIp,String fileName) {
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
.build();;
|
|
|
|
.build();;
|
|
|
|
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
|
|
|
|
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody body = RequestBody.create(mediaType, "fileName="+fileName);
|
|
|
|
RequestBody body = RequestBody.create(mediaType, "fileName="+fileName);
|
|
|
|
|
|
|
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(syncIp+"/spssync/common/downloadFile")
|
|
|
|
.url(syncIp+"/spssync/common/downloadFile")
|
|
|
|
.post(body)
|
|
|
|
.post(body)
|
|
|
@ -970,12 +970,12 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Response result = client.newCall(request).execute();
|
|
|
|
Response result = client.newCall(request).execute();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (MediaType.parse("application/force-download").equals(result.body().contentType())) {
|
|
|
|
if (MediaType.parse("application/force-download").equals(result.body().contentType())) {
|
|
|
|
try (InputStream inputStream = result.body().byteStream()) {
|
|
|
|
try (InputStream inputStream = result.body().byteStream()) {
|
|
|
|
String filePathSlash = filePath.substring(filePath.length() -1).equals("/") ? "" : "/";
|
|
|
|
String filePathSlash = filePath.substring(filePath.length() -1).equals("/") ? "" : "/";
|
|
|
|
|
|
|
|
|
|
|
|
FileOutputStream outputStream =new FileOutputStream(filePath +filePathSlash+fileName);
|
|
|
|
FileOutputStream outputStream =new FileOutputStream(filePath +filePathSlash+fileName);
|
|
|
|
|
|
|
|
|
|
|
|
byte b[]=new byte[1024];
|
|
|
|
byte b[]=new byte[1024];
|
|
|
@ -990,14 +990,14 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
|
|
outputStream.flush();
|
|
|
|
outputStream.flush();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -1005,7 +1005,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*获取转发服务地址,当前值允许单向,只使用参数upper_server_ip*/
|
|
|
|
/*获取转发服务地址,当前值允许单向,只使用参数upper_server_ip*/
|
|
|
|
private String getNextHost() {
|
|
|
|
private String getNextHost() {
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("upper_server_ip");
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("upper_server_ip");
|
|
|
@ -1019,7 +1019,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
Map<String,Object> map = dbDao.get("select * from idc_var where code='system_type'");
|
|
|
|
Map<String,Object> map = dbDao.get("select * from idc_var where code='system_type'");
|
|
|
|
return !(map!=null&&map.get("content")!=null&&map.get("content").toString().equals("IDC")) ;
|
|
|
|
return !(map!=null&&map.get("content")!=null&&map.get("content").toString().equals("IDC")) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*是否需要转发*/
|
|
|
|
/*是否需要转发*/
|
|
|
|
private boolean isRelay() {
|
|
|
|
private boolean isRelay() {
|
|
|
|
String relayHost = getNextHost();
|
|
|
|
String relayHost = getNextHost();
|
|
|
@ -1030,10 +1030,10 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
private List<Map<String,Object>> getList(String tableName,Map<String,Object> params) {
|
|
|
|
private List<Map<String,Object>> getList(String tableName,Map<String,Object> params) {
|
|
|
|
String sql = "select "+tableName+".*,'A' as operateMode from "+tableName;
|
|
|
|
String sql = "select "+tableName+".*,'A' as operateMode from "+tableName;
|
|
|
|
Map<String,Object> column = getColumn(tableName);
|
|
|
|
Map<String,Object> column = getColumn(tableName);
|
|
|
|
|
|
|
|
|
|
|
|
String where = DBAUtils.convertWhere(column,params,"");
|
|
|
|
String where = DBAUtils.convertWhere(column,params,"");
|
|
|
|
sql+=!StringUtils.isEmpty(where) ? " where "+where : "";
|
|
|
|
sql+=!StringUtils.isEmpty(where) ? " where "+where : "";
|
|
|
|
|
|
|
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
map.putAll(params);
|
|
|
|
map.putAll(params);
|
|
|
|
map.put("sql", sql);
|
|
|
|
map.put("sql", sql);
|
|
|
@ -1099,7 +1099,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
for(int i=0;i<columnList.size();i++) {
|
|
|
|
for(int i=0;i<columnList.size();i++) {
|
|
|
|
Map<String,Object> column = new HashMap<String,Object>();
|
|
|
|
Map<String,Object> column = new HashMap<String,Object>();
|
|
|
|
String dataType =columnList.get(i).get("dataType").toLowerCase().contains("char") || columnList.get(i).get("dataType").toLowerCase().contains("text")?
|
|
|
|
String dataType =columnList.get(i).get("dataType").toLowerCase().contains("char") || columnList.get(i).get("dataType").toLowerCase().contains("text")?
|
|
|
|
"C" : columnList.get(i).get("dataType").toLowerCase().contains("date") ? "D" : "N" ;;
|
|
|
|
"C" : columnList.get(i).get("dataType").toLowerCase().contains("date") ? "D" : "N" ;;
|
|
|
|
String attrName = columnList.get(i).get("columnName").toString();
|
|
|
|
String attrName = columnList.get(i).get("columnName").toString();
|
|
|
|
if(map.get(attrName)==null) {
|
|
|
|
if(map.get(attrName)==null) {
|
|
|
|
column.put("tableName", tname);
|
|
|
|
column.put("tableName", tname);
|
|
|
@ -1131,7 +1131,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
//国家库数据
|
|
|
|
//国家库数据
|
|
|
|
if(id.equals("productinfo")) {
|
|
|
|
if(id.equals("productinfo")) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateTime = "2000-01-01 00:00:00";
|
|
|
|
updateTime = "2000-01-01 00:00:00";
|
|
|
|
String sql = "insert into idc_status (id,statusTime) values ('"+id+"',cast('"+updateTime+"' as datetime))";
|
|
|
|
String sql = "insert into idc_status (id,statusTime) values ('"+id+"',cast('"+updateTime+"' as datetime))";
|
|
|
@ -1163,7 +1163,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
jdbcTemplate.execute("alter table idc_status modify column id varchar(100)");
|
|
|
|
jdbcTemplate.execute("alter table idc_status modify column id varchar(100)");
|
|
|
|
jdbcTemplate.execute("delete from idc_log where createTime<date_sub(now(),interval 3 day)");
|
|
|
|
jdbcTemplate.execute("delete from idc_log where createTime<date_sub(now(),interval 3 day)");
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void alterTable(String tableName,String sql) {
|
|
|
|
private void alterTable(String tableName,String sql) {
|
|
|
@ -1173,6 +1173,6 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|