保存后异步执行Sql操作(二次保存)
{
"saveSqlExtand": {
"bt-policy-item": {
"sortId": 1,
"connName": "ConnBt",
"sqlUpdate": "update bt_policy_item tb_pi,bt_policy_status tb_ps set tb_pi.status =tb_ps.status where tb_pi.policy_item_id = tb_ps.policy_item_id and tb_pi.create_user_id=@_userId and ((tb_pi.bz_jf_method=1 and year(payment_date)=@_currentYear) or (tb_pi.bz_jf_method=2 and month(payment_date)=@_currentMonth)) and tb_pi.policy_item_id=@policyItemId",
"sqlInsert": null
}
},
"responseField": {
"my_detail": {
"guidMethod": "None",
"dataFromType": "Database",
"show": "audit_opinion,audit_status,payment_date,policy_id,policy_item_id,policy_status_id,sort_id,status,tags",
"bridgeColumn": "audit_opinion,audit_status,payment_date,policy_id,policy_item_id,policy_status_id,sort_id,status,tags",
"original": "",
"auth": true
}
}
}
源码刨析
/// <summary>z
/// 保存结果进行二次处理
/// </summary>
/// <param name="pfGloal"></param>
/// <param name="sqlConfig"></param>
/// <param name="lstDic"></param>
/// <returns></returns>
public async Task SaveExtend(PFGlobalParameter pfGloal, SqlConfig sqlConfig, RequestModuleType rmt, Dictionary<string, object> dictionaryUrl, IEnumerable<Dictionary<string, object>> lstDic)
{
string sql = null;
try
{
if (sqlConfig.SaveSqlExtand == null) return;
if (sqlConfig.SaveSqlExtand.Values.Count == 0) return;
var lstSSE = sqlConfig.SaveSqlExtand.Values.OrderBy(temp => temp.SortId);
int result = 0;
await Task.Run(() =>
{
foreach (var item in lstSSE)
{
if (item.SqlInsert != null && item.SqlUpdate != null)
{
sql = item.SqlUpdate;
result = _db.Execute(pfGloal, item.ConnName ?? sqlConfig.Base.ConnName, item.SqlUpdate, lstDic);
if (item.SqlInsert != null && result == 0)
{
sql = item.SqlInsert;
result = _db.Execute(pfGloal, item.ConnName ?? sqlConfig.Base.ConnName, item.SqlInsert, lstDic);
}
}
else if (item.SqlUpdate != null)
{
sql = item.SqlUpdate;
result = _db.Execute(pfGloal, item.ConnName ?? sqlConfig.Base.ConnName, item.SqlUpdate, lstDic);
}
else if (item.SqlInsert != null)
{
sql = item.SqlInsert;
result = _db.Execute(pfGloal, item.ConnName ?? sqlConfig.Base.ConnName, item.SqlInsert, lstDic);
}
}
});
}
catch (Exception ex)
{
_logger.LogError(ex, $"{pfGloal.OwnerId}/{pfGloal.SysId}/{pfGloal.ModuleKey}/{pfGloal.ReponseField}/【{sql}】", lstDic);
}
}
}
文档更新时间: 2021-08-27 08:13 作者:admin