PrizeDo.cs 176 KB

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