parent
21dc167e11
commit
b6c44285f4
|
@ -0,0 +1,111 @@
|
||||||
|
package shkd.sys.sys.plugin.task;
|
||||||
|
|
||||||
|
import kd.bos.algo.DataSet;
|
||||||
|
import kd.bos.algo.Row;
|
||||||
|
import kd.bos.context.RequestContext;
|
||||||
|
import kd.bos.dataentity.OperateOption;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.resource.ResManager;
|
||||||
|
import kd.bos.entity.ExtendedDataEntity;
|
||||||
|
import kd.bos.entity.operate.result.OperationResult;
|
||||||
|
import kd.bos.exception.KDException;
|
||||||
|
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.schedule.executor.AbstractTask;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.QueryServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.OperationServiceHelper;
|
||||||
|
import kd.tmc.cdm.common.constant.CdmEntityConst;
|
||||||
|
import kd.tmc.cdm.common.enums.BillStatusEnum;
|
||||||
|
import kd.tmc.cdm.common.enums.DraftTradeTypeEnum;
|
||||||
|
import kd.tmc.cdm.common.enums.DraftTranStatusEnum;
|
||||||
|
import kd.tmc.fbp.common.util.EmptyUtil;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class redeemTaskPlugin extends AbstractTask {
|
||||||
|
|
||||||
|
private static final Log logger = LogFactory.getLog(redeemTaskPlugin.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
|
||||||
|
QFilter filter = new QFilter("draftbillstatus", QCP.equals, "payoffed");
|
||||||
|
filter=filter.and(new QFilter("draftbilltype.name", QCP.like, "%商业承兑汇票%"));
|
||||||
|
DynamicObject[] CDM_PAYABLEBILLs = BusinessDataServiceHelper.load(CdmEntityConst.CDM_PAYABLEBILL, "id,billno,amount,billstatus,draftbilltranstatus", filter.toArray());
|
||||||
|
Set<Object> draftIds = (Set)Arrays.stream(CDM_PAYABLEBILLs).map((s) -> {
|
||||||
|
return s.getPkValue();
|
||||||
|
}).collect(Collectors.toSet());
|
||||||
|
QFilter filter1 = new QFilter("entrys.draftbill.id", "in", draftIds);
|
||||||
|
filter1.and("tradetype", "=", DraftTradeTypeEnum.REDEEM.getValue());
|
||||||
|
filter1.and("draftbilltranstatus", "=", "success");
|
||||||
|
Map<Long, BigDecimal> amountMap = new HashMap(16);
|
||||||
|
DataSet rows = QueryServiceHelper.queryDataSet("PayableBillRedeemValidator", "cdm_drafttradebill", "entrys.draftbill.id,entrys.billamt", filter1.toArray(), (String)null);
|
||||||
|
Throwable var8 = null;
|
||||||
|
try {
|
||||||
|
Iterator var9 = rows.iterator();
|
||||||
|
|
||||||
|
while(var9.hasNext()) {
|
||||||
|
Row row = (Row)var9.next();
|
||||||
|
Long draftBillId = row.getLong("entrys.draftbill.id");
|
||||||
|
BigDecimal orDefault = (BigDecimal)amountMap.getOrDefault(draftBillId, BigDecimal.ZERO);
|
||||||
|
amountMap.put(draftBillId, orDefault.add(row.getBigDecimal("entrys.billamt")));
|
||||||
|
}
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
var8 = throwable;
|
||||||
|
throw throwable;
|
||||||
|
} finally {
|
||||||
|
if (rows != null) {
|
||||||
|
if (var8 != null) {
|
||||||
|
try {
|
||||||
|
rows.close();
|
||||||
|
} catch (Throwable var25) {
|
||||||
|
var8.addSuppressed(var25);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rows.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < CDM_PAYABLEBILLs.length; i++) {
|
||||||
|
DynamicObject cdm_payablebill = CDM_PAYABLEBILLs[i];
|
||||||
|
Long draftId = cdm_payablebill.getLong("id");
|
||||||
|
BigDecimal sumBillAmt = (BigDecimal)amountMap.getOrDefault(draftId, BigDecimal.ZERO);
|
||||||
|
BigDecimal amount = cdm_payablebill.getBigDecimal("amount");
|
||||||
|
boolean isNoAmount = sumBillAmt.compareTo(BigDecimal.ZERO) != 0 && amount.compareTo(sumBillAmt) == 0;
|
||||||
|
String billStatus = cdm_payablebill.getString("billstatus");
|
||||||
|
String draftbillTranstatus = cdm_payablebill.getString("draftbilltranstatus");
|
||||||
|
if (!BillStatusEnum.AUDIT.getValue().equals(billStatus) || !DraftTranStatusEnum.SUCCESS.getValue().equals(draftbillTranstatus) || isNoAmount) {
|
||||||
|
logger.info("单据编号:"+cdm_payablebill.getString("billno")+"单据状态为“已审核”且票据交易状态为“交易成功”的未兑付票据才能操作票据兑付。");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Long> dataEntitys = new ArrayList<>();
|
||||||
|
dataEntitys.add(Long.parseLong(cdm_payablebill.getString("id")));
|
||||||
|
OperateOption option = OperateOption.create();
|
||||||
|
option.setVariableValue("tradeType", "redeem");
|
||||||
|
option.setVariableValue("remarks", "后台下推");
|
||||||
|
//调用方法执行数据 - 自动兑付下推
|
||||||
|
OperationResult operationResult = OperationServiceHelper.executeOperate("pushandsaveredeem",
|
||||||
|
CdmEntityConst.CDM_PAYABLEBILL,
|
||||||
|
dataEntitys.toArray(new Object[]{}), option);
|
||||||
|
if (operationResult.getAllErrorInfo().size()!=0) {
|
||||||
|
logger.info("单据编号:"+cdm_payablebill.getString("billno")+"后台生单失败,原因:"+operationResult.getAllErrorInfo().get(0).getMessage());
|
||||||
|
String targetpkvalue = operationResult.getAllErrorInfo().get(0).getErrorCustInfos().get("targetpkvalue");
|
||||||
|
DynamicObject cdm_drafttradebill = BusinessDataServiceHelper.loadSingle(targetpkvalue, "cdm_drafttradebill");
|
||||||
|
OperationResult delete = OperationServiceHelper.executeOperate("delete", "cdm_drafttradebill", new DynamicObject[]{cdm_drafttradebill}, OperateOption.create());
|
||||||
|
if (delete.isSuccess()==true){
|
||||||
|
logger.info("删除单据编号:"+cdm_payablebill.getString("billno")+"成功");
|
||||||
|
}else {
|
||||||
|
logger.info("删除单据编号:"+cdm_payablebill.getString("billno")+"失败,原因:"+delete.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue