异地退货明细及校验
This commit is contained in:
parent
a54727f3bf
commit
d5add1ec4e
|
|
@ -4,13 +4,11 @@ import kd.bos.bill.AbstractBillPlugIn;
|
|||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.entity.datamodel.events.AfterAddRowEventArgs;
|
||||
import kd.bos.entity.datamodel.events.BeforeAddRowEventArgs;
|
||||
import kd.bos.entity.datamodel.events.ChangeData;
|
||||
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
||||
import kd.bos.form.control.EntryGrid;
|
||||
import kd.bos.form.events.AfterDoOperationEventArgs;
|
||||
import kd.bos.form.events.BeforeDoOperationEventArgs;
|
||||
import kd.bos.form.events.ClosedCallBackEvent;
|
||||
import kd.bos.form.field.BasedataEdit;
|
||||
import kd.bos.form.field.events.BeforeF7SelectEvent;
|
||||
import kd.bos.form.field.events.BeforeF7SelectListener;
|
||||
|
|
@ -39,16 +37,6 @@ public class PurRefundApplyFormPlugin extends AbstractBillPlugIn implements Befo
|
|||
tqq9_thck_ydth.addBeforeF7SelectListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
|
||||
super.closedCallBack(closedCallBackEvent);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 异地退货返回事件
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
|
||||
|
|
@ -56,7 +44,17 @@ public class PurRefundApplyFormPlugin extends AbstractBillPlugIn implements Befo
|
|||
FormOperate operate = (FormOperate) args.getSource();
|
||||
String operateKey = operate.getOperateKey();
|
||||
if ("tqq9_newentry_ydth".equals(operateKey)) {
|
||||
int index = this.getModel().getEntryCurrentRowIndex("billentry");
|
||||
String entry = "billentry";
|
||||
EntryGrid control = getControl(entry);
|
||||
int[] selectRows = control.getSelectRows();
|
||||
if (selectRows.length == 0) {
|
||||
this.getView().showTipNotification("请选择要执行的数据。");
|
||||
return;
|
||||
} else if (selectRows.length > 1) {
|
||||
this.getView().showTipNotification("请选择一行数据。");
|
||||
return;
|
||||
}
|
||||
int index = selectRows[0];
|
||||
DynamicObjectCollection billentry = this.getModel().getEntryEntity("billentry");
|
||||
if (billentry.size() > index) {
|
||||
DynamicObject dynamicObject = billentry.get(index);
|
||||
|
|
@ -89,9 +87,6 @@ public class PurRefundApplyFormPlugin extends AbstractBillPlugIn implements Befo
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 出库批号根据了做筛选
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void beforeF7Select(BeforeF7SelectEvent beforeF7SelectEvent) {
|
||||
|
|
@ -139,7 +134,19 @@ public class PurRefundApplyFormPlugin extends AbstractBillPlugIn implements Befo
|
|||
}
|
||||
}
|
||||
if (ydth_qty.compareTo(billentry_qty) > 0) {
|
||||
this.getModel().setValue("tqq9_qty_ydth", null, rowIndex);
|
||||
this.getView().showMessage("异地退货明细中物料为:" + tqq9_material_ydth.getDynamicObject("masterid").getString("name") + "的数量不能超过物料明细对应的数量");
|
||||
} else {
|
||||
for (int i = 0; i < billentry.size(); i++) {
|
||||
DynamicObject dynamicObject = billentry.get(i);
|
||||
DynamicObject material = dynamicObject.getDynamicObject("material");
|
||||
if (Objects.equals(tqq9_material_ydth, material)) {
|
||||
this.getModel().setValue("tqq9_stsl", billentry_qty.subtract(ydth_qty), i);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -147,14 +154,5 @@ public class PurRefundApplyFormPlugin extends AbstractBillPlugIn implements Befo
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeAddRow(BeforeAddRowEventArgs e) {
|
||||
super.beforeAddRow(e);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterAddRow(AfterAddRowEventArgs e) {
|
||||
super.afterAddRow(e);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,20 +2,20 @@ package tqq9.lc123.cloud.app.plugin.operate.pm;
|
|||
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.entity.ExtendedDataEntity;
|
||||
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||||
import kd.bos.entity.plugin.args.BeforeOperationArgs;
|
||||
import kd.bos.entity.plugin.PreparePropertysEventArgs;
|
||||
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
||||
import kd.bos.entity.validate.AbstractValidator;
|
||||
import kd.bos.logging.Log;
|
||||
import kd.bos.logging.LogFactory;
|
||||
import kd.bos.orm.query.QCP;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
import tqq9.lc123.cloud.app.plugin.utils.AutoFixLinkUtil;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -26,11 +26,21 @@ import java.util.stream.Collectors;
|
|||
public class PurRefundApplyValidOpPlugin extends AbstractOperationServicePlugIn implements Plugin {
|
||||
private final static Log logger = LogFactory.getLog(PurRefundApplyValidOpPlugin.class);
|
||||
|
||||
@Override
|
||||
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||||
super.onPreparePropertys(e);
|
||||
e.getFieldKeys().add("billentry.material");
|
||||
e.getFieldKeys().add("billentry.qty");
|
||||
e.getFieldKeys().add("tqq9_entryentity.tqq9_material_ydth");
|
||||
e.getFieldKeys().add("tqq9_entryentity.tqq9_qty_ydth");
|
||||
e.getFieldKeys().add("tqq9_entryentity.tqq9_cgthflid");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddValidators(AddValidatorsEventArgs e) {
|
||||
super.onAddValidators(e);
|
||||
e.addValidator(new AbstractValidator() {
|
||||
/*e.addValidator(new AbstractValidator() {
|
||||
@Override
|
||||
public void validate() {
|
||||
ExtendedDataEntity[] dataEntities = this.getDataEntities();
|
||||
|
|
@ -41,8 +51,77 @@ public class PurRefundApplyValidOpPlugin extends AbstractOperationServicePlugIn
|
|||
|
||||
DynamicObjectCollection tqq9_entryentity = dataEntity.getDynamicObjectCollection("tqq9_entryentity");
|
||||
|
||||
|
||||
Map<String, BigDecimal> quantityA = billentry.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
detail -> detail.getDynamicObject("material").getDynamicObject("masterid").getString("number"), // 获取物料编码
|
||||
Collectors.reducing(
|
||||
BigDecimal.ZERO,
|
||||
detail -> detail.getBigDecimal("qty"), // 获取物料数量
|
||||
BigDecimal::add
|
||||
)
|
||||
));
|
||||
|
||||
Map<String, BigDecimal> quantityB = tqq9_entryentity.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
detail -> detail.getDynamicObject("tqq9_material_ydth").getDynamicObject("masterid").getString("number"), // 获取物料编码
|
||||
Collectors.reducing(
|
||||
BigDecimal.ZERO,
|
||||
detail -> detail.getBigDecimal("tqq9_qty_ydth"), // 获取物料数量
|
||||
BigDecimal::add
|
||||
)
|
||||
));
|
||||
|
||||
Map<String, String> result = new HashMap<>();
|
||||
|
||||
for (Map.Entry<String, BigDecimal> entry : quantityB.entrySet()) {
|
||||
String materialCode = entry.getKey();
|
||||
BigDecimal qtyB = entry.getValue();
|
||||
BigDecimal qtyA = quantityA.getOrDefault(materialCode, BigDecimal.ZERO);
|
||||
|
||||
// 如果B数量 > A数量
|
||||
if (qtyB.compareTo(qtyA) > 0) {
|
||||
String errorMsg = String.format(
|
||||
"物料%s数量超标: B明细数量%s > A明细数量%s",
|
||||
materialCode, qtyB, qtyA
|
||||
);
|
||||
result.put(materialCode, errorMsg);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (result.size() > 0) {
|
||||
this.addErrorMessage(extendeDataEntity, result.toString());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
||||
super.afterExecuteOperationTransaction(e);
|
||||
DynamicObject[] dataEntities1 = e.getDataEntities();
|
||||
for (DynamicObject dynamicObject : dataEntities1) {
|
||||
DynamicObjectCollection billentry = dynamicObject.getDynamicObjectCollection("billentry");
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
for (DynamicObject object : billentry) {
|
||||
String number = object.getDynamicObject("material").getDynamicObject("masterid").getString("number");
|
||||
Object id = object.get("id");
|
||||
if (!map.containsKey(number)) {
|
||||
map.put(number, id);
|
||||
}
|
||||
}
|
||||
DynamicObjectCollection tqq9_entryentity = dynamicObject.getDynamicObjectCollection("tqq9_entryentity");
|
||||
for (DynamicObject object : tqq9_entryentity) {
|
||||
String number = object.getDynamicObject("tqq9_material_ydth").getDynamicObject("masterid").getString("number");
|
||||
if (map.containsKey(number)) {
|
||||
object.set("tqq9_cgthflid", map.get(number));
|
||||
}
|
||||
}
|
||||
SaveServiceHelper.save(new DynamicObject[]{dynamicObject});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue