共享合并生成凭证问题
This commit is contained in:
parent
8dfdf6c1bc
commit
f0115bb5d3
|
@ -2,32 +2,30 @@ package zcgj.zcdev.zcdev.fs.plugin.form;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import kd.ai.ids.core.utils.JsonUtils;
|
||||
import kd.bos.bill.AbstractBillPlugIn;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import kd.bos.dataentity.OperateOption;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.entity.EntityMetadataCache;
|
||||
import kd.bos.entity.datamodel.ListSelectedRow;
|
||||
import kd.bos.entity.datamodel.ListSelectedRowCollection;
|
||||
import kd.bos.entity.operate.result.IOperateInfo;
|
||||
import kd.bos.entity.operate.result.OperationResult;
|
||||
import kd.bos.form.IFormView;
|
||||
import kd.bos.form.ShowType;
|
||||
import kd.bos.form.control.events.ItemClickEvent;
|
||||
import kd.bos.list.BillList;
|
||||
import kd.bos.list.ListFilterParameter;
|
||||
import kd.bos.list.ListShowParameter;
|
||||
import kd.bos.list.plugin.AbstractListPlugin;
|
||||
import kd.bos.logging.Log;
|
||||
import kd.bos.logging.LogFactory;
|
||||
import kd.bos.openapi.common.result.OpenApiResult;
|
||||
import kd.bos.openapi.common.util.JacksonUtil;
|
||||
import kd.bos.openapi.common.util.JsonUtil;
|
||||
import kd.bos.openapi.common.util.OpenApiSdkUtil;
|
||||
import kd.bos.orm.query.QCP;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.QueryServiceHelper;
|
||||
import kd.bos.servicehelper.operation.OperationServiceHelper;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
import kd.ssc.task.formplugin.util.VoucherUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -52,11 +50,18 @@ public class TaskListBuildVoucherPlugin extends AbstractListPlugin implements Pl
|
|||
}
|
||||
List<Long> voucherIds = new ArrayList<>();
|
||||
Map<String,String> par= new HashMap<>();
|
||||
par.put("$key$","");//冗余参数
|
||||
par.put("$value$","");//冗余参数
|
||||
//{"ignorebillstatus":"true"}
|
||||
par.put("ignorebillstatus","true");//忽略单据状态
|
||||
//par.put("$key$","ignorebillstatus");//冗余参数
|
||||
//par.put("$value$","true");//冗余参数
|
||||
|
||||
int errorCount =0;
|
||||
int allCount =0;
|
||||
int successCount =0;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
Map<String,List<String>> map = new HashMap<>();
|
||||
//Map<String,String> idNumberMap = new HashMap<>();
|
||||
for (ListSelectedRow selectedRow : selectedRows) {
|
||||
Long pk = (Long) selectedRow.getPrimaryKeyValue();
|
||||
DynamicObject taskobj = BusinessDataServiceHelper.loadSingle(pk, "task_task");
|
||||
|
@ -64,37 +69,140 @@ public class TaskListBuildVoucherPlugin extends AbstractListPlugin implements Pl
|
|||
String entityName = billtype.getDynamicObject("bindbill").getString("number");
|
||||
String billid = taskobj.getString("billid");
|
||||
//messageBill.put(billid,taskobj.getString("billnumber")+":"+taskobj.getString("subject"));
|
||||
log.info("TaskListBuildVoucherPlugin:billid:"+billid);
|
||||
String billnumber = taskobj.getString("billnumber");
|
||||
log.info("TaskListBuildVoucherPlugin:billid:"+billid+" billnumber:"+billnumber);
|
||||
//idNumberMap.put(billid,billnumber);
|
||||
if(map.containsKey(entityName)){
|
||||
map.get(entityName).add(billid);
|
||||
}else{
|
||||
List<String> idList = new ArrayList<>();
|
||||
idList.add(billid);
|
||||
map.put(entityName,idList);
|
||||
}
|
||||
}
|
||||
OperateOption option = OperateOption.create();
|
||||
option.setVariableValue("ignoreValidation", "true");
|
||||
option.setVariableValue("ignorebillstatus", "true");
|
||||
Map<String, Object> voucherOperate = null;
|
||||
List<Object> successBillIds = new ArrayList<>();
|
||||
|
||||
OperationResult operationResult = null;
|
||||
for (String entityName : map.keySet()) {
|
||||
List<String> billIdList = map.get(entityName);
|
||||
voucherOperate = EntityMetadataCache.getDataEntityOperate(entityName, "generatevoucher");
|
||||
operationResult = OperationServiceHelper.executeOperate((String)voucherOperate.get("key"), entityName, billIdList.toArray(), option);
|
||||
|
||||
if (!operationResult.isSuccess()) {
|
||||
List<IOperateInfo> allErrorInfo = operationResult.getAllErrorOrValidateInfo();
|
||||
allErrorInfo.forEach((error) -> sb.append(error.getMessage()));
|
||||
errorCount++;
|
||||
// view.showTipNotification(sb.toString());
|
||||
// for (IOperateInfo iOperateInfo : allErrorInfo) {
|
||||
|
||||
// }
|
||||
// log.info("生成凭证失败,单据id:" + billid + ",失败原因:" + sb);
|
||||
} else {
|
||||
//VoucherUtil.viewVoucher(billid, this.getView(), true);
|
||||
List<Object> successPkIds = operationResult.getSuccessPkIds();
|
||||
successBillIds.addAll(successPkIds);
|
||||
Map<Object, String> billNos = operationResult.getBillNos();
|
||||
}
|
||||
}
|
||||
|
||||
if(errorCount == 0){//没有失败的,使用成功弹框提醒
|
||||
//this.getView().showSuccessNotification(String.format("凭证生成完成,一共%d条,成功:%d条,失败:%d条。",allCount,successCount,errorCount));
|
||||
if(successBillIds.size() ==1 ){
|
||||
VoucherUtil.viewVoucher(String.valueOf(successBillIds.get(0)), this.getView(), true);
|
||||
}else{
|
||||
List<Long> vids = new ArrayList<>();
|
||||
Set<Long> vidsSet = new HashSet<>();//去重
|
||||
for (Object successBillId : successBillIds) {
|
||||
List<Long> vouncheridByBillid = VoucherUtil.getVouncheridByBillid(Long.valueOf(String.valueOf(successBillId)));
|
||||
// voucherIdList.addAll(vouncheridByBillid);
|
||||
vids.addAll(vouncheridByBillid);
|
||||
vidsSet.addAll(vouncheridByBillid);
|
||||
}
|
||||
if(vidsSet.size() ==1){
|
||||
VoucherUtil.viewVoucher(String.valueOf(successBillIds.get(0)), this.getView(), true);
|
||||
}else{
|
||||
ListShowParameter listShowParameter = new ListShowParameter();
|
||||
listShowParameter.setFormId("bos_list");
|
||||
listShowParameter.setBillFormId("gl_voucher");
|
||||
listShowParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage);
|
||||
// 设置联查PK
|
||||
for (Long voucherId : vids) {
|
||||
listShowParameter.addLinkQueryPkId(voucherId);
|
||||
}
|
||||
this.getView().showForm(listShowParameter);
|
||||
}
|
||||
|
||||
}
|
||||
//this.getView().showSuccessNotification(String.format("凭证生成完成。"));
|
||||
|
||||
}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);
|
||||
}*/
|
||||
|
||||
/*for (String entityName : map.keySet()) {
|
||||
List<String> billIdList = map.get(entityName);
|
||||
Map<String,Object> params = new HashMap<String,Object>();
|
||||
params.put("billType", entityName);
|
||||
List<String> idList = new ArrayList<>();
|
||||
idList.add(billid);
|
||||
params.put("billIds", idList);
|
||||
params.put("billIds", billIdList);
|
||||
params.put("params", par);
|
||||
OpenApiResult invoke = OpenApiSdkUtil.invoke("/v2/ai/buildVoucher", params);
|
||||
Map<String, Object> map = invoke.toMap();
|
||||
if(map.get("status").toString().equals("true")){
|
||||
Map<String, Object> resultMap = invoke.toMap();
|
||||
if(resultMap.get("status").toString().equals("true")){
|
||||
//单据ID:凭证ID:凭证编码
|
||||
//{"2189115272965662720":"2189115761987977216:10006834-000001"}
|
||||
JSONObject data = JSON.parseObject(String.valueOf(map.get("data")));
|
||||
if(data!=null){
|
||||
String voucherInfo = data.getString(billid);
|
||||
String voucherIdStr = voucherInfo.split(":")[0];
|
||||
voucherIds.add(Long.valueOf(voucherIdStr));
|
||||
log.info("TaskListBuildVoucherPlugin:success:"+invoke.getData());
|
||||
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(String.format("凭证生成完成,一共%d条,成功:%d条,失败:%d条。",allCount,successCount,errorCount));
|
||||
this.getView().showTipNotification(sb.toString());
|
||||
}
|
||||
this.getView().invokeOperation("refresh");//调用表单的刷新操作
|
||||
|
||||
|
@ -114,7 +222,7 @@ public class TaskListBuildVoucherPlugin extends AbstractListPlugin implements Pl
|
|||
listShowParameter.addLinkQueryPkId(voucherId);
|
||||
}
|
||||
this.getView().showForm(listShowParameter);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
else if("zcgj_deletevoucher".equals(itemKey)){
|
||||
BillList billList = this.getView().getControl(AbstractListPlugin.BILLLISTID);
|
||||
|
@ -128,11 +236,13 @@ public class TaskListBuildVoucherPlugin extends AbstractListPlugin implements Pl
|
|||
int errorCount =0;
|
||||
int allCount =0;
|
||||
int successCount =0;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
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 billnumber = taskobj.getString("billnumber");
|
||||
String entityName = bindbill.getString("number");
|
||||
//String vouchernum = bindbill.getString("vouchernum");
|
||||
String billid = taskobj.getString("billid");
|
||||
|
@ -144,39 +254,26 @@ public class TaskListBuildVoucherPlugin extends AbstractListPlugin implements Pl
|
|||
.and(new QFilter("sourcebilltype.number", QCP.equals, entityName))
|
||||
//.and(new QFilter("billno", QCP.equals, vouchernum))
|
||||
});
|
||||
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:凭证编码
|
||||
/*{
|
||||
"data":{
|
||||
"failCount":"0",
|
||||
"filter":"[id IN (2189353147254737920)]",
|
||||
"result":[
|
||||
{
|
||||
"billStatus":true,
|
||||
"errors":[],
|
||||
"id":"2189353147254737920",
|
||||
"number":"10006834-000004"
|
||||
}
|
||||
],
|
||||
"successCount":"1",
|
||||
"totalCount":"1"
|
||||
},
|
||||
"errorCode":"0",
|
||||
"message":null,
|
||||
"status":true
|
||||
}*/
|
||||
successCount++;
|
||||
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++;
|
||||
log.info("TaskListBuildVoucherPlugin-delete:error:"+invoke.getMessage());
|
||||
sb.append(String.format("单据编号:【%s】,尚未生成凭证。",billnumber));
|
||||
}
|
||||
allCount++;
|
||||
}
|
||||
|
@ -184,7 +281,8 @@ public class TaskListBuildVoucherPlugin extends AbstractListPlugin implements Pl
|
|||
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(String.format("删除凭证完成,一共%d条,成功:%d条,失败:%d条。",allCount,successCount,errorCount));
|
||||
this.getView().showTipNotification(sb.toString());
|
||||
}
|
||||
this.getView().invokeOperation("refresh");//调用表单的刷新操作
|
||||
|
||||
|
|
Loading…
Reference in New Issue