PrizeDo.cs 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074
  1. using System.Data;
  2. using Common;
  3. using Infrastructure;
  4. using LitJson;
  5. using Microsoft.Extensions.Localization;
  6. using Model;
  7. using Model.Customer;
  8. using NuGet.Packaging;
  9. using Services;
  10. using System.Linq;
  11. using System.Net.Mime;
  12. namespace Util
  13. {
  14. public class PrizeDo
  15. {
  16. public static string batchNo = "";
  17. public static string publicStep = "";
  18. //发奖入口
  19. public static void sendPrize(string queueName, string content)
  20. {
  21. batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(3);
  22. publicStep = "";
  23. string priObjString = prizeInSet(queueName);
  24. if(!string.IsNullOrEmpty(priObjString))
  25. {
  26. string[] priObjData = priObjString.Split('|');
  27. string priListIds = priObjData[0];
  28. int projectId = int.Parse(priObjData[1]);
  29. int prizeInId = int.Parse(priObjData[2]);
  30. prizeSend(projectId, prizeInId, priListIds, content, queueName);
  31. }
  32. }
  33. //接收入参
  34. public static Dictionary<string, string> getRequestParams(int projectId, string content)
  35. {
  36. Dictionary<string, string> dic = new();
  37. JsonData jsonData = JsonMapper.ToObject(content);
  38. var paramService = App.GetService<IPriProjectParamService>();
  39. var paramList = paramService.GetList(m => m.projectId == projectId);
  40. foreach(var param in paramList)
  41. {
  42. if(content.Contains("\"" + param.fieldEnName + "\"")) dic.Add(param.fieldEnName, jsonData[param.fieldEnName].ToString());
  43. }
  44. return dic;
  45. }
  46. //数据库链接
  47. public static SqlSugarClient initDb(int id)
  48. {
  49. var databaseSetService = App.GetService<IPriDatabaseSetService>();
  50. var connectionString = databaseSetService.GetFirst(m => m.id == id);
  51. string server = connectionString.ipAddress;
  52. int port = connectionString.port;
  53. string user = connectionString.userId;
  54. string password = connectionString.password;
  55. string database = connectionString.databaseName;
  56. var db = new SqlSugarClient(new ConnectionConfig()
  57. {
  58. ConnectionString = "server=" + server + ";port=" + port + ";user=" + user + ";password=" + password + ";database=" + database + ";charset=utf8;",
  59. DbType = SqlSugar.DbType.MySql,
  60. IsAutoCloseConnection = true,
  61. });
  62. return db;
  63. }
  64. //查询条件匹配数据
  65. public static List<QueryCondition> condition(int listId, int projectId, List<int> ids, string content)
  66. {
  67. List<QueryCondition> dic = new();
  68. var queryTableService = App.GetService<IPriQueryTableService>();
  69. var queryFieldService = App.GetService<IPriQueryFieldService>();
  70. var returnFieldService = App.GetService<IPriReturnFieldService>();
  71. //查询表
  72. var queryTables = queryTableService.GetList(m => ids.Contains(m.id));
  73. foreach(var queryTable in queryTables)
  74. {
  75. //查询返回字段
  76. string fields = "";
  77. Dictionary<string, string> fieldDic = new();
  78. var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id);
  79. foreach(var returnField in returnFields)
  80. {
  81. if(returnField.fieldReturnKind == "2")
  82. {
  83. fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  84. }
  85. else if(returnField.fieldReturnKind == "3")
  86. {
  87. fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  88. }
  89. else if(returnField.fieldReturnKind == "4")
  90. {
  91. fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  92. }
  93. else
  94. {
  95. fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  96. }
  97. fieldDic.Add(queryTable.tableEnName + "_" + returnField.fieldEnName, returnField.fieldName);
  98. }
  99. fields = fields.TrimEnd(',');
  100. //查询匹配条件
  101. string condi = "";
  102. var queryFields = queryFieldService.GetList(m => m.queryTableId == queryTable.id);
  103. foreach(var queryField in queryFields)
  104. {
  105. string fieldEnName = queryField.fieldEnName;
  106. string fieldQueryKind = queryField.fieldQueryKind;
  107. string fieldQueryModel = queryField.fieldQueryModel;
  108. string fieldQueryValue = queryField.fieldQueryValue;
  109. string fieldQueryValueType = queryField.fieldQueryValueType;
  110. if(fieldQueryKind == "1") //模糊匹配
  111. {
  112. condi += " and " + fieldEnName + " like ";
  113. if(fieldQueryModel == "request_param")
  114. {
  115. Dictionary<string, string> req = getRequestParams(projectId, content);
  116. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  117. condi += "'%" + val + "%'";
  118. }
  119. else if(fieldQueryModel == "fixed_value")
  120. {
  121. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  122. }
  123. else if(fieldQueryModel == "db_field")
  124. {
  125. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  126. }
  127. else if(fieldQueryModel == "query_field")
  128. {
  129. string val = GetQueryTableData(dic, fieldQueryValue);
  130. condi += "'%" + val + "%'";
  131. }
  132. }
  133. else if(fieldQueryKind == "2") //精确匹配
  134. {
  135. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is null";
  136. else
  137. {
  138. condi += " and " + fieldEnName + "=";
  139. string val = "";
  140. if(fieldQueryModel == "request_param")
  141. {
  142. Dictionary<string, string> req = getRequestParams(projectId, content);
  143. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  144. }
  145. else if(fieldQueryModel == "fixed_value")
  146. {
  147. val = GetExpressionVal(fieldQueryValue);
  148. }
  149. else if(fieldQueryModel == "db_field")
  150. {
  151. val = GetDbExpressionVal(fieldQueryValue);
  152. }
  153. else if(fieldQueryModel == "query_field")
  154. {
  155. val = GetQueryTableData(dic, fieldQueryValue);
  156. }
  157. if(fieldQueryValueType == "text")
  158. {
  159. val = "'" + val + "'";
  160. }
  161. condi += val;
  162. }
  163. }
  164. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  165. {
  166. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  167. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  168. string val = "";
  169. string[] valList = fieldQueryValue.Split(',');
  170. if(fieldQueryModel == "request_param")
  171. {
  172. Dictionary<string, string> req = getRequestParams(projectId, content);
  173. foreach(string sub in valList)
  174. {
  175. if(fieldQueryValueType == "text")
  176. {
  177. val += "'" + req[sub] + "',";
  178. }
  179. else
  180. {
  181. val += req[sub] + ",";
  182. }
  183. }
  184. }
  185. else if(fieldQueryModel == "fixed_value")
  186. {
  187. foreach(string sub in valList)
  188. {
  189. if(fieldQueryValueType == "text")
  190. {
  191. val += "'" + GetExpressionVal(sub) + "',";
  192. }
  193. else
  194. {
  195. val += GetExpressionVal(sub) + ",";
  196. }
  197. }
  198. }
  199. else if(fieldQueryModel == "db_field")
  200. {
  201. foreach(string sub in valList)
  202. {
  203. if(fieldQueryValueType == "text")
  204. {
  205. val += "'" + GetDbExpressionVal(sub) + "',";
  206. }
  207. else
  208. {
  209. val += GetDbExpressionVal(sub) + ",";
  210. }
  211. }
  212. }
  213. else if(fieldQueryModel == "query_field")
  214. {
  215. foreach(string sub in valList)
  216. {
  217. string dicVal = GetQueryTableData(dic, sub);
  218. if(fieldQueryValueType == "text")
  219. {
  220. val += "'" + dicVal + "',";
  221. }
  222. else
  223. {
  224. val += dicVal + ",";
  225. }
  226. }
  227. }
  228. val = val.TrimEnd(',');
  229. condi += val + ")";
  230. }
  231. else if(fieldQueryKind == "3") //范围匹配
  232. {
  233. string[] val = fieldQueryValue.Split(':');
  234. if(fieldQueryModel == "request_param")
  235. {
  236. Dictionary<string, string> req = getRequestParams(projectId, content);
  237. if(fieldQueryValueType == "number")
  238. {
  239. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  240. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  241. }
  242. else
  243. {
  244. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  245. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  246. }
  247. }
  248. else if(fieldQueryModel == "fixed_value")
  249. {
  250. if(fieldQueryValueType == "number")
  251. {
  252. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  253. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  254. }
  255. else
  256. {
  257. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  258. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  259. }
  260. }
  261. else if(fieldQueryModel == "db_field")
  262. {
  263. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + GetDbExpressionVal(val[0]);
  264. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + GetDbExpressionVal(val[1]);
  265. }
  266. else if(fieldQueryModel == "query_field")
  267. {
  268. string valLeft = val[0];
  269. string valRight = val[1];
  270. string dicValLeft = GetQueryTableData(dic, valLeft);
  271. string dicValRight = GetQueryTableData(dic, valRight);
  272. if(fieldQueryValueType == "number")
  273. {
  274. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft;
  275. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight;
  276. }
  277. else
  278. {
  279. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'";
  280. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'";
  281. }
  282. }
  283. }
  284. else if(fieldQueryKind == "4") //取反匹配
  285. {
  286. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is not null";
  287. else
  288. {
  289. condi += " and " + fieldEnName + "!=";
  290. string val = "";
  291. if(fieldQueryModel == "request_param")
  292. {
  293. Dictionary<string, string> req = getRequestParams(projectId, content);
  294. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  295. }
  296. else if(fieldQueryModel == "fixed_value")
  297. {
  298. val = GetExpressionVal(fieldQueryValue);
  299. }
  300. else if(fieldQueryModel == "db_field")
  301. {
  302. val = GetDbExpressionVal(fieldQueryValue);
  303. }
  304. else if(fieldQueryModel == "query_field")
  305. {
  306. val = GetQueryTableData(dic, fieldQueryValue);
  307. }
  308. if(fieldQueryValueType == "text")
  309. {
  310. val = "'" + val + "'";
  311. }
  312. condi += val;
  313. }
  314. }
  315. }
  316. var db = initDb(queryTable.databaseId);
  317. string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
  318. var items = db.Ado.GetDataTable(sql);
  319. if(items.Rows.Count > 0)
  320. {
  321. foreach(string field in fieldDic.Keys)
  322. {
  323. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  324. {
  325. FieldName = fieldDic[field],
  326. FieldEnName = field,
  327. Value = items.Rows[0][field].ToString()
  328. });
  329. }
  330. }
  331. }
  332. return dic;
  333. }
  334. //奖励发放对象
  335. public static string prizeObject(int listId, int prizeObjectTag, string content)
  336. {
  337. Dictionary<string, object> logStepDic = new();
  338. Dictionary<string, object> dic = new();
  339. var prizeObjectTableService = App.GetService<IPriPrizeObjectTableService>();
  340. var prizeObjectFieldService = App.GetService<IPriPrizeObjectFieldService>();
  341. //查询表
  342. var prizeObjectTable = prizeObjectTableService.GetFirst(m => m.id == prizeObjectTag) ?? new PriPrizeObjectTable();
  343. //查询返回字段
  344. string field = prizeObjectTable.selectField;
  345. int projectId = prizeObjectTable.projectId;
  346. logStepDic.Add("奖励发放对象说明", prizeObjectTable.note);
  347. //查询匹配条件
  348. string condi = "";
  349. List<Dictionary<string, object>> condiDics = new();
  350. var queryFields = prizeObjectFieldService.GetList(m => m.objectTableId == prizeObjectTable.id);
  351. foreach(var queryField in queryFields)
  352. {
  353. string fieldName = queryField.fieldName;
  354. string fieldEnName = queryField.fieldEnName;
  355. string fieldQueryKind = queryField.fieldQueryKind;
  356. string fieldQueryModel = queryField.fieldQueryModel;
  357. string fieldQueryValue = queryField.fieldQueryValue;
  358. string fieldQueryValueType = queryField.fieldQueryValueType;
  359. Dictionary<string, object> condiDic = new();
  360. condiDic.Add("字段名称", fieldName);
  361. condiDic.Add("匹配条件", getQueryKind(fieldQueryKind));
  362. condiDic.Add("匹配方式", getQueryModel(fieldQueryModel));
  363. if(fieldQueryKind == "1") //模糊匹配
  364. {
  365. condi += " and " + fieldEnName + " like ";
  366. if(fieldQueryModel == "request_param")
  367. {
  368. Dictionary<string, string> req = getRequestParams(projectId, content);
  369. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  370. condi += "'%" + val + "%'";
  371. condiDic.Add("匹配值", val);
  372. }
  373. else if(fieldQueryModel == "fixed_value")
  374. {
  375. string val = GetExpressionVal(fieldQueryValue);
  376. condi += "'%" + val + "%'";
  377. condiDic.Add("匹配值", val);
  378. }
  379. else if(fieldQueryModel == "db_field")
  380. {
  381. string val = GetDbExpressionVal(fieldQueryValue);
  382. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  383. condiDic.Add("匹配值", val);
  384. }
  385. }
  386. else if(fieldQueryKind == "2") //精确匹配
  387. {
  388. condi += " and " + fieldEnName + "=";
  389. string val = "";
  390. if(fieldQueryModel == "request_param")
  391. {
  392. Dictionary<string, string> req = getRequestParams(projectId, content);
  393. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  394. }
  395. else if(fieldQueryModel == "fixed_value")
  396. {
  397. val = GetExpressionVal(fieldQueryValue);
  398. }
  399. else if(fieldQueryModel == "db_field")
  400. {
  401. val = GetDbExpressionVal(fieldQueryValue);
  402. }
  403. if(fieldQueryValueType == "text")
  404. {
  405. val = "'" + val + "'";
  406. }
  407. condi += val;
  408. condiDic.Add("匹配值", val);
  409. }
  410. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  411. {
  412. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  413. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  414. string val = "";
  415. string[] valList = fieldQueryValue.Split(',');
  416. if(fieldQueryModel == "request_param")
  417. {
  418. Dictionary<string, string> req = getRequestParams(projectId, content);
  419. foreach(string sub in valList)
  420. {
  421. if(fieldQueryValueType == "text")
  422. {
  423. val += "'" + req[sub] + "',";
  424. }
  425. else
  426. {
  427. val += req[sub] + ",";
  428. }
  429. }
  430. }
  431. else if(fieldQueryModel == "fixed_value")
  432. {
  433. foreach(string sub in valList)
  434. {
  435. if(fieldQueryValueType == "text")
  436. {
  437. val += "'" + GetExpressionVal(sub) + "',";
  438. }
  439. else
  440. {
  441. val += GetExpressionVal(sub) + ",";
  442. }
  443. }
  444. }
  445. else if(fieldQueryModel == "db_field")
  446. {
  447. foreach(string sub in valList)
  448. {
  449. if(fieldQueryValueType == "text")
  450. {
  451. val += "'" + GetDbExpressionVal(sub) + "',";
  452. }
  453. else
  454. {
  455. val += GetDbExpressionVal(sub) + ",";
  456. }
  457. }
  458. }
  459. val = val.TrimEnd(',');
  460. condi += val + ")";
  461. condiDic.Add("匹配值", val);
  462. }
  463. else if(fieldQueryKind == "3") //范围匹配
  464. {
  465. string[] val = fieldQueryValue.Split(':');
  466. if(fieldQueryModel == "request_param")
  467. {
  468. Dictionary<string, string> req = getRequestParams(projectId, content);
  469. if(fieldQueryValueType == "number")
  470. {
  471. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  472. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  473. }
  474. else
  475. {
  476. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  477. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  478. }
  479. }
  480. else if(fieldQueryModel == "fixed_value")
  481. {
  482. if(fieldQueryValueType == "number")
  483. {
  484. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  485. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  486. }
  487. else
  488. {
  489. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  490. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  491. }
  492. }
  493. else if(fieldQueryModel == "db_field")
  494. {
  495. if(fieldQueryValueType == "number")
  496. {
  497. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  498. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  499. }
  500. else
  501. {
  502. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  503. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  504. }
  505. }
  506. condiDic.Add("匹配值", val);
  507. }
  508. else if(fieldQueryKind == "4") //取反匹配
  509. {
  510. condi += " and " + fieldEnName + "!=";
  511. string val = "";
  512. if(fieldQueryModel == "request_param")
  513. {
  514. Dictionary<string, string> req = getRequestParams(projectId, content);
  515. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  516. }
  517. else if(fieldQueryModel == "fixed_value")
  518. {
  519. val = GetExpressionVal(fieldQueryValue);
  520. }
  521. else if(fieldQueryModel == "db_field")
  522. {
  523. val = GetDbExpressionVal(fieldQueryValue);
  524. }
  525. if(fieldQueryValueType == "text")
  526. {
  527. val = "'" + val + "'";
  528. }
  529. condi += val;
  530. condiDic.Add("匹配值", val);
  531. }
  532. condiDics.Add(condiDic);
  533. }
  534. logStepDic.Add("奖励发放对象查询条件", condiDics);
  535. string result = "0";
  536. var db = initDb(prizeObjectTable.databaseId);
  537. var item = db.Ado.GetScalar("select " + field + " from " + prizeObjectTable.tableEnName + " where 1=1" + condi);
  538. if(item != null)
  539. {
  540. result = item.ToString();
  541. }
  542. logStepDic.Add("奖励发放对象", result);
  543. setLogStep(listId, "奖励发放对象", logStepDic);
  544. return result;
  545. }
  546. //奖励发放入口
  547. public static string prizeInSet(string queueName)
  548. {
  549. Dictionary<string, object> dic = new();
  550. var prizeInSetService = App.GetService<IPriPrizeInSetService>();
  551. //查询表
  552. var prizeInSet = prizeInSetService.GetFirst(m => m.mqQueueName == queueName) ?? new PriPrizeInSet();
  553. if(prizeInSet.id > 0)
  554. {
  555. return prizeInSet.prizeListIds + "|" + prizeInSet.projectId + "|" + prizeInSet.id;
  556. }
  557. return "";
  558. }
  559. //奖励列表
  560. public static List<PriList> prizeList(int projectId, string prizeIds)
  561. {
  562. List<int> ids = Tools.SpitIntArrary(prizeIds, ',').ToList();
  563. var priListService = App.GetService<IPriListService>();
  564. var priList = priListService.GetList(m => m.projectId == projectId && ids.Contains(m.id)).ToList();
  565. return priList;
  566. }
  567. //奖励发放
  568. public static void prizeSend(int projectId, int prizeInId, string prizeIds, string content, string queueName)
  569. {
  570. var loopSetService = App.GetService<IPriLoopSetService>();
  571. var recursionStartTableService = App.GetService<IPriRecursionStartTableService>();
  572. var recursionStartConditionService = App.GetService<IPriRecursionStartConditionService>();
  573. var priList = prizeList(projectId, prizeIds);
  574. foreach(var sub in priList)
  575. {
  576. try
  577. {
  578. addLog(projectId, sub.id, prizeInId, content, queueName); //初始化日志
  579. string prizeObjectId = prizeObject(sub.id, sub.prizeObj, content);
  580. var recursionFlag = sub.recursionFlag; //是否递归
  581. setLogStep(sub.id, "是否递归", recursionFlag ? "是" : "否");
  582. if(recursionFlag)
  583. {
  584. List<QueryCondition> queryCondiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content);
  585. setLogStep(sub.id, "查询原始数据", queryCondiDic);
  586. var loopSet = loopSetService.GetFirst(m => m.listId == sub.id) ?? new PriLoopSet();
  587. var recursionStartTable = recursionStartTableService.GetFirst(m => m.listId == sub.id) ?? new PriRecursionStartTable();
  588. var tableEnName = loopSet.tableEnName; //递归查询表
  589. var parentField = loopSet.parentField; //父字段
  590. var sonField = loopSet.sonField; //子字段
  591. var afterPrizeFlag = loopSet.afterPrizeFlag; //发奖后是否继续
  592. var db = initDb(loopSet.databaseId);
  593. string objId = prizeObjectId;
  594. bool op = true;
  595. int index = 0;
  596. loopAmount = 0;
  597. List<Dictionary<string, object>> loopLogDic = new();
  598. while(!string.IsNullOrEmpty(objId) && objId != "0" && op)
  599. {
  600. Dictionary<string, object> loopLog = new();
  601. List<QueryCondition> condiDic = loopCondition(projectId, sub, objId, content);
  602. loopLog.Add("查询" + objId + "匹配数据", condiDic);
  603. if(condiDic.Count > 0)
  604. {
  605. bool prizeFlag = true;
  606. var conditions = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id);
  607. if(conditions.Count > 0)
  608. {
  609. int allCount = conditions.Count; //所有奖励条件数
  610. int passCount = 0; //通过条件数
  611. List<Dictionary<string, object>> logStepDics = new();
  612. foreach(var condition in conditions)
  613. {
  614. if(condition.startIndex <= index)
  615. {
  616. Dictionary<string, object> logStepDic = new();
  617. var returnFieldId = condition.returnFieldId; //条件返回字段
  618. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  619. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  620. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  621. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  622. string checkObj = "";
  623. string checkTitle = "";
  624. if(returnFieldId.Contains(","))
  625. {
  626. string[] returnFieldIdList = returnFieldId.Split(',');
  627. foreach(string subField in returnFieldIdList)
  628. {
  629. string val = GetQueryTableData(condiDic, subField);
  630. checkObj += val + ",";
  631. string title = GetQueryTableTitle(condiDic, subField);
  632. checkTitle += title + ",";
  633. }
  634. checkObj = checkObj.TrimEnd(',');
  635. checkTitle = checkTitle.TrimEnd(',');
  636. }
  637. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  638. {
  639. string expresssion = returnFieldId;
  640. checkTitle = returnFieldId;
  641. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  642. foreach(string returnField in returnFields)
  643. {
  644. string val = GetQueryTableData(condiDic, returnField);
  645. expresssion = expresssion.Replace(returnField, val);
  646. string title = GetQueryTableTitle(condiDic, returnField);
  647. checkTitle = checkTitle.Replace(returnField, title);
  648. }
  649. DataTable dt = new();
  650. checkObj = dt.Compute(expresssion, "false").ToString();
  651. }
  652. else
  653. {
  654. checkObj = GetQueryTableData(condiDic, returnFieldId);
  655. checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
  656. }
  657. logStepDic.Add("标题", checkTitle);
  658. logStepDic.Add("匹配条件", getQueryKind(fieldQueryKind));
  659. logStepDic.Add("匹配方式", getQueryModel(fieldQueryModel));
  660. logStepDic.Add("匹配值", fieldQueryValue);
  661. logStepDic.Add("实际值", checkObj);
  662. var checkVal = fieldQueryValue;
  663. bool passFlag = false;
  664. if(fieldQueryKind == "1") //模糊匹配
  665. {
  666. if(fieldQueryValueType == "text")
  667. {
  668. if(checkObj.ToString().Contains(GetExpressionVal(checkVal)))
  669. {
  670. passCount += 1; passFlag = true;
  671. }
  672. }
  673. }
  674. else if(fieldQueryKind == "2") //精确匹配
  675. {
  676. if(fieldQueryValueType == "int")
  677. {
  678. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal)))
  679. {
  680. passCount += 1; passFlag = true;
  681. }
  682. }
  683. else if(fieldQueryValueType == "number")
  684. {
  685. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal)))
  686. {
  687. passCount += 1; passFlag = true;
  688. }
  689. }
  690. else
  691. {
  692. if(checkObj.ToString() == GetExpressionVal(checkVal))
  693. {
  694. passCount += 1; passFlag = true;
  695. }
  696. }
  697. }
  698. else if(fieldQueryKind == "3") //范围匹配
  699. {
  700. string[] val = checkVal.Split(':');
  701. string valLeft = val[0];
  702. string valRight = val[1];
  703. if(fieldQueryModel == "request_param")
  704. {
  705. Dictionary<string, string> req = getRequestParams(projectId, content);
  706. if(fieldQueryValueType == "number")
  707. {
  708. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight])))
  709. {
  710. passCount += 1; passFlag = true;
  711. }
  712. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])))
  713. {
  714. passCount += 1; passFlag = true;
  715. }
  716. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight])))
  717. {
  718. passCount += 1; passFlag = true;
  719. }
  720. }
  721. else if(fieldQueryValueType == "int")
  722. {
  723. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight])))
  724. {
  725. passCount += 1; passFlag = true;
  726. }
  727. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])))
  728. {
  729. passCount += 1; passFlag = true;
  730. }
  731. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight])))
  732. {
  733. passCount += 1; passFlag = true;
  734. }
  735. }
  736. else if(fieldQueryValueType.StartsWith("date"))
  737. {
  738. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  739. {
  740. passCount += 1; passFlag = true;
  741. }
  742. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]))
  743. {
  744. passCount += 1; passFlag = true;
  745. }
  746. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  747. {
  748. passCount += 1; passFlag = true;
  749. }
  750. }
  751. }
  752. else if(fieldQueryModel == "fixed_value")
  753. {
  754. string checkValLeft = valLeft.Replace("#{", "").Replace("}#", "");
  755. string checkValRight = valRight.Replace("#{", "").Replace("}#", "");
  756. if(checkValLeft.Contains(",")) checkValLeft = checkValLeft.Split(',')[0];
  757. if(checkValRight.Contains(",")) checkValRight = checkValRight.Split(',')[0];
  758. valLeft = GetExpressionVal(valLeft);
  759. valRight = GetExpressionVal(valRight);
  760. if(fieldQueryValueType == "number")
  761. {
  762. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(valLeft)) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  763. {
  764. passCount += 1; passFlag = true;
  765. }
  766. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  767. {
  768. passCount += 1; passFlag = true;
  769. }
  770. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  771. {
  772. passCount += 1; passFlag = true;
  773. }
  774. }
  775. else if(fieldQueryValueType == "int")
  776. {
  777. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(valLeft)) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  778. {
  779. passCount += 1; passFlag = true;
  780. }
  781. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  782. {
  783. passCount += 1; passFlag = true;
  784. }
  785. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  786. {
  787. passCount += 1; passFlag = true;
  788. }
  789. }
  790. else if(fieldQueryValueType.StartsWith("date"))
  791. {
  792. if(valLeft == "0") valLeft = "";
  793. if(valRight == "0") valRight = "";
  794. if(checkObj != "0" && checkObj != "")
  795. {
  796. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  797. {
  798. passCount += 1; passFlag = true;
  799. }
  800. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)))
  801. {
  802. passCount += 1; passFlag = true;
  803. }
  804. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  805. {
  806. passCount += 1; passFlag = true;
  807. }
  808. }
  809. }
  810. }
  811. else if(fieldQueryModel == "query_field")
  812. {
  813. valLeft = GetComputeVal(queryCondiDic, valLeft);
  814. valRight = GetComputeVal(queryCondiDic, valRight);
  815. if(fieldQueryValueType == "number")
  816. {
  817. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(valLeft)) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  818. {
  819. passCount += 1; passFlag = true;
  820. }
  821. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  822. {
  823. passCount += 1; passFlag = true;
  824. }
  825. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  826. {
  827. passCount += 1; passFlag = true;
  828. }
  829. }
  830. else if(fieldQueryValueType == "int")
  831. {
  832. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(valLeft)) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  833. {
  834. passCount += 1; passFlag = true;
  835. }
  836. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  837. {
  838. passCount += 1; passFlag = true;
  839. }
  840. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  841. {
  842. passCount += 1; passFlag = true;
  843. }
  844. }
  845. else if(fieldQueryValueType.StartsWith("date"))
  846. {
  847. if(valLeft == "0") valLeft = "";
  848. if(valRight == "0") valRight = "";
  849. if(checkObj != "0" && checkObj != "")
  850. {
  851. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  852. {
  853. passCount += 1; passFlag = true;
  854. }
  855. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)))
  856. {
  857. passCount += 1; passFlag = true;
  858. }
  859. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  860. {
  861. passCount += 1; passFlag = true;
  862. }
  863. }
  864. }
  865. }
  866. }
  867. else if(fieldQueryKind == "4") //取反匹配
  868. {
  869. if(fieldQueryValueType == "int")
  870. {
  871. if(int.Parse(checkObj) != int.Parse(Function.CheckInt(checkVal)))
  872. {
  873. passCount += 1; passFlag = true;
  874. }
  875. }
  876. else if(fieldQueryValueType == "number")
  877. {
  878. if(decimal.Parse(checkObj) != decimal.Parse(Function.CheckNum(checkVal)))
  879. {
  880. passCount += 1; passFlag = true;
  881. }
  882. }
  883. else if(fieldQueryValueType == "text")
  884. {
  885. if(checkObj.ToString() != GetExpressionVal(checkVal))
  886. {
  887. passCount += 1; passFlag = true;
  888. }
  889. }
  890. }
  891. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  892. {
  893. string val = ",";
  894. string[] valList = checkVal.Split(',');
  895. if(fieldQueryModel == "request_param")
  896. {
  897. Dictionary<string, string> req = getRequestParams(projectId, content);
  898. foreach(string subVal in valList)
  899. {
  900. val += req[subVal] + ",";
  901. }
  902. }
  903. else if(fieldQueryModel == "fixed_value")
  904. {
  905. foreach(string subVal in valList)
  906. {
  907. val += GetExpressionVal(subVal) + ",";
  908. }
  909. }
  910. else if(fieldQueryModel == "db_field")
  911. {
  912. foreach(string subVal in valList)
  913. {
  914. val += GetDbExpressionVal(subVal) + ",";
  915. }
  916. }
  917. if(fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ","))
  918. {
  919. passCount += 1; passFlag = true;
  920. }
  921. if(fieldQueryKind == "6" && !val.Contains("," + checkObj.ToString() + ","))
  922. {
  923. passCount += 1; passFlag = true;
  924. }
  925. }
  926. logStepDic.Add("状态", passFlag ? "通过" : "未通过");
  927. logStepDics.Add(logStepDic);
  928. }
  929. }
  930. loopLog.Add(objId + "匹配情况", logStepDics);
  931. if(loopSet.conditionMode == "all" && passCount == allCount) prizeFlag = true;
  932. else if(loopSet.conditionMode == "one" && passCount >= 1) prizeFlag = true;
  933. else if(loopSet.conditionMode == "two" && passCount >= 2) prizeFlag = true;
  934. else if(loopSet.conditionMode == "three" && passCount >= 3) prizeFlag = true;
  935. else prizeFlag = false;
  936. }
  937. else
  938. {
  939. prizeFlag = false;
  940. }
  941. loopLog.Add("匹配结果", prizeFlag);
  942. if(prizeFlag)
  943. {
  944. decimal prizeAmt = prizeSendDo(projectId, sub, objId, content, loopSet);
  945. op = afterPrizeFlag;
  946. }
  947. }
  948. loopLogDic.Add(loopLog);
  949. var parent = db.Ado.GetScalar("select " + parentField + " from " + tableEnName + " where " + sonField + "=" + objId);
  950. if(parent != null)
  951. {
  952. objId = parent.ToString();
  953. }
  954. else
  955. {
  956. objId = "0";
  957. }
  958. index += 1;
  959. }
  960. setLogStep(sub.id, "向上递归流程", loopLogDic);
  961. }
  962. else
  963. {
  964. prizeSendDo(projectId, sub, prizeObjectId, content, new PriLoopSet());
  965. }
  966. }
  967. catch(Exception ex)
  968. {
  969. setLogFieldValue(sub.id, "errLog", ex.ToString());
  970. }
  971. }
  972. }
  973. static decimal loopAmount = 0;
  974. public static decimal prizeSendDo(int projectId, PriList sub, string prizeObjectId, string content, PriLoopSet set)
  975. {
  976. var projectService = App.GetService<IPriProjectService>();
  977. var recordService = App.GetService<IPriRecordService>();
  978. var conditionService = App.GetService<IPriConditionService>();
  979. var returnFieldService = App.GetService<IPriReturnFieldService>();
  980. var queryTableService = App.GetService<IPriQueryTableService>();
  981. var amountSetService = App.GetService<IPriListAmountSetService>();
  982. var project = projectService.GetFirst(m => m.id == projectId) ?? new PriProject();
  983. //查询匹配条件
  984. List<QueryCondition> condiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content);
  985. if(sub.prizeSourceFieldType == "loop") MergeCondiDic(condiDic, loopCondition(projectId, sub, prizeObjectId, content));
  986. setLogStep(sub.id, "发放奖励查询来源数据", condiDic);
  987. var prizeSourceField = sub.prizeSourceField; //奖励金额来源字段(对应条件匹配返回字段)
  988. var prizePercent = sub.prizePercent; //奖励比例
  989. var prizeAmount = sub.prizeAmount; //奖励固定值
  990. var prizeContent = sub.prizeContent; //奖励内容
  991. var conditionMode = sub.conditionMode; //条件模式
  992. var recursionFlag = sub.recursionFlag; //是否递归
  993. var conditions = conditionService.GetList(m => m.listId == sub.id);
  994. setLogStep(sub.id, "发放奖励匹配条件", condiDic);
  995. int allCount = conditions.Count; //所有奖励条件数
  996. int passCount = 0; //通过条件数
  997. List<Dictionary<string, object>> logStepDics = new();
  998. foreach(var condition in conditions)
  999. {
  1000. Dictionary<string, object> logStepDic = new();
  1001. var returnFieldId = condition.returnFieldId; //条件返回字段
  1002. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  1003. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  1004. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  1005. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  1006. string checkObj = "";
  1007. string checkTitle = "";
  1008. if(returnFieldId.Contains(","))
  1009. {
  1010. string[] returnFieldIdList = returnFieldId.Split(',');
  1011. foreach(string subField in returnFieldIdList)
  1012. {
  1013. string val = GetQueryTableData(condiDic, subField);
  1014. checkObj += val + ",";
  1015. string title = GetQueryTableTitle(condiDic, subField);
  1016. checkTitle += title + ",";
  1017. }
  1018. checkObj = checkObj.TrimEnd(',');
  1019. checkTitle = checkTitle.TrimEnd(',');
  1020. }
  1021. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  1022. {
  1023. string expresssion = returnFieldId;
  1024. checkTitle = returnFieldId;
  1025. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  1026. foreach(string returnField in returnFields)
  1027. {
  1028. string val = GetQueryTableData(condiDic, returnField);
  1029. expresssion = expresssion.Replace(returnField, val);
  1030. string title = GetQueryTableTitle(condiDic, returnField);
  1031. checkTitle = checkTitle.Replace(returnField, title);
  1032. }
  1033. DataTable dt = new();
  1034. checkObj = dt.Compute(expresssion, "false").ToString();
  1035. }
  1036. else
  1037. {
  1038. checkObj = GetQueryTableData(condiDic, returnFieldId);
  1039. checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
  1040. }
  1041. if(!sub.recursionFlag)
  1042. {
  1043. logStepDic.Add("标题", checkTitle);
  1044. logStepDic.Add("匹配条件", getQueryKind(fieldQueryKind));
  1045. logStepDic.Add("匹配方式", getQueryModel(fieldQueryModel));
  1046. logStepDic.Add("匹配值", fieldQueryValue);
  1047. logStepDic.Add("实际值", checkObj);
  1048. }
  1049. string checkVal = fieldQueryValue;
  1050. bool passFlag = false;
  1051. if(fieldQueryKind == "1") //模糊匹配
  1052. {
  1053. if(fieldQueryValueType == "text")
  1054. {
  1055. if(checkObj.ToString().Contains(GetExpressionVal(checkVal)))
  1056. {
  1057. passCount += 1; passFlag = true;
  1058. }
  1059. }
  1060. }
  1061. else if(fieldQueryKind == "2") //精确匹配
  1062. {
  1063. if(fieldQueryValueType == "int")
  1064. {
  1065. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal)))
  1066. {
  1067. passCount += 1; passFlag = true;
  1068. }
  1069. }
  1070. else if(fieldQueryValueType == "number")
  1071. {
  1072. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal)))
  1073. {
  1074. passCount += 1; passFlag = true;
  1075. }
  1076. }
  1077. else
  1078. {
  1079. if(checkObj.ToString() == GetExpressionVal(checkVal))
  1080. {
  1081. passCount += 1; passFlag = true;
  1082. }
  1083. }
  1084. }
  1085. else if(fieldQueryKind == "3") //范围匹配
  1086. {
  1087. string[] val = checkVal.Split(':');
  1088. string valLeft = val[0];
  1089. string valRight = val[1];
  1090. if(fieldQueryModel == "request_param")
  1091. {
  1092. Dictionary<string, string> req = getRequestParams(projectId, content);
  1093. if(fieldQueryValueType == "number")
  1094. {
  1095. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight])))
  1096. {
  1097. passCount += 1; passFlag = true;
  1098. }
  1099. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])))
  1100. {
  1101. passCount += 1; passFlag = true;
  1102. }
  1103. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight])))
  1104. {
  1105. passCount += 1; passFlag = true;
  1106. }
  1107. }
  1108. else if(fieldQueryValueType == "int")
  1109. {
  1110. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight])))
  1111. {
  1112. passCount += 1; passFlag = true;
  1113. }
  1114. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])))
  1115. {
  1116. passCount += 1; passFlag = true;
  1117. }
  1118. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight])))
  1119. {
  1120. passCount += 1; passFlag = true;
  1121. }
  1122. }
  1123. else if(fieldQueryValueType.StartsWith("date"))
  1124. {
  1125. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1126. {
  1127. passCount += 1; passFlag = true;
  1128. }
  1129. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]))
  1130. {
  1131. passCount += 1; passFlag = true;
  1132. }
  1133. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1134. {
  1135. passCount += 1; passFlag = true;
  1136. }
  1137. }
  1138. }
  1139. else if(fieldQueryModel == "fixed_value")
  1140. {
  1141. valLeft = GetExpressionVal(valLeft);
  1142. valRight = GetExpressionVal(valRight);
  1143. if(fieldQueryValueType == "number")
  1144. {
  1145. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1146. {
  1147. passCount += 1; passFlag = true;
  1148. }
  1149. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1150. {
  1151. passCount += 1; passFlag = true;
  1152. }
  1153. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1154. {
  1155. passCount += 1; passFlag = true;
  1156. }
  1157. }
  1158. else if(fieldQueryValueType == "int")
  1159. {
  1160. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckNum(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1161. {
  1162. passCount += 1; passFlag = true;
  1163. }
  1164. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1165. {
  1166. passCount += 1; passFlag = true;
  1167. }
  1168. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1169. {
  1170. passCount += 1; passFlag = true;
  1171. }
  1172. }
  1173. else if(fieldQueryValueType.StartsWith("date"))
  1174. {
  1175. if(valLeft == "0") valLeft = "";
  1176. if(valRight == "0") valRight = "";
  1177. if(checkObj != "0" && checkObj != "")
  1178. {
  1179. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1180. {
  1181. passCount += 1; passFlag = true;
  1182. }
  1183. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1184. {
  1185. passCount += 1; passFlag = true;
  1186. }
  1187. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1188. {
  1189. passCount += 1; passFlag = true;
  1190. }
  1191. }
  1192. }
  1193. }
  1194. else if(fieldQueryModel == "query_field")
  1195. {
  1196. string checkValLeft = valLeft.Replace("#{", "").Replace("}#", "");
  1197. string checkValRight = valRight.Replace("#{", "").Replace("}#", "");
  1198. if(checkValLeft.Contains(",")) checkValLeft = checkValLeft.Split(',')[0];
  1199. if(checkValRight.Contains(",")) checkValRight = checkValRight.Split(',')[0];
  1200. if(!string.IsNullOrEmpty(valLeft)) valLeft = valLeft.Replace(checkValLeft, GetQueryTableData(condiDic, checkValLeft));
  1201. if(!string.IsNullOrEmpty(valRight)) valRight = valRight.Replace(checkValRight, GetQueryTableData(condiDic, checkValRight));
  1202. valLeft = GetExpressionVal(valLeft);
  1203. valRight = GetExpressionVal(valRight);
  1204. if(fieldQueryValueType == "number")
  1205. {
  1206. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1207. {
  1208. passCount += 1; passFlag = true;
  1209. }
  1210. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1211. {
  1212. passCount += 1; passFlag = true;
  1213. }
  1214. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1215. {
  1216. passCount += 1; passFlag = true;
  1217. }
  1218. }
  1219. else if(fieldQueryValueType == "int")
  1220. {
  1221. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckNum(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1222. {
  1223. passCount += 1; passFlag = true;
  1224. }
  1225. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1226. {
  1227. passCount += 1; passFlag = true;
  1228. }
  1229. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1230. {
  1231. passCount += 1; passFlag = true;
  1232. }
  1233. }
  1234. else if(fieldQueryValueType.StartsWith("date"))
  1235. {
  1236. if(valLeft == "0") valLeft = "";
  1237. if(valRight == "0") valRight = "";
  1238. if(checkObj != "0" && checkObj != "")
  1239. {
  1240. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1241. {
  1242. passCount += 1; passFlag = true;
  1243. }
  1244. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1245. {
  1246. passCount += 1; passFlag = true;
  1247. }
  1248. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1249. {
  1250. passCount += 1; passFlag = true;
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. else if(fieldQueryKind == "4") //取反匹配
  1257. {
  1258. if(fieldQueryValueType == "int")
  1259. {
  1260. if(int.Parse(Function.CheckNum(checkObj.ToString())) != int.Parse(Function.CheckInt(checkVal)))
  1261. {
  1262. passCount += 1; passFlag = true;
  1263. }
  1264. }
  1265. else if(fieldQueryValueType == "number")
  1266. {
  1267. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) != decimal.Parse(Function.CheckNum(checkVal)))
  1268. {
  1269. passCount += 1; passFlag = true;
  1270. }
  1271. }
  1272. else if(fieldQueryValueType == "text")
  1273. {
  1274. if(checkObj.ToString() != GetExpressionVal(checkVal))
  1275. {
  1276. passCount += 1; passFlag = true;
  1277. }
  1278. }
  1279. }
  1280. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1281. {
  1282. string val = ",";
  1283. string[] valList = checkVal.Split(',');
  1284. if(fieldQueryModel == "request_param")
  1285. {
  1286. Dictionary<string, string> req = getRequestParams(projectId, content);
  1287. foreach(string subVal in valList)
  1288. {
  1289. val += req[subVal] + ",";
  1290. }
  1291. }
  1292. else if(fieldQueryModel == "fixed_value")
  1293. {
  1294. foreach(string subVal in valList)
  1295. {
  1296. val += GetExpressionVal(subVal) + ",";
  1297. }
  1298. }
  1299. else if(fieldQueryModel == "db_field")
  1300. {
  1301. foreach(string subVal in valList)
  1302. {
  1303. val += GetDbExpressionVal(subVal) + ",";
  1304. }
  1305. }
  1306. if (fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ","))
  1307. {
  1308. passCount += 1; passFlag = true;
  1309. }
  1310. if(fieldQueryKind == "6" && !val.Contains("," + checkObj.ToString() + ","))
  1311. {
  1312. passCount += 1; passFlag = true;
  1313. }
  1314. }
  1315. if(!sub.recursionFlag)
  1316. {
  1317. logStepDic.Add("状态", passFlag ? "通过" : "未通过");
  1318. logStepDics.Add(logStepDic);
  1319. }
  1320. }
  1321. setLogStep(sub.id, "匹配结果", logStepDics);
  1322. bool op = false;
  1323. decimal prizeAmt = 0;
  1324. if(conditionMode == "all" && passCount == allCount && passCount > 0) op = true;
  1325. else if(conditionMode == "one" && passCount >= 1) op = true;
  1326. else if(conditionMode == "two" && passCount >= 2) op = true;
  1327. else if(conditionMode == "three" && passCount >= 3) op = true;
  1328. setLogStep(sub.id, "是否通过", op ? "是" : "否");
  1329. if(op) //满足条件
  1330. {
  1331. decimal number = 0;
  1332. if(prizeSourceField.Contains("/"))
  1333. {
  1334. number = decimal.Parse(prizeSourceField.Split('/')[1]);
  1335. prizeSourceField = prizeSourceField.Split('/')[0];
  1336. }
  1337. string prizeSourceData = "";
  1338. if(prizeSourceField.Contains(","))
  1339. {
  1340. string[] prizeSourceFieldList = prizeSourceField.Split(',');
  1341. foreach(string subField in prizeSourceFieldList)
  1342. {
  1343. string val = GetQueryTableData(condiDic, subField);
  1344. prizeSourceData += val + ",";
  1345. }
  1346. prizeSourceData = prizeSourceData.TrimEnd(',');
  1347. }
  1348. else
  1349. {
  1350. prizeSourceData = GetQueryTableData(condiDic, prizeSourceField);
  1351. }
  1352. if(string.IsNullOrEmpty(prizeSourceData)) prizeSourceData = "0";
  1353. if(prizeSourceField.Contains("/") && number > 0)
  1354. {
  1355. decimal prizeSourceDataNum = decimal.Parse(prizeSourceData) / number;
  1356. prizeSourceData = prizeSourceDataNum.ToString("f2");
  1357. }
  1358. var amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField == prizeSourceData);
  1359. if(amountSet != null)
  1360. {
  1361. prizePercent = amountSet.prizePercent;
  1362. prizeAmount = amountSet.prizeAmount;
  1363. }
  1364. if(prizeSourceData.Contains(","))
  1365. {
  1366. string checkField = prizeSourceData.Split(',')[0] + ",";
  1367. amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField.StartsWith(checkField) && m.prizeSourceField.EndsWith(",%"));
  1368. if(amountSet != null)
  1369. {
  1370. prizePercent = amountSet.prizePercent;
  1371. prizeAmount = amountSet.prizeAmount;
  1372. prizeSourceData = prizeSourceData.Split(',')[1];
  1373. }
  1374. }
  1375. if(prizePercent > 0) prizeAmt += decimal.Parse(Function.CheckNum(prizeSourceData)) * prizePercent;
  1376. if(prizeAmount > 0) prizeAmt += prizeAmount;
  1377. decimal getPrizeAmount = prizeAmt;
  1378. if(set.levelDiffFlag) prizeAmt -= loopAmount;
  1379. setLogStep(sub.id, "发放金额", prizeAmt);
  1380. if(prizeAmt > 0)
  1381. {
  1382. setLogPrizeAmount(sub.id, prizeAmt);
  1383. var req = getRequestParams(projectId, content);
  1384. var requestParamField = req[sub.requestParamField];
  1385. var sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == requestParamField);
  1386. if(!sendFlag)
  1387. {
  1388. PriRecord item = new PriRecord()
  1389. {
  1390. createDate = DateTime.Now,
  1391. projectId = projectId,
  1392. listId = sub.id,
  1393. prizeAmount = prizeAmt,
  1394. prizeObjId = prizeObjectId,
  1395. requestParamField = content,
  1396. batchNo = batchNo,
  1397. };
  1398. recordService.Add(item);
  1399. string prizeOutContent = Newtonsoft.Json.JsonConvert.SerializeObject(item);
  1400. setLogFieldValue(sub.id, "prizeOutContent", prizeOutContent);
  1401. setLogFieldValue(sub.id, "prizeOutUrl", project.noticeUrl);
  1402. loopAmount = getPrizeAmount;
  1403. if(project.requestMode == "http" && !string.IsNullOrEmpty(project.noticeUrl))
  1404. {
  1405. Function.PostWebRequest(project.noticeUrl, prizeOutContent, "application/json");
  1406. }
  1407. else if(project.requestMode == "mq")
  1408. {}
  1409. else
  1410. {
  1411. prizeToDatabase(projectId, sub.id, content, condiDic, prizeAmt); //入库
  1412. }
  1413. }
  1414. }
  1415. }
  1416. // if(!sub.recursionFlag)
  1417. // {
  1418. setLogStatus(sub.id, op ? 1 : 0);
  1419. // }
  1420. return prizeAmt;
  1421. }
  1422. //递归条件判断
  1423. public static List<QueryCondition> loopCondition(int projectId, PriList sub, string objId, string content)
  1424. {
  1425. List<QueryCondition> dic = new();
  1426. var queryTableService = App.GetService<IPriRecursionStartTableService>();
  1427. var queryFieldService = App.GetService<IPriRecursionStartFieldService>();
  1428. var queryReturnFieldService = App.GetService<IPriRecursionStartReturnFieldService>();
  1429. int passCount = 0;
  1430. //查询表
  1431. var queryTables = queryTableService.GetList(m => m.listId == sub.id);
  1432. int allCount = queryTables.Count;
  1433. foreach(var queryTable in queryTables)
  1434. {
  1435. //查询返回字段
  1436. string fields = "1";
  1437. Dictionary<string, string> fieldDic = new();
  1438. var returnFields = queryReturnFieldService.GetList(m => m.objectTableId == queryTable.id);
  1439. if(returnFields.Count > 0)
  1440. {
  1441. fields = "";
  1442. foreach(var returnField in returnFields)
  1443. {
  1444. if(returnField.fieldReturnKind == "2")
  1445. {
  1446. fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1447. }
  1448. else if(returnField.fieldReturnKind == "3")
  1449. {
  1450. fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1451. }
  1452. else if(returnField.fieldReturnKind == "4")
  1453. {
  1454. fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1455. }
  1456. else
  1457. {
  1458. fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1459. }
  1460. fieldDic.Add(queryTable.tableEnName + "_" + returnField.fieldEnName, returnField.fieldName);
  1461. }
  1462. fields = fields.TrimEnd(',');
  1463. }
  1464. //查询匹配条件
  1465. string condi = "";
  1466. var queryFields = queryFieldService.GetList(m => m.objectTableId == queryTable.id);
  1467. foreach(var queryField in queryFields)
  1468. {
  1469. string fieldEnName = queryField.fieldEnName;
  1470. string fieldQueryKind = queryField.fieldQueryKind;
  1471. string fieldQueryModel = queryField.fieldQueryModel;
  1472. string fieldQueryValue = queryField.fieldQueryValue;
  1473. if(fieldQueryModel == "loop_field") fieldQueryValue = objId;
  1474. string fieldQueryValueType = queryField.fieldQueryValueType;
  1475. if(fieldQueryKind == "1") //模糊匹配
  1476. {
  1477. condi += " and " + fieldEnName + " like ";
  1478. if(fieldQueryModel == "request_param")
  1479. {
  1480. Dictionary<string, string> req = getRequestParams(projectId, content);
  1481. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1482. condi += "'%" + val + "%'";
  1483. }
  1484. else if(fieldQueryModel == "fixed_value")
  1485. {
  1486. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  1487. }
  1488. else if(fieldQueryModel == "db_field")
  1489. {
  1490. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  1491. }
  1492. }
  1493. else if(fieldQueryKind == "2") //精确匹配
  1494. {
  1495. condi += " and " + fieldEnName + "=";
  1496. string val = fieldQueryValue;
  1497. if(fieldQueryModel == "request_param")
  1498. {
  1499. Dictionary<string, string> req = getRequestParams(projectId, content);
  1500. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1501. }
  1502. else if(fieldQueryModel == "fixed_value")
  1503. {
  1504. val = GetExpressionVal(fieldQueryValue);
  1505. }
  1506. else if(fieldQueryModel == "db_field")
  1507. {
  1508. val = GetDbExpressionVal(fieldQueryValue);
  1509. }
  1510. if(fieldQueryValueType == "text")
  1511. {
  1512. val = "'" + val + "'";
  1513. }
  1514. condi += val;
  1515. }
  1516. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1517. {
  1518. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  1519. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  1520. string val = "";
  1521. string[] valList = fieldQueryValue.Split(',');
  1522. if(fieldQueryModel == "request_param")
  1523. {
  1524. Dictionary<string, string> req = getRequestParams(projectId, content);
  1525. foreach(string subval in valList)
  1526. {
  1527. if(fieldQueryValueType == "text")
  1528. {
  1529. val += "'" + req[subval] + "',";
  1530. }
  1531. else
  1532. {
  1533. val += req[subval] + ",";
  1534. }
  1535. }
  1536. }
  1537. else if(fieldQueryModel == "fixed_value")
  1538. {
  1539. foreach(string subval in valList)
  1540. {
  1541. if(fieldQueryValueType == "text")
  1542. {
  1543. val += "'" + GetExpressionVal(subval) + "',";
  1544. }
  1545. else
  1546. {
  1547. val += GetExpressionVal(subval) + ",";
  1548. }
  1549. }
  1550. }
  1551. else if(fieldQueryModel == "db_field")
  1552. {
  1553. foreach(string subval in valList)
  1554. {
  1555. if(fieldQueryValueType == "text")
  1556. {
  1557. val += "'" + GetDbExpressionVal(subval) + "',";
  1558. }
  1559. else
  1560. {
  1561. val += GetDbExpressionVal(subval) + ",";
  1562. }
  1563. }
  1564. }
  1565. val = val.TrimEnd(',');
  1566. condi += val + ")";
  1567. }
  1568. else if(fieldQueryKind == "3") //范围匹配
  1569. {
  1570. string[] val = fieldQueryValue.Split(':');
  1571. if(fieldQueryModel == "request_param")
  1572. {
  1573. Dictionary<string, string> req = getRequestParams(projectId, content);
  1574. if(fieldQueryValueType == "number")
  1575. {
  1576. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  1577. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  1578. }
  1579. else
  1580. {
  1581. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  1582. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  1583. }
  1584. }
  1585. else if(fieldQueryModel == "fixed_value")
  1586. {
  1587. if(fieldQueryValueType == "number")
  1588. {
  1589. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1590. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1591. }
  1592. else
  1593. {
  1594. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  1595. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  1596. }
  1597. }
  1598. else if(fieldQueryModel == "db_field")
  1599. {
  1600. if(fieldQueryValueType == "number")
  1601. {
  1602. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1603. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1604. }
  1605. else
  1606. {
  1607. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  1608. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  1609. }
  1610. }
  1611. }
  1612. else if(fieldQueryKind == "4") //取反匹配
  1613. {
  1614. condi += " and " + fieldEnName + "!=";
  1615. string val = "";
  1616. if(fieldQueryModel == "request_param")
  1617. {
  1618. Dictionary<string, string> req = getRequestParams(projectId, content);
  1619. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1620. }
  1621. else if(fieldQueryModel == "fixed_value")
  1622. {
  1623. val = GetExpressionVal(fieldQueryValue);
  1624. }
  1625. else if(fieldQueryModel == "db_field")
  1626. {
  1627. val = GetDbExpressionVal(fieldQueryValue);
  1628. }
  1629. if(fieldQueryValueType == "text")
  1630. {
  1631. val = "'" + val + "'";
  1632. }
  1633. condi += val;
  1634. }
  1635. }
  1636. var db = initDb(queryTable.databaseId);
  1637. string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
  1638. var items = db.Ado.GetDataTable(sql);
  1639. if(items.Rows.Count > 0)
  1640. {
  1641. foreach(string field in fieldDic.Keys)
  1642. {
  1643. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  1644. {
  1645. FieldName = fieldDic[field],
  1646. FieldEnName = field,
  1647. Value = items.Rows[0][field].ToString()
  1648. });
  1649. }
  1650. }
  1651. }
  1652. return dic;
  1653. }
  1654. //奖励入库
  1655. public static void prizeToDatabase(int projectId, int listId, string content, List<QueryCondition> condiDic, decimal prize_amt)
  1656. {
  1657. var prizeInTableService = App.GetService<IPriPrizeInTableService>();
  1658. var prizeInFieldService = App.GetService<IPriPrizeInFieldService>();
  1659. var prizeInQueryFieldService = App.GetService<IPriPrizeInQueryFieldService>();
  1660. //入库表
  1661. var prizeInTables = prizeInTableService.GetList(m => m.listId == listId);
  1662. foreach(var prizeInTable in prizeInTables)
  1663. {
  1664. var db = initDb(prizeInTable.databaseId);
  1665. Dictionary<string, object> doFields = new();
  1666. //入库字段
  1667. var prizeInFields = prizeInFieldService.GetList(m => m.inTableId == prizeInTable.id);
  1668. foreach(var prizeInField in prizeInFields)
  1669. {
  1670. string fieldEnName = prizeInField.fieldEnName;
  1671. string fieldQueryModel = prizeInField.fieldQueryModel;
  1672. string fieldQueryValue = prizeInField.fieldQueryValue;
  1673. string fieldQueryValueType = prizeInField.fieldQueryValueType;
  1674. if(fieldQueryModel == "request_param")
  1675. {
  1676. Dictionary<string, string> req = getRequestParams(projectId, content);
  1677. fieldQueryValue = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1678. }
  1679. else if(fieldQueryModel == "query_field")
  1680. {
  1681. fieldQueryValue = GetQueryTableData(condiDic, fieldQueryValue);
  1682. }
  1683. else if(fieldQueryModel == "fixed_value")
  1684. {
  1685. fieldQueryValue = GetExpressionVal(fieldQueryValue);
  1686. }
  1687. else if(fieldQueryModel == "db_field")
  1688. {
  1689. fieldQueryValue = GetDbExpressionVal(fieldQueryValue);
  1690. }
  1691. else if(fieldQueryModel == "prize_amt")
  1692. {
  1693. fieldQueryValue = prize_amt.ToString();
  1694. }
  1695. if(fieldQueryValueType == "text") doFields.Add(fieldEnName, fieldQueryValue);
  1696. if(fieldQueryValueType == "int") doFields.Add(fieldEnName, int.Parse(fieldQueryValue));
  1697. if(fieldQueryValueType == "number") doFields.Add(fieldEnName, decimal.Parse(fieldQueryValue));
  1698. if(fieldQueryValueType == "datetime") doFields.Add(fieldEnName, DateTime.Parse(fieldQueryValue));
  1699. if(fieldQueryValueType == "bool") doFields.Add(fieldEnName, bool.Parse(fieldQueryValue));
  1700. }
  1701. //查询匹配条件
  1702. string condi = "";
  1703. var queryFields = prizeInQueryFieldService.GetList(m => m.inTableId == prizeInTable.id);
  1704. foreach(var queryField in queryFields)
  1705. {
  1706. string fieldEnName = queryField.fieldEnName;
  1707. string fieldQueryKind = queryField.fieldQueryKind;
  1708. string fieldQueryModel = queryField.fieldQueryModel;
  1709. string fieldQueryValue = queryField.fieldQueryValue;
  1710. string fieldQueryValueType = queryField.fieldQueryValueType;
  1711. if(fieldQueryKind == "1") //模糊匹配
  1712. {
  1713. condi += " and " + fieldEnName + " like ";
  1714. if(fieldQueryModel == "request_param")
  1715. {
  1716. Dictionary<string, string> req = getRequestParams(projectId, content);
  1717. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1718. condi += "'%" + val + "%'";
  1719. }
  1720. else if(fieldQueryModel == "fixed_value")
  1721. {
  1722. condi += "'%" + fieldQueryValue + "%'";
  1723. }
  1724. else if(fieldQueryModel == "query_field")
  1725. {
  1726. condi += "'%" + GetQueryTableData(condiDic, fieldQueryValue) + "%'";
  1727. }
  1728. }
  1729. else if(fieldQueryKind == "2") //精确匹配
  1730. {
  1731. condi += " and " + fieldEnName + "=";
  1732. string val = "";
  1733. if(fieldQueryModel == "request_param")
  1734. {
  1735. Dictionary<string, string> req = getRequestParams(projectId, content);
  1736. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1737. }
  1738. else if(fieldQueryModel == "fixed_value")
  1739. {
  1740. val = fieldQueryValue;
  1741. }
  1742. else if(fieldQueryModel == "query_field")
  1743. {
  1744. val = GetQueryTableData(condiDic, fieldQueryValue);
  1745. }
  1746. if(fieldQueryValueType == "text")
  1747. {
  1748. val = "'" + val + "'";
  1749. }
  1750. condi += val;
  1751. }
  1752. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1753. {
  1754. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  1755. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  1756. string val = "";
  1757. string[] valList = fieldQueryValue.Split(',');
  1758. if(fieldQueryModel == "request_param")
  1759. {
  1760. Dictionary<string, string> req = getRequestParams(projectId, content);
  1761. foreach(string sub in valList)
  1762. {
  1763. if(fieldQueryValueType == "text")
  1764. {
  1765. val += "'" + req[sub] + "',";
  1766. }
  1767. else
  1768. {
  1769. val += req[sub] + ",";
  1770. }
  1771. }
  1772. }
  1773. else if(fieldQueryModel == "fixed_value")
  1774. {
  1775. foreach(string sub in valList)
  1776. {
  1777. if(fieldQueryValueType == "text")
  1778. {
  1779. val += "'" + GetExpressionVal(sub) + "',";
  1780. }
  1781. else
  1782. {
  1783. val += GetExpressionVal(sub) + ",";
  1784. }
  1785. }
  1786. }
  1787. else if(fieldQueryModel == "query_field")
  1788. {
  1789. foreach(string sub in valList)
  1790. {
  1791. if(fieldQueryValueType == "text")
  1792. {
  1793. val += "'" + GetQueryTableData(condiDic, sub) + "',";
  1794. }
  1795. else
  1796. {
  1797. val += GetQueryTableData(condiDic, sub) + ",";
  1798. }
  1799. }
  1800. }
  1801. else if(fieldQueryModel == "db_field")
  1802. {
  1803. foreach(string sub in valList)
  1804. {
  1805. if(fieldQueryValueType == "text")
  1806. {
  1807. val += "'" + GetDbExpressionVal(sub) + "',";
  1808. }
  1809. else
  1810. {
  1811. val += GetDbExpressionVal(sub) + ",";
  1812. }
  1813. }
  1814. }
  1815. val = val.TrimEnd(',');
  1816. condi += val + ")";
  1817. }
  1818. else if(fieldQueryKind == "3") //范围匹配
  1819. {
  1820. string[] val = fieldQueryValue.Split(':');
  1821. if(fieldQueryModel == "request_param")
  1822. {
  1823. Dictionary<string, string> req = getRequestParams(projectId, content);
  1824. if(fieldQueryValueType == "number")
  1825. {
  1826. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  1827. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  1828. }
  1829. else
  1830. {
  1831. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  1832. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  1833. }
  1834. }
  1835. else if(fieldQueryModel == "fixed_value")
  1836. {
  1837. if(fieldQueryValueType == "number")
  1838. {
  1839. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1840. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1841. }
  1842. else
  1843. {
  1844. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + val[0] + "'";
  1845. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + val[1] + "'";
  1846. }
  1847. }
  1848. }
  1849. else if(fieldQueryKind == "4") //取反匹配
  1850. {
  1851. condi += " and " + fieldEnName + "!=";
  1852. string val = "";
  1853. if(fieldQueryModel == "request_param")
  1854. {
  1855. Dictionary<string, string> req = getRequestParams(projectId, content);
  1856. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1857. }
  1858. else if(fieldQueryModel == "fixed_value")
  1859. {
  1860. val = fieldQueryValue;
  1861. }
  1862. if(fieldQueryValueType == "text")
  1863. {
  1864. val = "'" + val + "'";
  1865. }
  1866. condi += val;
  1867. }
  1868. }
  1869. // if(prizeInTable.excuteKind == "add") db.Insertable(doFields).AS(prizeInTable.tableEnName).ExecuteCommand();
  1870. // if(prizeInTable.excuteKind == "update") db.Updateable(doFields).AS(prizeInTable.tableEnName).Where("1=1" + condi).ExecuteCommand();
  1871. Function.WriteLog(DateTime.Now.ToString() + "\n" + prizeInTable.excuteKind + "\n" + prizeInTable.tableEnName + "\n" + Newtonsoft.Json.JsonConvert.SerializeObject(doFields) + "\n" + condi + "\n\n", "奖励入库数据");
  1872. }
  1873. }
  1874. //固定值表达式
  1875. public static string GetExpressionVal(string str)
  1876. {
  1877. if(str == "#{now}#") return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1878. if(str == "#{today}#") return DateTime.Now.ToString("yyyy-MM-dd");
  1879. if(str == "#{this_month}#") return DateTime.Now.ToString("yyyy-MM");
  1880. if(str.StartsWith("#{now") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
  1881. if(str.StartsWith("#{now") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
  1882. if(str.StartsWith("#{today") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1883. if(str.StartsWith("#{today") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1884. if(str.StartsWith("#{this_month") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1885. if(str.StartsWith("#{this_month") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1886. if(str.StartsWith("#{") && str.EndsWith("DAY}#")) return DateTime.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[0]).AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
  1887. if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) return DateTime.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[0]).AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
  1888. return str;
  1889. }
  1890. //库内字段值表达式
  1891. public static string GetDbExpressionVal(string str)
  1892. {
  1893. string[] data = str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',');
  1894. if(str.StartsWith("#{") && str.EndsWith("DAY}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " DAY)";
  1895. if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " MONTH)";
  1896. return str;
  1897. }
  1898. //四则混合运算
  1899. public static string GetComputeVal(List<QueryCondition> condiDic, string expresssion)
  1900. {
  1901. if (expresssion.Contains("+") || expresssion.Contains("-") || expresssion.Contains("*") || expresssion.Contains("/") || expresssion.Contains("(") || expresssion.Contains(")"))
  1902. {
  1903. string[] returnFields = expresssion.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  1904. foreach (string returnField in returnFields)
  1905. {
  1906. if(condiDic.Any(m => m.FieldEnName == returnField))
  1907. {
  1908. string val = GetQueryTableData(condiDic, returnField);
  1909. expresssion = expresssion.Replace(returnField, val);
  1910. }
  1911. }
  1912. DataTable dt = new();
  1913. return dt.Compute(expresssion, "false").ToString();
  1914. }
  1915. return expresssion;
  1916. }
  1917. //获取查询条件数据
  1918. public static string GetQueryTableData(List<QueryCondition> condiDic, string key)
  1919. {
  1920. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).Value.ToString() : "0";
  1921. }
  1922. public static string GetQueryTableTitle(List<QueryCondition> condiDic, string key)
  1923. {
  1924. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).FieldName : "";
  1925. }
  1926. //合并字典
  1927. public static void MergeCondiDic(List<QueryCondition> condiDic, List<QueryCondition> condiDic1)
  1928. {
  1929. foreach(QueryCondition sub in condiDic1)
  1930. {
  1931. condiDic.Add(sub);
  1932. }
  1933. }
  1934. //记录日志
  1935. public static void addLog(int projectId, int listId, int prizeIn, string requestParam, string prizeInUrl)
  1936. {
  1937. var logService = App.GetService<IPriLogService>();
  1938. logService.Add(new PriLog()
  1939. {
  1940. createDate = DateTime.Now,
  1941. projectId = projectId,
  1942. listId = listId,
  1943. batchNo = batchNo,
  1944. prizeIn = prizeIn,
  1945. requestParam = requestParam,
  1946. prizeInUrl = prizeInUrl,
  1947. });
  1948. }
  1949. public static void setLogPrizeAmount(int listId, decimal prizeAmount)
  1950. {
  1951. var logService = App.GetService<IPriLogService>();
  1952. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  1953. if(log != null)
  1954. {
  1955. log.prizeAmount = prizeAmount;
  1956. logService.Update(log);
  1957. }
  1958. }
  1959. public static void setLogStep(int listId, Dictionary<string, object> step)
  1960. {
  1961. var logService = App.GetService<IPriLogService>();
  1962. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  1963. if(log != null)
  1964. {
  1965. log.stepList += Newtonsoft.Json.JsonConvert.SerializeObject(step) + ",";
  1966. logService.Update(log);
  1967. }
  1968. }
  1969. public static void setLogStep(int listId, string key, object val)
  1970. {
  1971. var logService = App.GetService<IPriLogService>();
  1972. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  1973. if(log != null)
  1974. {
  1975. log.stepList += "\"" + key + "\":" + Newtonsoft.Json.JsonConvert.SerializeObject(val) + ",";
  1976. logService.Update(log);
  1977. }
  1978. }
  1979. public static void setLogStatus(int listId, int status)
  1980. {
  1981. var logService = App.GetService<IPriLogService>();
  1982. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  1983. if(log != null)
  1984. {
  1985. log.status = status;
  1986. logService.Update(log);
  1987. }
  1988. }
  1989. public static void setLogFieldValue(int listId, string field, string content)
  1990. {
  1991. var logService = App.GetService<IPriLogService>();
  1992. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  1993. if(log != null)
  1994. {
  1995. if(field == "errLog") log.errLog = content;
  1996. if(field == "prizeOutContent") log.prizeOutContent = content;
  1997. if(field == "prizeOutUrl") log.prizeOutUrl = content;
  1998. if(field == "stepListIndex") log.stepListIndex = content;
  1999. logService.Update(log);
  2000. }
  2001. }
  2002. public static string getQueryKind(string kind)
  2003. {
  2004. if(kind == "1") return "模糊匹配";
  2005. if(kind == "2") return "精确匹配";
  2006. if(kind == "4") return "取反匹配";
  2007. if(kind == "5") return "数组匹配";
  2008. if(kind == "6") return "数组排除";
  2009. if(kind == "3") return "范围匹配";
  2010. return kind;
  2011. }
  2012. public static string getQueryModel(string model)
  2013. {
  2014. if(model == "request_param") return "入参";
  2015. if(model == "query_field") return "条件匹配返回字段";
  2016. if(model == "loop_field") return "循环递归字段";
  2017. if(model == "loop_condition_field") return "循环递归条件字段";
  2018. if(model == "fixed_value") return "固定值";
  2019. if(model == "db_field") return "库内字段";
  2020. return model;
  2021. }
  2022. }
  2023. }