This commit is contained in:
parent
f53b4c987a
commit
70de408cfb
|
|
@ -0,0 +1,332 @@
|
||||||
|
//
|
||||||
|
// Source code recreated from a .class file by IntelliJ IDEA
|
||||||
|
// (powered by FernFlower decompiler)
|
||||||
|
//
|
||||||
|
|
||||||
|
package zcgj.zcdev.zcdev.pr.plugin.operate;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.dataentity.utils.StringUtils;
|
||||||
|
import kd.bos.entity.EntityMetadataCache;
|
||||||
|
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.BeginOperationTransactionArgs;
|
||||||
|
import kd.bos.entity.validate.AbstractValidator;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
|
import kd.ec.basedata.common.enums.ReferBillTypeEnum;
|
||||||
|
import kd.ec.contract.opplugin.AbstractContractSettleOp;
|
||||||
|
import kd.ec.contract.opplugin.validator.CheckSettleReferBillUsedValidator;
|
||||||
|
import kd.ec.contract.opplugin.validator.OutContractSettleReferValidator;
|
||||||
|
import kd.ec.contract.opplugin.validator.OutContractSettleTimeValidator;
|
||||||
|
import kd.ec.contract.opplugin.validator.OutContractSettleValidator;
|
||||||
|
|
||||||
|
public class OutContractSettleOpExt extends AbstractContractSettleOp {
|
||||||
|
public OutContractSettleOpExt() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||||||
|
super.onPreparePropertys(e);
|
||||||
|
List<String> fields = e.getFieldKeys();
|
||||||
|
fields.add("begindate");
|
||||||
|
fields.add("enddate");
|
||||||
|
fields.add("billstatus");
|
||||||
|
fields.add("contract");
|
||||||
|
fields.add("contattr");
|
||||||
|
fields.add("period");
|
||||||
|
fields.add("project");
|
||||||
|
fields.add("listentry");
|
||||||
|
fields.add("materialinentry");
|
||||||
|
fields.add("issettlebymatin");
|
||||||
|
fields.add("materialinbillid");
|
||||||
|
fields.add("reconcentry");
|
||||||
|
fields.add("issettlebyreconc");
|
||||||
|
fields.add("reconcbillid");
|
||||||
|
fields.add("iseqsettle");
|
||||||
|
fields.add("eqsettleentry");
|
||||||
|
fields.add("eqsettleid");
|
||||||
|
fields.add("settleunitproject");
|
||||||
|
fields.add("payitemdetailentry");
|
||||||
|
fields.add("referbilltype");
|
||||||
|
fields.add("referbillid");
|
||||||
|
fields.add("referbillnumber");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onAddValidators(AddValidatorsEventArgs e) {
|
||||||
|
boolean isUnaudit = false;
|
||||||
|
List<AbstractValidator> validators = e.getValidators();
|
||||||
|
Iterator var4 = validators.iterator();
|
||||||
|
|
||||||
|
while (var4.hasNext()) {
|
||||||
|
AbstractValidator val = (AbstractValidator) var4.next();
|
||||||
|
if ("unaudit".equals(val.getOperateKey())) {
|
||||||
|
isUnaudit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isUnaudit) {
|
||||||
|
e.getValidators().add(new OutContractSettleValidator());
|
||||||
|
e.getValidators().add(new CheckSettleReferBillUsedValidator());
|
||||||
|
e.getValidators().add(new OutContractSettleTimeValidator());
|
||||||
|
e.getValidators().add(new OutContractSettleReferValidator());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reverseWritingToContract(boolean isAudit, DynamicObject settle) {
|
||||||
|
DynamicObject contract = BusinessDataServiceHelper.loadSingle(settle.getDynamicObject("contract").getPkValue(), "ec_out_contract", (String) Stream.of("totalcalofamt", "totalcaloftaxamt", "totalnotcalofamt", "totalnotcaloftaxamt", "totalsettleamount", "totalsettleoftaxamount").collect(Collectors.joining(",")));
|
||||||
|
BigDecimal totalSettleAmount = contract.getBigDecimal("totalsettleamount");
|
||||||
|
BigDecimal totalSettleOfTaxAmount = contract.getBigDecimal("totalsettleoftaxamount");
|
||||||
|
BigDecimal settleAmount = settle.getBigDecimal("settleamount");
|
||||||
|
BigDecimal settleOfTaxAmount = settle.getBigDecimal("settleoftaxamount");
|
||||||
|
if (isAudit) {
|
||||||
|
contract.set("totalsettleamount", totalSettleAmount.add(settleAmount));
|
||||||
|
contract.set("totalsettleoftaxamount", totalSettleOfTaxAmount.add(settleOfTaxAmount));
|
||||||
|
contract.set("totalcalofamt", contract.getBigDecimal("totalcalofamt").add(settle.getBigDecimal("calofamt")));
|
||||||
|
contract.set("totalcaloftaxamt", contract.getBigDecimal("totalcaloftaxamt").add(settle.getBigDecimal("caloftaxamt")));
|
||||||
|
contract.set("totalnotcalofamt", contract.getBigDecimal("totalnotcalofamt").add(settle.getBigDecimal("notcalofamt")));
|
||||||
|
contract.set("totalnotcaloftaxamt", contract.getBigDecimal("totalnotcaloftaxamt").add(settle.getBigDecimal("notcaloftaxamt")));
|
||||||
|
} else {
|
||||||
|
contract.set("totalsettleamount", totalSettleAmount.subtract(settleAmount));
|
||||||
|
contract.set("totalsettleoftaxamount", totalSettleOfTaxAmount.subtract(settleOfTaxAmount));
|
||||||
|
contract.set("totalcalofamt", contract.getBigDecimal("totalcalofamt").subtract(settle.getBigDecimal("calofamt")));
|
||||||
|
contract.set("totalcaloftaxamt", contract.getBigDecimal("totalcaloftaxamt").subtract(settle.getBigDecimal("caloftaxamt")));
|
||||||
|
contract.set("totalnotcalofamt", contract.getBigDecimal("totalnotcalofamt").subtract(settle.getBigDecimal("notcalofamt")));
|
||||||
|
contract.set("totalnotcaloftaxamt", contract.getBigDecimal("totalnotcaloftaxamt").subtract(settle.getBigDecimal("notcaloftaxamt")));
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveServiceHelper.save(new DynamicObject[]{contract});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void beginOperationTransaction(BeginOperationTransactionArgs e) {
|
||||||
|
super.beginOperationTransaction(e);
|
||||||
|
String operationKey = e.getOperationKey();
|
||||||
|
if (StringUtils.equals("audit", operationKey) || StringUtils.equals("unaudit", operationKey)) {
|
||||||
|
DynamicObject[] dataArr = e.getDataEntities();
|
||||||
|
|
||||||
|
for (int i = 0; i < dataArr.length; ++i) {
|
||||||
|
boolean isSettleByMatIn = dataArr[i].getBoolean("issettlebymatin");
|
||||||
|
boolean isSettleByReconciliation = dataArr[i].getBoolean("issettlebyreconc");
|
||||||
|
boolean isSettleByEquipment = dataArr[i].getBoolean("iseqsettle");
|
||||||
|
Set<Long> materialInBillIds = new HashSet(16);
|
||||||
|
Set<Long> reconciliationBillIds = new HashSet(16);
|
||||||
|
Set<Long> equipmentBillIds = new HashSet(16);
|
||||||
|
DynamicObjectCollection dynamicObjects;
|
||||||
|
int j;
|
||||||
|
Object eqSettleId;
|
||||||
|
if (isSettleByReconciliation) {
|
||||||
|
dynamicObjects = dataArr[i].getDynamicObjectCollection("reconcentry");
|
||||||
|
|
||||||
|
for (j = 0; j < dynamicObjects.size(); ++j) {
|
||||||
|
eqSettleId = ((DynamicObject) dynamicObjects.get(j)).get("reconcbillid");
|
||||||
|
if (StringUtils.isNotBlank(eqSettleId)) {
|
||||||
|
reconciliationBillIds.add(Long.valueOf(eqSettleId.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicObject[] reconcBills = BusinessDataServiceHelper.load(reconciliationBillIds.toArray(), EntityMetadataCache.getDataEntityType("ecma_reconciliation"));
|
||||||
|
List<Long> matInBillIdList = (List) Arrays.stream(reconcBills).filter((d) -> {
|
||||||
|
return StringUtils.isNotBlank(d.getString("materialinbills"));
|
||||||
|
}).map((d) -> {
|
||||||
|
return d.getString("materialinbills").split(";");
|
||||||
|
}).flatMap((s) -> {
|
||||||
|
return Arrays.stream(s);
|
||||||
|
}).map((s) -> {
|
||||||
|
return Long.valueOf(s);
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
materialInBillIds.addAll(matInBillIdList);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSettleByMatIn) {
|
||||||
|
dynamicObjects = dataArr[i].getDynamicObjectCollection("materialinentry");
|
||||||
|
|
||||||
|
for (j = 0; j < dynamicObjects.size(); ++j) {
|
||||||
|
eqSettleId = ((DynamicObject) dynamicObjects.get(j)).get("materialinbillid");
|
||||||
|
if (StringUtils.isNotBlank(eqSettleId)) {
|
||||||
|
materialInBillIds.add(Long.valueOf(eqSettleId.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSettleByEquipment) {
|
||||||
|
dynamicObjects = dataArr[i].getDynamicObjectCollection("eqsettleentry");
|
||||||
|
|
||||||
|
for (j = 0; j < dynamicObjects.size(); ++j) {
|
||||||
|
eqSettleId = ((DynamicObject) dynamicObjects.get(j)).get("eqsettleid");
|
||||||
|
if (StringUtils.isNotBlank(eqSettleId)) {
|
||||||
|
equipmentBillIds.add(Long.valueOf(eqSettleId.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Object> measureBillIds = new HashSet(16);
|
||||||
|
DynamicObjectCollection detailEntries = dataArr[i].getDynamicObjectCollection("payitemdetailentry");
|
||||||
|
if (detailEntries != null && !detailEntries.isEmpty()) {
|
||||||
|
Iterator var27 = detailEntries.iterator();
|
||||||
|
|
||||||
|
while (var27.hasNext()) {
|
||||||
|
DynamicObject detailEntry = (DynamicObject) var27.next();
|
||||||
|
if (StringUtils.equals(detailEntry.getString("referbilltype"), ReferBillTypeEnum.MEASURE.getValue())) {
|
||||||
|
measureBillIds.add(detailEntry.get("referbillid"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicObject[] var15;
|
||||||
|
int var16;
|
||||||
|
int var17;
|
||||||
|
DynamicObject bill;
|
||||||
|
DynamicObject[] equipmentBill;
|
||||||
|
QFilter filter;
|
||||||
|
if (!measureBillIds.isEmpty()) {
|
||||||
|
filter = new QFilter("id", "in", measureBillIds);
|
||||||
|
filter.and("ismeasurebymatin", "=", "1");
|
||||||
|
equipmentBill = BusinessDataServiceHelper.load("ec_outcontractmeasure", "materialinentry,materialinentry.materialinbillid", new QFilter[]{filter});
|
||||||
|
if (equipmentBill != null && equipmentBill.length > 0) {
|
||||||
|
var15 = equipmentBill;
|
||||||
|
var16 = equipmentBill.length;
|
||||||
|
|
||||||
|
for (var17 = 0; var17 < var16; ++var17) {
|
||||||
|
bill = var15[var17];
|
||||||
|
DynamicObjectCollection materialInEntries = bill.getDynamicObjectCollection("materialinentry");
|
||||||
|
if (materialInEntries != null && !materialInEntries.isEmpty()) {
|
||||||
|
Iterator var20 = materialInEntries.iterator();
|
||||||
|
|
||||||
|
while (var20.hasNext()) {
|
||||||
|
DynamicObject materialInEntry = (DynamicObject) var20.next();
|
||||||
|
Object matInBillId = materialInEntry.get("materialinbillid");
|
||||||
|
if (StringUtils.isNotBlank(matInBillId)) {
|
||||||
|
materialInBillIds.add(Long.valueOf(matInBillId.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!materialInBillIds.isEmpty()) {
|
||||||
|
filter = new QFilter("id", "in", materialInBillIds);
|
||||||
|
equipmentBill = BusinessDataServiceHelper.load("ecma_materialinbill", "settlestatus", new QFilter[]{filter});
|
||||||
|
if (equipmentBill == null || equipmentBill.length == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var15 = equipmentBill;
|
||||||
|
var16 = equipmentBill.length;
|
||||||
|
|
||||||
|
for (var17 = 0; var17 < var16; ++var17) {
|
||||||
|
bill = var15[var17];
|
||||||
|
if (StringUtils.equals("audit", operationKey)) {
|
||||||
|
bill.set("settlestatus", "1");
|
||||||
|
} else {
|
||||||
|
bill.set("settlestatus", "0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveServiceHelper.save(equipmentBill);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reconciliationBillIds.isEmpty()) {
|
||||||
|
filter = new QFilter("id", "in", reconciliationBillIds);
|
||||||
|
equipmentBill = BusinessDataServiceHelper.load("ecma_reconciliation", "issettled", new QFilter[]{filter});
|
||||||
|
if (equipmentBill == null || equipmentBill.length == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var15 = equipmentBill;
|
||||||
|
var16 = equipmentBill.length;
|
||||||
|
|
||||||
|
for (var17 = 0; var17 < var16; ++var17) {
|
||||||
|
bill = var15[var17];
|
||||||
|
if (StringUtils.equals("audit", operationKey)) {
|
||||||
|
bill.set("issettled", "1");
|
||||||
|
} else {
|
||||||
|
bill.set("issettled", "0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveServiceHelper.save(equipmentBill);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!equipmentBillIds.isEmpty()) {
|
||||||
|
filter = new QFilter("id", "in", equipmentBillIds);
|
||||||
|
equipmentBill = BusinessDataServiceHelper.load("eceq_settle", "issettle", new QFilter[]{filter});
|
||||||
|
if (equipmentBill != null && equipmentBill.length != 0) {
|
||||||
|
var15 = equipmentBill;
|
||||||
|
var16 = equipmentBill.length;
|
||||||
|
|
||||||
|
for (var17 = 0; var17 < var16; ++var17) {
|
||||||
|
bill = var15[var17];
|
||||||
|
if (StringUtils.equals("audit", operationKey)) {
|
||||||
|
bill.set("issettle", "1");
|
||||||
|
} else {
|
||||||
|
bill.set("issettle", "0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveServiceHelper.save(equipmentBill);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
||||||
|
super.afterExecuteOperationTransaction(e);
|
||||||
|
String operation = e.getOperationKey();
|
||||||
|
DynamicObject[] settleBills = e.getDataEntities();
|
||||||
|
List<DynamicObject> settleBillList = Arrays.asList(settleBills);
|
||||||
|
List<DynamicObject> listingEntrys = (List) settleBillList.stream().flatMap((settleBill) -> {
|
||||||
|
String billId = ((DynamicObject) settleBillList.get(0)).getString("id");
|
||||||
|
DynamicObject bill = BusinessDataServiceHelper.loadSingle(billId, EntityMetadataCache.getDataEntityType("ec_out_contract_settle"));
|
||||||
|
return bill.getDynamicObjectCollection("listmodelentry").stream();
|
||||||
|
}).flatMap((modelObj) -> {
|
||||||
|
return modelObj.getDynamicObjectCollection("listentry").stream();
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
if ("audit".equals(operation)) {
|
||||||
|
this.updateListing(listingEntrys, true);
|
||||||
|
} else if ("unaudit".equals(operation)) {
|
||||||
|
this.updateListing(listingEntrys, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateListing(List<DynamicObject> listingEntrys, boolean isaudit) {
|
||||||
|
List<DynamicObject> listingArr = new ArrayList();
|
||||||
|
BigDecimal coefficient;
|
||||||
|
if (isaudit) {
|
||||||
|
coefficient = BigDecimal.ONE;
|
||||||
|
} else {
|
||||||
|
coefficient = BigDecimal.valueOf(-1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
listingEntrys.forEach((obj) -> {
|
||||||
|
BigDecimal thisQty = coefficient.multiply(obj.getBigDecimal("thisqty"));
|
||||||
|
BigDecimal thisOfTaxAmount = coefficient.multiply(obj.getBigDecimal("thisoftaxmount"));
|
||||||
|
DynamicObject listing = obj.getDynamicObject("listing");
|
||||||
|
String listingId = listing.getString("id");
|
||||||
|
DynamicObject listingObj = BusinessDataServiceHelper.loadSingle(listingId, "ec_outtreelisting");
|
||||||
|
listingObj.set("lstsettleqty", thisQty.add(listingObj.getBigDecimal("lstsettleqty")));
|
||||||
|
listingObj.set("lstsettleoftaxamount", thisOfTaxAmount.add(listingObj.getBigDecimal("lstsettleoftaxamount")));
|
||||||
|
listingArr.add(listingObj);
|
||||||
|
});
|
||||||
|
if (!listingArr.isEmpty()) {
|
||||||
|
SaveServiceHelper.save(((DynamicObject) listingArr.get(0)).getDataEntityType(), listingArr.toArray(new DynamicObject[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue