PrizeDo.cs 175 KB

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