PrizeDo.cs 57 KB

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