256 lines
8.9 KiB
C#
256 lines
8.9 KiB
C#
using MagData;
|
|
using Newtonsoft.Json;
|
|
|
|
//using SteamWare.IO;
|
|
//using SteamWare.Reports;
|
|
//using SteamWare;
|
|
using SteamWare.Reports;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Web.Http;
|
|
|
|
namespace MP_MAG.Controllers
|
|
{
|
|
public class PrintQueueController : ApiController
|
|
{
|
|
#region Protected Fields
|
|
|
|
/// <summary>
|
|
/// oggetto static/singleton per fare chiamate sul datalayer
|
|
/// </summary>
|
|
protected MagDataLayer MagDataLayerObj = new MagDataLayer();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
/// <summary>
|
|
/// Conteggio elementi in attesa stsampa da DB
|
|
/// </summary>
|
|
protected int countWaitingDb
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
// resetto conteggio in redis...
|
|
DS_Report.PrintJobQueueDataTable nextJob = MagDataLayerObj.taPJQ.getWaiting();
|
|
if (nextJob != null)
|
|
{
|
|
answ = nextJob.Count;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Private Methods
|
|
|
|
/// <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(MagData.reportRichiesto tipoReport, string keyParam)
|
|
{
|
|
Dictionary<string, DataTable> answ = new Dictionary<string, DataTable>();
|
|
DataTable tab = new DataTable();
|
|
switch (tipoReport)
|
|
{
|
|
case MagData.reportRichiesto.CartellinoFinitiOdette:
|
|
tab = MagDataLayerObj.taCFOdette.GetData(keyParam);
|
|
answ.Add("stp_prt_CartellinoFinitiOdette", tab);
|
|
break;
|
|
|
|
case MagData.reportRichiesto.CartellinoPedane:
|
|
tab = MagDataLayerObj.taCPed.GetData(keyParam);
|
|
answ.Add("stp_prt_CartellinoPedane", tab);
|
|
break;
|
|
|
|
case MagData.reportRichiesto.CartellinoSemilavorati:
|
|
tab = MagDataLayerObj.taCSemil.GetData(keyParam);
|
|
answ.Add("stp_prt_CartellinoSemilavorati", tab);
|
|
break;
|
|
|
|
case MagData.reportRichiesto.ReportPackList:
|
|
tab = MagDataLayerObj.taRepPL.GetData(keyParam, false);
|
|
answ.Add("stp_prt_ReportPackList", tab);
|
|
break;
|
|
|
|
case MagData.reportRichiesto.ReportPackListFull:
|
|
tab = MagDataLayerObj.taRepPLFull.GetData(keyParam, false);
|
|
answ.Add("stp_prt_ReportPackListFull", tab);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
// CHECK FIXME 2021.03.03: verificare sia OK dispose
|
|
tab.Dispose();
|
|
return answ;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Recupera report da CODA report
|
|
/// </summary>
|
|
/// <param name="queueName"></param>
|
|
/// <returns></returns>
|
|
protected MagData.reportRichiesto reportByQueue(string queueName)
|
|
{
|
|
MagData.reportRichiesto report = MagData.reportRichiesto.ND;
|
|
var qConf = MagDataLayerObj.queueConfRedis.Find(x => x.name == queueName);
|
|
if (qConf != null)
|
|
{
|
|
// decodifico
|
|
try
|
|
{
|
|
report = (MagData.reportRichiesto)Enum.Parse(typeof(MagData.reportRichiesto), qConf.template.Replace(".rdlc", ""));
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return report;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera report da conf TipoDoc
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
/// <returns></returns>
|
|
protected MagData.reportRichiesto reportByTipoDoc(string name)
|
|
{
|
|
MagData.reportRichiesto report = MagData.reportRichiesto.ND;
|
|
var qConf = MagDataLayerObj.reportConfRedis.Find(x => x.name == name);
|
|
if (qConf != null)
|
|
{
|
|
// decodifico
|
|
try
|
|
{
|
|
report = (MagData.reportRichiesto)Enum.Parse(typeof(MagData.reportRichiesto), qConf.template.Replace(".rdlc", ""));
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return report;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
/// <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 = SteamWare.memLayer.ML.getRSV(MagDataLayer.redQueueCount);
|
|
// cerco in redis se ci sia chiave..
|
|
if (!string.IsNullOrEmpty(redVal))
|
|
{
|
|
// recupero
|
|
int.TryParse(redVal, out answ);
|
|
}
|
|
else
|
|
{
|
|
int ttlPrintCount = SteamWare.memLayer.ML.CRI("ttlPrintCount");
|
|
// recupero da dbe e salvo
|
|
answ = countWaitingDb;
|
|
SteamWare.memLayer.ML.setRSV(MagDataLayer.redQueueCount, $"{answ}", ttlPrintCount);
|
|
}
|
|
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 = MagDataLayerObj.taPJQ.getByQueue(id);
|
|
if (tabPJQ.Count > 0)
|
|
{
|
|
reportData currReport = new reportData();
|
|
Dictionary<string, DataTable> currRdsData;
|
|
// ciclo!
|
|
MagData.reportRichiesto tipoRep = MagData.reportRichiesto.ND;
|
|
foreach (var pjReq in tabPJQ)
|
|
{
|
|
// verifico SE HO un tipo report particolare...
|
|
tipoRep = reportByTipoDoc(pjReq.TipoReport);
|
|
if (tipoRep == MagData.reportRichiesto.ND)
|
|
{
|
|
tipoRep = reportByQueue(pjReq.prtName);
|
|
}
|
|
currRdsData = caricaDati(tipoRep, pjReq.KeyParam);
|
|
// in base alla coda --> recupero i dati
|
|
currReport = new reportData()
|
|
{
|
|
ticketNum = $"{pjReq.IdxPrintJob}",
|
|
template = $"{pjReq.TipoReport}",
|
|
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);
|
|
MagDataLayerObj.taPJQ.updateStato(idxPJQ, printAnsw.newStatus);
|
|
// resetto conteggio in redis...
|
|
SteamWare.memLayer.ML.setRSV(MagDataLayer.redQueueCount, $"{countWaitingDb}", 30);
|
|
answ = "OK";
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
// restituisco esito!
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |