namespace CounsellorBL.BLStructure.SYS { using MonumentDefine; using OT.COM.ArsenalDB; using OT.COM.LogisticsUtil; using OT.COM.SignalerMessage; using SoldierData.EnterprizeV4; using System; using System.Collections.Generic; using CounsellorBL.Common; using static CounsellorBL.Common.EntityBaseExtension; using System.Data; using Newtonsoft.Json.Linq; using CounsellorBL.Helper; using Newtonsoft.Json; using Microsoft.Extensions.Caching.Memory; using System.Collections.Concurrent; public class TranslationService : SingleDataTableTemplate { // const string CACHE_KEY_tb_sys_translation = "CACHE_KEY_tb_sys_translation"; const string CACHE_KEY_tb_sys_translation2 = "CACHE_KEY_tb_sys_translation2"; public TranslationService() { dgGetExportPath = exportPath; dgImportCommandGenerator = importCommandGenerator; } [Auth(false)] public new CResponseMessage Read(CRequestMessage i_crmInput) { CResponseMessage crmRes = null; IMemoryCache imc = GetMemoryCache(); bool bUseBase = true; try { do { if (getCommonParameter(i_crmInput, BLWording.QRY_MASTER, out JArray jaDataArray, out tb_sys_session sUserSession) != null) { break; } if (jaDataArray.Count != 1 || jaDataArray[0] == null) { break; } JObject joWhere = jaDataArray[0][BLWording.WHEREDATA] as JObject; if (joWhere == null || joWhere.Count != 0) { break; } if (imc != null && imc.TryGetValue(CACHE_KEY_tb_sys_translation2, out List ul)) { lock (imc) { crmRes = new CSuccessResponseMessage(null, i_crmInput); crmRes.param.Add(BLWording.DATA, ul); bUseBase = false; } } } while (false); } catch { } if(bUseBase) { crmRes = base.Read(i_crmInput); } return crmRes; } protected string exportPath(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out string o_sFilePath, List i_saQryContainKeys, [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0, [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "", [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "") { string sMsg = null; string sPath = null; try { QueryDataSet qds = selectAllTrans(); CreateExcel(qds.DATA.Tables[0], i_crmInput, out sPath); } catch (Exception ex) { LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath); sMsg = $"{nameof(exportPath)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine})."; #if DEBUG System.Diagnostics.Debug.WriteLine(sMsg); #endif } o_sFilePath = sPath; return sMsg; } protected string importCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out List o_lcResult, List i_saQryContainKeys, [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0, [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "", [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "") { string sMsg = null; List lCmds = new List(); try { do { CResponseMessage crmUpload = Upload(i_crmInput); if (crmUpload.result == EResponseResult.RR_FALSE) { sMsg = crmUpload.msg; break; } List lUploads = crmUpload.param[BLWording.DATA] as List; string sPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, lUploads[0].path); DataTable dtData = ExcelHelper.GetDataTableFromExcelFile(sPath); // Parse Excel and Import // DB Data QueryDataSet qdsDB = selectAllTrans(); ExcelHelper.AddOrModifyRow(qdsDB.DATA.Tables[0], dtData, out List ldrAdd, out List ldrModify); List lAdd = EntityHelper.FromDataTable(ldrAdd); if (lAdd.Count > 0) { foreach (tb_sys_translation t in lAdd) { lCmds.Add(Command.SetupInsertCmd(t)); } } List lUpd = EntityHelper.FromDataTable(ldrModify); if (lUpd.Count > 0) { foreach (tb_sys_translation t in lUpd) { tb_sys_translation tCond = new tb_sys_translation() { uid = t.uid }; lCmds.Add(Command.SetupUpdateCmd(t, tCond)); } } } while (false); } catch (Exception ex) { LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath); sMsg = $"{nameof(importCommandGenerator)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine})."; #if DEBUG System.Diagnostics.Debug.WriteLine(sMsg); #endif } o_lcResult = lCmds; return sMsg; } protected QueryDataSet selectAllTrans() { tb_sys_translation tDisplay = new tb_sys_translation(); tDisplay.SetFullDirtyEx(EColumnFilter.ES_NO_SYSTEMCOLUMN); Command cSelect = Command.SetupSelectCmd(tDisplay); ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect, GetDefaultSystemColumnInfo()); return ai.RunQueryDataSet(cSelect); } } }