|
|
@ -1,5 +1,6 @@
|
|
|
|
package cn.estsh.i3plus.ext.mes.apiservice.dbinterface;
|
|
|
|
package cn.estsh.i3plus.ext.mes.apiservice.dbinterface;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
|
|
|
|
import cn.estsh.i3plus.mes.apiservice.serviceimpl.engine.script.EngineScriptManager;
|
|
|
|
import cn.estsh.i3plus.mes.apiservice.serviceimpl.engine.script.EngineScriptManager;
|
|
|
|
import cn.estsh.i3plus.mes.apiservice.util.datatable.DataRow;
|
|
|
|
import cn.estsh.i3plus.mes.apiservice.util.datatable.DataRow;
|
|
|
|
import cn.estsh.i3plus.mes.apiservice.util.datatable.DataSet;
|
|
|
|
import cn.estsh.i3plus.mes.apiservice.util.datatable.DataSet;
|
|
|
@ -8,17 +9,16 @@ import cn.estsh.i3plus.platform.plugin.datasource.DynamicDataSourceProxy;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.base.util.StringUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.base.util.StringUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.wms.dbinterface.UpdateSyncItem;
|
|
|
|
import cn.estsh.i3plus.pojo.wms.dbinterface.UpdateSyncItem;
|
|
|
|
import cn.estsh.i3plus.pojo.wms.dbinterface.WmsInterfaceEnumUtil;
|
|
|
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
|
|
|
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
import lombok.Setter;
|
|
|
|
import lombok.Setter;
|
|
|
|
|
|
|
|
import org.apache.commons.lang.exception.ExceptionUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.Connection;
|
|
|
@ -85,29 +85,15 @@ public class WmsSAPDbWriter extends WmsSAPDbSyncBase {
|
|
|
|
saveDestData(destDataSet);
|
|
|
|
saveDestData(destDataSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
//记录sap过来的数据 超过一定的请求次数放弃数据
|
|
|
|
LOGGER.info(ExceptionUtils.getStackTrace(e));
|
|
|
|
if (WmsInterfaceEnumUtil.DIRECTION_TYPE.SAP2WMS.getName().equals(this.dataMapper.getGroupName())) {
|
|
|
|
return;
|
|
|
|
if (!CollectionUtils.isEmpty(srcDataList)) {
|
|
|
|
} finally {
|
|
|
|
String key = this.dataMapper.getSoftAdaptorCode() + ":" + srcDataList.get(0).get("SID");
|
|
|
|
//同步失败,更新同步状态为同步失败
|
|
|
|
if (redisMes.hasKey(key)) {
|
|
|
|
if (this.dataMapper.getUseScriptMark() == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) {
|
|
|
|
int reqCount = Integer.parseInt(String.valueOf(redisMes.getObject(key)));
|
|
|
|
callScriptMark(srcDataList, originDataList);
|
|
|
|
if (reqCount + 1 > REQ_COUNT) {
|
|
|
|
} else {
|
|
|
|
if (this.dataMapper.getUseScriptMark() == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) {
|
|
|
|
callSqlMark(srcDataList, originDataList, false);
|
|
|
|
callScriptMark(srcDataList, originDataList);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
callSqlMark(srcDataList, originDataList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGGER.error("超过请求次数放弃数据 WmsSAPDbWriter.saveData SoftAdaptorCode:{}, SID:{}", this.dataMapper.getSoftAdaptorCode(), srcDataList.get(0).get("SID"));
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
redisMes.incr(key, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
redisMes.incr(key, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 再更新来源数据的同步标志
|
|
|
|
// 再更新来源数据的同步标志
|
|
|
@ -115,7 +101,7 @@ public class WmsSAPDbWriter extends WmsSAPDbSyncBase {
|
|
|
|
if (this.dataMapper.getUseScriptMark() == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) {
|
|
|
|
if (this.dataMapper.getUseScriptMark() == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) {
|
|
|
|
callScriptMark(srcDataList, originDataList);
|
|
|
|
callScriptMark(srcDataList, originDataList);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
callSqlMark(srcDataList, originDataList);
|
|
|
|
callSqlMark(srcDataList, originDataList,true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -125,12 +111,12 @@ public class WmsSAPDbWriter extends WmsSAPDbSyncBase {
|
|
|
|
* @param originDataList 原始查询到的数据集
|
|
|
|
* @param originDataList 原始查询到的数据集
|
|
|
|
* @throws Exception
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void callSqlMark(List<Map<String, Object>> srcDataList, List<Map<String, Object>> originDataList)
|
|
|
|
private void callSqlMark(List<Map<String, Object>> srcDataList, List<Map<String, Object>> originDataList,boolean isSuccess)
|
|
|
|
throws Exception {
|
|
|
|
throws Exception {
|
|
|
|
if (originDataList != null) {
|
|
|
|
if (originDataList != null) {
|
|
|
|
saveSrcData(originDataList);
|
|
|
|
saveSrcData(originDataList,isSuccess);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
saveSrcData(srcDataList);
|
|
|
|
saveSrcData(srcDataList,isSuccess);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -243,7 +229,7 @@ public class WmsSAPDbWriter extends WmsSAPDbSyncBase {
|
|
|
|
* @param srcDataList
|
|
|
|
* @param srcDataList
|
|
|
|
* @throws Exception
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void saveSrcData(List<Map<String, Object>> srcDataList) throws Exception {
|
|
|
|
private void saveSrcData(List<Map<String, Object>> srcDataList,boolean isSuccess) throws Exception {
|
|
|
|
if (srcDataList == null || srcDataList.size() == 0) {
|
|
|
|
if (srcDataList == null || srcDataList.size() == 0) {
|
|
|
|
LOGGER.error("no data in src datalist!");
|
|
|
|
LOGGER.error("no data in src datalist!");
|
|
|
|
throw new IllegalArgumentException("no data in src datalist!");
|
|
|
|
throw new IllegalArgumentException("no data in src datalist!");
|
|
|
@ -275,7 +261,7 @@ public class WmsSAPDbWriter extends WmsSAPDbSyncBase {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 把来源表的数据行放到表达式中,确保表达式可以引用
|
|
|
|
// 把来源表的数据行放到表达式中,确保表达式可以引用
|
|
|
|
HashMap<String, Object> updateValueMap = getUpdateSyncMap(srcRow);
|
|
|
|
HashMap<String, Object> updateValueMap = getUpdateSyncMap(srcRow,isSuccess);
|
|
|
|
// 存在来源表不需要更新同步标志的情况
|
|
|
|
// 存在来源表不需要更新同步标志的情况
|
|
|
|
if (updateValueMap.size() > 0) {
|
|
|
|
if (updateValueMap.size() > 0) {
|
|
|
|
// 拼接更新来源表同步标志的 SQL LIST
|
|
|
|
// 拼接更新来源表同步标志的 SQL LIST
|
|
|
@ -345,7 +331,7 @@ public class WmsSAPDbWriter extends WmsSAPDbSyncBase {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private HashMap<String, Object> getUpdateSyncMap(Map<String, Object> srcRow) throws Exception {
|
|
|
|
private HashMap<String, Object> getUpdateSyncMap(Map<String, Object> srcRow,boolean isSuccess) throws Exception {
|
|
|
|
HashMap<String, Object> updateSyncMap = new HashMap<>();
|
|
|
|
HashMap<String, Object> updateSyncMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
if (this.getSrcUpdateSync() == null) {
|
|
|
|
if (this.getSrcUpdateSync() == null) {
|
|
|
@ -354,9 +340,12 @@ public class WmsSAPDbWriter extends WmsSAPDbSyncBase {
|
|
|
|
|
|
|
|
|
|
|
|
for (UpdateSyncItem item : this.getSrcUpdateSync()) {
|
|
|
|
for (UpdateSyncItem item : this.getSrcUpdateSync()) {
|
|
|
|
Object updateValue = item.getUpdateValue();
|
|
|
|
Object updateValue = item.getUpdateValue();
|
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(item.getUpdateValue()) && item.getUpdateValue().contains(MesExtConstWords.COLON)){
|
|
|
|
|
|
|
|
updateValue = isSuccess ? item.getUpdateValue().split(MesExtConstWords.COLON)[0]:item.getUpdateValue().split(MesExtConstWords.COLON)[1];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果包含表达式,则计算后赋值
|
|
|
|
// 如果包含表达式,则计算后赋值
|
|
|
|
if (item.getUpdateValue().indexOf("#") != -1) {
|
|
|
|
if (item.getUpdateValue().contains("#")) {
|
|
|
|
updateValue = wmsSAPDbExpression.parse(item.getUpdateValue(), srcRow);
|
|
|
|
updateValue = wmsSAPDbExpression.parse(item.getUpdateValue(), srcRow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|