PrizeDo.cs 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  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 checkObj = condiDic.ContainsKey(returnFieldId) ? condiDic[returnFieldId] : "0";
  545. var checkVal = fieldQueryValue;
  546. if(fieldQueryKind == "1") //模糊匹配
  547. {
  548. if(fieldQueryValueType == "text")
  549. {
  550. if(checkObj.ToString().Contains(GetExpressionVal(checkVal))) passCount += 1;
  551. }
  552. }
  553. else if(fieldQueryKind == "2") //精确匹配
  554. {
  555. if(fieldQueryValueType == "int")
  556. {
  557. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal))) passCount += 1;
  558. }
  559. else if(fieldQueryValueType == "number")
  560. {
  561. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
  562. }
  563. else
  564. {
  565. if(checkObj.ToString() == GetExpressionVal(checkVal)) passCount += 1;
  566. }
  567. }
  568. else if(fieldQueryKind == "3") //范围匹配
  569. {
  570. string[] val = checkVal.Split(':');
  571. if(fieldQueryModel == "request_param")
  572. {
  573. Dictionary<string, string> req = getRequestParams(projectId, content);
  574. if(fieldQueryValueType == "number")
  575. {
  576. 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;
  577. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(req[val[0]]))) passCount += 1;
  578. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj <= decimal.Parse(Function.CheckNum(req[val[1]]))) passCount += 1;
  579. }
  580. else if(fieldQueryValueType == "int")
  581. {
  582. 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;
  583. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (int)checkObj >= int.Parse(Function.CheckInt(req[val[0]]))) passCount += 1;
  584. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (int)checkObj <= int.Parse(Function.CheckInt(req[val[1]]))) passCount += 1;
  585. }
  586. else if(fieldQueryValueType.StartsWith("date"))
  587. {
  588. 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;
  589. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj >= DateTime.Parse(req[val[0]])) passCount += 1;
  590. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj <= DateTime.Parse(req[val[1]])) passCount += 1;
  591. }
  592. }
  593. else if(fieldQueryModel == "fixed_value")
  594. {
  595. if(fieldQueryValueType == "number")
  596. {
  597. 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;
  598. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(val[0]))) passCount += 1;
  599. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(val[1]))) passCount += 1;
  600. }
  601. else if(fieldQueryValueType == "int")
  602. {
  603. 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;
  604. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(val[0]))) passCount += 1;
  605. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(val[1]))) passCount += 1;
  606. }
  607. else if(fieldQueryValueType.StartsWith("date"))
  608. {
  609. 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;
  610. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && (DateTime)checkObj >= DateTime.Parse(GetExpressionVal(val[0]))) passCount += 1;
  611. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (DateTime)checkObj <= DateTime.Parse(GetExpressionVal(val[1]))) passCount += 1;
  612. }
  613. }
  614. }
  615. else if(fieldQueryKind == "4") //取反匹配
  616. {
  617. if(fieldQueryValueType == "int")
  618. {
  619. if((int)checkObj != int.Parse(Function.CheckInt(checkVal))) passCount += 1;
  620. }
  621. else if(fieldQueryValueType == "number")
  622. {
  623. if((decimal)checkObj != decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
  624. }
  625. else if(fieldQueryValueType == "text")
  626. {
  627. if(checkObj.ToString() != GetExpressionVal(checkVal)) passCount += 1;
  628. }
  629. }
  630. }
  631. bool op = false;
  632. if(conditionMode == "all" && passCount == allCount) op = true;
  633. else if(conditionMode == "one" && passCount == 1) op = true;
  634. if(op) //满足条件
  635. {
  636. decimal number = 0;
  637. if(prizeSourceField.Contains("/"))
  638. {
  639. number = decimal.Parse(prizeSourceField.Split('/')[1]);
  640. prizeSourceField = prizeSourceField.Split('/')[0];
  641. }
  642. string prizeSourceData = "";
  643. if(prizeSourceField.Contains(","))
  644. {
  645. string[] prizeSourceFieldList = prizeSourceField.Split(',');
  646. foreach(string subField in prizeSourceFieldList)
  647. {
  648. prizeSourceData += condiDic.ContainsKey(subField) + ",";
  649. }
  650. prizeSourceData = prizeSourceData.TrimEnd(',');
  651. }
  652. else
  653. {
  654. prizeSourceData = condiDic.ContainsKey(prizeSourceField) ? condiDic[prizeSourceField].ToString() : "0";
  655. }
  656. if(string.IsNullOrEmpty(prizeSourceData)) prizeSourceData = "0";
  657. if(prizeSourceField.Contains("/") && number > 0)
  658. {
  659. decimal prizeSourceDataNum = decimal.Parse(prizeSourceData) / number;
  660. prizeSourceData = prizeSourceDataNum.ToString("f2");
  661. }
  662. decimal prizeAmt = 0;
  663. var amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField == prizeSourceData);
  664. if(amountSet != null)
  665. {
  666. prizePercent = amountSet.prizePercent;
  667. prizeAmount = amountSet.prizeAmount;
  668. }
  669. if(prizeSourceData.Contains(","))
  670. {
  671. string checkField = prizeSourceData.Split(',')[0] + ",";
  672. amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField.StartsWith(checkField) && m.prizeSourceField.EndsWith(",%"));
  673. if(amountSet != null)
  674. {
  675. prizePercent = amountSet.prizePercent;
  676. prizeAmount = amountSet.prizeAmount;
  677. prizeSourceData = prizeSourceData.Split(',')[1];
  678. }
  679. }
  680. if(prizePercent > 0) prizeAmt += decimal.Parse(Function.CheckNum(prizeSourceData)) * prizePercent;
  681. if(prizeAmount > 0) prizeAmt += prizeAmount;
  682. if(prizeAmt > 0)
  683. {
  684. var req = getRequestParams(projectId, content);
  685. var requestParamField = req[sub.requestParamField];
  686. var sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == requestParamField);
  687. if(!sendFlag)
  688. {
  689. recordService.Add(new PriRecord()
  690. {
  691. createDate = DateTime.Now,
  692. projectId = projectId,
  693. listId = sub.id,
  694. prizeAmount = prizeAmt,
  695. prizeObjId = prizeObjectId,
  696. requestParamField = requestParamField,
  697. batchNo = batchNo,
  698. });
  699. // prizeToDatabase(projectId, content); //入库
  700. }
  701. }
  702. }
  703. }
  704. //递归条件判断
  705. public static bool loopCondition(int projectId, PriList sub, string objId, string content)
  706. {
  707. Dictionary<string, object> dic = new Dictionary<string, object>();
  708. var queryTableService = App.GetService<IPriRecursionStartTableService>();
  709. var queryFieldService = App.GetService<IPriRecursionStartFieldService>();
  710. int passCount = 0;
  711. //查询表
  712. var queryTables = queryTableService.GetList(m => m.listId == sub.id);
  713. int allCount = queryTables.Count;
  714. foreach(var queryTable in queryTables)
  715. {
  716. //查询返回字段
  717. string fields = "1";
  718. //查询匹配条件
  719. string condi = "";
  720. var queryFields = queryFieldService.GetList(m => m.objectTableId == queryTable.id);
  721. foreach(var queryField in queryFields)
  722. {
  723. string fieldEnName = queryField.fieldEnName;
  724. string fieldQueryKind = queryField.fieldQueryKind;
  725. string fieldQueryModel = queryField.fieldQueryModel;
  726. string fieldQueryValue = queryField.fieldQueryValue;
  727. if(fieldQueryModel == "loop_field") fieldQueryValue = objId;
  728. string fieldQueryValueType = queryField.fieldQueryValueType;
  729. if(fieldQueryKind == "1") //模糊匹配
  730. {
  731. condi += " and " + fieldEnName + " like ";
  732. if(fieldQueryModel == "request_param")
  733. {
  734. Dictionary<string, string> req = getRequestParams(projectId, content);
  735. condi += "'%" + req[fieldQueryValue] + "%'";
  736. }
  737. else if(fieldQueryModel == "fixed_value")
  738. {
  739. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  740. }
  741. else if(fieldQueryModel == "db_field")
  742. {
  743. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  744. }
  745. }
  746. else if(fieldQueryKind == "2") //精确匹配
  747. {
  748. condi += " and " + fieldEnName + "=";
  749. string val = fieldQueryValue;
  750. if(fieldQueryModel == "request_param")
  751. {
  752. Dictionary<string, string> req = getRequestParams(projectId, content);
  753. val = req[fieldQueryValue];
  754. }
  755. else if(fieldQueryModel == "fixed_value")
  756. {
  757. val = GetExpressionVal(fieldQueryValue);
  758. }
  759. else if(fieldQueryModel == "db_field")
  760. {
  761. val = GetDbExpressionVal(fieldQueryValue);
  762. }
  763. if(fieldQueryValueType == "text")
  764. {
  765. val = "'" + val + "'";
  766. }
  767. condi += val;
  768. }
  769. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  770. {
  771. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  772. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  773. string val = "";
  774. string[] valList = fieldQueryValue.Split(',');
  775. if(fieldQueryModel == "request_param")
  776. {
  777. Dictionary<string, string> req = getRequestParams(projectId, content);
  778. foreach(string subval in valList)
  779. {
  780. if(fieldQueryValueType == "text")
  781. {
  782. val += "'" + req[subval] + "',";
  783. }
  784. else
  785. {
  786. val += req[subval] + ",";
  787. }
  788. }
  789. }
  790. else if(fieldQueryModel == "fixed_value")
  791. {
  792. foreach(string subval in valList)
  793. {
  794. if(fieldQueryValueType == "text")
  795. {
  796. val += "'" + GetExpressionVal(subval) + "',";
  797. }
  798. else
  799. {
  800. val += GetExpressionVal(subval) + ",";
  801. }
  802. }
  803. }
  804. else if(fieldQueryModel == "db_field")
  805. {
  806. foreach(string subval in valList)
  807. {
  808. if(fieldQueryValueType == "text")
  809. {
  810. val += "'" + GetDbExpressionVal(subval) + "',";
  811. }
  812. else
  813. {
  814. val += GetDbExpressionVal(subval) + ",";
  815. }
  816. }
  817. }
  818. val = val.TrimEnd(',');
  819. condi += val + ")";
  820. }
  821. else if(fieldQueryKind == "3") //范围匹配
  822. {
  823. string[] val = fieldQueryValue.Split(':');
  824. if(fieldQueryModel == "request_param")
  825. {
  826. Dictionary<string, string> req = getRequestParams(projectId, content);
  827. if(fieldQueryValueType == "number")
  828. {
  829. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  830. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  831. }
  832. else
  833. {
  834. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  835. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  836. }
  837. }
  838. else if(fieldQueryModel == "fixed_value")
  839. {
  840. if(fieldQueryValueType == "number")
  841. {
  842. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  843. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  844. }
  845. else
  846. {
  847. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  848. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  849. }
  850. }
  851. else if(fieldQueryModel == "db_field")
  852. {
  853. if(fieldQueryValueType == "number")
  854. {
  855. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  856. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  857. }
  858. else
  859. {
  860. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  861. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  862. }
  863. }
  864. }
  865. else if(fieldQueryKind == "4") //取反匹配
  866. {
  867. condi += " and " + fieldEnName + "!=";
  868. string val = "";
  869. if(fieldQueryModel == "request_param")
  870. {
  871. Dictionary<string, string> req = getRequestParams(projectId, content);
  872. val = req[fieldQueryValue];
  873. }
  874. else if(fieldQueryModel == "fixed_value")
  875. {
  876. val = GetExpressionVal(fieldQueryValue);
  877. }
  878. else if(fieldQueryModel == "db_field")
  879. {
  880. val = GetDbExpressionVal(fieldQueryValue);
  881. }
  882. if(fieldQueryValueType == "text")
  883. {
  884. val = "'" + val + "'";
  885. }
  886. condi += val;
  887. }
  888. }
  889. var db = initDb(queryTable.databaseId);
  890. var item = db.Ado.GetScalar("select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi);
  891. if(item != null) passCount += 1;
  892. }
  893. bool op = false;
  894. if(sub.conditionMode == "all" && passCount == allCount) op = true;
  895. else if(sub.conditionMode == "one" && passCount == 1) op = true;
  896. return op;
  897. }
  898. //奖励入库
  899. public static void prizeToDatabase(int projectId, string content)
  900. {
  901. var prizeInTableService = App.GetService<IPriPrizeInTableService>();
  902. var prizeInFieldService = App.GetService<IPriPrizeInFieldService>();
  903. var prizeInQueryFieldService = App.GetService<IPriPrizeInQueryFieldService>();
  904. //入库表
  905. var prizeInTables = prizeInTableService.GetList(m => m.projectId == projectId);
  906. foreach(var prizeInTable in prizeInTables)
  907. {
  908. var db = initDb(prizeInTable.databaseId);
  909. Dictionary<string, object> doFields = new Dictionary<string, object>();
  910. //入库字段
  911. var prizeInFields = prizeInFieldService.GetList(m => m.inTableId == prizeInTable.id);
  912. foreach(var prizeInField in prizeInFields)
  913. {
  914. string fieldEnName = prizeInField.fieldEnName;
  915. string fieldQueryModel = prizeInField.fieldQueryModel;
  916. string fieldQueryValue = prizeInField.fieldQueryValue;
  917. string fieldQueryValueType = prizeInField.fieldQueryValueType;
  918. if(fieldQueryModel == "request_param")
  919. {
  920. Dictionary<string, string> req = getRequestParams(projectId, content);
  921. fieldQueryValue = req[fieldQueryValue];
  922. }
  923. else if(fieldQueryModel == "fixed_value")
  924. {
  925. fieldQueryValue = GetExpressionVal(fieldQueryValue);
  926. }
  927. else if(fieldQueryModel == "db_field")
  928. {
  929. fieldQueryValue = GetDbExpressionVal(fieldQueryValue);
  930. }
  931. if(fieldQueryValueType == "text") doFields.Add(fieldEnName, fieldQueryValue);
  932. if(fieldQueryValueType == "int") doFields.Add(fieldEnName, int.Parse(fieldQueryValue));
  933. if(fieldQueryValueType == "number") doFields.Add(fieldEnName, decimal.Parse(fieldQueryValue));
  934. if(fieldQueryValueType == "datetime") doFields.Add(fieldEnName, DateTime.Parse(fieldQueryValue));
  935. if(fieldQueryValueType == "bool") doFields.Add(fieldEnName, bool.Parse(fieldQueryValue));
  936. }
  937. //查询匹配条件
  938. string condi = "";
  939. var queryFields = prizeInQueryFieldService.GetList(m => m.inTableId == prizeInTable.id);
  940. foreach(var queryField in queryFields)
  941. {
  942. string fieldEnName = queryField.fieldEnName;
  943. string fieldQueryKind = queryField.fieldQueryKind;
  944. string fieldQueryModel = queryField.fieldQueryModel;
  945. string fieldQueryValue = queryField.fieldQueryValue;
  946. string fieldQueryValueType = queryField.fieldQueryValueType;
  947. if(fieldQueryKind == "1") //模糊匹配
  948. {
  949. condi += " and " + fieldEnName + " like ";
  950. if(fieldQueryModel == "request_param")
  951. {
  952. Dictionary<string, string> req = getRequestParams(projectId, content);
  953. condi += "'%" + req[fieldQueryValue] + "%'";
  954. }
  955. else if(fieldQueryModel == "fixed_value")
  956. {
  957. condi += "'%" + fieldQueryValue + "%'";
  958. }
  959. }
  960. else if(fieldQueryKind == "2") //精确匹配
  961. {
  962. condi += " and " + fieldEnName + "=";
  963. string val = "";
  964. if(fieldQueryModel == "request_param")
  965. {
  966. Dictionary<string, string> req = getRequestParams(projectId, content);
  967. val = req[fieldQueryValue];
  968. }
  969. else if(fieldQueryModel == "fixed_value")
  970. {
  971. val = fieldQueryValue;
  972. }
  973. if(fieldQueryValueType == "text")
  974. {
  975. val = "'" + val + "'";
  976. }
  977. condi += val;
  978. }
  979. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  980. {
  981. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  982. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  983. string val = "";
  984. string[] valList = fieldQueryValue.Split(',');
  985. if(fieldQueryModel == "request_param")
  986. {
  987. Dictionary<string, string> req = getRequestParams(projectId, content);
  988. foreach(string sub in valList)
  989. {
  990. if(fieldQueryValueType == "text")
  991. {
  992. val += "'" + req[sub] + "',";
  993. }
  994. else
  995. {
  996. val += req[sub] + ",";
  997. }
  998. }
  999. }
  1000. else if(fieldQueryModel == "fixed_value")
  1001. {
  1002. foreach(string sub in valList)
  1003. {
  1004. if(fieldQueryValueType == "text")
  1005. {
  1006. val += "'" + GetExpressionVal(sub) + "',";
  1007. }
  1008. else
  1009. {
  1010. val += GetExpressionVal(sub) + ",";
  1011. }
  1012. }
  1013. }
  1014. else if(fieldQueryModel == "db_field")
  1015. {
  1016. foreach(string sub in valList)
  1017. {
  1018. if(fieldQueryValueType == "text")
  1019. {
  1020. val += "'" + GetDbExpressionVal(sub) + "',";
  1021. }
  1022. else
  1023. {
  1024. val += GetDbExpressionVal(sub) + ",";
  1025. }
  1026. }
  1027. }
  1028. val = val.TrimEnd(',');
  1029. condi += val + ")";
  1030. }
  1031. else if(fieldQueryKind == "3") //范围匹配
  1032. {
  1033. string[] val = fieldQueryValue.Split(':');
  1034. if(fieldQueryModel == "request_param")
  1035. {
  1036. Dictionary<string, string> req = getRequestParams(projectId, content);
  1037. if(fieldQueryValueType == "number")
  1038. {
  1039. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  1040. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  1041. }
  1042. else
  1043. {
  1044. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  1045. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  1046. }
  1047. }
  1048. else if(fieldQueryModel == "fixed_value")
  1049. {
  1050. if(fieldQueryValueType == "number")
  1051. {
  1052. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1053. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1054. }
  1055. else
  1056. {
  1057. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + val[0] + "'";
  1058. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + val[1] + "'";
  1059. }
  1060. }
  1061. }
  1062. else if(fieldQueryKind == "4") //取反匹配
  1063. {
  1064. condi += " and " + fieldEnName + "!=";
  1065. string val = "";
  1066. if(fieldQueryModel == "request_param")
  1067. {
  1068. Dictionary<string, string> req = getRequestParams(projectId, content);
  1069. val = req[fieldQueryValue];
  1070. }
  1071. else if(fieldQueryModel == "fixed_value")
  1072. {
  1073. val = fieldQueryValue;
  1074. }
  1075. if(fieldQueryValueType == "text")
  1076. {
  1077. val = "'" + val + "'";
  1078. }
  1079. condi += val;
  1080. }
  1081. }
  1082. if(prizeInTable.excuteKind == "add") db.Insertable(doFields).ExecuteCommand();
  1083. if(prizeInTable.excuteKind == "update") db.Updateable(doFields).Where("1=1" + condi).ExecuteCommand();
  1084. }
  1085. }
  1086. //固定值表达式
  1087. public static string GetExpressionVal(string str)
  1088. {
  1089. if(str == "#{now}#") str = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1090. if(str == "#{today}#") str = DateTime.Now.ToString("yyyy-MM-dd");
  1091. if(str == "#{this_month}#") str = DateTime.Now.ToString("yyyy-MM");
  1092. 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");
  1093. 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");
  1094. if(str.StartsWith("#{today") && str.EndsWith("DAY}#")) str = DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1095. if(str.StartsWith("#{today") && str.EndsWith("MONTH}#")) str = DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1096. if(str.StartsWith("#{this_month") && str.EndsWith("DAY}#")) str = DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1097. if(str.StartsWith("#{this_month") && str.EndsWith("MONTH}#")) str = DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1098. return str;
  1099. }
  1100. //库内字段值表达式
  1101. public static string GetDbExpressionVal(string str)
  1102. {
  1103. if(str.StartsWith("#{now") && str.EndsWith("DAY}#")) str = "DATE_ADD(" + str + ",INTERVAL " + str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1] + " DAY)";
  1104. if(str.StartsWith("#{now") && str.EndsWith("MONTH}#")) str = "DATE_ADD(" + str + ",INTERVAL " + str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1] + " MONTH)";
  1105. return str;
  1106. }
  1107. }
  1108. }