PrizeDo.cs 159 KB

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