2025-11-17 10:17:39 +00:00
|
|
|
package tqq9.lc123.cloud.app.plugin.operate.pm;
|
|
|
|
|
|
|
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
|
import kd.bos.entity.ExtendedDataEntity;
|
|
|
|
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
|
|
|
|
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
2025-11-18 05:50:32 +00:00
|
|
|
import kd.bos.entity.plugin.PreparePropertysEventArgs;
|
|
|
|
|
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
2025-11-17 10:17:39 +00:00
|
|
|
import kd.bos.entity.validate.AbstractValidator;
|
|
|
|
|
import kd.bos.logging.Log;
|
|
|
|
|
import kd.bos.logging.LogFactory;
|
2025-11-18 05:50:32 +00:00
|
|
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
2025-11-17 10:17:39 +00:00
|
|
|
import kd.sdk.plugin.Plugin;
|
|
|
|
|
|
2025-11-18 05:50:32 +00:00
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
2025-11-17 10:17:39 +00:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 采购退货单保存操作插件
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class PurRefundApplyValidOpPlugin extends AbstractOperationServicePlugIn implements Plugin {
|
|
|
|
|
private final static Log logger = LogFactory.getLog(PurRefundApplyValidOpPlugin.class);
|
|
|
|
|
|
2025-11-18 05:50:32 +00:00
|
|
|
@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");
|
|
|
|
|
|
|
|
|
|
}
|
2025-11-17 10:17:39 +00:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAddValidators(AddValidatorsEventArgs e) {
|
|
|
|
|
super.onAddValidators(e);
|
2025-11-18 05:50:32 +00:00
|
|
|
/*e.addValidator(new AbstractValidator() {
|
2025-11-17 10:17:39 +00:00
|
|
|
@Override
|
|
|
|
|
public void validate() {
|
|
|
|
|
ExtendedDataEntity[] dataEntities = this.getDataEntities();
|
|
|
|
|
for (ExtendedDataEntity extendeDataEntity : dataEntities) {
|
|
|
|
|
DynamicObject dataEntity = extendeDataEntity.getDataEntity();
|
|
|
|
|
|
|
|
|
|
DynamicObjectCollection billentry = dataEntity.getDynamicObjectCollection("billentry");
|
|
|
|
|
|
|
|
|
|
DynamicObjectCollection tqq9_entryentity = dataEntity.getDynamicObjectCollection("tqq9_entryentity");
|
|
|
|
|
|
2025-11-18 05:50:32 +00:00
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
}
|
2025-11-17 10:17:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
2025-11-18 05:50:32 +00:00
|
|
|
});*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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});
|
|
|
|
|
|
|
|
|
|
}
|
2025-11-17 10:17:39 +00:00
|
|
|
}
|
|
|
|
|
}
|