PrizeDo.cs 83 KB

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