PrizeDo.cs 155 KB

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