PrizeDo.cs 145 KB

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