You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
277 lines
12 KiB
277 lines
12 KiB
namespace CounsellorBL
|
|
{
|
|
using MonumentDefine;
|
|
using Newtonsoft.Json.Linq;
|
|
using OT.COM.ArsenalDB;
|
|
using OT.COM.SignalerMessage;
|
|
using SoldierData.EnterprizeV4;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using static CounsellorBL.Common.EntityBaseExtension;
|
|
|
|
public class ModelDataTemplate<TEntity> : DataServiceBase where TEntity : EntityBase, new()
|
|
{
|
|
protected delegate string DG_Copy_ModifyInstance(TEntity i_oTrage, JObject data, JObject wheredata, string i_sNewGUID);
|
|
|
|
protected DG_Copy_ModifyInstance dgCopy_ModifyInstance { get; set; }
|
|
protected List<DG_EditPostCommand> ldgCopy_ModifyEachCopyItemCommand { get; } = new List<DG_EditPostCommand>();
|
|
|
|
|
|
public DG_GenerateReadCommand dgReadCommandGenerator { get; set; }
|
|
|
|
public DG_PostHandleReadData dgReadCommandPostDataHandler { get; set; }
|
|
|
|
public DG_GenerateEditCommand dgCopyCommandGenerator { get; set; }
|
|
|
|
public DG_GenerateEditCommand dgCreateCommandGenerator { get; set; }
|
|
|
|
public DG_GenerateEditCommand dgUpdateCommandGenerator { get; set; }
|
|
|
|
public DG_GenerateEditCommand dgDeleteCommandGenerator { get; set; }
|
|
|
|
public override string MainTable => GetMainTableName(typeof(TEntity));
|
|
|
|
public override CResponseMessage Read(CRequestMessage i_crmInput)
|
|
{
|
|
return simpleRead(i_crmInput, dgReadCommandGenerator, dgReadCommandPostDataHandler);
|
|
}
|
|
|
|
|
|
public override CResponseMessage Copy(CRequestMessage i_crmInput)
|
|
{
|
|
return commonEditor(i_crmInput, BLWording.CPY_MASTER, dgCopyCommandGenerator);
|
|
}
|
|
|
|
public override CResponseMessage Create(CRequestMessage i_crmInput)
|
|
{
|
|
return commonEditor(i_crmInput, BLWording.ADD_MASTER, dgCreateCommandGenerator);
|
|
}
|
|
|
|
public override CResponseMessage Update(CRequestMessage i_crmInput)
|
|
{
|
|
return commonEditor(i_crmInput, BLWording.UPD_MASTER, dgUpdateCommandGenerator);
|
|
}
|
|
|
|
public override CResponseMessage Delete(CRequestMessage i_crmInput)
|
|
{
|
|
return commonEditor(i_crmInput, BLWording.DEL_MASTER, dgDeleteCommandGenerator);
|
|
}
|
|
|
|
protected string createSingleCommandGeneratorDefault(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out List<Command> o_lcCmds, List<string> i_saQryContainKeys,
|
|
[System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
|
|
[System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
|
|
[System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
|
|
{
|
|
o_lcCmds = getAddListCommand(i_crmInput, i_jaData, typeof(TEntity).GetField("TABLENAME").GetValue(null).ToString(), out string sMsg);
|
|
return sMsg;
|
|
}
|
|
|
|
protected string updateSingleCommandGeneratorDefault(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out List<Command> o_lcCmds, List<string> i_saQryContainKeys,
|
|
[System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
|
|
[System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
|
|
[System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
|
|
{
|
|
o_lcCmds = getUpdListCommand(i_crmInput, i_jaData, typeof(TEntity).GetField("TABLENAME").GetValue(null).ToString(), i_saQryContainKeys, out string sMsg);
|
|
return sMsg;
|
|
}
|
|
|
|
protected string deleteSingleCommandGeneratorDefault(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out List<Command> o_lcCmds, List<string> i_saQryContainKeys,
|
|
[System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
|
|
[System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
|
|
[System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
|
|
{
|
|
o_lcCmds = getDelListCommand(i_crmInput, i_jaData, typeof(TEntity).GetField("TABLENAME").GetValue(null).ToString(), i_saQryContainKeys, out string sMsg);
|
|
return sMsg;
|
|
}
|
|
|
|
protected string readCommandGeneratorDefault(CRequestMessage i_crmInput, JArray i_jaDataArray,
|
|
tb_sys_session i_sSessionUser,
|
|
out Command o_cCmd,
|
|
[System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
|
|
[System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
|
|
[System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
|
|
{
|
|
o_cCmd = getQryListCommand(i_jaDataArray, typeof(TEntity).GetField("TABLENAME").GetValue(null).ToString(), out string sMsg, i_bUseFullSelect: true,
|
|
i_ecfFilter: getQueryCustomerFilter(i_crmInput))[0];
|
|
return sMsg;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Would use dgCopyFlowModifyInstance/dgCopyFlowCopyPostCommand to custmize
|
|
/// </summary>
|
|
/// <param name="i_crmInput"></param>
|
|
/// <param name="i_jaData"></param>
|
|
/// <param name="i_sSessionUser"></param>
|
|
/// <param name="o_lcCmds"></param>
|
|
/// <param name="i_saQryContainKeys"></param>
|
|
/// <returns></returns>
|
|
protected string copyCommandGeneratorDefault(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out List<Command> o_lcCmds, List<string> 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<Command> lCmds = new List<Command>();
|
|
string sTbName = typeof(TEntity).GetField("TABLENAME").GetValue(null).ToString();
|
|
do
|
|
{
|
|
if (i_jaData == null)
|
|
{
|
|
sMsg = MessageWording.PARAM_NOT_EXPECTED;
|
|
break;
|
|
}
|
|
|
|
List<string> lsUID = new List<string>();
|
|
|
|
// 強化檢核
|
|
foreach (JToken joItem in i_jaData)
|
|
{
|
|
Dictionary<string, object> dicItem = joItem.ToObject<Dictionary<string, object>>();
|
|
|
|
if (dicItem == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!(dicItem[BLWording.WHEREDATA] is JObject joCond))
|
|
{
|
|
sMsg = MessageWording.PARAM_NOT_EXPECTED;
|
|
break;
|
|
}
|
|
IDictionary<string, JToken> dicCondProperty = joCond;
|
|
|
|
bool bQryContainKeys = true;
|
|
i_saQryContainKeys?.ForEach(f =>
|
|
{
|
|
if (bQryContainKeys && !dicCondProperty.ContainsKey(f))
|
|
{
|
|
bQryContainKeys = false;
|
|
}
|
|
});
|
|
if (!bQryContainKeys)
|
|
{
|
|
sMsg = MessageWording.PARAM_NOT_EXPECTED;
|
|
break;
|
|
}
|
|
|
|
lsUID.Add(dicCondProperty[BLWording.UID].ToString());
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
|
|
sMsg = getEntity(sTbName, out object oSelect);
|
|
EntityBase ebSelect = oSelect as EntityBase;
|
|
ebSelect.SetFullDirtyEx(EColumnFilter.ES_NO_SYSTEMCOLUMN);
|
|
|
|
Command cSelectOriginData = Command.SetupSelectCmd(ebSelect,
|
|
new WhereNode(BLWording.UID, WhereNode.EColumnOperation.EOT_IN, ebSelect.GetType(), lsUID.ToArray()));
|
|
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelectOriginData);
|
|
List<TEntity> qdsOrigin = ai.RunQueryList<TEntity>(cSelectOriginData);
|
|
|
|
if (!cSelectOriginData.IsSuccess)
|
|
{
|
|
sMsg = GetLastErrorCode(cSelectOriginData);
|
|
break;
|
|
}
|
|
|
|
if (qdsOrigin.Count != lsUID.Count)
|
|
{
|
|
sMsg = MessageWording.PARAM_NOT_EXPECTED;
|
|
break;
|
|
}
|
|
|
|
|
|
foreach (JToken jtkProg in i_jaData)
|
|
{
|
|
Dictionary<string, object> dicItem = jtkProg.ToObject<Dictionary<string, object>>();
|
|
|
|
string sParamCatalogUID = null;
|
|
if (dicItem.ContainsKey(BLWording.DATA) && dicItem[BLWording.DATA] is JObject data &&
|
|
dicItem.ContainsKey(BLWording.WHEREDATA) && dicItem[BLWording.WHEREDATA] is JObject wheredata)
|
|
{
|
|
Dictionary<string, object> wheredataDic = wheredata.ToObject<Dictionary<string, object>>();
|
|
|
|
// Get all prgram
|
|
if (wheredataDic != null && wheredataDic.ContainsKey(BLWording.UID))
|
|
{
|
|
string sNewMstGUID = Guid.NewGuid().ToString();
|
|
sParamCatalogUID = wheredataDic[BLWording.UID].ToString();
|
|
|
|
TEntity teMstNew = qdsOrigin.Find(f =>
|
|
{
|
|
return f.GetValue(BLWording.UID).ToString() == sParamCatalogUID;
|
|
});
|
|
|
|
TEntity teMstOriginClone = teMstNew.Clone() as TEntity;
|
|
sMsg = valueAssignment(i_crmInput, teMstNew, dicItem[BLWording.DATA] as JObject, out List<Command> o_lcAddInsert, i_bIsCreate: true);
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if (dgCopy_ModifyInstance != null)
|
|
{
|
|
sMsg = dgCopy_ModifyInstance(teMstNew, data, wheredata, sNewMstGUID);
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
teMstNew.SetValue(BLWording.UID, sNewMstGUID);
|
|
}
|
|
|
|
|
|
if (o_lcAddInsert != null && o_lcAddInsert.Count > 0)
|
|
{
|
|
lCmds.AddRange(o_lcAddInsert);
|
|
}
|
|
|
|
lCmds.Add(Command.SetupInsertCmd(teMstNew));
|
|
|
|
if (ldgCopy_ModifyEachCopyItemCommand.Any())
|
|
{
|
|
foreach (DG_EditPostCommand dgCopy_PostCommand in ldgCopy_ModifyEachCopyItemCommand)
|
|
{
|
|
if (dgCopy_PostCommand != null)
|
|
{
|
|
sMsg = dgCopy_PostCommand(ai, teMstOriginClone, teMstNew, out List<Command> o_lcAddition);
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if (o_lcAddition != null)
|
|
{
|
|
lCmds.AddRange(o_lcAddition);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
while (false);
|
|
|
|
|
|
o_lcCmds = lCmds;
|
|
return sMsg;
|
|
}
|
|
}
|
|
}
|