PrizeDo.cs 175 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027
  1. using System.Data;
  2. using System.Linq;
  3. using System.Net.Mime;
  4. using System.Text.RegularExpressions;
  5. using Common;
  6. using Infrastructure;
  7. using LitJson;
  8. using Microsoft.Extensions.Localization;
  9. using Model;
  10. using Model.Customer;
  11. using NuGet.Packaging;
  12. using Services;
  13. namespace Util
  14. {
  15. public class PrizeDo
  16. {
  17. public static string batchNo = "";
  18. public static string publicStep = "";
  19. public static bool logFlag = true;
  20. //发奖入口
  21. public static void sendPrize(string queueName, string content)
  22. {
  23. batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(3);
  24. publicStep = "";
  25. string priObjString = prizeInSet(queueName);
  26. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-1", "接收mq数据日志");
  27. if(!string.IsNullOrEmpty(priObjString))
  28. {
  29. string[] priObjData = priObjString.Split('|');
  30. string priListIds = priObjData[0];
  31. int projectId = int.Parse(priObjData[1]);
  32. int prizeInId = int.Parse(priObjData[2]);
  33. var projectService = App.GetService<IPriProjectService>();
  34. var project = projectService.GetFirst(m => m.id == projectId) ?? new PriProject();
  35. logFlag = project.logFlag;
  36. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-2", "接收mq数据日志");
  37. prizeSend(projectId, prizeInId, priListIds, content, queueName);
  38. }
  39. }
  40. //补奖入口
  41. public static void addPrize(string queueName, string content)
  42. {
  43. batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(3);
  44. publicStep = "";
  45. string priObjString = prizeInSet(queueName);
  46. if(!string.IsNullOrEmpty(priObjString))
  47. {
  48. string[] priObjData = priObjString.Split('|');
  49. string priListIds = "";
  50. int projectId = int.Parse(priObjData[1]);
  51. int prizeInId = int.Parse(priObjData[2]);
  52. var projectService = App.GetService<IPriProjectService>();
  53. var project = projectService.GetFirst(m => m.id == projectId) ?? new PriProject();
  54. logFlag = project.logFlag;
  55. JsonData jsonObj = JsonMapper.ToObject(content);
  56. JsonData posSn = jsonObj["pos_sn"].ToString();
  57. JsonData prizeKinds = jsonObj["prize_kind_list"];
  58. for (int i = 0; i < prizeKinds.Count; i++)
  59. {
  60. string kind = prizeKinds[i].ToString();
  61. if(kind == "0") priListIds += "42,45,";
  62. if(kind == "7") priListIds += "43,";
  63. if(kind == "50") priListIds += "44,";
  64. if(kind == "116") priListIds += "49,";
  65. if(kind == "121") priListIds += "50,";
  66. if(kind == "139") priListIds += "56,";
  67. }
  68. prizeSend(projectId, prizeInId, priListIds.TrimEnd(','), content, queueName);
  69. }
  70. }
  71. //接收入参
  72. public static Dictionary<string, string> getRequestParams(int projectId, string content)
  73. {
  74. Dictionary<string, string> dic = new();
  75. JsonData jsonData = JsonMapper.ToObject(content);
  76. var paramService = App.GetService<IPriProjectParamService>();
  77. var paramList = paramService.GetList(m => m.projectId == projectId);
  78. foreach(var param in paramList)
  79. {
  80. if(content.Contains("\"" + param.fieldEnName + "\"")) dic.Add(param.fieldEnName, jsonData[param.fieldEnName].ToString());
  81. }
  82. return dic;
  83. }
  84. public static string getRequestParams(int projectId, string content, string key)
  85. {
  86. JsonData jsonData = JsonMapper.ToObject(content);
  87. var paramService = App.GetService<IPriProjectParamService>();
  88. var param = paramService.GetFirst(m => m.projectId == projectId && m.fieldEnName == key);
  89. if(param != null)
  90. {
  91. return jsonData[param.fieldEnName].ToString();
  92. }
  93. return key;
  94. }
  95. public static string getRequestParamsIndex(int projectId, string content)
  96. {
  97. string result = ",";
  98. JsonData jsonData = JsonMapper.ToObject(content);
  99. var paramService = App.GetService<IPriProjectParamService>();
  100. var paramList = paramService.GetList(m => m.projectId == projectId && m.queryIndex == "1");
  101. foreach(var param in paramList)
  102. {
  103. if(content.Contains("\"" + param.fieldEnName + "\"")) result += jsonData[param.fieldEnName].ToString() + ",";
  104. }
  105. return result;
  106. }
  107. //数据库链接
  108. public static SqlSugarClient initDb(int id)
  109. {
  110. var databaseSetService = App.GetService<IPriDatabaseSetService>();
  111. var connectionString = databaseSetService.GetFirst(m => m.id == id);
  112. string server = connectionString.ipAddress;
  113. int port = connectionString.port;
  114. string user = connectionString.userId;
  115. string password = connectionString.password;
  116. string database = connectionString.databaseName;
  117. var db = new SqlSugarClient(new ConnectionConfig()
  118. {
  119. ConnectionString = "server=" + server + ";port=" + port + ";user=" + user + ";password=" + password + ";database=" + database + ";charset=utf8;",
  120. DbType = SqlSugar.DbType.MySql,
  121. IsAutoCloseConnection = true,
  122. });
  123. return db;
  124. }
  125. //查询条件匹配数据
  126. public static List<QueryCondition> condition(int listId, int projectId, List<int> ids, string content, Dictionary<string, string> startData)
  127. {
  128. List<QueryCondition> dic = new();
  129. var queryTableService = App.GetService<IPriQueryTableService>();
  130. var queryFieldService = App.GetService<IPriQueryFieldService>();
  131. var returnFieldService = App.GetService<IPriReturnFieldService>();
  132. //查询表
  133. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-query-0", "接收mq数据日志");
  134. var queryTables = queryTableService.GetList(m => ids.Contains(m.id) && m.startDataFlag == false).OrderByDescending(m => m.sort).ThenBy(m => m.id).ToList();
  135. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-query-1", "接收mq数据日志");
  136. foreach(var queryTable in queryTables)
  137. {
  138. string sql = "";
  139. Dictionary<string, string> fieldDic = new();
  140. if(string.IsNullOrEmpty(queryTable.customSql))
  141. {
  142. string tableEnName = queryTable.tableEnName;
  143. if(tableEnName.Contains("#{")) tableEnName = MatchExpressionVal(tableEnName);
  144. //查询返回字段
  145. string fields = "";
  146. var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id);
  147. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-query-2", "接收mq数据日志");
  148. foreach(var returnField in returnFields)
  149. {
  150. string aliasName = returnField.fieldAliasName;
  151. if(string.IsNullOrEmpty(aliasName)) aliasName = tableEnName + "_" + returnField.fieldEnName;
  152. if(aliasName.Contains("-")) aliasName = aliasName.Split('-')[0];
  153. if(returnField.fieldReturnKind == "2")
  154. {
  155. fields += "count(" + returnField.fieldEnName + ") " + aliasName + ",";
  156. }
  157. else if(returnField.fieldReturnKind == "3")
  158. {
  159. fields += "sum(" + returnField.fieldEnName + ") " + aliasName + ",";
  160. }
  161. else if(returnField.fieldReturnKind == "4")
  162. {
  163. fields += "avg(" + returnField.fieldEnName + ") " + aliasName + ",";
  164. }
  165. else if(returnField.fieldReturnKind == "5")
  166. {
  167. fields += "max(" + returnField.fieldEnName + ") " + aliasName + ",";
  168. }
  169. else if(returnField.fieldReturnKind == "6")
  170. {
  171. fields += "min(" + returnField.fieldEnName + ") " + aliasName + ",";
  172. }
  173. else if(returnField.fieldReturnKind == "7")
  174. {
  175. fields += GetDbExpressionVal(returnField.fieldEnName, projectId, content, dic, startData) + ",";
  176. }
  177. else
  178. {
  179. fields += returnField.fieldEnName + " " + aliasName + ",";
  180. }
  181. fieldDic.Add(aliasName, returnField.fieldName);
  182. }
  183. fields = fields.TrimEnd(',');
  184. //查询匹配条件
  185. string condi = "";
  186. var queryFields = queryFieldService.GetList(m => m.queryTableId == queryTable.id);
  187. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-query-3", "接收mq数据日志");
  188. foreach(var queryField in queryFields)
  189. {
  190. string fieldEnName = queryField.fieldEnName;
  191. string fieldQueryKind = queryField.fieldQueryKind;
  192. string fieldQueryModel = queryField.fieldQueryModel;
  193. string fieldQueryValue = queryField.fieldQueryValue;
  194. fieldQueryValue = MatchExpressionVal(fieldQueryValue);
  195. string fieldQueryValueType = queryField.fieldQueryValueType;
  196. if(fieldQueryKind == "1") //模糊匹配
  197. {
  198. condi += " and " + fieldEnName + " like ";
  199. if(fieldQueryModel == "request_param")
  200. {
  201. condi += "'%" + getRequestParams(projectId, content, fieldQueryValue) + "%'";
  202. }
  203. else if(fieldQueryModel == "fixed_value")
  204. {
  205. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  206. }
  207. else if(fieldQueryModel == "db_field")
  208. {
  209. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  210. }
  211. else if(fieldQueryModel == "query_field")
  212. {
  213. string val = GetQueryTableData(dic, fieldQueryValue);
  214. condi += "'%" + val + "%'";
  215. }
  216. else if(fieldQueryModel == "querystart_list_field")
  217. {
  218. string val = GetStartData(startData, fieldQueryValue);
  219. condi += "'%" + val + "%'";
  220. }
  221. }
  222. else if(fieldQueryKind == "2") //精确匹配
  223. {
  224. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is null";
  225. else
  226. {
  227. condi += " and " + fieldEnName + "=";
  228. string val = "";
  229. if(fieldQueryModel == "request_param")
  230. {
  231. Dictionary<string, string> req = getRequestParams(projectId, content);
  232. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  233. }
  234. else if(fieldQueryModel == "fixed_value")
  235. {
  236. val = GetExpressionVal(fieldQueryValue);
  237. }
  238. else if(fieldQueryModel == "db_field")
  239. {
  240. val = GetDbExpressionVal(fieldQueryValue);
  241. }
  242. else if(fieldQueryModel == "query_field")
  243. {
  244. val = GetQueryTableData(dic, fieldQueryValue);
  245. }
  246. else if(fieldQueryModel == "querystart_list_field")
  247. {
  248. val = GetStartData(startData, fieldQueryValue);
  249. }
  250. if(fieldQueryValueType == "text")
  251. {
  252. val = "'" + val + "'";
  253. }
  254. condi += val;
  255. }
  256. }
  257. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  258. {
  259. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  260. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  261. string val = "";
  262. string[] valList = fieldQueryValue.Split(',');
  263. if(fieldQueryModel == "request_param")
  264. {
  265. Dictionary<string, string> req = getRequestParams(projectId, content);
  266. foreach(string sub in valList)
  267. {
  268. if(fieldQueryValueType == "text")
  269. {
  270. val += "'" + req[sub] + "',";
  271. }
  272. else
  273. {
  274. val += req[sub] + ",";
  275. }
  276. }
  277. }
  278. else if(fieldQueryModel == "fixed_value")
  279. {
  280. foreach(string sub in valList)
  281. {
  282. if(fieldQueryValueType == "text")
  283. {
  284. val += "'" + GetExpressionVal(sub) + "',";
  285. }
  286. else
  287. {
  288. val += GetExpressionVal(sub) + ",";
  289. }
  290. }
  291. }
  292. else if(fieldQueryModel == "db_field")
  293. {
  294. foreach(string sub in valList)
  295. {
  296. if(fieldQueryValueType == "text")
  297. {
  298. val += "'" + GetDbExpressionVal(sub) + "',";
  299. }
  300. else
  301. {
  302. val += GetDbExpressionVal(sub) + ",";
  303. }
  304. }
  305. }
  306. else if(fieldQueryModel == "query_field")
  307. {
  308. foreach(string sub in valList)
  309. {
  310. string dicVal = GetQueryTableData(dic, sub);
  311. if(fieldQueryValueType == "text")
  312. {
  313. val += "'" + dicVal + "',";
  314. }
  315. else
  316. {
  317. val += dicVal + ",";
  318. }
  319. }
  320. }
  321. else if(fieldQueryModel == "querystart_list_field")
  322. {
  323. foreach(string sub in valList)
  324. {
  325. string dicVal = GetStartData(startData, sub);
  326. if(fieldQueryValueType == "text")
  327. {
  328. val += "'" + dicVal + "',";
  329. }
  330. else
  331. {
  332. val += dicVal + ",";
  333. }
  334. }
  335. }
  336. val = val.TrimEnd(',');
  337. condi += val + ")";
  338. }
  339. else if(fieldQueryKind == "3") //范围匹配
  340. {
  341. string[] val = fieldQueryValue.Split(':');
  342. if(fieldQueryModel == "request_param")
  343. {
  344. Dictionary<string, string> req = getRequestParams(projectId, content);
  345. if(fieldQueryValueType == "number")
  346. {
  347. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  348. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  349. }
  350. else
  351. {
  352. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  353. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  354. }
  355. }
  356. else if(fieldQueryModel == "fixed_value")
  357. {
  358. if(fieldQueryValueType == "number")
  359. {
  360. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  361. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  362. }
  363. else
  364. {
  365. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  366. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  367. }
  368. }
  369. else if(fieldQueryModel == "db_field")
  370. {
  371. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + GetDbExpressionVal(val[0]);
  372. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + GetDbExpressionVal(val[1]);
  373. }
  374. else if(fieldQueryModel == "query_field")
  375. {
  376. string valLeft = val[0];
  377. string valRight = val[1];
  378. string dicValLeft = GetQueryTableData(dic, valLeft);
  379. string dicValRight = GetQueryTableData(dic, valRight);
  380. if(fieldQueryValueType == "number")
  381. {
  382. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft;
  383. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight;
  384. }
  385. else
  386. {
  387. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'";
  388. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'";
  389. }
  390. }
  391. else if(fieldQueryModel == "querystart_list_field")
  392. {
  393. string valLeft = val[0];
  394. string valRight = val[1];
  395. string dicValLeft = GetStartData(startData, valLeft);
  396. string dicValRight = GetStartData(startData, valRight);
  397. if(fieldQueryValueType == "number")
  398. {
  399. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft;
  400. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight;
  401. }
  402. else
  403. {
  404. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'";
  405. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'";
  406. }
  407. }
  408. }
  409. else if(fieldQueryKind == "4") //取反匹配
  410. {
  411. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is not null";
  412. else
  413. {
  414. condi += " and " + fieldEnName + "!=";
  415. string val = "";
  416. if(fieldQueryModel == "request_param")
  417. {
  418. Dictionary<string, string> req = getRequestParams(projectId, content);
  419. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  420. }
  421. else if(fieldQueryModel == "fixed_value")
  422. {
  423. val = GetExpressionVal(fieldQueryValue);
  424. }
  425. else if(fieldQueryModel == "db_field")
  426. {
  427. val = GetDbExpressionVal(fieldQueryValue);
  428. }
  429. else if(fieldQueryModel == "query_field")
  430. {
  431. val = GetQueryTableData(dic, fieldQueryValue);
  432. }
  433. else if(fieldQueryModel == "querystart_list_field")
  434. {
  435. val = GetStartData(startData, fieldQueryValue);
  436. }
  437. if(fieldQueryValueType == "text")
  438. {
  439. val = "'" + val + "'";
  440. }
  441. condi += val;
  442. }
  443. }
  444. }
  445. sql = "select " + fields + " from " + tableEnName + " where 1=1" + condi;
  446. if(!string.IsNullOrEmpty(queryTable.orderBy))
  447. {
  448. sql += " order by " + queryTable.orderBy;
  449. }
  450. sql += " limit 1";
  451. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-query-4", "接收mq数据日志");
  452. }
  453. else
  454. {
  455. sql = queryTable.customSql;
  456. sql = GetDbExpressionVal(sql, projectId, content, dic, startData);
  457. }
  458. var db = initDb(queryTable.databaseId);
  459. var items = db.Ado.GetDataTable(sql);
  460. if(items.Rows.Count > 0)
  461. {
  462. if(string.IsNullOrEmpty(queryTable.customSql))
  463. {
  464. foreach(string field in fieldDic.Keys)
  465. {
  466. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  467. {
  468. FieldName = fieldDic[field],
  469. FieldEnName = field,
  470. Value = items.Rows[0][field].ToString()
  471. });
  472. }
  473. }
  474. else
  475. {
  476. foreach(DataColumn column in items.Columns)
  477. {
  478. string field = column.ColumnName;
  479. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  480. {
  481. FieldName = field,
  482. FieldEnName = field,
  483. Value = items.Rows[0][field].ToString()
  484. });
  485. }
  486. }
  487. }
  488. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-query-5", "接收mq数据日志");
  489. }
  490. return dic;
  491. }
  492. public static DataTable conditionList(int listId, int projectId, List<int> ids, string content, int skip = 0, int size = 1000)
  493. {
  494. List<QueryCondition> dic = new();
  495. var queryTableService = App.GetService<IPriQueryTableService>();
  496. var queryFieldService = App.GetService<IPriQueryFieldService>();
  497. var returnFieldService = App.GetService<IPriReturnFieldService>();
  498. //查询表
  499. var queryTable = queryTableService.GetFirst(m => ids.Contains(m.id) && m.startDataFlag == true);
  500. if (queryTable != null)
  501. {
  502. string sql = "";
  503. if(string.IsNullOrEmpty(queryTable.customSql))
  504. {
  505. string groupBy = "";
  506. string tableEnName = queryTable.tableEnName;
  507. if(tableEnName.Contains("#{")) tableEnName = MatchExpressionVal(tableEnName);
  508. //查询返回字段
  509. string fields = "";
  510. Dictionary<string, string> fieldDic = new();
  511. var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id);
  512. foreach(var returnField in returnFields)
  513. {
  514. if(returnField.fieldReturnKind == "2")
  515. {
  516. fields += "count(" + returnField.fieldEnName + ") " + tableEnName + "_" + returnField.fieldEnName.Split('+')[0] + ",";
  517. }
  518. else if(returnField.fieldReturnKind == "3")
  519. {
  520. fields += "sum(" + returnField.fieldEnName + ") " + tableEnName + "_" + returnField.fieldEnName.Split('+')[0] + ",";
  521. }
  522. else if(returnField.fieldReturnKind == "4")
  523. {
  524. fields += "avg(" + returnField.fieldEnName + ") " + tableEnName + "_" + returnField.fieldEnName.Split('+')[0] + ",";
  525. }
  526. else if(returnField.fieldReturnKind == "5")
  527. {
  528. fields += "max(" + returnField.fieldEnName + ") " + tableEnName + "_" + returnField.fieldEnName.Split('+')[0] + ",";
  529. }
  530. else if(returnField.fieldReturnKind == "6")
  531. {
  532. fields += "min(" + returnField.fieldEnName + ") " + tableEnName + "_" + returnField.fieldEnName.Split('+')[0] + ",";
  533. }
  534. else
  535. {
  536. fields += returnField.fieldEnName + " " + tableEnName + "_" + returnField.fieldEnName + ",";
  537. }
  538. fieldDic.Add(tableEnName + "_" + returnField.fieldEnName, returnField.fieldName);
  539. }
  540. fields = fields.TrimEnd(',');
  541. //查询匹配条件
  542. string condi = "";
  543. var queryFields = queryFieldService.GetList(m => m.queryTableId == queryTable.id);
  544. foreach(var queryField in queryFields)
  545. {
  546. string fieldEnName = queryField.fieldEnName;
  547. string fieldQueryKind = queryField.fieldQueryKind;
  548. string fieldQueryModel = queryField.fieldQueryModel;
  549. string fieldQueryValue = queryField.fieldQueryValue;
  550. string fieldQueryValueType = queryField.fieldQueryValueType;
  551. //拼装聚合字段
  552. if(queryField.groupByFlag)
  553. {
  554. groupBy += queryField.fieldEnName + ",";
  555. }
  556. else
  557. {
  558. if(fieldQueryKind == "1") //模糊匹配
  559. {
  560. condi += " and " + fieldEnName + " like ";
  561. if(fieldQueryModel == "request_param")
  562. {
  563. Dictionary<string, string> req = getRequestParams(projectId, content);
  564. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  565. condi += "'%" + val + "%'";
  566. }
  567. else if(fieldQueryModel == "fixed_value")
  568. {
  569. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  570. }
  571. else if(fieldQueryModel == "db_field")
  572. {
  573. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  574. }
  575. else if(fieldQueryModel == "query_field")
  576. {
  577. string val = GetQueryTableData(dic, fieldQueryValue);
  578. condi += "'%" + val + "%'";
  579. }
  580. }
  581. else if(fieldQueryKind == "2") //精确匹配
  582. {
  583. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is null";
  584. else
  585. {
  586. condi += " and " + fieldEnName + "=";
  587. string val = "";
  588. if(fieldQueryModel == "request_param")
  589. {
  590. Dictionary<string, string> req = getRequestParams(projectId, content);
  591. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  592. }
  593. else if(fieldQueryModel == "fixed_value")
  594. {
  595. val = GetExpressionVal(fieldQueryValue);
  596. }
  597. else if(fieldQueryModel == "db_field")
  598. {
  599. val = GetDbExpressionVal(fieldQueryValue);
  600. }
  601. else if(fieldQueryModel == "query_field")
  602. {
  603. val = GetQueryTableData(dic, fieldQueryValue);
  604. }
  605. if(fieldQueryValueType == "text")
  606. {
  607. val = "'" + val + "'";
  608. }
  609. condi += val;
  610. }
  611. }
  612. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  613. {
  614. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  615. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  616. string val = "";
  617. string[] valList = fieldQueryValue.Split(',');
  618. if(fieldQueryModel == "request_param")
  619. {
  620. Dictionary<string, string> req = getRequestParams(projectId, content);
  621. foreach(string sub in valList)
  622. {
  623. if(fieldQueryValueType == "text")
  624. {
  625. val += "'" + req[sub] + "',";
  626. }
  627. else
  628. {
  629. val += req[sub] + ",";
  630. }
  631. }
  632. }
  633. else if(fieldQueryModel == "fixed_value")
  634. {
  635. foreach(string sub in valList)
  636. {
  637. if(fieldQueryValueType == "text")
  638. {
  639. val += "'" + GetExpressionVal(sub) + "',";
  640. }
  641. else
  642. {
  643. val += GetExpressionVal(sub) + ",";
  644. }
  645. }
  646. }
  647. else if(fieldQueryModel == "db_field")
  648. {
  649. foreach(string sub in valList)
  650. {
  651. if(fieldQueryValueType == "text")
  652. {
  653. val += "'" + GetDbExpressionVal(sub) + "',";
  654. }
  655. else
  656. {
  657. val += GetDbExpressionVal(sub) + ",";
  658. }
  659. }
  660. }
  661. else if(fieldQueryModel == "query_field")
  662. {
  663. foreach(string sub in valList)
  664. {
  665. string dicVal = GetQueryTableData(dic, sub);
  666. if(fieldQueryValueType == "text")
  667. {
  668. val += "'" + dicVal + "',";
  669. }
  670. else
  671. {
  672. val += dicVal + ",";
  673. }
  674. }
  675. }
  676. val = val.TrimEnd(',');
  677. condi += val + ")";
  678. }
  679. else if(fieldQueryKind == "3") //范围匹配
  680. {
  681. string[] val = fieldQueryValue.Split(':');
  682. if(fieldQueryModel == "request_param")
  683. {
  684. Dictionary<string, string> req = getRequestParams(projectId, content);
  685. if(fieldQueryValueType == "number")
  686. {
  687. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  688. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  689. }
  690. else
  691. {
  692. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  693. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  694. }
  695. }
  696. else if(fieldQueryModel == "fixed_value")
  697. {
  698. if(fieldQueryValueType == "number")
  699. {
  700. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  701. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  702. }
  703. else
  704. {
  705. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  706. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  707. }
  708. }
  709. else if(fieldQueryModel == "db_field")
  710. {
  711. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + GetDbExpressionVal(val[0]);
  712. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + GetDbExpressionVal(val[1]);
  713. }
  714. else if(fieldQueryModel == "query_field")
  715. {
  716. string valLeft = val[0];
  717. string valRight = val[1];
  718. string dicValLeft = GetQueryTableData(dic, valLeft);
  719. string dicValRight = GetQueryTableData(dic, valRight);
  720. if(fieldQueryValueType == "number")
  721. {
  722. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft;
  723. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight;
  724. }
  725. else
  726. {
  727. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'";
  728. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'";
  729. }
  730. }
  731. }
  732. else if(fieldQueryKind == "4") //取反匹配
  733. {
  734. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is not null";
  735. else
  736. {
  737. condi += " and " + fieldEnName + "!=";
  738. string val = "";
  739. if(fieldQueryModel == "request_param")
  740. {
  741. Dictionary<string, string> req = getRequestParams(projectId, content);
  742. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  743. }
  744. else if(fieldQueryModel == "fixed_value")
  745. {
  746. val = GetExpressionVal(fieldQueryValue);
  747. }
  748. else if(fieldQueryModel == "db_field")
  749. {
  750. val = GetDbExpressionVal(fieldQueryValue);
  751. }
  752. else if(fieldQueryModel == "query_field")
  753. {
  754. val = GetQueryTableData(dic, fieldQueryValue);
  755. }
  756. if(fieldQueryValueType == "text")
  757. {
  758. val = "'" + val + "'";
  759. }
  760. condi += val;
  761. }
  762. }
  763. }
  764. }
  765. if(!string.IsNullOrEmpty(groupBy)) groupBy = " group by " + groupBy.TrimEnd(',') + " order by " + groupBy.TrimEnd(',');
  766. if(!string.IsNullOrEmpty(queryTable.orderBy))
  767. {
  768. groupBy += " " + queryTable.orderBy;
  769. }
  770. sql = "select " + fields + " from " + tableEnName + " where 1=1" + condi + groupBy + " limit " + skip + "," + size;
  771. }
  772. else
  773. {
  774. sql = queryTable.customSql;
  775. }
  776. var db = initDb(queryTable.databaseId);
  777. var items = db.Ado.GetDataTable(sql);
  778. return items;
  779. }
  780. return new DataTable();
  781. }
  782. //奖励发放对象
  783. public static string prizeObject(int listId, int prizeObjectTag, string content)
  784. {
  785. Dictionary<string, object> logStepDic = new();
  786. Dictionary<string, object> dic = new();
  787. var prizeObjectTableService = App.GetService<IPriPrizeObjectTableService>();
  788. var prizeObjectFieldService = App.GetService<IPriPrizeObjectFieldService>();
  789. //查询表
  790. var prizeObjectTable = prizeObjectTableService.GetFirst(m => m.id == prizeObjectTag) ?? new PriPrizeObjectTable();
  791. //查询返回字段
  792. string field = prizeObjectTable.selectField;
  793. if(string.IsNullOrEmpty(field)) return "0";
  794. int projectId = prizeObjectTable.projectId;
  795. logStepDic.Add("奖励发放对象说明", prizeObjectTable.note);
  796. //查询匹配条件
  797. string condi = "";
  798. List<Dictionary<string, object>> condiDics = new();
  799. var queryFields = prizeObjectFieldService.GetList(m => m.objectTableId == prizeObjectTable.id);
  800. foreach(var queryField in queryFields)
  801. {
  802. string fieldName = queryField.fieldName;
  803. string fieldEnName = queryField.fieldEnName;
  804. string fieldQueryKind = queryField.fieldQueryKind;
  805. string fieldQueryModel = queryField.fieldQueryModel;
  806. string fieldQueryValue = queryField.fieldQueryValue;
  807. string fieldQueryValueType = queryField.fieldQueryValueType;
  808. Dictionary<string, object> condiDic = new();
  809. condiDic.Add("字段名称", fieldName);
  810. condiDic.Add("匹配条件", getQueryKind(fieldQueryKind));
  811. condiDic.Add("匹配方式", getQueryModel(fieldQueryModel));
  812. if(fieldQueryKind == "1") //模糊匹配
  813. {
  814. condi += " and " + fieldEnName + " like ";
  815. if(fieldQueryModel == "request_param")
  816. {
  817. Dictionary<string, string> req = getRequestParams(projectId, content);
  818. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  819. condi += "'%" + val + "%'";
  820. condiDic.Add("匹配值", val);
  821. }
  822. else if(fieldQueryModel == "fixed_value")
  823. {
  824. string val = GetExpressionVal(fieldQueryValue);
  825. condi += "'%" + val + "%'";
  826. condiDic.Add("匹配值", val);
  827. }
  828. else if(fieldQueryModel == "db_field")
  829. {
  830. string val = GetDbExpressionVal(fieldQueryValue);
  831. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  832. condiDic.Add("匹配值", val);
  833. }
  834. }
  835. else if(fieldQueryKind == "2") //精确匹配
  836. {
  837. condi += " and " + fieldEnName + "=";
  838. string val = "";
  839. if(fieldQueryModel == "request_param")
  840. {
  841. Dictionary<string, string> req = getRequestParams(projectId, content);
  842. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  843. }
  844. else if(fieldQueryModel == "fixed_value")
  845. {
  846. val = GetExpressionVal(fieldQueryValue);
  847. }
  848. else if(fieldQueryModel == "db_field")
  849. {
  850. val = GetDbExpressionVal(fieldQueryValue);
  851. }
  852. if(fieldQueryValueType == "text")
  853. {
  854. val = "'" + val + "'";
  855. }
  856. condi += val;
  857. condiDic.Add("匹配值", val);
  858. }
  859. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  860. {
  861. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  862. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  863. string val = "";
  864. string[] valList = fieldQueryValue.Split(',');
  865. if(fieldQueryModel == "request_param")
  866. {
  867. Dictionary<string, string> req = getRequestParams(projectId, content);
  868. foreach(string sub in valList)
  869. {
  870. if(fieldQueryValueType == "text")
  871. {
  872. val += "'" + req[sub] + "',";
  873. }
  874. else
  875. {
  876. val += req[sub] + ",";
  877. }
  878. }
  879. }
  880. else if(fieldQueryModel == "fixed_value")
  881. {
  882. foreach(string sub in valList)
  883. {
  884. if(fieldQueryValueType == "text")
  885. {
  886. val += "'" + GetExpressionVal(sub) + "',";
  887. }
  888. else
  889. {
  890. val += GetExpressionVal(sub) + ",";
  891. }
  892. }
  893. }
  894. else if(fieldQueryModel == "db_field")
  895. {
  896. foreach(string sub in valList)
  897. {
  898. if(fieldQueryValueType == "text")
  899. {
  900. val += "'" + GetDbExpressionVal(sub) + "',";
  901. }
  902. else
  903. {
  904. val += GetDbExpressionVal(sub) + ",";
  905. }
  906. }
  907. }
  908. val = val.TrimEnd(',');
  909. condi += val + ")";
  910. condiDic.Add("匹配值", val);
  911. }
  912. else if(fieldQueryKind == "3") //范围匹配
  913. {
  914. string[] val = fieldQueryValue.Split(':');
  915. if(fieldQueryModel == "request_param")
  916. {
  917. Dictionary<string, string> req = getRequestParams(projectId, content);
  918. if(fieldQueryValueType == "number")
  919. {
  920. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  921. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  922. }
  923. else
  924. {
  925. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  926. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  927. }
  928. }
  929. else if(fieldQueryModel == "fixed_value")
  930. {
  931. if(fieldQueryValueType == "number")
  932. {
  933. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  934. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  935. }
  936. else
  937. {
  938. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  939. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  940. }
  941. }
  942. else if(fieldQueryModel == "db_field")
  943. {
  944. if(fieldQueryValueType == "number")
  945. {
  946. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  947. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  948. }
  949. else
  950. {
  951. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  952. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  953. }
  954. }
  955. condiDic.Add("匹配值", val);
  956. }
  957. else if(fieldQueryKind == "4") //取反匹配
  958. {
  959. condi += " and " + fieldEnName + "!=";
  960. string val = "";
  961. if(fieldQueryModel == "request_param")
  962. {
  963. Dictionary<string, string> req = getRequestParams(projectId, content);
  964. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  965. }
  966. else if(fieldQueryModel == "fixed_value")
  967. {
  968. val = GetExpressionVal(fieldQueryValue);
  969. }
  970. else if(fieldQueryModel == "db_field")
  971. {
  972. val = GetDbExpressionVal(fieldQueryValue);
  973. }
  974. if(fieldQueryValueType == "text")
  975. {
  976. val = "'" + val + "'";
  977. }
  978. condi += val;
  979. condiDic.Add("匹配值", val);
  980. }
  981. condiDics.Add(condiDic);
  982. }
  983. logStepDic.Add("奖励发放对象查询条件", condiDics);
  984. string result = "0";
  985. var db = initDb(prizeObjectTable.databaseId);
  986. var item = db.Ado.GetScalar("select " + field + " from " + prizeObjectTable.tableEnName + " where 1=1" + condi);
  987. if(item != null)
  988. {
  989. result = item.ToString();
  990. }
  991. logStepDic.Add("奖励发放对象", result);
  992. setLogStep(listId, "奖励发放对象", logStepDic);
  993. return result;
  994. }
  995. //奖励发放入口
  996. public static string prizeInSet(string queueName)
  997. {
  998. Dictionary<string, object> dic = new();
  999. var prizeInSetService = App.GetService<IPriPrizeInSetService>();
  1000. //查询表
  1001. var prizeInSet = prizeInSetService.GetFirst(m => m.mqQueueName == queueName) ?? new PriPrizeInSet();
  1002. if(prizeInSet.id > 0)
  1003. {
  1004. return prizeInSet.prizeListIds + "|" + prizeInSet.projectId + "|" + prizeInSet.id;
  1005. }
  1006. return "";
  1007. }
  1008. //奖励列表
  1009. public static List<PriList> prizeList(int projectId, string prizeIds)
  1010. {
  1011. List<int> ids = Tools.SpitIntArrary(prizeIds, ',').ToList();
  1012. var priListService = App.GetService<IPriListService>();
  1013. var priList = priListService.GetList(m => m.projectId == projectId && ids.Contains(m.id)).ToList();
  1014. return priList;
  1015. }
  1016. //奖励发放
  1017. public static void prizeSend(int projectId, int prizeInId, string prizeIds, string content, string queueName)
  1018. {
  1019. var queryTableService = App.GetService<IPriQueryTableService>();
  1020. var priList = prizeList(projectId, prizeIds);
  1021. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-3", "接收mq数据日志");
  1022. foreach(var sub in priList)
  1023. {
  1024. try
  1025. {
  1026. List<int> ids = Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList();
  1027. var queryTable = queryTableService.GetFirst(m => ids.Contains(m.id) && m.startDataFlag == true);
  1028. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-4", "接收mq数据日志");
  1029. if (queryTable != null)
  1030. {
  1031. int page = 0;
  1032. int size = queryTable.stepCount;
  1033. if(size == 0) size = 20;
  1034. bool op = true;
  1035. while(op)
  1036. {
  1037. int skip = page * size;
  1038. DataTable query = conditionList(sub.id, projectId, ids, content, skip, size);
  1039. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-41", "接收mq数据日志");
  1040. if(query.Rows.Count > 0)
  1041. {
  1042. foreach(DataRow dr in query.Rows)
  1043. {
  1044. Dictionary<string, string> startData = new();
  1045. foreach(DataColumn dc in query.Columns)
  1046. {
  1047. startData.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
  1048. }
  1049. prizeSendSub(sub, projectId, prizeInId, prizeIds, content, queueName, startData);
  1050. }
  1051. page += 1;
  1052. }
  1053. else
  1054. {
  1055. op = false;
  1056. }
  1057. }
  1058. }
  1059. else
  1060. {
  1061. prizeSendSub(sub, projectId, prizeInId, prizeIds, content, queueName, new Dictionary<string, string>());
  1062. }
  1063. }
  1064. catch(Exception ex)
  1065. {
  1066. setLogFieldValue(sub.id, "errLog", ex.ToString());
  1067. }
  1068. }
  1069. }
  1070. //执行每个奖励发放逻辑
  1071. public static void prizeSendSub(PriList sub, int projectId, int prizeInId, string prizeIds, string content, string queueName, Dictionary<string, string> startData)
  1072. {
  1073. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-" + sub.prizeName, "接收mq数据日志");
  1074. var loopSetService = App.GetService<IPriLoopSetService>();
  1075. var recursionStartTableService = App.GetService<IPriRecursionStartTableService>();
  1076. var recursionStartConditionService = App.GetService<IPriRecursionStartConditionService>();
  1077. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-s1", "接收mq数据日志");
  1078. addLog(projectId, sub.id, prizeInId, content, queueName, content); //初始化日志
  1079. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-s2", "接收mq数据日志");
  1080. string prizeObjectId = prizeObject(sub.id, sub.prizeObj, content);
  1081. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-s3", "接收mq数据日志");
  1082. var recursionFlag = sub.recursionFlag; //是否递归
  1083. setLogStep(sub.id, "是否递归", recursionFlag ? "是" : "否");
  1084. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-s4", "接收mq数据日志");
  1085. bool check = prizeSendDo(projectId, sub, prizeObjectId, content, new PriLoopSet(), startData);
  1086. if(check)
  1087. {
  1088. List<QueryCondition> rootCondiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content, startData);
  1089. if(recursionFlag)
  1090. {
  1091. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop0", "接收mq数据日志");
  1092. List<QueryCondition> queryCondiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content, startData);
  1093. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop1", "接收mq数据日志");
  1094. // setLogStep(sub.id, "查询原始数据", queryCondiDic);
  1095. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop2", "接收mq数据日志");
  1096. var loopSet = loopSetService.GetFirst(m => m.listId == sub.id) ?? new PriLoopSet();
  1097. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop3", "接收mq数据日志");
  1098. var recursionStartTable = recursionStartTableService.GetFirst(m => m.listId == sub.id) ?? new PriRecursionStartTable();
  1099. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop4", "接收mq数据日志");
  1100. var tableEnName = loopSet.tableEnName; //递归查询表
  1101. var parentField = loopSet.parentField; //父字段
  1102. var sonField = loopSet.sonField; //子字段
  1103. var afterPrizeFlag = loopSet.afterPrizeFlag; //发奖后是否继续
  1104. var db = initDb(loopSet.databaseId);
  1105. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop5", "接收mq数据日志");
  1106. string objId = prizeObjectId;
  1107. bool op = true;
  1108. int index = 0;
  1109. loopAmount = 0;
  1110. List<Dictionary<string, object>> loopLogDic = new();
  1111. while(!string.IsNullOrEmpty(objId) && objId != "0" && op)
  1112. {
  1113. Dictionary<string, object> loopLog = new();
  1114. List<QueryCondition> condiDic = loopCondition(projectId, sub, objId, content);
  1115. condiDic.AddRange(rootCondiDic);
  1116. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop-in-1", "接收mq数据日志");
  1117. loopLog.Add("查询" + objId + "匹配数据", condiDic);
  1118. if(condiDic.Count > 0)
  1119. {
  1120. bool prizeFlag = false;
  1121. List<Dictionary<string, object>> logStepDics = new();
  1122. var groupNos = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id).ToList().Select(m => m.groupNo).Distinct().ToList();
  1123. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop-in-2", "接收mq数据日志");
  1124. foreach(var groupNo in groupNos)
  1125. {
  1126. var conditions = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id && m.groupNo == groupNo);
  1127. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop-in-11", "接收mq数据日志");
  1128. if(conditions.Count > 0)
  1129. {
  1130. int allCount = conditions.Count; //所有奖励条件数
  1131. int passCount = 0; //通过条件数
  1132. foreach(var condition in conditions)
  1133. {
  1134. if(condition.startIndex <= index)
  1135. {
  1136. Dictionary<string, object> logStepDic = new();
  1137. var returnFieldId = condition.returnFieldId; //条件返回字段
  1138. returnFieldId = MatchExpressionVal(returnFieldId);
  1139. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  1140. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  1141. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  1142. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  1143. string checkObj = "";
  1144. string checkTitle = "";
  1145. if(returnFieldId.Contains(","))
  1146. {
  1147. string[] returnFieldIdList = returnFieldId.Split(',');
  1148. foreach(string subField in returnFieldIdList)
  1149. {
  1150. string val = GetQueryTableData(condiDic, subField);
  1151. checkObj += val + ",";
  1152. string title = GetQueryTableTitle(condiDic, subField);
  1153. checkTitle += title + ",";
  1154. }
  1155. checkObj = checkObj.TrimEnd(',');
  1156. checkTitle = checkTitle.TrimEnd(',');
  1157. }
  1158. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  1159. {
  1160. string expresssion = returnFieldId;
  1161. checkTitle = returnFieldId;
  1162. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  1163. foreach(string returnField in returnFields)
  1164. {
  1165. string val = GetQueryTableData(condiDic, returnField);
  1166. if(val == returnField) val = "0";
  1167. expresssion = expresssion.Replace(returnField, val);
  1168. string title = GetQueryTableTitle(condiDic, returnField);
  1169. checkTitle = checkTitle.Replace(returnField, title);
  1170. }
  1171. DataTable dt = new();
  1172. checkObj = dt.Compute(expresssion, "false").ToString();
  1173. }
  1174. else if(returnFieldId.StartsWith("val"))
  1175. {
  1176. checkObj = returnFieldId.Replace("val{", "").Replace("}", "");
  1177. }
  1178. else
  1179. {
  1180. checkObj = GetQueryTableData(condiDic, returnFieldId);
  1181. checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
  1182. }
  1183. logStepDic.Add("标题", checkTitle);
  1184. logStepDic.Add("分组", condition.groupNo);
  1185. logStepDic.Add("匹配条件", getQueryKind(fieldQueryKind));
  1186. logStepDic.Add("匹配方式", getQueryModel(fieldQueryModel));
  1187. logStepDic.Add("匹配值", fieldQueryValue);
  1188. logStepDic.Add("实际值", checkObj);
  1189. var checkVal = fieldQueryValue;
  1190. bool passFlag = false;
  1191. if(fieldQueryKind == "1") //模糊匹配
  1192. {
  1193. if(fieldQueryValueType == "text")
  1194. {
  1195. if(checkObj.ToString().Contains(GetExpressionVal(checkVal)))
  1196. {
  1197. passCount += 1; passFlag = true;
  1198. }
  1199. }
  1200. }
  1201. else if(fieldQueryKind == "2") //精确匹配
  1202. {
  1203. if(fieldQueryValueType == "int")
  1204. {
  1205. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal)))
  1206. {
  1207. passCount += 1; passFlag = true;
  1208. }
  1209. }
  1210. else if(fieldQueryValueType == "number")
  1211. {
  1212. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal)))
  1213. {
  1214. passCount += 1; passFlag = true;
  1215. }
  1216. }
  1217. else
  1218. {
  1219. if(checkObj.ToString() == GetExpressionVal(checkVal))
  1220. {
  1221. passCount += 1; passFlag = true;
  1222. }
  1223. }
  1224. }
  1225. else if(fieldQueryKind == "3") //范围匹配
  1226. {
  1227. string[] val = checkVal.Split(':');
  1228. string valLeft = val[0];
  1229. string valRight = val[1];
  1230. if(fieldQueryModel == "request_param")
  1231. {
  1232. Dictionary<string, string> req = getRequestParams(projectId, content);
  1233. if(fieldQueryValueType == "number")
  1234. {
  1235. 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])))
  1236. {
  1237. passCount += 1; passFlag = true;
  1238. }
  1239. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])))
  1240. {
  1241. passCount += 1; passFlag = true;
  1242. }
  1243. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight])))
  1244. {
  1245. passCount += 1; passFlag = true;
  1246. }
  1247. }
  1248. else if(fieldQueryValueType == "int")
  1249. {
  1250. 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])))
  1251. {
  1252. passCount += 1; passFlag = true;
  1253. }
  1254. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])))
  1255. {
  1256. passCount += 1; passFlag = true;
  1257. }
  1258. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight])))
  1259. {
  1260. passCount += 1; passFlag = true;
  1261. }
  1262. }
  1263. else if(fieldQueryValueType.StartsWith("date"))
  1264. {
  1265. checkObj = checkDateTime(checkObj);
  1266. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1267. {
  1268. passCount += 1; passFlag = true;
  1269. }
  1270. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]))
  1271. {
  1272. passCount += 1; passFlag = true;
  1273. }
  1274. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1275. {
  1276. passCount += 1; passFlag = true;
  1277. }
  1278. }
  1279. }
  1280. else if(fieldQueryModel == "fixed_value")
  1281. {
  1282. string checkValLeft = valLeft.Replace("#{", "").Replace("}#", "");
  1283. string checkValRight = valRight.Replace("#{", "").Replace("}#", "");
  1284. if(checkValLeft.Contains(",")) checkValLeft = checkValLeft.Split(',')[0];
  1285. if(checkValRight.Contains(",")) checkValRight = checkValRight.Split(',')[0];
  1286. valLeft = GetExpressionVal(valLeft);
  1287. valRight = GetExpressionVal(valRight);
  1288. if(fieldQueryValueType == "number")
  1289. {
  1290. 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)))
  1291. {
  1292. passCount += 1; passFlag = true;
  1293. }
  1294. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1295. {
  1296. passCount += 1; passFlag = true;
  1297. }
  1298. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1299. {
  1300. passCount += 1; passFlag = true;
  1301. }
  1302. }
  1303. else if(fieldQueryValueType == "int")
  1304. {
  1305. 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)))
  1306. {
  1307. passCount += 1; passFlag = true;
  1308. }
  1309. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1310. {
  1311. passCount += 1; passFlag = true;
  1312. }
  1313. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1314. {
  1315. passCount += 1; passFlag = true;
  1316. }
  1317. }
  1318. else if(fieldQueryValueType.StartsWith("date"))
  1319. {
  1320. if(valLeft == "0") valLeft = "";
  1321. if(valRight == "0") valRight = "";
  1322. if(checkObj != "0" && checkObj != "")
  1323. {
  1324. checkObj = checkDateTime(checkObj);
  1325. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  1326. {
  1327. passCount += 1; passFlag = true;
  1328. }
  1329. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1330. {
  1331. passCount += 1; passFlag = true;
  1332. }
  1333. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  1334. {
  1335. passCount += 1; passFlag = true;
  1336. }
  1337. }
  1338. }
  1339. }
  1340. else if(fieldQueryModel == "query_field")
  1341. {
  1342. valLeft = GetComputeVal(queryCondiDic, valLeft);
  1343. valRight = GetComputeVal(queryCondiDic, valRight);
  1344. if(fieldQueryValueType == "number")
  1345. {
  1346. 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)))
  1347. {
  1348. passCount += 1; passFlag = true;
  1349. }
  1350. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1351. {
  1352. passCount += 1; passFlag = true;
  1353. }
  1354. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1355. {
  1356. passCount += 1; passFlag = true;
  1357. }
  1358. }
  1359. else if(fieldQueryValueType == "int")
  1360. {
  1361. 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)))
  1362. {
  1363. passCount += 1; passFlag = true;
  1364. }
  1365. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1366. {
  1367. passCount += 1; passFlag = true;
  1368. }
  1369. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1370. {
  1371. passCount += 1; passFlag = true;
  1372. }
  1373. }
  1374. else if(fieldQueryValueType.StartsWith("date"))
  1375. {
  1376. if(valLeft == "0") valLeft = "";
  1377. if(valRight == "0") valRight = "";
  1378. if(checkObj != "0" && checkObj != "")
  1379. {
  1380. checkObj = checkDateTime(checkObj);
  1381. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  1382. {
  1383. passCount += 1; passFlag = true;
  1384. }
  1385. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1386. {
  1387. passCount += 1; passFlag = true;
  1388. }
  1389. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  1390. {
  1391. passCount += 1; passFlag = true;
  1392. }
  1393. }
  1394. }
  1395. }
  1396. }
  1397. else if(fieldQueryKind == "4") //取反匹配
  1398. {
  1399. if(fieldQueryValueType == "int")
  1400. {
  1401. if(int.Parse(checkObj) != int.Parse(Function.CheckInt(checkVal)))
  1402. {
  1403. passCount += 1; passFlag = true;
  1404. }
  1405. }
  1406. else if(fieldQueryValueType == "number")
  1407. {
  1408. if(decimal.Parse(checkObj) != decimal.Parse(Function.CheckNum(checkVal)))
  1409. {
  1410. passCount += 1; passFlag = true;
  1411. }
  1412. }
  1413. else if(fieldQueryValueType == "text")
  1414. {
  1415. if(checkObj.ToString() != GetExpressionVal(checkVal))
  1416. {
  1417. passCount += 1; passFlag = true;
  1418. }
  1419. }
  1420. }
  1421. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1422. {
  1423. string val = ",";
  1424. string[] valList = checkVal.Split(',');
  1425. if(fieldQueryModel == "request_param")
  1426. {
  1427. Dictionary<string, string> req = getRequestParams(projectId, content);
  1428. foreach(string subVal in valList)
  1429. {
  1430. val += req[subVal] + ",";
  1431. }
  1432. }
  1433. else if(fieldQueryModel == "fixed_value")
  1434. {
  1435. foreach(string subVal in valList)
  1436. {
  1437. val += GetExpressionVal(subVal) + ",";
  1438. }
  1439. }
  1440. else if(fieldQueryModel == "db_field")
  1441. {
  1442. foreach(string subVal in valList)
  1443. {
  1444. val += GetDbExpressionVal(subVal) + ",";
  1445. }
  1446. }
  1447. if(fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ","))
  1448. {
  1449. passCount += 1; passFlag = true;
  1450. }
  1451. if(fieldQueryKind == "6" && !val.Contains("," + checkObj.ToString() + ","))
  1452. {
  1453. passCount += 1; passFlag = true;
  1454. }
  1455. }
  1456. logStepDic.Add("状态", passFlag ? "通过" : "未通过");
  1457. logStepDics.Add(logStepDic);
  1458. }
  1459. }
  1460. if(loopSet.conditionMode == "all" && passCount == allCount) prizeFlag = true;
  1461. else if(loopSet.conditionMode == "one" && passCount >= 1) prizeFlag = true;
  1462. else if(loopSet.conditionMode == "two" && passCount >= 2) prizeFlag = true;
  1463. else if(loopSet.conditionMode == "three" && passCount >= 3) prizeFlag = true;
  1464. // else prizeFlag = false;
  1465. }
  1466. // else
  1467. // {
  1468. // prizeFlag = false;
  1469. // }
  1470. }
  1471. loopLog.Add(objId + "匹配情况", logStepDics);
  1472. loopLog.Add("匹配结果", prizeFlag);
  1473. if(prizeFlag)
  1474. {
  1475. prizeAck(projectId, sub, objId, content, new PriLoopSet(), rootCondiDic, startData);
  1476. op = afterPrizeFlag;
  1477. }
  1478. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-loop-in-3", "接收mq数据日志");
  1479. }
  1480. loopLogDic.Add(loopLog);
  1481. var parent = db.Ado.GetScalar("select " + parentField + " from " + tableEnName + " where " + sonField + "=" + objId);
  1482. if(parent != null)
  1483. {
  1484. objId = parent.ToString();
  1485. }
  1486. else
  1487. {
  1488. objId = "0";
  1489. }
  1490. index += 1;
  1491. }
  1492. setLogStep(sub.id, "向上递归流程", loopLogDic);
  1493. }
  1494. else
  1495. {
  1496. prizeAck(projectId, sub, prizeObjectId, content, new PriLoopSet(), rootCondiDic, startData);
  1497. }
  1498. }
  1499. }
  1500. static decimal loopAmount = 0;
  1501. public static bool prizeSendDo(int projectId, PriList sub, string prizeObjectId, string content, PriLoopSet set, Dictionary<string, string> startData)
  1502. {
  1503. var projectService = App.GetService<IPriProjectService>();
  1504. var recordService = App.GetService<IPriRecordService>();
  1505. var conditionService = App.GetService<IPriConditionService>();
  1506. var returnFieldService = App.GetService<IPriReturnFieldService>();
  1507. // var queryTableService = App.GetService<IPriQueryTableService>();
  1508. var amountSetService = App.GetService<IPriListAmountSetService>();
  1509. //查询匹配条件
  1510. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p1", "接收mq数据日志");
  1511. List<QueryCondition> condiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content, startData);
  1512. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p2", "接收mq数据日志");
  1513. if(sub.prizeSourceFieldType == "loop") MergeCondiDic(condiDic, loopCondition(projectId, sub, prizeObjectId, content));
  1514. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p3", "接收mq数据日志");
  1515. setLogStep(sub.id, "发放奖励查询来源数据", condiDic);
  1516. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p4", "接收mq数据日志");
  1517. var prizeSourceField = sub.prizeSourceField; //奖励金额来源字段(对应条件匹配返回字段)
  1518. var prizePercent = sub.prizePercent; //奖励比例
  1519. var prizeAmount = sub.prizeAmount; //奖励固定值
  1520. var prizeContent = sub.prizeContent; //奖励内容
  1521. var conditionMode = sub.conditionMode; //条件模式
  1522. var recursionFlag = sub.recursionFlag; //是否递归
  1523. var prizeCode = sub.prizeCode; //奖励代码
  1524. prizeSourceField = MatchExpressionVal(prizeSourceField);
  1525. bool op = false;
  1526. var groupNos = conditionService.GetList(m => m.listId == sub.id).ToList().Select(m => m.groupNo).Distinct().ToList();
  1527. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p5", "接收mq数据日志");
  1528. foreach(var groupNo in groupNos)
  1529. {
  1530. var conditions = conditionService.GetList(m => m.listId == sub.id && m.groupNo == groupNo);
  1531. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p6", "接收mq数据日志");
  1532. // setLogStep(sub.id, "发放奖励匹配条件", condiDic);
  1533. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p7", "接收mq数据日志");
  1534. int allCount = conditions.Count; //所有奖励条件数
  1535. int passCount = 0; //通过条件数
  1536. List<Dictionary<string, object>> logStepDics = new();
  1537. foreach(var condition in conditions)
  1538. {
  1539. Dictionary<string, object> logStepDic = new();
  1540. var returnFieldId = condition.returnFieldId; //条件返回字段
  1541. returnFieldId = MatchExpressionVal(returnFieldId);
  1542. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  1543. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  1544. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  1545. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  1546. string checkObj = "";
  1547. string checkTitle = "";
  1548. if(returnFieldId.Contains(","))
  1549. {
  1550. string[] returnFieldIdList = returnFieldId.Split(',');
  1551. foreach(string subField in returnFieldIdList)
  1552. {
  1553. string val = GetQueryTableData(condiDic, subField);
  1554. checkObj += val + ",";
  1555. string title = GetQueryTableTitle(condiDic, subField);
  1556. checkTitle += title + ",";
  1557. }
  1558. checkObj = checkObj.TrimEnd(',');
  1559. checkTitle = checkTitle.TrimEnd(',');
  1560. }
  1561. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  1562. {
  1563. string expresssion = returnFieldId;
  1564. checkTitle = returnFieldId;
  1565. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  1566. foreach(string returnField in returnFields)
  1567. {
  1568. string val = GetQueryTableData(condiDic, returnField);
  1569. expresssion = expresssion.Replace(returnField, val);
  1570. string title = GetQueryTableTitle(condiDic, returnField);
  1571. checkTitle = checkTitle.Replace(returnField, title);
  1572. }
  1573. DataTable dt = new();
  1574. checkObj = dt.Compute(expresssion, "false").ToString();
  1575. }
  1576. else if(returnFieldId.StartsWith("val"))
  1577. {
  1578. checkObj = returnFieldId.Replace("val{", "").Replace("}", "");
  1579. }
  1580. else
  1581. {
  1582. checkObj = GetQueryTableData(condiDic, returnFieldId);
  1583. checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
  1584. }
  1585. // if(!sub.recursionFlag)
  1586. // {
  1587. logStepDic.Add("标题", checkTitle);
  1588. logStepDic.Add("分组", condition.groupNo);
  1589. logStepDic.Add("匹配条件", getQueryKind(fieldQueryKind));
  1590. logStepDic.Add("匹配方式", getQueryModel(fieldQueryModel));
  1591. logStepDic.Add("匹配值", fieldQueryValue);
  1592. logStepDic.Add("实际值", checkObj);
  1593. // }
  1594. string checkVal = fieldQueryValue;
  1595. bool passFlag = false;
  1596. if(fieldQueryKind == "1") //模糊匹配
  1597. {
  1598. if(fieldQueryValueType == "text")
  1599. {
  1600. if(checkObj.ToString().Contains(GetExpressionVal(checkVal)))
  1601. {
  1602. passCount += 1; passFlag = true;
  1603. }
  1604. }
  1605. }
  1606. else if(fieldQueryKind == "2") //精确匹配
  1607. {
  1608. if(fieldQueryValueType == "int")
  1609. {
  1610. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal)))
  1611. {
  1612. passCount += 1; passFlag = true;
  1613. }
  1614. }
  1615. else if(fieldQueryValueType == "number")
  1616. {
  1617. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal)))
  1618. {
  1619. passCount += 1; passFlag = true;
  1620. }
  1621. }
  1622. else
  1623. {
  1624. if(checkObj.ToString() == GetExpressionVal(checkVal))
  1625. {
  1626. passCount += 1; passFlag = true;
  1627. }
  1628. }
  1629. }
  1630. else if(fieldQueryKind == "3") //范围匹配
  1631. {
  1632. string[] val = checkVal.Split(':');
  1633. string valLeft = val[0];
  1634. string valRight = val[1];
  1635. if(fieldQueryModel == "request_param")
  1636. {
  1637. Dictionary<string, string> req = getRequestParams(projectId, content);
  1638. if(fieldQueryValueType == "number")
  1639. {
  1640. 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])))
  1641. {
  1642. passCount += 1; passFlag = true;
  1643. }
  1644. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])))
  1645. {
  1646. passCount += 1; passFlag = true;
  1647. }
  1648. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight])))
  1649. {
  1650. passCount += 1; passFlag = true;
  1651. }
  1652. }
  1653. else if(fieldQueryValueType == "int")
  1654. {
  1655. 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])))
  1656. {
  1657. passCount += 1; passFlag = true;
  1658. }
  1659. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])))
  1660. {
  1661. passCount += 1; passFlag = true;
  1662. }
  1663. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight])))
  1664. {
  1665. passCount += 1; passFlag = true;
  1666. }
  1667. }
  1668. else if(fieldQueryValueType.StartsWith("date"))
  1669. {
  1670. checkObj = checkDateTime(checkObj);
  1671. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1672. {
  1673. passCount += 1; passFlag = true;
  1674. }
  1675. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]))
  1676. {
  1677. passCount += 1; passFlag = true;
  1678. }
  1679. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1680. {
  1681. passCount += 1; passFlag = true;
  1682. }
  1683. }
  1684. }
  1685. else if(fieldQueryModel == "fixed_value")
  1686. {
  1687. valLeft = GetExpressionVal(valLeft);
  1688. valRight = GetExpressionVal(valRight);
  1689. if(fieldQueryValueType == "number")
  1690. {
  1691. 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)))
  1692. {
  1693. passCount += 1; passFlag = true;
  1694. }
  1695. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1696. {
  1697. passCount += 1; passFlag = true;
  1698. }
  1699. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1700. {
  1701. passCount += 1; passFlag = true;
  1702. }
  1703. }
  1704. else if(fieldQueryValueType == "int")
  1705. {
  1706. 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)))
  1707. {
  1708. passCount += 1; passFlag = true;
  1709. }
  1710. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1711. {
  1712. passCount += 1; passFlag = true;
  1713. }
  1714. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1715. {
  1716. passCount += 1; passFlag = true;
  1717. }
  1718. }
  1719. else if(fieldQueryValueType.StartsWith("date"))
  1720. {
  1721. if(valLeft == "0") valLeft = "";
  1722. if(valRight == "0") valRight = "";
  1723. if(checkObj != "0" && checkObj != "")
  1724. {
  1725. checkObj = checkDateTime(checkObj);
  1726. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1727. {
  1728. passCount += 1; passFlag = true;
  1729. }
  1730. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1731. {
  1732. passCount += 1; passFlag = true;
  1733. }
  1734. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1735. {
  1736. passCount += 1; passFlag = true;
  1737. }
  1738. }
  1739. }
  1740. }
  1741. else if(fieldQueryModel == "query_field")
  1742. {
  1743. string checkValLeft = valLeft.Replace("#{", "").Replace("}#", "");
  1744. string checkValRight = valRight.Replace("#{", "").Replace("}#", "");
  1745. if(checkValLeft.Contains(",")) checkValLeft = checkValLeft.Split(',')[0];
  1746. if(checkValRight.Contains(",")) checkValRight = checkValRight.Split(',')[0];
  1747. if(!string.IsNullOrEmpty(valLeft)) valLeft = valLeft.Replace(checkValLeft, GetQueryTableData(condiDic, checkValLeft));
  1748. if(!string.IsNullOrEmpty(valRight)) valRight = valRight.Replace(checkValRight, GetQueryTableData(condiDic, checkValRight));
  1749. valLeft = GetExpressionVal(valLeft);
  1750. valRight = GetExpressionVal(valRight);
  1751. if(fieldQueryValueType == "number")
  1752. {
  1753. 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)))
  1754. {
  1755. passCount += 1; passFlag = true;
  1756. }
  1757. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1758. {
  1759. passCount += 1; passFlag = true;
  1760. }
  1761. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1762. {
  1763. passCount += 1; passFlag = true;
  1764. }
  1765. }
  1766. else if(fieldQueryValueType == "int")
  1767. {
  1768. 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)))
  1769. {
  1770. passCount += 1; passFlag = true;
  1771. }
  1772. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1773. {
  1774. passCount += 1; passFlag = true;
  1775. }
  1776. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1777. {
  1778. passCount += 1; passFlag = true;
  1779. }
  1780. }
  1781. else if(fieldQueryValueType.StartsWith("date"))
  1782. {
  1783. if(valLeft == "0") valLeft = "";
  1784. if(valRight == "0") valRight = "";
  1785. if(checkObj != "0" && checkObj != "")
  1786. {
  1787. checkObj = checkDateTime(checkObj);
  1788. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1789. {
  1790. passCount += 1; passFlag = true;
  1791. }
  1792. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1793. {
  1794. passCount += 1; passFlag = true;
  1795. }
  1796. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1797. {
  1798. passCount += 1; passFlag = true;
  1799. }
  1800. }
  1801. }
  1802. }
  1803. }
  1804. else if(fieldQueryKind == "4") //取反匹配
  1805. {
  1806. if(fieldQueryValueType == "int")
  1807. {
  1808. if(int.Parse(Function.CheckNum(checkObj.ToString())) != int.Parse(Function.CheckInt(checkVal)))
  1809. {
  1810. passCount += 1; passFlag = true;
  1811. }
  1812. }
  1813. else if(fieldQueryValueType == "number")
  1814. {
  1815. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) != decimal.Parse(Function.CheckNum(checkVal)))
  1816. {
  1817. passCount += 1; passFlag = true;
  1818. }
  1819. }
  1820. else if(fieldQueryValueType == "text")
  1821. {
  1822. if(checkObj.ToString() != GetExpressionVal(checkVal))
  1823. {
  1824. passCount += 1; passFlag = true;
  1825. }
  1826. }
  1827. }
  1828. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1829. {
  1830. string val = ",";
  1831. string[] valList = checkVal.Split(',');
  1832. if(fieldQueryModel == "request_param")
  1833. {
  1834. Dictionary<string, string> req = getRequestParams(projectId, content);
  1835. foreach(string subVal in valList)
  1836. {
  1837. val += req[subVal] + ",";
  1838. }
  1839. }
  1840. else if(fieldQueryModel == "fixed_value")
  1841. {
  1842. foreach(string subVal in valList)
  1843. {
  1844. val += GetExpressionVal(subVal) + ",";
  1845. }
  1846. }
  1847. else if(fieldQueryModel == "db_field")
  1848. {
  1849. foreach(string subVal in valList)
  1850. {
  1851. val += GetDbExpressionVal(subVal) + ",";
  1852. }
  1853. }
  1854. if (fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ","))
  1855. {
  1856. passCount += 1; passFlag = true;
  1857. }
  1858. if(fieldQueryKind == "6" && !val.Contains("," + checkObj.ToString() + ","))
  1859. {
  1860. passCount += 1; passFlag = true;
  1861. }
  1862. }
  1863. // if(!sub.recursionFlag)
  1864. // {
  1865. logStepDic.Add("状态", passFlag ? "通过" : "未通过");
  1866. logStepDics.Add(logStepDic);
  1867. // }
  1868. }
  1869. setLogStep(sub.id, "匹配结果", logStepDics);
  1870. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p8", "接收mq数据日志");
  1871. if(conditionMode == "all" && passCount == allCount && passCount > 0) op = true;
  1872. else if(conditionMode == "one" && passCount >= 1) op = true;
  1873. else if(conditionMode == "two" && passCount >= 2) op = true;
  1874. else if(conditionMode == "three" && passCount >= 3) op = true;
  1875. }
  1876. setLogStep(sub.id, "是否通过", op ? "是" : "否");
  1877. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p9", "接收mq数据日志");
  1878. // if(op) //满足条件
  1879. // {
  1880. // }
  1881. // if(!sub.recursionFlag)
  1882. // {
  1883. setLogStatus(sub.id, op ? 1 : 0);
  1884. // }
  1885. return op;
  1886. }
  1887. public static decimal prizeAck(int projectId, PriList sub, string prizeObjectId, string content, PriLoopSet set, List<QueryCondition> condiDic, Dictionary<string, string> startData)
  1888. {
  1889. var projectService = App.GetService<IPriProjectService>();
  1890. var recordService = App.GetService<IPriRecordService>();
  1891. var conditionService = App.GetService<IPriConditionService>();
  1892. var returnFieldService = App.GetService<IPriReturnFieldService>();
  1893. // var queryTableService = App.GetService<IPriQueryTableService>();
  1894. var amountSetService = App.GetService<IPriListAmountSetService>();
  1895. var project = projectService.GetFirst(m => m.id == projectId) ?? new PriProject();
  1896. var prizeSourceField = sub.prizeSourceField; //奖励金额来源字段(对应条件匹配返回字段)
  1897. var prizePercent = sub.prizePercent; //奖励比例
  1898. var prizeAmount = sub.prizeAmount; //奖励固定值
  1899. var prizeContent = sub.prizeContent; //奖励内容
  1900. var conditionMode = sub.conditionMode; //条件模式
  1901. var recursionFlag = sub.recursionFlag; //是否递归
  1902. var prizeCode = sub.prizeCode; //奖励代码
  1903. decimal prizeAmt = 0;
  1904. prizeSourceField = MatchExpressionVal(prizeSourceField);
  1905. bool repeatFlag = sub.repeatFlag;
  1906. decimal number = 0;
  1907. if(prizeSourceField.Contains("/"))
  1908. {
  1909. number = decimal.Parse(prizeSourceField.Split('/')[1]);
  1910. prizeSourceField = prizeSourceField.Split('/')[0];
  1911. }
  1912. string prizeSourceData = "";
  1913. if(prizeSourceField.Contains(","))
  1914. {
  1915. string[] list = prizeSourceField.Split(',');
  1916. foreach(string subField in list)
  1917. {
  1918. string val = GetQueryTableData(condiDic, subField);
  1919. if(subField == val) val = GetStartData(startData, subField);
  1920. prizeSourceData += val + ",";
  1921. }
  1922. prizeSourceData = prizeSourceData.TrimEnd(',');
  1923. }
  1924. else
  1925. {
  1926. prizeSourceData = GetQueryTableData(condiDic, prizeSourceField);
  1927. }
  1928. if(string.IsNullOrEmpty(prizeSourceData)) prizeSourceData = "0";
  1929. if(prizeSourceField.Contains("/") && number > 0)
  1930. {
  1931. decimal prizeSourceDataNum = decimal.Parse(prizeSourceData) / number;
  1932. prizeSourceData = prizeSourceDataNum.ToString("f2");
  1933. }
  1934. var amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField == prizeSourceData);
  1935. if(amountSet != null)
  1936. {
  1937. prizePercent = amountSet.prizePercent;
  1938. prizeAmount = amountSet.prizeAmount;
  1939. prizeCode = amountSet.prizeCode;
  1940. repeatFlag = amountSet.repeatFlag;
  1941. }
  1942. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p9", "接收mq数据日志");
  1943. if(!prizeSourceData.Contains("$") && !prizeSourceData.Contains("=") && prizeSourceData.Contains(","))
  1944. {
  1945. string[] prizeSourceDataList = prizeSourceData.Split(',');
  1946. string checkField = "";
  1947. for (int i = 0; i < prizeSourceDataList.Length - 1; i++)
  1948. {
  1949. checkField += prizeSourceDataList[i] + ",";
  1950. }
  1951. amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField.StartsWith(checkField) && m.prizeSourceField.EndsWith(",%"));
  1952. if(amountSet != null)
  1953. {
  1954. prizePercent = amountSet.prizePercent;
  1955. prizeAmount = amountSet.prizeAmount;
  1956. prizeCode = amountSet.prizeCode;
  1957. repeatFlag = amountSet.repeatFlag;
  1958. prizeSourceData = prizeSourceDataList[prizeSourceDataList.Length - 1];
  1959. }
  1960. }
  1961. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p10", "接收mq数据日志");
  1962. string[] prizeSourceFieldList = prizeSourceData.Split(',');
  1963. var amountSets = amountSetService.GetList(m => m.listId == sub.id && m.prizeSourceField.Contains("${"));
  1964. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p11", "接收mq数据日志");
  1965. foreach(var subAmountSet in amountSets)
  1966. {
  1967. string subPrizeSourceField = subAmountSet.prizeSourceField;
  1968. for (int i = 0; i < prizeSourceFieldList.Length; i++)
  1969. {
  1970. subPrizeSourceField = subPrizeSourceField.Replace("${" + i + "}", prizeSourceFieldList[i]);
  1971. }
  1972. DataTable dt = new();
  1973. string chk = dt.Compute(subPrizeSourceField, "false").ToString();
  1974. if(chk == "True")
  1975. {
  1976. prizePercent = subAmountSet.prizePercent;
  1977. prizePercent = subAmountSet.prizePercent;
  1978. prizeAmount = subAmountSet.prizeAmount;
  1979. prizeCode = subAmountSet.prizeCode;
  1980. repeatFlag = subAmountSet.repeatFlag;
  1981. prizeSourceData = prizeSourceFieldList[subAmountSet.prizeSourceFieldIndex];
  1982. break;
  1983. }
  1984. }
  1985. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p12", "接收mq数据日志");
  1986. if(prizePercent > 0) prizeAmt += decimal.Parse(Function.CheckNum(prizeSourceData)) * prizePercent;
  1987. if(prizeAmount > 0) prizeAmt += prizeAmount;
  1988. decimal getPrizeAmount = prizeAmt;
  1989. if(set.levelDiffFlag) prizeAmt -= loopAmount;
  1990. setLogStep(sub.id, "发放金额", prizeAmt);
  1991. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p13", "接收mq数据日志");
  1992. if(prizeAmt > 0)
  1993. {
  1994. prizeAmt = Util.PublicFunction.NumberFormat(prizeAmt);
  1995. setLogPrizeAmount(sub.id, prizeAmt);
  1996. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p14", "接收mq数据日志");
  1997. var req = getRequestParams(projectId, content);
  1998. // var requestParamField = req[sub.requestParamField];
  1999. var sendFlag = false;
  2000. if(!repeatFlag) sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.prizeCode == prizeCode && m.requestParamField == content);
  2001. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p15", "接收mq数据日志");
  2002. if(!sendFlag && prizeObjectId != "0" && !string.IsNullOrEmpty(prizeObjectId))
  2003. {
  2004. PriRecord item = new PriRecord()
  2005. {
  2006. createDate = DateTime.Now,
  2007. projectId = projectId,
  2008. listId = sub.id,
  2009. prizeAmount = prizeAmt,
  2010. prizeCode = prizeCode,
  2011. prizeObjId = prizeObjectId,
  2012. requestParamField = content,
  2013. batchNo = batchNo,
  2014. };
  2015. recordService.Add(item);
  2016. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p16", "接收mq数据日志");
  2017. Dictionary<string, object> prizeItem = new Dictionary<string, object>();
  2018. prizeItem.Add("prize_date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  2019. prizeItem.Add("prize_name", sub.prizeName);
  2020. prizeItem.Add("prize_code", prizeCode);
  2021. prizeItem.Add("batch_no", batchNo);
  2022. prizeItem.Add("request_param_field", content);
  2023. List<Dictionary<string, object>> prizeItemList = new List<Dictionary<string, object>>();
  2024. Dictionary<string, object> prizeItemSub = new Dictionary<string, object>();
  2025. prizeItemSub.Add("prize_amount", prizeAmt);
  2026. prizeItemSub.Add("prize_obj", prizeObjectId);
  2027. prizeItemList.Add(prizeItemSub);
  2028. prizeItem.Add("prize_list", prizeItemList);
  2029. string prizeOutContent = Newtonsoft.Json.JsonConvert.SerializeObject(prizeItem);
  2030. setLogFieldValue(sub.id, "prizeOutContent", prizeOutContent);
  2031. setLogFieldValue(sub.id, "prizeOutUrl", project.noticeUrl);
  2032. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p17", "接收mq数据日志");
  2033. if(project.requestMode == "http" && !string.IsNullOrEmpty(project.noticeUrl))
  2034. {
  2035. int status = -1;
  2036. string noticeJson = Function.PostWebRequest(project.noticeUrl, prizeOutContent, "application/json");
  2037. Function.WriteLog(noticeJson, "通知返回报文");
  2038. JsonData jsonObj = JsonMapper.ToObject(noticeJson);
  2039. if(jsonObj["status"].ToString() == "1")
  2040. {
  2041. status = 1;
  2042. }
  2043. Function.WriteLog(status.ToString(), "通知返回报文");
  2044. var sendItem = recordService.GetFirst(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == content && m.status == 0);
  2045. if(sendItem != null)
  2046. {
  2047. Function.WriteLog("in", "通知返回报文");
  2048. sendItem.status = status;
  2049. recordService.Update(sendItem);
  2050. Function.WriteLog("end", "通知返回报文");
  2051. }
  2052. }
  2053. else if(project.requestMode == "mq")
  2054. {}
  2055. else if(project.requestMode == "db")
  2056. {
  2057. prizeToDatabase(projectId, sub.id, content, condiDic, prizeAmt, startData); //入库
  2058. }
  2059. Function.WriteLog(batchNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-p18", "接收mq数据日志");
  2060. }
  2061. else if(project.requestMode == "db")
  2062. {
  2063. prizeToDatabase(projectId, sub.id, content, condiDic, prizeAmt, startData); //入库
  2064. }
  2065. loopAmount = getPrizeAmount;
  2066. }
  2067. return prizeAmt;
  2068. }
  2069. //递归条件判断
  2070. public static List<QueryCondition> loopCondition(int projectId, PriList sub, string objId, string content)
  2071. {
  2072. List<QueryCondition> dic = new();
  2073. var queryTableService = App.GetService<IPriRecursionStartTableService>();
  2074. var queryFieldService = App.GetService<IPriRecursionStartFieldService>();
  2075. var queryReturnFieldService = App.GetService<IPriRecursionStartReturnFieldService>();
  2076. int passCount = 0;
  2077. //查询表
  2078. var queryTables = queryTableService.GetList(m => m.listId == sub.id).OrderByDescending(m => m.sort).ThenBy(m => m.id).ToList();
  2079. int allCount = queryTables.Count;
  2080. foreach(var queryTable in queryTables)
  2081. {
  2082. //查询返回字段
  2083. string fields = "1";
  2084. string tableEnName = queryTable.tableEnName;
  2085. if(tableEnName.Contains("#{")) tableEnName = MatchExpressionVal(tableEnName);
  2086. Dictionary<string, string> fieldDic = new();
  2087. var returnFields = queryReturnFieldService.GetList(m => m.objectTableId == queryTable.id);
  2088. if(returnFields.Count > 0)
  2089. {
  2090. fields = "";
  2091. foreach(var returnField in returnFields)
  2092. {
  2093. string aliasName = returnField.fieldAliasName;
  2094. if(string.IsNullOrEmpty(aliasName)) aliasName = tableEnName + "_" + returnField.fieldEnName;
  2095. if(returnField.fieldReturnKind == "2")
  2096. {
  2097. fields += "count(" + returnField.fieldEnName + ") " + aliasName + ",";
  2098. }
  2099. else if(returnField.fieldReturnKind == "3")
  2100. {
  2101. fields += "sum(" + returnField.fieldEnName + ") " + aliasName + ",";
  2102. }
  2103. else if(returnField.fieldReturnKind == "4")
  2104. {
  2105. fields += "avg(" + returnField.fieldEnName + ") " + aliasName + ",";
  2106. }
  2107. else if(returnField.fieldReturnKind == "5")
  2108. {
  2109. fields += "max(" + returnField.fieldEnName + ") " + aliasName + ",";
  2110. }
  2111. else if(returnField.fieldReturnKind == "6")
  2112. {
  2113. fields += "min(" + returnField.fieldEnName + ") " + aliasName + ",";
  2114. }
  2115. else
  2116. {
  2117. fields += returnField.fieldEnName + " " + aliasName + ",";
  2118. }
  2119. fieldDic.Add(aliasName, returnField.fieldName);
  2120. }
  2121. fields = fields.TrimEnd(',');
  2122. }
  2123. //查询匹配条件
  2124. string condi = "";
  2125. var queryFields = queryFieldService.GetList(m => m.objectTableId == queryTable.id);
  2126. foreach(var queryField in queryFields)
  2127. {
  2128. string fieldEnName = queryField.fieldEnName;
  2129. string fieldQueryKind = queryField.fieldQueryKind;
  2130. string fieldQueryModel = queryField.fieldQueryModel;
  2131. string fieldQueryValue = queryField.fieldQueryValue;
  2132. if(fieldQueryModel == "loop_field") fieldQueryValue = objId;
  2133. string fieldQueryValueType = queryField.fieldQueryValueType;
  2134. if(fieldQueryKind == "1") //模糊匹配
  2135. {
  2136. condi += " and " + fieldEnName + " like ";
  2137. if(fieldQueryModel == "request_param")
  2138. {
  2139. Dictionary<string, string> req = getRequestParams(projectId, content);
  2140. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2141. condi += "'%" + val + "%'";
  2142. }
  2143. else if(fieldQueryModel == "fixed_value")
  2144. {
  2145. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  2146. }
  2147. else if(fieldQueryModel == "query_field")
  2148. {
  2149. condi += "'%" + GetQueryTableData(dic, fieldQueryValue) + "%'";
  2150. }
  2151. else if(fieldQueryModel == "db_field")
  2152. {
  2153. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  2154. }
  2155. }
  2156. else if(fieldQueryKind == "2") //精确匹配
  2157. {
  2158. condi += " and " + fieldEnName + "=";
  2159. string val = fieldQueryValue;
  2160. if(fieldQueryModel == "request_param")
  2161. {
  2162. Dictionary<string, string> req = getRequestParams(projectId, content);
  2163. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2164. }
  2165. else if(fieldQueryModel == "fixed_value")
  2166. {
  2167. val = GetExpressionVal(fieldQueryValue);
  2168. }
  2169. else if(fieldQueryModel == "query_field")
  2170. {
  2171. val = GetQueryTableData(dic, fieldQueryValue);
  2172. }
  2173. else if(fieldQueryModel == "db_field")
  2174. {
  2175. val = GetDbExpressionVal(fieldQueryValue);
  2176. }
  2177. if(fieldQueryValueType == "text")
  2178. {
  2179. val = "'" + val + "'";
  2180. }
  2181. condi += val;
  2182. }
  2183. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  2184. {
  2185. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  2186. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  2187. string val = "";
  2188. string[] valList = fieldQueryValue.Split(',');
  2189. if(fieldQueryModel == "request_param")
  2190. {
  2191. Dictionary<string, string> req = getRequestParams(projectId, content);
  2192. foreach(string subval in valList)
  2193. {
  2194. if(fieldQueryValueType == "text")
  2195. {
  2196. val += "'" + req[subval] + "',";
  2197. }
  2198. else
  2199. {
  2200. val += req[subval] + ",";
  2201. }
  2202. }
  2203. }
  2204. else if(fieldQueryModel == "fixed_value")
  2205. {
  2206. foreach(string subval in valList)
  2207. {
  2208. if(fieldQueryValueType == "text")
  2209. {
  2210. val += "'" + GetExpressionVal(subval) + "',";
  2211. }
  2212. else
  2213. {
  2214. val += GetExpressionVal(subval) + ",";
  2215. }
  2216. }
  2217. }
  2218. else if(fieldQueryModel == "query_field")
  2219. {
  2220. foreach(string subval in valList)
  2221. {
  2222. if(fieldQueryValueType == "text")
  2223. {
  2224. val += "'" + GetQueryTableData(dic, subval) + "',";
  2225. }
  2226. else
  2227. {
  2228. val += GetQueryTableData(dic, subval) + ",";
  2229. }
  2230. }
  2231. }
  2232. else if(fieldQueryModel == "db_field")
  2233. {
  2234. foreach(string subval in valList)
  2235. {
  2236. if(fieldQueryValueType == "text")
  2237. {
  2238. val += "'" + GetDbExpressionVal(subval) + "',";
  2239. }
  2240. else
  2241. {
  2242. val += GetDbExpressionVal(subval) + ",";
  2243. }
  2244. }
  2245. }
  2246. val = val.TrimEnd(',');
  2247. condi += val + ")";
  2248. }
  2249. else if(fieldQueryKind == "3") //范围匹配
  2250. {
  2251. string[] val = fieldQueryValue.Split(':');
  2252. if(fieldQueryModel == "request_param")
  2253. {
  2254. Dictionary<string, string> req = getRequestParams(projectId, content);
  2255. if(fieldQueryValueType == "number")
  2256. {
  2257. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  2258. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  2259. }
  2260. else
  2261. {
  2262. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  2263. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  2264. }
  2265. }
  2266. else if(fieldQueryModel == "fixed_value")
  2267. {
  2268. if(fieldQueryValueType == "number")
  2269. {
  2270. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  2271. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  2272. }
  2273. else
  2274. {
  2275. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  2276. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  2277. }
  2278. }
  2279. else if(fieldQueryModel == "db_field")
  2280. {
  2281. if(fieldQueryValueType == "number")
  2282. {
  2283. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  2284. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  2285. }
  2286. else
  2287. {
  2288. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  2289. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  2290. }
  2291. }
  2292. }
  2293. else if(fieldQueryKind == "4") //取反匹配
  2294. {
  2295. condi += " and " + fieldEnName + "!=";
  2296. string val = "";
  2297. if(fieldQueryModel == "request_param")
  2298. {
  2299. Dictionary<string, string> req = getRequestParams(projectId, content);
  2300. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2301. }
  2302. else if(fieldQueryModel == "fixed_value")
  2303. {
  2304. val = GetExpressionVal(fieldQueryValue);
  2305. }
  2306. else if(fieldQueryModel == "db_field")
  2307. {
  2308. val = GetDbExpressionVal(fieldQueryValue);
  2309. }
  2310. if(fieldQueryValueType == "text")
  2311. {
  2312. val = "'" + val + "'";
  2313. }
  2314. condi += val;
  2315. }
  2316. }
  2317. var db = initDb(queryTable.databaseId);
  2318. string sql = "select " + fields + " from " + tableEnName + " where 1=1" + condi;
  2319. if(!string.IsNullOrEmpty(queryTable.orderBy))
  2320. {
  2321. sql += " order by " + queryTable.orderBy;
  2322. }
  2323. sql += " limit 1";
  2324. var items = db.Ado.GetDataTable(sql);
  2325. if(items.Rows.Count > 0)
  2326. {
  2327. foreach(string field in fieldDic.Keys)
  2328. {
  2329. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  2330. {
  2331. FieldName = fieldDic[field],
  2332. FieldEnName = field,
  2333. Value = items.Rows[0][field].ToString()
  2334. });
  2335. }
  2336. }
  2337. }
  2338. return dic;
  2339. }
  2340. //奖励入库
  2341. public static void prizeToDatabase(int projectId, int listId, string content, List<QueryCondition> condiDic, decimal prize_amt, Dictionary<string, string> startData)
  2342. {
  2343. var prizeInTableService = App.GetService<IPriPrizeInTableService>();
  2344. var prizeInFieldService = App.GetService<IPriPrizeInFieldService>();
  2345. var prizeInQueryFieldService = App.GetService<IPriPrizeInQueryFieldService>();
  2346. //入库表
  2347. var prizeInTables = prizeInTableService.GetList(m => m.listId == listId);
  2348. foreach(var prizeInTable in prizeInTables)
  2349. {
  2350. var db = initDb(prizeInTable.databaseId);
  2351. Dictionary<string, object> doFields = new();
  2352. List<string> inFields = new();
  2353. //入库字段
  2354. var prizeInFields = prizeInFieldService.GetList(m => m.inTableId == prizeInTable.id);
  2355. foreach(var prizeInField in prizeInFields)
  2356. {
  2357. string fieldEnName = prizeInField.fieldEnName;
  2358. string fieldQueryModel = prizeInField.fieldQueryModel;
  2359. string fieldQueryValue = prizeInField.fieldQueryValue;
  2360. fieldQueryValue = fieldQueryValue.Replace("${prize_amt}", prize_amt.ToString());
  2361. fieldQueryValue = GetDbExpressionVal(fieldQueryValue, projectId, content, condiDic, startData);
  2362. fieldQueryValue = MatchExpressionVal(fieldQueryValue);
  2363. string fieldQueryValueType = prizeInField.fieldQueryValueType;
  2364. if(fieldQueryModel == "request_param")
  2365. {
  2366. Dictionary<string, string> req = getRequestParams(projectId, content);
  2367. fieldQueryValue = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2368. }
  2369. else if(fieldQueryModel == "query_field")
  2370. {
  2371. if (fieldQueryValue.Contains("+") || fieldQueryValue.Contains("-") || fieldQueryValue.Contains("*") || fieldQueryValue.Contains("/") || fieldQueryValue.Contains("(") || fieldQueryValue.Contains(")"))
  2372. {
  2373. string[] texts = fieldQueryValue.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  2374. foreach (string text in texts)
  2375. {
  2376. string val = GetStartData(startData, text);
  2377. if(string.IsNullOrEmpty(val)) val = GetQueryTableData(condiDic, text);
  2378. fieldQueryValue = fieldQueryValue.Replace(text, val);
  2379. }
  2380. DataTable dt = new();
  2381. fieldQueryValue = dt.Compute(fieldQueryValue, "false").ToString();
  2382. }
  2383. else
  2384. {
  2385. fieldQueryValue = GetQueryTableData(condiDic, fieldQueryValue);
  2386. }
  2387. }
  2388. else if(fieldQueryModel == "querystart_list_field")
  2389. {
  2390. fieldQueryValue = GetStartData(startData, fieldQueryValue);
  2391. }
  2392. else if(fieldQueryModel == "query_all_field")
  2393. {
  2394. if (fieldQueryValue.Contains("+") || fieldQueryValue.Contains("-") || fieldQueryValue.Contains("*") || fieldQueryValue.Contains("/") || fieldQueryValue.Contains("(") || fieldQueryValue.Contains(")"))
  2395. {
  2396. string[] texts = fieldQueryValue.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  2397. foreach (string text in texts)
  2398. {
  2399. string val = GetStartData(startData, text);
  2400. if(string.IsNullOrEmpty(val)) val = GetQueryTableData(condiDic, text);
  2401. fieldQueryValue = fieldQueryValue.Replace(text, val);
  2402. }
  2403. DataTable dt = new();
  2404. fieldQueryValue = dt.Compute(fieldQueryValue, "false").ToString();
  2405. }
  2406. else
  2407. {
  2408. string val = GetStartData(startData, fieldQueryValue);
  2409. if(string.IsNullOrEmpty(val)) val = GetQueryTableData(condiDic, fieldQueryValue);
  2410. fieldQueryValue = val;
  2411. }
  2412. }
  2413. else if(fieldQueryModel == "fixed_value")
  2414. {
  2415. fieldQueryValue = GetExpressionVal(fieldQueryValue);
  2416. }
  2417. else if(fieldQueryModel == "db_field")
  2418. {
  2419. fieldQueryValue = GetDbExpressionVal(fieldQueryValue);
  2420. }
  2421. else if(fieldQueryModel == "prize_amt")
  2422. {
  2423. if (fieldQueryValue.Contains("+") || fieldQueryValue.Contains("-") || fieldQueryValue.Contains("*") || fieldQueryValue.Contains("/") || fieldQueryValue.Contains("(") || fieldQueryValue.Contains(")"))
  2424. {
  2425. fieldQueryValue = fieldQueryValue.Replace("${prize_amt}", prize_amt.ToString());
  2426. if(fieldQueryValue.Contains("${"))
  2427. {
  2428. string[] texts = fieldQueryValue.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  2429. foreach (string text in texts)
  2430. {
  2431. string val = GetStartData(startData, text);
  2432. if(string.IsNullOrEmpty(val)) val = GetQueryTableData(condiDic, text);
  2433. fieldQueryValue = fieldQueryValue.Replace(text, val);
  2434. }
  2435. }
  2436. DataTable dt = new();
  2437. fieldQueryValue = dt.Compute(fieldQueryValue, "false").ToString();
  2438. }
  2439. else
  2440. {
  2441. fieldQueryValue = prize_amt.ToString();
  2442. }
  2443. }
  2444. if(fieldQueryValueType == "text") doFields.Add(fieldEnName, fieldQueryValue);
  2445. if(fieldQueryValueType == "int") doFields.Add(fieldEnName, int.Parse(Function.CheckInt(fieldQueryValue)));
  2446. if(fieldQueryValueType == "number") doFields.Add(fieldEnName, decimal.Parse(Function.CheckNum(fieldQueryValue)));
  2447. if(fieldQueryValueType == "datetime") doFields.Add(fieldEnName, DateTime.Parse(fieldQueryValue));
  2448. if(fieldQueryValueType == "bool") doFields.Add(fieldEnName, bool.Parse(fieldQueryValue));
  2449. inFields.Add(fieldEnName + "#cut#" + fieldQueryValue + "#cut#" + fieldQueryValueType + "#cut#" + prizeInField.fieldInModel);
  2450. }
  2451. //查询匹配条件
  2452. string condi = "";
  2453. var queryFields = prizeInQueryFieldService.GetList(m => m.inTableId == prizeInTable.id);
  2454. foreach(var queryField in queryFields)
  2455. {
  2456. string fieldEnName = queryField.fieldEnName;
  2457. string fieldQueryKind = queryField.fieldQueryKind;
  2458. string fieldQueryModel = queryField.fieldQueryModel;
  2459. string fieldQueryValue = queryField.fieldQueryValue;
  2460. string fieldQueryValueType = queryField.fieldQueryValueType;
  2461. if(fieldQueryKind == "1") //模糊匹配
  2462. {
  2463. condi += " and " + fieldEnName + " like ";
  2464. if(fieldQueryModel == "request_param")
  2465. {
  2466. Dictionary<string, string> req = getRequestParams(projectId, content);
  2467. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2468. condi += "'%" + val + "%'";
  2469. }
  2470. else if(fieldQueryModel == "fixed_value")
  2471. {
  2472. condi += "'%" + fieldQueryValue + "%'";
  2473. }
  2474. else if(fieldQueryModel == "query_field")
  2475. {
  2476. condi += "'%" + GetQueryTableData(condiDic, fieldQueryValue) + "%'";
  2477. }
  2478. else if(fieldQueryModel == "querystart_list_field")
  2479. {
  2480. condi += "'%" + GetStartData(startData, fieldQueryValue) + "%'";
  2481. }
  2482. }
  2483. else if(fieldQueryKind == "2") //精确匹配
  2484. {
  2485. condi += " and " + fieldEnName + "=";
  2486. string val = "";
  2487. if(fieldQueryModel == "request_param")
  2488. {
  2489. Dictionary<string, string> req = getRequestParams(projectId, content);
  2490. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2491. }
  2492. else if(fieldQueryModel == "fixed_value")
  2493. {
  2494. val = fieldQueryValue;
  2495. }
  2496. else if(fieldQueryModel == "query_field")
  2497. {
  2498. val = GetQueryTableData(condiDic, fieldQueryValue);
  2499. }
  2500. else if(fieldQueryModel == "querystart_list_field")
  2501. {
  2502. val = GetStartData(startData, fieldQueryValue);
  2503. }
  2504. if(fieldQueryValueType == "text")
  2505. {
  2506. val = "'" + val + "'";
  2507. }
  2508. condi += val;
  2509. }
  2510. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  2511. {
  2512. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  2513. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  2514. string val = "";
  2515. string[] valList = fieldQueryValue.Split(',');
  2516. if(fieldQueryModel == "request_param")
  2517. {
  2518. Dictionary<string, string> req = getRequestParams(projectId, content);
  2519. foreach(string sub in valList)
  2520. {
  2521. if(fieldQueryValueType == "text")
  2522. {
  2523. val += "'" + req[sub] + "',";
  2524. }
  2525. else
  2526. {
  2527. val += req[sub] + ",";
  2528. }
  2529. }
  2530. }
  2531. else if(fieldQueryModel == "fixed_value")
  2532. {
  2533. foreach(string sub in valList)
  2534. {
  2535. if(fieldQueryValueType == "text")
  2536. {
  2537. val += "'" + GetExpressionVal(sub) + "',";
  2538. }
  2539. else
  2540. {
  2541. val += GetExpressionVal(sub) + ",";
  2542. }
  2543. }
  2544. }
  2545. else if(fieldQueryModel == "query_field")
  2546. {
  2547. foreach(string sub in valList)
  2548. {
  2549. if(fieldQueryValueType == "text")
  2550. {
  2551. val += "'" + GetQueryTableData(condiDic, sub) + "',";
  2552. }
  2553. else
  2554. {
  2555. val += GetQueryTableData(condiDic, sub) + ",";
  2556. }
  2557. }
  2558. }
  2559. else if(fieldQueryModel == "querystart_list_field")
  2560. {
  2561. foreach(string sub in valList)
  2562. {
  2563. if(fieldQueryValueType == "text")
  2564. {
  2565. val += "'" + GetStartData(startData, sub) + "',";
  2566. }
  2567. else
  2568. {
  2569. val += GetStartData(startData, sub) + ",";
  2570. }
  2571. }
  2572. }
  2573. else if(fieldQueryModel == "db_field")
  2574. {
  2575. foreach(string sub in valList)
  2576. {
  2577. if(fieldQueryValueType == "text")
  2578. {
  2579. val += "'" + GetDbExpressionVal(sub) + "',";
  2580. }
  2581. else
  2582. {
  2583. val += GetDbExpressionVal(sub) + ",";
  2584. }
  2585. }
  2586. }
  2587. val = val.TrimEnd(',');
  2588. condi += val + ")";
  2589. }
  2590. else if(fieldQueryKind == "3") //范围匹配
  2591. {
  2592. string[] val = fieldQueryValue.Split(':');
  2593. if(fieldQueryModel == "request_param")
  2594. {
  2595. Dictionary<string, string> req = getRequestParams(projectId, content);
  2596. if(fieldQueryValueType == "number")
  2597. {
  2598. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  2599. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  2600. }
  2601. else
  2602. {
  2603. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  2604. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  2605. }
  2606. }
  2607. else if(fieldQueryModel == "fixed_value")
  2608. {
  2609. if(fieldQueryValueType == "number")
  2610. {
  2611. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  2612. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  2613. }
  2614. else
  2615. {
  2616. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + val[0] + "'";
  2617. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + val[1] + "'";
  2618. }
  2619. }
  2620. }
  2621. else if(fieldQueryKind == "4") //取反匹配
  2622. {
  2623. condi += " and " + fieldEnName + "!=";
  2624. string val = "";
  2625. if(fieldQueryModel == "request_param")
  2626. {
  2627. Dictionary<string, string> req = getRequestParams(projectId, content);
  2628. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2629. }
  2630. else if(fieldQueryModel == "fixed_value")
  2631. {
  2632. val = fieldQueryValue;
  2633. }
  2634. if(fieldQueryValueType == "text")
  2635. {
  2636. val = "'" + val + "'";
  2637. }
  2638. condi += val;
  2639. }
  2640. }
  2641. if(prizeInTable.excuteKind == "add") db.Insertable(doFields).AS(prizeInTable.tableEnName).ExecuteCommand();
  2642. if(prizeInTable.excuteKind == "update") db.Updateable(doFields).AS(prizeInTable.tableEnName).Where("1=1" + condi).ExecuteCommand();
  2643. if(prizeInTable.excuteKind == "update_or_add")
  2644. {
  2645. string doSql = "";
  2646. var check = db.Ado.GetDataTable("select 1 from " + prizeInTable.tableEnName + " where 1=1" + condi);
  2647. if(check.Rows.Count > 0)
  2648. {
  2649. string fieldString = "";
  2650. foreach(var inField in inFields)
  2651. {
  2652. string[] inFieldData = inField.Split(new string[]{ "#cut#" }, StringSplitOptions.None);
  2653. string fieldEnName = inFieldData[0];
  2654. string fieldQueryValue = inFieldData[1];
  2655. string fieldQueryValueType = inFieldData[2];
  2656. string fieldInModel = inFieldData[3];
  2657. if(fieldQueryValueType == "int" || fieldQueryValueType == "number" || fieldQueryValueType == "bool")
  2658. {
  2659. if(fieldInModel == "add")
  2660. {
  2661. fieldString += fieldEnName + "=" + fieldEnName + "+" + fieldQueryValue;
  2662. }
  2663. else
  2664. {
  2665. fieldString += fieldEnName + "=" + fieldQueryValue;
  2666. }
  2667. }
  2668. else
  2669. {
  2670. if(fieldInModel == "add")
  2671. {
  2672. fieldString += fieldEnName + "=" + "concat(" + fieldEnName + ", '" + fieldQueryValue + "')";
  2673. }
  2674. else
  2675. {
  2676. fieldString += fieldEnName + "=" + "'" + fieldQueryValue + "'";
  2677. }
  2678. }
  2679. fieldString += ",";
  2680. }
  2681. if(!string.IsNullOrEmpty(fieldString))
  2682. {
  2683. fieldString = fieldString.TrimEnd(',');
  2684. }
  2685. doSql = "update " + prizeInTable.tableEnName + " set " + fieldString + " where 1=1" + condi;
  2686. }
  2687. else
  2688. {
  2689. string fieldString = "";
  2690. string valString = "";
  2691. foreach(var fieldEnName in doFields.Keys)
  2692. {
  2693. fieldString += fieldEnName;
  2694. if(typeof(int) == doFields[fieldEnName].GetType() || typeof(decimal) == doFields[fieldEnName].GetType())
  2695. {
  2696. valString += doFields[fieldEnName].ToString();
  2697. }
  2698. else
  2699. {
  2700. valString += "'" + doFields[fieldEnName].ToString() + "'";
  2701. }
  2702. fieldString += ",";
  2703. valString += ",";
  2704. }
  2705. if(!string.IsNullOrEmpty(fieldString))
  2706. {
  2707. fieldString = fieldString.TrimEnd(',');
  2708. valString = valString.TrimEnd(',');
  2709. }
  2710. doSql = "insert into " + prizeInTable.tableEnName + " (" + fieldString + ") values (" + valString + ")";
  2711. }
  2712. db.Ado.ExecuteCommand(doSql);
  2713. }
  2714. Function.WriteLog(DateTime.Now.ToString() + "\n" + prizeInTable.excuteKind + "\n" + prizeInTable.tableEnName + "\n" + Newtonsoft.Json.JsonConvert.SerializeObject(doFields) + "\n" + condi + "\n\n", "奖励入库数据");
  2715. }
  2716. }
  2717. //固定值表达式
  2718. public static string GetExpressionVal(string str)
  2719. {
  2720. if(str == "#{now}#") return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2721. if(str == "#{today}#") return DateTime.Now.ToString("yyyy-MM-dd");
  2722. if(str == "#{this_month}#") return DateTime.Now.ToString("yyyy-MM");
  2723. 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");
  2724. 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");
  2725. if(str.StartsWith("#{today") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  2726. if(str.StartsWith("#{today") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  2727. if(str.StartsWith("#{this_month") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  2728. if(str.StartsWith("#{this_month") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  2729. 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");
  2730. 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");
  2731. if(str.StartsWith("#{split") && str.EndsWith("}#"))
  2732. {
  2733. string[] data = str.Replace("#{", "").Replace("}#", "").Split(',');
  2734. string text = data[1];
  2735. string splitTag = data[2];
  2736. string index = data[3];
  2737. return text.Split(new string[]{ splitTag }, StringSplitOptions.None)[int.Parse(index)];
  2738. }
  2739. else if(str.StartsWith("#{") && str.EndsWith("}#"))
  2740. {
  2741. string[] data = str.Replace("#{", "").Replace("}#", "").Split(',');
  2742. string tag = data[0];
  2743. string format = data[data.Length - 1];
  2744. if(tag == "now" && format.StartsWith("yyyy"))
  2745. {
  2746. if(data.Length == 2)
  2747. {
  2748. return DateTime.Now.ToString(format);
  2749. }
  2750. else if(data.Length == 4)
  2751. {
  2752. if(data[2] == "DAY") return DateTime.Now.AddDays(int.Parse(data[1])).ToString(format);
  2753. if(data[2] == "MONTH") return DateTime.Now.AddMonths(int.Parse(data[1])).ToString(format);
  2754. }
  2755. }
  2756. }
  2757. return str;
  2758. }
  2759. public static string MatchExpressionVal(string str)
  2760. {
  2761. MatchCollection mc = Regex.Matches(str, "#\\{.*?\\}#");
  2762. foreach(Match m in mc)
  2763. {
  2764. str = str.Replace(m.Value, GetExpressionVal(m.Value));
  2765. }
  2766. return str;
  2767. }
  2768. //库内字段值表达式
  2769. public static string GetDbExpressionVal(string str)
  2770. {
  2771. string[] data = str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',');
  2772. if(str.StartsWith("#{") && str.EndsWith("DAY}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " DAY)";
  2773. if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " MONTH)";
  2774. return str;
  2775. }
  2776. public static string GetDbExpressionVal(string str, int projectId, string content, List<QueryCondition> dic, Dictionary<string, string> startData)
  2777. {
  2778. MatchCollection mc = Regex.Matches(str, "\\$\\{.*?\\}");
  2779. foreach(Match m in mc)
  2780. {
  2781. string matchValue = m.Value.Replace("${", "").Replace("}", "");
  2782. string val = "";
  2783. if(string.IsNullOrEmpty(val) || val == matchValue) val = getRequestParams(projectId, content, matchValue);
  2784. if(string.IsNullOrEmpty(val) || val == matchValue) val = GetQueryTableData(dic, matchValue);
  2785. if(string.IsNullOrEmpty(val) || val == matchValue) val = GetStartData(startData, matchValue);
  2786. str = str.Replace(m.Value, val);
  2787. }
  2788. return str;
  2789. }
  2790. //四则混合运算
  2791. public static string GetComputeVal(List<QueryCondition> condiDic, string expresssion)
  2792. {
  2793. if (expresssion.Contains("+") || expresssion.Contains("-") || expresssion.Contains("*") || expresssion.Contains("/") || expresssion.Contains("(") || expresssion.Contains(")"))
  2794. {
  2795. string[] returnFields = expresssion.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  2796. foreach (string returnField in returnFields)
  2797. {
  2798. if(condiDic.Any(m => m.FieldEnName == returnField))
  2799. {
  2800. string val = GetQueryTableData(condiDic, returnField);
  2801. expresssion = expresssion.Replace(returnField, val);
  2802. }
  2803. }
  2804. DataTable dt = new();
  2805. return dt.Compute(expresssion, "false").ToString();
  2806. }
  2807. return expresssion;
  2808. }
  2809. //获取查询条件数据
  2810. public static string GetQueryTableData(List<QueryCondition> condiDic, string key)
  2811. {
  2812. if(key.Contains("#{"))
  2813. {
  2814. Match m = Regex.Match(key, "\\$\\{.*?\\}\\$");
  2815. if(m.Success)
  2816. {
  2817. string keyString = m.Value.Replace("${", "").Replace("}$", "");
  2818. string val = condiDic.Any(m => m.FieldEnName == keyString) ? condiDic.FirstOrDefault(m => m.FieldEnName == keyString).Value.ToString() : key;
  2819. key = key.Replace(m.Value, val);
  2820. key = GetExpressionVal(key);
  2821. return key;
  2822. }
  2823. }
  2824. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).Value.ToString() : key;
  2825. }
  2826. public static string GetQueryTableTitle(List<QueryCondition> condiDic, string key)
  2827. {
  2828. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).FieldName : "";
  2829. }
  2830. public static string GetStartData(Dictionary<string, string> startData, string key)
  2831. {
  2832. return startData.ContainsKey(key) ? startData[key] : key;
  2833. }
  2834. //合并字典
  2835. public static void MergeCondiDic(List<QueryCondition> condiDic, List<QueryCondition> condiDic1)
  2836. {
  2837. foreach(QueryCondition sub in condiDic1)
  2838. {
  2839. condiDic.Add(sub);
  2840. }
  2841. }
  2842. //记录日志
  2843. public static void addLog(int projectId, int listId, int prizeIn, string requestParam, string prizeInUrl, string content = "")
  2844. {
  2845. if(!logFlag) return;
  2846. var logService = App.GetService<IPriLogService>();
  2847. logService.Add(new PriLog()
  2848. {
  2849. createDate = DateTime.Now,
  2850. projectId = projectId,
  2851. listId = listId,
  2852. batchNo = batchNo,
  2853. prizeIn = prizeIn,
  2854. requestParam = requestParam,
  2855. prizeInUrl = prizeInUrl,
  2856. stepListIndex = getRequestParamsIndex(projectId, content), //获取参数索引字段值
  2857. });
  2858. }
  2859. public static void setLogPrizeAmount(int listId, decimal prizeAmount)
  2860. {
  2861. if(!logFlag) return;
  2862. var logService = App.GetService<IPriLogService>();
  2863. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2864. if(log != null)
  2865. {
  2866. log.prizeAmount = prizeAmount;
  2867. logService.Update(log);
  2868. }
  2869. }
  2870. public static void setLogStep(int listId, Dictionary<string, object> step)
  2871. {
  2872. if(!logFlag) return;
  2873. var logService = App.GetService<IPriLogService>();
  2874. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2875. if(log != null)
  2876. {
  2877. log.stepList += Newtonsoft.Json.JsonConvert.SerializeObject(step) + ",";
  2878. logService.Update(log);
  2879. }
  2880. }
  2881. public static void setLogStep(int listId, string key, object val)
  2882. {
  2883. if(!logFlag) return;
  2884. var logService = App.GetService<IPriLogService>();
  2885. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2886. if(log != null)
  2887. {
  2888. log.stepList += "\"" + key + "\":" + Newtonsoft.Json.JsonConvert.SerializeObject(val) + ",";
  2889. logService.Update(log);
  2890. }
  2891. }
  2892. public static void setLogStatus(int listId, int status)
  2893. {
  2894. if(!logFlag) return;
  2895. var logService = App.GetService<IPriLogService>();
  2896. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2897. if(log != null)
  2898. {
  2899. log.status = status;
  2900. logService.Update(log);
  2901. }
  2902. }
  2903. public static void setLogFieldValue(int listId, string field, string content)
  2904. {
  2905. if(!logFlag) return;
  2906. var logService = App.GetService<IPriLogService>();
  2907. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2908. if(log != null)
  2909. {
  2910. if(field == "errLog") log.errLog = content;
  2911. if(field == "prizeOutContent") log.prizeOutContent = content;
  2912. if(field == "prizeOutUrl") log.prizeOutUrl = content;
  2913. if(field == "stepListIndex") log.stepListIndex = content;
  2914. logService.Update(log);
  2915. }
  2916. }
  2917. public static string getQueryKind(string kind)
  2918. {
  2919. if(kind == "1") return "模糊匹配";
  2920. if(kind == "2") return "精确匹配";
  2921. if(kind == "4") return "取反匹配";
  2922. if(kind == "5") return "数组匹配";
  2923. if(kind == "6") return "数组排除";
  2924. if(kind == "3") return "范围匹配";
  2925. return kind;
  2926. }
  2927. public static string getQueryModel(string model)
  2928. {
  2929. if(model == "request_param") return "入参";
  2930. if(model == "query_field") return "条件匹配返回字段";
  2931. if(model == "loop_field") return "循环递归字段";
  2932. if(model == "loop_condition_field") return "循环递归条件字段";
  2933. if(model == "fixed_value") return "固定值";
  2934. if(model == "db_field") return "库内字段";
  2935. return model;
  2936. }
  2937. //检查时间格式,否则返回默认时间
  2938. public static string checkDateTime(string date)
  2939. {
  2940. DateTime s = DateTime.Now;
  2941. if(DateTime.TryParse(date, out s))
  2942. {
  2943. return date;
  2944. }
  2945. return "1900-01-01";
  2946. }
  2947. }
  2948. }