共享合并生成凭证问题

This commit is contained in:
zhangzhiguo 2025-07-14 16:03:06 +08:00
parent f0115bb5d3
commit 0caafcd63d
1 changed files with 35 additions and 138 deletions

View File

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import kd.bos.dataentity.OperateOption; import kd.bos.dataentity.OperateOption;
import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.entity.EntityMetadataCache; import kd.bos.entity.EntityMetadataCache;
import kd.bos.entity.datamodel.ListSelectedRow; import kd.bos.entity.datamodel.ListSelectedRow;
import kd.bos.entity.datamodel.ListSelectedRowCollection; import kd.bos.entity.datamodel.ListSelectedRowCollection;
@ -96,11 +97,6 @@ public class TaskListBuildVoucherPlugin extends AbstractListPlugin implements Pl
List<IOperateInfo> allErrorInfo = operationResult.getAllErrorOrValidateInfo(); List<IOperateInfo> allErrorInfo = operationResult.getAllErrorOrValidateInfo();
allErrorInfo.forEach((error) -> sb.append(error.getMessage())); allErrorInfo.forEach((error) -> sb.append(error.getMessage()));
errorCount++; errorCount++;
// view.showTipNotification(sb.toString());
// for (IOperateInfo iOperateInfo : allErrorInfo) {
// }
// log.info("生成凭证失败单据id" + billid + ",失败原因:" + sb);
} else { } else {
//VoucherUtil.viewVoucher(billid, this.getView(), true); //VoucherUtil.viewVoucher(billid, this.getView(), true);
List<Object> successPkIds = operationResult.getSuccessPkIds(); List<Object> successPkIds = operationResult.getSuccessPkIds();
@ -137,92 +133,11 @@ public class TaskListBuildVoucherPlugin extends AbstractListPlugin implements Pl
} }
} }
//this.getView().showSuccessNotification(String.format("凭证生成完成。"));
}else{//有失败的使用警告弹框提醒 }else{//有失败的使用警告弹框提醒
//this.getView().showTipNotification(String.format("凭证生成完成,一共%d条成功%d条失败%d条。",allCount,successCount,errorCount)); //this.getView().showTipNotification(String.format("凭证生成完成,一共%d条成功%d条失败%d条。",allCount,successCount,errorCount));
this.getView().showTipNotification(sb.toString()); this.getView().showTipNotification(sb.toString());
} }
this.getView().invokeOperation("refresh");//调用表单的刷新操作 this.getView().invokeOperation("refresh");//调用表单的刷新操作
//如果有成功生成的凭证则调整到凭证列表页面
/*if(successCount != 0){
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
ListShowParameter listShowParameter = new ListShowParameter();
listShowParameter.setFormId("bos_list");
listShowParameter.setBillFormId("gl_voucher");
listShowParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage);
// 设置联查PK
for (Long voucherId : voucherIds) {
listShowParameter.addLinkQueryPkId(voucherId);
}
this.getView().showForm(listShowParameter);
}*/
/*for (String entityName : map.keySet()) {
List<String> billIdList = map.get(entityName);
Map<String,Object> params = new HashMap<String,Object>();
params.put("billType", entityName);
params.put("billIds", billIdList);
params.put("params", par);
OpenApiResult invoke = OpenApiSdkUtil.invoke("/v2/ai/buildVoucher", params);
Map<String, Object> resultMap = invoke.toMap();
if(resultMap.get("status").toString().equals("true")){
//单据ID:凭证ID:凭证编码
//{"2189115272965662720":"2189115761987977216:10006834-000001"}
Map<String, String> dataMap = JSON.parseObject(String.valueOf(resultMap.get("data")), new TypeReference<Map<String, String>>() {});
//JSONObject data = JSON.parseObject(String.valueOf(resultMap.get("data")));
if(dataMap!=null){
for (String voucherInfo : dataMap.keySet()) {
String voucherIdStr = voucherInfo.split(":")[0];
voucherIds.add(Long.valueOf(voucherIdStr));
}
successCount++;
}
}else{
errorCount++;
Map<String, String> stringStringMap = JSON.parseObject(invoke.getMessage(), new TypeReference<Map<String, String>>() {
});
Collection<String> values = stringStringMap.values();
Object[] array = values.toArray();
String msg = String.valueOf(array[0]);
sb.append(String.format("单据编号:生成凭证失败,失败原因:【%s】;",msg));
VoucherUtil.viewVoucher("", this.getView(), true);
log.info("TaskListBuildVoucherPlugin:error:"+invoke.getMessage());
}
allCount++;
}
if(errorCount == 0){//没有失败的使用成功弹框提醒
this.getView().showSuccessNotification(String.format("凭证生成完成,一共%d条成功%d条失败%d条。",allCount,successCount,errorCount));
}else{//有失败的使用警告弹框提醒
//this.getView().showTipNotification(String.format("凭证生成完成,一共%d条成功%d条失败%d条。",allCount,successCount,errorCount));
this.getView().showTipNotification(sb.toString());
}
this.getView().invokeOperation("refresh");//调用表单的刷新操作
//如果有成功生成的凭证则调整到凭证列表页面
if(successCount != 0){
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
ListShowParameter listShowParameter = new ListShowParameter();
listShowParameter.setFormId("bos_list");
listShowParameter.setBillFormId("gl_voucher");
listShowParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage);
// 设置联查PK
for (Long voucherId : voucherIds) {
listShowParameter.addLinkQueryPkId(voucherId);
}
this.getView().showForm(listShowParameter);
}*/
} }
else if("zcgj_deletevoucher".equals(itemKey)){ else if("zcgj_deletevoucher".equals(itemKey)){
BillList billList = this.getView().getControl(AbstractListPlugin.BILLLISTID); BillList billList = this.getView().getControl(AbstractListPlugin.BILLLISTID);
@ -237,6 +152,7 @@ public class TaskListBuildVoucherPlugin extends AbstractListPlugin implements Pl
int allCount =0; int allCount =0;
int successCount =0; int successCount =0;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Map<String,List<String>> map = new HashMap<>();
for (ListSelectedRow selectedRow : selectedRows) { for (ListSelectedRow selectedRow : selectedRows) {
Long pk = (Long) selectedRow.getPrimaryKeyValue(); Long pk = (Long) selectedRow.getPrimaryKeyValue();
DynamicObject taskobj = BusinessDataServiceHelper.loadSingle(pk, "task_task"); DynamicObject taskobj = BusinessDataServiceHelper.loadSingle(pk, "task_task");
@ -248,38 +164,42 @@ public class TaskListBuildVoucherPlugin extends AbstractListPlugin implements Pl
String billid = taskobj.getString("billid"); String billid = taskobj.getString("billid");
//log.info("TaskListBuildVoucherPlugin-delete:vouchernum:"+vouchernum); //log.info("TaskListBuildVoucherPlugin-delete:vouchernum:"+vouchernum);
log.info("TaskListBuildVoucherPlugin-delete:billid:"+billid); log.info("TaskListBuildVoucherPlugin-delete:billid:"+billid);
if(billid!=null && !billid.isEmpty() ){ if(map.containsKey(entityName)){
DynamicObject voucherObject = BusinessDataServiceHelper.loadSingle("gl_voucher", "id", map.get(entityName).add(billid);
new QFilter[]{new QFilter("sourcebill", QCP.equals, Long.valueOf(billid)) }else{
.and(new QFilter("sourcebilltype.number", QCP.equals, entityName)) List<String> idList = new ArrayList<>();
//.and(new QFilter("billno", QCP.equals, vouchernum)) idList.add(billid);
}); map.put(entityName,idList);
if(voucherObject != null){
long voucherId = voucherObject.getLong("id");
log.info("TaskListBuildVoucherPlugin-delete:voucherId:"+voucherId);
Map<String,Object> params = new HashMap<String,Object>();
Map<String,Long> idMap = new HashMap<>();
idMap.put("id", voucherId);
params.put("data",idMap);
OpenApiResult invoke = OpenApiSdkUtil.invoke("/v2/gl/gl_voucher/delete", params);
Map<String, Object> map = invoke.toMap();
if(map.get("status").toString().equals("true")){
//单据ID:凭证ID:凭证编码
successCount++;
}else{
errorCount++;
sb.append(String.format(invoke.getMessage()));
log.info("TaskListBuildVoucherPlugin-delete:error:"+invoke.getMessage());
}
}else{
errorCount++;
sb.append(String.format("单据编号:【%s】尚未生成凭证。",billnumber));
}
allCount++;
} }
} }
OperateOption option = OperateOption.create();
OperationResult operationResult = null;
Map<String, Object> voucherOperate = null;
for (String entityName : map.keySet()) {
List<String> billIds = map.get(entityName);
for (String billId : billIds) {
List<Long> vouncherids = VoucherUtil.getVouncheridByBillid(Long.parseLong(billId));
if (vouncherids.isEmpty()) {
this.getView().showTipNotification(ResManager.loadKDString("单据不存在关联凭证。", "VoucherUtil_4", "ssc-task-formplugin", new Object[0]));
}else{
voucherOperate = EntityMetadataCache.getDataEntityOperate(entityName, "deletevoucher");
operationResult = OperationServiceHelper.executeOperate((String)voucherOperate.get("key"), entityName, billIds.toArray(), option);
if (!operationResult.isSuccess()) {
List<IOperateInfo> allErrorInfo = operationResult.getAllErrorOrValidateInfo();
allErrorInfo.forEach((error) -> sb.append(error.getMessage()));
// this.getView().showTipNotification(sb.toString());
log.info("删除凭证失败单据id" + billId + ",失败原因:" + sb);
errorCount++;
}
}
}
}
if(errorCount == 0){//没有失败的使用成功弹框提醒 if(errorCount == 0){//没有失败的使用成功弹框提醒
this.getView().showSuccessNotification(String.format("删除凭证完成,一共%d条成功%d条失败%d条。",allCount,successCount,errorCount)); // this.getView().showSuccessNotification(String.format("删除凭证完成,一共%d条成功%d条失败%d条。",allCount,successCount,errorCount));
String text = "成功删除凭证。";
this.getView().showSuccessNotification(String.format(ResManager.loadKDString(" %s", "TaskVoucherApproveFormPlugin_3", "ssc-task-formplugin", new Object[0]), text));
}else{//有失败的使用警告弹框提醒 }else{//有失败的使用警告弹框提醒
//this.getView().showTipNotification(String.format("删除凭证完成,一共%d条成功%d条失败%d条。",allCount,successCount,errorCount)); //this.getView().showTipNotification(String.format("删除凭证完成,一共%d条成功%d条失败%d条。",allCount,successCount,errorCount));
this.getView().showTipNotification(sb.toString()); this.getView().showTipNotification(sb.toString());
@ -287,29 +207,6 @@ public class TaskListBuildVoucherPlugin extends AbstractListPlugin implements Pl
this.getView().invokeOperation("refresh");//调用表单的刷新操作 this.getView().invokeOperation("refresh");//调用表单的刷新操作
} }
/*else if("zcgj_bar_payp".equals(itemKey)){
BillList billList = this.getView().getControl(AbstractListPlugin.BILLLISTID);
//获取到选中行的数据
ListSelectedRowCollection selectedRows = billList.getSelectedRows();
if(selectedRows.isEmpty()){
this.getView().showTipNotification(String.format("请选择需要付款的数据。"));
return;
}
for (ListSelectedRow selectedRow : selectedRows) {
Long pk = (Long) selectedRow.getPrimaryKeyValue();
DynamicObject taskobj = BusinessDataServiceHelper.loadSingle(pk, "task_task");
DynamicObject billtype = taskobj.getDynamicObject("billtype");
DynamicObject bindbill = billtype.getDynamicObject("bindbill"); //源单
String entityName = bindbill.getString("number");
String billid = taskobj.getString("billid");
OperateOption operateOption = OperateOption.create();
QFilter accountTableFilter = new QFilter("id", QCP.equals,Long.valueOf(billid));
DynamicObject sourceBillObject = BusinessDataServiceHelper.loadSingle(entityName, new QFilter[]{accountTableFilter});
OperationResult opResult= OperationServiceHelper.executeOperate("pushpaybill", entityName, new DynamicObject[] {sourceBillObject},operateOption );
//OperationResult opResult= OperationServiceHelper.executeOperate("pushpaybill", entityName, new DynamicObject[] {sourceBillObject},operateOption );
log.info(opResult.toString());
}
}*/
} }
} }