75 lines
4.2 KiB
C#
75 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Jingyao.AIEmployee
|
|
{
|
|
public sealed partial class PersonalInboxHandler
|
|
{
|
|
const string PayableList = "ai_采购与应付来源核对";
|
|
const string PayableDetail = "ai_采购与应付来源核对_来源单详情";
|
|
const string PayableSuppliers = "ai_采购与应付来源核对_来源单详情_供应商查询";
|
|
const string PayableConfirm = "ai_采购与应付来源核对_来源单详情_确认接管";
|
|
|
|
static bool IsPayableSource(string name)
|
|
{
|
|
return name == PayableList || name == PayableDetail || name == PayableSuppliers || name == PayableConfirm;
|
|
}
|
|
|
|
static void PayableVersion(SqlCommand command, Dictionary<string, object> inputs, string field)
|
|
{
|
|
string version = Text(inputs, field, 16, null);
|
|
if (!Regex.IsMatch(version, @"\A[0-9A-Fa-f]{16}\z")) throw BadInput();
|
|
command.Parameters.Add("@" + field, SqlDbType.VarChar, 16).Value = version.ToUpperInvariant();
|
|
}
|
|
|
|
static void BindPayableSource(SqlCommand command, string name, Dictionary<string,object> inputs, Dictionary<string,object> body)
|
|
{
|
|
if (name == PayableList || name == PayableSuppliers) {
|
|
if (name == PayableList) {
|
|
Only(inputs, "来源类型", "状态", "关键字");
|
|
AddText(command, inputs, "来源类型", 20, null, "PURCHASE_ORDER", "PAYABLE");
|
|
AddText(command, inputs, "状态", 12, null, "PENDING", "CONFIRMED", "ALL");
|
|
} else Only(inputs, "关键字");
|
|
AddText(command, inputs, "关键字", 100, "");
|
|
command.Parameters.Add("@页码", SqlDbType.Int).Value = (int)Positive(body, "pageList", 100000, 1);
|
|
command.Parameters.Add("@每页条数", SqlDbType.Int).Value = (int)Positive(body, "pageSize", 200, 20);
|
|
return;
|
|
}
|
|
AddText(command, inputs, "来源类型", 20, null, "PURCHASE_ORDER", "PAYABLE");
|
|
command.Parameters.Add("@来源流水号", SqlDbType.Int).Value = (int)Positive(inputs, "来源流水号", Int32.MaxValue, 0);
|
|
if (name == PayableDetail) {
|
|
Only(inputs, "来源类型", "来源流水号");
|
|
return;
|
|
}
|
|
if (name != PayableConfirm || body.ContainsKey("pageList") || body.ContainsKey("pageSize")) throw BadInput();
|
|
Only(inputs, "来源类型", "来源流水号", "供应商流水号", "预期版本", "关联订单预期版本", "接管依据", "幂等键");
|
|
command.Parameters.Add("@供应商流水号", SqlDbType.Int).Value = (int)Positive(inputs, "供应商流水号", Int32.MaxValue, 0);
|
|
PayableVersion(command, inputs, "预期版本");
|
|
if ((string)command.Parameters["@来源类型"].Value == "PAYABLE") PayableVersion(command, inputs, "关联订单预期版本");
|
|
else if (inputs.ContainsKey("关联订单预期版本")) throw BadInput();
|
|
AddText(command, inputs, "接管依据", 1000, null);
|
|
string key = Text(inputs, "幂等键", 100, null);
|
|
if (!Regex.IsMatch(key, @"\A[A-Za-z0-9_.:-]+\z")) throw BadInput();
|
|
command.Parameters.Add("@幂等键", SqlDbType.VarChar, 100).Value = key;
|
|
string fingerprint = RequestFingerprint(command);
|
|
command.Parameters.Add("@请求指纹", SqlDbType.Char, 64).Value = fingerprint;
|
|
}
|
|
|
|
static object ReadPayableSource(SqlCommand command, string name, SqlDataReader reader)
|
|
{
|
|
if (name == PayableList || name == PayableSuppliers) return ReadPageWithSummary(command, reader, false);
|
|
var header = ReadRows(reader, 1);
|
|
if (name == PayableConfirm) {
|
|
if (header.Count != 1 || reader.NextResult()) throw Unavailable();
|
|
return new { rows = header };
|
|
}
|
|
var audit = NextRows(reader, Int32.MaxValue);
|
|
if (reader.NextResult() || (header.Count == 0 && audit.Count != 0)) throw Unavailable();
|
|
return new { record = header.Count == 0 ? null : header[0], audit = audit };
|
|
}
|
|
}
|
|
}
|