using System.Data; using System.Linq; using System.Net.Mime; using System.Text.RegularExpressions; using Common; using Infrastructure; using LitJson; using Microsoft.Extensions.Localization; using Model; using Model.Customer; using NuGet.Packaging; using Services; namespace Util { public class PrizeDo { public static string batchNo = ""; public static string publicStep = ""; public static bool logFlag = true; //发奖入口 public static void sendPrize(string queueName, string content) { batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(3); publicStep = ""; string priObjString = prizeInSet(queueName); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-1", "接收mq数据日志"); if(!string.IsNullOrEmpty(priObjString)) { string[] priObjData = priObjString.Split('|'); string priListIds = priObjData[0]; int projectId = int.Parse(priObjData[1]); int prizeInId = int.Parse(priObjData[2]); var projectService = App.GetService(); var project = projectService.GetFirst(m => m.id == projectId) ?? new PriProject(); logFlag = project.logFlag; Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-2", "接收mq数据日志"); prizeSend(projectId, prizeInId, priListIds, content, queueName); } } //补奖入口 public static void addPrize(string queueName, string content) { batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(3); publicStep = ""; string priObjString = prizeInSet(queueName); if(!string.IsNullOrEmpty(priObjString)) { string[] priObjData = priObjString.Split('|'); string priListIds = ""; int projectId = int.Parse(priObjData[1]); int prizeInId = int.Parse(priObjData[2]); var projectService = App.GetService(); var project = projectService.GetFirst(m => m.id == projectId) ?? new PriProject(); logFlag = project.logFlag; JsonData jsonObj = JsonMapper.ToObject(content); JsonData posSn = jsonObj["pos_sn"].ToString(); JsonData prizeKinds = jsonObj["prize_kind_list"]; for (int i = 0; i < prizeKinds.Count; i++) { string kind = prizeKinds[i].ToString(); if(kind == "0") priListIds += "42,45,"; if(kind == "7") priListIds += "43,"; if(kind == "50") priListIds += "44,"; if(kind == "116") priListIds += "49,"; if(kind == "121") priListIds += "50,"; if(kind == "139") priListIds += "56,"; } prizeSend(projectId, prizeInId, priListIds.TrimEnd(','), content, queueName); } } //接收入参 public static Dictionary getRequestParams(int projectId, string content) { Dictionary dic = new(); JsonData jsonData = JsonMapper.ToObject(content); var paramService = App.GetService(); var paramList = paramService.GetList(m => m.projectId == projectId); foreach(var param in paramList) { if(content.Contains("\"" + param.fieldEnName + "\"")) dic.Add(param.fieldEnName, jsonData[param.fieldEnName].ToString()); } return dic; } public static string getRequestParams(int projectId, string content, string key) { JsonData jsonData = JsonMapper.ToObject(content); var paramService = App.GetService(); var param = paramService.GetFirst(m => m.projectId == projectId && m.fieldEnName == key); if(param != null) { if(content.Contains("\"" + param.fieldEnName + "\"")) return jsonData[param.fieldEnName].ToString(); } return key; } public static string getRequestParamsIndex(int projectId, string content) { string result = ","; JsonData jsonData = JsonMapper.ToObject(content); var paramService = App.GetService(); var paramList = paramService.GetList(m => m.projectId == projectId && m.queryIndex == "1"); foreach(var param in paramList) { if(content.Contains("\"" + param.fieldEnName + "\"")) result += jsonData[param.fieldEnName].ToString() + ","; } return result; } //数据库链接 public static SqlSugarClient initDb(int id) { var databaseSetService = App.GetService(); var connectionString = databaseSetService.GetFirst(m => m.id == id); string server = connectionString.ipAddress; int port = connectionString.port; string user = connectionString.userId; string password = connectionString.password; string database = connectionString.databaseName; var db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = "server=" + server + ";port=" + port + ";user=" + user + ";password=" + password + ";database=" + database + ";charset=utf8;", DbType = SqlSugar.DbType.MySql, IsAutoCloseConnection = true, }); return db; } //查询条件匹配数据 public static List condition(int listId, int projectId, List ids, string content, Dictionary startData) { List dic = new(); var queryTableService = App.GetService(); var queryFieldService = App.GetService(); var returnFieldService = App.GetService(); //查询表 Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-query-0", "接收mq数据日志"); var queryTables = queryTableService.GetList(m => ids.Contains(m.id) && m.startDataFlag == false).OrderByDescending(m => m.sort).ThenBy(m => m.id).ToList(); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-query-1", "接收mq数据日志"); foreach(var queryTable in queryTables) { string sql = ""; Dictionary fieldDic = new(); if(string.IsNullOrEmpty(queryTable.customSql)) { string tableEnName = queryTable.tableEnName; if(tableEnName.Contains("#{")) tableEnName = MatchExpressionVal(tableEnName); //查询返回字段 string fields = ""; var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-query-2", "接收mq数据日志"); foreach(var returnField in returnFields) { string aliasName = returnField.fieldAliasName; if(string.IsNullOrEmpty(aliasName)) aliasName = tableEnName + "_" + returnField.fieldEnName; if(aliasName.Contains("-")) aliasName = aliasName.Split('-')[0]; if(returnField.fieldReturnKind == "2") { fields += "count(" + returnField.fieldEnName + ") " + aliasName + ","; } else if(returnField.fieldReturnKind == "3") { fields += "sum(" + returnField.fieldEnName + ") " + aliasName + ","; } else if(returnField.fieldReturnKind == "4") { fields += "avg(" + returnField.fieldEnName + ") " + aliasName + ","; } else if(returnField.fieldReturnKind == "5") { fields += "max(" + returnField.fieldEnName + ") " + aliasName + ","; } else if(returnField.fieldReturnKind == "6") { fields += "min(" + returnField.fieldEnName + ") " + aliasName + ","; } else if(returnField.fieldReturnKind == "7") { fields += GetDbExpressionVal(returnField.fieldEnName, projectId, content, dic, startData) + ","; } else { fields += returnField.fieldEnName + " " + aliasName + ","; } fieldDic.Add(aliasName, returnField.fieldName); } fields = fields.TrimEnd(','); //查询匹配条件 string condi = ""; var queryFields = queryFieldService.GetList(m => m.queryTableId == queryTable.id); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-query-3", "接收mq数据日志"); foreach(var queryField in queryFields) { string fieldEnName = queryField.fieldEnName; string fieldQueryKind = queryField.fieldQueryKind; string fieldQueryModel = queryField.fieldQueryModel; string fieldQueryValue = queryField.fieldQueryValue; if(fieldQueryValue.Contains("${")) fieldQueryValue = GetDbExpressionVal(fieldQueryValue, projectId, content, dic, startData); fieldQueryValue = MatchExpressionVal(fieldQueryValue); string fieldQueryValueType = queryField.fieldQueryValueType; if(fieldQueryKind == "1") //模糊匹配 { condi += " and " + fieldEnName + " like "; if(fieldQueryModel == "request_param") { condi += "'%" + getRequestParams(projectId, content, fieldQueryValue) + "%'"; } else if(fieldQueryModel == "fixed_value") { condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'"; } else if(fieldQueryModel == "db_field") { condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'"; } else if(fieldQueryModel == "query_field") { string val = GetQueryTableData(dic, fieldQueryValue); condi += "'%" + val + "%'"; } else if(fieldQueryModel == "querystart_list_field") { string val = GetStartData(startData, fieldQueryValue); condi += "'%" + val + "%'"; } } else if(fieldQueryKind == "2") //精确匹配 { if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is null"; else { condi += " and " + fieldEnName + "="; string val = ""; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; } else if(fieldQueryModel == "fixed_value") { val = GetExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "db_field") { val = GetDbExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "query_field") { val = GetQueryTableData(dic, fieldQueryValue); } else if(fieldQueryModel == "querystart_list_field") { val = GetStartData(startData, fieldQueryValue); } if(fieldQueryValueType == "text") { val = "'" + val + "'"; } condi += val; } } else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除 { if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in ("; else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in ("; string val = ""; string[] valList = fieldQueryValue.Split(','); if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + req[sub] + "',"; } else { val += req[sub] + ","; } } } else if(fieldQueryModel == "fixed_value") { foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + GetExpressionVal(sub) + "',"; } else { val += GetExpressionVal(sub) + ","; } } } else if(fieldQueryModel == "db_field") { foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + GetDbExpressionVal(sub) + "',"; } else { val += GetDbExpressionVal(sub) + ","; } } } else if(fieldQueryModel == "query_field") { foreach(string sub in valList) { string dicVal = GetQueryTableData(dic, sub); if(fieldQueryValueType == "text") { val += "'" + dicVal + "',"; } else { val += dicVal + ","; } } } else if(fieldQueryModel == "querystart_list_field") { foreach(string sub in valList) { string dicVal = GetStartData(startData, sub); if(fieldQueryValueType == "text") { val += "'" + dicVal + "',"; } else { val += dicVal + ","; } } } val = val.TrimEnd(','); condi += val + ")"; } else if(fieldQueryKind == "3") //范围匹配 { string[] val = RangeSplit(fieldQueryValue); if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]]; if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]]; } else { if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'"; if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'"; } } else if(fieldQueryModel == "fixed_value") { if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0]; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1]; } else { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'"; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'"; } } else if(fieldQueryModel == "db_field") { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + GetDbExpressionVal(val[0]); if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + GetDbExpressionVal(val[1]); } else if(fieldQueryModel == "query_field") { string valLeft = val[0]; string valRight = val[1]; string dicValLeft = GetQueryTableData(dic, valLeft); string dicValRight = GetQueryTableData(dic, valRight); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft; if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight; } else { if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'"; if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'"; } } else if(fieldQueryModel == "querystart_list_field") { string valLeft = val[0]; string valRight = val[1]; string dicValLeft = GetStartData(startData, valLeft); string dicValRight = GetStartData(startData, valRight); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft; if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight; } else { if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'"; if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'"; } } } else if(fieldQueryKind == "4") //取反匹配 { if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is not null"; else { condi += " and " + fieldEnName + "!="; string val = ""; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; } else if(fieldQueryModel == "fixed_value") { val = GetExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "db_field") { val = GetDbExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "query_field") { val = GetQueryTableData(dic, fieldQueryValue); } else if(fieldQueryModel == "querystart_list_field") { val = GetStartData(startData, fieldQueryValue); } if(fieldQueryValueType == "text") { val = "'" + val + "'"; } condi += val; } } } sql = "select " + fields + " from " + tableEnName + " where 1=1" + condi; if(!string.IsNullOrEmpty(queryTable.orderBy)) { sql += " order by " + queryTable.orderBy; } sql += " limit 1"; Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-query-4", "接收mq数据日志"); } else { sql = queryTable.customSql; sql = GetDbExpressionVal(sql, projectId, content, dic, startData); } var db = initDb(queryTable.databaseId); var items = db.Ado.GetDataTable(sql); if(items.Rows.Count > 0) { if(string.IsNullOrEmpty(queryTable.customSql)) { foreach(string field in fieldDic.Keys) { if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition() { FieldName = fieldDic[field], FieldEnName = field, Value = items.Rows[0][field].ToString() }); } } else { foreach(DataColumn column in items.Columns) { string field = column.ColumnName; if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition() { FieldName = field, FieldEnName = field, Value = items.Rows[0][field].ToString() }); } } } Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-query-5", "接收mq数据日志"); } return dic; } public static DataTable conditionList(int listId, int projectId, List ids, string content, int skip = 0, int size = 1000) { List dic = new(); var queryTableService = App.GetService(); var queryFieldService = App.GetService(); var returnFieldService = App.GetService(); //查询表 var queryTable = queryTableService.GetFirst(m => ids.Contains(m.id) && m.startDataFlag == true); if (queryTable != null) { string sql = ""; if(string.IsNullOrEmpty(queryTable.customSql)) { string groupBy = ""; string tableEnName = queryTable.tableEnName; if(tableEnName.Contains("#{")) tableEnName = MatchExpressionVal(tableEnName); //查询返回字段 string fields = ""; Dictionary fieldDic = new(); var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id); foreach(var returnField in returnFields) { string aliasName = returnField.fieldAliasName; if(string.IsNullOrEmpty(aliasName)) aliasName = tableEnName + "_" + returnField.fieldEnName.Split('+')[0]; if(returnField.fieldReturnKind == "2") { fields += "count(" + returnField.fieldEnName + ") " + aliasName + ","; } else if(returnField.fieldReturnKind == "3") { fields += "sum(" + returnField.fieldEnName + ") " + aliasName + ","; } else if(returnField.fieldReturnKind == "4") { fields += "avg(" + returnField.fieldEnName + ") " + aliasName + ","; } else if(returnField.fieldReturnKind == "5") { fields += "max(" + returnField.fieldEnName + ") " + aliasName + ","; } else if(returnField.fieldReturnKind == "6") { fields += "min(" + returnField.fieldEnName + ") " + aliasName + ","; } else { fields += returnField.fieldEnName + " " + aliasName + ","; } fieldDic.Add(tableEnName + "_" + returnField.fieldEnName, returnField.fieldName); } fields = fields.TrimEnd(','); //查询匹配条件 string condi = ""; var queryFields = queryFieldService.GetList(m => m.queryTableId == queryTable.id); foreach(var queryField in queryFields) { string fieldEnName = queryField.fieldEnName; string fieldQueryKind = queryField.fieldQueryKind; string fieldQueryModel = queryField.fieldQueryModel; string fieldQueryValue = queryField.fieldQueryValue; string fieldQueryValueType = queryField.fieldQueryValueType; //拼装聚合字段 if(queryField.groupByFlag) { groupBy += queryField.fieldEnName + ","; } else { if(fieldQueryKind == "1") //模糊匹配 { condi += " and " + fieldEnName + " like "; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; condi += "'%" + val + "%'"; } else if(fieldQueryModel == "fixed_value") { condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'"; } else if(fieldQueryModel == "db_field") { condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'"; } else if(fieldQueryModel == "query_field") { string val = GetQueryTableData(dic, fieldQueryValue); condi += "'%" + val + "%'"; } } else if(fieldQueryKind == "2") //精确匹配 { if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is null"; else { condi += " and " + fieldEnName + "="; string val = ""; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; } else if(fieldQueryModel == "fixed_value") { val = GetExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "db_field") { val = GetDbExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "query_field") { val = GetQueryTableData(dic, fieldQueryValue); } if(fieldQueryValueType == "text") { val = "'" + val + "'"; } condi += val; } } else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除 { if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in ("; else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in ("; string val = ""; string[] valList = fieldQueryValue.Split(','); if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + req[sub] + "',"; } else { val += req[sub] + ","; } } } else if(fieldQueryModel == "fixed_value") { foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + GetExpressionVal(sub) + "',"; } else { val += GetExpressionVal(sub) + ","; } } } else if(fieldQueryModel == "db_field") { foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + GetDbExpressionVal(sub) + "',"; } else { val += GetDbExpressionVal(sub) + ","; } } } else if(fieldQueryModel == "query_field") { foreach(string sub in valList) { string dicVal = GetQueryTableData(dic, sub); if(fieldQueryValueType == "text") { val += "'" + dicVal + "',"; } else { val += dicVal + ","; } } } val = val.TrimEnd(','); condi += val + ")"; } else if(fieldQueryKind == "3") //范围匹配 { string[] val = RangeSplit(fieldQueryValue); if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]]; if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]]; } else { if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'"; if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'"; } } else if(fieldQueryModel == "fixed_value") { if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0]; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1]; } else { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'"; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'"; } } else if(fieldQueryModel == "db_field") { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + GetDbExpressionVal(val[0]); if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + GetDbExpressionVal(val[1]); } else if(fieldQueryModel == "query_field") { string valLeft = val[0]; string valRight = val[1]; string dicValLeft = GetQueryTableData(dic, valLeft); string dicValRight = GetQueryTableData(dic, valRight); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft; if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight; } else { if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'"; if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'"; } } } else if(fieldQueryKind == "4") //取反匹配 { if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is not null"; else { condi += " and " + fieldEnName + "!="; string val = ""; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; } else if(fieldQueryModel == "fixed_value") { val = GetExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "db_field") { val = GetDbExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "query_field") { val = GetQueryTableData(dic, fieldQueryValue); } if(fieldQueryValueType == "text") { val = "'" + val + "'"; } condi += val; } } } } if(!string.IsNullOrEmpty(groupBy)) groupBy = " group by " + groupBy.TrimEnd(',') + " order by " + groupBy.TrimEnd(','); if(!string.IsNullOrEmpty(queryTable.orderBy)) { groupBy += " " + queryTable.orderBy; } sql = "select " + fields + " from " + tableEnName + " where 1=1" + condi + groupBy + " limit " + skip + "," + size; } else { sql = queryTable.customSql + " limit " + skip + "," + size; sql = MatchExpressionVal(sql); } var db = initDb(queryTable.databaseId); var items = db.Ado.GetDataTable(sql); return items; } return new DataTable(); } //奖励发放对象 public static string prizeObject(int listId, int prizeObjectTag, string content) { Dictionary logStepDic = new(); Dictionary dic = new(); var prizeObjectTableService = App.GetService(); var prizeObjectFieldService = App.GetService(); //查询表 var prizeObjectTable = prizeObjectTableService.GetFirst(m => m.id == prizeObjectTag) ?? new PriPrizeObjectTable(); //查询返回字段 string field = prizeObjectTable.selectField; if(string.IsNullOrEmpty(field)) return "0"; int projectId = prizeObjectTable.projectId; logStepDic.Add("奖励发放对象说明", prizeObjectTable.note); //查询匹配条件 string condi = ""; List> condiDics = new(); var queryFields = prizeObjectFieldService.GetList(m => m.objectTableId == prizeObjectTable.id); foreach(var queryField in queryFields) { string fieldName = queryField.fieldName; string fieldEnName = queryField.fieldEnName; string fieldQueryKind = queryField.fieldQueryKind; string fieldQueryModel = queryField.fieldQueryModel; string fieldQueryValue = queryField.fieldQueryValue; string fieldQueryValueType = queryField.fieldQueryValueType; Dictionary condiDic = new(); condiDic.Add("字段名称", fieldName); condiDic.Add("匹配条件", getQueryKind(fieldQueryKind)); condiDic.Add("匹配方式", getQueryModel(fieldQueryModel)); if(fieldQueryKind == "1") //模糊匹配 { condi += " and " + fieldEnName + " like "; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; condi += "'%" + val + "%'"; condiDic.Add("匹配值", val); } else if(fieldQueryModel == "fixed_value") { string val = GetExpressionVal(fieldQueryValue); condi += "'%" + val + "%'"; condiDic.Add("匹配值", val); } else if(fieldQueryModel == "db_field") { string val = GetDbExpressionVal(fieldQueryValue); condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'"; condiDic.Add("匹配值", val); } } else if(fieldQueryKind == "2") //精确匹配 { condi += " and " + fieldEnName + "="; string val = ""; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; } else if(fieldQueryModel == "fixed_value") { val = GetExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "db_field") { val = GetDbExpressionVal(fieldQueryValue); } if(fieldQueryValueType == "text") { val = "'" + val + "'"; } condi += val; condiDic.Add("匹配值", val); } else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除 { if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in ("; else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in ("; string val = ""; string[] valList = fieldQueryValue.Split(','); if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + req[sub] + "',"; } else { val += req[sub] + ","; } } } else if(fieldQueryModel == "fixed_value") { foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + GetExpressionVal(sub) + "',"; } else { val += GetExpressionVal(sub) + ","; } } } else if(fieldQueryModel == "db_field") { foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + GetDbExpressionVal(sub) + "',"; } else { val += GetDbExpressionVal(sub) + ","; } } } val = val.TrimEnd(','); condi += val + ")"; condiDic.Add("匹配值", val); } else if(fieldQueryKind == "3") //范围匹配 { string[] val = RangeSplit(fieldQueryValue); if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]]; if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]]; } else { if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'"; if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'"; } } else if(fieldQueryModel == "fixed_value") { if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0]; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1]; } else { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'"; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'"; } } else if(fieldQueryModel == "db_field") { if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0]; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1]; } else { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'"; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'"; } } condiDic.Add("匹配值", val); } else if(fieldQueryKind == "4") //取反匹配 { condi += " and " + fieldEnName + "!="; string val = ""; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; } else if(fieldQueryModel == "fixed_value") { val = GetExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "db_field") { val = GetDbExpressionVal(fieldQueryValue); } if(fieldQueryValueType == "text") { val = "'" + val + "'"; } condi += val; condiDic.Add("匹配值", val); } condiDics.Add(condiDic); } logStepDic.Add("奖励发放对象查询条件", condiDics); string result = "0"; var db = initDb(prizeObjectTable.databaseId); var item = db.Ado.GetScalar("select " + field + " from " + prizeObjectTable.tableEnName + " where 1=1" + condi); if(item != null) { result = item.ToString(); } logStepDic.Add("奖励发放对象", result); setLogStep(listId, "奖励发放对象", logStepDic); return result; } //奖励发放入口 public static string prizeInSet(string queueName) { Dictionary dic = new(); var prizeInSetService = App.GetService(); //查询表 var prizeInSet = prizeInSetService.GetFirst(m => m.mqQueueName == queueName) ?? new PriPrizeInSet(); if(prizeInSet.id > 0) { return prizeInSet.prizeListIds + "|" + prizeInSet.projectId + "|" + prizeInSet.id; } return ""; } //奖励列表 public static List prizeList(int projectId, string prizeIds) { List ids = Tools.SpitIntArrary(prizeIds, ',').ToList(); var priListService = App.GetService(); var priList = priListService.GetList(m => m.projectId == projectId && ids.Contains(m.id)).ToList(); return priList; } //奖励发放 public static void prizeSend(int projectId, int prizeInId, string prizeIds, string content, string queueName) { var queryTableService = App.GetService(); var priList = prizeList(projectId, prizeIds); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-3", "接收mq数据日志"); foreach(var sub in priList) { try { List ids = Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(); var queryTable = queryTableService.GetFirst(m => ids.Contains(m.id) && m.startDataFlag == true); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-4", "接收mq数据日志"); if (queryTable != null) { int page = 0; int size = queryTable.stepCount; if(size == 0) size = 20; bool op = true; while(op) { int skip = page * size; DataTable query = conditionList(sub.id, projectId, ids, content, skip, size); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-41", "接收mq数据日志"); if(query.Rows.Count > 0) { foreach(DataRow dr in query.Rows) { Dictionary startData = new(); foreach(DataColumn dc in query.Columns) { startData.Add(dc.ColumnName, dr[dc.ColumnName].ToString()); } prizeSendSub(sub, projectId, prizeInId, prizeIds, content, queueName, startData); } page += 1; } else { op = false; } } } else { prizeSendSub(sub, projectId, prizeInId, prizeIds, content, queueName, new Dictionary()); } } catch(Exception ex) { Function.WriteLog(ex.ToString(), "errlog"); setLogFieldValue(sub.id, "errLog", ex.ToString()); } } } //执行每个奖励发放逻辑 public static void prizeSendSub(PriList sub, int projectId, int prizeInId, string prizeIds, string content, string queueName, Dictionary startData) { Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-" + sub.prizeName, "接收mq数据日志"); var loopSetService = App.GetService(); var recursionStartTableService = App.GetService(); var recursionStartConditionService = App.GetService(); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-s1", "接收mq数据日志"); addLog(projectId, sub.id, prizeInId, content, queueName, content); //初始化日志 Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-s2", "接收mq数据日志"); string prizeObjectId = prizeObject(sub.id, sub.prizeObj, content); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-s3", "接收mq数据日志"); var recursionFlag = sub.recursionFlag; //是否递归 setLogStep(sub.id, "是否递归", recursionFlag ? "是" : "否"); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-s4", "接收mq数据日志"); bool check = prizeSendDo(projectId, sub, prizeObjectId, content, new PriLoopSet(), startData); if(check) { List rootCondiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content, startData); if(recursionFlag) { Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop0", "接收mq数据日志"); List queryCondiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content, startData); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop1", "接收mq数据日志"); // setLogStep(sub.id, "查询原始数据", queryCondiDic); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop2", "接收mq数据日志"); var loopSet = loopSetService.GetFirst(m => m.listId == sub.id) ?? new PriLoopSet(); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop3", "接收mq数据日志"); var recursionStartTable = recursionStartTableService.GetFirst(m => m.listId == sub.id) ?? new PriRecursionStartTable(); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop4", "接收mq数据日志"); var tableEnName = loopSet.tableEnName; //递归查询表 var parentField = loopSet.parentField; //父字段 var sonField = loopSet.sonField; //子字段 var afterPrizeFlag = loopSet.afterPrizeFlag; //发奖后是否继续 var db = initDb(loopSet.databaseId); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop5", "接收mq数据日志"); string objId = prizeObjectId; bool op = true; int index = 0; loopAmount = 0; List> loopLogDic = new(); while(!string.IsNullOrEmpty(objId) && objId != "0" && op) { Dictionary loopLog = new(); List condiDic = loopCondition(projectId, sub, objId, content); condiDic.AddRange(rootCondiDic); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop-in-1", "接收mq数据日志"); loopLog.Add("查询" + objId + "匹配数据", condiDic); if(condiDic.Count > 0) { bool prizeFlag = false; List> logStepDics = new(); var groupNos = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id).ToList().Select(m => m.groupNo).Distinct().ToList(); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop-in-2", "接收mq数据日志"); foreach(var groupNo in groupNos) { var conditions = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id && m.groupNo == groupNo); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop-in-11", "接收mq数据日志"); if(conditions.Count > 0) { int allCount = conditions.Count; //所有奖励条件数 int passCount = 0; //通过条件数 foreach(var condition in conditions) { if(condition.startIndex <= index) { Dictionary logStepDic = new(); var returnFieldId = condition.returnFieldId; //条件返回字段 returnFieldId = MatchExpressionVal(returnFieldId); var fieldQueryKind = condition.fieldQueryKind; //匹配条件 var fieldQueryModel = condition.fieldQueryModel; //匹配方式 var fieldQueryValue = condition.fieldQueryValue; //匹配值 var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型 string checkObj = ""; string checkTitle = ""; if(returnFieldId.Contains(",")) { string[] returnFieldIdList = returnFieldId.Split(','); foreach(string subField in returnFieldIdList) { string val = GetQueryTableData(condiDic, subField); checkObj += val + ","; string title = GetQueryTableTitle(condiDic, subField); checkTitle += title + ","; } checkObj = checkObj.TrimEnd(','); checkTitle = checkTitle.TrimEnd(','); } else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")")) { string expresssion = returnFieldId; checkTitle = returnFieldId; string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' }); foreach(string returnField in returnFields) { string val = GetQueryTableData(condiDic, returnField); if(val == returnField) val = "0"; expresssion = expresssion.Replace(returnField, Function.CheckNum(val)); string title = GetQueryTableTitle(condiDic, returnField); checkTitle = checkTitle.Replace(returnField, title); } DataTable dt = new(); checkObj = dt.Compute(expresssion, "false").ToString(); } else if(returnFieldId.StartsWith("val")) { checkObj = returnFieldId.Replace("val{", "").Replace("}", ""); } else { checkObj = GetQueryTableData(condiDic, returnFieldId); checkTitle = GetQueryTableTitle(condiDic, returnFieldId); } logStepDic.Add("标题", checkTitle); logStepDic.Add("分组", condition.groupNo); logStepDic.Add("匹配条件", getQueryKind(fieldQueryKind)); logStepDic.Add("匹配方式", getQueryModel(fieldQueryModel)); logStepDic.Add("匹配值", fieldQueryValue); logStepDic.Add("实际值", checkObj); var checkVal = fieldQueryValue; bool passFlag = false; if(fieldQueryKind == "1") //模糊匹配 { if(fieldQueryValueType == "text") { if(checkObj.ToString().Contains(GetExpressionVal(checkVal))) { passCount += 1; passFlag = true; } } } else if(fieldQueryKind == "2") //精确匹配 { if(fieldQueryValueType == "int") { if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType == "number") { if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal))) { passCount += 1; passFlag = true; } } else { if(checkObj.ToString() == GetExpressionVal(checkVal)) { passCount += 1; passFlag = true; } } } else if(fieldQueryKind == "3") //范围匹配 { string[] val = RangeSplit(checkVal); string valLeft = val[0]; string valRight = val[1]; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight]))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft]))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight]))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType == "int") { if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight]))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft]))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight]))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType.StartsWith("date")) { checkObj = checkDateTime(checkObj); if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight])) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft])) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight])) { passCount += 1; passFlag = true; } } } else if(fieldQueryModel == "fixed_value") { string checkValLeft = valLeft.Replace("#{", "").Replace("}#", ""); string checkValRight = valRight.Replace("#{", "").Replace("}#", ""); if(checkValLeft.Contains(",")) checkValLeft = checkValLeft.Split(',')[0]; if(checkValRight.Contains(",")) checkValRight = checkValRight.Split(',')[0]; valLeft = GetExpressionVal(valLeft); valRight = GetExpressionVal(valRight); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(valLeft)) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType == "int") { if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(valLeft)) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType.StartsWith("date")) { if(valLeft == "0") valLeft = ""; if(valRight == "0") valRight = ""; if(checkObj != "0" && checkObj != "") { checkObj = checkDateTime(checkObj); if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight))) { passCount += 1; passFlag = true; } } } } else if(fieldQueryModel == "query_field") { valLeft = GetComputeVal(queryCondiDic, valLeft); valRight = GetComputeVal(queryCondiDic, valRight); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(valLeft)) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType == "int") { if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(valLeft)) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType.StartsWith("date")) { if(valLeft == "0") valLeft = ""; if(valRight == "0") valRight = ""; if(checkObj != "0" && checkObj != "") { checkObj = checkDateTime(checkObj); if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight))) { passCount += 1; passFlag = true; } } } } } else if(fieldQueryKind == "4") //取反匹配 { if(fieldQueryValueType == "int") { if(int.Parse(checkObj) != int.Parse(Function.CheckInt(checkVal))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType == "number") { if(decimal.Parse(checkObj) != decimal.Parse(Function.CheckNum(checkVal))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType == "text") { if(checkObj.ToString() != GetExpressionVal(checkVal)) { passCount += 1; passFlag = true; } } } else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除 { string val = ","; string[] valList = checkVal.Split(','); if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); foreach(string subVal in valList) { val += req[subVal] + ","; } } else if(fieldQueryModel == "fixed_value") { foreach(string subVal in valList) { val += GetExpressionVal(subVal) + ","; } } else if(fieldQueryModel == "db_field") { foreach(string subVal in valList) { val += GetDbExpressionVal(subVal) + ","; } } if(fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ",")) { passCount += 1; passFlag = true; } if(fieldQueryKind == "6" && !val.Contains("," + checkObj.ToString() + ",")) { passCount += 1; passFlag = true; } } logStepDic.Add("状态", passFlag ? "通过" : "未通过"); logStepDics.Add(logStepDic); } } if(loopSet.conditionMode == "all" && passCount == allCount) prizeFlag = true; else if(loopSet.conditionMode == "one" && passCount >= 1) prizeFlag = true; else if(loopSet.conditionMode == "two" && passCount >= 2) prizeFlag = true; else if(loopSet.conditionMode == "three" && passCount >= 3) prizeFlag = true; // else prizeFlag = false; } // else // { // prizeFlag = false; // } } loopLog.Add(objId + "匹配情况", logStepDics); loopLog.Add("匹配结果", prizeFlag); if(prizeFlag) { prizeAck(projectId, sub, objId, content, new PriLoopSet(), rootCondiDic, startData); op = afterPrizeFlag; } Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop-in-3", "接收mq数据日志"); } loopLogDic.Add(loopLog); var parent = db.Ado.GetScalar("select " + parentField + " from " + tableEnName + " where " + sonField + "=" + objId); if(parent != null) { objId = parent.ToString(); } else { objId = "0"; } index += 1; } setLogStep(sub.id, "向上递归流程", loopLogDic); } else { prizeAck(projectId, sub, prizeObjectId, content, new PriLoopSet(), rootCondiDic, startData); } } } static decimal loopAmount = 0; public static bool prizeSendDo(int projectId, PriList sub, string prizeObjectId, string content, PriLoopSet set, Dictionary startData) { var projectService = App.GetService(); var recordService = App.GetService(); var conditionService = App.GetService(); var returnFieldService = App.GetService(); // var queryTableService = App.GetService(); var amountSetService = App.GetService(); //查询匹配条件 Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p1", "接收mq数据日志"); List condiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content, startData); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p2", "接收mq数据日志"); if(sub.prizeSourceFieldType == "loop") MergeCondiDic(condiDic, loopCondition(projectId, sub, prizeObjectId, content)); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p3", "接收mq数据日志"); setLogStep(sub.id, "发放奖励查询来源数据", condiDic); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p4", "接收mq数据日志"); var prizeSourceField = sub.prizeSourceField; //奖励金额来源字段(对应条件匹配返回字段) var prizePercent = sub.prizePercent; //奖励比例 var prizeAmount = sub.prizeAmount; //奖励固定值 var prizeContent = sub.prizeContent; //奖励内容 var conditionMode = sub.conditionMode; //条件模式 var recursionFlag = sub.recursionFlag; //是否递归 var prizeCode = sub.prizeCode; //奖励代码 prizeSourceField = MatchExpressionVal(prizeSourceField); bool op = false; var groupNos = conditionService.GetList(m => m.listId == sub.id).ToList().Select(m => m.groupNo).Distinct().ToList(); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p5", "接收mq数据日志"); foreach(var groupNo in groupNos) { var conditions = conditionService.GetList(m => m.listId == sub.id && m.groupNo == groupNo); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p6", "接收mq数据日志"); // setLogStep(sub.id, "发放奖励匹配条件", condiDic); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p7", "接收mq数据日志"); int allCount = conditions.Count; //所有奖励条件数 int passCount = 0; //通过条件数 List> logStepDics = new(); foreach(var condition in conditions) { Dictionary logStepDic = new(); var returnFieldId = condition.returnFieldId; //条件返回字段 returnFieldId = MatchExpressionVal(returnFieldId); var fieldQueryKind = condition.fieldQueryKind; //匹配条件 var fieldQueryModel = condition.fieldQueryModel; //匹配方式 var fieldQueryValue = condition.fieldQueryValue; //匹配值 var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型 string checkObj = ""; string checkTitle = ""; if(returnFieldId.Contains(",")) { string[] returnFieldIdList = returnFieldId.Split(','); foreach(string subField in returnFieldIdList) { string val = GetQueryTableData(condiDic, subField); checkObj += val + ","; string title = GetQueryTableTitle(condiDic, subField); checkTitle += title + ","; } checkObj = checkObj.TrimEnd(','); checkTitle = checkTitle.TrimEnd(','); } else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")")) { string expresssion = returnFieldId; checkTitle = returnFieldId; string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' }); foreach(string returnField in returnFields) { string val = GetQueryTableData(condiDic, returnField); expresssion = expresssion.Replace(returnField, Function.CheckNum(val)); string title = GetQueryTableTitle(condiDic, returnField); checkTitle = checkTitle.Replace(returnField, title); } DataTable dt = new(); checkObj = dt.Compute(expresssion, "false").ToString(); } else if(returnFieldId.StartsWith("val")) { checkObj = returnFieldId.Replace("val{", "").Replace("}", ""); } else { checkObj = GetQueryTableData(condiDic, returnFieldId); checkTitle = GetQueryTableTitle(condiDic, returnFieldId); if(checkObj == returnFieldId) { checkObj = getRequestParams(projectId, content, returnFieldId); checkTitle = checkObj; } } // if(!sub.recursionFlag) // { logStepDic.Add("标题", checkTitle); logStepDic.Add("分组", condition.groupNo); logStepDic.Add("匹配条件", getQueryKind(fieldQueryKind)); logStepDic.Add("匹配方式", getQueryModel(fieldQueryModel)); logStepDic.Add("匹配值", fieldQueryValue); logStepDic.Add("实际值", checkObj); // } string checkVal = fieldQueryValue; bool passFlag = false; if(fieldQueryKind == "1") //模糊匹配 { if(fieldQueryValueType == "text") { if(checkObj.ToString().Contains(GetExpressionVal(checkVal))) { passCount += 1; passFlag = true; } } } else if(fieldQueryKind == "2") //精确匹配 { if(fieldQueryValueType == "int") { if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType == "number") { if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal))) { passCount += 1; passFlag = true; } } else { if(checkObj.ToString() == GetExpressionVal(checkVal)) { passCount += 1; passFlag = true; } } } else if(fieldQueryKind == "3") //范围匹配 { string[] val = RangeSplit(checkVal); string valLeft = val[0]; string valRight = val[1]; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight]))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft]))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight]))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType == "int") { if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight]))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft]))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight]))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType.StartsWith("date")) { checkObj = checkDateTime(checkObj); if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight])) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft])) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight])) { passCount += 1; passFlag = true; } } } else if(fieldQueryModel == "fixed_value") { valLeft = GetExpressionVal(valLeft); valRight = GetExpressionVal(valRight); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType == "int") { if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckNum(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType.StartsWith("date")) { if(valLeft == "0") valLeft = ""; if(valRight == "0") valRight = ""; if(checkObj != "0" && checkObj != "") { checkObj = checkDateTime(checkObj); if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight))) { passCount += 1; passFlag = true; } } } } else if(fieldQueryModel == "query_field") { string checkValLeft = valLeft.Replace("#{", "").Replace("}#", ""); string checkValRight = valRight.Replace("#{", "").Replace("}#", ""); if(checkValLeft.Contains(",")) checkValLeft = checkValLeft.Split(',')[0]; if(checkValRight.Contains(",")) checkValRight = checkValRight.Split(',')[0]; if(!string.IsNullOrEmpty(valLeft)) valLeft = valLeft.Replace(checkValLeft, GetQueryTableData(condiDic, checkValLeft)); if(!string.IsNullOrEmpty(valRight)) valRight = valRight.Replace(checkValRight, GetQueryTableData(condiDic, checkValRight)); valLeft = GetExpressionVal(valLeft); valRight = GetExpressionVal(valRight); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType == "int") { if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckNum(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType.StartsWith("date")) { if(valLeft == "0") valLeft = ""; if(valRight == "0") valRight = ""; if(checkObj != "0" && checkObj != "") { checkObj = checkDateTime(checkObj); if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight))) { passCount += 1; passFlag = true; } else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft))) { passCount += 1; passFlag = true; } else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight))) { passCount += 1; passFlag = true; } } } } } else if(fieldQueryKind == "4") //取反匹配 { if(fieldQueryValueType == "int") { if(int.Parse(Function.CheckNum(checkObj.ToString())) != int.Parse(Function.CheckInt(checkVal))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType == "number") { if(decimal.Parse(Function.CheckNum(checkObj.ToString())) != decimal.Parse(Function.CheckNum(checkVal))) { passCount += 1; passFlag = true; } } else if(fieldQueryValueType == "text") { if(checkObj.ToString() != GetExpressionVal(checkVal)) { passCount += 1; passFlag = true; } } } else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除 { string val = ","; string[] valList = checkVal.Split(','); if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); foreach(string subVal in valList) { val += req[subVal] + ","; } } else if(fieldQueryModel == "fixed_value") { foreach(string subVal in valList) { val += GetExpressionVal(subVal) + ","; } } else if(fieldQueryModel == "db_field") { foreach(string subVal in valList) { val += GetDbExpressionVal(subVal) + ","; } } if (fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ",")) { passCount += 1; passFlag = true; } if(fieldQueryKind == "6" && !val.Contains("," + checkObj.ToString() + ",")) { passCount += 1; passFlag = true; } } // if(!sub.recursionFlag) // { logStepDic.Add("状态", passFlag ? "通过" : "未通过"); logStepDics.Add(logStepDic); // } } setLogStep(sub.id, "匹配结果", logStepDics); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p8", "接收mq数据日志"); if(conditionMode == "all" && passCount == allCount && passCount > 0) op = true; else if(conditionMode == "one" && passCount >= 1) op = true; else if(conditionMode == "two" && passCount >= 2) op = true; else if(conditionMode == "three" && passCount >= 3) op = true; } setLogStep(sub.id, "是否通过", op ? "是" : "否"); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p9", "接收mq数据日志"); // if(op) //满足条件 // { // } // if(!sub.recursionFlag) // { setLogStatus(sub.id, op ? 1 : 0); // } return op; } public static decimal prizeAck(int projectId, PriList sub, string prizeObjectId, string content, PriLoopSet set, List condiDic, Dictionary startData) { var projectService = App.GetService(); var recordService = App.GetService(); var conditionService = App.GetService(); var returnFieldService = App.GetService(); // var queryTableService = App.GetService(); var amountSetService = App.GetService(); var project = projectService.GetFirst(m => m.id == projectId) ?? new PriProject(); var prizeSourceField = sub.prizeSourceField; //奖励金额来源字段(对应条件匹配返回字段) var prizePercent = sub.prizePercent; //奖励比例 var prizeAmount = sub.prizeAmount; //奖励固定值 var prizeContent = sub.prizeContent; //奖励内容 var conditionMode = sub.conditionMode; //条件模式 var recursionFlag = sub.recursionFlag; //是否递归 var prizeCode = sub.prizeCode; //奖励代码 decimal prizeAmt = 0; prizeSourceField = MatchExpressionVal(prizeSourceField); bool repeatFlag = sub.repeatFlag; decimal number = 0; if(prizeSourceField.Contains("/")) { number = decimal.Parse(prizeSourceField.Split('/')[1]); prizeSourceField = prizeSourceField.Split('/')[0]; } string prizeSourceData = ""; if(prizeSourceField.Contains(",")) { string[] list = prizeSourceField.Split(','); foreach(string subField in list) { string val = GetQueryTableData(condiDic, subField); if(subField == val) val = getRequestParams(projectId, content, subField); if(subField == val) val = GetStartData(startData, subField); prizeSourceData += val + ","; } prizeSourceData = prizeSourceData.TrimEnd(','); } else { if(sub.prizeSourceFieldType == "request_param") { prizeSourceData = getRequestParams(projectId, content, prizeSourceField); } else { prizeSourceData = GetQueryTableData(condiDic, prizeSourceField); } } if(string.IsNullOrEmpty(prizeSourceData)) prizeSourceData = "0"; if(prizeSourceField.Contains("/") && number > 0) { decimal prizeSourceDataNum = decimal.Parse(prizeSourceData) / number; prizeSourceData = prizeSourceDataNum.ToString("f2"); } var amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField == prizeSourceData); if(amountSet != null) { prizePercent = amountSet.prizePercent; prizeAmount = amountSet.prizeAmount; prizeCode = amountSet.prizeCode; repeatFlag = amountSet.repeatFlag; } Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p9", "接收mq数据日志"); if(!prizeSourceData.Contains("$") && !prizeSourceData.Contains("=") && prizeSourceData.Contains(",")) { string[] prizeSourceDataList = prizeSourceData.Split(','); string checkField = ""; for (int i = 0; i < prizeSourceDataList.Length - 1; i++) { checkField += prizeSourceDataList[i] + ","; } amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField.StartsWith(checkField) && m.prizeSourceField.EndsWith(",%")); if(amountSet != null) { prizePercent = amountSet.prizePercent; prizeAmount = amountSet.prizeAmount; prizeCode = amountSet.prizeCode; repeatFlag = amountSet.repeatFlag; prizeSourceData = prizeSourceDataList[prizeSourceDataList.Length - 1]; } } Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p10", "接收mq数据日志"); string[] prizeSourceFieldList = prizeSourceData.Split(','); var amountSets = amountSetService.GetList(m => m.listId == sub.id && m.prizeSourceField.Contains("${")); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p11", "接收mq数据日志"); foreach(var subAmountSet in amountSets) { string subPrizeSourceField = subAmountSet.prizeSourceField; for (int i = 0; i < prizeSourceFieldList.Length; i++) { subPrizeSourceField = subPrizeSourceField.Replace("${" + i + "}", prizeSourceFieldList[i]); } DataTable dt = new(); string chk = dt.Compute(subPrizeSourceField, "false").ToString(); if(chk == "True") { prizePercent = subAmountSet.prizePercent; prizePercent = subAmountSet.prizePercent; prizeAmount = subAmountSet.prizeAmount; prizeCode = subAmountSet.prizeCode; repeatFlag = subAmountSet.repeatFlag; prizeSourceData = prizeSourceFieldList[subAmountSet.prizeSourceFieldIndex]; break; } } Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p12", "接收mq数据日志"); if(prizePercent > 0) prizeAmt += decimal.Parse(Function.CheckNum(prizeSourceData)) * prizePercent; if(prizeAmount > 0) prizeAmt += prizeAmount; decimal getPrizeAmount = prizeAmt; if(set.levelDiffFlag) prizeAmt -= loopAmount; setLogStep(sub.id, "发放金额", prizeAmt); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p13", "接收mq数据日志"); if(prizeAmt > 0) { prizeAmt = Util.PublicFunction.NumberFormat(prizeAmt); setLogPrizeAmount(sub.id, prizeAmt); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p14", "接收mq数据日志"); var req = getRequestParams(projectId, content); // var requestParamField = req[sub.requestParamField]; var sendFlag = false; if(!repeatFlag) sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.prizeCode == prizeCode && m.requestParamField == content); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p15", "接收mq数据日志"); if(!sendFlag && prizeObjectId != "0" && !string.IsNullOrEmpty(prizeObjectId)) { PriRecord item = new PriRecord() { createDate = DateTime.Now, projectId = projectId, listId = sub.id, prizeAmount = prizeAmt, prizeCode = prizeCode, prizeObjId = prizeObjectId, requestParamField = content, batchNo = batchNo, }; recordService.Add(item); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p16", "接收mq数据日志"); Dictionary prizeItem = new Dictionary(); prizeItem.Add("prize_date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); prizeItem.Add("prize_name", sub.prizeName); prizeItem.Add("prize_code", prizeCode); prizeItem.Add("batch_no", batchNo); prizeItem.Add("request_param_field", content); List> prizeItemList = new List>(); Dictionary prizeItemSub = new Dictionary(); prizeItemSub.Add("prize_amount", prizeAmt); prizeItemSub.Add("prize_obj", prizeObjectId); prizeItemList.Add(prizeItemSub); prizeItem.Add("prize_list", prizeItemList); string prizeOutContent = Newtonsoft.Json.JsonConvert.SerializeObject(prizeItem); setLogFieldValue(sub.id, "prizeOutContent", prizeOutContent); setLogFieldValue(sub.id, "prizeOutUrl", project.noticeUrl); Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p17", "接收mq数据日志"); if(project.requestMode == "http" && !string.IsNullOrEmpty(project.noticeUrl)) { int status = -1; string noticeJson = Function.PostWebRequest(project.noticeUrl, prizeOutContent, "application/json"); Function.WriteLog(noticeJson, "通知返回报文"); JsonData jsonObj = JsonMapper.ToObject(noticeJson); if(jsonObj["status"].ToString() == "1") { status = 1; } Function.WriteLog(status.ToString(), "通知返回报文"); var sendItem = recordService.GetFirst(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == content && m.status == 0); if(sendItem != null) { Function.WriteLog("in", "通知返回报文"); sendItem.status = status; recordService.Update(sendItem); Function.WriteLog("end", "通知返回报文"); } } else if(project.requestMode == "mq") {} else if(project.requestMode == "db") { prizeToDatabase(projectId, sub.id, content, condiDic, prizeAmt, startData); //入库 } Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p18", "接收mq数据日志"); } else if(project.requestMode == "db") { prizeToDatabase(projectId, sub.id, content, condiDic, prizeAmt, startData); //入库 } loopAmount = getPrizeAmount; } return prizeAmt; } //递归条件判断 public static List loopCondition(int projectId, PriList sub, string objId, string content) { List dic = new(); var queryTableService = App.GetService(); var queryFieldService = App.GetService(); var queryReturnFieldService = App.GetService(); int passCount = 0; //查询表 var queryTables = queryTableService.GetList(m => m.listId == sub.id).OrderByDescending(m => m.sort).ThenBy(m => m.id).ToList(); int allCount = queryTables.Count; foreach(var queryTable in queryTables) { //查询返回字段 string fields = "1"; string tableEnName = queryTable.tableEnName; if(tableEnName.Contains("#{")) tableEnName = MatchExpressionVal(tableEnName); Dictionary fieldDic = new(); var returnFields = queryReturnFieldService.GetList(m => m.objectTableId == queryTable.id); if(returnFields.Count > 0) { fields = ""; foreach(var returnField in returnFields) { string aliasName = returnField.fieldAliasName; if(string.IsNullOrEmpty(aliasName)) aliasName = tableEnName + "_" + returnField.fieldEnName; if(returnField.fieldReturnKind == "2") { fields += "count(" + returnField.fieldEnName + ") " + aliasName + ","; } else if(returnField.fieldReturnKind == "3") { fields += "sum(" + returnField.fieldEnName + ") " + aliasName + ","; } else if(returnField.fieldReturnKind == "4") { fields += "avg(" + returnField.fieldEnName + ") " + aliasName + ","; } else if(returnField.fieldReturnKind == "5") { fields += "max(" + returnField.fieldEnName + ") " + aliasName + ","; } else if(returnField.fieldReturnKind == "6") { fields += "min(" + returnField.fieldEnName + ") " + aliasName + ","; } else { fields += returnField.fieldEnName + " " + aliasName + ","; } fieldDic.Add(aliasName, returnField.fieldName); } fields = fields.TrimEnd(','); } //查询匹配条件 string condi = ""; var queryFields = queryFieldService.GetList(m => m.objectTableId == queryTable.id); foreach(var queryField in queryFields) { string fieldEnName = queryField.fieldEnName; string fieldQueryKind = queryField.fieldQueryKind; string fieldQueryModel = queryField.fieldQueryModel; string fieldQueryValue = queryField.fieldQueryValue; if(fieldQueryModel == "loop_field") fieldQueryValue = objId; string fieldQueryValueType = queryField.fieldQueryValueType; if(fieldQueryKind == "1") //模糊匹配 { condi += " and " + fieldEnName + " like "; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; condi += "'%" + val + "%'"; } else if(fieldQueryModel == "fixed_value") { condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'"; } else if(fieldQueryModel == "query_field") { condi += "'%" + GetQueryTableData(dic, fieldQueryValue) + "%'"; } else if(fieldQueryModel == "db_field") { condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'"; } } else if(fieldQueryKind == "2") //精确匹配 { condi += " and " + fieldEnName + "="; string val = fieldQueryValue; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; } else if(fieldQueryModel == "fixed_value") { val = GetExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "query_field") { val = GetQueryTableData(dic, fieldQueryValue); } else if(fieldQueryModel == "db_field") { val = GetDbExpressionVal(fieldQueryValue); } if(fieldQueryValueType == "text") { val = "'" + val + "'"; } condi += val; } else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除 { if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in ("; else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in ("; string val = ""; string[] valList = fieldQueryValue.Split(','); if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); foreach(string subval in valList) { if(fieldQueryValueType == "text") { val += "'" + req[subval] + "',"; } else { val += req[subval] + ","; } } } else if(fieldQueryModel == "fixed_value") { foreach(string subval in valList) { if(fieldQueryValueType == "text") { val += "'" + GetExpressionVal(subval) + "',"; } else { val += GetExpressionVal(subval) + ","; } } } else if(fieldQueryModel == "query_field") { foreach(string subval in valList) { if(fieldQueryValueType == "text") { val += "'" + GetQueryTableData(dic, subval) + "',"; } else { val += GetQueryTableData(dic, subval) + ","; } } } else if(fieldQueryModel == "db_field") { foreach(string subval in valList) { if(fieldQueryValueType == "text") { val += "'" + GetDbExpressionVal(subval) + "',"; } else { val += GetDbExpressionVal(subval) + ","; } } } val = val.TrimEnd(','); condi += val + ")"; } else if(fieldQueryKind == "3") //范围匹配 { string[] val = RangeSplit(fieldQueryValue); if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]]; if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]]; } else { if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'"; if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'"; } } else if(fieldQueryModel == "fixed_value") { if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0]; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1]; } else { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'"; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'"; } } else if(fieldQueryModel == "db_field") { if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0]; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1]; } else { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'"; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'"; } } } else if(fieldQueryKind == "4") //取反匹配 { condi += " and " + fieldEnName + "!="; string val = ""; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; } else if(fieldQueryModel == "fixed_value") { val = GetExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "db_field") { val = GetDbExpressionVal(fieldQueryValue); } if(fieldQueryValueType == "text") { val = "'" + val + "'"; } condi += val; } } var db = initDb(queryTable.databaseId); string sql = "select " + fields + " from " + tableEnName + " where 1=1" + condi; if(!string.IsNullOrEmpty(queryTable.orderBy)) { sql += " order by " + queryTable.orderBy; } sql += " limit 1"; var items = db.Ado.GetDataTable(sql); if(items.Rows.Count > 0) { foreach(string field in fieldDic.Keys) { if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition() { FieldName = fieldDic[field], FieldEnName = field, Value = items.Rows[0][field].ToString() }); } } } return dic; } //奖励入库 public static void prizeToDatabase(int projectId, int listId, string content, List condiDic, decimal prize_amt, Dictionary startData) { var prizeInTableService = App.GetService(); var prizeInFieldService = App.GetService(); var prizeInQueryFieldService = App.GetService(); //入库表 var prizeInTables = prizeInTableService.GetList(m => m.listId == listId); foreach(var prizeInTable in prizeInTables) { var db = initDb(prizeInTable.databaseId); Dictionary doFields = new(); List inFields = new(); //入库字段 var prizeInFields = prizeInFieldService.GetList(m => m.inTableId == prizeInTable.id); foreach(var prizeInField in prizeInFields) { string fieldEnName = prizeInField.fieldEnName; string fieldQueryModel = prizeInField.fieldQueryModel; string fieldQueryValue = prizeInField.fieldQueryValue; fieldQueryValue = fieldQueryValue.Replace("${prize_amt}", prize_amt.ToString()); fieldQueryValue = GetDbExpressionVal(fieldQueryValue, projectId, content, condiDic, startData); fieldQueryValue = MatchExpressionVal(fieldQueryValue); string fieldQueryValueType = prizeInField.fieldQueryValueType; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); fieldQueryValue = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; } else if(fieldQueryModel == "query_field") { if (fieldQueryValue.Contains("+") || fieldQueryValue.Contains("-") || fieldQueryValue.Contains("*") || fieldQueryValue.Contains("/") || fieldQueryValue.Contains("(") || fieldQueryValue.Contains(")")) { string[] texts = fieldQueryValue.Split(new char[] { '+', '-', '*', '/', '(', ')' }); foreach (string text in texts) { string val = GetStartData(startData, text); if(string.IsNullOrEmpty(val)) val = GetQueryTableData(condiDic, text); fieldQueryValue = fieldQueryValue.Replace(text, Function.CheckInt(val)); } DataTable dt = new(); fieldQueryValue = dt.Compute(fieldQueryValue, "false").ToString(); } else { fieldQueryValue = GetQueryTableData(condiDic, fieldQueryValue); } } else if(fieldQueryModel == "querystart_list_field") { fieldQueryValue = GetStartData(startData, fieldQueryValue); } else if(fieldQueryModel == "query_all_field") { if (fieldQueryValue.Contains("+") || fieldQueryValue.Contains("-") || fieldQueryValue.Contains("*") || fieldQueryValue.Contains("/") || fieldQueryValue.Contains("(") || fieldQueryValue.Contains(")")) { string[] texts = fieldQueryValue.Split(new char[] { '+', '-', '*', '/', '(', ')' }); foreach (string text in texts) { string val = GetStartData(startData, text); if(string.IsNullOrEmpty(val) || val == text) val = GetQueryTableData(condiDic, text); fieldQueryValue = fieldQueryValue.Replace(text, Function.CheckInt(val)); } DataTable dt = new(); fieldQueryValue = dt.Compute(fieldQueryValue, "false").ToString(); } else { string val = GetStartData(startData, fieldQueryValue); if(string.IsNullOrEmpty(val)) val = GetQueryTableData(condiDic, fieldQueryValue); fieldQueryValue = val; } } else if(fieldQueryModel == "fixed_value") { fieldQueryValue = GetExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "db_field") { fieldQueryValue = GetDbExpressionVal(fieldQueryValue); } else if(fieldQueryModel == "prize_amt") { if (fieldQueryValue.Contains("+") || fieldQueryValue.Contains("-") || fieldQueryValue.Contains("*") || fieldQueryValue.Contains("/") || fieldQueryValue.Contains("(") || fieldQueryValue.Contains(")")) { fieldQueryValue = fieldQueryValue.Replace("${prize_amt}", prize_amt.ToString()); if(fieldQueryValue.Contains("${")) { string[] texts = fieldQueryValue.Split(new char[] { '+', '-', '*', '/', '(', ')' }); foreach (string text in texts) { string val = GetStartData(startData, text); if(string.IsNullOrEmpty(val)) val = GetQueryTableData(condiDic, text); fieldQueryValue = fieldQueryValue.Replace(text, Function.CheckInt(val)); } } DataTable dt = new(); fieldQueryValue = dt.Compute(fieldQueryValue, "false").ToString(); } else { fieldQueryValue = prize_amt.ToString(); } } if(fieldQueryValueType == "text") doFields.Add(fieldEnName, fieldQueryValue); if(fieldQueryValueType == "int") doFields.Add(fieldEnName, int.Parse(Function.CheckInt(fieldQueryValue))); if(fieldQueryValueType == "number") doFields.Add(fieldEnName, decimal.Parse(Function.CheckNum(fieldQueryValue))); if(fieldQueryValueType == "datetime") doFields.Add(fieldEnName, DateTime.Parse(fieldQueryValue)); if(fieldQueryValueType == "bool") doFields.Add(fieldEnName, bool.Parse(fieldQueryValue)); inFields.Add(fieldEnName + "#cut#" + fieldQueryValue + "#cut#" + fieldQueryValueType + "#cut#" + prizeInField.fieldInModel); } //查询匹配条件 string condi = ""; var queryFields = prizeInQueryFieldService.GetList(m => m.inTableId == prizeInTable.id); foreach(var queryField in queryFields) { string fieldEnName = queryField.fieldEnName; string fieldQueryKind = queryField.fieldQueryKind; string fieldQueryModel = queryField.fieldQueryModel; string fieldQueryValue = queryField.fieldQueryValue; string fieldQueryValueType = queryField.fieldQueryValueType; if(fieldQueryKind == "1") //模糊匹配 { condi += " and " + fieldEnName + " like "; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; condi += "'%" + val + "%'"; } else if(fieldQueryModel == "fixed_value") { condi += "'%" + fieldQueryValue + "%'"; } else if(fieldQueryModel == "query_field") { condi += "'%" + GetQueryTableData(condiDic, fieldQueryValue) + "%'"; } else if(fieldQueryModel == "querystart_list_field") { condi += "'%" + GetStartData(startData, fieldQueryValue) + "%'"; } } else if(fieldQueryKind == "2") //精确匹配 { condi += " and " + fieldEnName + "="; string val = ""; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; } else if(fieldQueryModel == "fixed_value") { val = fieldQueryValue; } else if(fieldQueryModel == "query_field") { val = GetQueryTableData(condiDic, fieldQueryValue); } else if(fieldQueryModel == "querystart_list_field") { val = GetStartData(startData, fieldQueryValue); } if(fieldQueryValueType == "text") { val = "'" + val + "'"; } condi += val; } else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除 { if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in ("; else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in ("; string val = ""; string[] valList = fieldQueryValue.Split(','); if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + req[sub] + "',"; } else { val += req[sub] + ","; } } } else if(fieldQueryModel == "fixed_value") { foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + GetExpressionVal(sub) + "',"; } else { val += GetExpressionVal(sub) + ","; } } } else if(fieldQueryModel == "query_field") { foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + GetQueryTableData(condiDic, sub) + "',"; } else { val += GetQueryTableData(condiDic, sub) + ","; } } } else if(fieldQueryModel == "querystart_list_field") { foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + GetStartData(startData, sub) + "',"; } else { val += GetStartData(startData, sub) + ","; } } } else if(fieldQueryModel == "db_field") { foreach(string sub in valList) { if(fieldQueryValueType == "text") { val += "'" + GetDbExpressionVal(sub) + "',"; } else { val += GetDbExpressionVal(sub) + ","; } } } val = val.TrimEnd(','); condi += val + ")"; } else if(fieldQueryKind == "3") //范围匹配 { string[] val = RangeSplit(fieldQueryValue); if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]]; if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]]; } else { if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'"; if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'"; } } else if(fieldQueryModel == "fixed_value") { if(fieldQueryValueType == "number") { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0]; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1]; } else { if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + val[0] + "'"; if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + val[1] + "'"; } } } else if(fieldQueryKind == "4") //取反匹配 { condi += " and " + fieldEnName + "!="; string val = ""; if(fieldQueryModel == "request_param") { Dictionary req = getRequestParams(projectId, content); val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0"; } else if(fieldQueryModel == "fixed_value") { val = fieldQueryValue; } if(fieldQueryValueType == "text") { val = "'" + val + "'"; } condi += val; } } if(prizeInTable.excuteKind == "add") db.Insertable(doFields).AS(prizeInTable.tableEnName).ExecuteCommand(); if(prizeInTable.excuteKind == "update") db.Updateable(doFields).AS(prizeInTable.tableEnName).Where("1=1" + condi).ExecuteCommand(); if(prizeInTable.excuteKind == "update_or_add") { string doSql = ""; var check = db.Ado.GetDataTable("select 1 from " + prizeInTable.tableEnName + " where 1=1" + condi); if(check.Rows.Count > 0) { string fieldString = ""; foreach(var inField in inFields) { string[] inFieldData = inField.Split(new string[]{ "#cut#" }, StringSplitOptions.None); string fieldEnName = inFieldData[0]; string fieldQueryValue = inFieldData[1]; string fieldQueryValueType = inFieldData[2]; string fieldInModel = inFieldData[3]; if(fieldQueryValueType == "int" || fieldQueryValueType == "number" || fieldQueryValueType == "bool") { if(fieldInModel == "add") { fieldString += fieldEnName + "=" + fieldEnName + "+" + fieldQueryValue; } else { fieldString += fieldEnName + "=" + fieldQueryValue; } } else { if(fieldInModel == "add") { fieldString += fieldEnName + "=" + "concat(" + fieldEnName + ", '" + fieldQueryValue + "')"; } else { fieldString += fieldEnName + "=" + "'" + fieldQueryValue + "'"; } } fieldString += ","; } if(!string.IsNullOrEmpty(fieldString)) { fieldString = fieldString.TrimEnd(','); } doSql = "update " + prizeInTable.tableEnName + " set " + fieldString + " where 1=1" + condi; } else { string fieldString = ""; string valString = ""; foreach(var fieldEnName in doFields.Keys) { fieldString += fieldEnName; if(typeof(int) == doFields[fieldEnName].GetType() || typeof(decimal) == doFields[fieldEnName].GetType()) { valString += doFields[fieldEnName].ToString(); } else { valString += "'" + doFields[fieldEnName].ToString() + "'"; } fieldString += ","; valString += ","; } if(!string.IsNullOrEmpty(fieldString)) { fieldString = fieldString.TrimEnd(','); valString = valString.TrimEnd(','); } doSql = "insert into " + prizeInTable.tableEnName + " (" + fieldString + ") values (" + valString + ")"; } db.Ado.ExecuteCommand(doSql); } Function.WriteLog(DateTime.Now.ToString() + "\n" + prizeInTable.excuteKind + "\n" + prizeInTable.tableEnName + "\n" + Newtonsoft.Json.JsonConvert.SerializeObject(doFields) + "\n" + condi + "\n\n", "奖励入库数据"); } } //固定值表达式 public static string GetExpressionVal(string str) { if(str == "#{now}#") return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); if(str == "#{today}#") return DateTime.Now.ToString("yyyy-MM-dd"); if(str == "#{this_month}#") return DateTime.Now.ToString("yyyy-MM"); if(str.StartsWith("#{now") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss"); if(str.StartsWith("#{now") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss"); if(str.StartsWith("#{today") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd"); if(str.StartsWith("#{today") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd"); if(str.StartsWith("#{this_month") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM"); if(str.StartsWith("#{this_month") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM"); if(str.StartsWith("#{") && str.EndsWith("DAY}#")) return DateTime.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[0]).AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss"); if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) return DateTime.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[0]).AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss"); if(str.StartsWith("#{split") && str.EndsWith("}#")) { string[] data = str.Replace("#{", "").Replace("}#", "").Split(','); string text = data[1]; string splitTag = data[2]; string index = data[3]; return text.Split(new string[]{ splitTag }, StringSplitOptions.None)[int.Parse(index)]; } else if(str.StartsWith("#{") && str.EndsWith("}#")) { string[] data = str.Replace("#{", "").Replace("}#", "").Split(','); string tag = data[0]; string format = data[data.Length - 1]; if(tag == "now" && format.StartsWith("yyyy")) { if(data.Length == 2) { return DateTime.Now.ToString(format); } else if(data.Length == 4) { if(data[2] == "DAY") return DateTime.Now.AddDays(int.Parse(data[1])).ToString(format); if(data[2] == "MONTH") return DateTime.Now.AddMonths(int.Parse(data[1])).ToString(format); } } } return str; } public static string MatchExpressionVal(string str) { MatchCollection mc = Regex.Matches(str, "#\\{.*?\\}#"); foreach(Match m in mc) { str = str.Replace(m.Value, GetExpressionVal(m.Value)); } return str; } //库内字段值表达式 public static string GetDbExpressionVal(string str) { string[] data = str.Replace("#", "").Replace("{", "").Replace("}", "").Split(','); if(str.StartsWith("#{") && str.EndsWith("DAY}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " DAY)"; if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " MONTH)"; return str; } public static string GetDbExpressionVal(string str, int projectId, string content, List dic, Dictionary startData) { MatchCollection mc = Regex.Matches(str, "\\$\\{.*?\\}"); foreach(Match m in mc) { string matchValue = m.Value.Replace("${", "").Replace("}", ""); string val = ""; if(string.IsNullOrEmpty(val) || val == matchValue) val = getRequestParams(projectId, content, matchValue); if(string.IsNullOrEmpty(val) || val == matchValue) val = GetQueryTableData(dic, matchValue); if(string.IsNullOrEmpty(val) || val == matchValue) val = GetStartData(startData, matchValue); str = str.Replace(m.Value, val); } return str; } //四则混合运算 public static string GetComputeVal(List condiDic, string expresssion) { if (expresssion.Contains("+") || expresssion.Contains("-") || expresssion.Contains("*") || expresssion.Contains("/") || expresssion.Contains("(") || expresssion.Contains(")")) { string[] returnFields = expresssion.Split(new char[] { '+', '-', '*', '/', '(', ')' }); foreach (string returnField in returnFields) { if(condiDic.Any(m => m.FieldEnName == returnField)) { string val = GetQueryTableData(condiDic, returnField); expresssion = expresssion.Replace(returnField, Function.CheckNum(val)); } } DataTable dt = new(); return dt.Compute(expresssion, "false").ToString(); } return expresssion; } //获取查询条件数据 public static string GetQueryTableData(List condiDic, string key) { if(key.Contains("#{")) { Match m = Regex.Match(key, "\\$\\{.*?\\}\\$"); if(m.Success) { string keyString = m.Value.Replace("${", "").Replace("}$", ""); string val = condiDic.Any(m => m.FieldEnName == keyString) ? condiDic.FirstOrDefault(m => m.FieldEnName == keyString).Value.ToString() : key; key = key.Replace(m.Value, val); key = GetExpressionVal(key); return key; } } return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).Value.ToString() : key; } public static string GetQueryTableTitle(List condiDic, string key) { return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).FieldName : ""; } public static string GetStartData(Dictionary startData, string key) { return startData.ContainsKey(key) ? startData[key] : key; } //合并字典 public static void MergeCondiDic(List condiDic, List condiDic1) { foreach(QueryCondition sub in condiDic1) { condiDic.Add(sub); } } //记录日志 public static void addLog(int projectId, int listId, int prizeIn, string requestParam, string prizeInUrl, string content = "") { if(!logFlag) return; var logService = App.GetService(); logService.Add(new PriLog() { createDate = DateTime.Now, projectId = projectId, listId = listId, batchNo = batchNo, prizeIn = prizeIn, requestParam = requestParam, prizeInUrl = prizeInUrl, stepListIndex = getRequestParamsIndex(projectId, content), //获取参数索引字段值 }); } public static void setLogPrizeAmount(int listId, decimal prizeAmount) { if(!logFlag) return; var logService = App.GetService(); var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId); if(log != null) { log.prizeAmount = prizeAmount; logService.Update(log); } } public static void setLogStep(int listId, Dictionary step) { if(!logFlag) return; var logService = App.GetService(); var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId); if(log != null) { log.stepList += Newtonsoft.Json.JsonConvert.SerializeObject(step) + ","; logService.Update(log); } } public static void setLogStep(int listId, string key, object val) { if(!logFlag) return; var logService = App.GetService(); var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId); if(log != null) { log.stepList += "\"" + key + "\":" + Newtonsoft.Json.JsonConvert.SerializeObject(val) + ","; logService.Update(log); } } public static void setLogStatus(int listId, int status) { if(!logFlag) return; var logService = App.GetService(); var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId); if(log != null) { log.status = status; logService.Update(log); } } public static void setLogFieldValue(int listId, string field, string content) { if(!logFlag) return; var logService = App.GetService(); var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId); if(log != null) { if(field == "errLog") log.errLog = content; if(field == "prizeOutContent") log.prizeOutContent = content; if(field == "prizeOutUrl") log.prizeOutUrl = content; if(field == "stepListIndex") log.stepListIndex = content; logService.Update(log); } } public static string getQueryKind(string kind) { if(kind == "1") return "模糊匹配"; if(kind == "2") return "精确匹配"; if(kind == "4") return "取反匹配"; if(kind == "5") return "数组匹配"; if(kind == "6") return "数组排除"; if(kind == "3") return "范围匹配"; return kind; } public static string getQueryModel(string model) { if(model == "request_param") return "入参"; if(model == "query_field") return "条件匹配返回字段"; if(model == "loop_field") return "循环递归字段"; if(model == "loop_condition_field") return "循环递归条件字段"; if(model == "fixed_value") return "固定值"; if(model == "db_field") return "库内字段"; return model; } //检查时间格式,否则返回默认时间 public static string checkDateTime(string date) { DateTime s = DateTime.Now; if(DateTime.TryParse(date, out s)) { return date; } return "1900-01-01"; } public static string[] RangeSplit(string str) { if(str.Contains(" - ")) return str.Split(" - ", StringSplitOptions.None); return str.Split(':'); } } }