信用档案调用审核后单据为暂存状态
金蝶云社区-云社区用户f8CL6036
云社区用户f8CL6036
0人赞赏了该文章 605次浏览 未经作者许可,禁止转载编辑于2017年05月17日 23:46:23

调用审核接口审核《信用档案》单据,跟代码提示审核成功但是查看单据状态为暂存,请老师帮忙提携一下,代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;

namespace SYDBZY.K3.BPM.App.CTEx
{
[Description("年/季度客户授信申请单服务端插件")]
public class CustomerSXBillCTEx : AbstractOperationServicePlugIn
{
///


/// 操作前准备
///

///
public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
{
base.OnPreparePropertys(e);
e.FieldKeys.Add("F_BTO_KHDM");//客户
e.FieldKeys.Add("F_BTO_SXBM");//部门
e.FieldKeys.Add("F_BTO_BQSQED");//本期申请额度
e.FieldKeys.Add("F_BTO_BQSQZQ");//本期申请账期
}

///


/// 事件操作后 执行段
///

///
public override void EndOperationTransaction(EndOperationTransactionArgs e)
{
base.EndOperationTransaction(e);
//审核后,通过部门查询进行更新或增加对应的分录信息 modify by yq 2017-5-5
if (this.FormOperation.Operation.Equals("Audit"))
{
if (e.DataEntitys != null && e.DataEntitys.Count() > 0)
{
foreach (DynamicObject item in e.DataEntitys)
{
//1、获取当前单据中【客户】、【部门】信息
DynamicObject khObject = item["F_BTO_KHDM"] as DynamicObject;//客户
DynamicObject bmObject = item["F_BTO_SXBM"] as DynamicObject;//部门
decimal sqed = Convert.ToDecimal(item["F_BTO_BQSQED"])*10000;//本期申请额度
decimal sqzq = Convert.ToDecimal(item["F_BTO_BQSQZQ"]);//本期申请账期
//2、通过以上两个字段 到【信用档案】中查询是否存在记录
string sql = "select fid from T_CRE_CUSTARCHIVES where FDEPTID = " + bmObject["Id"].ToString() + "";
DynamicObjectCollection col = DBUtils.ExecuteDynamicObject(this.Context, sql);
if (col.Count > 0)
{
string sqlKH = "select y.fid from T_CRE_CUSTARCHIVESENTRY y left join T_CRE_CUSTARCHIVES s on y.fid = s.fid where y.fobjectid = " + khObject["Id"].ToString() + " and s.fdeptid = " + bmObject["Id"].ToString() + "";
DynamicObjectCollection colKH = DBUtils.ExecuteDynamicObject(this.Context, sqlKH);
if (colKH.Count > 0)
{
//查询档案信息对象
IMetaDataService metaService = Kingdee.BOS.App.ServiceHelper.GetService();
FormMetadata XydaMeta = metaService.Load(this.Context, "CRE_CustArchives") as FormMetadata; //信用档案
BusinessInfo XydaInfo = XydaMeta.BusinessInfo;
DynamicObject XydaObject = BusinessDataServiceHelper.LoadSingle(this.Context, colKH[0]["fid"], XydaInfo.GetDynamicObjectType());
DynamicObjectCollection entryEntitys = XydaObject["Entity"] as DynamicObjectCollection; //信用对象设置分录集合
string billState = XydaObject["DocumentStatus"].ToString();
//结束查询档案信息对象
//反审核
List> lstKeyValuePairs = new List>();
ISetStatusService setStatusService = Kingdee.BOS.App.ServiceHelper.GetService();
KeyValuePair keyValuePair = new KeyValuePair(XydaObject[0], "");
lstKeyValuePairs.Add(keyValuePair);
IOperationResult unAuditResult = null;
if ("C".Equals(billState)) {
unAuditResult = setStatusService.SetBillStatus(this.Context, XydaInfo, lstKeyValuePairs, null, "UnAudit");
}
if (unAuditResult !=null && (unAuditResult.ValidationErrors != null && unAuditResult.ValidationErrors.Count > 0))
{
throw new KDBusinessException("zx-001", "反审核信用档案失败!");
}
else
{
foreach (DynamicObject entryObj in entryEntitys)
{
if (khObject["Id"].ToString().Equals(entryObj["ObjectId_Id"].ToString()))
{
entryObj["CreditAmount"] = sqed;
entryObj["OverDays"] = sqzq;
}
}
}
//通过fid 得到当前信用档案的对象,然后修改此客户条的分录
ISaveService saveService = Kingdee.BOS.App.ServiceHelper.GetService();
DynamicObject[] objs = new DynamicObject[1];
objs[0] = XydaObject;
IOperationResult result = saveService.Save(this.Context, XydaInfo, objs);
if ((result.ValidationErrors != null && result.ValidationErrors.Count > 0))
{
result.IsSuccess = false;
StringBuilder errorMessage = new StringBuilder();
errorMessage.AppendLine("保存失败!");
foreach (Kingdee.BOS.Core.Validation.ValidationErrorInfo error in result.ValidationErrors.ToArray())
{
errorMessage.AppendLine(error.Message);
}
throw new KDBusinessException("zx-001", errorMessage.ToString());
}
//提交并审核
ISubmitService submitService = Kingdee.BOS.App.ServiceHelper.GetService();
IOperationResult submitResult = submitService.Submit(this.Context, XydaInfo, new object[] { XydaObject[0] }, "Submit");
if ((submitResult.ValidationErrors != null && submitResult.ValidationErrors.Count > 0))
{
submitResult.IsSuccess = false;
StringBuilder errorMessage = new StringBuilder();
errorMessage.AppendLine("提交失败!");
foreach (Kingdee.BOS.Core.Validation.ValidationErrorInfo error in submitResult.ValidationErrors.ToArray())
{
errorMessage.AppendLine(error.Message);
}
throw new KDBusinessException("zx-001", errorMessage.ToString());
}
//IOperationResult auditResult = setStatusService.SetBillStatus(this.Context, XydaInfo, lstKeyValuePairs, null, "Audit");
IOperationResult auditResult = BusinessDataServiceHelper.SetBillStatus(this.Context,XydaInfo,lstKeyValuePairs,null,"Audit");
if ((auditResult.ValidationErrors != null && auditResult.ValidationErrors.Count > 0))
{
auditResult.IsSuccess = false;
StringBuilder errorMessage = new StringBuilder();
errorMessage.AppendLine("审核失败!");
foreach (Kingdee.BOS.Core.Validation.ValidationErrorInfo error in result.ValidationErrors.ToArray())
{
errorMessage.AppendLine(error.Message);
}
throw new KDBusinessException("zx-001", errorMessage.ToString());
}
}
else
{
//查询档案信息对象
IMetaDataService metaService = Kingdee.BOS.App.ServiceHelper.GetService();
FormMetadata XydaMeta = metaService.Load(this.Context, "CRE_CustArchives") as FormMetadata; //信用档案
BusinessInfo XydaInfo = XydaMeta.BusinessInfo;
DynamicObject XydaObject = BusinessDataServiceHelper.LoadSingle(this.Context, col[0]["fid"], XydaInfo.GetDynamicObjectType());
DynamicObjectCollection entryEntitys = XydaObject["Entity"] as DynamicObjectCollection; //信用对象设置分录集合
string billState = XydaObject["DocumentStatus"].ToString();
//结束查询档案信息对象
//反审核
List> lstKeyValuePairs = new List>();
ISetStatusService setStatusService = Kingdee.BOS.App.ServiceHelper.GetService();
KeyValuePair keyValuePair = new KeyValuePair(XydaObject[0], "");
lstKeyValuePairs.Add(keyValuePair);
IOperationResult unAuditResult = null;
if ("C".Equals(billState))
{
unAuditResult = setStatusService.SetBillStatus(this.Context, XydaInfo, lstKeyValuePairs, null, "UnAudit");
}
if (unAuditResult != null && (unAuditResult.ValidationErrors != null && unAuditResult.ValidationErrors.Count > 0))
{
throw new KDBusinessException("zx-001", "反审核信用档案失败!");
}
else
{
DynamicObject entry = new DynamicObject(entryEntitys.DynamicCollectionItemPropertyType);
entry["Seq"] = entryEntitys.Count() + 1;//序号
entry["ObjectId_Id"] = khObject["Id"];//授信对象Id
entry["ObjectId"] = khObject;//授信对象
entry["CurrencyId_Id"] = 1;//币别Id
FormMetadata bbMeta = metaService.Load(this.Context, "BD_Currency") as FormMetadata; //币别
BusinessInfo bbInfo = bbMeta.BusinessInfo;
DynamicObject bbObject = BusinessDataServiceHelper.LoadSingle(this.Context,1, bbInfo.GetDynamicObjectType());
entry["CurrencyId"] = bbObject;//币别
entry["CreditStatus"] = "A";//信用状态
entry["CheckRuleId_Id"] = "1639018";//检查规则Id
FormMetadata jcgzMeta = metaService.Load(this.Context, "CRE_CheckRule") as FormMetadata; //检查规则
BusinessInfo jcgzInfo = jcgzMeta.BusinessInfo;
DynamicObject jcgzObject = BusinessDataServiceHelper.LoadSingle(this.Context, 1639018, jcgzInfo.GetDynamicObjectType());
entry["CheckRuleId"] = jcgzObject;//检查规则
entry["FDyRecConditionId_Id"] = "1639022";//收款条件Id
FormMetadata sktjMeta = metaService.Load(this.Context, "BD_RecCondition") as FormMetadata; //收款条件
BusinessInfo sktjInfo = sktjMeta.BusinessInfo;
DynamicObject sktjObject = BusinessDataServiceHelper.LoadSingle(this.Context, 1639022, sktjInfo.GetDynamicObjectType());
entry["FDyRecConditionId"] = sktjObject;//收款条件
entry["CreditAmount"] = sqed;//信用额度
entry["OverDays"] = sqzq;//逾期天数
entry["EffectiveDate"] = DateTime.Now;//生效日期
entryEntitys.Add(entry);
}
ISaveService saveService = Kingdee.BOS.App.ServiceHelper.GetService();
DynamicObject[] objs = new DynamicObject[1];
objs[0] = XydaObject;
IOperationResult result = saveService.Save(this.Context, XydaInfo, objs);
if ((result.ValidationErrors != null && result.ValidationErrors.Count > 0))
{
result.IsSuccess = false;
StringBuilder errorMessage = new StringBuilder();
errorMessage.AppendLine("保存失败!");
foreach (Kingdee.BOS.Core.Validation.ValidationErrorInfo error in result.ValidationErrors.ToArray())
{
errorMessage.AppendLine(error.Message);
}
throw new KDBusinessException("zx-001", errorMessage.ToString());
}
//提交并审核
ISubmitService submitService = Kingdee.BOS.App.ServiceHelper.GetService();
IOperationResult submitResult =submitService.Submit(this.Context, XydaInfo, new object[] { XydaObject[0] }, "Submit");
if ((submitResult.ValidationErrors != null && submitResult.ValidationErrors.Count > 0))
{
submitResult.IsSuccess = false;
StringBuilder errorMessage = new StringBuilder();
errorMessage.AppendLine("提交失败!");
foreach (Kingdee.BOS.Core.Validation.ValidationErrorInfo error in submitResult.ValidationErrors.ToArray())
{
errorMessage.AppendLine(error.Message);
}
throw new KDBusinessException("zx-001", errorMessage.ToString());
}
//IOperationResult auditResult = setStatusService.SetBillStatus(this.Context, XydaInfo, lstKeyValuePairs, null, "Audit");
IOperationResult auditResult = BusinessDataServiceHelper.SetBillStatus(this.Context, XydaInfo, lstKeyValuePairs, null, "Audit");
if ((auditResult.ValidationErrors != null && auditResult.ValidationErrors.Count > 0))
{
auditResult.IsSuccess = false;
StringBuilder errorMessage = new StringBuilder();
errorMessage.AppendLine("审核失败!");
foreach (Kingdee.BOS.Core.Validation.ValidationErrorInfo error in result.ValidationErrors.ToArray())
{
errorMessage.AppendLine(error.Message);
}
throw new KDBusinessException("zx-001", errorMessage.ToString());
}
}
//结束反审核
}
//3.1、如果都存在 通过获取的信用档案ID 获取对象,做修改分录数据
//3.2、如果只存在部门,通过获取的信用档案ID 获取对象,增加分录数据
}
}
}
} // EndOperationTransaction end
}
}