SYNC_TABLS由TableUtils.syncTables()获取

master
chengqf 2 years ago
parent f4e17649c5
commit 78ae9d9806

@ -40,6 +40,7 @@ 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.idc.utils.TableUtils;
import com.glxp.api.req.system.ScheduledRequest;
import com.glxp.api.service.system.SystemParamConfigService;
import com.glxp.api.util.CustomUtil;
@ -54,7 +55,6 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
/*数据中继数据中心(接收)*/
@Slf4j
@Service
@ -70,25 +70,7 @@ public class IdcServiceImpl implements IdcService {
@Value("${API_SECRET}")
private String apiSecret;
/*同步表,格式:同步设置表列名/同步设置表列名(子表时设置,主表不设置)/主表唯一列(多列逗号分隔)/主表关联列/子表关联列/数据库实际表/时间列/图片或文件列/数据条件/说明*/
private final String[] SYNC_TABLES= {
"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///供应商关联信息",
"basicCorp//basic_corp/id///updateTime///往来单位","typeThird//thr_bustype_origin/id///updateTime///第三方单据类型",
"basicThirdCorp//thr_corp/id///updateTime///第三方往来单位","//thr_dept/id///updateTime///第三方部门",
"//thr_inv_products/id///updateTime///第三方库存","basicThirdInv//thr_inv_warehouse/id//////第三方仓库",
"basicThirdBusOrder//thr_order/id///updateTime///第三方业务单据","/basicThirdBusOrder/thr_order_detail/orderIdFk/id/orderIdFk/updateTime///第三方单据详情",
"basicThirdProducts//thr_products/id///updateTime///第三方产品信息",
"//sup_cert_set/id///updateTime///供应商资质证书设置","companyCert//sup_company/customerId///updateTime///配送企业",
"manufacturerCert//sup_manufacturer/id///updateTime///生产企业","productCert//sup_product/id///updateTime///产品资质信息",
"/companyCert/sup_cert/id/customerId/customerId/updateTime/filePath/type=1/配送企业资质证书信息",
"/manufacturerCert/sup_cert/id/manufacturerId/manufacturerIdFk/updateTime/filePath/type=2/生产企业资质证书信息",
"/productCert/sup_cert/id/productId/productIdFk/updateTime/filePath/type=3/产品资质证书信息",
"//udicompany/id///updateTime///国际库医疗器械注册人信息"};
//"dbDiProducts//productinfo/id///updateTime///DI产品信息",
//"basicInv/////////仓库字典",
//"typeBus/////////业务单据类型",
//"typeScan/////////扫码单据类型",
private int orderNum = 0;
@Resource
@ -137,7 +119,7 @@ public class IdcServiceImpl implements IdcService {
BaseResponse response = JSON.parseObject(json, BaseResponse.class);
return response;
}
logger.info("json-->" + json);
return ResultVOUtils.success(object);
}
@ -148,6 +130,7 @@ public class IdcServiceImpl implements IdcService {
logger.info("UDI管理系统同步任务开始--------");
asyncDataTask(true);
}
/*自助平台生成任务,不上传*/
@Override
public void asyncSpsTask() {
@ -161,6 +144,7 @@ public class IdcServiceImpl implements IdcService {
public void asyncFetchUdiTask() {
fetchTask(false);
}
@Async
@Override
public void asyncFetchTask() {
@ -222,14 +206,15 @@ public class IdcServiceImpl implements IdcService {
return;
}
}
for(int i=0;i<SYNC_TABLES.length;i++) {
String[] tnames = SYNC_TABLES[i].split("/");
String[] syncTables = TableUtils.syncTables();
for (int i = 0; i < syncTables.length; i++) {
String[] tnames = syncTables[i].split("/");
boolean sync = StringUtils.isEmpty(tnames[0]) ||
(!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]) + syncTables[i], 0, 0);
if (sync) {
String syncIp = map.get("syncIp") != null ? map.get("syncIp").toString() : "";
syncData(SYNC_TABLES[i],isUpload,syncIp);
syncData(syncTables[i], isUpload, syncIp);
}
}
}
@ -284,7 +269,6 @@ public class IdcServiceImpl implements IdcService {
}
private String fetchData(String host, Map<String, Object> params) {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
@ -363,6 +347,7 @@ public class IdcServiceImpl implements IdcService {
dbDao.update(sql);
return ResultVOUtils.success();
}
/****/
@Override
public BaseResponse receive(HttpServletRequest request,
@ -445,6 +430,7 @@ public class IdcServiceImpl implements IdcService {
}
@Override
public BaseResponse send(String messageType, String tableName, Map<String, Object> params) {
@ -492,6 +478,7 @@ public class IdcServiceImpl implements IdcService {
dbDao.save(sql);
}
private void saveDownloadStatus(Map<String, Object> params) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("receiveStatus", "0");
@ -502,6 +489,7 @@ 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());
@ -526,7 +514,8 @@ public class IdcServiceImpl implements IdcService {
String[] childs = new String[30];
int childNum = -1;
/*子表*/
for(String str:SYNC_TABLES) {
String[] syncTables = TableUtils.syncTables();
for (String str : syncTables) {
if (str.contains("/" + tableKey + "/")) {
childNum++;
childs[childNum] = str;
@ -661,8 +650,7 @@ public class IdcServiceImpl implements IdcService {
/*增加同步任务状态*/
private void syncAddTaskStatus(Map<String, Object> json, int scheduleType, boolean success, Date startTime, boolean isEnd) {
try
{
try {
String content = JSON.toJSONString(json);
String datePath = DateUtil.formatDate(new Date(), "yyyy-MM-dd");
String fileName = filePath + datePath + "/" + json.get("messageType") + "-" + json.get("messageId") + ".udi";
@ -968,9 +956,11 @@ public class IdcServiceImpl implements IdcService {
}
return success;
}
private boolean signleDownloadFile(String syncIp, String fileName) {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();;
.build();
;
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "fileName=" + fileName);
@ -1003,7 +993,6 @@ public class IdcServiceImpl implements IdcService {
outputStream.flush();
} catch (Exception e) {
@ -1051,6 +1040,7 @@ public class IdcServiceImpl implements IdcService {
List<Map<String, Object>> list = dbDao.list(map);
return list;
}
/*由表名获取数据*/
private Map<String, Object> getData(String messageType, String tableName, Map<String, Object> params, Map<String, Object> whereParams) {
List<Map<String, Object>> list = getList(tableName, whereParams);
@ -1069,8 +1059,6 @@ 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()))) {
@ -1086,6 +1074,7 @@ public class IdcServiceImpl implements IdcService {
}
return systemParamConfigEntity;
}
private void writeFile(byte[] file, String filePath, String fileName) throws Exception {
File targetFile = new File(filePath);
if (!targetFile.exists()) {
@ -1110,7 +1099,8 @@ 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);
@ -1150,6 +1140,7 @@ 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 + "'");
@ -1162,6 +1153,7 @@ 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(100),statusTime datetime,PRIMARY KEY (id))");
@ -1177,6 +1169,7 @@ public class IdcServiceImpl implements IdcService {
}
}
private void alterTable(String tableName, String sql) {
Map<String, String> map = dbDao.getMysql(tableName);
if (!(map != null && map.get("tableName") != null)) {

Loading…
Cancel
Save