parent
69a40551c8
commit
6c60bffed8
|
@ -0,0 +1,102 @@
|
||||||
|
package shkd.sys.sys.plugin.operation;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.entity.operate.result.OperateErrorInfo;
|
||||||
|
import kd.bos.entity.operate.result.OperationResult;
|
||||||
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||||
|
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||||||
|
import kd.bos.entity.plugin.PreparePropertysEventArgs;
|
||||||
|
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
||||||
|
import kd.bos.entity.plugin.args.BeforeOperationArgs;
|
||||||
|
import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
|
||||||
|
import kd.bos.entity.plugin.args.ReturnOperationArgs;
|
||||||
|
import kd.bos.entity.validate.AbstractValidator;
|
||||||
|
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.LogFactory;
|
||||||
|
import kd.sdk.plugin.Plugin;
|
||||||
|
import shkd.sys.sys.plugin.operation.domain.TimeValidator;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class ElectronicPayDealOPPlugin extends AbstractOperationServicePlugIn implements Plugin {
|
||||||
|
|
||||||
|
private static final Log logger = LogFactory.getLog(ElectronicPayDealOPPlugin.class);
|
||||||
|
|
||||||
|
|
||||||
|
public static Map<Long, LocalDateTime> timemap=new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||||||
|
super.onPreparePropertys(e);
|
||||||
|
Iterator<Map.Entry<Long, LocalDateTime>> iterator = timemap.entrySet().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Map.Entry<Long, LocalDateTime> entry = iterator.next();
|
||||||
|
Duration duration = Duration.between(entry.getValue(), LocalDateTime.now());
|
||||||
|
if (duration.getSeconds() > 10) {
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
|
||||||
|
super.beforeExecuteOperationTransaction(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAddValidators(AddValidatorsEventArgs e) {
|
||||||
|
super.onAddValidators(e);
|
||||||
|
e.addValidator(new TimeValidator());
|
||||||
|
List<AbstractValidator> validators = e.getValidators();
|
||||||
|
for (AbstractValidator validator : validators) {
|
||||||
|
if (validator instanceof TimeValidator) {
|
||||||
|
// 是你的类或者子类
|
||||||
|
validator.setValidatePriority(ValidatePriority.First);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beginOperationTransaction(BeginOperationTransactionArgs e) {
|
||||||
|
super.beginOperationTransaction(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initializeOperationResult(OperationResult result) {
|
||||||
|
super.initializeOperationResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
||||||
|
super.afterExecuteOperationTransaction(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReturnOperation(ReturnOperationArgs e) {
|
||||||
|
List<Object> overtime = new ArrayList<>();//存放因连续点击而校验失败的数据
|
||||||
|
super.onReturnOperation(e);
|
||||||
|
ValidateResultCollection validateResult = this.operationResult.getValidateResult();
|
||||||
|
List<ValidateResult> validateErrors = validateResult.getValidateErrors();
|
||||||
|
for (ValidateResult validateError : validateErrors) {
|
||||||
|
List<OperateErrorInfo> allErrorInfo = validateError.getAllErrorInfo();
|
||||||
|
for (OperateErrorInfo operateErrorInfo : allErrorInfo) {
|
||||||
|
String message = operateErrorInfo.getMessage();
|
||||||
|
if (message.contains("当前单据已更新操作结果,请十秒后再更新")){
|
||||||
|
overtime.add(operateErrorInfo.getPkValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<Object> successPkIds = e.getOperationResult().getSuccessPkIds();//执行成功的数据
|
||||||
|
Map<Object, String> billNos = ((OperationResult) e.getOperationResult()).getBillNos();
|
||||||
|
billNos.keySet().removeAll(successPkIds);
|
||||||
|
billNos.keySet().removeAll(overtime);
|
||||||
|
for (Object key : billNos.keySet()) {
|
||||||
|
timemap.remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package shkd.sys.sys.plugin.operation.domain;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.entity.ExtendedDataEntity;
|
||||||
|
import kd.bos.entity.validate.AbstractValidator;
|
||||||
|
import kd.bos.entity.validate.ErrorLevel;
|
||||||
|
import shkd.sys.sys.plugin.operation.ElectronicPayDealOPPlugin;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TimeValidator extends AbstractValidator {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() {
|
||||||
|
ExtendedDataEntity[] dataEntities = this.getDataEntities();//获取操作执行时的所有单据数据的集合
|
||||||
|
for(ExtendedDataEntity obj :dataEntities){
|
||||||
|
DynamicObject bill = obj.getDataEntity();//获取当前单据的数据包
|
||||||
|
Long id = bill.getLong("id");//进一步获取编码字段
|
||||||
|
Map<Long, LocalDateTime> timemap = ElectronicPayDealOPPlugin.timemap;
|
||||||
|
LocalDateTime localDateTime = timemap.get(id);
|
||||||
|
LocalDateTime currentTime = LocalDateTime.now();
|
||||||
|
if (localDateTime!=null){
|
||||||
|
|
||||||
|
Duration duration = Duration.between(localDateTime, currentTime);
|
||||||
|
// 判断时间差是否超过 10 秒
|
||||||
|
if (duration.getSeconds() <= 10) {
|
||||||
|
this.addMessage(obj,"当前单据已更新操作结果,请十秒后再更新", ErrorLevel.Error);//错误消息
|
||||||
|
}
|
||||||
|
}
|
||||||
|
timemap.put(id,currentTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue