PrizeDo.cs 158 KB

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