1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960 |
- using System.Data;
- using Common;
- using Infrastructure;
- using LitJson;
- using Microsoft.Extensions.Localization;
- using Model;
- using Model.Customer;
- using NuGet.Packaging;
- using Services;
- using System.Linq;
- using System.Net.Mime;
- namespace Util
- {
- public class PrizeDo
- {
- public static string batchNo = "";
- public static string publicStep = "";
- //发奖入口
- public static void sendPrize(int prizeInId, string content)
- {
- batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(3);
- publicStep = "";
- string priObjString = prizeInSet(prizeInId);
- if(!string.IsNullOrEmpty(priObjString))
- {
- string[] priObjData = priObjString.Split('|');
- string priListIds = priObjData[0];
- int projectId = int.Parse(priObjData[1]);
- prizeSend(projectId, prizeInId, priListIds, content);
- }
- }
- //接收入参
- public static Dictionary<string, string> getRequestParams(int projectId, string content)
- {
- Dictionary<string, string> dic = new Dictionary<string, string>();
- JsonData jsonData = JsonMapper.ToObject(content);
- var paramService = App.GetService<IPriProjectParamService>();
- 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 SqlSugarClient initDb(int id)
- {
- var databaseSetService = App.GetService<IPriDatabaseSetService>();
- 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<QueryCondition> condition(int projectId, List<int> ids, string content)
- {
- List<QueryCondition> dic = new List<QueryCondition>();
- var queryTableService = App.GetService<IPriQueryTableService>();
- var queryFieldService = App.GetService<IPriQueryFieldService>();
- var returnFieldService = App.GetService<IPriReturnFieldService>();
- //查询表
- var queryTables = queryTableService.GetList(m => ids.Contains(m.id));
- foreach(var queryTable in queryTables)
- {
- //查询返回字段
- string fields = "";
- Dictionary<string, string> fieldDic = new Dictionary<string, string>();
- var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id);
- foreach(var returnField in returnFields)
- {
- if(returnField.fieldReturnKind == "2")
- {
- fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
- }
- else if(returnField.fieldReturnKind == "3")
- {
- fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
- }
- else if(returnField.fieldReturnKind == "4")
- {
- fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
- }
- else
- {
- fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
- }
- fieldDic.Add(queryTable.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(fieldQueryKind == "1") //模糊匹配
- {
- condi += " and " + fieldEnName + " like ";
- if(fieldQueryModel == "request_param")
- {
- Dictionary<string, string> 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<string, string> 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<string, string> 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 = fieldQueryValue.Split(':');
- if(fieldQueryModel == "request_param")
- {
- Dictionary<string, string> 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<string, string> 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;
- }
- }
- }
- var db = initDb(queryTable.databaseId);
- string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
- 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 string prizeObject(int prizeObjectTag, string content)
- {
- Dictionary<string, object> dic = new Dictionary<string, object>();
- var prizeObjectTableService = App.GetService<IPriPrizeObjectTableService>();
- var prizeObjectFieldService = App.GetService<IPriPrizeObjectFieldService>();
- //查询表
- var prizeObjectTable = prizeObjectTableService.GetFirst(m => m.id == prizeObjectTag) ?? new PriPrizeObjectTable();
- //查询返回字段
- string field = prizeObjectTable.selectField;
- int projectId = prizeObjectTable.projectId;
- //查询匹配条件
- string condi = "";
- var queryFields = prizeObjectFieldService.GetList(m => m.objectTableId == prizeObjectTable.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<string, string> 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(fieldQueryKind == "2") //精确匹配
- {
- condi += " and " + fieldEnName + "=";
- string val = "";
- if(fieldQueryModel == "request_param")
- {
- Dictionary<string, string> 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;
- }
- 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<string, string> 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 + ")";
- }
- else if(fieldQueryKind == "3") //范围匹配
- {
- string[] val = fieldQueryValue.Split(':');
- if(fieldQueryModel == "request_param")
- {
- Dictionary<string, string> 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<string, string> 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(prizeObjectTable.databaseId);
- var item = db.Ado.GetScalar("select " + field + " from " + prizeObjectTable.tableEnName + " where 1=1" + condi);
- if(item != null)
- {
- return item.ToString();
- }
- return "0";
- }
- //奖励发放入口
- public static string prizeInSet(int prizeObjectTag)
- {
- Dictionary<string, object> dic = new Dictionary<string, object>();
- var prizeInSetService = App.GetService<IPriPrizeInSetService>();
- //查询表
- var prizeInSet = prizeInSetService.GetFirst(m => m.id == prizeObjectTag) ?? new PriPrizeInSet();
- if(prizeInSet.id > 0)
- {
- int projectId = prizeInSet.projectId;
- return prizeInSet.prizeListIds + "|" + projectId;
- }
- return "";
- }
- //奖励列表
- public static List<PriList> prizeList(int projectId, string prizeIds)
- {
- List<int> ids = Tools.SpitIntArrary(prizeIds, ',').ToList();
- var priListService = App.GetService<IPriListService>();
- 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)
- {
- var loopSetService = App.GetService<IPriLoopSetService>();
- var recursionStartTableService = App.GetService<IPriRecursionStartTableService>();
- var recursionStartConditionService = App.GetService<IPriRecursionStartConditionService>();
- var priList = prizeList(projectId, prizeIds);
- foreach(var sub in priList)
- {
- addLog(projectId, sub.id, prizeInId, content); //初始化日志
- string prizeObjectId = prizeObject(sub.prizeObj, content);
- var recursionFlag = sub.recursionFlag; //是否递归
- if(recursionFlag)
- {
- List<QueryCondition> queryCondiDic = condition(projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content);
- var loopSet = loopSetService.GetFirst(m => m.listId == sub.id) ?? new PriLoopSet();
- var recursionStartTable = recursionStartTableService.GetFirst(m => m.listId == sub.id) ?? new PriRecursionStartTable();
- var tableEnName = loopSet.tableEnName; //递归查询表
- var parentField = loopSet.parentField; //父字段
- var sonField = loopSet.sonField; //子字段
- var afterPrizeFlag = loopSet.afterPrizeFlag; //发奖后是否继续
- var db = initDb(recursionStartTable.databaseId);
- string objId = prizeObjectId;
- bool op = true;
- int index = 0;
- loopAmount = 0;
- while(!string.IsNullOrEmpty(objId) && objId != "0" && op)
- {
- List<QueryCondition> condiDic = loopCondition(projectId, sub, objId, content);
- if(condiDic.Count > 0)
- {
- bool prizeFlag = true;
- var conditions = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id);
- if(conditions.Count > 0)
- {
- int allCount = conditions.Count; //所有奖励条件数
- int passCount = 0; //通过条件数
- foreach(var condition in conditions)
- {
- if(condition.startIndex <= index)
- {
- Dictionary<string, string> logStepDic = new Dictionary<string, string>();
-
- var returnFieldId = condition.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, val);
- string title = GetQueryTableTitle(condiDic, returnField);
- checkTitle = checkTitle.Replace(returnField, title);
- }
- DataTable dt = new DataTable();
- checkObj = dt.Compute(expresssion, "false").ToString();
- }
- else
- {
- checkObj = GetQueryTableData(condiDic, returnFieldId);
- checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
- }
-
- logStepDic.Add("标题", checkTitle);
- 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 = checkVal.Split(':');
- string valLeft = val[0];
- string valRight = val[1];
- if(fieldQueryModel == "request_param")
- {
- Dictionary<string, string> 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"))
- {
- 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 != "")
- {
- 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 != "")
- {
- 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<string, string> 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 ? "通过" : "未通过");
- setLogStep(sub.id, Newtonsoft.Json.JsonConvert.SerializeObject(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;
- }
- if(prizeFlag)
- {
- decimal prizeAmt = prizeSendDo(projectId, sub, objId, content, loopSet);
- op = afterPrizeFlag;
- }
- }
- var parent = db.Ado.GetScalar("select " + parentField + " from " + tableEnName + " where " + sonField + "=" + objId);
- if(parent != null)
- {
- objId = parent.ToString();
- }
- else
- {
- objId = "0";
- }
- index += 1;
- }
- }
- else
- {
- prizeSendDo(projectId, sub, prizeObjectId, content, new PriLoopSet());
- }
- }
- }
- static decimal loopAmount = 0;
- public static decimal prizeSendDo(int projectId, PriList sub, string prizeObjectId, string content, PriLoopSet set)
- {
- var recordService = App.GetService<IPriRecordService>();
- var conditionService = App.GetService<IPriConditionService>();
- var returnFieldService = App.GetService<IPriReturnFieldService>();
- var queryTableService = App.GetService<IPriQueryTableService>();
- var amountSetService = App.GetService<IPriListAmountSetService>();
- //查询匹配条件
- List<QueryCondition> condiDic = condiDic = condition(projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content);
- if(sub.prizeSourceFieldType == "loop") MergeCondiDic(condiDic, loopCondition(projectId, sub, prizeObjectId, content));
- 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 conditions = conditionService.GetList(m => m.listId == sub.id);
- int allCount = conditions.Count; //所有奖励条件数
- int passCount = 0; //通过条件数
- List<Dictionary<string, string>> logStepDics = new List<Dictionary<string, string>>();
- foreach(var condition in conditions)
- {
- Dictionary<string, string> logStepDic = new Dictionary<string, string>();
- var returnFieldId = condition.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, val);
- string title = GetQueryTableTitle(condiDic, returnField);
- checkTitle = checkTitle.Replace(returnField, title);
- }
- DataTable dt = new DataTable();
- checkObj = dt.Compute(expresssion, "false").ToString();
- }
- else
- {
- checkObj = GetQueryTableData(condiDic, returnFieldId);
- checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
- }
- if(!sub.recursionFlag)
- {
- logStepDic.Add("标题", checkTitle);
- 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 = checkVal.Split(':');
- string valLeft = val[0];
- string valRight = val[1];
- if(fieldQueryModel == "request_param")
- {
- Dictionary<string, string> 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"))
- {
- 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 != "")
- {
- 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 != "")
- {
- 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<string, string> 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);
- }
- }
- bool op = false;
- decimal prizeAmt = 0;
- 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;
- if(op) //满足条件
- {
- decimal number = 0;
- if(prizeSourceField.Contains("/"))
- {
- number = decimal.Parse(prizeSourceField.Split('/')[1]);
- prizeSourceField = prizeSourceField.Split('/')[0];
- }
- string prizeSourceData = "";
- if(prizeSourceField.Contains(","))
- {
- string[] prizeSourceFieldList = prizeSourceField.Split(',');
- foreach(string subField in prizeSourceFieldList)
- {
- string val = GetQueryTableData(condiDic, subField);
- prizeSourceData += val + ",";
- }
- prizeSourceData = prizeSourceData.TrimEnd(',');
- }
- 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;
- }
- if(prizeSourceData.Contains(","))
- {
- string checkField = prizeSourceData.Split(',')[0] + ",";
- amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField.StartsWith(checkField) && m.prizeSourceField.EndsWith(",%"));
- if(amountSet != null)
- {
- prizePercent = amountSet.prizePercent;
- prizeAmount = amountSet.prizeAmount;
- prizeSourceData = prizeSourceData.Split(',')[1];
- }
- }
- if(prizePercent > 0) prizeAmt += decimal.Parse(Function.CheckNum(prizeSourceData)) * prizePercent;
- if(prizeAmount > 0) prizeAmt += prizeAmount;
- decimal getPrizeAmount = prizeAmt;
- if(set.levelDiffFlag) prizeAmt -= loopAmount;
- if(prizeAmt > 0)
- {
- setLogPrizeAmount(sub.id, prizeAmt);
- var req = getRequestParams(projectId, content);
- var requestParamField = req[sub.requestParamField];
- var sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == requestParamField);
- if(!sendFlag)
- {
- recordService.Add(new PriRecord()
- {
- createDate = DateTime.Now,
- projectId = projectId,
- listId = sub.id,
- prizeAmount = prizeAmt,
- prizeObjId = prizeObjectId,
- requestParamField = requestParamField,
- batchNo = batchNo,
- });
- loopAmount = getPrizeAmount;
- prizeToDatabase(projectId, sub.id, content, condiDic, prizeAmt); //入库
- }
- }
- }
- if(!sub.recursionFlag)
- {
- setLogStatus(sub.id, op ? 1 : 0);
- setLogStep(sub.id, Newtonsoft.Json.JsonConvert.SerializeObject(logStepDics));
- }
- return prizeAmt;
- }
- //递归条件判断
- public static List<QueryCondition> loopCondition(int projectId, PriList sub, string objId, string content)
- {
- List<QueryCondition> dic = new List<QueryCondition>();
- var queryTableService = App.GetService<IPriRecursionStartTableService>();
- var queryFieldService = App.GetService<IPriRecursionStartFieldService>();
- var queryReturnFieldService = App.GetService<IPriRecursionStartReturnFieldService>();
- int passCount = 0;
- //查询表
- var queryTables = queryTableService.GetList(m => m.listId == sub.id);
- int allCount = queryTables.Count;
- foreach(var queryTable in queryTables)
- {
- //查询返回字段
- string fields = "1";
- Dictionary<string, string> fieldDic = new Dictionary<string, string>();
- var returnFields = queryReturnFieldService.GetList(m => m.objectTableId == queryTable.id);
- if(returnFields.Count > 0)
- {
- fields = "";
- foreach(var returnField in returnFields)
- {
- if(returnField.fieldReturnKind == "2")
- {
- fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
- }
- else if(returnField.fieldReturnKind == "3")
- {
- fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
- }
- else if(returnField.fieldReturnKind == "4")
- {
- fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
- }
- else
- {
- fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
- }
- fieldDic.Add(queryTable.tableEnName + "_" + returnField.fieldEnName, 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<string, string> 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(fieldQueryKind == "2") //精确匹配
- {
- condi += " and " + fieldEnName + "=";
- string val = fieldQueryValue;
- if(fieldQueryModel == "request_param")
- {
- Dictionary<string, string> 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;
- }
- 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<string, string> 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 == "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 = fieldQueryValue.Split(':');
- if(fieldQueryModel == "request_param")
- {
- Dictionary<string, string> 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<string, string> 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 " + queryTable.tableEnName + " where 1=1" + condi;
- 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<QueryCondition> condiDic, decimal prize_amt)
- {
- var prizeInTableService = App.GetService<IPriPrizeInTableService>();
- var prizeInFieldService = App.GetService<IPriPrizeInFieldService>();
- var prizeInQueryFieldService = App.GetService<IPriPrizeInQueryFieldService>();
- //入库表
- var prizeInTables = prizeInTableService.GetList(m => m.listId == listId);
- foreach(var prizeInTable in prizeInTables)
- {
- var db = initDb(prizeInTable.databaseId);
- Dictionary<string, object> doFields = new Dictionary<string, object>();
- //入库字段
- 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;
- string fieldQueryValueType = prizeInField.fieldQueryValueType;
- if(fieldQueryModel == "request_param")
- {
- Dictionary<string, string> req = getRequestParams(projectId, content);
- fieldQueryValue = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
- }
- else if(fieldQueryModel == "query_field")
- {
- fieldQueryValue = GetQueryTableData(condiDic, fieldQueryValue);
- }
- else if(fieldQueryModel == "fixed_value")
- {
- fieldQueryValue = GetExpressionVal(fieldQueryValue);
- }
- else if(fieldQueryModel == "db_field")
- {
- fieldQueryValue = GetDbExpressionVal(fieldQueryValue);
- }
- else if(fieldQueryModel == "prize_amt")
- {
- fieldQueryValue = prize_amt.ToString();
- }
- if(fieldQueryValueType == "text") doFields.Add(fieldEnName, fieldQueryValue);
- if(fieldQueryValueType == "int") doFields.Add(fieldEnName, int.Parse(fieldQueryValue));
- if(fieldQueryValueType == "number") doFields.Add(fieldEnName, decimal.Parse(fieldQueryValue));
- if(fieldQueryValueType == "datetime") doFields.Add(fieldEnName, DateTime.Parse(fieldQueryValue));
- if(fieldQueryValueType == "bool") doFields.Add(fieldEnName, bool.Parse(fieldQueryValue));
- }
- //查询匹配条件
- 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<string, string> 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(fieldQueryKind == "2") //精确匹配
- {
- condi += " and " + fieldEnName + "=";
- string val = "";
- if(fieldQueryModel == "request_param")
- {
- Dictionary<string, string> 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);
- }
- 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<string, string> 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 == "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 = fieldQueryValue.Split(':');
- if(fieldQueryModel == "request_param")
- {
- Dictionary<string, string> 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<string, string> 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();
- 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");
- 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 GetComputeVal(List<QueryCondition> 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, val);
- }
- }
- DataTable dt = new DataTable();
- return dt.Compute(expresssion, "false").ToString();
- }
- return expresssion;
- }
- //获取查询条件数据
- public static string GetQueryTableData(List<QueryCondition> condiDic, string key)
- {
- return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).Value.ToString() : "0";
- }
- public static string GetQueryTableTitle(List<QueryCondition> condiDic, string key)
- {
- return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).FieldName : "";
- }
- //合并字典
- public static void MergeCondiDic(List<QueryCondition> condiDic, List<QueryCondition> condiDic1)
- {
- foreach(QueryCondition sub in condiDic1)
- {
- condiDic.Add(sub);
- }
- }
- //记录日志
- public static void addLog(int projectId, int listId, int prizeIn, string requestParam)
- {
- var logService = App.GetService<IPriLogService>();
- logService.Add(new PriLog()
- {
- createDate = DateTime.Now,
- projectId = projectId,
- listId = listId,
- batchNo = batchNo,
- prizeIn = prizeIn,
- requestParam = requestParam,
- });
- }
- public static void setLogPrizeAmount(int listId, decimal prizeAmount)
- {
- var logService = App.GetService<IPriLogService>();
- 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, string step)
- {
- var logService = App.GetService<IPriLogService>();
- var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
- if(log != null)
- {
- log.stepList += step;
- logService.Update(log);
- }
- }
- public static void setLogStatus(int listId, int status)
- {
- var logService = App.GetService<IPriLogService>();
- var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
- if(log != null)
- {
- log.status = status;
- logService.Update(log);
- }
- }
- }
- }
|