|
|
|
@ -1,25 +1,21 @@
|
|
|
|
|
package com.glxp.api.idc.service.impl;
|
|
|
|
|
package com.glxp.sale.admin.idc.service.impl;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
|
|
|
import com.glxp.api.common.util.ResultVOUtils;
|
|
|
|
|
import com.glxp.api.dao.idc.DbDao;
|
|
|
|
|
import com.glxp.api.dao.schedule.ScheduledDao;
|
|
|
|
|
import com.glxp.api.entity.system.ScheduledEntity;
|
|
|
|
|
import com.glxp.api.entity.system.SystemParamConfigEntity;
|
|
|
|
|
import com.glxp.api.idc.service.IdcService;
|
|
|
|
|
import com.glxp.api.idc.utils.DBAUtils;
|
|
|
|
|
import com.glxp.api.idc.utils.IDCUtils;
|
|
|
|
|
import com.glxp.api.req.system.ScheduledRequest;
|
|
|
|
|
import com.glxp.api.service.system.SystemParamConfigService;
|
|
|
|
|
import com.glxp.api.util.CustomUtil;
|
|
|
|
|
import com.glxp.api.util.DateUtil;
|
|
|
|
|
import com.glxp.api.util.FileUtils;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import okhttp3.*;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.text.WordUtils;
|
|
|
|
|
import org.apache.commons.text.WordUtils;
|
|
|
|
|
import org.apache.tools.ant.util.DateUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
@ -30,13 +26,30 @@ import org.springframework.scheduling.support.CronSequenceGenerator;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.glxp.sale.admin.dao.info.ScheduledDao;
|
|
|
|
|
import com.glxp.sale.admin.entity.info.ScheduledEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.param.SystemParamConfigEntity;
|
|
|
|
|
import com.glxp.sale.admin.idc.dao.DbDao;
|
|
|
|
|
import com.glxp.sale.admin.idc.service.IdcService;
|
|
|
|
|
import com.glxp.sale.admin.idc.utils.DBAUtils;
|
|
|
|
|
import com.glxp.sale.admin.idc.utils.IDCUtils;
|
|
|
|
|
import com.glxp.sale.admin.req.info.ScheduledRequest;
|
|
|
|
|
import com.glxp.sale.admin.service.param.SystemParamConfigService;
|
|
|
|
|
import com.glxp.sale.admin.util.CustomUtil;
|
|
|
|
|
import com.glxp.sale.admin.util.DateUtil;
|
|
|
|
|
import com.glxp.sale.admin.util.FileUtils;
|
|
|
|
|
import com.glxp.sale.common.res.BaseResponse;
|
|
|
|
|
import com.glxp.sale.common.util.ResultVOUtils;
|
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import okhttp3.MediaType;
|
|
|
|
|
import okhttp3.MultipartBody;
|
|
|
|
|
import okhttp3.OkHttpClient;
|
|
|
|
|
import okhttp3.Request;
|
|
|
|
|
import okhttp3.RequestBody;
|
|
|
|
|
import okhttp3.Response;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*数据中继数据中心(接收)*/
|
|
|
|
@ -54,27 +67,18 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
@Value("${API_SECRET}")
|
|
|
|
|
private String apiSecret;
|
|
|
|
|
|
|
|
|
|
/*自助平台->UDI*/
|
|
|
|
|
private final String[] SPMS_TO_UDI_TABLES = {
|
|
|
|
|
"basic_udirel/updateTime//耗材字典", "basic_products///耗材字典信息详情", "company_product_relevance/updateTime//供应商关联信息",
|
|
|
|
|
"basic_corp/updateTime//往来单位", "thr_bustype_origin/updateTime//第三方单据类型",
|
|
|
|
|
"thr_corp/updateTime//第三方往来单位", "thr_dept/updateTime//第三方部门",
|
|
|
|
|
"thr_inv_products/updateTime//第三方库存", "thr_inv_warehouse///第三方仓库",
|
|
|
|
|
"thr_order/updateTime//第三方单据", "thr_order_detail/updateTime//第三方单据详情",
|
|
|
|
|
"thr_products/updateTime//第三方产品信息", "sup_cert/updateTime/filePath/资质证书信息",
|
|
|
|
|
"sup_cert_set/updateTime//供应商资质证书设置", "sup_company/updateTime//配送供应商资质信息",
|
|
|
|
|
"sup_manufacturer/updateTime//生产企业资质信息", "sup_product/updateTime//产品资质信息"};
|
|
|
|
|
/*UDI->自助平台*/
|
|
|
|
|
private final String[] UDI_TO_SPMS_TABLES = {
|
|
|
|
|
"basic_udirel/updateTime//耗材字典", "basic_products///耗材字典信息详情", "company_product_relevance/updateTime//供应商关联信息",
|
|
|
|
|
"basic_corp/updateTime//往来单位", "thr_bustype_origin/updateTime//第三方单据类型",
|
|
|
|
|
"thr_corp/updateTime//第三方往来单位", "thr_dept/updateTime//第三方部门",
|
|
|
|
|
"thr_inv_products/updateTime//第三方库存", "thr_inv_warehouse///第三方仓库",
|
|
|
|
|
"thr_order/updateTime//第三方单据", "thr_order_detail/updateTime//第三方单据详情",
|
|
|
|
|
"thr_products/updateTime//第三方产品信息", "sup_cert/updateTime/filePath/资质证书信息",
|
|
|
|
|
"sup_cert_set/updateTime//供应商资质证书设置", "sup_company/updateTime//配送供应商资质信息",
|
|
|
|
|
"sup_manufacturer/updateTime//生产企业资质信息", "sup_product/updateTime//产品资质信息",
|
|
|
|
|
"productinfo/updateTime//国家库UDI数据,udicompany/updateTime//国际库医疗器械注册人信息"};
|
|
|
|
|
/*同步表,格式:同步设置表列名/同步设置表列名(子表时设置,主表不设置)/主表关联列/子表关联列/数据库实际表/时间列/图片或文件列/数据条件/说明*/
|
|
|
|
|
private final String[] SYNC_TABLES= {
|
|
|
|
|
"entrustAction////////委托验收,basicProducts//basic_udirel///updateTime///耗材字典","/basicProducts/basic_products//////耗材字典信息详情",
|
|
|
|
|
"//company_product_relevance///updateTime///供应商关联信息",
|
|
|
|
|
"basicCorp//basic_corp///updateTime///往来单位","typeThird//thr_bustype_origin///updateTime///第三方单据类型",
|
|
|
|
|
"basicThirdCorp//thr_corp///updateTime///第三方往来单位","//thr_dept///updateTime///第三方部门",
|
|
|
|
|
"//thr_inv_products///updateTime///第三方库存","basicThirdInv//thr_inv_warehouse//////第三方仓库",
|
|
|
|
|
"basicThirdBusOrder//thr_order///updateTime///第三方业务单据","/basicThirdBusOrder/thr_order_detail///updateTime///第三方单据详情",
|
|
|
|
|
"basicThirdProducts//thr_products///updateTime///第三方产品信息","//sup_cert///updateTime/filePath//资质证书信息",
|
|
|
|
|
"//sup_cert_set///updateTime///供应商资质证书设置","companyCert//sup_company///updateTime///配送企业",
|
|
|
|
|
"manufacturerCert//sup_manufacturer///updateTime///生产企业","productCert//sup_product///updateTime///产品资质信息",
|
|
|
|
|
"dbDiProducts//productinfo///updateTime///DI产品信息,//udicompany///updateTime///国际库医疗器械注册人信息"};
|
|
|
|
|
|
|
|
|
|
private int orderNum=0;
|
|
|
|
|
|
|
|
|
@ -108,14 +112,25 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
return ResultVOUtils.success(object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*UDI系统上传自助平台*/
|
|
|
|
|
@Override
|
|
|
|
|
public void asyncUdiTask() {
|
|
|
|
|
asyncDataTask(true);
|
|
|
|
|
}
|
|
|
|
|
/*自助平台生成任务,不上传*/
|
|
|
|
|
@Override
|
|
|
|
|
public void asyncSpsTask() {
|
|
|
|
|
asyncDataTask(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*拉取前一级中继服务数据*/
|
|
|
|
|
@Async
|
|
|
|
|
@Override
|
|
|
|
|
public void asyncFetchTask() {
|
|
|
|
|
String[] directions = {"I", "U"};
|
|
|
|
|
for (String dir : directions) {
|
|
|
|
|
|
|
|
|
|
Map<String,Object> query = new HashMap<String,Object>();
|
|
|
|
|
String host = getNextHost(dir);
|
|
|
|
|
String host = getNextHost();
|
|
|
|
|
if(!StringUtils.isEmpty(host)) {
|
|
|
|
|
String result = post(host+"/spssync/common/list",query);
|
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
@ -132,73 +147,83 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Async
|
|
|
|
|
@Override
|
|
|
|
|
public void asyncIdcTask() {
|
|
|
|
|
initTable();
|
|
|
|
|
String[] tNames = {};
|
|
|
|
|
String direction = getDirection();
|
|
|
|
|
|
|
|
|
|
if (direction.equals("I")) {
|
|
|
|
|
tNames = SPMS_TO_UDI_TABLES;
|
|
|
|
|
} else if (direction.equals("U")) {
|
|
|
|
|
tNames = UDI_TO_SPMS_TABLES;
|
|
|
|
|
}
|
|
|
|
|
/*为顶级或末级,以及下游或上游连通,可执行*/
|
|
|
|
|
Boolean isLastLevel = isLastLevel(direction);
|
|
|
|
|
Boolean isRelay = isRelay(direction);
|
|
|
|
|
logger.info("-----数据传输任务开始----" + direction + "\n");
|
|
|
|
|
logger.info("-----是否需要上传或下发数据:" + isLastLevel + ",是否已配置接收地址:" + isRelay + "----\n");
|
|
|
|
|
if (isLastLevel && isRelay) {
|
|
|
|
|
for (String t : tNames) {
|
|
|
|
|
uploadData(t);
|
|
|
|
|
Map<String,Object> map = dbDao.get("select * from idc_var where code='system_type'");
|
|
|
|
|
if(map==null) {
|
|
|
|
|
dbDao.save("insert into idc_var (code,content) values ('system_type','IDC')");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void asyncDataTask(boolean isUpload) {
|
|
|
|
|
initTable();
|
|
|
|
|
Map<String,Object> map = dbDao.get("select * from sync_data_set limit 1");
|
|
|
|
|
if(map!=null&&map.get("downstreamEnable")!=null&&map.get("downstreamEnable").toString().equals("1"))
|
|
|
|
|
for(int i=0;i<SYNC_TABLES.length;i++) {
|
|
|
|
|
String[] tnames = SYNC_TABLES[i].split("/");
|
|
|
|
|
if(!StringUtils.isEmpty(tnames[0])&&map!=null&&map.get(tnames[0])!=null&&map.get(tnames[0]).toString().equals("1"))
|
|
|
|
|
syncData(SYNC_TABLES[i],isUpload);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void uploadData(String t) {
|
|
|
|
|
String[] tn = t.split("/");
|
|
|
|
|
String lastUpdateTime = getUpdateTime(tn[0]);
|
|
|
|
|
private void syncData(String t,boolean isUpload) {
|
|
|
|
|
boolean sync = true;
|
|
|
|
|
String[] tnames = t.split("/");
|
|
|
|
|
String[] cnames = {};
|
|
|
|
|
String lastUpdateTime = getUpdateTime(tnames[0]);
|
|
|
|
|
Date nowUpdateTime = new Date();
|
|
|
|
|
List<Map<String, String>> keyList = dbDao.listKeyMysql(tn[0]);
|
|
|
|
|
if(!StringUtils.isEmpty(tnames[0])) {
|
|
|
|
|
int n=-1;
|
|
|
|
|
for(int k=0;k<SYNC_TABLES.length;k++) {
|
|
|
|
|
if(SYNC_TABLES[k].contains("/"+tnames[0]+"/")) {
|
|
|
|
|
n++;
|
|
|
|
|
cnames[n] = SYNC_TABLES[k];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<Map<String, String>> keyList = dbDao.listKeyMysql(tnames[2]);
|
|
|
|
|
String keyColumn = keyList!=null&&keyList.size()>0 ? keyList.get(0).get("columnName").toString() : "id";
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
String sqlWhere = "not exists (select fkId from idc_record where type='" + tn[0] + "' and fkId=" + tn[0] + "." + keyColumn + ")";
|
|
|
|
|
if (!StringUtils.isEmpty(tn[1])) {
|
|
|
|
|
sqlWhere += " and " + tn[1] + ">=cast('" + lastUpdateTime + "' as datetime)";
|
|
|
|
|
String sqlWhere = "not exists (select fkId from idc_record where type='"+tnames[2]+"' and fkId="+tnames[2]+"."+keyColumn+")";
|
|
|
|
|
if(!StringUtils.isEmpty(tnames[2])) {
|
|
|
|
|
sqlWhere+=" and "+tnames[5]+">=cast('"+lastUpdateTime+"' as datetime)";
|
|
|
|
|
} else {
|
|
|
|
|
map.put("isEnd", "1");
|
|
|
|
|
}
|
|
|
|
|
if (tn[0].equals("thr_order"))
|
|
|
|
|
logger.info("-------------------" + sqlWhere);
|
|
|
|
|
map.put("sqlWhere", sqlWhere);
|
|
|
|
|
map.put("tableName", tn[0]);
|
|
|
|
|
map.put("filePathColumn", tn[2]);
|
|
|
|
|
map.put("messageType", tn[3]);
|
|
|
|
|
map.put("messageName", tn[3]);
|
|
|
|
|
map.put("dataWhere", tnames[7]);
|
|
|
|
|
map.put("tableKey", tnames[0]);
|
|
|
|
|
map.put("tableName", tnames[2]);
|
|
|
|
|
map.put("masterLinkColumn", tnames[3]);
|
|
|
|
|
map.put("subLinkColumn", tnames[4]);
|
|
|
|
|
map.put("filePathColumn", tnames[6]);
|
|
|
|
|
map.put("messageType", tnames[8]);
|
|
|
|
|
map.put("messageName", tnames[8]);
|
|
|
|
|
ScheduledRequest scheduledRequest = new ScheduledRequest();
|
|
|
|
|
scheduledRequest.setCronName("sync" + WordUtils.capitalizeFully(tn[0], new char[]{'_'}).replace("_", ""));
|
|
|
|
|
scheduledRequest.setCronName("sync"+WordUtils.capitalizeFully(tnames[2], new char[]{'_'}).replace("_", ""));
|
|
|
|
|
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
|
|
|
|
|
String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "";
|
|
|
|
|
boolean send = true;
|
|
|
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(cron)) {
|
|
|
|
|
CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(cron);
|
|
|
|
|
Date nextTimePoint = cronSequenceGenerator.next(DateUtil.parseDate(lastUpdateTime));
|
|
|
|
|
send = nextTimePoint.before(nowUpdateTime);
|
|
|
|
|
sync = nextTimePoint.before(nowUpdateTime);
|
|
|
|
|
}
|
|
|
|
|
if(sync) {
|
|
|
|
|
if(syncMasterData(map,isUpload)) {
|
|
|
|
|
setUpdateTime(tnames[2],DateUtil.formatDate(nowUpdateTime,"yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
}
|
|
|
|
|
if (send) {
|
|
|
|
|
BaseResponse result = send(map);
|
|
|
|
|
if (result.getCode() == 20000) {
|
|
|
|
|
setUpdateTime(tn[0], DateUtil.formatDate(nowUpdateTime, "yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String fetchData(String url,Map<String,Object> params) {
|
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
.build();
|
|
|
|
@ -250,10 +275,9 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
dbDao.update(sql);
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*direction方向 U 上传,I 下发,往自助平台为上传,往UDI管理系统为下发*/
|
|
|
|
|
/****/
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse receive(String direction, HttpServletRequest request,
|
|
|
|
|
public BaseResponse receive(HttpServletRequest request,
|
|
|
|
|
String content,MultipartFile[] files) {
|
|
|
|
|
/*授权检查,后续完善*/
|
|
|
|
|
String apiKey = request.getHeader("apiKey");
|
|
|
|
@ -291,12 +315,12 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
saveUploadStatus(json.getString("messageType"),json.getString("messageId"),fileName);
|
|
|
|
|
/*解析入库*/
|
|
|
|
|
if (isLastLevel(direction)) {
|
|
|
|
|
if(isLastLevel()) {
|
|
|
|
|
analyToDB(json,files);
|
|
|
|
|
} else {
|
|
|
|
|
//需要转发
|
|
|
|
|
if (isRelay(direction)) {
|
|
|
|
|
relay(direction, request.getHeader("reqNo"), content, saveFiles);
|
|
|
|
|
if(isRelay()) {
|
|
|
|
|
relay(request.getHeader("reqNo"),content,saveFiles);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
@ -311,15 +335,9 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse send(String messageType,String tableName,Map<String,Object> params) {
|
|
|
|
|
try {
|
|
|
|
|
if (sendOnPage(messageType, tableName, params))
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
logger.error(ex.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.error(9999, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -338,6 +356,19 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveExportStatus(String messageType,String taskId,String fileName) {
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
map.put("id", CustomUtil.getId());
|
|
|
|
|
map.put("taskId", taskId);
|
|
|
|
|
map.put("cacheFilePath", fileName);
|
|
|
|
|
map.put("status", "0");
|
|
|
|
|
map.put("type", messageType);
|
|
|
|
|
map.put("updateTime", new Date());
|
|
|
|
|
Map<String,Object> columns = getColumn("basic_export_status");
|
|
|
|
|
String sql = "insert into basic_export_status "+DBAUtils.parseInsert(map, columns);
|
|
|
|
|
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
|
}
|
|
|
|
|
private void saveDownloadStatus(String messageType,String taskId,String remark) {
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
map.put("id", CustomUtil.getId());
|
|
|
|
@ -351,7 +382,6 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveIdcLog(String messageType,String taskId,String content,int offset,int total) {
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
map.put("id", CustomUtil.getId());
|
|
|
|
@ -368,29 +398,43 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean sendOnPage(String messageType, String tableName, Map<String, Object> params) {
|
|
|
|
|
|
|
|
|
|
private boolean syncMasterData(Map<String,Object> params,boolean isUplaod) {
|
|
|
|
|
boolean success=false;
|
|
|
|
|
String tableName = params.get("tableName").toString();
|
|
|
|
|
String tableKey = params.get("tableKey").toString();
|
|
|
|
|
String[] childs = {};
|
|
|
|
|
int childNum = -1;
|
|
|
|
|
for(String str:SYNC_TABLES) {
|
|
|
|
|
if(str.contains("/"+tableKey+"/")) {
|
|
|
|
|
childNum++;
|
|
|
|
|
childs[childNum] = str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Map<String,String> table = dbDao.getMysql(tableName);
|
|
|
|
|
if(!(table!=null&&table.get("tableName")!=null))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
String sql = "select count(*) from "+tableName;
|
|
|
|
|
Map<String,Object> column = getColumn(tableName);
|
|
|
|
|
|
|
|
|
|
Map<String,Object> whMap = new HashMap<String,Object>();
|
|
|
|
|
whMap.put("sqlWhere", params.get("sqlWhere"));
|
|
|
|
|
whMap.put("dataWhere", params.get("dataWhere"));
|
|
|
|
|
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
String where = DBAUtils.convertWhere(column, params, "");
|
|
|
|
|
String where = DBAUtils.convertWhere(column,whMap,"");
|
|
|
|
|
sql+=!StringUtils.isEmpty(where) ? " where "+where : "";
|
|
|
|
|
map.put("sql", sql);
|
|
|
|
|
int total = dbDao.count(map);
|
|
|
|
|
String direction = getDirection();
|
|
|
|
|
|
|
|
|
|
String isEnd = params.get("isEnd")!=null ? params.get("isEnd").toString() : "0";
|
|
|
|
|
int limit = 50;
|
|
|
|
|
String[] files = new String[limit];
|
|
|
|
|
String filePathColumn = params.get("filePathColumn")!=null ? params.get("filePathColumn").toString() : "";
|
|
|
|
|
orderNum++;
|
|
|
|
|
String messageType = params.get("messageType").toString();
|
|
|
|
|
saveIdcLog(messageType,"",tableName +">"+where,0,total);
|
|
|
|
|
if (tableName.equals("thr_order"))
|
|
|
|
|
logger.info("tableName-->" + tableName + "-->row-->" + total + "-->sqlWhere-->" + where);
|
|
|
|
|
|
|
|
|
|
if(total>0) {
|
|
|
|
|
success = true;
|
|
|
|
|
params.put("page", 0);
|
|
|
|
@ -414,10 +458,22 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
recordSql+=!StringUtils.isEmpty(recordSql) ? "," : "";
|
|
|
|
|
recordSql+="('"+UUID.randomUUID().toString().replaceAll("-", "")+"','"+tableName+"','"+list.get(m).get(keyColumn)+"','"+isEnd+"',now())";
|
|
|
|
|
if(childNum>-1&¶ms.get("masterLinkColumn")!=null&¶ms.get("subLinkColumn")!=null) {
|
|
|
|
|
for(int z=0;z<childNum+1;z++) {
|
|
|
|
|
String[] chidTnames = childs[z].split("/");
|
|
|
|
|
String keyValue = list.get(i).get(params.get("masterLinkColumn")).toString();
|
|
|
|
|
Map<String,Object> childMap = new HashMap<>();
|
|
|
|
|
childMap.put(params.get("subLinkColumn").toString(), keyValue);
|
|
|
|
|
List<Map<String,Object>> childList = getList(chidTnames[2],childMap);
|
|
|
|
|
list.get(m).put("tableName"+z, chidTnames[2]);
|
|
|
|
|
list.get(m).put("data"+z, childList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
orderNum++;
|
|
|
|
|
String result = relay(direction, "", JSON.toJSONString(data), files);
|
|
|
|
|
if(isUplaod) {
|
|
|
|
|
String result = relay("",JSON.toJSONString(data),files);
|
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
|
JSONObject json = JSON.parseObject(result);
|
|
|
|
|
if(json.getInteger("code")==20000) {
|
|
|
|
@ -432,14 +488,36 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
saveIdcLog(messageType,"",tableName +">"+result,i *limit,total);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
syncAddTask(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*增加同步任务*/
|
|
|
|
|
private void syncAddTask(Map<String,Object> json) {
|
|
|
|
|
String content = JSON.toJSONString(json);
|
|
|
|
|
String datePath = DateUtil.formatDate(new Date(),"yyyy-MM-dd");
|
|
|
|
|
|
|
|
|
|
FileUtils.makeDirectory(filePath +datePath+"/");
|
|
|
|
|
FileUtils.makeDirectory(backFilePath +datePath+"/");
|
|
|
|
|
String fileName = filePath +datePath+"/"+json.get("messageType")+"-"+json.get("messageId")+".udi";
|
|
|
|
|
String backFileName = backFilePath +datePath+"/"+json.get("messageType")+"-"+json.get("messageId")+".udi";
|
|
|
|
|
FileUtils.SaveFileAs(content, fileName);
|
|
|
|
|
FileUtils.SaveFileAs(content, backFileName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
saveExportStatus(json.get("messageType").toString(),json.get("messageId").toString(),fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*解析到数据库*/
|
|
|
|
|
private void analyToDB(JSONObject jsonObject,MultipartFile[] files) {
|
|
|
|
|
if(!StringUtils.isEmpty(jsonObject.getString("tableName"))) {
|
|
|
|
@ -539,6 +617,18 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
sql+=")";
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int m=0;m<6;m++) {
|
|
|
|
|
if(list.get(i).get("tableName"+m)!=null&&list.get(i).get("data"+m)!=null) {
|
|
|
|
|
Object obj = list.get(i).get("data"+m);
|
|
|
|
|
List<Map<String,Object>> chList = new ArrayList<Map<String,Object>>();
|
|
|
|
|
for (Object o : (List<?>) obj) {
|
|
|
|
|
chList.add((Map<String,Object>)o);
|
|
|
|
|
}
|
|
|
|
|
analyData(list.get(i).get("tableName"+m).toString(),chList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if(n>0)
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
@ -549,13 +639,13 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*转发下级或上级中继服务*/
|
|
|
|
|
private String relay(String direction, String reqNo, String content, String[] files) {
|
|
|
|
|
String host = getNextHost(direction);
|
|
|
|
|
private String relay(String reqNo,String content,String[] files) {
|
|
|
|
|
String host = getNextHost();
|
|
|
|
|
String result="";
|
|
|
|
|
if(StringUtils.isEmpty(reqNo))
|
|
|
|
|
reqNo = UUID.randomUUID().toString();
|
|
|
|
|
if(!StringUtils.isEmpty(host)) {
|
|
|
|
|
host += direction.equals("U") ? "/spssync/common/upload" : "/spssync/common/issued";
|
|
|
|
|
host+="/spssync/common/upload" ;
|
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
.connectTimeout(30, TimeUnit.SECONDS)//设置连接超时时间
|
|
|
|
|
.readTimeout(30, TimeUnit.SECONDS)//设置读取超时时间
|
|
|
|
@ -602,42 +692,38 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*获取转发服务地址,当前值允许单向,只使用参数upper_server_ip*/
|
|
|
|
|
private String getNextHost(String direction) {
|
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity =
|
|
|
|
|
direction.equals("U") ? getSystemParamConfig("upper_server_host", "自助平台数据接收服务地址", "", "接收由UDI系统上传的数据") :
|
|
|
|
|
direction.equals("I") ? getSystemParamConfig("lower_server_host", "UDI系统数据接收服务地址", "", "接收由自助平台下发的数据") : null;
|
|
|
|
|
private String getNextHost() {
|
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("upper_server_ip");
|
|
|
|
|
String host = systemParamConfigEntity!=null ? systemParamConfigEntity.getParamValue() : "";
|
|
|
|
|
host = !StringUtils.isEmpty(host)&&host.substring(host.length() -1).equals("/") ? host.substring(0,host.length() -1) : host;
|
|
|
|
|
return host;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*判断是否上传或下发数据*/
|
|
|
|
|
private boolean isLastLevel(String direction) {
|
|
|
|
|
return direction.equals("I") || direction.equals("U") ? true : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*检查当前系统为自助平台(下发)还是UDI系统(上传),返回传输方向,如果都未设置,默认返回下发*/
|
|
|
|
|
private String getDirection() {
|
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity = getSystemParamConfig("sync_system_type", "系统类型", "IDC", "UDI(UDI管理系统,由UDI系统往自助平台上传数据),SPS(自助平台,由自助平台往UDI系统下发数据),IDC(中继服务,只接收,转发或暂存数据供下一级服务拉取数据)");
|
|
|
|
|
return systemParamConfigEntity.getParamValue().equals("UDI") ? "U" : systemParamConfigEntity.getParamValue().equals("SPS") ? "I" : "N";
|
|
|
|
|
/*判断是否需要解析入库,中继服务只转发*/
|
|
|
|
|
private boolean isLastLevel() {
|
|
|
|
|
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")) ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*是否需要转发*/
|
|
|
|
|
private boolean isRelay(String direction) {
|
|
|
|
|
String relayHost = getNextHost(direction);
|
|
|
|
|
|
|
|
|
|
private boolean isRelay() {
|
|
|
|
|
String relayHost = getNextHost();
|
|
|
|
|
return !StringUtils.isEmpty(relayHost);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*由表名获取数据*/
|
|
|
|
|
private Map<String, Object> getData(String messageType, 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;
|
|
|
|
|
Map<String,Object> column = getColumn(tableName);
|
|
|
|
|
String where = DBAUtils.convertWhere(column,params,"");
|
|
|
|
|
sql+=!StringUtils.isEmpty(where) ? " where "+where : "";
|
|
|
|
|
params.put("sql", sql);
|
|
|
|
|
List<Map<String,Object>> list = dbDao.list(params);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
/*由表名获取数据*/
|
|
|
|
|
private Map<String,Object> getData(String messageType,String tableName,Map<String,Object> params) {
|
|
|
|
|
List<Map<String,Object>> list = getList(tableName,params);
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
map.put("messageId", UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
|
|
map.put("messageType", messageType);
|
|
|
|
@ -651,6 +737,8 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SystemParamConfigEntity getSystemParamConfig(String paramKey,String paramName,String defaultValue,String paramExplain) {
|
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey(paramKey);
|
|
|
|
|
if(systemParamConfigEntity==null||(systemParamConfigEntity!=null&&StringUtils.isEmpty(systemParamConfigEntity.getParamKey()))) {
|
|
|
|
@ -667,7 +755,6 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
System.out.print(JSON.toJSONString(systemParamConfigEntity)+"\n");
|
|
|
|
|
return systemParamConfigEntity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void writeFile(byte[] file, String filePath, String fileName) throws Exception {
|
|
|
|
|
File targetFile = new File(filePath);
|
|
|
|
|
if (!targetFile.exists()) {
|
|
|
|
@ -692,8 +779,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
for(int i=0;i<columnList.size();i++) {
|
|
|
|
|
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")?
|
|
|
|
|
"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();
|
|
|
|
|
if(map.get(attrName)==null) {
|
|
|
|
|
column.put("tableName", tname);
|
|
|
|
@ -729,7 +815,6 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
return updateTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String setUpdateTime(String id,String updateTime) {
|
|
|
|
|
String sql = "";
|
|
|
|
|
Map<String,Object> map = dbDao.get("select * from idc_status where id='"+id+"'");
|
|
|
|
@ -742,14 +827,19 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
return updateTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initTable() {
|
|
|
|
|
alterTable("idc_var","create table idc_var (code varchar(60),content varchar(200),PRIMARY KEY (code))");
|
|
|
|
|
alterTable("idc_status","create table idc_status (id varchar(36),statusTime datetime,PRIMARY KEY (id))");
|
|
|
|
|
alterTable("idc_record","create table idc_record (id varchar(36),type varchar(60),fkId varchar(36),isEnd char(1),createTime datetime,primary key (id),INDEX i_idc_record_fk_id (fkId),INDEX i_idc_record_create_time (createTime))");
|
|
|
|
|
alterTable("idc_log","create table idc_log (id varchar(36),orderNum int,taskId varchar(60),type varchar(60),content varchar(2000),offset int,total int,createTime datetime,PRIMARY KEY (id))");
|
|
|
|
|
dbDao.delete("delete from idc_record where createTime<date_sub(now(),interval 2 day) and isEnd='0'");
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
jdbcTemplate.execute("alter table basic_export_status add column cacheFilePath varchar(255)");
|
|
|
|
|
jdbcTemplate.execute("alter table basic_upload_status add column cacheFilePath varchar(255)");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void alterTable(String tableName,String sql) {
|
|
|
|
|
Map<String,String> map = dbDao.getMysql(tableName);
|
|
|
|
|
if(!(map!=null&&map.get("tableName")!=null)) {
|
|
|
|
@ -757,5 +847,4 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|