PrizeDo.cs 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  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. //发奖入口
  19. public static void sendPrize(string queueName, string content)
  20. {
  21. batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(3);
  22. publicStep = "";
  23. string priObjString = prizeInSet(queueName);
  24. if(!string.IsNullOrEmpty(priObjString))
  25. {
  26. string[] priObjData = priObjString.Split('|');
  27. string priListIds = priObjData[0];
  28. int projectId = int.Parse(priObjData[1]);
  29. int prizeInId = int.Parse(priObjData[2]);
  30. prizeSend(projectId, prizeInId, priListIds, content);
  31. }
  32. }
  33. //接收入参
  34. public static Dictionary<string, string> getRequestParams(int projectId, string content)
  35. {
  36. Dictionary<string, string> dic = new();
  37. JsonData jsonData = JsonMapper.ToObject(content);
  38. var paramService = App.GetService<IPriProjectParamService>();
  39. var paramList = paramService.GetList(m => m.projectId == projectId);
  40. foreach(var param in paramList)
  41. {
  42. if(content.Contains("\"" + param.fieldEnName + "\"")) dic.Add(param.fieldEnName, jsonData[param.fieldEnName].ToString());
  43. }
  44. return dic;
  45. }
  46. //数据库链接
  47. public static SqlSugarClient initDb(int id)
  48. {
  49. var databaseSetService = App.GetService<IPriDatabaseSetService>();
  50. var connectionString = databaseSetService.GetFirst(m => m.id == id);
  51. string server = connectionString.ipAddress;
  52. int port = connectionString.port;
  53. string user = connectionString.userId;
  54. string password = connectionString.password;
  55. string database = connectionString.databaseName;
  56. var db = new SqlSugarClient(new ConnectionConfig()
  57. {
  58. ConnectionString = "server=" + server + ";port=" + port + ";user=" + user + ";password=" + password + ";database=" + database + ";charset=utf8;",
  59. DbType = SqlSugar.DbType.MySql,
  60. IsAutoCloseConnection = true,
  61. });
  62. return db;
  63. }
  64. //查询条件匹配数据
  65. public static List<QueryCondition> condition(int projectId, List<int> ids, string content)
  66. {
  67. List<QueryCondition> dic = new();
  68. var queryTableService = App.GetService<IPriQueryTableService>();
  69. var queryFieldService = App.GetService<IPriQueryFieldService>();
  70. var returnFieldService = App.GetService<IPriReturnFieldService>();
  71. //查询表
  72. var queryTables = queryTableService.GetList(m => ids.Contains(m.id));
  73. foreach(var queryTable in queryTables)
  74. {
  75. //查询返回字段
  76. string fields = "";
  77. Dictionary<string, string> fieldDic = new();
  78. var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id);
  79. foreach(var returnField in returnFields)
  80. {
  81. if(returnField.fieldReturnKind == "2")
  82. {
  83. fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  84. }
  85. else if(returnField.fieldReturnKind == "3")
  86. {
  87. fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  88. }
  89. else if(returnField.fieldReturnKind == "4")
  90. {
  91. fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  92. }
  93. else
  94. {
  95. fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  96. }
  97. fieldDic.Add(queryTable.tableEnName + "_" + returnField.fieldEnName, returnField.fieldName);
  98. }
  99. fields = fields.TrimEnd(',');
  100. //查询匹配条件
  101. string condi = "";
  102. var queryFields = queryFieldService.GetList(m => m.queryTableId == queryTable.id);
  103. foreach(var queryField in queryFields)
  104. {
  105. string fieldEnName = queryField.fieldEnName;
  106. string fieldQueryKind = queryField.fieldQueryKind;
  107. string fieldQueryModel = queryField.fieldQueryModel;
  108. string fieldQueryValue = queryField.fieldQueryValue;
  109. string fieldQueryValueType = queryField.fieldQueryValueType;
  110. if(fieldQueryKind == "1") //模糊匹配
  111. {
  112. condi += " and " + fieldEnName + " like ";
  113. if(fieldQueryModel == "request_param")
  114. {
  115. Dictionary<string, string> req = getRequestParams(projectId, content);
  116. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  117. condi += "'%" + val + "%'";
  118. }
  119. else if(fieldQueryModel == "fixed_value")
  120. {
  121. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  122. }
  123. else if(fieldQueryModel == "db_field")
  124. {
  125. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  126. }
  127. else if(fieldQueryModel == "query_field")
  128. {
  129. string val = GetQueryTableData(dic, fieldQueryValue);
  130. condi += "'%" + val + "%'";
  131. }
  132. }
  133. else if(fieldQueryKind == "2") //精确匹配
  134. {
  135. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is null";
  136. else
  137. {
  138. condi += " and " + fieldEnName + "=";
  139. string val = "";
  140. if(fieldQueryModel == "request_param")
  141. {
  142. Dictionary<string, string> req = getRequestParams(projectId, content);
  143. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  144. }
  145. else if(fieldQueryModel == "fixed_value")
  146. {
  147. val = GetExpressionVal(fieldQueryValue);
  148. }
  149. else if(fieldQueryModel == "db_field")
  150. {
  151. val = GetDbExpressionVal(fieldQueryValue);
  152. }
  153. else if(fieldQueryModel == "query_field")
  154. {
  155. val = GetQueryTableData(dic, fieldQueryValue);
  156. }
  157. if(fieldQueryValueType == "text")
  158. {
  159. val = "'" + val + "'";
  160. }
  161. condi += val;
  162. }
  163. }
  164. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  165. {
  166. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  167. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  168. string val = "";
  169. string[] valList = fieldQueryValue.Split(',');
  170. if(fieldQueryModel == "request_param")
  171. {
  172. Dictionary<string, string> req = getRequestParams(projectId, content);
  173. foreach(string sub in valList)
  174. {
  175. if(fieldQueryValueType == "text")
  176. {
  177. val += "'" + req[sub] + "',";
  178. }
  179. else
  180. {
  181. val += req[sub] + ",";
  182. }
  183. }
  184. }
  185. else if(fieldQueryModel == "fixed_value")
  186. {
  187. foreach(string sub in valList)
  188. {
  189. if(fieldQueryValueType == "text")
  190. {
  191. val += "'" + GetExpressionVal(sub) + "',";
  192. }
  193. else
  194. {
  195. val += GetExpressionVal(sub) + ",";
  196. }
  197. }
  198. }
  199. else if(fieldQueryModel == "db_field")
  200. {
  201. foreach(string sub in valList)
  202. {
  203. if(fieldQueryValueType == "text")
  204. {
  205. val += "'" + GetDbExpressionVal(sub) + "',";
  206. }
  207. else
  208. {
  209. val += GetDbExpressionVal(sub) + ",";
  210. }
  211. }
  212. }
  213. else if(fieldQueryModel == "query_field")
  214. {
  215. foreach(string sub in valList)
  216. {
  217. string dicVal = GetQueryTableData(dic, sub);
  218. if(fieldQueryValueType == "text")
  219. {
  220. val += "'" + dicVal + "',";
  221. }
  222. else
  223. {
  224. val += dicVal + ",";
  225. }
  226. }
  227. }
  228. val = val.TrimEnd(',');
  229. condi += val + ")";
  230. }
  231. else if(fieldQueryKind == "3") //范围匹配
  232. {
  233. string[] val = fieldQueryValue.Split(':');
  234. if(fieldQueryModel == "request_param")
  235. {
  236. Dictionary<string, string> req = getRequestParams(projectId, content);
  237. if(fieldQueryValueType == "number")
  238. {
  239. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  240. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  241. }
  242. else
  243. {
  244. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  245. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  246. }
  247. }
  248. else if(fieldQueryModel == "fixed_value")
  249. {
  250. if(fieldQueryValueType == "number")
  251. {
  252. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  253. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  254. }
  255. else
  256. {
  257. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  258. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  259. }
  260. }
  261. else if(fieldQueryModel == "db_field")
  262. {
  263. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + GetDbExpressionVal(val[0]);
  264. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + GetDbExpressionVal(val[1]);
  265. }
  266. else if(fieldQueryModel == "query_field")
  267. {
  268. string valLeft = val[0];
  269. string valRight = val[1];
  270. string dicValLeft = GetQueryTableData(dic, valLeft);
  271. string dicValRight = GetQueryTableData(dic, valRight);
  272. if(fieldQueryValueType == "number")
  273. {
  274. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft;
  275. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight;
  276. }
  277. else
  278. {
  279. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'";
  280. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'";
  281. }
  282. }
  283. }
  284. else if(fieldQueryKind == "4") //取反匹配
  285. {
  286. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is not null";
  287. else
  288. {
  289. condi += " and " + fieldEnName + "!=";
  290. string val = "";
  291. if(fieldQueryModel == "request_param")
  292. {
  293. Dictionary<string, string> req = getRequestParams(projectId, content);
  294. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  295. }
  296. else if(fieldQueryModel == "fixed_value")
  297. {
  298. val = GetExpressionVal(fieldQueryValue);
  299. }
  300. else if(fieldQueryModel == "db_field")
  301. {
  302. val = GetDbExpressionVal(fieldQueryValue);
  303. }
  304. else if(fieldQueryModel == "query_field")
  305. {
  306. val = GetQueryTableData(dic, fieldQueryValue);
  307. }
  308. if(fieldQueryValueType == "text")
  309. {
  310. val = "'" + val + "'";
  311. }
  312. condi += val;
  313. }
  314. }
  315. }
  316. var db = initDb(queryTable.databaseId);
  317. string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
  318. var items = db.Ado.GetDataTable(sql);
  319. if(items.Rows.Count > 0)
  320. {
  321. foreach(string field in fieldDic.Keys)
  322. {
  323. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  324. {
  325. FieldName = fieldDic[field],
  326. FieldEnName = field,
  327. Value = items.Rows[0][field].ToString()
  328. });
  329. }
  330. }
  331. }
  332. return dic;
  333. }
  334. //奖励发放对象
  335. public static string prizeObject(int prizeObjectTag, string content)
  336. {
  337. Dictionary<string, object> dic = new();
  338. var prizeObjectTableService = App.GetService<IPriPrizeObjectTableService>();
  339. var prizeObjectFieldService = App.GetService<IPriPrizeObjectFieldService>();
  340. //查询表
  341. var prizeObjectTable = prizeObjectTableService.GetFirst(m => m.id == prizeObjectTag) ?? new PriPrizeObjectTable();
  342. //查询返回字段
  343. string field = prizeObjectTable.selectField;
  344. int projectId = prizeObjectTable.projectId;
  345. //查询匹配条件
  346. string condi = "";
  347. var queryFields = prizeObjectFieldService.GetList(m => m.objectTableId == prizeObjectTable.id);
  348. foreach(var queryField in queryFields)
  349. {
  350. string fieldEnName = queryField.fieldEnName;
  351. string fieldQueryKind = queryField.fieldQueryKind;
  352. string fieldQueryModel = queryField.fieldQueryModel;
  353. string fieldQueryValue = queryField.fieldQueryValue;
  354. string fieldQueryValueType = queryField.fieldQueryValueType;
  355. if(fieldQueryKind == "1") //模糊匹配
  356. {
  357. condi += " and " + fieldEnName + " like ";
  358. if(fieldQueryModel == "request_param")
  359. {
  360. Dictionary<string, string> req = getRequestParams(projectId, content);
  361. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  362. condi += "'%" + val + "%'";
  363. }
  364. else if(fieldQueryModel == "fixed_value")
  365. {
  366. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  367. }
  368. else if(fieldQueryModel == "db_field")
  369. {
  370. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  371. }
  372. }
  373. else if(fieldQueryKind == "2") //精确匹配
  374. {
  375. condi += " and " + fieldEnName + "=";
  376. string val = "";
  377. if(fieldQueryModel == "request_param")
  378. {
  379. Dictionary<string, string> req = getRequestParams(projectId, content);
  380. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  381. }
  382. else if(fieldQueryModel == "fixed_value")
  383. {
  384. val = GetExpressionVal(fieldQueryValue);
  385. }
  386. else if(fieldQueryModel == "db_field")
  387. {
  388. val = GetDbExpressionVal(fieldQueryValue);
  389. }
  390. if(fieldQueryValueType == "text")
  391. {
  392. val = "'" + val + "'";
  393. }
  394. condi += val;
  395. }
  396. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  397. {
  398. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  399. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  400. string val = "";
  401. string[] valList = fieldQueryValue.Split(',');
  402. if(fieldQueryModel == "request_param")
  403. {
  404. Dictionary<string, string> req = getRequestParams(projectId, content);
  405. foreach(string sub in valList)
  406. {
  407. if(fieldQueryValueType == "text")
  408. {
  409. val += "'" + req[sub] + "',";
  410. }
  411. else
  412. {
  413. val += req[sub] + ",";
  414. }
  415. }
  416. }
  417. else if(fieldQueryModel == "fixed_value")
  418. {
  419. foreach(string sub in valList)
  420. {
  421. if(fieldQueryValueType == "text")
  422. {
  423. val += "'" + GetExpressionVal(sub) + "',";
  424. }
  425. else
  426. {
  427. val += GetExpressionVal(sub) + ",";
  428. }
  429. }
  430. }
  431. else if(fieldQueryModel == "db_field")
  432. {
  433. foreach(string sub in valList)
  434. {
  435. if(fieldQueryValueType == "text")
  436. {
  437. val += "'" + GetDbExpressionVal(sub) + "',";
  438. }
  439. else
  440. {
  441. val += GetDbExpressionVal(sub) + ",";
  442. }
  443. }
  444. }
  445. val = val.TrimEnd(',');
  446. condi += val + ")";
  447. }
  448. else if(fieldQueryKind == "3") //范围匹配
  449. {
  450. string[] val = fieldQueryValue.Split(':');
  451. if(fieldQueryModel == "request_param")
  452. {
  453. Dictionary<string, string> req = getRequestParams(projectId, content);
  454. if(fieldQueryValueType == "number")
  455. {
  456. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  457. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  458. }
  459. else
  460. {
  461. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  462. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  463. }
  464. }
  465. else if(fieldQueryModel == "fixed_value")
  466. {
  467. if(fieldQueryValueType == "number")
  468. {
  469. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  470. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  471. }
  472. else
  473. {
  474. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  475. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  476. }
  477. }
  478. else if(fieldQueryModel == "db_field")
  479. {
  480. if(fieldQueryValueType == "number")
  481. {
  482. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  483. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  484. }
  485. else
  486. {
  487. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  488. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  489. }
  490. }
  491. }
  492. else if(fieldQueryKind == "4") //取反匹配
  493. {
  494. condi += " and " + fieldEnName + "!=";
  495. string val = "";
  496. if(fieldQueryModel == "request_param")
  497. {
  498. Dictionary<string, string> req = getRequestParams(projectId, content);
  499. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  500. }
  501. else if(fieldQueryModel == "fixed_value")
  502. {
  503. val = GetExpressionVal(fieldQueryValue);
  504. }
  505. else if(fieldQueryModel == "db_field")
  506. {
  507. val = GetDbExpressionVal(fieldQueryValue);
  508. }
  509. if(fieldQueryValueType == "text")
  510. {
  511. val = "'" + val + "'";
  512. }
  513. condi += val;
  514. }
  515. }
  516. var db = initDb(prizeObjectTable.databaseId);
  517. var item = db.Ado.GetScalar("select " + field + " from " + prizeObjectTable.tableEnName + " where 1=1" + condi);
  518. if(item != null)
  519. {
  520. return item.ToString();
  521. }
  522. return "0";
  523. }
  524. //奖励发放入口
  525. public static string prizeInSet(string queueName)
  526. {
  527. Dictionary<string, object> dic = new();
  528. var prizeInSetService = App.GetService<IPriPrizeInSetService>();
  529. //查询表
  530. var prizeInSet = prizeInSetService.GetFirst(m => m.mqQueueName == queueName) ?? new PriPrizeInSet();
  531. if(prizeInSet.id > 0)
  532. {
  533. return prizeInSet.prizeListIds + "|" + prizeInSet.projectId + "|" + prizeInSet.id;
  534. }
  535. return "";
  536. }
  537. //奖励列表
  538. public static List<PriList> prizeList(int projectId, string prizeIds)
  539. {
  540. List<int> ids = Tools.SpitIntArrary(prizeIds, ',').ToList();
  541. var priListService = App.GetService<IPriListService>();
  542. var priList = priListService.GetList(m => m.projectId == projectId && ids.Contains(m.id)).ToList();
  543. return priList;
  544. }
  545. //奖励发放
  546. public static void prizeSend(int projectId, int prizeInId, string prizeIds, string content)
  547. {
  548. var loopSetService = App.GetService<IPriLoopSetService>();
  549. var recursionStartTableService = App.GetService<IPriRecursionStartTableService>();
  550. var recursionStartConditionService = App.GetService<IPriRecursionStartConditionService>();
  551. var priList = prizeList(projectId, prizeIds);
  552. foreach(var sub in priList)
  553. {
  554. addLog(projectId, sub.id, prizeInId, content); //初始化日志
  555. string prizeObjectId = prizeObject(sub.prizeObj, content);
  556. var recursionFlag = sub.recursionFlag; //是否递归
  557. if(recursionFlag)
  558. {
  559. List<QueryCondition> queryCondiDic = condition(projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content);
  560. var loopSet = loopSetService.GetFirst(m => m.listId == sub.id) ?? new PriLoopSet();
  561. var recursionStartTable = recursionStartTableService.GetFirst(m => m.listId == sub.id) ?? new PriRecursionStartTable();
  562. var tableEnName = loopSet.tableEnName; //递归查询表
  563. var parentField = loopSet.parentField; //父字段
  564. var sonField = loopSet.sonField; //子字段
  565. var afterPrizeFlag = loopSet.afterPrizeFlag; //发奖后是否继续
  566. var db = initDb(recursionStartTable.databaseId);
  567. string objId = prizeObjectId;
  568. bool op = true;
  569. int index = 0;
  570. loopAmount = 0;
  571. while(!string.IsNullOrEmpty(objId) && objId != "0" && op)
  572. {
  573. List<QueryCondition> condiDic = loopCondition(projectId, sub, objId, content);
  574. if(condiDic.Count > 0)
  575. {
  576. bool prizeFlag = true;
  577. var conditions = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id);
  578. if(conditions.Count > 0)
  579. {
  580. int allCount = conditions.Count; //所有奖励条件数
  581. int passCount = 0; //通过条件数
  582. foreach(var condition in conditions)
  583. {
  584. if(condition.startIndex <= index)
  585. {
  586. Dictionary<string, string> logStepDic = new();
  587. var returnFieldId = condition.returnFieldId; //条件返回字段
  588. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  589. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  590. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  591. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  592. string checkObj = "";
  593. string checkTitle = "";
  594. if(returnFieldId.Contains(","))
  595. {
  596. string[] returnFieldIdList = returnFieldId.Split(',');
  597. foreach(string subField in returnFieldIdList)
  598. {
  599. string val = GetQueryTableData(condiDic, subField);
  600. checkObj += val + ",";
  601. string title = GetQueryTableTitle(condiDic, subField);
  602. checkTitle += title + ",";
  603. }
  604. checkObj = checkObj.TrimEnd(',');
  605. checkTitle = checkTitle.TrimEnd(',');
  606. }
  607. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  608. {
  609. string expresssion = returnFieldId;
  610. checkTitle = returnFieldId;
  611. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  612. foreach(string returnField in returnFields)
  613. {
  614. string val = GetQueryTableData(condiDic, returnField);
  615. expresssion = expresssion.Replace(returnField, val);
  616. string title = GetQueryTableTitle(condiDic, returnField);
  617. checkTitle = checkTitle.Replace(returnField, title);
  618. }
  619. DataTable dt = new();
  620. checkObj = dt.Compute(expresssion, "false").ToString();
  621. }
  622. else
  623. {
  624. checkObj = GetQueryTableData(condiDic, returnFieldId);
  625. checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
  626. }
  627. logStepDic.Add("标题", checkTitle);
  628. logStepDic.Add("匹配值", fieldQueryValue);
  629. logStepDic.Add("实际值", checkObj);
  630. var checkVal = fieldQueryValue;
  631. bool passFlag = false;
  632. if(fieldQueryKind == "1") //模糊匹配
  633. {
  634. if(fieldQueryValueType == "text")
  635. {
  636. if(checkObj.ToString().Contains(GetExpressionVal(checkVal)))
  637. {
  638. passCount += 1; passFlag = true;
  639. }
  640. }
  641. }
  642. else if(fieldQueryKind == "2") //精确匹配
  643. {
  644. if(fieldQueryValueType == "int")
  645. {
  646. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal)))
  647. {
  648. passCount += 1; passFlag = true;
  649. }
  650. }
  651. else if(fieldQueryValueType == "number")
  652. {
  653. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal)))
  654. {
  655. passCount += 1; passFlag = true;
  656. }
  657. }
  658. else
  659. {
  660. if(checkObj.ToString() == GetExpressionVal(checkVal))
  661. {
  662. passCount += 1; passFlag = true;
  663. }
  664. }
  665. }
  666. else if(fieldQueryKind == "3") //范围匹配
  667. {
  668. string[] val = checkVal.Split(':');
  669. string valLeft = val[0];
  670. string valRight = val[1];
  671. if(fieldQueryModel == "request_param")
  672. {
  673. Dictionary<string, string> req = getRequestParams(projectId, content);
  674. if(fieldQueryValueType == "number")
  675. {
  676. 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])))
  677. {
  678. passCount += 1; passFlag = true;
  679. }
  680. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])))
  681. {
  682. passCount += 1; passFlag = true;
  683. }
  684. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight])))
  685. {
  686. passCount += 1; passFlag = true;
  687. }
  688. }
  689. else if(fieldQueryValueType == "int")
  690. {
  691. 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])))
  692. {
  693. passCount += 1; passFlag = true;
  694. }
  695. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])))
  696. {
  697. passCount += 1; passFlag = true;
  698. }
  699. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight])))
  700. {
  701. passCount += 1; passFlag = true;
  702. }
  703. }
  704. else if(fieldQueryValueType.StartsWith("date"))
  705. {
  706. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  707. {
  708. passCount += 1; passFlag = true;
  709. }
  710. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]))
  711. {
  712. passCount += 1; passFlag = true;
  713. }
  714. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  715. {
  716. passCount += 1; passFlag = true;
  717. }
  718. }
  719. }
  720. else if(fieldQueryModel == "fixed_value")
  721. {
  722. string checkValLeft = valLeft.Replace("#{", "").Replace("}#", "");
  723. string checkValRight = valRight.Replace("#{", "").Replace("}#", "");
  724. if(checkValLeft.Contains(",")) checkValLeft = checkValLeft.Split(',')[0];
  725. if(checkValRight.Contains(",")) checkValRight = checkValRight.Split(',')[0];
  726. valLeft = GetExpressionVal(valLeft);
  727. valRight = GetExpressionVal(valRight);
  728. if(fieldQueryValueType == "number")
  729. {
  730. 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)))
  731. {
  732. passCount += 1; passFlag = true;
  733. }
  734. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  735. {
  736. passCount += 1; passFlag = true;
  737. }
  738. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  739. {
  740. passCount += 1; passFlag = true;
  741. }
  742. }
  743. else if(fieldQueryValueType == "int")
  744. {
  745. 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)))
  746. {
  747. passCount += 1; passFlag = true;
  748. }
  749. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  750. {
  751. passCount += 1; passFlag = true;
  752. }
  753. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  754. {
  755. passCount += 1; passFlag = true;
  756. }
  757. }
  758. else if(fieldQueryValueType.StartsWith("date"))
  759. {
  760. if(valLeft == "0") valLeft = "";
  761. if(valRight == "0") valRight = "";
  762. if(checkObj != "0" && checkObj != "")
  763. {
  764. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  765. {
  766. passCount += 1; passFlag = true;
  767. }
  768. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)))
  769. {
  770. passCount += 1; passFlag = true;
  771. }
  772. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  773. {
  774. passCount += 1; passFlag = true;
  775. }
  776. }
  777. }
  778. }
  779. else if(fieldQueryModel == "query_field")
  780. {
  781. valLeft = GetComputeVal(queryCondiDic, valLeft);
  782. valRight = GetComputeVal(queryCondiDic, valRight);
  783. if(fieldQueryValueType == "number")
  784. {
  785. 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)))
  786. {
  787. passCount += 1; passFlag = true;
  788. }
  789. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  790. {
  791. passCount += 1; passFlag = true;
  792. }
  793. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  794. {
  795. passCount += 1; passFlag = true;
  796. }
  797. }
  798. else if(fieldQueryValueType == "int")
  799. {
  800. 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)))
  801. {
  802. passCount += 1; passFlag = true;
  803. }
  804. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  805. {
  806. passCount += 1; passFlag = true;
  807. }
  808. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  809. {
  810. passCount += 1; passFlag = true;
  811. }
  812. }
  813. else if(fieldQueryValueType.StartsWith("date"))
  814. {
  815. if(valLeft == "0") valLeft = "";
  816. if(valRight == "0") valRight = "";
  817. if(checkObj != "0" && checkObj != "")
  818. {
  819. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  820. {
  821. passCount += 1; passFlag = true;
  822. }
  823. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)))
  824. {
  825. passCount += 1; passFlag = true;
  826. }
  827. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  828. {
  829. passCount += 1; passFlag = true;
  830. }
  831. }
  832. }
  833. }
  834. }
  835. else if(fieldQueryKind == "4") //取反匹配
  836. {
  837. if(fieldQueryValueType == "int")
  838. {
  839. if(int.Parse(checkObj) != int.Parse(Function.CheckInt(checkVal)))
  840. {
  841. passCount += 1; passFlag = true;
  842. }
  843. }
  844. else if(fieldQueryValueType == "number")
  845. {
  846. if(decimal.Parse(checkObj) != decimal.Parse(Function.CheckNum(checkVal)))
  847. {
  848. passCount += 1; passFlag = true;
  849. }
  850. }
  851. else if(fieldQueryValueType == "text")
  852. {
  853. if(checkObj.ToString() != GetExpressionVal(checkVal))
  854. {
  855. passCount += 1; passFlag = true;
  856. }
  857. }
  858. }
  859. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  860. {
  861. string val = ",";
  862. string[] valList = checkVal.Split(',');
  863. if(fieldQueryModel == "request_param")
  864. {
  865. Dictionary<string, string> req = getRequestParams(projectId, content);
  866. foreach(string subVal in valList)
  867. {
  868. val += req[subVal] + ",";
  869. }
  870. }
  871. else if(fieldQueryModel == "fixed_value")
  872. {
  873. foreach(string subVal in valList)
  874. {
  875. val += GetExpressionVal(subVal) + ",";
  876. }
  877. }
  878. else if(fieldQueryModel == "db_field")
  879. {
  880. foreach(string subVal in valList)
  881. {
  882. val += GetDbExpressionVal(subVal) + ",";
  883. }
  884. }
  885. if(fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ","))
  886. {
  887. passCount += 1; passFlag = true;
  888. }
  889. if(fieldQueryKind == "6" && !val.Contains("," + checkObj.ToString() + ","))
  890. {
  891. passCount += 1; passFlag = true;
  892. }
  893. }
  894. logStepDic.Add("状态", passFlag ? "通过" : "未通过");
  895. setLogStep(sub.id, logStepDic);
  896. }
  897. }
  898. if(loopSet.conditionMode == "all" && passCount == allCount) prizeFlag = true;
  899. else if(loopSet.conditionMode == "one" && passCount >= 1) prizeFlag = true;
  900. else if(loopSet.conditionMode == "two" && passCount >= 2) prizeFlag = true;
  901. else if(loopSet.conditionMode == "three" && passCount >= 3) prizeFlag = true;
  902. else prizeFlag = false;
  903. }
  904. else
  905. {
  906. prizeFlag = false;
  907. }
  908. if(prizeFlag)
  909. {
  910. decimal prizeAmt = prizeSendDo(projectId, sub, objId, content, loopSet);
  911. op = afterPrizeFlag;
  912. }
  913. }
  914. var parent = db.Ado.GetScalar("select " + parentField + " from " + tableEnName + " where " + sonField + "=" + objId);
  915. if(parent != null)
  916. {
  917. objId = parent.ToString();
  918. }
  919. else
  920. {
  921. objId = "0";
  922. }
  923. index += 1;
  924. }
  925. }
  926. else
  927. {
  928. prizeSendDo(projectId, sub, prizeObjectId, content, new PriLoopSet());
  929. }
  930. }
  931. }
  932. static decimal loopAmount = 0;
  933. public static decimal prizeSendDo(int projectId, PriList sub, string prizeObjectId, string content, PriLoopSet set)
  934. {
  935. var recordService = App.GetService<IPriRecordService>();
  936. var conditionService = App.GetService<IPriConditionService>();
  937. var returnFieldService = App.GetService<IPriReturnFieldService>();
  938. var queryTableService = App.GetService<IPriQueryTableService>();
  939. var amountSetService = App.GetService<IPriListAmountSetService>();
  940. //查询匹配条件
  941. List<QueryCondition> condiDic = condiDic = condition(projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content);
  942. if(sub.prizeSourceFieldType == "loop") MergeCondiDic(condiDic, loopCondition(projectId, sub, prizeObjectId, content));
  943. var prizeSourceField = sub.prizeSourceField; //奖励金额来源字段(对应条件匹配返回字段)
  944. var prizePercent = sub.prizePercent; //奖励比例
  945. var prizeAmount = sub.prizeAmount; //奖励固定值
  946. var prizeContent = sub.prizeContent; //奖励内容
  947. var conditionMode = sub.conditionMode; //条件模式
  948. var recursionFlag = sub.recursionFlag; //是否递归
  949. var conditions = conditionService.GetList(m => m.listId == sub.id);
  950. int allCount = conditions.Count; //所有奖励条件数
  951. int passCount = 0; //通过条件数
  952. foreach(var condition in conditions)
  953. {
  954. Dictionary<string, string> logStepDic = new();
  955. var returnFieldId = condition.returnFieldId; //条件返回字段
  956. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  957. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  958. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  959. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  960. string checkObj = "";
  961. string checkTitle = "";
  962. if(returnFieldId.Contains(","))
  963. {
  964. string[] returnFieldIdList = returnFieldId.Split(',');
  965. foreach(string subField in returnFieldIdList)
  966. {
  967. string val = GetQueryTableData(condiDic, subField);
  968. checkObj += val + ",";
  969. string title = GetQueryTableTitle(condiDic, subField);
  970. checkTitle += title + ",";
  971. }
  972. checkObj = checkObj.TrimEnd(',');
  973. checkTitle = checkTitle.TrimEnd(',');
  974. }
  975. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  976. {
  977. string expresssion = returnFieldId;
  978. checkTitle = returnFieldId;
  979. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  980. foreach(string returnField in returnFields)
  981. {
  982. string val = GetQueryTableData(condiDic, returnField);
  983. expresssion = expresssion.Replace(returnField, val);
  984. string title = GetQueryTableTitle(condiDic, returnField);
  985. checkTitle = checkTitle.Replace(returnField, title);
  986. }
  987. DataTable dt = new();
  988. checkObj = dt.Compute(expresssion, "false").ToString();
  989. }
  990. else
  991. {
  992. checkObj = GetQueryTableData(condiDic, returnFieldId);
  993. checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
  994. }
  995. if(!sub.recursionFlag)
  996. {
  997. logStepDic.Add("标题", checkTitle);
  998. logStepDic.Add("匹配值", fieldQueryValue);
  999. logStepDic.Add("实际值", checkObj);
  1000. }
  1001. string checkVal = fieldQueryValue;
  1002. bool passFlag = false;
  1003. if(fieldQueryKind == "1") //模糊匹配
  1004. {
  1005. if(fieldQueryValueType == "text")
  1006. {
  1007. if(checkObj.ToString().Contains(GetExpressionVal(checkVal)))
  1008. {
  1009. passCount += 1; passFlag = true;
  1010. }
  1011. }
  1012. }
  1013. else if(fieldQueryKind == "2") //精确匹配
  1014. {
  1015. if(fieldQueryValueType == "int")
  1016. {
  1017. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal)))
  1018. {
  1019. passCount += 1; passFlag = true;
  1020. }
  1021. }
  1022. else if(fieldQueryValueType == "number")
  1023. {
  1024. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal)))
  1025. {
  1026. passCount += 1; passFlag = true;
  1027. }
  1028. }
  1029. else
  1030. {
  1031. if(checkObj.ToString() == GetExpressionVal(checkVal))
  1032. {
  1033. passCount += 1; passFlag = true;
  1034. }
  1035. }
  1036. }
  1037. else if(fieldQueryKind == "3") //范围匹配
  1038. {
  1039. string[] val = checkVal.Split(':');
  1040. string valLeft = val[0];
  1041. string valRight = val[1];
  1042. if(fieldQueryModel == "request_param")
  1043. {
  1044. Dictionary<string, string> req = getRequestParams(projectId, content);
  1045. if(fieldQueryValueType == "number")
  1046. {
  1047. 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])))
  1048. {
  1049. passCount += 1; passFlag = true;
  1050. }
  1051. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])))
  1052. {
  1053. passCount += 1; passFlag = true;
  1054. }
  1055. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight])))
  1056. {
  1057. passCount += 1; passFlag = true;
  1058. }
  1059. }
  1060. else if(fieldQueryValueType == "int")
  1061. {
  1062. 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])))
  1063. {
  1064. passCount += 1; passFlag = true;
  1065. }
  1066. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])))
  1067. {
  1068. passCount += 1; passFlag = true;
  1069. }
  1070. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight])))
  1071. {
  1072. passCount += 1; passFlag = true;
  1073. }
  1074. }
  1075. else if(fieldQueryValueType.StartsWith("date"))
  1076. {
  1077. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1078. {
  1079. passCount += 1; passFlag = true;
  1080. }
  1081. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]))
  1082. {
  1083. passCount += 1; passFlag = true;
  1084. }
  1085. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1086. {
  1087. passCount += 1; passFlag = true;
  1088. }
  1089. }
  1090. }
  1091. else if(fieldQueryModel == "fixed_value")
  1092. {
  1093. valLeft = GetExpressionVal(valLeft);
  1094. valRight = GetExpressionVal(valRight);
  1095. if(fieldQueryValueType == "number")
  1096. {
  1097. 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)))
  1098. {
  1099. passCount += 1; passFlag = true;
  1100. }
  1101. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1102. {
  1103. passCount += 1; passFlag = true;
  1104. }
  1105. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1106. {
  1107. passCount += 1; passFlag = true;
  1108. }
  1109. }
  1110. else if(fieldQueryValueType == "int")
  1111. {
  1112. 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)))
  1113. {
  1114. passCount += 1; passFlag = true;
  1115. }
  1116. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1117. {
  1118. passCount += 1; passFlag = true;
  1119. }
  1120. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1121. {
  1122. passCount += 1; passFlag = true;
  1123. }
  1124. }
  1125. else if(fieldQueryValueType.StartsWith("date"))
  1126. {
  1127. if(valLeft == "0") valLeft = "";
  1128. if(valRight == "0") valRight = "";
  1129. if(checkObj != "0" && checkObj != "")
  1130. {
  1131. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1132. {
  1133. passCount += 1; passFlag = true;
  1134. }
  1135. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1136. {
  1137. passCount += 1; passFlag = true;
  1138. }
  1139. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1140. {
  1141. passCount += 1; passFlag = true;
  1142. }
  1143. }
  1144. }
  1145. }
  1146. else if(fieldQueryModel == "query_field")
  1147. {
  1148. string checkValLeft = valLeft.Replace("#{", "").Replace("}#", "");
  1149. string checkValRight = valRight.Replace("#{", "").Replace("}#", "");
  1150. if(checkValLeft.Contains(",")) checkValLeft = checkValLeft.Split(',')[0];
  1151. if(checkValRight.Contains(",")) checkValRight = checkValRight.Split(',')[0];
  1152. if(!string.IsNullOrEmpty(valLeft)) valLeft = valLeft.Replace(checkValLeft, GetQueryTableData(condiDic, checkValLeft));
  1153. if(!string.IsNullOrEmpty(valRight)) valRight = valRight.Replace(checkValRight, GetQueryTableData(condiDic, checkValRight));
  1154. valLeft = GetExpressionVal(valLeft);
  1155. valRight = GetExpressionVal(valRight);
  1156. if(fieldQueryValueType == "number")
  1157. {
  1158. 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)))
  1159. {
  1160. passCount += 1; passFlag = true;
  1161. }
  1162. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1163. {
  1164. passCount += 1; passFlag = true;
  1165. }
  1166. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1167. {
  1168. passCount += 1; passFlag = true;
  1169. }
  1170. }
  1171. else if(fieldQueryValueType == "int")
  1172. {
  1173. 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)))
  1174. {
  1175. passCount += 1; passFlag = true;
  1176. }
  1177. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1178. {
  1179. passCount += 1; passFlag = true;
  1180. }
  1181. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1182. {
  1183. passCount += 1; passFlag = true;
  1184. }
  1185. }
  1186. else if(fieldQueryValueType.StartsWith("date"))
  1187. {
  1188. if(valLeft == "0") valLeft = "";
  1189. if(valRight == "0") valRight = "";
  1190. if(checkObj != "0" && checkObj != "")
  1191. {
  1192. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1193. {
  1194. passCount += 1; passFlag = true;
  1195. }
  1196. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1197. {
  1198. passCount += 1; passFlag = true;
  1199. }
  1200. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1201. {
  1202. passCount += 1; passFlag = true;
  1203. }
  1204. }
  1205. }
  1206. }
  1207. }
  1208. else if(fieldQueryKind == "4") //取反匹配
  1209. {
  1210. if(fieldQueryValueType == "int")
  1211. {
  1212. if(int.Parse(Function.CheckNum(checkObj.ToString())) != int.Parse(Function.CheckInt(checkVal)))
  1213. {
  1214. passCount += 1; passFlag = true;
  1215. }
  1216. }
  1217. else if(fieldQueryValueType == "number")
  1218. {
  1219. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) != decimal.Parse(Function.CheckNum(checkVal)))
  1220. {
  1221. passCount += 1; passFlag = true;
  1222. }
  1223. }
  1224. else if(fieldQueryValueType == "text")
  1225. {
  1226. if(checkObj.ToString() != GetExpressionVal(checkVal))
  1227. {
  1228. passCount += 1; passFlag = true;
  1229. }
  1230. }
  1231. }
  1232. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1233. {
  1234. string val = ",";
  1235. string[] valList = checkVal.Split(',');
  1236. if(fieldQueryModel == "request_param")
  1237. {
  1238. Dictionary<string, string> req = getRequestParams(projectId, content);
  1239. foreach(string subVal in valList)
  1240. {
  1241. val += req[subVal] + ",";
  1242. }
  1243. }
  1244. else if(fieldQueryModel == "fixed_value")
  1245. {
  1246. foreach(string subVal in valList)
  1247. {
  1248. val += GetExpressionVal(subVal) + ",";
  1249. }
  1250. }
  1251. else if(fieldQueryModel == "db_field")
  1252. {
  1253. foreach(string subVal in valList)
  1254. {
  1255. val += GetDbExpressionVal(subVal) + ",";
  1256. }
  1257. }
  1258. if (fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ","))
  1259. {
  1260. passCount += 1; passFlag = true;
  1261. }
  1262. if(fieldQueryKind == "6" && !val.Contains("," + checkObj.ToString() + ","))
  1263. {
  1264. passCount += 1; passFlag = true;
  1265. }
  1266. }
  1267. if(!sub.recursionFlag)
  1268. {
  1269. logStepDic.Add("状态", passFlag ? "通过" : "未通过");
  1270. setLogStep(sub.id, logStepDic);
  1271. }
  1272. }
  1273. bool op = false;
  1274. decimal prizeAmt = 0;
  1275. if(conditionMode == "all" && passCount == allCount && passCount > 0) op = true;
  1276. else if(conditionMode == "one" && passCount >= 1) op = true;
  1277. else if(conditionMode == "two" && passCount >= 2) op = true;
  1278. else if(conditionMode == "three" && passCount >= 3) op = true;
  1279. if(op) //满足条件
  1280. {
  1281. decimal number = 0;
  1282. if(prizeSourceField.Contains("/"))
  1283. {
  1284. number = decimal.Parse(prizeSourceField.Split('/')[1]);
  1285. prizeSourceField = prizeSourceField.Split('/')[0];
  1286. }
  1287. string prizeSourceData = "";
  1288. if(prizeSourceField.Contains(","))
  1289. {
  1290. string[] prizeSourceFieldList = prizeSourceField.Split(',');
  1291. foreach(string subField in prizeSourceFieldList)
  1292. {
  1293. string val = GetQueryTableData(condiDic, subField);
  1294. prizeSourceData += val + ",";
  1295. }
  1296. prizeSourceData = prizeSourceData.TrimEnd(',');
  1297. }
  1298. else
  1299. {
  1300. prizeSourceData = GetQueryTableData(condiDic, prizeSourceField);
  1301. }
  1302. if(string.IsNullOrEmpty(prizeSourceData)) prizeSourceData = "0";
  1303. if(prizeSourceField.Contains("/") && number > 0)
  1304. {
  1305. decimal prizeSourceDataNum = decimal.Parse(prizeSourceData) / number;
  1306. prizeSourceData = prizeSourceDataNum.ToString("f2");
  1307. }
  1308. var amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField == prizeSourceData);
  1309. if(amountSet != null)
  1310. {
  1311. prizePercent = amountSet.prizePercent;
  1312. prizeAmount = amountSet.prizeAmount;
  1313. }
  1314. if(prizeSourceData.Contains(","))
  1315. {
  1316. string checkField = prizeSourceData.Split(',')[0] + ",";
  1317. amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField.StartsWith(checkField) && m.prizeSourceField.EndsWith(",%"));
  1318. if(amountSet != null)
  1319. {
  1320. prizePercent = amountSet.prizePercent;
  1321. prizeAmount = amountSet.prizeAmount;
  1322. prizeSourceData = prizeSourceData.Split(',')[1];
  1323. }
  1324. }
  1325. if(prizePercent > 0) prizeAmt += decimal.Parse(Function.CheckNum(prizeSourceData)) * prizePercent;
  1326. if(prizeAmount > 0) prizeAmt += prizeAmount;
  1327. decimal getPrizeAmount = prizeAmt;
  1328. if(set.levelDiffFlag) prizeAmt -= loopAmount;
  1329. if(prizeAmt > 0)
  1330. {
  1331. setLogPrizeAmount(sub.id, prizeAmt);
  1332. var req = getRequestParams(projectId, content);
  1333. var requestParamField = req[sub.requestParamField];
  1334. var sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == requestParamField);
  1335. if(!sendFlag)
  1336. {
  1337. recordService.Add(new PriRecord()
  1338. {
  1339. createDate = DateTime.Now,
  1340. projectId = projectId,
  1341. listId = sub.id,
  1342. prizeAmount = prizeAmt,
  1343. prizeObjId = prizeObjectId,
  1344. requestParamField = requestParamField,
  1345. batchNo = batchNo,
  1346. });
  1347. loopAmount = getPrizeAmount;
  1348. prizeToDatabase(projectId, sub.id, content, condiDic, prizeAmt); //入库
  1349. }
  1350. }
  1351. }
  1352. if(!sub.recursionFlag)
  1353. {
  1354. setLogStatus(sub.id, op ? 1 : 0);
  1355. }
  1356. return prizeAmt;
  1357. }
  1358. //递归条件判断
  1359. public static List<QueryCondition> loopCondition(int projectId, PriList sub, string objId, string content)
  1360. {
  1361. List<QueryCondition> dic = new();
  1362. var queryTableService = App.GetService<IPriRecursionStartTableService>();
  1363. var queryFieldService = App.GetService<IPriRecursionStartFieldService>();
  1364. var queryReturnFieldService = App.GetService<IPriRecursionStartReturnFieldService>();
  1365. int passCount = 0;
  1366. //查询表
  1367. var queryTables = queryTableService.GetList(m => m.listId == sub.id);
  1368. int allCount = queryTables.Count;
  1369. foreach(var queryTable in queryTables)
  1370. {
  1371. //查询返回字段
  1372. string fields = "1";
  1373. Dictionary<string, string> fieldDic = new();
  1374. var returnFields = queryReturnFieldService.GetList(m => m.objectTableId == queryTable.id);
  1375. if(returnFields.Count > 0)
  1376. {
  1377. fields = "";
  1378. foreach(var returnField in returnFields)
  1379. {
  1380. if(returnField.fieldReturnKind == "2")
  1381. {
  1382. fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1383. }
  1384. else if(returnField.fieldReturnKind == "3")
  1385. {
  1386. fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1387. }
  1388. else if(returnField.fieldReturnKind == "4")
  1389. {
  1390. fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1391. }
  1392. else
  1393. {
  1394. fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1395. }
  1396. fieldDic.Add(queryTable.tableEnName + "_" + returnField.fieldEnName, returnField.fieldName);
  1397. }
  1398. fields = fields.TrimEnd(',');
  1399. }
  1400. //查询匹配条件
  1401. string condi = "";
  1402. var queryFields = queryFieldService.GetList(m => m.objectTableId == queryTable.id);
  1403. foreach(var queryField in queryFields)
  1404. {
  1405. string fieldEnName = queryField.fieldEnName;
  1406. string fieldQueryKind = queryField.fieldQueryKind;
  1407. string fieldQueryModel = queryField.fieldQueryModel;
  1408. string fieldQueryValue = queryField.fieldQueryValue;
  1409. if(fieldQueryModel == "loop_field") fieldQueryValue = objId;
  1410. string fieldQueryValueType = queryField.fieldQueryValueType;
  1411. if(fieldQueryKind == "1") //模糊匹配
  1412. {
  1413. condi += " and " + fieldEnName + " like ";
  1414. if(fieldQueryModel == "request_param")
  1415. {
  1416. Dictionary<string, string> req = getRequestParams(projectId, content);
  1417. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1418. condi += "'%" + val + "%'";
  1419. }
  1420. else if(fieldQueryModel == "fixed_value")
  1421. {
  1422. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  1423. }
  1424. else if(fieldQueryModel == "db_field")
  1425. {
  1426. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  1427. }
  1428. }
  1429. else if(fieldQueryKind == "2") //精确匹配
  1430. {
  1431. condi += " and " + fieldEnName + "=";
  1432. string val = fieldQueryValue;
  1433. if(fieldQueryModel == "request_param")
  1434. {
  1435. Dictionary<string, string> req = getRequestParams(projectId, content);
  1436. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1437. }
  1438. else if(fieldQueryModel == "fixed_value")
  1439. {
  1440. val = GetExpressionVal(fieldQueryValue);
  1441. }
  1442. else if(fieldQueryModel == "db_field")
  1443. {
  1444. val = GetDbExpressionVal(fieldQueryValue);
  1445. }
  1446. if(fieldQueryValueType == "text")
  1447. {
  1448. val = "'" + val + "'";
  1449. }
  1450. condi += val;
  1451. }
  1452. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1453. {
  1454. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  1455. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  1456. string val = "";
  1457. string[] valList = fieldQueryValue.Split(',');
  1458. if(fieldQueryModel == "request_param")
  1459. {
  1460. Dictionary<string, string> req = getRequestParams(projectId, content);
  1461. foreach(string subval in valList)
  1462. {
  1463. if(fieldQueryValueType == "text")
  1464. {
  1465. val += "'" + req[subval] + "',";
  1466. }
  1467. else
  1468. {
  1469. val += req[subval] + ",";
  1470. }
  1471. }
  1472. }
  1473. else if(fieldQueryModel == "fixed_value")
  1474. {
  1475. foreach(string subval in valList)
  1476. {
  1477. if(fieldQueryValueType == "text")
  1478. {
  1479. val += "'" + GetExpressionVal(subval) + "',";
  1480. }
  1481. else
  1482. {
  1483. val += GetExpressionVal(subval) + ",";
  1484. }
  1485. }
  1486. }
  1487. else if(fieldQueryModel == "db_field")
  1488. {
  1489. foreach(string subval in valList)
  1490. {
  1491. if(fieldQueryValueType == "text")
  1492. {
  1493. val += "'" + GetDbExpressionVal(subval) + "',";
  1494. }
  1495. else
  1496. {
  1497. val += GetDbExpressionVal(subval) + ",";
  1498. }
  1499. }
  1500. }
  1501. val = val.TrimEnd(',');
  1502. condi += val + ")";
  1503. }
  1504. else if(fieldQueryKind == "3") //范围匹配
  1505. {
  1506. string[] val = fieldQueryValue.Split(':');
  1507. if(fieldQueryModel == "request_param")
  1508. {
  1509. Dictionary<string, string> req = getRequestParams(projectId, content);
  1510. if(fieldQueryValueType == "number")
  1511. {
  1512. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  1513. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  1514. }
  1515. else
  1516. {
  1517. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  1518. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  1519. }
  1520. }
  1521. else if(fieldQueryModel == "fixed_value")
  1522. {
  1523. if(fieldQueryValueType == "number")
  1524. {
  1525. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1526. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1527. }
  1528. else
  1529. {
  1530. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  1531. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  1532. }
  1533. }
  1534. else if(fieldQueryModel == "db_field")
  1535. {
  1536. if(fieldQueryValueType == "number")
  1537. {
  1538. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1539. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1540. }
  1541. else
  1542. {
  1543. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  1544. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  1545. }
  1546. }
  1547. }
  1548. else if(fieldQueryKind == "4") //取反匹配
  1549. {
  1550. condi += " and " + fieldEnName + "!=";
  1551. string val = "";
  1552. if(fieldQueryModel == "request_param")
  1553. {
  1554. Dictionary<string, string> req = getRequestParams(projectId, content);
  1555. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1556. }
  1557. else if(fieldQueryModel == "fixed_value")
  1558. {
  1559. val = GetExpressionVal(fieldQueryValue);
  1560. }
  1561. else if(fieldQueryModel == "db_field")
  1562. {
  1563. val = GetDbExpressionVal(fieldQueryValue);
  1564. }
  1565. if(fieldQueryValueType == "text")
  1566. {
  1567. val = "'" + val + "'";
  1568. }
  1569. condi += val;
  1570. }
  1571. }
  1572. var db = initDb(queryTable.databaseId);
  1573. string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
  1574. var items = db.Ado.GetDataTable(sql);
  1575. if(items.Rows.Count > 0)
  1576. {
  1577. foreach(string field in fieldDic.Keys)
  1578. {
  1579. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  1580. {
  1581. FieldName = fieldDic[field],
  1582. FieldEnName = field,
  1583. Value = items.Rows[0][field].ToString()
  1584. });
  1585. }
  1586. }
  1587. }
  1588. return dic;
  1589. }
  1590. //奖励入库
  1591. public static void prizeToDatabase(int projectId, int listId, string content, List<QueryCondition> condiDic, decimal prize_amt)
  1592. {
  1593. var prizeInTableService = App.GetService<IPriPrizeInTableService>();
  1594. var prizeInFieldService = App.GetService<IPriPrizeInFieldService>();
  1595. var prizeInQueryFieldService = App.GetService<IPriPrizeInQueryFieldService>();
  1596. //入库表
  1597. var prizeInTables = prizeInTableService.GetList(m => m.listId == listId);
  1598. foreach(var prizeInTable in prizeInTables)
  1599. {
  1600. var db = initDb(prizeInTable.databaseId);
  1601. Dictionary<string, object> doFields = new();
  1602. //入库字段
  1603. var prizeInFields = prizeInFieldService.GetList(m => m.inTableId == prizeInTable.id);
  1604. foreach(var prizeInField in prizeInFields)
  1605. {
  1606. string fieldEnName = prizeInField.fieldEnName;
  1607. string fieldQueryModel = prizeInField.fieldQueryModel;
  1608. string fieldQueryValue = prizeInField.fieldQueryValue;
  1609. string fieldQueryValueType = prizeInField.fieldQueryValueType;
  1610. if(fieldQueryModel == "request_param")
  1611. {
  1612. Dictionary<string, string> req = getRequestParams(projectId, content);
  1613. fieldQueryValue = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1614. }
  1615. else if(fieldQueryModel == "query_field")
  1616. {
  1617. fieldQueryValue = GetQueryTableData(condiDic, fieldQueryValue);
  1618. }
  1619. else if(fieldQueryModel == "fixed_value")
  1620. {
  1621. fieldQueryValue = GetExpressionVal(fieldQueryValue);
  1622. }
  1623. else if(fieldQueryModel == "db_field")
  1624. {
  1625. fieldQueryValue = GetDbExpressionVal(fieldQueryValue);
  1626. }
  1627. else if(fieldQueryModel == "prize_amt")
  1628. {
  1629. fieldQueryValue = prize_amt.ToString();
  1630. }
  1631. if(fieldQueryValueType == "text") doFields.Add(fieldEnName, fieldQueryValue);
  1632. if(fieldQueryValueType == "int") doFields.Add(fieldEnName, int.Parse(fieldQueryValue));
  1633. if(fieldQueryValueType == "number") doFields.Add(fieldEnName, decimal.Parse(fieldQueryValue));
  1634. if(fieldQueryValueType == "datetime") doFields.Add(fieldEnName, DateTime.Parse(fieldQueryValue));
  1635. if(fieldQueryValueType == "bool") doFields.Add(fieldEnName, bool.Parse(fieldQueryValue));
  1636. }
  1637. //查询匹配条件
  1638. string condi = "";
  1639. var queryFields = prizeInQueryFieldService.GetList(m => m.inTableId == prizeInTable.id);
  1640. foreach(var queryField in queryFields)
  1641. {
  1642. string fieldEnName = queryField.fieldEnName;
  1643. string fieldQueryKind = queryField.fieldQueryKind;
  1644. string fieldQueryModel = queryField.fieldQueryModel;
  1645. string fieldQueryValue = queryField.fieldQueryValue;
  1646. string fieldQueryValueType = queryField.fieldQueryValueType;
  1647. if(fieldQueryKind == "1") //模糊匹配
  1648. {
  1649. condi += " and " + fieldEnName + " like ";
  1650. if(fieldQueryModel == "request_param")
  1651. {
  1652. Dictionary<string, string> req = getRequestParams(projectId, content);
  1653. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1654. condi += "'%" + val + "%'";
  1655. }
  1656. else if(fieldQueryModel == "fixed_value")
  1657. {
  1658. condi += "'%" + fieldQueryValue + "%'";
  1659. }
  1660. else if(fieldQueryModel == "query_field")
  1661. {
  1662. condi += "'%" + GetQueryTableData(condiDic, fieldQueryValue) + "%'";
  1663. }
  1664. }
  1665. else if(fieldQueryKind == "2") //精确匹配
  1666. {
  1667. condi += " and " + fieldEnName + "=";
  1668. string val = "";
  1669. if(fieldQueryModel == "request_param")
  1670. {
  1671. Dictionary<string, string> req = getRequestParams(projectId, content);
  1672. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1673. }
  1674. else if(fieldQueryModel == "fixed_value")
  1675. {
  1676. val = fieldQueryValue;
  1677. }
  1678. else if(fieldQueryModel == "query_field")
  1679. {
  1680. val = GetQueryTableData(condiDic, fieldQueryValue);
  1681. }
  1682. if(fieldQueryValueType == "text")
  1683. {
  1684. val = "'" + val + "'";
  1685. }
  1686. condi += val;
  1687. }
  1688. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1689. {
  1690. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  1691. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  1692. string val = "";
  1693. string[] valList = fieldQueryValue.Split(',');
  1694. if(fieldQueryModel == "request_param")
  1695. {
  1696. Dictionary<string, string> req = getRequestParams(projectId, content);
  1697. foreach(string sub in valList)
  1698. {
  1699. if(fieldQueryValueType == "text")
  1700. {
  1701. val += "'" + req[sub] + "',";
  1702. }
  1703. else
  1704. {
  1705. val += req[sub] + ",";
  1706. }
  1707. }
  1708. }
  1709. else if(fieldQueryModel == "fixed_value")
  1710. {
  1711. foreach(string sub in valList)
  1712. {
  1713. if(fieldQueryValueType == "text")
  1714. {
  1715. val += "'" + GetExpressionVal(sub) + "',";
  1716. }
  1717. else
  1718. {
  1719. val += GetExpressionVal(sub) + ",";
  1720. }
  1721. }
  1722. }
  1723. else if(fieldQueryModel == "query_field")
  1724. {
  1725. foreach(string sub in valList)
  1726. {
  1727. if(fieldQueryValueType == "text")
  1728. {
  1729. val += "'" + GetQueryTableData(condiDic, sub) + "',";
  1730. }
  1731. else
  1732. {
  1733. val += GetQueryTableData(condiDic, sub) + ",";
  1734. }
  1735. }
  1736. }
  1737. else if(fieldQueryModel == "db_field")
  1738. {
  1739. foreach(string sub in valList)
  1740. {
  1741. if(fieldQueryValueType == "text")
  1742. {
  1743. val += "'" + GetDbExpressionVal(sub) + "',";
  1744. }
  1745. else
  1746. {
  1747. val += GetDbExpressionVal(sub) + ",";
  1748. }
  1749. }
  1750. }
  1751. val = val.TrimEnd(',');
  1752. condi += val + ")";
  1753. }
  1754. else if(fieldQueryKind == "3") //范围匹配
  1755. {
  1756. string[] val = fieldQueryValue.Split(':');
  1757. if(fieldQueryModel == "request_param")
  1758. {
  1759. Dictionary<string, string> req = getRequestParams(projectId, content);
  1760. if(fieldQueryValueType == "number")
  1761. {
  1762. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  1763. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  1764. }
  1765. else
  1766. {
  1767. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  1768. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  1769. }
  1770. }
  1771. else if(fieldQueryModel == "fixed_value")
  1772. {
  1773. if(fieldQueryValueType == "number")
  1774. {
  1775. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1776. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1777. }
  1778. else
  1779. {
  1780. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + val[0] + "'";
  1781. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + val[1] + "'";
  1782. }
  1783. }
  1784. }
  1785. else if(fieldQueryKind == "4") //取反匹配
  1786. {
  1787. condi += " and " + fieldEnName + "!=";
  1788. string val = "";
  1789. if(fieldQueryModel == "request_param")
  1790. {
  1791. Dictionary<string, string> req = getRequestParams(projectId, content);
  1792. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1793. }
  1794. else if(fieldQueryModel == "fixed_value")
  1795. {
  1796. val = fieldQueryValue;
  1797. }
  1798. if(fieldQueryValueType == "text")
  1799. {
  1800. val = "'" + val + "'";
  1801. }
  1802. condi += val;
  1803. }
  1804. }
  1805. // if(prizeInTable.excuteKind == "add") db.Insertable(doFields).AS(prizeInTable.tableEnName).ExecuteCommand();
  1806. // if(prizeInTable.excuteKind == "update") db.Updateable(doFields).AS(prizeInTable.tableEnName).Where("1=1" + condi).ExecuteCommand();
  1807. Function.WriteLog(DateTime.Now.ToString() + "\n" + prizeInTable.excuteKind + "\n" + prizeInTable.tableEnName + "\n" + Newtonsoft.Json.JsonConvert.SerializeObject(doFields) + "\n" + condi + "\n\n", "奖励入库数据");
  1808. }
  1809. }
  1810. //固定值表达式
  1811. public static string GetExpressionVal(string str)
  1812. {
  1813. if(str == "#{now}#") return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1814. if(str == "#{today}#") return DateTime.Now.ToString("yyyy-MM-dd");
  1815. if(str == "#{this_month}#") return DateTime.Now.ToString("yyyy-MM");
  1816. 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");
  1817. 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");
  1818. if(str.StartsWith("#{today") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1819. if(str.StartsWith("#{today") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1820. if(str.StartsWith("#{this_month") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1821. if(str.StartsWith("#{this_month") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1822. 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");
  1823. 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");
  1824. return str;
  1825. }
  1826. //库内字段值表达式
  1827. public static string GetDbExpressionVal(string str)
  1828. {
  1829. string[] data = str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',');
  1830. if(str.StartsWith("#{") && str.EndsWith("DAY}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " DAY)";
  1831. if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " MONTH)";
  1832. return str;
  1833. }
  1834. //四则混合运算
  1835. public static string GetComputeVal(List<QueryCondition> condiDic, string expresssion)
  1836. {
  1837. if (expresssion.Contains("+") || expresssion.Contains("-") || expresssion.Contains("*") || expresssion.Contains("/") || expresssion.Contains("(") || expresssion.Contains(")"))
  1838. {
  1839. string[] returnFields = expresssion.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  1840. foreach (string returnField in returnFields)
  1841. {
  1842. if(condiDic.Any(m => m.FieldEnName == returnField))
  1843. {
  1844. string val = GetQueryTableData(condiDic, returnField);
  1845. expresssion = expresssion.Replace(returnField, val);
  1846. }
  1847. }
  1848. DataTable dt = new();
  1849. return dt.Compute(expresssion, "false").ToString();
  1850. }
  1851. return expresssion;
  1852. }
  1853. //获取查询条件数据
  1854. public static string GetQueryTableData(List<QueryCondition> condiDic, string key)
  1855. {
  1856. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).Value.ToString() : "0";
  1857. }
  1858. public static string GetQueryTableTitle(List<QueryCondition> condiDic, string key)
  1859. {
  1860. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).FieldName : "";
  1861. }
  1862. //合并字典
  1863. public static void MergeCondiDic(List<QueryCondition> condiDic, List<QueryCondition> condiDic1)
  1864. {
  1865. foreach(QueryCondition sub in condiDic1)
  1866. {
  1867. condiDic.Add(sub);
  1868. }
  1869. }
  1870. //记录日志
  1871. public static void addLog(int projectId, int listId, int prizeIn, string requestParam)
  1872. {
  1873. var logService = App.GetService<IPriLogService>();
  1874. logService.Add(new PriLog()
  1875. {
  1876. createDate = DateTime.Now,
  1877. projectId = projectId,
  1878. listId = listId,
  1879. batchNo = batchNo,
  1880. prizeIn = prizeIn,
  1881. requestParam = requestParam,
  1882. });
  1883. }
  1884. public static void setLogPrizeAmount(int listId, decimal prizeAmount)
  1885. {
  1886. var logService = App.GetService<IPriLogService>();
  1887. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  1888. if(log != null)
  1889. {
  1890. log.prizeAmount = prizeAmount;
  1891. logService.Update(log);
  1892. }
  1893. }
  1894. public static void setLogStep(int listId, Dictionary<string, string> step)
  1895. {
  1896. var logService = App.GetService<IPriLogService>();
  1897. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  1898. if(log != null)
  1899. {
  1900. log.stepList += Newtonsoft.Json.JsonConvert.SerializeObject(step);
  1901. logService.Update(log);
  1902. }
  1903. }
  1904. public static void setLogStatus(int listId, int status)
  1905. {
  1906. var logService = App.GetService<IPriLogService>();
  1907. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  1908. if(log != null)
  1909. {
  1910. log.status = status;
  1911. logService.Update(log);
  1912. }
  1913. }
  1914. }
  1915. }