PrizeDo.cs 153 KB

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