12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498 |
- 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 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);
- 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<IPriProjectService>();
- var project = projectService.GetFirst(m => m.id == projectId) ?? new PriProject();
- logFlag = project.logFlag;
- prizeSend(projectId, prizeInId, priListIds, content, queueName);
- }
- }
- //接收入参
- public static Dictionary<string, string> getRequestParams(int projectId, string content)
- {
- Dictionary<string, string> dic = new();
- 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 listId, int projectId, List<int> ids, string content, Dictionary<string, string> startData)
- {
- List<QueryCondition> dic = new();
- var queryTableService = App.GetService<IPriQueryTableService>();
- var queryFieldService = App.GetService<IPriQueryFieldService>();
- var returnFieldService = App.GetService<IPriReturnFieldService>();
- //查询表
- var queryTables = queryTableService.GetList(m => ids.Contains(m.id) && m.startDataFlag == false);
- foreach(var queryTable in queryTables)
- {
- //查询返回字段
- string fields = "";
- Dictionary<string, string> fieldDic = new();
- 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(fieldQueryModel == "start_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<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);
- }
- else if(fieldQueryModel == "start_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<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 + ",";
- }
- }
- }
- else if(fieldQueryModel == "start_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 = 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(fieldQueryModel == "start_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<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);
- }
- else if(fieldQueryModel == "start_list_field")
- {
- val = GetStartData(startData, 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 DataTable conditionList(int listId, int projectId, List<int> ids, string content, int skip = 0, int size = 1000)
- {
- List<QueryCondition> dic = new();
- var queryTableService = App.GetService<IPriQueryTableService>();
- var queryFieldService = App.GetService<IPriQueryFieldService>();
- var returnFieldService = App.GetService<IPriReturnFieldService>();
- //查询表
- var queryTable = queryTableService.GetFirst(m => ids.Contains(m.id) && m.startDataFlag == true);
- if (queryTable != null)
- {
- string groupBy = "";
- //查询返回字段
- string fields = "";
- Dictionary<string, string> fieldDic = new();
- 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.Split('+')[0] + ",";
- }
- else if(returnField.fieldReturnKind == "3")
- {
- fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName.Split('+')[0] + ",";
- }
- else if(returnField.fieldReturnKind == "4")
- {
- fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName.Split('+')[0] + ",";
- }
- 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;
- }
- }
- //拼装聚合字段
- if(queryField.groupByFlag) groupBy += queryField.fieldEnName +",";
- }
- if(!string.IsNullOrEmpty(groupBy)) groupBy = " group by " + groupBy.TrimEnd(',') + " order by " + groupBy.TrimEnd(',');
- var db = initDb(queryTable.databaseId);
- string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi + groupBy + " limit " + skip + "," + size;
- var items = db.Ado.GetDataTable(sql);
- return items;
- }
- return new DataTable();
- }
- //奖励发放对象
- public static string prizeObject(int listId, int prizeObjectTag, string content)
- {
- Dictionary<string, object> logStepDic = new();
- Dictionary<string, object> dic = new();
- 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;
- logStepDic.Add("奖励发放对象说明", prizeObjectTable.note);
- //查询匹配条件
- string condi = "";
- List<Dictionary<string, object>> 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<string, object> 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<string, string> 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<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;
- 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<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 + ")";
- condiDic.Add("匹配值", 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]) + "'";
- }
- }
- condiDic.Add("匹配值", val);
- }
- 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;
- 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<string, object> dic = new();
- var prizeInSetService = App.GetService<IPriPrizeInSetService>();
- //查询表
- 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<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, string queueName)
- {
- var queryTableService = App.GetService<IPriQueryTableService>();
- var priList = prizeList(projectId, prizeIds);
- foreach(var sub in priList)
- {
- try
- {
- List<int> ids = Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList();
- var queryTable = queryTableService.GetFirst(m => ids.Contains(m.id) && m.startDataFlag == true);
- 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);
- if(query.Rows.Count > 0)
- {
- foreach(DataRow dr in query.Rows)
- {
- Dictionary<string, string> 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<string, string>());
- }
- }
- catch(Exception ex)
- {
- setLogFieldValue(sub.id, "errLog", ex.ToString());
- }
- }
- }
- //执行每个奖励发放逻辑
- public static void prizeSendSub(PriList sub, int projectId, int prizeInId, string prizeIds, string content, string queueName, Dictionary<string, string> startData)
- {
- var loopSetService = App.GetService<IPriLoopSetService>();
- var recursionStartTableService = App.GetService<IPriRecursionStartTableService>();
- var recursionStartConditionService = App.GetService<IPriRecursionStartConditionService>();
- addLog(projectId, sub.id, prizeInId, content, queueName); //初始化日志
- string prizeObjectId = prizeObject(sub.id, sub.prizeObj, content);
- var recursionFlag = sub.recursionFlag; //是否递归
- setLogStep(sub.id, "是否递归", recursionFlag ? "是" : "否");
- if(recursionFlag)
- {
- List<QueryCondition> queryCondiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content, startData);
- setLogStep(sub.id, "查询原始数据", queryCondiDic);
- 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(loopSet.databaseId);
- string objId = prizeObjectId;
- bool op = true;
- int index = 0;
- loopAmount = 0;
- List<Dictionary<string, object>> loopLogDic = new();
- while(!string.IsNullOrEmpty(objId) && objId != "0" && op)
- {
- Dictionary<string, object> loopLog = new();
- List<QueryCondition> condiDic = loopCondition(projectId, sub, objId, content);
- loopLog.Add("查询" + objId + "匹配数据", condiDic);
- 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; //通过条件数
- List<Dictionary<string, object>> logStepDics = new();
- foreach(var condition in conditions)
- {
- if(condition.startIndex <= index)
- {
- Dictionary<string, object> logStepDic = new();
-
- 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();
- checkObj = dt.Compute(expresssion, "false").ToString();
- }
- else
- {
- checkObj = GetQueryTableData(condiDic, returnFieldId);
- checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
- }
-
- logStepDic.Add("标题", checkTitle);
- 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 = 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 ? "通过" : "未通过");
- logStepDics.Add(logStepDic);
- }
- }
- loopLog.Add(objId + "匹配情况", logStepDics);
- 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("匹配结果", prizeFlag);
- if(prizeFlag)
- {
- decimal prizeAmt = prizeSendDo(projectId, sub, objId, content, loopSet, startData);
- op = afterPrizeFlag;
- }
- }
- 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
- {
- prizeSendDo(projectId, sub, prizeObjectId, content, new PriLoopSet(), startData);
- }
- }
- static decimal loopAmount = 0;
- public static decimal prizeSendDo(int projectId, PriList sub, string prizeObjectId, string content, PriLoopSet set, Dictionary<string, string> startData)
- {
- var projectService = App.GetService<IPriProjectService>();
- 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>();
- var project = projectService.GetFirst(m => m.id == projectId) ?? new PriProject();
- //查询匹配条件
- List<QueryCondition> condiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content, startData);
- if(sub.prizeSourceFieldType == "loop") MergeCondiDic(condiDic, loopCondition(projectId, sub, prizeObjectId, content));
- setLogStep(sub.id, "发放奖励查询来源数据", condiDic);
- 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);
- setLogStep(sub.id, "发放奖励匹配条件", condiDic);
- int allCount = conditions.Count; //所有奖励条件数
- int passCount = 0; //通过条件数
- List<Dictionary<string, object>> logStepDics = new();
- foreach(var condition in conditions)
- {
- Dictionary<string, object> logStepDic = new();
- 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();
- checkObj = dt.Compute(expresssion, "false").ToString();
- }
- else
- {
- checkObj = GetQueryTableData(condiDic, returnFieldId);
- checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
- }
- if(!sub.recursionFlag)
- {
- logStepDic.Add("标题", checkTitle);
- 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 = 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);
- }
- }
- setLogStep(sub.id, "匹配结果", logStepDics);
- 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;
- setLogStep(sub.id, "是否通过", op ? "是" : "否");
- 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;
- setLogStep(sub.id, "发放金额", prizeAmt);
- 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)
- {
- PriRecord item = new PriRecord()
- {
- createDate = DateTime.Now,
- projectId = projectId,
- listId = sub.id,
- prizeAmount = prizeAmt,
- prizeObjId = prizeObjectId,
- requestParamField = content,
- batchNo = batchNo,
- };
- recordService.Add(item);
- Dictionary<string, object> prizeItem = new Dictionary<string, object>();
- prizeItem.Add("prize_date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- prizeItem.Add("prize_name", sub.prizeName);
- prizeItem.Add("batch_no", batchNo);
- prizeItem.Add("request_param_field", content);
- List<Dictionary<string, object>> prizeItemList = new List<Dictionary<string, object>>();
- Dictionary<string, object> prizeItemSub = new Dictionary<string, object>();
- 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);
- loopAmount = getPrizeAmount;
- 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);
- if(sendItem != null)
- {
- Function.WriteLog("in", "通知返回报文");
- sendItem.status = status;
- recordService.Update(sendItem);
- Function.WriteLog("end", "通知返回报文");
- }
- }
- else if(project.requestMode == "mq")
- {}
- else
- {
- prizeToDatabase(projectId, sub.id, content, condiDic, prizeAmt, startData); //入库
- }
- }
- }
- }
- // if(!sub.recursionFlag)
- // {
- setLogStatus(sub.id, op ? 1 : 0);
- // }
- return prizeAmt;
- }
- //递归条件判断
- public static List<QueryCondition> loopCondition(int projectId, PriList sub, string objId, string content)
- {
- List<QueryCondition> dic = new();
- 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();
- 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, Dictionary<string, string> startData)
- {
- 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();
- //入库字段
- 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 == "querystart_list_field_field")
- {
- fieldQueryValue = GetStartData(startData, 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(fieldQueryModel == "start_list_field")
- {
- condi += "'%" + GetStartData(startData, 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);
- }
- else if(fieldQueryModel == "start_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<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 == "start_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 = 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();
- 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 string GetStartData(Dictionary<string, string> startData, string key)
- {
- return startData.ContainsKey(key) ? startData[key] : "";
- }
- //合并字典
- 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, string prizeInUrl)
- {
- if(!logFlag) return;
- var logService = App.GetService<IPriLogService>();
- logService.Add(new PriLog()
- {
- createDate = DateTime.Now,
- projectId = projectId,
- listId = listId,
- batchNo = batchNo,
- prizeIn = prizeIn,
- requestParam = requestParam,
- prizeInUrl = prizeInUrl,
- });
- }
- public static void setLogPrizeAmount(int listId, decimal prizeAmount)
- {
- if(!logFlag) return;
- 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, Dictionary<string, object> step)
- {
- if(!logFlag) return;
- var logService = App.GetService<IPriLogService>();
- 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<IPriLogService>();
- 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<IPriLogService>();
- 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<IPriLogService>();
- 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;
- }
- }
- }
|