PrizeDo.cs 59 KB

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