123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529 |
- 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 = false;
- List<Dictionary<string, object>> logStepDics = new();
- var groupNos = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id).ToList().Select(m => m.groupNo).Distinct().ToList();
- foreach(var groupNo in groupNos)
- {
- var conditions = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id && m.groupNo == groupNo);
- if(conditions.Count > 0)
- {
- int allCount = conditions.Count; //所有奖励条件数
- int passCount = 0; //通过条件数
- 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);
- }
- }
- if(loopSet.conditionMode == "all" && passCount == allCount) prizeFlag = true;
- else if(loopSet.conditionMode == "one" && passCount >= 1) prizeFlag = true;
- else if(loopSet.conditionMode == "two" && passCount >= 2) prizeFlag = true;
- else if(loopSet.conditionMode == "three" && passCount >= 3) prizeFlag = true;
- // else prizeFlag = false;
- }
- // else
- // {
- // prizeFlag = false;
- // }
- }
- loopLog.Add(objId + "匹配情况", logStepDics);
- loopLog.Add("匹配结果", prizeFlag);
- if(prizeFlag)
- {
- 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; //是否递归
-
- bool op = false;
- var groupNos = conditionService.GetList(m => m.listId == sub.id).ToList().Select(m => m.groupNo).Distinct().ToList();
- foreach(var groupNo in groupNos)
- {
- var conditions = conditionService.GetList(m => m.listId == sub.id && m.groupNo == groupNo);
- 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);
- 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;
- }
- decimal prizeAmt = 0;
- 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 == content);
- 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("prize_code", sub.prizeCode);
- 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 if(project.requestMode == "db")
- {
- 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")
- {
- fieldQueryValue = GetStartData(startData, fieldQueryValue);
- }
- else if(fieldQueryModel == "query_all_field")
- {
- if (fieldQueryValue.Contains("+") || fieldQueryValue.Contains("-") || fieldQueryValue.Contains("*") || fieldQueryValue.Contains("/") || fieldQueryValue.Contains("(") || fieldQueryValue.Contains(")"))
- {
- string[] texts = fieldQueryValue.Split(new char[] { '+', '-', '*', '/', '(', ')' });
- foreach (string text in texts)
- {
- string val = GetStartData(startData, text);
- if(string.IsNullOrEmpty(val)) val = GetQueryTableData(condiDic, text);
- fieldQueryValue = fieldQueryValue.Replace(text, val);
- }
- DataTable dt = new();
- fieldQueryValue = dt.Compute(fieldQueryValue, "false").ToString();
- }
- else
- {
- string val = GetStartData(startData, fieldQueryValue);
- if(string.IsNullOrEmpty(val)) val = GetQueryTableData(condiDic, fieldQueryValue);
- fieldQueryValue = val;
- }
- }
- else if(fieldQueryModel == "fixed_value")
- {
- fieldQueryValue = GetExpressionVal(fieldQueryValue);
- }
- else if(fieldQueryModel == "db_field")
- {
- fieldQueryValue = GetDbExpressionVal(fieldQueryValue);
- }
- else if(fieldQueryModel == "prize_amt")
- {
- 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;
- }
- }
- }
|