Commit 0f8e711c by 陶然

优化

parent 7562303f
...@@ -3,6 +3,7 @@ using Kivii.Finances.Entities; ...@@ -3,6 +3,7 @@ using Kivii.Finances.Entities;
using Kivii.Finances.Seeyon.Extensions; using Kivii.Finances.Seeyon.Extensions;
using Kivii.Linq; using Kivii.Linq;
using Kivii.Seeyon; using Kivii.Seeyon;
using Kivii.Seeyon.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -72,6 +73,67 @@ namespace Kivii.Finances.Seeyon.Entities ...@@ -72,6 +73,67 @@ namespace Kivii.Finances.Seeyon.Entities
return rtns; return rtns;
} }
public object OnGetApplyResult(List<Guid> Kvids, object Result, string Message)
{
if (Kvids.IsNullOrEmpty()) throw new Exception("缺少业务编号!");
if (Result == null) throw new Exception("缺少审批结果信息");
var conn = KiviiContext.GetOpenedDbConnection<InvoiceApply>();
var rtns = new RestfulExecutionResponse<InvoiceApply>();
rtns.Results = new List<InvoiceApply>();
var applys = conn.SelectByIds<InvoiceApply>(Kvids);
if (applys.IsNullOrEmpty()) throw new Exception("未找到此业务信息!");
//var apply = conn.SingleById<InvoiceApply>(Kvids);
//if (apply == null) throw new Exception("未找到此业务信息!");
var result = Result.ToString();
foreach (var apply in applys)
{
if (apply.Metadata.IsNullOrEmpty()) apply.Metadata = new Dictionary<string, string>();
EntityLog<InvoiceApply> log = null;
if (result == "审批通过")
{
apply.Metadata["SeeyonResult"] = result;
apply.AddOnlyProperties(o => o.Metadata);
if (apply.Status == (int)InvoiceApplyStatus.ProcessAdoption)
{
apply.Status = (int)InvoiceApplyStatus.FinancialApproval;
apply.AddOnlyProperties(o => o.Status);
log = new EntityLog<InvoiceApply>();
log.OwnerKvid = apply.Kvid;
log.Title = "账单借票";
log.Type = "流转";
log.Summary = "OA审批通过,可进行开票";
log.Remark = Message;
log.CreatorName = "OA审批";
}
}
else if (result == "审批不通过")
{
apply.Metadata["SeeyonResult"] = result;
apply.Metadata["SeeyonMessage"] = Message;
apply.AddOnlyProperties(o => o.Metadata);
if (apply.Status == (int)InvoiceApplyStatus.ProcessAdoption)
{
apply.Status = (int)InvoiceApplyStatus.ApplyReject;
apply.AddOnlyProperties(o => o.Status);
log = new EntityLog<InvoiceApply>();
log.OwnerKvid = apply.Kvid;
log.Title = "账单借票";
log.Type = "流转";
log.Summary = "OA审批不通过,驳回了账单借票审批";
log.Remark = Message;
log.CreatorName = "OA审批";
}
}
if (log != null) conn.Insert(log);
if (!apply.OnlyProperties.IsNullOrEmpty())
{
conn.UpdateOnly(apply);
rtns.Results.Add(apply);
}
}
return rtns;
}
public object OnSubmitApplyForm<T>(Guid Kvid) public object OnSubmitApplyForm<T>(Guid Kvid)
{ {
Kvid.ThrowIfEmpty("请传入要申请的账单借票信息!"); Kvid.ThrowIfEmpty("请传入要申请的账单借票信息!");
...@@ -107,8 +169,60 @@ namespace Kivii.Finances.Seeyon.Entities ...@@ -107,8 +169,60 @@ namespace Kivii.Finances.Seeyon.Entities
public object OnSubmitApplyForm<T>(T form) public object OnSubmitApplyForm<T>(T form)
{ {
return null; form.ThrowIfNull("请传入借票信息!");
var formApply = form as BillApply;
formApply.ThrowIfNull("传入的借票信息不能为空!");
var kvids = formApply.Kvids;
var conn = KiviiContext.GetOpenedDbConnection<InvoiceApply>();
var applys = conn.SelectByIds<InvoiceApply>(kvids);
applys.ThrowIfNullOrEmpty("未找到借票信息!");
if (applys.Exists(o => o.Status > (int)InvoiceApplyStatus.ProcessAdoption)) throw new Exception("当前账单借票非待审批状态,无法申请审批!");
var groupPayer = applys.GroupBy(a => a.PayerName);
if (groupPayer.Count() != 1) throw new Exception("不允许多个借票抬头同时申请!");
var applySum = new InvoiceApply();
applySum.PopulateWith(applys[0]);
applySum.Amount = applys.Sum(a => a.Amount);
applySum.Remark = applys[0].Remark;
var applyForm = applySum.ConvertToForm();
var bizKvids = applys.ConvertAll(o => o.Kvid);
var strBizKvids = string.Join(",", bizKvids);
applyForm.业务编号 = strBizKvids;
var session = KiviiContext.Request.GetSession();
var client = new JsonServiceClient(Configs.BaseUrl);
var resp = client.RequestBillForm(applyForm, session);
if (resp.code != "0") throw new Exception($"OA接口调用失败,原因:{resp.message}");
var rtns = new RestfulUpdateResponse<InvoiceApply>();
rtns.Results = new List<InvoiceApply>();
foreach (var apply in applys)
{
apply.BizId = resp.data.subject;
apply.AddOnlyProperties(o => o.BizId);
apply.BizType = typeof(BillApply).FullName;
apply.AddOnlyProperties(o => o.BizType);
apply.Status = (int)InvoiceApplyStatus.ProcessAdoption;
apply.AddOnlyProperties(o => o.Status);
conn.UpdateOnly(apply);
var _log = new EntityLog<InvoiceApply>();
_log.OwnerKvid = apply.Kvid;
_log.Title = "账单借票";
_log.Type = "流转";
_log.Summary = $"提交了账单借票,审批将在OA执行";
conn.Insert(_log);
rtns.Results.Add(apply);
}
return rtns;
} }
[Ignore]
public List<Guid> Kvids { get; set; }
} }
public class RequestForm_InvoiceApply public class RequestForm_InvoiceApply
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment