合并两个工位的 ERP 页面、存储过程及测试工具,分离 8010 与 9528 工位配置
This commit is contained in:
83
server/AIEmployee/App_Code/OutsourcingDrafts.cs
Normal file
83
server/AIEmployee/App_Code/OutsourcingDrafts.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
|
||||
namespace Jingyao.AIEmployee
|
||||
{
|
||||
public sealed partial class PersonalInboxHandler
|
||||
{
|
||||
const string DraftList = "ai_外协单位与加工草稿";
|
||||
const string DraftDetail = DraftList + "_草稿详情";
|
||||
const string DraftSave = DraftDetail + "_保存";
|
||||
const string DraftRehearsal = DraftList + "_软件演练";
|
||||
|
||||
static bool IsDraft(string name)
|
||||
{
|
||||
return name == DraftList || name == DraftDetail || name == DraftSave || name == DraftRehearsal;
|
||||
}
|
||||
|
||||
static void BindIdempotency(SqlCommand command, Dictionary<string,object> inputs)
|
||||
{
|
||||
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 int DraftNumber(Dictionary<string,object> inputs, string field, bool allowZero)
|
||||
{
|
||||
object value;
|
||||
if (allowZero && inputs.TryGetValue(field, out value) &&
|
||||
(Object.Equals(value, 0) || Object.Equals(value,"0"))) return 0;
|
||||
return (int)Positive(inputs, field, Int32.MaxValue, 0);
|
||||
}
|
||||
|
||||
static void BindDraft(SqlCommand command, string name, Dictionary<string,object> inputs, Dictionary<string,object> body)
|
||||
{
|
||||
if (name == DraftRehearsal) { Only(inputs); return; }
|
||||
AddText(command, inputs, "类型", 10, null, "vendor", "process");
|
||||
if (name == DraftList) {
|
||||
Only(inputs, "类型");
|
||||
command.Parameters.Add("@页码", SqlDbType.Int).Value = (int)Positive(body, "pageList", 100000, 1);
|
||||
command.Parameters.Add("@每页条数", SqlDbType.Int).Value = (int)Positive(body, "pageSize", 200, 25);
|
||||
return;
|
||||
}
|
||||
bool save = name == DraftSave;
|
||||
command.Parameters.Add("@编号", SqlDbType.Int).Value = DraftNumber(inputs,"编号",save);
|
||||
command.Parameters.Add("@版本", SqlDbType.Int).Value = DraftNumber(inputs,"版本",save);
|
||||
if (!save) { Only(inputs,"类型","编号","版本"); return; }
|
||||
Only(inputs, "类型","编号","版本","资料XML","幂等键");
|
||||
if (body.ContainsKey("pageList") || body.ContainsKey("pageSize")) throw BadInput();
|
||||
string xml = Text(inputs, "资料XML", 12000, null);
|
||||
var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Prohibit, XmlResolver = null, MaxCharactersInDocument = 12000 };
|
||||
try {
|
||||
using (var reader = XmlReader.Create(new StringReader(xml), settings)) {
|
||||
if (reader.MoveToContent() != XmlNodeType.Element || reader.Name != "draft") throw BadInput();
|
||||
while (reader.Read()) { }
|
||||
}
|
||||
} catch (XmlException) { throw BadInput(); }
|
||||
command.Parameters.Add("@资料XML", SqlDbType.NVarChar, -1).Value = xml;
|
||||
BindIdempotency(command, inputs);
|
||||
}
|
||||
|
||||
static object ReadDraft(SqlCommand command, string name, SqlDataReader reader)
|
||||
{
|
||||
if (name == DraftList) return ReadPageWithSummary(command, reader, false);
|
||||
if (name == DraftDetail) {
|
||||
var records = ReadRows(reader, 1);
|
||||
var checks = NextRows(reader, 64);
|
||||
if (records.Count != 1 || checks.Count == 0 || reader.NextResult()) throw Unavailable();
|
||||
return new { record = records[0], checks = checks };
|
||||
}
|
||||
int expected = name == DraftSave ? 1 : 7;
|
||||
var rows = ReadRows(reader, expected);
|
||||
if (rows.Count != expected || reader.NextResult()) throw Unavailable();
|
||||
return new { rows = rows };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user