PrizeDo.cs 165 KB

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