PrizeDo.cs 138 KB

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