处理分片插入

main
钱涛 1 year ago
parent f95310163a
commit 13117c90b1

@ -10,6 +10,7 @@ import com.engine.salary.elog.util.ElogUtils;
import com.engine.salary.mapper.elog.LocalElogAopDaoMapper; import com.engine.salary.mapper.elog.LocalElogAopDaoMapper;
import com.engine.salary.elog.util.db.IdGenerator; import com.engine.salary.elog.util.db.IdGenerator;
import com.engine.salary.elog.util.db.MapperProxyFactory; import com.engine.salary.elog.util.db.MapperProxyFactory;
import com.google.common.collect.Lists;
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;
@ -166,9 +167,15 @@ public class LocalElogService implements ILocalElogService {
if (hasCustonInfo) { if (hasCustonInfo) {
getLocalElogAopDaoMapper().insertElogDetailPreparedHasCustonInfo(detailTableName, detailContexts, context.getUuid(), cusColumns); List<List<LoggerDetailContext>> partition = Lists.partition(detailContexts, 50);
for (int i = 0; i < partition.size(); i++) {
getLocalElogAopDaoMapper().insertElogDetailPreparedHasCustonInfo(detailTableName, partition.get(i), context.getUuid(), cusColumns);
}
} else { } else {
getLocalElogAopDaoMapper().insertElogDetailPrepared(detailTableName, detailContexts, context.getUuid()); List<List<LoggerDetailContext>> partition = Lists.partition(detailContexts, 50);
partition.forEach(part -> {
getLocalElogAopDaoMapper().insertElogDetailPrepared(detailTableName, part, context.getUuid());
});
} }
} }

@ -86,8 +86,9 @@ public class LoggerTemplate {
*/ */
public void write(LoggerContext context, boolean isLocal) { public void write(LoggerContext context, boolean isLocal) {
String elogLocalQueue = ELOG + this.applicationName; String elogLocalQueue = ELOG + this.applicationName;
if (StringUtils.isEmpty(this.localQueue)) if (StringUtils.isEmpty(this.localQueue)) {
this.localQueue = (StringUtils.isNotEmpty(this.moduleName) ? this.moduleName : elogLocalQueue) + "LocalQueue" + this.publishkitGroup; this.localQueue = (StringUtils.isNotEmpty(this.moduleName) ? this.moduleName : elogLocalQueue) + "LocalQueue" + this.publishkitGroup;
}
try { try {
handleContext(context); handleContext(context);
} catch (Exception e) { } catch (Exception e) {
@ -230,12 +231,15 @@ public class LoggerTemplate {
// } // }
private void handleContext(LoggerContext context) { private void handleContext(LoggerContext context) {
if (StringUtils.isEmpty(context.getModuleName())) if (StringUtils.isEmpty(context.getModuleName())) {
context.setModuleName(module); context.setModuleName(module);
if (StringUtils.isEmpty(context.getFunctionName())) }
if (StringUtils.isEmpty(context.getFunctionName())) {
context.setFunctionName(function); context.setFunctionName(function);
if (!(context.getId() > 0)) }
if (!(context.getId() > 0)) {
context.setId(IdGenerator.generate()); context.setId(IdGenerator.generate());
}
if (StringUtils.isEmpty(context.getUuid())) { if (StringUtils.isEmpty(context.getUuid())) {
context.setUuid(UUID.randomUUID().toString().replace("-", "")); context.setUuid(UUID.randomUUID().toString().replace("-", ""));
} }
@ -278,7 +282,7 @@ public class LoggerTemplate {
List<LoggerDetailContext> valueChangeList = new ArrayList<>(); List<LoggerDetailContext> valueChangeList = new ArrayList<>();
int showOrder = 0; int showOrder = 0;
if (changeBeans != null) if (changeBeans != null) {
for (TableChangeBean changeBean : changeBeans) { for (TableChangeBean changeBean : changeBeans) {
if (changeBean != null && (changeBean.getNewValue() != null || changeBean.getOldValue() != null)) { if (changeBean != null && (changeBean.getNewValue() != null || changeBean.getOldValue() != null)) {
String uuid = UUID.randomUUID().toString().replace("-", ""); String uuid = UUID.randomUUID().toString().replace("-", "");
@ -340,7 +344,7 @@ public class LoggerTemplate {
valueChangeBean.setNewValue(newJo.getString(field.getName())); valueChangeBean.setNewValue(newJo.getString(field.getName()));
valueChangeBean.setOldValue(oldJo.getString(field.getName())); valueChangeBean.setOldValue(oldJo.getString(field.getName()));
valueChangeBean.setCreator(-1l); valueChangeBean.setCreator(-1L);
try { try {
extracted(newJo, oldJo, field, fieldElogTransform, valueChangeBean); extracted(newJo, oldJo, field, fieldElogTransform, valueChangeBean);
} catch (Exception e) { } catch (Exception e) {
@ -371,12 +375,13 @@ public class LoggerTemplate {
valueChangeBean.setNewValue(newJo.getString(key)); valueChangeBean.setNewValue(newJo.getString(key));
valueChangeBean.setOldValue(oldJo.getString(key)); valueChangeBean.setOldValue(oldJo.getString(key));
valueChangeBean.setShoworder(showOrder++); valueChangeBean.setShoworder(showOrder++);
valueChangeBean.setCreator(-1l); valueChangeBean.setCreator(-1L);
valueChangeList.add(valueChangeBean); valueChangeList.add(valueChangeBean);
} }
for (String key : (Set<String>) oldJo.keySet()) { for (String key : (Set<String>) oldJo.keySet()) {
if (keys.contains(key)) if (keys.contains(key)) {
continue; continue;
}
keys.add(key); keys.add(key);
if (oldJo.getString(key).equals(newJo.getString(key))) { if (oldJo.getString(key).equals(newJo.getString(key))) {
continue; continue;
@ -389,15 +394,17 @@ public class LoggerTemplate {
valueChangeBean.setNewValue(newJo.getString(key)); valueChangeBean.setNewValue(newJo.getString(key));
valueChangeBean.setOldValue(oldJo.getString(key)); valueChangeBean.setOldValue(oldJo.getString(key));
valueChangeBean.setShoworder(showOrder++); valueChangeBean.setShoworder(showOrder++);
valueChangeBean.setCreator(-1l); valueChangeBean.setCreator(-1L);
valueChangeList.add(valueChangeBean); valueChangeList.add(valueChangeBean);
} }
} }
} }
} }
}
if (valueChangeList.size() > 0) if (valueChangeList.size() > 0) {
context.setDetailContexts(valueChangeList); context.setDetailContexts(valueChangeList);
}
} }
@ -455,7 +462,7 @@ public class LoggerTemplate {
valueChangeBean.setFieldName(allField.getName()); valueChangeBean.setFieldName(allField.getName());
valueChangeBean.setNewValue(newValue.getString(allField.getName())); valueChangeBean.setNewValue(newValue.getString(allField.getName()));
valueChangeBean.setOldValue(oldValue.getString(allField.getName())); valueChangeBean.setOldValue(oldValue.getString(allField.getName()));
valueChangeBean.setCreator(-1l); valueChangeBean.setCreator(-1L);
valueChangeBean.setBelongDataid(""); valueChangeBean.setBelongDataid("");
valueChangeBean.setDataid(String.valueOf(dataid)); valueChangeBean.setDataid(String.valueOf(dataid));

Loading…
Cancel
Save