PrizeDo.cs 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  1. using System.Data;
  2. using Common;
  3. using Infrastructure;
  4. using LitJson;
  5. using Microsoft.Extensions.Localization;
  6. using Model;
  7. using NuGet.Packaging;
  8. using Services;
  9. namespace Util
  10. {
  11. public class PrizeDo
  12. {
  13. public static string batchNo = "";
  14. //发奖入口
  15. public static void sendPrize(string content)
  16. {
  17. batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(3);
  18. JsonData jsonObj = JsonMapper.ToObject(content);
  19. string priObjString = prizeInSet(jsonObj["prize_tag"].ToString());
  20. if(!string.IsNullOrEmpty(priObjString))
  21. {
  22. string[] priObjData = priObjString.Split('|');
  23. string priListIds = priObjData[0];
  24. int projectId = int.Parse(priObjData[1]);
  25. prizeSend(projectId, priListIds, content);
  26. }
  27. }
  28. //接收入参
  29. public static Dictionary<string, string> getRequestParams(int projectId, string content)
  30. {
  31. Dictionary<string, string> dic = new Dictionary<string, string>();
  32. JsonData jsonData = JsonMapper.ToObject(content);
  33. var paramService = App.GetService<IPriProjectParamService>();
  34. var paramList = paramService.GetList(m => m.projectId == projectId);
  35. foreach(var param in paramList)
  36. {
  37. if(content.Contains("\"" + param.fieldEnName + "\"")) dic.Add(param.fieldEnName, jsonData[param.fieldEnName].ToString());
  38. }
  39. return dic;
  40. }
  41. //数据库链接
  42. public static SqlSugarClient initDb(int id)
  43. {
  44. var databaseSetService = App.GetService<IPriDatabaseSetService>();
  45. var connectionString = databaseSetService.GetFirst(m => m.id == id);
  46. string server = connectionString.ipAddress;
  47. int port = connectionString.port;
  48. string user = connectionString.userId;
  49. string password = connectionString.password;
  50. string database = connectionString.databaseName;
  51. var db = new SqlSugarClient(new ConnectionConfig()
  52. {
  53. ConnectionString = "server=" + server + ";port=" + port + ";user=" + user + ";password=" + password + ";database=" + database + ";charset=utf8;",
  54. DbType = SqlSugar.DbType.MySql,
  55. IsAutoCloseConnection = true,
  56. });
  57. return db;
  58. }
  59. //查询条件匹配数据
  60. public static Dictionary<string, object> condition(int projectId, string content)
  61. {
  62. Dictionary<string, object> dic = new Dictionary<string, object>();
  63. var queryTableService = App.GetService<IPriQueryTableService>();
  64. var queryFieldService = App.GetService<IPriQueryFieldService>();
  65. var returnFieldService = App.GetService<IPriReturnFieldService>();
  66. //查询表
  67. var queryTables = queryTableService.GetList(m => m.projectId == projectId);
  68. foreach(var queryTable in queryTables)
  69. {
  70. //查询返回字段
  71. string fields = "";
  72. var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id);
  73. foreach(var returnField in returnFields)
  74. {
  75. if(returnField.fieldReturnKind == "2")
  76. {
  77. fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  78. }
  79. else if(returnField.fieldReturnKind == "3")
  80. {
  81. fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  82. }
  83. else if(returnField.fieldReturnKind == "4")
  84. {
  85. fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  86. }
  87. else
  88. {
  89. fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  90. }
  91. }
  92. fields = fields.TrimEnd(',');
  93. //查询匹配条件
  94. string condi = "";
  95. var queryFields = queryFieldService.GetList(m => m.queryTableId == queryTable.id);
  96. foreach(var queryField in queryFields)
  97. {
  98. string fieldEnName = queryField.fieldEnName;
  99. string fieldQueryKind = queryField.fieldQueryKind;
  100. string fieldQueryModel = queryField.fieldQueryModel;
  101. string fieldQueryValue = queryField.fieldQueryValue;
  102. string fieldQueryValueType = queryField.fieldQueryValueType;
  103. if(fieldQueryKind == "1") //模糊匹配
  104. {
  105. condi += " and " + fieldEnName + " like ";
  106. if(fieldQueryModel == "request_param")
  107. {
  108. Dictionary<string, string> req = getRequestParams(projectId, content);
  109. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  110. condi += "'%" + val + "%'";
  111. }
  112. else if(fieldQueryModel == "fixed_value")
  113. {
  114. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  115. }
  116. else if(fieldQueryModel == "db_field")
  117. {
  118. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  119. }
  120. else if(fieldQueryModel == "query_field")
  121. {
  122. string val = dic.ContainsKey(fieldQueryValue) ? dic[fieldQueryValue].ToString() : "0";
  123. condi += "'%" + val + "%'";
  124. }
  125. }
  126. else if(fieldQueryKind == "2") //精确匹配
  127. {
  128. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is null";
  129. else
  130. {
  131. condi += " and " + fieldEnName + "=";
  132. string val = "";
  133. if(fieldQueryModel == "request_param")
  134. {
  135. Dictionary<string, string> req = getRequestParams(projectId, content);
  136. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  137. }
  138. else if(fieldQueryModel == "fixed_value")
  139. {
  140. val = GetExpressionVal(fieldQueryValue);
  141. }
  142. else if(fieldQueryModel == "db_field")
  143. {
  144. val = GetDbExpressionVal(fieldQueryValue);
  145. }
  146. else if(fieldQueryModel == "query_field")
  147. {
  148. val = dic.ContainsKey(fieldQueryValue) ? dic[fieldQueryValue].ToString() : "0";
  149. }
  150. if(fieldQueryValueType == "text")
  151. {
  152. val = "'" + val + "'";
  153. }
  154. condi += val;
  155. }
  156. }
  157. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  158. {
  159. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  160. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  161. string val = "";
  162. string[] valList = fieldQueryValue.Split(',');
  163. if(fieldQueryModel == "request_param")
  164. {
  165. Dictionary<string, string> req = getRequestParams(projectId, content);
  166. foreach(string sub in valList)
  167. {
  168. if(fieldQueryValueType == "text")
  169. {
  170. val += "'" + req[sub] + "',";
  171. }
  172. else
  173. {
  174. val += req[sub] + ",";
  175. }
  176. }
  177. }
  178. else if(fieldQueryModel == "fixed_value")
  179. {
  180. foreach(string sub in valList)
  181. {
  182. if(fieldQueryValueType == "text")
  183. {
  184. val += "'" + GetExpressionVal(sub) + "',";
  185. }
  186. else
  187. {
  188. val += GetExpressionVal(sub) + ",";
  189. }
  190. }
  191. }
  192. else if(fieldQueryModel == "db_field")
  193. {
  194. foreach(string sub in valList)
  195. {
  196. if(fieldQueryValueType == "text")
  197. {
  198. val += "'" + GetDbExpressionVal(sub) + "',";
  199. }
  200. else
  201. {
  202. val += GetDbExpressionVal(sub) + ",";
  203. }
  204. }
  205. }
  206. else if(fieldQueryModel == "query_field")
  207. {
  208. foreach(string sub in valList)
  209. {
  210. string dicVal = dic.ContainsKey(sub) ? dic[sub].ToString() : "0";
  211. if(fieldQueryValueType == "text")
  212. {
  213. val += "'" + dicVal + "',";
  214. }
  215. else
  216. {
  217. val += dicVal + ",";
  218. }
  219. }
  220. }
  221. val = val.TrimEnd(',');
  222. condi += val + ")";
  223. }
  224. else if(fieldQueryKind == "3") //范围匹配
  225. {
  226. string[] val = fieldQueryValue.Split(':');
  227. if(fieldQueryModel == "request_param")
  228. {
  229. Dictionary<string, string> req = getRequestParams(projectId, content);
  230. if(fieldQueryValueType == "number")
  231. {
  232. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  233. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  234. }
  235. else
  236. {
  237. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  238. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  239. }
  240. }
  241. else if(fieldQueryModel == "fixed_value")
  242. {
  243. if(fieldQueryValueType == "number")
  244. {
  245. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  246. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  247. }
  248. else
  249. {
  250. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  251. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  252. }
  253. }
  254. else if(fieldQueryModel == "db_field")
  255. {
  256. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + GetDbExpressionVal(val[0]);
  257. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + GetDbExpressionVal(val[1]);
  258. }
  259. else if(fieldQueryModel == "query_field")
  260. {
  261. string dicValLeft = dic.ContainsKey(val[0]) ? dic[val[0]].ToString() : "0";
  262. string dicValRight = dic.ContainsKey(val[1]) ? dic[val[1]].ToString() : "0";
  263. if(fieldQueryValueType == "number")
  264. {
  265. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft;
  266. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight;
  267. }
  268. else
  269. {
  270. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'";
  271. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'";
  272. }
  273. }
  274. }
  275. else if(fieldQueryKind == "4") //取反匹配
  276. {
  277. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is not null";
  278. else
  279. {
  280. condi += " and " + fieldEnName + "!=";
  281. string val = "";
  282. if(fieldQueryModel == "request_param")
  283. {
  284. Dictionary<string, string> req = getRequestParams(projectId, content);
  285. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  286. }
  287. else if(fieldQueryModel == "fixed_value")
  288. {
  289. val = GetExpressionVal(fieldQueryValue);
  290. }
  291. else if(fieldQueryModel == "db_field")
  292. {
  293. val = GetDbExpressionVal(fieldQueryValue);
  294. }
  295. else if(fieldQueryModel == "query_field")
  296. {
  297. val = dic.ContainsKey(fieldQueryValue) ? dic[fieldQueryValue].ToString() : "0";
  298. }
  299. if(fieldQueryValueType == "text")
  300. {
  301. val = "'" + val + "'";
  302. }
  303. condi += val;
  304. }
  305. }
  306. }
  307. var db = initDb(queryTable.databaseId);
  308. string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
  309. var items = db.Ado.GetDataTable(sql);
  310. if(items.Rows.Count > 0)
  311. {
  312. foreach(System.Data.DataColumn item in items.Columns)
  313. {
  314. if(!dic.ContainsKey(item.ColumnName)) dic.Add(item.ColumnName, items.Rows[0][item.ColumnName].ToString());
  315. }
  316. }
  317. }
  318. return dic;
  319. }
  320. //奖励发放对象
  321. public static string prizeObject(int prizeObjectTag, string content)
  322. {
  323. Dictionary<string, object> dic = new Dictionary<string, object>();
  324. var prizeObjectTableService = App.GetService<IPriPrizeObjectTableService>();
  325. var prizeObjectFieldService = App.GetService<IPriPrizeObjectFieldService>();
  326. //查询表
  327. var prizeObjectTable = prizeObjectTableService.GetFirst(m => m.id == prizeObjectTag) ?? new PriPrizeObjectTable();
  328. //查询返回字段
  329. string field = prizeObjectTable.selectField;
  330. int projectId = prizeObjectTable.projectId;
  331. //查询匹配条件
  332. string condi = "";
  333. var queryFields = prizeObjectFieldService.GetList(m => m.objectTableId == prizeObjectTable.id);
  334. foreach(var queryField in queryFields)
  335. {
  336. string fieldEnName = queryField.fieldEnName;
  337. string fieldQueryKind = queryField.fieldQueryKind;
  338. string fieldQueryModel = queryField.fieldQueryModel;
  339. string fieldQueryValue = queryField.fieldQueryValue;
  340. string fieldQueryValueType = queryField.fieldQueryValueType;
  341. if(fieldQueryKind == "1") //模糊匹配
  342. {
  343. condi += " and " + fieldEnName + " like ";
  344. if(fieldQueryModel == "request_param")
  345. {
  346. Dictionary<string, string> req = getRequestParams(projectId, content);
  347. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  348. condi += "'%" + val + "%'";
  349. }
  350. else if(fieldQueryModel == "fixed_value")
  351. {
  352. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  353. }
  354. else if(fieldQueryModel == "db_field")
  355. {
  356. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  357. }
  358. }
  359. else if(fieldQueryKind == "2") //精确匹配
  360. {
  361. condi += " and " + fieldEnName + "=";
  362. string val = "";
  363. if(fieldQueryModel == "request_param")
  364. {
  365. Dictionary<string, string> req = getRequestParams(projectId, content);
  366. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  367. }
  368. else if(fieldQueryModel == "fixed_value")
  369. {
  370. val = GetExpressionVal(fieldQueryValue);
  371. }
  372. else if(fieldQueryModel == "db_field")
  373. {
  374. val = GetDbExpressionVal(fieldQueryValue);
  375. }
  376. if(fieldQueryValueType == "text")
  377. {
  378. val = "'" + val + "'";
  379. }
  380. condi += val;
  381. }
  382. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  383. {
  384. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  385. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  386. string val = "";
  387. string[] valList = fieldQueryValue.Split(',');
  388. if(fieldQueryModel == "request_param")
  389. {
  390. Dictionary<string, string> req = getRequestParams(projectId, content);
  391. foreach(string sub in valList)
  392. {
  393. if(fieldQueryValueType == "text")
  394. {
  395. val += "'" + req[sub] + "',";
  396. }
  397. else
  398. {
  399. val += req[sub] + ",";
  400. }
  401. }
  402. }
  403. else if(fieldQueryModel == "fixed_value")
  404. {
  405. foreach(string sub in valList)
  406. {
  407. if(fieldQueryValueType == "text")
  408. {
  409. val += "'" + GetExpressionVal(sub) + "',";
  410. }
  411. else
  412. {
  413. val += GetExpressionVal(sub) + ",";
  414. }
  415. }
  416. }
  417. else if(fieldQueryModel == "db_field")
  418. {
  419. foreach(string sub in valList)
  420. {
  421. if(fieldQueryValueType == "text")
  422. {
  423. val += "'" + GetDbExpressionVal(sub) + "',";
  424. }
  425. else
  426. {
  427. val += GetDbExpressionVal(sub) + ",";
  428. }
  429. }
  430. }
  431. val = val.TrimEnd(',');
  432. condi += val + ")";
  433. }
  434. else if(fieldQueryKind == "3") //范围匹配
  435. {
  436. string[] val = fieldQueryValue.Split(':');
  437. if(fieldQueryModel == "request_param")
  438. {
  439. Dictionary<string, string> req = getRequestParams(projectId, content);
  440. if(fieldQueryValueType == "number")
  441. {
  442. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  443. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  444. }
  445. else
  446. {
  447. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  448. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  449. }
  450. }
  451. else if(fieldQueryModel == "fixed_value")
  452. {
  453. if(fieldQueryValueType == "number")
  454. {
  455. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  456. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  457. }
  458. else
  459. {
  460. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  461. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  462. }
  463. }
  464. else if(fieldQueryModel == "db_field")
  465. {
  466. if(fieldQueryValueType == "number")
  467. {
  468. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  469. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  470. }
  471. else
  472. {
  473. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  474. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  475. }
  476. }
  477. }
  478. else if(fieldQueryKind == "4") //取反匹配
  479. {
  480. condi += " and " + fieldEnName + "!=";
  481. string val = "";
  482. if(fieldQueryModel == "request_param")
  483. {
  484. Dictionary<string, string> req = getRequestParams(projectId, content);
  485. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  486. }
  487. else if(fieldQueryModel == "fixed_value")
  488. {
  489. val = GetExpressionVal(fieldQueryValue);
  490. }
  491. else if(fieldQueryModel == "db_field")
  492. {
  493. val = GetDbExpressionVal(fieldQueryValue);
  494. }
  495. if(fieldQueryValueType == "text")
  496. {
  497. val = "'" + val + "'";
  498. }
  499. condi += val;
  500. }
  501. }
  502. var db = initDb(prizeObjectTable.databaseId);
  503. var item = db.Ado.GetScalar("select " + field + " from " + prizeObjectTable.tableEnName + " where 1=1" + condi);
  504. if(item != null)
  505. {
  506. return item.ToString();
  507. }
  508. return "0";
  509. }
  510. //奖励发放入口
  511. public static string prizeInSet(string prizeObjectTag)
  512. {
  513. Dictionary<string, object> dic = new Dictionary<string, object>();
  514. var prizeInSetService = App.GetService<IPriPrizeInSetService>();
  515. //查询表
  516. var prizeInSet = prizeInSetService.GetFirst(m => m.prizeListIds == prizeObjectTag) ?? new PriPrizeInSet();
  517. int projectId = prizeInSet.projectId;
  518. return prizeInSet.prizeListIds + "|" + projectId;
  519. }
  520. //奖励列表
  521. public static List<PriList> prizeList(int projectId, string prizeIds)
  522. {
  523. List<int> ids = Tools.SpitIntArrary(prizeIds, ',').ToList();
  524. var priListService = App.GetService<IPriListService>();
  525. var priList = priListService.GetList(m => m.projectId == projectId && ids.Contains(m.id)).ToList();
  526. return priList;
  527. }
  528. //奖励发放
  529. public static void prizeSend(int projectId, string prizeIds, string content)
  530. {
  531. var loopSetService = App.GetService<IPriLoopSetService>();
  532. var recursionStartTableService = App.GetService<IPriRecursionStartTableService>();
  533. var recursionStartConditionService = App.GetService<IPriRecursionStartConditionService>();
  534. var priList = prizeList(projectId, prizeIds);
  535. foreach(var sub in priList)
  536. {
  537. string prizeObjectId = prizeObject(sub.prizeObj, content);
  538. var recursionFlag = sub.recursionFlag; //是否递归
  539. if(recursionFlag)
  540. {
  541. var loopSet = loopSetService.GetFirst(m => m.listId == sub.id) ?? new PriLoopSet();
  542. var recursionStartTable = recursionStartTableService.GetFirst(m => m.listId == sub.id) ?? new PriRecursionStartTable();
  543. var tableEnName = loopSet.tableEnName; //递归查询表
  544. var parentField = loopSet.parentField; //父字段
  545. var sonField = loopSet.sonField; //子字段
  546. var afterPrizeFlag = loopSet.afterPrizeFlag; //发奖后是否继续
  547. var db = initDb(recursionStartTable.databaseId);
  548. string objId = prizeObjectId;
  549. bool op = true;
  550. int index = 0;
  551. loopAmount = 0;
  552. while(!string.IsNullOrEmpty(objId) && objId != "0" && op)
  553. {
  554. Dictionary<string, object> condiDic = loopCondition(projectId, sub, objId, content);
  555. if(condiDic.Count > 0)
  556. {
  557. bool prizeFlag = true;
  558. var conditions = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id);
  559. if(conditions.Count > 0)
  560. {
  561. int allCount = conditions.Count; //所有奖励条件数
  562. int passCount = 0; //通过条件数
  563. foreach(var condition in conditions)
  564. {
  565. if(condition.startIndex <= index)
  566. {
  567. var returnFieldId = condition.returnFieldId; //条件返回字段
  568. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  569. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  570. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  571. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  572. string checkObj = "";
  573. if(returnFieldId.Contains(","))
  574. {
  575. string[] returnFieldIdList = returnFieldId.Split(',');
  576. foreach(string subField in returnFieldIdList)
  577. {
  578. string val = condiDic.ContainsKey(subField) ? condiDic[subField].ToString() : "0";
  579. checkObj += val + ",";
  580. }
  581. checkObj = checkObj.TrimEnd(',');
  582. }
  583. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  584. {
  585. string expresssion = returnFieldId;
  586. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  587. foreach(string returnField in returnFields)
  588. {
  589. string val = condiDic.ContainsKey(returnField) ? condiDic[returnField].ToString() : "0";
  590. expresssion = expresssion.Replace(returnField, val);
  591. }
  592. DataTable dt = new DataTable();
  593. checkObj = dt.Compute(expresssion, "false").ToString();
  594. }
  595. else
  596. {
  597. checkObj = condiDic.ContainsKey(returnFieldId) ? condiDic[returnFieldId].ToString() : "0";
  598. }
  599. var checkVal = fieldQueryValue;
  600. if(fieldQueryKind == "1") //模糊匹配
  601. {
  602. if(fieldQueryValueType == "text")
  603. {
  604. if(checkObj.ToString().Contains(GetExpressionVal(checkVal))) passCount += 1;
  605. }
  606. }
  607. else if(fieldQueryKind == "2") //精确匹配
  608. {
  609. if(fieldQueryValueType == "int")
  610. {
  611. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal))) passCount += 1;
  612. }
  613. else if(fieldQueryValueType == "number")
  614. {
  615. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
  616. }
  617. else
  618. {
  619. if(checkObj.ToString() == GetExpressionVal(checkVal)) passCount += 1;
  620. }
  621. }
  622. else if(fieldQueryKind == "3") //范围匹配
  623. {
  624. string[] val = checkVal.Split(':');
  625. if(fieldQueryModel == "request_param")
  626. {
  627. Dictionary<string, string> req = getRequestParams(projectId, content);
  628. if(fieldQueryValueType == "number")
  629. {
  630. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[val[0]])) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[val[1]]))) passCount += 1;
  631. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[val[0]]))) passCount += 1;
  632. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[val[1]]))) passCount += 1;
  633. }
  634. else if(fieldQueryValueType == "int")
  635. {
  636. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[val[0]])) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[val[1]]))) passCount += 1;
  637. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[val[0]]))) passCount += 1;
  638. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[val[1]]))) passCount += 1;
  639. }
  640. else if(fieldQueryValueType.StartsWith("date"))
  641. {
  642. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[val[0]]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[val[1]])) passCount += 1;
  643. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[val[0]])) passCount += 1;
  644. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[val[1]])) passCount += 1;
  645. }
  646. }
  647. else if(fieldQueryModel == "fixed_value")
  648. {
  649. if(fieldQueryValueType == "number")
  650. {
  651. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(val[0])) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(val[1]))) passCount += 1;
  652. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(val[0]))) passCount += 1;
  653. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(val[1]))) passCount += 1;
  654. }
  655. else if(fieldQueryValueType == "int")
  656. {
  657. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(val[0])) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(val[1]))) passCount += 1;
  658. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(val[0]))) passCount += 1;
  659. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(val[1]))) passCount += 1;
  660. }
  661. else if(fieldQueryValueType.StartsWith("date"))
  662. {
  663. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(val[0])) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(val[1]))) passCount += 1;
  664. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(val[0]))) passCount += 1;
  665. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(val[1]))) passCount += 1;
  666. }
  667. }
  668. }
  669. else if(fieldQueryKind == "4") //取反匹配
  670. {
  671. if(fieldQueryValueType == "int")
  672. {
  673. if(int.Parse(checkObj) != int.Parse(Function.CheckInt(checkVal))) passCount += 1;
  674. }
  675. else if(fieldQueryValueType == "number")
  676. {
  677. if(decimal.Parse(checkObj) != decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
  678. }
  679. else if(fieldQueryValueType == "text")
  680. {
  681. if(checkObj.ToString() != GetExpressionVal(checkVal)) passCount += 1;
  682. }
  683. }
  684. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  685. {
  686. string val = ",";
  687. string[] valList = checkVal.Split(',');
  688. if(fieldQueryModel == "request_param")
  689. {
  690. Dictionary<string, string> req = getRequestParams(projectId, content);
  691. foreach(string subVal in valList)
  692. {
  693. val += req[subVal] + ",";
  694. }
  695. }
  696. else if(fieldQueryModel == "fixed_value")
  697. {
  698. foreach(string subVal in valList)
  699. {
  700. val += GetExpressionVal(subVal) + ",";
  701. }
  702. }
  703. else if(fieldQueryModel == "db_field")
  704. {
  705. foreach(string subVal in valList)
  706. {
  707. val += GetDbExpressionVal(subVal) + ",";
  708. }
  709. }
  710. if(fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ",")) passCount += 1;
  711. if(fieldQueryKind == "6" && val.Contains("," + checkObj.ToString() + ",")) passCount += 1;
  712. }
  713. }
  714. }
  715. if(loopSet.conditionMode == "all" && passCount == allCount) prizeFlag = true;
  716. else if(loopSet.conditionMode == "one" && passCount >= 1) prizeFlag = true;
  717. else prizeFlag = false;
  718. }
  719. else
  720. {
  721. prizeFlag = false;
  722. }
  723. if(prizeFlag)
  724. {
  725. prizeSendDo(projectId, sub, objId, content, loopSet);
  726. op = afterPrizeFlag;
  727. }
  728. }
  729. var parent = db.Ado.GetScalar("select " + parentField + " from " + tableEnName + " where " + sonField + "=" + objId);
  730. if(parent != null)
  731. {
  732. objId = parent.ToString();
  733. }
  734. index += 1;
  735. }
  736. }
  737. else
  738. {
  739. prizeSendDo(projectId, sub, prizeObjectId, content, new PriLoopSet());
  740. }
  741. }
  742. }
  743. static decimal loopAmount = 0;
  744. public static void prizeSendDo(int projectId, PriList sub, string prizeObjectId, string content, PriLoopSet set)
  745. {
  746. var recordService = App.GetService<IPriRecordService>();
  747. var conditionService = App.GetService<IPriConditionService>();
  748. var returnFieldService = App.GetService<IPriReturnFieldService>();
  749. var queryTableService = App.GetService<IPriQueryTableService>();
  750. var amountSetService = App.GetService<IPriListAmountSetService>();
  751. //查询匹配条件
  752. Dictionary<string, object> condiDic = new Dictionary<string, object>();
  753. if(sub.prizeSourceFieldType == "condi") condiDic = condition(projectId, content);
  754. if(sub.prizeSourceFieldType == "loop") condiDic = loopCondition(projectId, sub, prizeObjectId, content);
  755. var prizeSourceField = sub.prizeSourceField; //奖励金额来源字段(对应条件匹配返回字段)
  756. var prizePercent = sub.prizePercent; //奖励比例
  757. var prizeAmount = sub.prizeAmount; //奖励固定值
  758. var prizeContent = sub.prizeContent; //奖励内容
  759. var conditionMode = sub.conditionMode; //条件模式
  760. var recursionFlag = sub.recursionFlag; //是否递归
  761. var conditions = conditionService.GetList(m => m.listId == sub.id);
  762. int allCount = conditions.Count; //所有奖励条件数
  763. int passCount = 0; //通过条件数
  764. foreach(var condition in conditions)
  765. {
  766. var returnFieldId = condition.returnFieldId; //条件返回字段
  767. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  768. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  769. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  770. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  771. string checkObj = "";
  772. if(returnFieldId.Contains(","))
  773. {
  774. string[] returnFieldIdList = returnFieldId.Split(',');
  775. foreach(string subField in returnFieldIdList)
  776. {
  777. string val = condiDic.ContainsKey(subField) ? condiDic[subField].ToString() : "0";
  778. checkObj += val + ",";
  779. }
  780. checkObj = checkObj.TrimEnd(',');
  781. }
  782. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  783. {
  784. string expresssion = returnFieldId;
  785. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  786. foreach(string returnField in returnFields)
  787. {
  788. string val = condiDic.ContainsKey(returnField) ? condiDic[returnField].ToString() : "0";
  789. expresssion = expresssion.Replace(returnField, val);
  790. }
  791. DataTable dt = new DataTable();
  792. checkObj = dt.Compute(expresssion, "false").ToString();
  793. }
  794. else
  795. {
  796. checkObj = condiDic.ContainsKey(returnFieldId) ? condiDic[returnFieldId].ToString() : "0";
  797. }
  798. string checkVal = fieldQueryValue;
  799. if(fieldQueryKind == "1") //模糊匹配
  800. {
  801. if(fieldQueryValueType == "text")
  802. {
  803. if(checkObj.ToString().Contains(GetExpressionVal(checkVal))) passCount += 1;
  804. }
  805. }
  806. else if(fieldQueryKind == "2") //精确匹配
  807. {
  808. if(fieldQueryValueType == "int")
  809. {
  810. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal))) passCount += 1;
  811. }
  812. else if(fieldQueryValueType == "number")
  813. {
  814. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
  815. }
  816. else
  817. {
  818. if(checkObj.ToString() == GetExpressionVal(checkVal)) passCount += 1;
  819. }
  820. }
  821. else if(fieldQueryKind == "3") //范围匹配
  822. {
  823. string[] val = checkVal.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]]) && !string.IsNullOrEmpty(req[val[1]]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[val[0]])) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[val[1]]))) passCount += 1;
  830. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[val[0]]))) passCount += 1;
  831. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[val[1]]))) passCount += 1;
  832. }
  833. else if(fieldQueryValueType == "int")
  834. {
  835. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[val[0]])) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[val[1]]))) passCount += 1;
  836. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[val[0]]))) passCount += 1;
  837. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[val[1]]))) passCount += 1;
  838. }
  839. else if(fieldQueryValueType.StartsWith("date"))
  840. {
  841. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[val[0]]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[val[1]])) passCount += 1;
  842. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[val[0]])) passCount += 1;
  843. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[val[1]])) passCount += 1;
  844. }
  845. }
  846. else if(fieldQueryModel == "fixed_value")
  847. {
  848. if(fieldQueryValueType == "number")
  849. {
  850. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(val[0])) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(val[1]))) passCount += 1;
  851. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(val[0]))) passCount += 1;
  852. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(val[1]))) passCount += 1;
  853. }
  854. else if(fieldQueryValueType == "int")
  855. {
  856. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckNum(checkObj.ToString())) >= int.Parse(Function.CheckInt(val[0])) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(val[1]))) passCount += 1;
  857. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(val[0]))) passCount += 1;
  858. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(val[1]))) passCount += 1;
  859. }
  860. else if(fieldQueryValueType.StartsWith("date"))
  861. {
  862. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(val[0])) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(val[1]))) passCount += 1;
  863. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(val[0]))) passCount += 1;
  864. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(val[1]))) passCount += 1;
  865. }
  866. }
  867. }
  868. else if(fieldQueryKind == "4") //取反匹配
  869. {
  870. if(fieldQueryValueType == "int")
  871. {
  872. if(int.Parse(Function.CheckNum(checkObj.ToString())) != int.Parse(Function.CheckInt(checkVal))) passCount += 1;
  873. }
  874. else if(fieldQueryValueType == "number")
  875. {
  876. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) != decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
  877. }
  878. else if(fieldQueryValueType == "text")
  879. {
  880. if(checkObj.ToString() != GetExpressionVal(checkVal)) passCount += 1;
  881. }
  882. }
  883. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  884. {
  885. string val = ",";
  886. string[] valList = checkVal.Split(',');
  887. if(fieldQueryModel == "request_param")
  888. {
  889. Dictionary<string, string> req = getRequestParams(projectId, content);
  890. foreach(string subVal in valList)
  891. {
  892. val += req[subVal] + ",";
  893. }
  894. }
  895. else if(fieldQueryModel == "fixed_value")
  896. {
  897. foreach(string subVal in valList)
  898. {
  899. val += GetExpressionVal(subVal) + ",";
  900. }
  901. }
  902. else if(fieldQueryModel == "db_field")
  903. {
  904. foreach(string subVal in valList)
  905. {
  906. val += GetDbExpressionVal(subVal) + ",";
  907. }
  908. }
  909. if(fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ",")) passCount += 1;
  910. if(fieldQueryKind == "6" && val.Contains("," + checkObj.ToString() + ",")) passCount += 1;
  911. }
  912. }
  913. bool op = false;
  914. if(conditionMode == "all" && passCount == allCount && passCount > 0) op = true;
  915. else if(conditionMode == "one" && passCount >= 1) op = true;
  916. if(op) //满足条件
  917. {
  918. decimal number = 0;
  919. if(prizeSourceField.Contains("/"))
  920. {
  921. number = decimal.Parse(prizeSourceField.Split('/')[1]);
  922. prizeSourceField = prizeSourceField.Split('/')[0];
  923. }
  924. string prizeSourceData = "";
  925. if(prizeSourceField.Contains(","))
  926. {
  927. string[] prizeSourceFieldList = prizeSourceField.Split(',');
  928. foreach(string subField in prizeSourceFieldList)
  929. {
  930. string val = condiDic.ContainsKey(subField) ? condiDic[subField].ToString() : "0";
  931. prizeSourceData += val + ",";
  932. }
  933. prizeSourceData = prizeSourceData.TrimEnd(',');
  934. }
  935. else
  936. {
  937. prizeSourceData = condiDic.ContainsKey(prizeSourceField) ? condiDic[prizeSourceField].ToString() : "0";
  938. }
  939. if(string.IsNullOrEmpty(prizeSourceData)) prizeSourceData = "0";
  940. if(prizeSourceField.Contains("/") && number > 0)
  941. {
  942. decimal prizeSourceDataNum = decimal.Parse(prizeSourceData) / number;
  943. prizeSourceData = prizeSourceDataNum.ToString("f2");
  944. }
  945. decimal prizeAmt = 0;
  946. var amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField == prizeSourceData);
  947. if(amountSet != null)
  948. {
  949. prizePercent = amountSet.prizePercent;
  950. prizeAmount = amountSet.prizeAmount;
  951. }
  952. if(prizeSourceData.Contains(","))
  953. {
  954. string checkField = prizeSourceData.Split(',')[0] + ",";
  955. amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField.StartsWith(checkField) && m.prizeSourceField.EndsWith(",%"));
  956. if(amountSet != null)
  957. {
  958. prizePercent = amountSet.prizePercent;
  959. prizeAmount = amountSet.prizeAmount;
  960. prizeSourceData = prizeSourceData.Split(',')[1];
  961. }
  962. }
  963. if(prizePercent > 0) prizeAmt += decimal.Parse(Function.CheckNum(prizeSourceData)) * prizePercent;
  964. if(prizeAmount > 0) prizeAmt += prizeAmount;
  965. decimal getPrizeAmount = prizeAmt;
  966. if(set.levelDiffFlag) prizeAmt -= loopAmount;
  967. if(prizeAmt > 0)
  968. {
  969. var req = getRequestParams(projectId, content);
  970. var requestParamField = req[sub.requestParamField];
  971. var sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == requestParamField);
  972. if(!sendFlag)
  973. {
  974. recordService.Add(new PriRecord()
  975. {
  976. createDate = DateTime.Now,
  977. projectId = projectId,
  978. listId = sub.id,
  979. prizeAmount = prizeAmt,
  980. prizeObjId = prizeObjectId,
  981. requestParamField = requestParamField,
  982. batchNo = batchNo,
  983. });
  984. loopAmount = getPrizeAmount;
  985. // prizeToDatabase(projectId, content); //入库
  986. }
  987. }
  988. }
  989. }
  990. //递归条件判断
  991. public static Dictionary<string, object> loopCondition(int projectId, PriList sub, string objId, string content)
  992. {
  993. Dictionary<string, object> dic = new Dictionary<string, object>();
  994. var queryTableService = App.GetService<IPriRecursionStartTableService>();
  995. var queryFieldService = App.GetService<IPriRecursionStartFieldService>();
  996. var queryReturnFieldService = App.GetService<IPriRecursionStartReturnFieldService>();
  997. int passCount = 0;
  998. //查询表
  999. var queryTables = queryTableService.GetList(m => m.listId == sub.id);
  1000. int allCount = queryTables.Count;
  1001. foreach(var queryTable in queryTables)
  1002. {
  1003. //查询返回字段
  1004. string fields = "1";
  1005. var returnFields = queryReturnFieldService.GetList(m => m.objectTableId == queryTable.id);
  1006. if(returnFields.Count > 0)
  1007. {
  1008. fields = "";
  1009. foreach(var returnField in returnFields)
  1010. {
  1011. if(returnField.fieldReturnKind == "2")
  1012. {
  1013. fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1014. }
  1015. else if(returnField.fieldReturnKind == "3")
  1016. {
  1017. fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1018. }
  1019. else if(returnField.fieldReturnKind == "4")
  1020. {
  1021. fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1022. }
  1023. else
  1024. {
  1025. fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1026. }
  1027. }
  1028. fields = fields.TrimEnd(',');
  1029. }
  1030. //查询匹配条件
  1031. string condi = "";
  1032. var queryFields = queryFieldService.GetList(m => m.objectTableId == queryTable.id);
  1033. foreach(var queryField in queryFields)
  1034. {
  1035. string fieldEnName = queryField.fieldEnName;
  1036. string fieldQueryKind = queryField.fieldQueryKind;
  1037. string fieldQueryModel = queryField.fieldQueryModel;
  1038. string fieldQueryValue = queryField.fieldQueryValue;
  1039. if(fieldQueryModel == "loop_field") fieldQueryValue = objId;
  1040. string fieldQueryValueType = queryField.fieldQueryValueType;
  1041. if(fieldQueryKind == "1") //模糊匹配
  1042. {
  1043. condi += " and " + fieldEnName + " like ";
  1044. if(fieldQueryModel == "request_param")
  1045. {
  1046. Dictionary<string, string> req = getRequestParams(projectId, content);
  1047. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1048. condi += "'%" + val + "%'";
  1049. }
  1050. else if(fieldQueryModel == "fixed_value")
  1051. {
  1052. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  1053. }
  1054. else if(fieldQueryModel == "db_field")
  1055. {
  1056. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  1057. }
  1058. }
  1059. else if(fieldQueryKind == "2") //精确匹配
  1060. {
  1061. condi += " and " + fieldEnName + "=";
  1062. string val = fieldQueryValue;
  1063. if(fieldQueryModel == "request_param")
  1064. {
  1065. Dictionary<string, string> req = getRequestParams(projectId, content);
  1066. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1067. }
  1068. else if(fieldQueryModel == "fixed_value")
  1069. {
  1070. val = GetExpressionVal(fieldQueryValue);
  1071. }
  1072. else if(fieldQueryModel == "db_field")
  1073. {
  1074. val = GetDbExpressionVal(fieldQueryValue);
  1075. }
  1076. if(fieldQueryValueType == "text")
  1077. {
  1078. val = "'" + val + "'";
  1079. }
  1080. condi += val;
  1081. }
  1082. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1083. {
  1084. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  1085. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  1086. string val = "";
  1087. string[] valList = fieldQueryValue.Split(',');
  1088. if(fieldQueryModel == "request_param")
  1089. {
  1090. Dictionary<string, string> req = getRequestParams(projectId, content);
  1091. foreach(string subval in valList)
  1092. {
  1093. if(fieldQueryValueType == "text")
  1094. {
  1095. val += "'" + req[subval] + "',";
  1096. }
  1097. else
  1098. {
  1099. val += req[subval] + ",";
  1100. }
  1101. }
  1102. }
  1103. else if(fieldQueryModel == "fixed_value")
  1104. {
  1105. foreach(string subval in valList)
  1106. {
  1107. if(fieldQueryValueType == "text")
  1108. {
  1109. val += "'" + GetExpressionVal(subval) + "',";
  1110. }
  1111. else
  1112. {
  1113. val += GetExpressionVal(subval) + ",";
  1114. }
  1115. }
  1116. }
  1117. else if(fieldQueryModel == "db_field")
  1118. {
  1119. foreach(string subval in valList)
  1120. {
  1121. if(fieldQueryValueType == "text")
  1122. {
  1123. val += "'" + GetDbExpressionVal(subval) + "',";
  1124. }
  1125. else
  1126. {
  1127. val += GetDbExpressionVal(subval) + ",";
  1128. }
  1129. }
  1130. }
  1131. val = val.TrimEnd(',');
  1132. condi += val + ")";
  1133. }
  1134. else if(fieldQueryKind == "3") //范围匹配
  1135. {
  1136. string[] val = fieldQueryValue.Split(':');
  1137. if(fieldQueryModel == "request_param")
  1138. {
  1139. Dictionary<string, string> req = getRequestParams(projectId, content);
  1140. if(fieldQueryValueType == "number")
  1141. {
  1142. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  1143. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  1144. }
  1145. else
  1146. {
  1147. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  1148. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  1149. }
  1150. }
  1151. else if(fieldQueryModel == "fixed_value")
  1152. {
  1153. if(fieldQueryValueType == "number")
  1154. {
  1155. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1156. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1157. }
  1158. else
  1159. {
  1160. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  1161. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  1162. }
  1163. }
  1164. else if(fieldQueryModel == "db_field")
  1165. {
  1166. if(fieldQueryValueType == "number")
  1167. {
  1168. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1169. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1170. }
  1171. else
  1172. {
  1173. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  1174. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  1175. }
  1176. }
  1177. }
  1178. else if(fieldQueryKind == "4") //取反匹配
  1179. {
  1180. condi += " and " + fieldEnName + "!=";
  1181. string val = "";
  1182. if(fieldQueryModel == "request_param")
  1183. {
  1184. Dictionary<string, string> req = getRequestParams(projectId, content);
  1185. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1186. }
  1187. else if(fieldQueryModel == "fixed_value")
  1188. {
  1189. val = GetExpressionVal(fieldQueryValue);
  1190. }
  1191. else if(fieldQueryModel == "db_field")
  1192. {
  1193. val = GetDbExpressionVal(fieldQueryValue);
  1194. }
  1195. if(fieldQueryValueType == "text")
  1196. {
  1197. val = "'" + val + "'";
  1198. }
  1199. condi += val;
  1200. }
  1201. }
  1202. var db = initDb(queryTable.databaseId);
  1203. string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
  1204. var items = db.Ado.GetDataTable(sql);
  1205. if(items.Rows.Count > 0)
  1206. {
  1207. foreach(System.Data.DataColumn item in items.Columns)
  1208. {
  1209. if(!dic.ContainsKey(item.ColumnName)) dic.Add(item.ColumnName, items.Rows[0][item.ColumnName].ToString());
  1210. }
  1211. }
  1212. }
  1213. return dic;
  1214. }
  1215. //奖励入库
  1216. public static void prizeToDatabase(int projectId, string content)
  1217. {
  1218. var prizeInTableService = App.GetService<IPriPrizeInTableService>();
  1219. var prizeInFieldService = App.GetService<IPriPrizeInFieldService>();
  1220. var prizeInQueryFieldService = App.GetService<IPriPrizeInQueryFieldService>();
  1221. //入库表
  1222. var prizeInTables = prizeInTableService.GetList(m => m.projectId == projectId);
  1223. foreach(var prizeInTable in prizeInTables)
  1224. {
  1225. var db = initDb(prizeInTable.databaseId);
  1226. Dictionary<string, object> doFields = new Dictionary<string, object>();
  1227. //入库字段
  1228. var prizeInFields = prizeInFieldService.GetList(m => m.inTableId == prizeInTable.id);
  1229. foreach(var prizeInField in prizeInFields)
  1230. {
  1231. string fieldEnName = prizeInField.fieldEnName;
  1232. string fieldQueryModel = prizeInField.fieldQueryModel;
  1233. string fieldQueryValue = prizeInField.fieldQueryValue;
  1234. string fieldQueryValueType = prizeInField.fieldQueryValueType;
  1235. if(fieldQueryModel == "request_param")
  1236. {
  1237. Dictionary<string, string> req = getRequestParams(projectId, content);
  1238. fieldQueryValue = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1239. }
  1240. else if(fieldQueryModel == "fixed_value")
  1241. {
  1242. fieldQueryValue = GetExpressionVal(fieldQueryValue);
  1243. }
  1244. else if(fieldQueryModel == "db_field")
  1245. {
  1246. fieldQueryValue = GetDbExpressionVal(fieldQueryValue);
  1247. }
  1248. if(fieldQueryValueType == "text") doFields.Add(fieldEnName, fieldQueryValue);
  1249. if(fieldQueryValueType == "int") doFields.Add(fieldEnName, int.Parse(fieldQueryValue));
  1250. if(fieldQueryValueType == "number") doFields.Add(fieldEnName, decimal.Parse(fieldQueryValue));
  1251. if(fieldQueryValueType == "datetime") doFields.Add(fieldEnName, DateTime.Parse(fieldQueryValue));
  1252. if(fieldQueryValueType == "bool") doFields.Add(fieldEnName, bool.Parse(fieldQueryValue));
  1253. }
  1254. //查询匹配条件
  1255. string condi = "";
  1256. var queryFields = prizeInQueryFieldService.GetList(m => m.inTableId == prizeInTable.id);
  1257. foreach(var queryField in queryFields)
  1258. {
  1259. string fieldEnName = queryField.fieldEnName;
  1260. string fieldQueryKind = queryField.fieldQueryKind;
  1261. string fieldQueryModel = queryField.fieldQueryModel;
  1262. string fieldQueryValue = queryField.fieldQueryValue;
  1263. string fieldQueryValueType = queryField.fieldQueryValueType;
  1264. if(fieldQueryKind == "1") //模糊匹配
  1265. {
  1266. condi += " and " + fieldEnName + " like ";
  1267. if(fieldQueryModel == "request_param")
  1268. {
  1269. Dictionary<string, string> req = getRequestParams(projectId, content);
  1270. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1271. condi += "'%" + val + "%'";
  1272. }
  1273. else if(fieldQueryModel == "fixed_value")
  1274. {
  1275. condi += "'%" + fieldQueryValue + "%'";
  1276. }
  1277. }
  1278. else if(fieldQueryKind == "2") //精确匹配
  1279. {
  1280. condi += " and " + fieldEnName + "=";
  1281. string val = "";
  1282. if(fieldQueryModel == "request_param")
  1283. {
  1284. Dictionary<string, string> req = getRequestParams(projectId, content);
  1285. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1286. }
  1287. else if(fieldQueryModel == "fixed_value")
  1288. {
  1289. val = fieldQueryValue;
  1290. }
  1291. if(fieldQueryValueType == "text")
  1292. {
  1293. val = "'" + val + "'";
  1294. }
  1295. condi += val;
  1296. }
  1297. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1298. {
  1299. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  1300. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  1301. string val = "";
  1302. string[] valList = fieldQueryValue.Split(',');
  1303. if(fieldQueryModel == "request_param")
  1304. {
  1305. Dictionary<string, string> req = getRequestParams(projectId, content);
  1306. foreach(string sub in valList)
  1307. {
  1308. if(fieldQueryValueType == "text")
  1309. {
  1310. val += "'" + req[sub] + "',";
  1311. }
  1312. else
  1313. {
  1314. val += req[sub] + ",";
  1315. }
  1316. }
  1317. }
  1318. else if(fieldQueryModel == "fixed_value")
  1319. {
  1320. foreach(string sub in valList)
  1321. {
  1322. if(fieldQueryValueType == "text")
  1323. {
  1324. val += "'" + GetExpressionVal(sub) + "',";
  1325. }
  1326. else
  1327. {
  1328. val += GetExpressionVal(sub) + ",";
  1329. }
  1330. }
  1331. }
  1332. else if(fieldQueryModel == "db_field")
  1333. {
  1334. foreach(string sub in valList)
  1335. {
  1336. if(fieldQueryValueType == "text")
  1337. {
  1338. val += "'" + GetDbExpressionVal(sub) + "',";
  1339. }
  1340. else
  1341. {
  1342. val += GetDbExpressionVal(sub) + ",";
  1343. }
  1344. }
  1345. }
  1346. val = val.TrimEnd(',');
  1347. condi += val + ")";
  1348. }
  1349. else if(fieldQueryKind == "3") //范围匹配
  1350. {
  1351. string[] val = fieldQueryValue.Split(':');
  1352. if(fieldQueryModel == "request_param")
  1353. {
  1354. Dictionary<string, string> req = getRequestParams(projectId, content);
  1355. if(fieldQueryValueType == "number")
  1356. {
  1357. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  1358. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  1359. }
  1360. else
  1361. {
  1362. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  1363. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  1364. }
  1365. }
  1366. else if(fieldQueryModel == "fixed_value")
  1367. {
  1368. if(fieldQueryValueType == "number")
  1369. {
  1370. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1371. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1372. }
  1373. else
  1374. {
  1375. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + val[0] + "'";
  1376. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + val[1] + "'";
  1377. }
  1378. }
  1379. }
  1380. else if(fieldQueryKind == "4") //取反匹配
  1381. {
  1382. condi += " and " + fieldEnName + "!=";
  1383. string val = "";
  1384. if(fieldQueryModel == "request_param")
  1385. {
  1386. Dictionary<string, string> req = getRequestParams(projectId, content);
  1387. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1388. }
  1389. else if(fieldQueryModel == "fixed_value")
  1390. {
  1391. val = fieldQueryValue;
  1392. }
  1393. if(fieldQueryValueType == "text")
  1394. {
  1395. val = "'" + val + "'";
  1396. }
  1397. condi += val;
  1398. }
  1399. }
  1400. if(prizeInTable.excuteKind == "add") db.Insertable(doFields).ExecuteCommand();
  1401. if(prizeInTable.excuteKind == "update") db.Updateable(doFields).Where("1=1" + condi).ExecuteCommand();
  1402. }
  1403. }
  1404. //固定值表达式
  1405. public static string GetExpressionVal(string str)
  1406. {
  1407. if(str == "#{now}#") str = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1408. if(str == "#{today}#") str = DateTime.Now.ToString("yyyy-MM-dd");
  1409. if(str == "#{this_month}#") str = DateTime.Now.ToString("yyyy-MM");
  1410. 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");
  1411. 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");
  1412. if(str.StartsWith("#{today") && str.EndsWith("DAY}#")) str = DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1413. if(str.StartsWith("#{today") && str.EndsWith("MONTH}#")) str = DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1414. if(str.StartsWith("#{this_month") && str.EndsWith("DAY}#")) str = DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1415. if(str.StartsWith("#{this_month") && str.EndsWith("MONTH}#")) str = DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1416. return str;
  1417. }
  1418. //库内字段值表达式
  1419. public static string GetDbExpressionVal(string str)
  1420. {
  1421. string[] data = str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',');
  1422. if(str.StartsWith("#{") && str.EndsWith("DAY}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " DAY)";
  1423. if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " MONTH)";
  1424. return str;
  1425. }
  1426. }
  1427. }