合并两个工位的 ERP 页面、存储过程及测试工具,分离 8010 与 9528 工位配置
This commit is contained in:
133
server/AIEmployee/App_Code/LegacyCommercial.cs
Normal file
133
server/AIEmployee/App_Code/LegacyCommercial.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
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 LegacyList = "ai_旧订单商务与回款核验";
|
||||
const string LegacySource = LegacyList + "_商务来源", LegacyCash = LegacyList + "_回款记录", LegacyFinance = LegacyList + "_财务决定";
|
||||
const string LegacyRegister = LegacySource + "_登记", LegacyVerify = LegacyCash + "_登记核验", LegacyDecide = LegacyFinance + "_登记";
|
||||
|
||||
static bool LegacyWrite(string name) { return name == LegacyRegister || name == LegacyVerify || name == LegacyDecide; }
|
||||
static bool IsLegacy(string name)
|
||||
{
|
||||
return name == LegacyList || name == LegacySource || name == LegacyCash || name == LegacyFinance || LegacyWrite(name);
|
||||
}
|
||||
|
||||
static void LegacyVersion(SqlCommand command, Dictionary<string,object> fields, string key)
|
||||
{
|
||||
string value = Text(fields,key,64,null);
|
||||
if (!Revision.IsMatch(value)) throw BadInput();
|
||||
command.Parameters.Add("@" + key,SqlDbType.VarChar,64).Value = value;
|
||||
}
|
||||
|
||||
static void LegacyAmount(SqlCommand command, Dictionary<string,object> fields, string key)
|
||||
{
|
||||
string value = Text(fields,key,19,null);
|
||||
if (!Regex.IsMatch(value,@"\A(?:0|[1-9][0-9]{0,15})(?:\.[0-9]{1,2})?\z")) throw BadInput();
|
||||
command.Parameters.Add("@" + key,SqlDbType.VarChar,19).Value = value;
|
||||
}
|
||||
|
||||
static void BindLegacy(SqlCommand command, string name, Dictionary<string,object> inputs, Dictionary<string,object> body)
|
||||
{
|
||||
if (name == LegacyList) {
|
||||
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",100,20);
|
||||
return;
|
||||
}
|
||||
command.Parameters.Add("@旧项目流水号", SqlDbType.Int).Value = (int)Positive(inputs,"旧项目流水号",Int32.MaxValue,0);
|
||||
if (name == LegacySource || name == LegacyRegister) {
|
||||
ReworkKey(command,inputs,"装配计划流水号"); ReworkKey(command,inputs,"旧订单装配基线流水号");
|
||||
} else ReworkKey(command,inputs,"商务承接流水号");
|
||||
if (name == LegacyRegister || name == LegacyFinance || name == LegacyDecide)
|
||||
command.Parameters.Add("@旧订单流水号",SqlDbType.Int).Value = (int)Positive(inputs,"旧订单流水号",Int32.MaxValue,0);
|
||||
if (!LegacyWrite(name)) {
|
||||
if (name == LegacySource) Only(inputs,"装配计划流水号","旧订单装配基线流水号","旧项目流水号");
|
||||
else if (name == LegacyFinance) Only(inputs,"商务承接流水号","旧项目流水号","旧订单流水号");
|
||||
else Only(inputs,"商务承接流水号","旧项目流水号");
|
||||
return;
|
||||
}
|
||||
if (body.ContainsKey("pageList") || body.ContainsKey("pageSize")) throw BadInput();
|
||||
if (inputs.ContainsKey("预期前版流水号")) ReworkKey(command,inputs,"预期前版流水号");
|
||||
else command.Parameters.Add("@预期前版流水号",SqlDbType.BigInt).Value = DBNull.Value;
|
||||
string statement;
|
||||
if (name == LegacyRegister) {
|
||||
Only(inputs,"装配计划流水号","旧订单装配基线流水号","旧订单流水号","旧项目流水号","组件流水号","预期制造来源版本",
|
||||
"预期商务来源版本","预期前版流水号","金额口径","合同金额文本","合同依据来源","收货地址","收货联系人","收货联系电话","商务确认依据","幂等键");
|
||||
command.Parameters.Add("@组件流水号",SqlDbType.Int).Value = (int)Positive(inputs,"组件流水号",Int32.MaxValue,0);
|
||||
LegacyVersion(command,inputs,"预期制造来源版本"); LegacyVersion(command,inputs,"预期商务来源版本");
|
||||
AddText(command,inputs,"金额口径",20,null,"TAX_INCLUDED","TAX_EXCLUDED");
|
||||
LegacyAmount(command,inputs,"合同金额文本");
|
||||
AddText(command,inputs,"合同依据来源",30,null,"LEGACY_REVISION","LEGACY_HEADER");
|
||||
AddText(command,inputs,"收货地址",300,null); AddText(command,inputs,"收货联系人",100,null);
|
||||
AddText(command,inputs,"收货联系电话",100,null); AddText(command,inputs,"商务确认依据",1000,null);
|
||||
statement = "REGISTER_LEGACY_COMMERCIAL_SNAPSHOT_NOT_RELEASE";
|
||||
} else if (name == LegacyVerify) {
|
||||
Only(inputs,"商务承接流水号","旧项目流水号","旧收款记录流水号","预期旧记录版本","预期前版流水号","核验结论","核验金额文本","核验依据","幂等键");
|
||||
command.Parameters.Add("@旧收款记录流水号",SqlDbType.Int).Value = (int)Positive(inputs,"旧收款记录流水号",Int32.MaxValue,0);
|
||||
LegacyVersion(command,inputs,"预期旧记录版本");
|
||||
AddText(command,inputs,"核验结论",20,null,"CONFIRMED","REJECTED");
|
||||
if (Text(inputs,"核验结论",20,null) == "CONFIRMED") LegacyAmount(command,inputs,"核验金额文本");
|
||||
else if (inputs.ContainsKey("核验金额文本")) throw BadInput();
|
||||
else command.Parameters.Add("@核验金额文本",SqlDbType.VarChar,19).Value = DBNull.Value;
|
||||
AddText(command,inputs,"核验依据",1000,null); statement = "VERIFY_LEGACY_CASH_EVIDENCE_NOT_SHIPMENT_RELEASE";
|
||||
} else {
|
||||
Only(inputs,"商务承接流水号","旧订单流水号","旧项目流水号","预期商务来源版本","预期回款证据版本","预期前版流水号","结论","复核意见","幂等键");
|
||||
LegacyVersion(command,inputs,"预期商务来源版本"); LegacyVersion(command,inputs,"预期回款证据版本");
|
||||
AddText(command,inputs,"结论",20,null,"APPROVED","REJECTED"); AddText(command,inputs,"复核意见",1000,null);
|
||||
statement = Text(inputs,"结论",20,null) == "APPROVED" ? "APPROVE_LEGACY_SHIPMENT_FINANCE_ONLY" : "REJECT_LEGACY_SHIPMENT_FINANCE_ONLY";
|
||||
}
|
||||
command.Parameters.Add("@确认声明",SqlDbType.NVarChar,100).Value = statement;
|
||||
BindIdempotency(command,inputs);
|
||||
}
|
||||
|
||||
static void LegacyMoney(Dictionary<string,object> row)
|
||||
{
|
||||
foreach (string key in new[] {"原记录数量","待核验数量","来源丢失数量"}) {
|
||||
object count;
|
||||
if (!row.TryGetValue(key,out count)) continue;
|
||||
int value;
|
||||
if (!Int32.TryParse(Convert.ToString(count,Invariant),out value) || value < 0) throw Unavailable();
|
||||
row[key] = value;
|
||||
}
|
||||
foreach (string key in new[] {"合同金额","核验金额","已核验回款合计"}) {
|
||||
object value;
|
||||
if (!row.TryGetValue(key,out value)) continue;
|
||||
if (value != null && (!(value is decimal) || (decimal)value < 0 || Decimal.Round((decimal)value,2) != (decimal)value)) throw Unavailable();
|
||||
row[key + "文本"] = value == null ? null : ((decimal)value).ToString("0.00",Invariant);
|
||||
}
|
||||
object approximate;
|
||||
if (row.TryGetValue("原金额",out approximate))
|
||||
row["原金额近似文本"] = approximate == null ? null : Convert.ToDouble(approximate,Invariant).ToString("R",Invariant);
|
||||
}
|
||||
|
||||
static object ReadLegacy(SqlCommand command, string name, SqlDataReader reader)
|
||||
{
|
||||
if (name == LegacyList) return ReadPageWithSummary(command, reader, false);
|
||||
var first = ReadRows(reader,1);
|
||||
if (first.Count != 1) throw Unavailable();
|
||||
LegacyMoney(first[0]);
|
||||
if (LegacyWrite(name)) {
|
||||
if (reader.NextResult()) throw Unavailable();
|
||||
return new { rows = first };
|
||||
}
|
||||
var second = NextRows(reader,name == LegacyCash ? Int32.MaxValue : 1);
|
||||
foreach (var row in second) LegacyMoney(row);
|
||||
if (name == LegacyCash) {
|
||||
var summary = NextRows(reader,1);
|
||||
if (summary.Count != 1 || reader.NextResult()) throw Unavailable();
|
||||
LegacyMoney(summary[0]);
|
||||
return new { source = first[0], records = second, summary = summary[0] };
|
||||
}
|
||||
if (reader.NextResult()) throw Unavailable();
|
||||
if (name == LegacySource) return new { source = first[0], registration = second.Count == 0 ? null : second[0] };
|
||||
return new { source = first[0], decision = second.Count == 0 ? null : second[0] };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user