PrizeDo.cs 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  1. using Common;
  2. using Infrastructure;
  3. using LitJson;
  4. using Microsoft.Extensions.Localization;
  5. using Model;
  6. using NuGet.Packaging;
  7. using Services;
  8. namespace Util
  9. {
  10. public class PrizeDo
  11. {
  12. public static string batchNo = "";
  13. //发奖入口
  14. public static void sendPrize(string content)
  15. {
  16. batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(3);
  17. int projectId = 5;
  18. string priObjString = prizeObject(projectId, content);
  19. if(!string.IsNullOrEmpty(priObjString))
  20. {
  21. string[] priObjData = priObjString.Split('|');
  22. string priObj = priObjData[0];
  23. string priListIds = priObjData[1];
  24. prizeSend(projectId, priListIds, priObj, content);
  25. }
  26. }
  27. //接收入参
  28. public static Dictionary<string, string> getRequestParams(int projectId, string content)
  29. {
  30. Dictionary<string, string> dic = new Dictionary<string, string>();
  31. JsonData jsonData = JsonMapper.ToObject(content);
  32. var paramService = App.GetService<IPriProjectParamService>();
  33. var paramList = paramService.GetList(m => m.projectId == projectId);
  34. foreach(var param in paramList)
  35. {
  36. dic.Add(param.fieldEnName, jsonData[param.fieldEnName].ToString());
  37. }
  38. return dic;
  39. }
  40. //数据库链接
  41. public static SqlSugarClient initDb(int id)
  42. {
  43. var databaseSetService = App.GetService<IPriDatabaseSetService>();
  44. var connectionString = databaseSetService.GetFirst(m => m.id == id);
  45. string server = connectionString.ipAddress;
  46. int port = connectionString.port;
  47. string user = connectionString.userId;
  48. string password = connectionString.password;
  49. string database = connectionString.databaseName;
  50. var db = new SqlSugarClient(new ConnectionConfig()
  51. {
  52. ConnectionString = "server=" + server + ";port=" + port + ";user=" + user + ";password=" + password + ";database=" + database + ";charset=utf8;",
  53. DbType = DbType.MySql,
  54. IsAutoCloseConnection = true,
  55. });
  56. return db;
  57. }
  58. //查询条件匹配数据
  59. public static Dictionary<string, object> condition(int projectId, string content)
  60. {
  61. Dictionary<string, object> dic = new Dictionary<string, object>();
  62. var queryTableService = App.GetService<IPriQueryTableService>();
  63. var queryFieldService = App.GetService<IPriQueryFieldService>();
  64. var returnFieldService = App.GetService<IPriReturnFieldService>();
  65. //查询表
  66. var queryTables = queryTableService.GetList(m => m.projectId == projectId);
  67. foreach(var queryTable in queryTables)
  68. {
  69. //查询返回字段
  70. string fields = "";
  71. var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id);
  72. foreach(var returnField in returnFields)
  73. {
  74. if(returnField.fieldReturnKind == "2")
  75. {
  76. fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  77. }
  78. else if(returnField.fieldReturnKind == "3")
  79. {
  80. fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  81. }
  82. else if(returnField.fieldReturnKind == "4")
  83. {
  84. fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  85. }
  86. else
  87. {
  88. fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  89. }
  90. }
  91. fields = fields.TrimEnd(',');
  92. //查询匹配条件
  93. string condi = "";
  94. var queryFields = queryFieldService.GetList(m => m.queryTableId == queryTable.id);
  95. foreach(var queryField in queryFields)
  96. {
  97. string fieldEnName = queryField.fieldEnName;
  98. string fieldQueryKind = queryField.fieldQueryKind;
  99. string fieldQueryModel = queryField.fieldQueryModel;
  100. string fieldQueryValue = queryField.fieldQueryValue;
  101. string fieldQueryValueType = queryField.fieldQueryValueType;
  102. if(fieldQueryKind == "1") //模糊匹配
  103. {
  104. condi += " and " + fieldEnName + " like ";
  105. if(fieldQueryModel == "request_param")
  106. {
  107. Dictionary<string, string> req = getRequestParams(projectId, content);
  108. condi += "'%" + req[fieldQueryValue] + "%'";
  109. }
  110. else if(fieldQueryModel == "fixed_value")
  111. {
  112. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  113. }
  114. else if(fieldQueryModel == "db_field")
  115. {
  116. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  117. }
  118. }
  119. else if(fieldQueryKind == "2") //精确匹配
  120. {
  121. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is null";
  122. else
  123. {
  124. condi += " and " + fieldEnName + "=";
  125. string val = "";
  126. if(fieldQueryModel == "request_param")
  127. {
  128. Dictionary<string, string> req = getRequestParams(projectId, content);
  129. val = req[fieldQueryValue];
  130. }
  131. else if(fieldQueryModel == "fixed_value")
  132. {
  133. val = GetExpressionVal(fieldQueryValue);
  134. }
  135. else if(fieldQueryModel == "db_field")
  136. {
  137. val = GetDbExpressionVal(fieldQueryValue);
  138. }
  139. if(fieldQueryValueType == "text")
  140. {
  141. val = "'" + val + "'";
  142. }
  143. condi += val;
  144. }
  145. }
  146. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  147. {
  148. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  149. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  150. string val = "";
  151. string[] valList = fieldQueryValue.Split(',');
  152. if(fieldQueryModel == "request_param")
  153. {
  154. Dictionary<string, string> req = getRequestParams(projectId, content);
  155. foreach(string sub in valList)
  156. {
  157. if(fieldQueryValueType == "text")
  158. {
  159. val += "'" + req[sub] + "',";
  160. }
  161. else
  162. {
  163. val += req[sub] + ",";
  164. }
  165. }
  166. }
  167. else if(fieldQueryModel == "fixed_value")
  168. {
  169. foreach(string sub in valList)
  170. {
  171. if(fieldQueryValueType == "text")
  172. {
  173. val += "'" + GetExpressionVal(sub) + "',";
  174. }
  175. else
  176. {
  177. val += GetExpressionVal(sub) + ",";
  178. }
  179. }
  180. }
  181. else if(fieldQueryModel == "db_field")
  182. {
  183. foreach(string sub in valList)
  184. {
  185. if(fieldQueryValueType == "text")
  186. {
  187. val += "'" + GetDbExpressionVal(sub) + "',";
  188. }
  189. else
  190. {
  191. val += GetDbExpressionVal(sub) + ",";
  192. }
  193. }
  194. }
  195. val = val.TrimEnd(',');
  196. condi += val + ")";
  197. }
  198. else if(fieldQueryKind == "3") //范围匹配
  199. {
  200. string[] val = fieldQueryValue.Split(':');
  201. if(fieldQueryModel == "request_param")
  202. {
  203. Dictionary<string, string> req = getRequestParams(projectId, content);
  204. if(fieldQueryValueType == "number")
  205. {
  206. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  207. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  208. }
  209. else
  210. {
  211. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  212. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  213. }
  214. }
  215. else if(fieldQueryModel == "fixed_value")
  216. {
  217. if(fieldQueryValueType == "number")
  218. {
  219. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  220. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  221. }
  222. else
  223. {
  224. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  225. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  226. }
  227. }
  228. else if(fieldQueryModel == "db_field")
  229. {
  230. if(fieldQueryValueType == "number")
  231. {
  232. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  233. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  234. }
  235. else
  236. {
  237. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  238. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  239. }
  240. }
  241. }
  242. else if(fieldQueryKind == "4") //取反匹配
  243. {
  244. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is not null";
  245. else
  246. {
  247. condi += " and " + fieldEnName + "!=";
  248. string val = "";
  249. if(fieldQueryModel == "request_param")
  250. {
  251. Dictionary<string, string> req = getRequestParams(projectId, content);
  252. val = req[fieldQueryValue];
  253. }
  254. else if(fieldQueryModel == "fixed_value")
  255. {
  256. val = GetExpressionVal(fieldQueryValue);
  257. }
  258. else if(fieldQueryModel == "db_field")
  259. {
  260. val = GetDbExpressionVal(fieldQueryValue);
  261. }
  262. if(fieldQueryValueType == "text")
  263. {
  264. val = "'" + val + "'";
  265. }
  266. condi += val;
  267. }
  268. }
  269. }
  270. var db = initDb(queryTable.databaseId);
  271. string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
  272. var items = db.Ado.GetDataTable(sql);
  273. if(items.Rows.Count > 0)
  274. {
  275. foreach(System.Data.DataColumn item in items.Columns)
  276. {
  277. dic.Add(item.ColumnName, items.Rows[0][item.ColumnName].ToString());
  278. }
  279. }
  280. }
  281. return dic;
  282. }
  283. //奖励发放对象
  284. public static string prizeObject(int projectId, string content)
  285. {
  286. Dictionary<string, object> dic = new Dictionary<string, object>();
  287. var prizeObjectTableService = App.GetService<IPriPrizeObjectTableService>();
  288. var prizeObjectFieldService = App.GetService<IPriPrizeObjectFieldService>();
  289. //查询表
  290. var prizeObjectTable = prizeObjectTableService.GetFirst(m => m.projectId == projectId) ?? new PriPrizeObjectTable();
  291. //查询返回字段
  292. string field = prizeObjectTable.selectField;
  293. //查询匹配条件
  294. string condi = "";
  295. var queryFields = prizeObjectFieldService.GetList(m => m.objectTableId == prizeObjectTable.id);
  296. foreach(var queryField in queryFields)
  297. {
  298. string fieldEnName = queryField.fieldEnName;
  299. string fieldQueryKind = queryField.fieldQueryKind;
  300. string fieldQueryModel = queryField.fieldQueryModel;
  301. string fieldQueryValue = queryField.fieldQueryValue;
  302. string fieldQueryValueType = queryField.fieldQueryValueType;
  303. if(fieldQueryKind == "1") //模糊匹配
  304. {
  305. condi += " and " + fieldEnName + " like ";
  306. if(fieldQueryModel == "request_param")
  307. {
  308. Dictionary<string, string> req = getRequestParams(projectId, content);
  309. condi += "'%" + req[fieldQueryValue] + "%'";
  310. }
  311. else if(fieldQueryModel == "fixed_value")
  312. {
  313. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  314. }
  315. else if(fieldQueryModel == "db_field")
  316. {
  317. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  318. }
  319. }
  320. else if(fieldQueryKind == "2") //精确匹配
  321. {
  322. condi += " and " + fieldEnName + "=";
  323. string val = "";
  324. if(fieldQueryModel == "request_param")
  325. {
  326. Dictionary<string, string> req = getRequestParams(projectId, content);
  327. val = req[fieldQueryValue];
  328. }
  329. else if(fieldQueryModel == "fixed_value")
  330. {
  331. val = GetExpressionVal(fieldQueryValue);
  332. }
  333. else if(fieldQueryModel == "db_field")
  334. {
  335. val = GetDbExpressionVal(fieldQueryValue);
  336. }
  337. if(fieldQueryValueType == "text")
  338. {
  339. val = "'" + val + "'";
  340. }
  341. condi += val;
  342. }
  343. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  344. {
  345. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  346. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  347. string val = "";
  348. string[] valList = fieldQueryValue.Split(',');
  349. if(fieldQueryModel == "request_param")
  350. {
  351. Dictionary<string, string> req = getRequestParams(projectId, content);
  352. foreach(string sub in valList)
  353. {
  354. if(fieldQueryValueType == "text")
  355. {
  356. val += "'" + req[sub] + "',";
  357. }
  358. else
  359. {
  360. val += req[sub] + ",";
  361. }
  362. }
  363. }
  364. else if(fieldQueryModel == "fixed_value")
  365. {
  366. foreach(string sub in valList)
  367. {
  368. if(fieldQueryValueType == "text")
  369. {
  370. val += "'" + GetExpressionVal(sub) + "',";
  371. }
  372. else
  373. {
  374. val += GetExpressionVal(sub) + ",";
  375. }
  376. }
  377. }
  378. else if(fieldQueryModel == "db_field")
  379. {
  380. foreach(string sub in valList)
  381. {
  382. if(fieldQueryValueType == "text")
  383. {
  384. val += "'" + GetDbExpressionVal(sub) + "',";
  385. }
  386. else
  387. {
  388. val += GetDbExpressionVal(sub) + ",";
  389. }
  390. }
  391. }
  392. val = val.TrimEnd(',');
  393. condi += val + ")";
  394. }
  395. else if(fieldQueryKind == "3") //范围匹配
  396. {
  397. string[] val = fieldQueryValue.Split(':');
  398. if(fieldQueryModel == "request_param")
  399. {
  400. Dictionary<string, string> req = getRequestParams(projectId, content);
  401. if(fieldQueryValueType == "number")
  402. {
  403. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  404. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  405. }
  406. else
  407. {
  408. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  409. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  410. }
  411. }
  412. else if(fieldQueryModel == "fixed_value")
  413. {
  414. if(fieldQueryValueType == "number")
  415. {
  416. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  417. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  418. }
  419. else
  420. {
  421. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  422. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  423. }
  424. }
  425. else if(fieldQueryModel == "db_field")
  426. {
  427. if(fieldQueryValueType == "number")
  428. {
  429. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  430. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  431. }
  432. else
  433. {
  434. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  435. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  436. }
  437. }
  438. }
  439. else if(fieldQueryKind == "4") //取反匹配
  440. {
  441. condi += " and " + fieldEnName + "!=";
  442. string val = "";
  443. if(fieldQueryModel == "request_param")
  444. {
  445. Dictionary<string, string> req = getRequestParams(projectId, content);
  446. val = req[fieldQueryValue];
  447. }
  448. else if(fieldQueryModel == "fixed_value")
  449. {
  450. val = GetExpressionVal(fieldQueryValue);
  451. }
  452. else if(fieldQueryModel == "db_field")
  453. {
  454. val = GetDbExpressionVal(fieldQueryValue);
  455. }
  456. if(fieldQueryValueType == "text")
  457. {
  458. val = "'" + val + "'";
  459. }
  460. condi += val;
  461. }
  462. }
  463. var db = initDb(prizeObjectTable.databaseId);
  464. var item = db.Ado.GetScalar("select " + field + " from " + prizeObjectTable.tableEnName + " where 1=1" + condi);
  465. if(item != null)
  466. {
  467. return item.ToString() + "|" + prizeObjectTable.prizeListIds;
  468. }
  469. return "";
  470. }
  471. //奖励列表
  472. public static List<PriList> prizeList(int projectId, string prizeIds)
  473. {
  474. List<int> ids = Tools.SpitIntArrary(prizeIds, ',').ToList();
  475. var priListService = App.GetService<IPriListService>();
  476. var priList = priListService.GetList(m => m.projectId == projectId && ids.Contains(m.id)).ToList();
  477. return priList;
  478. }
  479. //奖励发放
  480. public static void prizeSend(int projectId, string prizeIds, string prizeObjectId, string content)
  481. {
  482. var priList = prizeList(projectId, prizeIds);
  483. foreach(var sub in priList)
  484. {
  485. var recursionFlag = sub.recursionFlag; //是否递归
  486. if(recursionFlag)
  487. {
  488. var loopSetService = App.GetService<IPriLoopSetService>();
  489. var recursionStartTableService = App.GetService<IPriRecursionStartTableService>();
  490. var loopSet = loopSetService.GetFirst(m => m.listId == sub.id) ?? new PriLoopSet();
  491. var recursionStartTable = recursionStartTableService.GetFirst(m => m.listId == sub.id) ?? new PriRecursionStartTable();
  492. var tableEnName = loopSet.tableEnName; //递归查询表
  493. var parentField = loopSet.parentField; //父字段
  494. var sonField = loopSet.sonField; //子字段
  495. var afterPrizeFlag = loopSet.afterPrizeFlag; //发奖后是否继续
  496. var db = initDb(recursionStartTable.databaseId);
  497. string objId = prizeObjectId;
  498. bool op = true;
  499. while(!string.IsNullOrEmpty(objId) && objId != "0" && op)
  500. {
  501. if(loopCondition(projectId, sub, objId, content))
  502. {
  503. prizeSendDo(projectId, sub, objId, content);
  504. op = afterPrizeFlag;
  505. }
  506. var parent = db.Ado.GetScalar("select " + parentField + " from " + tableEnName + " where " + sonField + "=" + objId);
  507. if(parent != null)
  508. {
  509. objId = parent.ToString();
  510. }
  511. }
  512. }
  513. else
  514. {
  515. prizeSendDo(projectId, sub, prizeObjectId, content);
  516. }
  517. }
  518. }
  519. public static void prizeSendDo(int projectId, PriList sub, string prizeObjectId, string content)
  520. {
  521. var recordService = App.GetService<IPriRecordService>();
  522. var conditionService = App.GetService<IPriConditionService>();
  523. var returnFieldService = App.GetService<IPriReturnFieldService>();
  524. var queryTableService = App.GetService<IPriQueryTableService>();
  525. var amountSetService = App.GetService<IPriListAmountSetService>();
  526. //查询匹配条件
  527. var condiDic = condition(projectId, content);
  528. var prizeSourceField = sub.prizeSourceField; //奖励金额来源字段(对应条件匹配返回字段)
  529. var prizePercent = sub.prizePercent; //奖励比例
  530. var prizeAmount = sub.prizeAmount; //奖励固定值
  531. var prizeContent = sub.prizeContent; //奖励内容
  532. var conditionMode = sub.conditionMode; //条件模式
  533. var recursionFlag = sub.recursionFlag; //是否递归
  534. var conditions = conditionService.GetList(m => m.listId == sub.id);
  535. int allCount = conditions.Count; //所有奖励条件数
  536. int passCount = 0; //通过条件数
  537. foreach(var condition in conditions)
  538. {
  539. var returnFieldId = condition.returnFieldId; //条件返回字段
  540. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  541. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  542. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  543. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  544. var returnField = returnFieldService.GetFirst(m => m.id == returnFieldId);
  545. var queryTable = queryTableService.GetFirst(m => m.id == returnField.queryTableId);
  546. var checkObj = condiDic.ContainsKey(queryTable.tableEnName + "_" + returnField.fieldEnName) ? condiDic[queryTable.tableEnName + "_" + returnField.fieldEnName] : "0";
  547. var checkVal = fieldQueryValue;
  548. if(fieldQueryKind == "1") //模糊匹配
  549. {
  550. if(fieldQueryValueType == "text")
  551. {
  552. if(checkObj.ToString().Contains(GetExpressionVal(checkVal))) passCount += 1;
  553. }
  554. }
  555. else if(fieldQueryKind == "2") //精确匹配
  556. {
  557. if(fieldQueryValueType == "int")
  558. {
  559. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal))) passCount += 1;
  560. }
  561. else if(fieldQueryValueType == "number")
  562. {
  563. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
  564. }
  565. else
  566. {
  567. if(checkObj.ToString() == GetExpressionVal(checkVal)) passCount += 1;
  568. }
  569. }
  570. else if(fieldQueryKind == "3") //范围匹配
  571. {
  572. string[] val = checkVal.Split(':');
  573. if(fieldQueryModel == "request_param")
  574. {
  575. Dictionary<string, string> req = getRequestParams(projectId, content);
  576. if(fieldQueryValueType == "number")
  577. {
  578. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(req[val[0]])) && (decimal)checkObj <= decimal.Parse(Function.CheckNum(req[val[1]]))) passCount += 1;
  579. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(req[val[0]]))) passCount += 1;
  580. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj <= decimal.Parse(Function.CheckNum(req[val[1]]))) passCount += 1;
  581. }
  582. else if(fieldQueryValueType == "int")
  583. {
  584. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (int)checkObj >= int.Parse(Function.CheckInt(req[val[0]])) && (int)checkObj <= int.Parse(Function.CheckInt(req[val[1]]))) passCount += 1;
  585. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (int)checkObj >= int.Parse(Function.CheckInt(req[val[0]]))) passCount += 1;
  586. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (int)checkObj <= int.Parse(Function.CheckInt(req[val[1]]))) passCount += 1;
  587. }
  588. else if(fieldQueryValueType.StartsWith("date"))
  589. {
  590. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj >= DateTime.Parse(req[val[0]]) && (DateTime)checkObj <= DateTime.Parse(req[val[1]])) passCount += 1;
  591. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj >= DateTime.Parse(req[val[0]])) passCount += 1;
  592. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj <= DateTime.Parse(req[val[1]])) passCount += 1;
  593. }
  594. }
  595. else if(fieldQueryModel == "fixed_value")
  596. {
  597. if(fieldQueryValueType == "number")
  598. {
  599. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(val[0])) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(val[1]))) passCount += 1;
  600. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(val[0]))) passCount += 1;
  601. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(val[1]))) passCount += 1;
  602. }
  603. else if(fieldQueryValueType == "int")
  604. {
  605. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (int)checkObj >= int.Parse(Function.CheckInt(val[0])) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(val[1]))) passCount += 1;
  606. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(val[0]))) passCount += 1;
  607. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(val[1]))) passCount += 1;
  608. }
  609. else if(fieldQueryValueType.StartsWith("date"))
  610. {
  611. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (DateTime)checkObj >= DateTime.Parse(GetExpressionVal(val[0])) && (DateTime)checkObj <= DateTime.Parse(GetExpressionVal(val[1]))) passCount += 1;
  612. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && (DateTime)checkObj >= DateTime.Parse(GetExpressionVal(val[0]))) passCount += 1;
  613. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (DateTime)checkObj <= DateTime.Parse(GetExpressionVal(val[1]))) passCount += 1;
  614. }
  615. }
  616. }
  617. else if(fieldQueryKind == "4") //取反匹配
  618. {
  619. if(fieldQueryValueType == "int")
  620. {
  621. if((int)checkObj != int.Parse(Function.CheckInt(checkVal))) passCount += 1;
  622. }
  623. else if(fieldQueryValueType == "number")
  624. {
  625. if((decimal)checkObj != decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
  626. }
  627. else if(fieldQueryValueType == "text")
  628. {
  629. if(checkObj.ToString() != GetExpressionVal(checkVal)) passCount += 1;
  630. }
  631. }
  632. }
  633. bool op = false;
  634. if(conditionMode == "all" && passCount == allCount) op = true;
  635. else if(conditionMode == "one" && passCount == 1) op = true;
  636. if(op) //满足条件
  637. {
  638. decimal number = 0;
  639. if(prizeSourceField.Contains("/"))
  640. {
  641. number = decimal.Parse(prizeSourceField.Split('/')[1]);
  642. prizeSourceField = prizeSourceField.Split('/')[0];
  643. }
  644. string prizeSourceData = "";
  645. if(prizeSourceField.Contains(","))
  646. {
  647. string[] prizeSourceFieldList = prizeSourceField.Split(',');
  648. foreach(string subField in prizeSourceFieldList)
  649. {
  650. prizeSourceData += condiDic.ContainsKey(subField) + ",";
  651. }
  652. prizeSourceData = prizeSourceData.TrimEnd(',');
  653. }
  654. else
  655. {
  656. prizeSourceData = condiDic.ContainsKey(prizeSourceField) ? condiDic[prizeSourceField].ToString() : "0";
  657. }
  658. if(string.IsNullOrEmpty(prizeSourceData)) prizeSourceData = "0";
  659. if(prizeSourceField.Contains("/") && number > 0)
  660. {
  661. decimal prizeSourceDataNum = decimal.Parse(prizeSourceData) / number;
  662. prizeSourceData = prizeSourceDataNum.ToString("f2");
  663. }
  664. decimal prizeAmt = 0;
  665. var amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField == prizeSourceData);
  666. if(amountSet != null)
  667. {
  668. prizePercent = amountSet.prizePercent;
  669. prizeAmount = amountSet.prizeAmount;
  670. }
  671. if(prizePercent > 0) prizeAmt += decimal.Parse(Function.CheckNum(prizeSourceData)) * prizePercent;
  672. if(prizeAmount > 0) prizeAmt += prizeAmount;
  673. if(prizeAmt > 0)
  674. {
  675. var req = getRequestParams(projectId, content);
  676. var requestParamField = req[sub.requestParamField];
  677. var sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == requestParamField);
  678. if(!sendFlag)
  679. {
  680. recordService.Add(new PriRecord()
  681. {
  682. createDate = DateTime.Now,
  683. projectId = projectId,
  684. listId = sub.id,
  685. prizeAmount = prizeAmt,
  686. prizeObjId = prizeObjectId,
  687. requestParamField = requestParamField,
  688. batchNo = batchNo,
  689. });
  690. // prizeToDatabase(projectId, content); //入库
  691. }
  692. }
  693. }
  694. }
  695. //递归条件判断
  696. public static bool loopCondition(int projectId, PriList sub, string objId, string content)
  697. {
  698. Dictionary<string, object> dic = new Dictionary<string, object>();
  699. var queryTableService = App.GetService<IPriRecursionStartTableService>();
  700. var queryFieldService = App.GetService<IPriRecursionStartFieldService>();
  701. int passCount = 0;
  702. //查询表
  703. var queryTables = queryTableService.GetList(m => m.listId == sub.id);
  704. int allCount = queryTables.Count;
  705. foreach(var queryTable in queryTables)
  706. {
  707. //查询返回字段
  708. string fields = "1";
  709. //查询匹配条件
  710. string condi = "";
  711. var queryFields = queryFieldService.GetList(m => m.objectTableId == queryTable.id);
  712. foreach(var queryField in queryFields)
  713. {
  714. string fieldEnName = queryField.fieldEnName;
  715. string fieldQueryKind = queryField.fieldQueryKind;
  716. string fieldQueryModel = queryField.fieldQueryModel;
  717. string fieldQueryValue = queryField.fieldQueryValue;
  718. if(fieldQueryModel == "loop_field") fieldQueryValue = objId;
  719. string fieldQueryValueType = queryField.fieldQueryValueType;
  720. if(fieldQueryKind == "1") //模糊匹配
  721. {
  722. condi += " and " + fieldEnName + " like ";
  723. if(fieldQueryModel == "request_param")
  724. {
  725. Dictionary<string, string> req = getRequestParams(projectId, content);
  726. condi += "'%" + req[fieldQueryValue] + "%'";
  727. }
  728. else if(fieldQueryModel == "fixed_value")
  729. {
  730. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  731. }
  732. else if(fieldQueryModel == "db_field")
  733. {
  734. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  735. }
  736. }
  737. else if(fieldQueryKind == "2") //精确匹配
  738. {
  739. condi += " and " + fieldEnName + "=";
  740. string val = fieldQueryValue;
  741. if(fieldQueryModel == "request_param")
  742. {
  743. Dictionary<string, string> req = getRequestParams(projectId, content);
  744. val = req[fieldQueryValue];
  745. }
  746. else if(fieldQueryModel == "fixed_value")
  747. {
  748. val = GetExpressionVal(fieldQueryValue);
  749. }
  750. else if(fieldQueryModel == "db_field")
  751. {
  752. val = GetDbExpressionVal(fieldQueryValue);
  753. }
  754. if(fieldQueryValueType == "text")
  755. {
  756. val = "'" + val + "'";
  757. }
  758. condi += val;
  759. }
  760. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  761. {
  762. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  763. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  764. string val = "";
  765. string[] valList = fieldQueryValue.Split(',');
  766. if(fieldQueryModel == "request_param")
  767. {
  768. Dictionary<string, string> req = getRequestParams(projectId, content);
  769. foreach(string subval in valList)
  770. {
  771. if(fieldQueryValueType == "text")
  772. {
  773. val += "'" + req[subval] + "',";
  774. }
  775. else
  776. {
  777. val += req[subval] + ",";
  778. }
  779. }
  780. }
  781. else if(fieldQueryModel == "fixed_value")
  782. {
  783. foreach(string subval in valList)
  784. {
  785. if(fieldQueryValueType == "text")
  786. {
  787. val += "'" + GetExpressionVal(subval) + "',";
  788. }
  789. else
  790. {
  791. val += GetExpressionVal(subval) + ",";
  792. }
  793. }
  794. }
  795. else if(fieldQueryModel == "db_field")
  796. {
  797. foreach(string subval in valList)
  798. {
  799. if(fieldQueryValueType == "text")
  800. {
  801. val += "'" + GetDbExpressionVal(subval) + "',";
  802. }
  803. else
  804. {
  805. val += GetDbExpressionVal(subval) + ",";
  806. }
  807. }
  808. }
  809. val = val.TrimEnd(',');
  810. condi += val + ")";
  811. }
  812. else if(fieldQueryKind == "3") //范围匹配
  813. {
  814. string[] val = fieldQueryValue.Split(':');
  815. if(fieldQueryModel == "request_param")
  816. {
  817. Dictionary<string, string> req = getRequestParams(projectId, content);
  818. if(fieldQueryValueType == "number")
  819. {
  820. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  821. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  822. }
  823. else
  824. {
  825. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  826. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  827. }
  828. }
  829. else if(fieldQueryModel == "fixed_value")
  830. {
  831. if(fieldQueryValueType == "number")
  832. {
  833. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  834. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  835. }
  836. else
  837. {
  838. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  839. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  840. }
  841. }
  842. else if(fieldQueryModel == "db_field")
  843. {
  844. if(fieldQueryValueType == "number")
  845. {
  846. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  847. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  848. }
  849. else
  850. {
  851. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  852. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  853. }
  854. }
  855. }
  856. else if(fieldQueryKind == "4") //取反匹配
  857. {
  858. condi += " and " + fieldEnName + "!=";
  859. string val = "";
  860. if(fieldQueryModel == "request_param")
  861. {
  862. Dictionary<string, string> req = getRequestParams(projectId, content);
  863. val = req[fieldQueryValue];
  864. }
  865. else if(fieldQueryModel == "fixed_value")
  866. {
  867. val = GetExpressionVal(fieldQueryValue);
  868. }
  869. else if(fieldQueryModel == "db_field")
  870. {
  871. val = GetDbExpressionVal(fieldQueryValue);
  872. }
  873. if(fieldQueryValueType == "text")
  874. {
  875. val = "'" + val + "'";
  876. }
  877. condi += val;
  878. }
  879. }
  880. var db = initDb(queryTable.databaseId);
  881. var item = db.Ado.GetScalar("select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi);
  882. if(item != null) passCount += 1;
  883. }
  884. bool op = false;
  885. if(sub.conditionMode == "all" && passCount == allCount) op = true;
  886. else if(sub.conditionMode == "one" && passCount == 1) op = true;
  887. return op;
  888. }
  889. //奖励入库
  890. public static void prizeToDatabase(int projectId, string content)
  891. {
  892. var prizeInTableService = App.GetService<IPriPrizeInTableService>();
  893. var prizeInFieldService = App.GetService<IPriPrizeInFieldService>();
  894. var prizeInQueryFieldService = App.GetService<IPriPrizeInQueryFieldService>();
  895. //入库表
  896. var prizeInTables = prizeInTableService.GetList(m => m.projectId == projectId);
  897. foreach(var prizeInTable in prizeInTables)
  898. {
  899. var db = initDb(prizeInTable.databaseId);
  900. Dictionary<string, object> doFields = new Dictionary<string, object>();
  901. //入库字段
  902. var prizeInFields = prizeInFieldService.GetList(m => m.inTableId == prizeInTable.id);
  903. foreach(var prizeInField in prizeInFields)
  904. {
  905. string fieldEnName = prizeInField.fieldEnName;
  906. string fieldQueryModel = prizeInField.fieldQueryModel;
  907. string fieldQueryValue = prizeInField.fieldQueryValue;
  908. string fieldQueryValueType = prizeInField.fieldQueryValueType;
  909. if(fieldQueryModel == "request_param")
  910. {
  911. Dictionary<string, string> req = getRequestParams(projectId, content);
  912. fieldQueryValue = req[fieldQueryValue];
  913. }
  914. else if(fieldQueryModel == "fixed_value")
  915. {
  916. fieldQueryValue = GetExpressionVal(fieldQueryValue);
  917. }
  918. else if(fieldQueryModel == "db_field")
  919. {
  920. fieldQueryValue = GetDbExpressionVal(fieldQueryValue);
  921. }
  922. if(fieldQueryValueType == "text") doFields.Add(fieldEnName, fieldQueryValue);
  923. if(fieldQueryValueType == "int") doFields.Add(fieldEnName, int.Parse(fieldQueryValue));
  924. if(fieldQueryValueType == "number") doFields.Add(fieldEnName, decimal.Parse(fieldQueryValue));
  925. if(fieldQueryValueType == "datetime") doFields.Add(fieldEnName, DateTime.Parse(fieldQueryValue));
  926. if(fieldQueryValueType == "bool") doFields.Add(fieldEnName, bool.Parse(fieldQueryValue));
  927. }
  928. //查询匹配条件
  929. string condi = "";
  930. var queryFields = prizeInQueryFieldService.GetList(m => m.inTableId == prizeInTable.id);
  931. foreach(var queryField in queryFields)
  932. {
  933. string fieldEnName = queryField.fieldEnName;
  934. string fieldQueryKind = queryField.fieldQueryKind;
  935. string fieldQueryModel = queryField.fieldQueryModel;
  936. string fieldQueryValue = queryField.fieldQueryValue;
  937. string fieldQueryValueType = queryField.fieldQueryValueType;
  938. if(fieldQueryKind == "1") //模糊匹配
  939. {
  940. condi += " and " + fieldEnName + " like ";
  941. if(fieldQueryModel == "request_param")
  942. {
  943. Dictionary<string, string> req = getRequestParams(projectId, content);
  944. condi += "'%" + req[fieldQueryValue] + "%'";
  945. }
  946. else if(fieldQueryModel == "fixed_value")
  947. {
  948. condi += "'%" + fieldQueryValue + "%'";
  949. }
  950. }
  951. else if(fieldQueryKind == "2") //精确匹配
  952. {
  953. condi += " and " + fieldEnName + "=";
  954. string val = "";
  955. if(fieldQueryModel == "request_param")
  956. {
  957. Dictionary<string, string> req = getRequestParams(projectId, content);
  958. val = req[fieldQueryValue];
  959. }
  960. else if(fieldQueryModel == "fixed_value")
  961. {
  962. val = fieldQueryValue;
  963. }
  964. if(fieldQueryValueType == "text")
  965. {
  966. val = "'" + val + "'";
  967. }
  968. condi += val;
  969. }
  970. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  971. {
  972. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  973. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  974. string val = "";
  975. string[] valList = fieldQueryValue.Split(',');
  976. if(fieldQueryModel == "request_param")
  977. {
  978. Dictionary<string, string> req = getRequestParams(projectId, content);
  979. foreach(string sub in valList)
  980. {
  981. if(fieldQueryValueType == "text")
  982. {
  983. val += "'" + req[sub] + "',";
  984. }
  985. else
  986. {
  987. val += req[sub] + ",";
  988. }
  989. }
  990. }
  991. else if(fieldQueryModel == "fixed_value")
  992. {
  993. foreach(string sub in valList)
  994. {
  995. if(fieldQueryValueType == "text")
  996. {
  997. val += "'" + GetExpressionVal(sub) + "',";
  998. }
  999. else
  1000. {
  1001. val += GetExpressionVal(sub) + ",";
  1002. }
  1003. }
  1004. }
  1005. else if(fieldQueryModel == "db_field")
  1006. {
  1007. foreach(string sub in valList)
  1008. {
  1009. if(fieldQueryValueType == "text")
  1010. {
  1011. val += "'" + GetDbExpressionVal(sub) + "',";
  1012. }
  1013. else
  1014. {
  1015. val += GetDbExpressionVal(sub) + ",";
  1016. }
  1017. }
  1018. }
  1019. val = val.TrimEnd(',');
  1020. condi += val + ")";
  1021. }
  1022. else if(fieldQueryKind == "3") //范围匹配
  1023. {
  1024. string[] val = fieldQueryValue.Split(':');
  1025. if(fieldQueryModel == "request_param")
  1026. {
  1027. Dictionary<string, string> req = getRequestParams(projectId, content);
  1028. if(fieldQueryValueType == "number")
  1029. {
  1030. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  1031. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  1032. }
  1033. else
  1034. {
  1035. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  1036. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  1037. }
  1038. }
  1039. else if(fieldQueryModel == "fixed_value")
  1040. {
  1041. if(fieldQueryValueType == "number")
  1042. {
  1043. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1044. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1045. }
  1046. else
  1047. {
  1048. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + val[0] + "'";
  1049. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + val[1] + "'";
  1050. }
  1051. }
  1052. }
  1053. else if(fieldQueryKind == "4") //取反匹配
  1054. {
  1055. condi += " and " + fieldEnName + "!=";
  1056. string val = "";
  1057. if(fieldQueryModel == "request_param")
  1058. {
  1059. Dictionary<string, string> req = getRequestParams(projectId, content);
  1060. val = req[fieldQueryValue];
  1061. }
  1062. else if(fieldQueryModel == "fixed_value")
  1063. {
  1064. val = fieldQueryValue;
  1065. }
  1066. if(fieldQueryValueType == "text")
  1067. {
  1068. val = "'" + val + "'";
  1069. }
  1070. condi += val;
  1071. }
  1072. }
  1073. if(prizeInTable.excuteKind == "add") db.Insertable(doFields).ExecuteCommand();
  1074. if(prizeInTable.excuteKind == "update") db.Updateable(doFields).Where("1=1" + condi).ExecuteCommand();
  1075. }
  1076. }
  1077. //固定值表达式
  1078. public static string GetExpressionVal(string str)
  1079. {
  1080. if(str == "#{now}#") str = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1081. if(str == "#{today}#") str = DateTime.Now.ToString("yyyy-MM-dd");
  1082. if(str == "#{this_month}#") str = DateTime.Now.ToString("yyyy-MM");
  1083. if(str.StartsWith("#{now") && str.EndsWith("DAY}#")) str = DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
  1084. if(str.StartsWith("#{now") && str.EndsWith("MONTH}#")) str = DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
  1085. if(str.StartsWith("#{today") && str.EndsWith("DAY}#")) str = DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1086. if(str.StartsWith("#{today") && str.EndsWith("MONTH}#")) str = DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1087. if(str.StartsWith("#{this_month") && str.EndsWith("DAY}#")) str = DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1088. if(str.StartsWith("#{this_month") && str.EndsWith("MONTH}#")) str = DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1089. return str;
  1090. }
  1091. //库内字段值表达式
  1092. public static string GetDbExpressionVal(string str)
  1093. {
  1094. if(str.StartsWith("#{now") && str.EndsWith("DAY}#")) str = "DATE_ADD(" + str + ",INTERVAL " + str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1] + " DAY)";
  1095. if(str.StartsWith("#{now") && str.EndsWith("MONTH}#")) str = "DATE_ADD(" + str + ",INTERVAL " + str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1] + " MONTH)";
  1096. return str;
  1097. }
  1098. }
  1099. }