PrizeDo.cs 147 KB

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