218 lines
7.7 KiB
C#
218 lines
7.7 KiB
C#
using AppData;
|
|
using Newtonsoft.Json;
|
|
using NKC_SDK;
|
|
using SteamWare;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Web.Http;
|
|
|
|
namespace NKC_WF.Controllers
|
|
{
|
|
public class PrintQueueController : ApiController
|
|
{
|
|
#region classi gestione PJQ
|
|
|
|
/// <summary>
|
|
/// chaive redis x cache conteggio coda PJQ
|
|
/// </summary>
|
|
internal static string redQueueCount = "NKC:SERV:PJQ";
|
|
/// <summary>
|
|
/// Conteggio elementi in attesa stsampa da DB
|
|
/// </summary>
|
|
protected int countWaitingDb
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
// resetto conteggio in redis...
|
|
DS_Report.PrintJobQueueDataTable nextJob = DataLayer.man.taPJQ.getWaiting();
|
|
if (nextJob != null)
|
|
{
|
|
answ = nextJob.Count;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Carica i dati richiesti dal report dalla StoredProcedure (filtrando quindi...) e restituisce Dictionary [nome RDS / tab RDS]
|
|
/// </summary>
|
|
/// <param name="tipoReport"></param>
|
|
/// <param name="keyParam">cod UDC</param>
|
|
/// <returns>tabella dati</returns>
|
|
private Dictionary<string, DataTable> caricaDati(reportRichiesto tipoReport, string keyParam)
|
|
{
|
|
int intIdx = 0;
|
|
Dictionary<string, DataTable> answ = new Dictionary<string, DataTable>();
|
|
DataTable tab = new DataTable();
|
|
switch (tipoReport)
|
|
{
|
|
case reportRichiesto.bunkLabel:
|
|
int.TryParse(keyParam, out intIdx);
|
|
tab = (DataTable)DataLayer.man.taRepStack.GetData(intIdx);
|
|
answ.Add("stp_prt_StackLabel", tab);
|
|
break;
|
|
case reportRichiesto.cartLabel:
|
|
// int.TryParse(keyParam, out intIdx);
|
|
// tab = (DataTable)DataLayer.man.taRepStack.GetData(intIdx);
|
|
break;
|
|
case reportRichiesto.offlineLabel:
|
|
// int.TryParse(keyParam, out intIdx);
|
|
// tab = (DataTable)DataLayer.man.taRepStack.GetData(intIdx);
|
|
break;
|
|
case reportRichiesto.paintLabelPre:
|
|
// int.TryParse(keyParam, out intIdx);
|
|
// tab = (DataTable)DataLayer.man.taRepStack.GetData(intIdx);
|
|
break;
|
|
case reportRichiesto.paintLabelPost:
|
|
// int.TryParse(keyParam, out intIdx);
|
|
// tab = (DataTable)DataLayer.man.taRepStack.GetData(intIdx);
|
|
break;
|
|
case reportRichiesto.partLabel:
|
|
int.TryParse(keyParam, out intIdx);
|
|
tab = (DataTable)DataLayer.man.taIL.getByKey(intIdx);
|
|
answ.Add("stp_prt_PartLabel", tab);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
tab.Dispose();
|
|
return answ;
|
|
}
|
|
|
|
|
|
protected reportRichiesto reportByTipo(string tipo)
|
|
{
|
|
reportRichiesto report = reportRichiesto.bunkLabel;
|
|
switch (tipo)
|
|
{
|
|
case "docStack":
|
|
report = reportRichiesto.bunkLabel;
|
|
break;
|
|
case "docBinPre":
|
|
report = reportRichiesto.paintLabelPre;
|
|
break;
|
|
case "docBinPost":
|
|
report = reportRichiesto.paintLabelPost;
|
|
break;
|
|
case "docCart":
|
|
report = reportRichiesto.cartLabel;
|
|
break;
|
|
case "docPart":
|
|
report = reportRichiesto.partLabel;
|
|
break;
|
|
case "docOffline":
|
|
report = reportRichiesto.offlineLabel;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return report;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region REST api call
|
|
|
|
/// <summary>
|
|
/// Restituisce numero jobs aperti (stato = 0...), se 0 = NESSUNO
|
|
/// GET: api/PrintQueue
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public int Get()
|
|
{
|
|
// restituisco...
|
|
int answ = 0;
|
|
string redVal = memLayer.ML.getRSV(redQueueCount);
|
|
// cerco in redis se ci sia chiave..
|
|
if (!string.IsNullOrEmpty(redVal))
|
|
{
|
|
// recupero
|
|
int.TryParse(redVal, out answ);
|
|
}
|
|
else
|
|
{
|
|
// recupero da dbe e salvo
|
|
answ = countWaitingDb;
|
|
memLayer.ML.setRSV(redQueueCount, answ.ToString(), 30);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco dei jobs aperti per la coda indicata
|
|
/// GET: api/PrintQueue/queue_01
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public List<reportData> Get(string id)
|
|
{
|
|
List<reportData> answ = new List<reportData>();
|
|
// recupero da DB...
|
|
DS_Report.PrintJobQueueDataTable tabPJQ = DataLayer.man.taPJQ.getByQueue(id);
|
|
if (tabPJQ.Count > 0)
|
|
{
|
|
reportData currReport = new reportData();
|
|
Dictionary<string, DataTable> currRdsData;
|
|
// ciclo!
|
|
foreach (var pjReq in tabPJQ)
|
|
{
|
|
currRdsData = caricaDati(reportByTipo(pjReq.TipoReport), pjReq.KeyParam);
|
|
// in base alla coda --> recupero i dati
|
|
currReport = new reportData()
|
|
{
|
|
ticketNum = pjReq.IdxPrintJob.ToString(),
|
|
rdsData = currRdsData
|
|
};
|
|
answ.Add(currReport);
|
|
}
|
|
}
|
|
// compongo risposta...
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Processa una chiamata POST per l'invio in blocco del risultato dell'elaborazione
|
|
/// POST: api/PrintQueue
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public string Post()
|
|
{
|
|
string answ = "UNKN";
|
|
// questa classe è derivata da Controller.Response... x cui recupero lo stream in altro modo...
|
|
string content = "";
|
|
System.Web.HttpContext.Current.Request.InputStream.Position = 0;
|
|
using (var reader = new StreamReader(System.Web.HttpContext.Current.Request.InputStream, System.Text.Encoding.UTF8, true, 4096, true))
|
|
{
|
|
content = reader.ReadToEnd();
|
|
}
|
|
//Rest
|
|
System.Web.HttpContext.Current.Request.InputStream.Position = 0;
|
|
// procedo a deserializzare in blocco l'oggetto...
|
|
try
|
|
{
|
|
// deserializzo.
|
|
printTask printAnsw = JsonConvert.DeserializeObject<printTask>(content);
|
|
// verifico se mi abbia dato esito 1 --> aggiorno DB!
|
|
if (printAnsw != null)
|
|
{
|
|
int idxPJQ = 0;
|
|
int.TryParse(printAnsw.ticketNum, out idxPJQ);
|
|
DataLayer.man.taPJQ.updateStato(idxPJQ, printAnsw.newStatus);
|
|
// resetto conteggio in redis...
|
|
memLayer.ML.setRSV(redQueueCount, countWaitingDb.ToString(), 30);
|
|
answ = "OK";
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
// restituisco esito!
|
|
return answ;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|