1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692 |
- 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;
- using System.Text.RegularExpressions;
- 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 string getRequestParams(int projectId, string content, string key)
- {
- JsonData jsonData = JsonMapper.ToObject(content);
- var paramService = App.GetService<IPriProjectParamService>();
- var param = paramService.GetFirst(m => m.projectId == projectId && m.fieldEnName == key);
- if(param != null)
- {
- return jsonData[param.fieldEnName].ToString();
- }
- return "0";
- }
- //数据库链接
- 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 sql = "";
- Dictionary<string, string> fieldDic = new();
- if(string.IsNullOrEmpty(queryTable.customSql))
- {
- //查询返回字段
- string fields = "";
- var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id);
- foreach(var returnField in returnFields)
- {
- string aliasName = returnField.fieldAliasName;
- if(string.IsNullOrEmpty(aliasName)) aliasName = queryTable.tableEnName + "_" + returnField.fieldEnName;
- if(returnField.fieldReturnKind == "2")
- {
- fields += "count(" + returnField.fieldEnName + ") " + aliasName + ",";
- }
- else if(returnField.fieldReturnKind == "3")
- {
- fields += "sum(" + returnField.fieldEnName + ") " + aliasName + ",";
- }
- else if(returnField.fieldReturnKind == "4")
- {
- fields += "avg(" + returnField.fieldEnName + ") " + aliasName + ",";
- }
- else if(returnField.fieldReturnKind == "5")
- {
- fields += "max(" + returnField.fieldEnName + ") " + aliasName + ",";
- }
- else if(returnField.fieldReturnKind == "6")
- {
- fields += "min(" + returnField.fieldEnName + ") " + aliasName + ",";
- }
- else if(returnField.fieldReturnKind == "7")
- {
- fields += GetDbExpressionVal(returnField.fieldEnName, projectId, content, dic, startData) + ",";
- }
- else
- {
- fields += returnField.fieldEnName + " " + aliasName + ",";
- }
- fieldDic.Add(aliasName, returnField.fieldName);
- }
- fields = fields.TrimEnd(',');
- //查询匹配条件
- string condi = "";
- var queryFields = queryFieldService.GetList(m => m.queryTableId == queryTable.id);
- 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")
- {
- condi += "'%" + getRequestParams(projectId, content, fieldQueryValue) + "%'";
- }
- else if(fieldQueryModel == "fixed_value")
- {
- condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
- }
- else if(fieldQueryModel == "db_field")
- {
- condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
- }
- else if(fieldQueryModel == "query_field")
- {
- string val = GetQueryTableData(dic, fieldQueryValue);
- condi += "'%" + val + "%'";
- }
- else if(fieldQueryModel == "querystart_list_field")
- {
- string val = GetStartData(startData, fieldQueryValue);
- condi += "'%" + val + "%'";
- }
- }
- else if(fieldQueryKind == "2") //精确匹配
- {
- if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is null";
- else
- {
- condi += " and " + fieldEnName + "=";
- string val = "";
- if(fieldQueryModel == "request_param")
- {
- Dictionary<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 == "querystart_list_field")
- {
- val = GetStartData(startData, fieldQueryValue);
- }
- if(fieldQueryValueType == "text")
- {
- val = "'" + val + "'";
- }
- condi += val;
- }
- }
- else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
- {
- if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
- else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
- string val = "";
- string[] valList = fieldQueryValue.Split(',');
- if(fieldQueryModel == "request_param")
- {
- Dictionary<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 == "querystart_list_field")
- {
- foreach(string sub in valList)
- {
- string dicVal = GetStartData(startData, sub);
- if(fieldQueryValueType == "text")
- {
- val += "'" + dicVal + "',";
- }
- else
- {
- val += dicVal + ",";
- }
- }
- }
- val = val.TrimEnd(',');
- condi += val + ")";
- }
- else if(fieldQueryKind == "3") //范围匹配
- {
- string[] val = 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 == "querystart_list_field")
- {
- string valLeft = val[0];
- string valRight = val[1];
- string dicValLeft = GetStartData(startData, valLeft);
- string dicValRight = GetStartData(startData, valRight);
- if(fieldQueryValueType == "number")
- {
- if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft;
- if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight;
- }
- else
- {
- if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'";
- if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'";
- }
- }
- }
- else if(fieldQueryKind == "4") //取反匹配
- {
- if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is not null";
- else
- {
- condi += " and " + fieldEnName + "!=";
- string val = "";
- if(fieldQueryModel == "request_param")
- {
- Dictionary<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 == "querystart_list_field")
- {
- val = GetStartData(startData, fieldQueryValue);
- }
- if(fieldQueryValueType == "text")
- {
- val = "'" + val + "'";
- }
- condi += val;
- }
- }
- }
- sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
- }
- else
- {
- sql = queryTable.customSql;
- sql = GetDbExpressionVal(sql, projectId, content, dic, startData);
- }
- var db = initDb(queryTable.databaseId);
- var items = db.Ado.GetDataTable(sql);
- if(items.Rows.Count > 0)
- {
- if(string.IsNullOrEmpty(queryTable.customSql))
- {
- foreach(string field in fieldDic.Keys)
- {
- if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
- {
- FieldName = fieldDic[field],
- FieldEnName = field,
- Value = items.Rows[0][field].ToString()
- });
- }
- }
- else
- {
- foreach(DataColumn column in items.Columns)
- {
- string field = column.ColumnName;
- if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
- {
- FieldName = 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 if(returnField.fieldReturnKind == "5")
- {
- fields += "max(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName.Split('+')[0] + ",";
- }
- else if(returnField.fieldReturnKind == "6")
- {
- fields += "min(" + 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(queryField.groupByFlag)
- {
- groupBy += queryField.fieldEnName + ",";
- }
- else
- {
- 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(!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; //是否递归
- var prizeCode = sub.prizeCode; //奖励代码
-
- 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;
- prizeCode = amountSet.prizeCode;
- }
- 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;
- prizeCode = amountSet.prizeCode;
- 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.prizeCode == prizeCode && m.requestParamField == content);
- if(!sendFlag)
- {
- PriRecord item = new PriRecord()
- {
- createDate = DateTime.Now,
- projectId = projectId,
- listId = sub.id,
- prizeAmount = prizeAmt,
- prizeCode = prizeCode,
- prizeObjId = prizeObjectId,
- requestParamField = content,
- batchNo = batchNo,
- };
- recordService.Add(item);
- 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)
- {
- string aliasName = returnField.fieldAliasName;
- if(string.IsNullOrEmpty(aliasName)) aliasName = queryTable.tableEnName + "_" + returnField.fieldEnName;
- if(returnField.fieldReturnKind == "2")
- {
- fields += "count(" + returnField.fieldEnName + ") " + aliasName + ",";
- }
- else if(returnField.fieldReturnKind == "3")
- {
- fields += "sum(" + returnField.fieldEnName + ") " + aliasName + ",";
- }
- else if(returnField.fieldReturnKind == "4")
- {
- fields += "avg(" + returnField.fieldEnName + ") " + aliasName + ",";
- }
- else if(returnField.fieldReturnKind == "5")
- {
- fields += "max(" + returnField.fieldEnName + ") " + aliasName + ",";
- }
- else if(returnField.fieldReturnKind == "6")
- {
- fields += "min(" + returnField.fieldEnName + ") " + aliasName + ",";
- }
- else
- {
- fields += returnField.fieldEnName + " " + aliasName + ",";
- }
- fieldDic.Add(aliasName, returnField.fieldName);
- }
- fields = fields.TrimEnd(',');
- }
- //查询匹配条件
- string condi = "";
- var queryFields = queryFieldService.GetList(m => m.objectTableId == queryTable.id);
- foreach(var queryField in queryFields)
- {
- string fieldEnName = queryField.fieldEnName;
- string fieldQueryKind = queryField.fieldQueryKind;
- string fieldQueryModel = queryField.fieldQueryModel;
- string fieldQueryValue = queryField.fieldQueryValue;
- if(fieldQueryModel == "loop_field") fieldQueryValue = objId;
- string fieldQueryValueType = queryField.fieldQueryValueType;
- if(fieldQueryKind == "1") //模糊匹配
- {
- condi += " and " + fieldEnName + " like ";
- if(fieldQueryModel == "request_param")
- {
- Dictionary<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();
- List<string> inFields = new();
- //入库字段
- var prizeInFields = prizeInFieldService.GetList(m => m.inTableId == prizeInTable.id);
- foreach(var prizeInField in prizeInFields)
- {
- string fieldEnName = prizeInField.fieldEnName;
- string fieldQueryModel = prizeInField.fieldQueryModel;
- string fieldQueryValue = prizeInField.fieldQueryValue;
- 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));
- inFields.Add(fieldEnName + "#cut#" + fieldQueryValue + "#cut#" + fieldQueryValueType + "#cut#" + prizeInField.fieldInModel);
- }
- //查询匹配条件
- string condi = "";
- var queryFields = prizeInQueryFieldService.GetList(m => m.inTableId == prizeInTable.id);
- foreach(var queryField in queryFields)
- {
- string fieldEnName = queryField.fieldEnName;
- string fieldQueryKind = queryField.fieldQueryKind;
- string fieldQueryModel = queryField.fieldQueryModel;
- string fieldQueryValue = queryField.fieldQueryValue;
- string fieldQueryValueType = queryField.fieldQueryValueType;
- if(fieldQueryKind == "1") //模糊匹配
- {
- condi += " and " + fieldEnName + " like ";
- if(fieldQueryModel == "request_param")
- {
- Dictionary<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 == "querystart_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 == "querystart_list_field")
- {
- val = GetStartData(startData, fieldQueryValue);
- }
- if(fieldQueryValueType == "text")
- {
- val = "'" + val + "'";
- }
- condi += val;
- }
- else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
- {
- if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
- else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
- string val = "";
- string[] valList = fieldQueryValue.Split(',');
- if(fieldQueryModel == "request_param")
- {
- Dictionary<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 == "querystart_list_field")
- {
- foreach(string sub in valList)
- {
- if(fieldQueryValueType == "text")
- {
- val += "'" + GetStartData(startData, sub) + "',";
- }
- else
- {
- val += GetStartData(startData, sub) + ",";
- }
- }
- }
- else if(fieldQueryModel == "db_field")
- {
- foreach(string sub in valList)
- {
- if(fieldQueryValueType == "text")
- {
- val += "'" + GetDbExpressionVal(sub) + "',";
- }
- else
- {
- val += GetDbExpressionVal(sub) + ",";
- }
- }
- }
- val = val.TrimEnd(',');
- condi += val + ")";
- }
- else if(fieldQueryKind == "3") //范围匹配
- {
- string[] val = 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();
- if(prizeInTable.excuteKind == "update_or_add")
- {
- string doSql = "";
- var check = db.Ado.GetDataTable("select 1 from " + prizeInTable.tableEnName + " where 1=1" + condi);
- if(check.Rows.Count > 0)
- {
- string fieldString = "";
- foreach(var inField in inFields)
- {
- string[] inFieldData = inField.Split(new string[]{ "#cut#" }, StringSplitOptions.None);
- string fieldEnName = inFieldData[0];
- string fieldQueryValue = inFieldData[1];
- string fieldQueryValueType = inFieldData[2];
- string fieldInModel = inFieldData[3];
- if(fieldQueryValueType == "int" || fieldQueryValueType == "number" || fieldQueryValueType == "bool")
- {
- if(fieldInModel == "add")
- {
- fieldString += fieldEnName + "=" + fieldEnName + "+" + fieldQueryValue;
- }
- else
- {
- fieldString += fieldEnName + "=" + fieldQueryValue;
- }
- }
- else
- {
- if(fieldInModel == "add")
- {
- fieldString += fieldEnName + "=" + "concat(" + fieldEnName + ", '" + fieldQueryValue + "')";
- }
- else
- {
- fieldString += fieldEnName + "=" + "'" + fieldQueryValue + "'";
- }
- }
- fieldString += ",";
- }
- if(!string.IsNullOrEmpty(fieldString))
- {
- fieldString = fieldString.TrimEnd(',');
- }
- doSql = "update " + prizeInTable.tableEnName + " set " + fieldString + " where 1=1" + condi;
- }
- else
- {
- string fieldString = "";
- string valString = "";
- foreach(var fieldEnName in doFields.Keys)
- {
- fieldString += fieldEnName;
- if(typeof(int) == doFields[fieldEnName].GetType() || typeof(decimal) == doFields[fieldEnName].GetType())
- {
- valString += doFields[fieldEnName].ToString();
- }
- else
- {
- valString += "'" + doFields[fieldEnName].ToString() + "'";
- }
- fieldString += ",";
- valString += ",";
- }
- if(!string.IsNullOrEmpty(fieldString))
- {
- fieldString = fieldString.TrimEnd(',');
- valString = valString.TrimEnd(',');
- }
- doSql = "insert into " + prizeInTable.tableEnName + " (" + fieldString + ") values (" + valString + ")";
- }
- db.Ado.ExecuteCommand(doSql);
- }
- Function.WriteLog(DateTime.Now.ToString() + "\n" + prizeInTable.excuteKind + "\n" + prizeInTable.tableEnName + "\n" + Newtonsoft.Json.JsonConvert.SerializeObject(doFields) + "\n" + condi + "\n\n", "奖励入库数据");
- }
- }
- //固定值表达式
- public static string GetExpressionVal(string str)
- {
- if(str == "#{now}#") return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- if(str == "#{today}#") return DateTime.Now.ToString("yyyy-MM-dd");
- if(str == "#{this_month}#") return DateTime.Now.ToString("yyyy-MM");
- if(str.StartsWith("#{now") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
- if(str.StartsWith("#{now") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
- if(str.StartsWith("#{today") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
- if(str.StartsWith("#{today") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
- if(str.StartsWith("#{this_month") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
- if(str.StartsWith("#{this_month") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
- if(str.StartsWith("#{") && str.EndsWith("DAY}#")) return DateTime.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[0]).AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
- if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) return DateTime.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[0]).AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
- return str;
- }
- //库内字段值表达式
- public static string GetDbExpressionVal(string str)
- {
- string[] data = str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',');
- if(str.StartsWith("#{") && str.EndsWith("DAY}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " DAY)";
- if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " MONTH)";
- return str;
- }
- public static string GetDbExpressionVal(string str, int projectId, string content, List<QueryCondition> dic, Dictionary<string, string> startData)
- {
- MatchCollection mc = Regex.Matches(str, "\\$\\{.*?\\}");
- foreach(Match m in mc)
- {
- string matchValue = m.Value.Replace("${", "").Replace("}", "");
- matchValue = getRequestParams(projectId, content, matchValue);
- matchValue = GetQueryTableData(dic, matchValue);
- matchValue = GetStartData(startData, matchValue);
- str = str.Replace(m.Value, matchValue);
- }
- 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;
- }
- }
- }
|