Files
JY1.0/server/AIEmployee/App_Code/MesAssemblyDisposition.cs

65 lines
7.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
namespace Jingyao.AIEmployee
{
public sealed partial class PersonalInboxHandler
{
static readonly Dictionary<string,string[]> AssemblyForms=new Dictionary<string,string[]>(StringComparer.Ordinal) {
{ "ai_报工质量终判_组装质量处置_安排返工", new[] { "确认安排返工","ncrId|@不合格流水号|id;reason|@依据|text|1000;evidenceReference|@依据引用|text|500;evidenceHash|@依据哈希|text|64;quantity|@数量|positive;workerId|@执行人编号|id","","/qms/final-decision","REWORK_ASSIGN" } },
{ "ai_报工质量终判_组装质量处置_申请处置", new[] { "确认申请处置","ncrId|@不合格流水号|id;reason|@依据|text|1000;evidenceReference|@依据引用|text|500;evidenceHash|@依据哈希|text|64;kind|@处置类型|enum;quantity|@数量|positive","SCRAP|CONCESSION","/qms/final-decision","DISPOSITION_REQUEST" } },
{ "ai_报工质量终判_组装质量处置_审批处置", new[] { "确认审批处置","ncrId|@不合格流水号|id;reason|@依据|text|1000;evidenceReference|@依据引用|text|500;evidenceHash|@依据哈希|text|64;requestId|@处置申请流水号|id;expectedVersion|@预期版本|version;decision|@结论|enum","APPROVE|REJECT","/qms/final-decision","DISPOSITION_REVIEW" } },
{ "ai_报工质量终判_组装质量处置_确认报废实物", new[] { "确认实际报废处置","ncrId|@不合格流水号|id;reason|@依据|text|1000;evidenceReference|@依据引用|text|500;evidenceHash|@依据哈希|text|64;requestId|@处置申请流水号|id;expectedVersion|@预期版本|version;expectedConfirmedQuantity|@预期已处置数量|nonnegative;quantity|@数量|positive;occurredAtUtc|@处置时间UTC|utc","","/qms/final-decision","SCRAP_CONFIRM" } },
{ "ai_通用件装配返工_返工执行_核对准备", new[] { "确认返工准备","workId|@返工任务流水号|id;expectedVersion|@预期执行版本|version?;reason|@依据|text|1000;materialEvidence|@物料依据|text|1000;checkResult|@检查结果|enum;validUntilUtc|@有效截止UTC|utc","PASS|BLOCKED","/mes/assembly-rework","PREPARE" } },
{ "ai_通用件装配返工_返工执行_开工", new[] { "确认返工开工","workId|@返工任务流水号|id;expectedVersion|@预期执行版本|version;reason|@依据|text?|1000","","/mes/assembly-rework","START" } },
{ "ai_通用件装配返工_返工执行_暂停", new[] { "确认返工暂停","workId|@返工任务流水号|id;expectedVersion|@预期执行版本|version;reason|@依据|text?|1000;pauseReason|@暂停原因|enum","OFF_DUTY|BREAK|DOWNTIME|OTHER","/mes/assembly-rework","PAUSE" } },
{ "ai_通用件装配返工_返工执行_恢复", new[] { "确认返工恢复","workId|@返工任务流水号|id;expectedVersion|@预期执行版本|version;reason|@依据|text?|1000","","/mes/assembly-rework","RESUME" } },
{ "ai_通用件装配返工_返工执行_报工", new[] { "确认返工报工","workId|@返工任务流水号|id;expectedVersion|@预期执行版本|version;reason|@依据|text?|1000;quantity|@报工数量|positive;selfQualifiedQuantity|@自检合格数量|nonnegative;pendingQuantity|@不合格待处理数量|nonnegative;exception|@异常说明|text?|1000","","/mes/assembly-rework","REPORT" } },
{ "ai_通用件装配返工_返工执行_送检", new[] { "确认返工送检","workId|@返工任务流水号|id;expectedVersion|@预期执行版本|version;reason|@依据|text|1000","","/mes/assembly-rework","SEND" } },
{ "ai_报工质量终判_组装质量处置_接收复检", new[] { "确认接收复检","workId|@返工任务流水号|id;expectedVersion|@预期执行版本|version;reason|@依据|text|1000;expectedTaskVersion|@预期送检版本|version","","/qms/final-decision","ACCEPT" } },
};
static void RegisterAssemblyDisposition()
{
foreach(var entry in AssemblyForms) MesWorkRoutes.Add(entry.Key,entry.Value[3]);
NavigationRoutes.Add("ai_通用件装配返工_返工任务_查询",new[] { "/mes/assembly-rework" });
MesResultSets.Add("ai_通用件装配返工_返工任务_查询",new[] { "context","checks","reports","audit" });
}
static bool BindAssemblyForm(SqlCommand command,string name,Dictionary<string,object> inputs)
{
string[] spec;
if (!AssemblyForms.TryGetValue(name,out spec)) return false;
BindQualityForm(command,inputs,spec);
if (command.Parameters.Contains("@执行人编号") && Convert.ToInt64(command.Parameters["@执行人编号"].Value,Invariant)>Int32.MaxValue) throw BadInput();
string op=spec[4];
if (inputs.ContainsKey("依据哈希") && !System.Text.RegularExpressions.Regex.IsMatch(Text(inputs,"依据哈希",64,null),"^[A-Fa-f0-9]{64}$")) throw BadInput();
if (op=="PAUSE" && Text(inputs,"暂停原因",30,null)=="OTHER" && String.IsNullOrWhiteSpace(Text(inputs,"依据",1000,""))) throw BadInput();
if (op=="ACCEPT" && Text(inputs,"依据",1000,"").Trim().Length<10) throw BadInput();
if (op=="REPORT") {
long good=Convert.ToInt64(command.Parameters["@自检合格数量"].Value,Invariant),bad=Convert.ToInt64(command.Parameters["@不合格待处理数量"].Value,Invariant);
if (good+bad!=Convert.ToInt64(command.Parameters["@报工数量"].Value,Invariant) || (bad>0 && String.IsNullOrWhiteSpace(Text(inputs,"异常说明",1000,"")))) throw BadInput();
}
return true;
}
static object AssemblyDispositionReceipt(SqlDataReader reader,SqlCommand command,string name)
{
var rows=ReadRows(reader,1);
if (rows.Count!=1 || reader.NextResult()) throw Unavailable();
var row=rows[0];var op=AssemblyForms[name][4];
if (!Object.Equals(row["本次动作"],op) || Convert.ToString(row["本次操作人"],Invariant)!=Convert.ToString(command.Parameters["@人员编号"].Value,Invariant) || !Object.Equals(row["幂等键"],command.Parameters["@幂等键"].Value)) throw Unavailable();
foreach(string key in new[] { "返工任务流水号","不合格流水号","处置申请流水号" }) {
if(command.Parameters.Contains("@"+key) && Convert.ToInt64(row[key],Invariant)!=Convert.ToInt64(command.Parameters["@"+key].Value,Invariant)) throw Unavailable();
}
if (Convert.ToInt64(row[command.Parameters.Contains("@返工任务流水号")?"返工任务流水号":"处置申请流水号"],Invariant)<=0) throw Unavailable();
if (op=="SCRAP_CONFIRM" && (Convert.ToInt64(row["报废确认流水号"],Invariant)<=0 || Convert.ToInt32(row["本次确认数量"],Invariant)!=Convert.ToInt32(command.Parameters["@数量"].Value,Invariant) || !Object.Equals(row["库存变更"],false))) throw Unavailable();
bool repeat=(bool)row["是否幂等返回"];
FormatMesBinaryFields(row);
return new { record=row,idempotent=repeat,refreshRequired=true,productionReady=false };
}
}
}