提交人:陈绍鑫

日期:2025/6/16 17:30
内容:操作冷却优化
This commit is contained in:
陈绍鑫 2025-06-16 17:38:29 +08:00
parent 78b5d1c91b
commit 21b6a01732
2 changed files with 50 additions and 47 deletions

View File

@ -10,13 +10,11 @@ import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.entity.plugin.args.BeforeOperationArgs; import kd.bos.entity.plugin.args.BeforeOperationArgs;
import kd.bos.entity.plugin.args.BeginOperationTransactionArgs; import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
import kd.bos.entity.plugin.args.ReturnOperationArgs; import kd.bos.entity.plugin.args.ReturnOperationArgs;
import kd.bos.entity.validate.AbstractValidator; import kd.bos.entity.validate.*;
import kd.bos.entity.validate.ValidatePriority;
import kd.bos.entity.validate.ValidateResult;
import kd.bos.entity.validate.ValidateResultCollection;
import kd.bos.logging.Log; import kd.bos.logging.Log;
import kd.bos.logging.LogFactory; import kd.bos.logging.LogFactory;
import kd.sdk.plugin.Plugin; import kd.sdk.plugin.Plugin;
import shkd.sys.sys.plugin.list.ElectronicPayDealListPlugin;
import shkd.sys.sys.plugin.operation.domain.TimeValidator; import shkd.sys.sys.plugin.operation.domain.TimeValidator;
import java.time.Duration; import java.time.Duration;
@ -33,14 +31,14 @@ public class ElectronicPayDealOPPlugin extends AbstractOperationServicePlugIn im
@Override @Override
public void onPreparePropertys(PreparePropertysEventArgs e) { public void onPreparePropertys(PreparePropertysEventArgs e) {
super.onPreparePropertys(e); super.onPreparePropertys(e);
Iterator<Map.Entry<Long, LocalDateTime>> iterator = timemap.entrySet().iterator(); // Iterator<Map.Entry<Long, LocalDateTime>> iterator = timemap.entrySet().iterator();
while (iterator.hasNext()) { // while (iterator.hasNext()) {
Map.Entry<Long, LocalDateTime> entry = iterator.next(); // Map.Entry<Long, LocalDateTime> entry = iterator.next();
Duration duration = Duration.between(entry.getValue(), LocalDateTime.now()); // Duration duration = Duration.between(entry.getValue(), LocalDateTime.now());
if (duration.getSeconds() > 10) { // if (duration.getSeconds() > 10) {
iterator.remove(); // iterator.remove();
} // }
} // }
} }
@Override @Override
@ -78,25 +76,25 @@ public class ElectronicPayDealOPPlugin extends AbstractOperationServicePlugIn im
@Override @Override
public void onReturnOperation(ReturnOperationArgs e) { public void onReturnOperation(ReturnOperationArgs e) {
List<Object> overtime = new ArrayList<>();//存放因连续点击而校验失败的数据 // List<Object> overtime = new ArrayList<>();//存放因连续点击而校验失败的数据
super.onReturnOperation(e); // super.onReturnOperation(e);
ValidateResultCollection validateResult = this.operationResult.getValidateResult(); // ValidateResultCollection validateResult = this.operationResult.getValidateResult();
List<ValidateResult> validateErrors = validateResult.getValidateErrors(); // List<ValidateResult> validateErrors = validateResult.getValidateErrors();
for (ValidateResult validateError : validateErrors) { // for (ValidateResult validateError : validateErrors) {
List<OperateErrorInfo> allErrorInfo = validateError.getAllErrorInfo(); // List<OperateErrorInfo> allErrorInfo = validateError.getAllErrorInfo();
for (OperateErrorInfo operateErrorInfo : allErrorInfo) { // for (OperateErrorInfo operateErrorInfo : allErrorInfo) {
String message = operateErrorInfo.getMessage(); // String message = operateErrorInfo.getMessage();
if (message.contains("当前单据已更新操作结果,请十秒后再更新")){ // if (message.contains("当前单据已更新操作结果,请十秒后再更新")){
overtime.add(operateErrorInfo.getPkValue()); // overtime.add(operateErrorInfo.getPkValue());
} // }
} // }
} // }
List<Object> successPkIds = e.getOperationResult().getSuccessPkIds();//执行成功的数据 // List<Object> successPkIds = e.getOperationResult().getSuccessPkIds();//执行成功的数据
Map<Object, String> billNos = ((OperationResult) e.getOperationResult()).getBillNos(); // Map<Object, String> billNos = ((OperationResult) e.getOperationResult()).getBillNos();//用于存放要去除的数据
billNos.keySet().removeAll(successPkIds); // billNos.keySet().removeAll(successPkIds);
billNos.keySet().removeAll(overtime); // billNos.keySet().removeAll(overtime);
for (Object key : billNos.keySet()) { // for (Object key : billNos.keySet()) {
timemap.remove(key); // timemap.remove(key);
} // }
} }
} }

View File

@ -20,21 +20,26 @@ public class TimeValidator extends AbstractValidator {
for(ExtendedDataEntity obj :dataEntities){ for(ExtendedDataEntity obj :dataEntities){
DynamicObject bill = obj.getDataEntity();//获取当前单据的数据包 DynamicObject bill = obj.getDataEntity();//获取当前单据的数据包
Long id = bill.getLong("id");//进一步获取编码字段 Long id = bill.getLong("id");//进一步获取编码字段
Map<Long, LocalDateTime> timemap = ElectronicPayDealOPPlugin.timemap; // Map<Long, LocalDateTime> timemap = ElectronicPayDealOPPlugin.timemap;
LocalDateTime localDateTime = timemap.get(id); // LocalDateTime localDateTime = timemap.get(id);
LocalDateTime currentTime = LocalDateTime.now(); // LocalDateTime currentTime = LocalDateTime.now();
if (localDateTime!=null){ // if (localDateTime!=null){
//
Duration duration = Duration.between(localDateTime, currentTime); // Duration duration = Duration.between(localDateTime, currentTime);
// 判断时间差是否超过 10 // // 判断时间差是否超过 10
if (duration.getSeconds() <= 10) { // if (duration.getSeconds() <= 10) {
this.addMessage(obj,"当前单据已更新操作结果,请十秒后再更新", ErrorLevel.Error);//错误消息 // this.addMessage(obj,"当前单据已更新操作结果,请十秒后再更新", ErrorLevel.Error);//错误消息
timemap.put(id,localDateTime); // timemap.put(id,localDateTime);
}else { // }else {
timemap.put(id,currentTime); // timemap.put(id,currentTime);
} // }
}else { // }else {
timemap.put(id,currentTime); // timemap.put(id,currentTime);
// }
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(id, obj.getDataEntity().getDataEntityType().getName());
boolean shkd_lock = dynamicObject.getBoolean("shkd_lock");
if (shkd_lock){
this.addMessage(obj,"当前单据已锁定", ErrorLevel.Error);//错误消息
} }
} }