PrizeDo.cs 172 KB

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