85 lines
4.6 KiB
C#
85 lines
4.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Globalization;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Jingyao.AIEmployee
|
|
{
|
|
public sealed partial class PersonalInboxHandler
|
|
{
|
|
const string ReportCreate="ai_报工申请与复核_建立申请", ReportLine="ai_报工申请与复核_登记明细", ReportTransition="ai_报工申请与复核_办理";
|
|
static bool MesReportAction(string name) { return name==ReportCreate || name==ReportLine || name==ReportTransition; }
|
|
|
|
static void MesVersion(SqlCommand command,Dictionary<string,object> input,string field)
|
|
{
|
|
string value=Text(input,field,18,null);
|
|
if (!Regex.IsMatch(value,@"\A(?:0x)?[0-9A-Fa-f]{16}\z")) throw BadInput();
|
|
if(value.Length==18) value=value.Substring(2);
|
|
byte[] bytes=new byte[8];
|
|
for(int i=0;i<8;i++) bytes[i]=Byte.Parse(value.Substring(i*2,2),NumberStyles.HexNumber,Invariant);
|
|
command.Parameters.Add("@"+field,SqlDbType.Binary,8).Value=bytes;
|
|
}
|
|
|
|
static decimal MesQuantity(SqlCommand command,Dictionary<string,object> input,string field,byte scale)
|
|
{
|
|
object raw; decimal value;
|
|
if (!input.TryGetValue(field,out raw) || raw==null ||
|
|
!Decimal.TryParse(Convert.ToString(raw,Invariant),NumberStyles.AllowDecimalPoint,Invariant,out value) ||
|
|
value<0 || value!=Decimal.Round(value,scale) || value>=(scale==4 ? 100000000000000m : 10000000000000000m)) throw BadInput();
|
|
var p=command.Parameters.Add("@"+field,SqlDbType.Decimal);p.Precision=18;p.Scale=scale;p.Value=value;
|
|
return value;
|
|
}
|
|
|
|
static void BindMesReport(SqlCommand command,string name,Dictionary<string,object> inputs)
|
|
{
|
|
if (name==ReportCreate) {
|
|
Only(inputs,"开工门禁流水号","预期门禁版本","幂等键");
|
|
ReworkKey(command,inputs,"开工门禁流水号");
|
|
} else if (name==ReportLine) {
|
|
Only(inputs,"报工申请流水号","报工明细流水号","完成数量","合格数量","不合格数量","实际分钟","报工证据","预期申请版本","预期明细版本","预期门禁版本","幂等键");
|
|
ReworkKey(command,inputs,"报工申请流水号");ReworkKey(command,inputs,"报工明细流水号");
|
|
decimal completed=MesQuantity(command,inputs,"完成数量",4), good=MesQuantity(command,inputs,"合格数量",4), bad=MesQuantity(command,inputs,"不合格数量",4);
|
|
if (completed<=0 || good+bad!=completed || MesQuantity(command,inputs,"实际分钟",2)<=0) throw BadInput();
|
|
AddText(command,inputs,"报工证据",1000,null);
|
|
MesVersion(command,inputs,"预期申请版本");MesVersion(command,inputs,"预期明细版本");
|
|
} else {
|
|
Only(inputs,"报工申请流水号","动作","意见","确认声明","预期版本","预期门禁版本","幂等键");
|
|
ReworkKey(command,inputs,"报工申请流水号");
|
|
string action=Text(inputs,"动作",30,null);
|
|
if (Array.IndexOf(new[]{"SUBMIT","APPROVE","REJECT","REVISE","POST"},action)<0) throw BadInput();
|
|
AddText(command,inputs,"动作",30,null);AddText(command,inputs,"意见",1000,"");AddText(command,inputs,"确认声明",100,"");
|
|
MesVersion(command,inputs,"预期版本");
|
|
}
|
|
MesVersion(command,inputs,"预期门禁版本");
|
|
BindIdempotency(command,inputs,true);
|
|
}
|
|
|
|
static void FormatMesBinaryFields(Dictionary<string,object> row)
|
|
{
|
|
foreach (string key in new List<string>(row.Keys)) {
|
|
byte[] value = row[key] as byte[];
|
|
if (value != null) row[key] = "0x" + BitConverter.ToString(value).Replace("-","");
|
|
}
|
|
}
|
|
|
|
static bool IsMesNavigationRead(string name)
|
|
{
|
|
string[] routes;
|
|
return NavigationRoutes.TryGetValue(name,out routes) &&
|
|
Array.Exists(routes,route => route.StartsWith("/mes/",StringComparison.Ordinal));
|
|
}
|
|
|
|
static object MesReportReceipt(SqlDataReader reader)
|
|
{
|
|
var rows=ReadRows(reader,1);
|
|
if(rows.Count!=1 || reader.NextResult()) throw Unavailable();
|
|
var row=rows[0];object replay;
|
|
if(!row.TryGetValue("是否幂等返回",out replay) || !(replay is bool)) throw Unavailable();
|
|
FormatMesBinaryFields(row);
|
|
return new { record=row, idempotent=(bool)replay };
|
|
}
|
|
}
|
|
}
|