PrizeDo.cs 132 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383
  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, Dictionary<string, string> startData)
  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) && m.startDataFlag == false);
  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. public static DataTable conditionList(int listId, int projectId, List<int> ids, string content, int skip = 0, int size = 1000)
  335. {
  336. List<QueryCondition> dic = new();
  337. var queryTableService = App.GetService<IPriQueryTableService>();
  338. var queryFieldService = App.GetService<IPriQueryFieldService>();
  339. var returnFieldService = App.GetService<IPriReturnFieldService>();
  340. //查询表
  341. var queryTable = queryTableService.GetFirst(m => ids.Contains(m.id) && m.startDataFlag == true);
  342. if (queryTable != null)
  343. {
  344. string groupBy = "";
  345. //查询返回字段
  346. string fields = "";
  347. Dictionary<string, string> fieldDic = new();
  348. var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id);
  349. foreach(var returnField in returnFields)
  350. {
  351. if(returnField.fieldReturnKind == "2")
  352. {
  353. fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  354. }
  355. else if(returnField.fieldReturnKind == "3")
  356. {
  357. fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  358. }
  359. else if(returnField.fieldReturnKind == "4")
  360. {
  361. fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  362. }
  363. else
  364. {
  365. fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  366. }
  367. fieldDic.Add(queryTable.tableEnName + "_" + returnField.fieldEnName, returnField.fieldName);
  368. }
  369. fields = fields.TrimEnd(',');
  370. //查询匹配条件
  371. string condi = "";
  372. var queryFields = queryFieldService.GetList(m => m.queryTableId == queryTable.id);
  373. foreach(var queryField in queryFields)
  374. {
  375. string fieldEnName = queryField.fieldEnName;
  376. string fieldQueryKind = queryField.fieldQueryKind;
  377. string fieldQueryModel = queryField.fieldQueryModel;
  378. string fieldQueryValue = queryField.fieldQueryValue;
  379. string fieldQueryValueType = queryField.fieldQueryValueType;
  380. if(fieldQueryKind == "1") //模糊匹配
  381. {
  382. condi += " and " + fieldEnName + " like ";
  383. if(fieldQueryModel == "request_param")
  384. {
  385. Dictionary<string, string> req = getRequestParams(projectId, content);
  386. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  387. condi += "'%" + val + "%'";
  388. }
  389. else if(fieldQueryModel == "fixed_value")
  390. {
  391. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  392. }
  393. else if(fieldQueryModel == "db_field")
  394. {
  395. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  396. }
  397. else if(fieldQueryModel == "query_field")
  398. {
  399. string val = GetQueryTableData(dic, fieldQueryValue);
  400. condi += "'%" + val + "%'";
  401. }
  402. }
  403. else if(fieldQueryKind == "2") //精确匹配
  404. {
  405. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is null";
  406. else
  407. {
  408. condi += " and " + fieldEnName + "=";
  409. string val = "";
  410. if(fieldQueryModel == "request_param")
  411. {
  412. Dictionary<string, string> req = getRequestParams(projectId, content);
  413. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  414. }
  415. else if(fieldQueryModel == "fixed_value")
  416. {
  417. val = GetExpressionVal(fieldQueryValue);
  418. }
  419. else if(fieldQueryModel == "db_field")
  420. {
  421. val = GetDbExpressionVal(fieldQueryValue);
  422. }
  423. else if(fieldQueryModel == "query_field")
  424. {
  425. val = GetQueryTableData(dic, fieldQueryValue);
  426. }
  427. if(fieldQueryValueType == "text")
  428. {
  429. val = "'" + val + "'";
  430. }
  431. condi += val;
  432. }
  433. }
  434. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  435. {
  436. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  437. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  438. string val = "";
  439. string[] valList = fieldQueryValue.Split(',');
  440. if(fieldQueryModel == "request_param")
  441. {
  442. Dictionary<string, string> req = getRequestParams(projectId, content);
  443. foreach(string sub in valList)
  444. {
  445. if(fieldQueryValueType == "text")
  446. {
  447. val += "'" + req[sub] + "',";
  448. }
  449. else
  450. {
  451. val += req[sub] + ",";
  452. }
  453. }
  454. }
  455. else if(fieldQueryModel == "fixed_value")
  456. {
  457. foreach(string sub in valList)
  458. {
  459. if(fieldQueryValueType == "text")
  460. {
  461. val += "'" + GetExpressionVal(sub) + "',";
  462. }
  463. else
  464. {
  465. val += GetExpressionVal(sub) + ",";
  466. }
  467. }
  468. }
  469. else if(fieldQueryModel == "db_field")
  470. {
  471. foreach(string sub in valList)
  472. {
  473. if(fieldQueryValueType == "text")
  474. {
  475. val += "'" + GetDbExpressionVal(sub) + "',";
  476. }
  477. else
  478. {
  479. val += GetDbExpressionVal(sub) + ",";
  480. }
  481. }
  482. }
  483. else if(fieldQueryModel == "query_field")
  484. {
  485. foreach(string sub in valList)
  486. {
  487. string dicVal = GetQueryTableData(dic, sub);
  488. if(fieldQueryValueType == "text")
  489. {
  490. val += "'" + dicVal + "',";
  491. }
  492. else
  493. {
  494. val += dicVal + ",";
  495. }
  496. }
  497. }
  498. val = val.TrimEnd(',');
  499. condi += val + ")";
  500. }
  501. else if(fieldQueryKind == "3") //范围匹配
  502. {
  503. string[] val = fieldQueryValue.Split(':');
  504. if(fieldQueryModel == "request_param")
  505. {
  506. Dictionary<string, string> req = getRequestParams(projectId, content);
  507. if(fieldQueryValueType == "number")
  508. {
  509. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  510. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  511. }
  512. else
  513. {
  514. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  515. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  516. }
  517. }
  518. else if(fieldQueryModel == "fixed_value")
  519. {
  520. if(fieldQueryValueType == "number")
  521. {
  522. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  523. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  524. }
  525. else
  526. {
  527. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  528. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  529. }
  530. }
  531. else if(fieldQueryModel == "db_field")
  532. {
  533. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + GetDbExpressionVal(val[0]);
  534. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + GetDbExpressionVal(val[1]);
  535. }
  536. else if(fieldQueryModel == "query_field")
  537. {
  538. string valLeft = val[0];
  539. string valRight = val[1];
  540. string dicValLeft = GetQueryTableData(dic, valLeft);
  541. string dicValRight = GetQueryTableData(dic, valRight);
  542. if(fieldQueryValueType == "number")
  543. {
  544. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft;
  545. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight;
  546. }
  547. else
  548. {
  549. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'";
  550. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'";
  551. }
  552. }
  553. }
  554. else if(fieldQueryKind == "4") //取反匹配
  555. {
  556. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is not null";
  557. else
  558. {
  559. condi += " and " + fieldEnName + "!=";
  560. string val = "";
  561. if(fieldQueryModel == "request_param")
  562. {
  563. Dictionary<string, string> req = getRequestParams(projectId, content);
  564. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  565. }
  566. else if(fieldQueryModel == "fixed_value")
  567. {
  568. val = GetExpressionVal(fieldQueryValue);
  569. }
  570. else if(fieldQueryModel == "db_field")
  571. {
  572. val = GetDbExpressionVal(fieldQueryValue);
  573. }
  574. else if(fieldQueryModel == "query_field")
  575. {
  576. val = GetQueryTableData(dic, fieldQueryValue);
  577. }
  578. if(fieldQueryValueType == "text")
  579. {
  580. val = "'" + val + "'";
  581. }
  582. condi += val;
  583. }
  584. }
  585. //拼装聚合字段
  586. if(queryField.groupByFlag) groupBy += queryField.fieldEnName +",";
  587. }
  588. if(!string.IsNullOrEmpty(groupBy)) groupBy = " group by " + groupBy.TrimEnd(',');
  589. var db = initDb(queryTable.databaseId);
  590. string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi + groupBy + " limit " + skip + "," + size;
  591. var items = db.Ado.GetDataTable(sql);
  592. return items;
  593. }
  594. return new DataTable();
  595. }
  596. //奖励发放对象
  597. public static string prizeObject(int listId, int prizeObjectTag, string content)
  598. {
  599. Dictionary<string, object> logStepDic = new();
  600. Dictionary<string, object> dic = new();
  601. var prizeObjectTableService = App.GetService<IPriPrizeObjectTableService>();
  602. var prizeObjectFieldService = App.GetService<IPriPrizeObjectFieldService>();
  603. //查询表
  604. var prizeObjectTable = prizeObjectTableService.GetFirst(m => m.id == prizeObjectTag) ?? new PriPrizeObjectTable();
  605. //查询返回字段
  606. string field = prizeObjectTable.selectField;
  607. int projectId = prizeObjectTable.projectId;
  608. logStepDic.Add("奖励发放对象说明", prizeObjectTable.note);
  609. //查询匹配条件
  610. string condi = "";
  611. List<Dictionary<string, object>> condiDics = new();
  612. var queryFields = prizeObjectFieldService.GetList(m => m.objectTableId == prizeObjectTable.id);
  613. foreach(var queryField in queryFields)
  614. {
  615. string fieldName = queryField.fieldName;
  616. string fieldEnName = queryField.fieldEnName;
  617. string fieldQueryKind = queryField.fieldQueryKind;
  618. string fieldQueryModel = queryField.fieldQueryModel;
  619. string fieldQueryValue = queryField.fieldQueryValue;
  620. string fieldQueryValueType = queryField.fieldQueryValueType;
  621. Dictionary<string, object> condiDic = new();
  622. condiDic.Add("字段名称", fieldName);
  623. condiDic.Add("匹配条件", getQueryKind(fieldQueryKind));
  624. condiDic.Add("匹配方式", getQueryModel(fieldQueryModel));
  625. if(fieldQueryKind == "1") //模糊匹配
  626. {
  627. condi += " and " + fieldEnName + " like ";
  628. if(fieldQueryModel == "request_param")
  629. {
  630. Dictionary<string, string> req = getRequestParams(projectId, content);
  631. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  632. condi += "'%" + val + "%'";
  633. condiDic.Add("匹配值", val);
  634. }
  635. else if(fieldQueryModel == "fixed_value")
  636. {
  637. string val = GetExpressionVal(fieldQueryValue);
  638. condi += "'%" + val + "%'";
  639. condiDic.Add("匹配值", val);
  640. }
  641. else if(fieldQueryModel == "db_field")
  642. {
  643. string val = GetDbExpressionVal(fieldQueryValue);
  644. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  645. condiDic.Add("匹配值", val);
  646. }
  647. }
  648. else if(fieldQueryKind == "2") //精确匹配
  649. {
  650. condi += " and " + fieldEnName + "=";
  651. string val = "";
  652. if(fieldQueryModel == "request_param")
  653. {
  654. Dictionary<string, string> req = getRequestParams(projectId, content);
  655. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  656. }
  657. else if(fieldQueryModel == "fixed_value")
  658. {
  659. val = GetExpressionVal(fieldQueryValue);
  660. }
  661. else if(fieldQueryModel == "db_field")
  662. {
  663. val = GetDbExpressionVal(fieldQueryValue);
  664. }
  665. if(fieldQueryValueType == "text")
  666. {
  667. val = "'" + val + "'";
  668. }
  669. condi += val;
  670. condiDic.Add("匹配值", val);
  671. }
  672. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  673. {
  674. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  675. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  676. string val = "";
  677. string[] valList = fieldQueryValue.Split(',');
  678. if(fieldQueryModel == "request_param")
  679. {
  680. Dictionary<string, string> req = getRequestParams(projectId, content);
  681. foreach(string sub in valList)
  682. {
  683. if(fieldQueryValueType == "text")
  684. {
  685. val += "'" + req[sub] + "',";
  686. }
  687. else
  688. {
  689. val += req[sub] + ",";
  690. }
  691. }
  692. }
  693. else if(fieldQueryModel == "fixed_value")
  694. {
  695. foreach(string sub in valList)
  696. {
  697. if(fieldQueryValueType == "text")
  698. {
  699. val += "'" + GetExpressionVal(sub) + "',";
  700. }
  701. else
  702. {
  703. val += GetExpressionVal(sub) + ",";
  704. }
  705. }
  706. }
  707. else if(fieldQueryModel == "db_field")
  708. {
  709. foreach(string sub in valList)
  710. {
  711. if(fieldQueryValueType == "text")
  712. {
  713. val += "'" + GetDbExpressionVal(sub) + "',";
  714. }
  715. else
  716. {
  717. val += GetDbExpressionVal(sub) + ",";
  718. }
  719. }
  720. }
  721. val = val.TrimEnd(',');
  722. condi += val + ")";
  723. condiDic.Add("匹配值", val);
  724. }
  725. else if(fieldQueryKind == "3") //范围匹配
  726. {
  727. string[] val = fieldQueryValue.Split(':');
  728. if(fieldQueryModel == "request_param")
  729. {
  730. Dictionary<string, string> req = getRequestParams(projectId, content);
  731. if(fieldQueryValueType == "number")
  732. {
  733. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  734. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  735. }
  736. else
  737. {
  738. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  739. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  740. }
  741. }
  742. else if(fieldQueryModel == "fixed_value")
  743. {
  744. if(fieldQueryValueType == "number")
  745. {
  746. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  747. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  748. }
  749. else
  750. {
  751. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  752. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  753. }
  754. }
  755. else if(fieldQueryModel == "db_field")
  756. {
  757. if(fieldQueryValueType == "number")
  758. {
  759. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  760. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  761. }
  762. else
  763. {
  764. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  765. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  766. }
  767. }
  768. condiDic.Add("匹配值", val);
  769. }
  770. else if(fieldQueryKind == "4") //取反匹配
  771. {
  772. condi += " and " + fieldEnName + "!=";
  773. string val = "";
  774. if(fieldQueryModel == "request_param")
  775. {
  776. Dictionary<string, string> req = getRequestParams(projectId, content);
  777. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  778. }
  779. else if(fieldQueryModel == "fixed_value")
  780. {
  781. val = GetExpressionVal(fieldQueryValue);
  782. }
  783. else if(fieldQueryModel == "db_field")
  784. {
  785. val = GetDbExpressionVal(fieldQueryValue);
  786. }
  787. if(fieldQueryValueType == "text")
  788. {
  789. val = "'" + val + "'";
  790. }
  791. condi += val;
  792. condiDic.Add("匹配值", val);
  793. }
  794. condiDics.Add(condiDic);
  795. }
  796. logStepDic.Add("奖励发放对象查询条件", condiDics);
  797. string result = "0";
  798. var db = initDb(prizeObjectTable.databaseId);
  799. var item = db.Ado.GetScalar("select " + field + " from " + prizeObjectTable.tableEnName + " where 1=1" + condi);
  800. if(item != null)
  801. {
  802. result = item.ToString();
  803. }
  804. logStepDic.Add("奖励发放对象", result);
  805. setLogStep(listId, "奖励发放对象", logStepDic);
  806. return result;
  807. }
  808. //奖励发放入口
  809. public static string prizeInSet(string queueName)
  810. {
  811. Dictionary<string, object> dic = new();
  812. var prizeInSetService = App.GetService<IPriPrizeInSetService>();
  813. //查询表
  814. var prizeInSet = prizeInSetService.GetFirst(m => m.mqQueueName == queueName) ?? new PriPrizeInSet();
  815. if(prizeInSet.id > 0)
  816. {
  817. return prizeInSet.prizeListIds + "|" + prizeInSet.projectId + "|" + prizeInSet.id;
  818. }
  819. return "";
  820. }
  821. //奖励列表
  822. public static List<PriList> prizeList(int projectId, string prizeIds)
  823. {
  824. List<int> ids = Tools.SpitIntArrary(prizeIds, ',').ToList();
  825. var priListService = App.GetService<IPriListService>();
  826. var priList = priListService.GetList(m => m.projectId == projectId && ids.Contains(m.id)).ToList();
  827. return priList;
  828. }
  829. //奖励发放
  830. public static void prizeSend(int projectId, int prizeInId, string prizeIds, string content, string queueName)
  831. {
  832. var queryTableService = App.GetService<IPriQueryTableService>();
  833. var priList = prizeList(projectId, prizeIds);
  834. foreach(var sub in priList)
  835. {
  836. try
  837. {
  838. List<int> ids = Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList();
  839. var queryTable = queryTableService.GetFirst(m => ids.Contains(m.id) && m.startDataFlag == true);
  840. if (queryTable != null)
  841. {
  842. int page = 0;
  843. int size = queryTable.stepCount;
  844. if(size == 0) size = 20;
  845. bool op = true;
  846. while(op)
  847. {
  848. int skip = page * size;
  849. DataTable query = conditionList(sub.id, projectId, ids, content, skip, size);
  850. if(query.Rows.Count > 0)
  851. {
  852. foreach(DataRow dr in query.Rows)
  853. {
  854. Dictionary<string, string> startData = new();
  855. foreach(DataColumn dc in query.Columns)
  856. {
  857. startData.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
  858. }
  859. prizeSendSub(sub, projectId, prizeInId, prizeIds, content, queueName, startData);
  860. }
  861. page += 1;
  862. }
  863. else
  864. {
  865. op = false;
  866. }
  867. }
  868. }
  869. else
  870. {
  871. prizeSendSub(sub, projectId, prizeInId, prizeIds, content, queueName, new Dictionary<string, string>());
  872. }
  873. }
  874. catch(Exception ex)
  875. {
  876. setLogFieldValue(sub.id, "errLog", ex.ToString());
  877. }
  878. }
  879. }
  880. //执行每个奖励发放逻辑
  881. public static void prizeSendSub(PriList sub, int projectId, int prizeInId, string prizeIds, string content, string queueName, Dictionary<string, string> startData)
  882. {
  883. var loopSetService = App.GetService<IPriLoopSetService>();
  884. var recursionStartTableService = App.GetService<IPriRecursionStartTableService>();
  885. var recursionStartConditionService = App.GetService<IPriRecursionStartConditionService>();
  886. addLog(projectId, sub.id, prizeInId, content, queueName); //初始化日志
  887. string prizeObjectId = prizeObject(sub.id, sub.prizeObj, content);
  888. var recursionFlag = sub.recursionFlag; //是否递归
  889. setLogStep(sub.id, "是否递归", recursionFlag ? "是" : "否");
  890. if(recursionFlag)
  891. {
  892. List<QueryCondition> queryCondiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content, startData);
  893. setLogStep(sub.id, "查询原始数据", queryCondiDic);
  894. var loopSet = loopSetService.GetFirst(m => m.listId == sub.id) ?? new PriLoopSet();
  895. var recursionStartTable = recursionStartTableService.GetFirst(m => m.listId == sub.id) ?? new PriRecursionStartTable();
  896. var tableEnName = loopSet.tableEnName; //递归查询表
  897. var parentField = loopSet.parentField; //父字段
  898. var sonField = loopSet.sonField; //子字段
  899. var afterPrizeFlag = loopSet.afterPrizeFlag; //发奖后是否继续
  900. var db = initDb(loopSet.databaseId);
  901. string objId = prizeObjectId;
  902. bool op = true;
  903. int index = 0;
  904. loopAmount = 0;
  905. List<Dictionary<string, object>> loopLogDic = new();
  906. while(!string.IsNullOrEmpty(objId) && objId != "0" && op)
  907. {
  908. Dictionary<string, object> loopLog = new();
  909. List<QueryCondition> condiDic = loopCondition(projectId, sub, objId, content);
  910. loopLog.Add("查询" + objId + "匹配数据", condiDic);
  911. if(condiDic.Count > 0)
  912. {
  913. bool prizeFlag = true;
  914. var conditions = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id);
  915. if(conditions.Count > 0)
  916. {
  917. int allCount = conditions.Count; //所有奖励条件数
  918. int passCount = 0; //通过条件数
  919. List<Dictionary<string, object>> logStepDics = new();
  920. foreach(var condition in conditions)
  921. {
  922. if(condition.startIndex <= index)
  923. {
  924. Dictionary<string, object> logStepDic = new();
  925. var returnFieldId = condition.returnFieldId; //条件返回字段
  926. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  927. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  928. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  929. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  930. string checkObj = "";
  931. string checkTitle = "";
  932. if(returnFieldId.Contains(","))
  933. {
  934. string[] returnFieldIdList = returnFieldId.Split(',');
  935. foreach(string subField in returnFieldIdList)
  936. {
  937. string val = GetQueryTableData(condiDic, subField);
  938. checkObj += val + ",";
  939. string title = GetQueryTableTitle(condiDic, subField);
  940. checkTitle += title + ",";
  941. }
  942. checkObj = checkObj.TrimEnd(',');
  943. checkTitle = checkTitle.TrimEnd(',');
  944. }
  945. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  946. {
  947. string expresssion = returnFieldId;
  948. checkTitle = returnFieldId;
  949. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  950. foreach(string returnField in returnFields)
  951. {
  952. string val = GetQueryTableData(condiDic, returnField);
  953. expresssion = expresssion.Replace(returnField, val);
  954. string title = GetQueryTableTitle(condiDic, returnField);
  955. checkTitle = checkTitle.Replace(returnField, title);
  956. }
  957. DataTable dt = new();
  958. checkObj = dt.Compute(expresssion, "false").ToString();
  959. }
  960. else
  961. {
  962. checkObj = GetQueryTableData(condiDic, returnFieldId);
  963. checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
  964. }
  965. logStepDic.Add("标题", checkTitle);
  966. logStepDic.Add("匹配条件", getQueryKind(fieldQueryKind));
  967. logStepDic.Add("匹配方式", getQueryModel(fieldQueryModel));
  968. logStepDic.Add("匹配值", fieldQueryValue);
  969. logStepDic.Add("实际值", checkObj);
  970. var checkVal = fieldQueryValue;
  971. bool passFlag = false;
  972. if(fieldQueryKind == "1") //模糊匹配
  973. {
  974. if(fieldQueryValueType == "text")
  975. {
  976. if(checkObj.ToString().Contains(GetExpressionVal(checkVal)))
  977. {
  978. passCount += 1; passFlag = true;
  979. }
  980. }
  981. }
  982. else if(fieldQueryKind == "2") //精确匹配
  983. {
  984. if(fieldQueryValueType == "int")
  985. {
  986. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal)))
  987. {
  988. passCount += 1; passFlag = true;
  989. }
  990. }
  991. else if(fieldQueryValueType == "number")
  992. {
  993. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal)))
  994. {
  995. passCount += 1; passFlag = true;
  996. }
  997. }
  998. else
  999. {
  1000. if(checkObj.ToString() == GetExpressionVal(checkVal))
  1001. {
  1002. passCount += 1; passFlag = true;
  1003. }
  1004. }
  1005. }
  1006. else if(fieldQueryKind == "3") //范围匹配
  1007. {
  1008. string[] val = checkVal.Split(':');
  1009. string valLeft = val[0];
  1010. string valRight = val[1];
  1011. if(fieldQueryModel == "request_param")
  1012. {
  1013. Dictionary<string, string> req = getRequestParams(projectId, content);
  1014. if(fieldQueryValueType == "number")
  1015. {
  1016. 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])))
  1017. {
  1018. passCount += 1; passFlag = true;
  1019. }
  1020. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])))
  1021. {
  1022. passCount += 1; passFlag = true;
  1023. }
  1024. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight])))
  1025. {
  1026. passCount += 1; passFlag = true;
  1027. }
  1028. }
  1029. else if(fieldQueryValueType == "int")
  1030. {
  1031. 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])))
  1032. {
  1033. passCount += 1; passFlag = true;
  1034. }
  1035. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])))
  1036. {
  1037. passCount += 1; passFlag = true;
  1038. }
  1039. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight])))
  1040. {
  1041. passCount += 1; passFlag = true;
  1042. }
  1043. }
  1044. else if(fieldQueryValueType.StartsWith("date"))
  1045. {
  1046. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1047. {
  1048. passCount += 1; passFlag = true;
  1049. }
  1050. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]))
  1051. {
  1052. passCount += 1; passFlag = true;
  1053. }
  1054. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1055. {
  1056. passCount += 1; passFlag = true;
  1057. }
  1058. }
  1059. }
  1060. else if(fieldQueryModel == "fixed_value")
  1061. {
  1062. string checkValLeft = valLeft.Replace("#{", "").Replace("}#", "");
  1063. string checkValRight = valRight.Replace("#{", "").Replace("}#", "");
  1064. if(checkValLeft.Contains(",")) checkValLeft = checkValLeft.Split(',')[0];
  1065. if(checkValRight.Contains(",")) checkValRight = checkValRight.Split(',')[0];
  1066. valLeft = GetExpressionVal(valLeft);
  1067. valRight = GetExpressionVal(valRight);
  1068. if(fieldQueryValueType == "number")
  1069. {
  1070. 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)))
  1071. {
  1072. passCount += 1; passFlag = true;
  1073. }
  1074. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1075. {
  1076. passCount += 1; passFlag = true;
  1077. }
  1078. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1079. {
  1080. passCount += 1; passFlag = true;
  1081. }
  1082. }
  1083. else if(fieldQueryValueType == "int")
  1084. {
  1085. 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)))
  1086. {
  1087. passCount += 1; passFlag = true;
  1088. }
  1089. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1090. {
  1091. passCount += 1; passFlag = true;
  1092. }
  1093. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1094. {
  1095. passCount += 1; passFlag = true;
  1096. }
  1097. }
  1098. else if(fieldQueryValueType.StartsWith("date"))
  1099. {
  1100. if(valLeft == "0") valLeft = "";
  1101. if(valRight == "0") valRight = "";
  1102. if(checkObj != "0" && checkObj != "")
  1103. {
  1104. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  1105. {
  1106. passCount += 1; passFlag = true;
  1107. }
  1108. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1109. {
  1110. passCount += 1; passFlag = true;
  1111. }
  1112. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  1113. {
  1114. passCount += 1; passFlag = true;
  1115. }
  1116. }
  1117. }
  1118. }
  1119. else if(fieldQueryModel == "query_field")
  1120. {
  1121. valLeft = GetComputeVal(queryCondiDic, valLeft);
  1122. valRight = GetComputeVal(queryCondiDic, valRight);
  1123. if(fieldQueryValueType == "number")
  1124. {
  1125. 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)))
  1126. {
  1127. passCount += 1; passFlag = true;
  1128. }
  1129. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1130. {
  1131. passCount += 1; passFlag = true;
  1132. }
  1133. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1134. {
  1135. passCount += 1; passFlag = true;
  1136. }
  1137. }
  1138. else if(fieldQueryValueType == "int")
  1139. {
  1140. 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)))
  1141. {
  1142. passCount += 1; passFlag = true;
  1143. }
  1144. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1145. {
  1146. passCount += 1; passFlag = true;
  1147. }
  1148. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1149. {
  1150. passCount += 1; passFlag = true;
  1151. }
  1152. }
  1153. else if(fieldQueryValueType.StartsWith("date"))
  1154. {
  1155. if(valLeft == "0") valLeft = "";
  1156. if(valRight == "0") valRight = "";
  1157. if(checkObj != "0" && checkObj != "")
  1158. {
  1159. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  1160. {
  1161. passCount += 1; passFlag = true;
  1162. }
  1163. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1164. {
  1165. passCount += 1; passFlag = true;
  1166. }
  1167. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  1168. {
  1169. passCount += 1; passFlag = true;
  1170. }
  1171. }
  1172. }
  1173. }
  1174. }
  1175. else if(fieldQueryKind == "4") //取反匹配
  1176. {
  1177. if(fieldQueryValueType == "int")
  1178. {
  1179. if(int.Parse(checkObj) != int.Parse(Function.CheckInt(checkVal)))
  1180. {
  1181. passCount += 1; passFlag = true;
  1182. }
  1183. }
  1184. else if(fieldQueryValueType == "number")
  1185. {
  1186. if(decimal.Parse(checkObj) != decimal.Parse(Function.CheckNum(checkVal)))
  1187. {
  1188. passCount += 1; passFlag = true;
  1189. }
  1190. }
  1191. else if(fieldQueryValueType == "text")
  1192. {
  1193. if(checkObj.ToString() != GetExpressionVal(checkVal))
  1194. {
  1195. passCount += 1; passFlag = true;
  1196. }
  1197. }
  1198. }
  1199. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1200. {
  1201. string val = ",";
  1202. string[] valList = checkVal.Split(',');
  1203. if(fieldQueryModel == "request_param")
  1204. {
  1205. Dictionary<string, string> req = getRequestParams(projectId, content);
  1206. foreach(string subVal in valList)
  1207. {
  1208. val += req[subVal] + ",";
  1209. }
  1210. }
  1211. else if(fieldQueryModel == "fixed_value")
  1212. {
  1213. foreach(string subVal in valList)
  1214. {
  1215. val += GetExpressionVal(subVal) + ",";
  1216. }
  1217. }
  1218. else if(fieldQueryModel == "db_field")
  1219. {
  1220. foreach(string subVal in valList)
  1221. {
  1222. val += GetDbExpressionVal(subVal) + ",";
  1223. }
  1224. }
  1225. if(fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ","))
  1226. {
  1227. passCount += 1; passFlag = true;
  1228. }
  1229. if(fieldQueryKind == "6" && !val.Contains("," + checkObj.ToString() + ","))
  1230. {
  1231. passCount += 1; passFlag = true;
  1232. }
  1233. }
  1234. logStepDic.Add("状态", passFlag ? "通过" : "未通过");
  1235. logStepDics.Add(logStepDic);
  1236. }
  1237. }
  1238. loopLog.Add(objId + "匹配情况", logStepDics);
  1239. if(loopSet.conditionMode == "all" && passCount == allCount) prizeFlag = true;
  1240. else if(loopSet.conditionMode == "one" && passCount >= 1) prizeFlag = true;
  1241. else if(loopSet.conditionMode == "two" && passCount >= 2) prizeFlag = true;
  1242. else if(loopSet.conditionMode == "three" && passCount >= 3) prizeFlag = true;
  1243. else prizeFlag = false;
  1244. }
  1245. else
  1246. {
  1247. prizeFlag = false;
  1248. }
  1249. loopLog.Add("匹配结果", prizeFlag);
  1250. if(prizeFlag)
  1251. {
  1252. decimal prizeAmt = prizeSendDo(projectId, sub, objId, content, loopSet, startData);
  1253. op = afterPrizeFlag;
  1254. }
  1255. }
  1256. loopLogDic.Add(loopLog);
  1257. var parent = db.Ado.GetScalar("select " + parentField + " from " + tableEnName + " where " + sonField + "=" + objId);
  1258. if(parent != null)
  1259. {
  1260. objId = parent.ToString();
  1261. }
  1262. else
  1263. {
  1264. objId = "0";
  1265. }
  1266. index += 1;
  1267. }
  1268. setLogStep(sub.id, "向上递归流程", loopLogDic);
  1269. }
  1270. else
  1271. {
  1272. prizeSendDo(projectId, sub, prizeObjectId, content, new PriLoopSet(), startData);
  1273. }
  1274. }
  1275. static decimal loopAmount = 0;
  1276. public static decimal prizeSendDo(int projectId, PriList sub, string prizeObjectId, string content, PriLoopSet set, Dictionary<string, string> startData)
  1277. {
  1278. var projectService = App.GetService<IPriProjectService>();
  1279. var recordService = App.GetService<IPriRecordService>();
  1280. var conditionService = App.GetService<IPriConditionService>();
  1281. var returnFieldService = App.GetService<IPriReturnFieldService>();
  1282. // var queryTableService = App.GetService<IPriQueryTableService>();
  1283. var amountSetService = App.GetService<IPriListAmountSetService>();
  1284. var project = projectService.GetFirst(m => m.id == projectId) ?? new PriProject();
  1285. //查询匹配条件
  1286. List<QueryCondition> condiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content, startData);
  1287. if(sub.prizeSourceFieldType == "loop") MergeCondiDic(condiDic, loopCondition(projectId, sub, prizeObjectId, content));
  1288. setLogStep(sub.id, "发放奖励查询来源数据", condiDic);
  1289. var prizeSourceField = sub.prizeSourceField; //奖励金额来源字段(对应条件匹配返回字段)
  1290. var prizePercent = sub.prizePercent; //奖励比例
  1291. var prizeAmount = sub.prizeAmount; //奖励固定值
  1292. var prizeContent = sub.prizeContent; //奖励内容
  1293. var conditionMode = sub.conditionMode; //条件模式
  1294. var recursionFlag = sub.recursionFlag; //是否递归
  1295. var conditions = conditionService.GetList(m => m.listId == sub.id);
  1296. setLogStep(sub.id, "发放奖励匹配条件", condiDic);
  1297. int allCount = conditions.Count; //所有奖励条件数
  1298. int passCount = 0; //通过条件数
  1299. List<Dictionary<string, object>> logStepDics = new();
  1300. foreach(var condition in conditions)
  1301. {
  1302. Dictionary<string, object> logStepDic = new();
  1303. var returnFieldId = condition.returnFieldId; //条件返回字段
  1304. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  1305. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  1306. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  1307. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  1308. string checkObj = "";
  1309. string checkTitle = "";
  1310. if(returnFieldId.Contains(","))
  1311. {
  1312. string[] returnFieldIdList = returnFieldId.Split(',');
  1313. foreach(string subField in returnFieldIdList)
  1314. {
  1315. string val = GetQueryTableData(condiDic, subField);
  1316. checkObj += val + ",";
  1317. string title = GetQueryTableTitle(condiDic, subField);
  1318. checkTitle += title + ",";
  1319. }
  1320. checkObj = checkObj.TrimEnd(',');
  1321. checkTitle = checkTitle.TrimEnd(',');
  1322. }
  1323. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  1324. {
  1325. string expresssion = returnFieldId;
  1326. checkTitle = returnFieldId;
  1327. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  1328. foreach(string returnField in returnFields)
  1329. {
  1330. string val = GetQueryTableData(condiDic, returnField);
  1331. expresssion = expresssion.Replace(returnField, val);
  1332. string title = GetQueryTableTitle(condiDic, returnField);
  1333. checkTitle = checkTitle.Replace(returnField, title);
  1334. }
  1335. DataTable dt = new();
  1336. checkObj = dt.Compute(expresssion, "false").ToString();
  1337. }
  1338. else
  1339. {
  1340. checkObj = GetQueryTableData(condiDic, returnFieldId);
  1341. checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
  1342. }
  1343. if(!sub.recursionFlag)
  1344. {
  1345. logStepDic.Add("标题", checkTitle);
  1346. logStepDic.Add("匹配条件", getQueryKind(fieldQueryKind));
  1347. logStepDic.Add("匹配方式", getQueryModel(fieldQueryModel));
  1348. logStepDic.Add("匹配值", fieldQueryValue);
  1349. logStepDic.Add("实际值", checkObj);
  1350. }
  1351. string checkVal = fieldQueryValue;
  1352. bool passFlag = false;
  1353. if(fieldQueryKind == "1") //模糊匹配
  1354. {
  1355. if(fieldQueryValueType == "text")
  1356. {
  1357. if(checkObj.ToString().Contains(GetExpressionVal(checkVal)))
  1358. {
  1359. passCount += 1; passFlag = true;
  1360. }
  1361. }
  1362. }
  1363. else if(fieldQueryKind == "2") //精确匹配
  1364. {
  1365. if(fieldQueryValueType == "int")
  1366. {
  1367. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal)))
  1368. {
  1369. passCount += 1; passFlag = true;
  1370. }
  1371. }
  1372. else if(fieldQueryValueType == "number")
  1373. {
  1374. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal)))
  1375. {
  1376. passCount += 1; passFlag = true;
  1377. }
  1378. }
  1379. else
  1380. {
  1381. if(checkObj.ToString() == GetExpressionVal(checkVal))
  1382. {
  1383. passCount += 1; passFlag = true;
  1384. }
  1385. }
  1386. }
  1387. else if(fieldQueryKind == "3") //范围匹配
  1388. {
  1389. string[] val = checkVal.Split(':');
  1390. string valLeft = val[0];
  1391. string valRight = val[1];
  1392. if(fieldQueryModel == "request_param")
  1393. {
  1394. Dictionary<string, string> req = getRequestParams(projectId, content);
  1395. if(fieldQueryValueType == "number")
  1396. {
  1397. 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])))
  1398. {
  1399. passCount += 1; passFlag = true;
  1400. }
  1401. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])))
  1402. {
  1403. passCount += 1; passFlag = true;
  1404. }
  1405. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight])))
  1406. {
  1407. passCount += 1; passFlag = true;
  1408. }
  1409. }
  1410. else if(fieldQueryValueType == "int")
  1411. {
  1412. 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])))
  1413. {
  1414. passCount += 1; passFlag = true;
  1415. }
  1416. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])))
  1417. {
  1418. passCount += 1; passFlag = true;
  1419. }
  1420. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight])))
  1421. {
  1422. passCount += 1; passFlag = true;
  1423. }
  1424. }
  1425. else if(fieldQueryValueType.StartsWith("date"))
  1426. {
  1427. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1428. {
  1429. passCount += 1; passFlag = true;
  1430. }
  1431. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]))
  1432. {
  1433. passCount += 1; passFlag = true;
  1434. }
  1435. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1436. {
  1437. passCount += 1; passFlag = true;
  1438. }
  1439. }
  1440. }
  1441. else if(fieldQueryModel == "fixed_value")
  1442. {
  1443. valLeft = GetExpressionVal(valLeft);
  1444. valRight = GetExpressionVal(valRight);
  1445. if(fieldQueryValueType == "number")
  1446. {
  1447. 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)))
  1448. {
  1449. passCount += 1; passFlag = true;
  1450. }
  1451. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1452. {
  1453. passCount += 1; passFlag = true;
  1454. }
  1455. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1456. {
  1457. passCount += 1; passFlag = true;
  1458. }
  1459. }
  1460. else if(fieldQueryValueType == "int")
  1461. {
  1462. 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)))
  1463. {
  1464. passCount += 1; passFlag = true;
  1465. }
  1466. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1467. {
  1468. passCount += 1; passFlag = true;
  1469. }
  1470. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1471. {
  1472. passCount += 1; passFlag = true;
  1473. }
  1474. }
  1475. else if(fieldQueryValueType.StartsWith("date"))
  1476. {
  1477. if(valLeft == "0") valLeft = "";
  1478. if(valRight == "0") valRight = "";
  1479. if(checkObj != "0" && checkObj != "")
  1480. {
  1481. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1482. {
  1483. passCount += 1; passFlag = true;
  1484. }
  1485. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1486. {
  1487. passCount += 1; passFlag = true;
  1488. }
  1489. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1490. {
  1491. passCount += 1; passFlag = true;
  1492. }
  1493. }
  1494. }
  1495. }
  1496. else if(fieldQueryModel == "query_field")
  1497. {
  1498. string checkValLeft = valLeft.Replace("#{", "").Replace("}#", "");
  1499. string checkValRight = valRight.Replace("#{", "").Replace("}#", "");
  1500. if(checkValLeft.Contains(",")) checkValLeft = checkValLeft.Split(',')[0];
  1501. if(checkValRight.Contains(",")) checkValRight = checkValRight.Split(',')[0];
  1502. if(!string.IsNullOrEmpty(valLeft)) valLeft = valLeft.Replace(checkValLeft, GetQueryTableData(condiDic, checkValLeft));
  1503. if(!string.IsNullOrEmpty(valRight)) valRight = valRight.Replace(checkValRight, GetQueryTableData(condiDic, checkValRight));
  1504. valLeft = GetExpressionVal(valLeft);
  1505. valRight = GetExpressionVal(valRight);
  1506. if(fieldQueryValueType == "number")
  1507. {
  1508. 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)))
  1509. {
  1510. passCount += 1; passFlag = true;
  1511. }
  1512. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1513. {
  1514. passCount += 1; passFlag = true;
  1515. }
  1516. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1517. {
  1518. passCount += 1; passFlag = true;
  1519. }
  1520. }
  1521. else if(fieldQueryValueType == "int")
  1522. {
  1523. 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)))
  1524. {
  1525. passCount += 1; passFlag = true;
  1526. }
  1527. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1528. {
  1529. passCount += 1; passFlag = true;
  1530. }
  1531. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1532. {
  1533. passCount += 1; passFlag = true;
  1534. }
  1535. }
  1536. else if(fieldQueryValueType.StartsWith("date"))
  1537. {
  1538. if(valLeft == "0") valLeft = "";
  1539. if(valRight == "0") valRight = "";
  1540. if(checkObj != "0" && checkObj != "")
  1541. {
  1542. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1543. {
  1544. passCount += 1; passFlag = true;
  1545. }
  1546. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1547. {
  1548. passCount += 1; passFlag = true;
  1549. }
  1550. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1551. {
  1552. passCount += 1; passFlag = true;
  1553. }
  1554. }
  1555. }
  1556. }
  1557. }
  1558. else if(fieldQueryKind == "4") //取反匹配
  1559. {
  1560. if(fieldQueryValueType == "int")
  1561. {
  1562. if(int.Parse(Function.CheckNum(checkObj.ToString())) != int.Parse(Function.CheckInt(checkVal)))
  1563. {
  1564. passCount += 1; passFlag = true;
  1565. }
  1566. }
  1567. else if(fieldQueryValueType == "number")
  1568. {
  1569. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) != decimal.Parse(Function.CheckNum(checkVal)))
  1570. {
  1571. passCount += 1; passFlag = true;
  1572. }
  1573. }
  1574. else if(fieldQueryValueType == "text")
  1575. {
  1576. if(checkObj.ToString() != GetExpressionVal(checkVal))
  1577. {
  1578. passCount += 1; passFlag = true;
  1579. }
  1580. }
  1581. }
  1582. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1583. {
  1584. string val = ",";
  1585. string[] valList = checkVal.Split(',');
  1586. if(fieldQueryModel == "request_param")
  1587. {
  1588. Dictionary<string, string> req = getRequestParams(projectId, content);
  1589. foreach(string subVal in valList)
  1590. {
  1591. val += req[subVal] + ",";
  1592. }
  1593. }
  1594. else if(fieldQueryModel == "fixed_value")
  1595. {
  1596. foreach(string subVal in valList)
  1597. {
  1598. val += GetExpressionVal(subVal) + ",";
  1599. }
  1600. }
  1601. else if(fieldQueryModel == "db_field")
  1602. {
  1603. foreach(string subVal in valList)
  1604. {
  1605. val += GetDbExpressionVal(subVal) + ",";
  1606. }
  1607. }
  1608. if (fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ","))
  1609. {
  1610. passCount += 1; passFlag = true;
  1611. }
  1612. if(fieldQueryKind == "6" && !val.Contains("," + checkObj.ToString() + ","))
  1613. {
  1614. passCount += 1; passFlag = true;
  1615. }
  1616. }
  1617. if(!sub.recursionFlag)
  1618. {
  1619. logStepDic.Add("状态", passFlag ? "通过" : "未通过");
  1620. logStepDics.Add(logStepDic);
  1621. }
  1622. }
  1623. setLogStep(sub.id, "匹配结果", logStepDics);
  1624. bool op = false;
  1625. decimal prizeAmt = 0;
  1626. if(conditionMode == "all" && passCount == allCount && passCount > 0) op = true;
  1627. else if(conditionMode == "one" && passCount >= 1) op = true;
  1628. else if(conditionMode == "two" && passCount >= 2) op = true;
  1629. else if(conditionMode == "three" && passCount >= 3) op = true;
  1630. setLogStep(sub.id, "是否通过", op ? "是" : "否");
  1631. if(op) //满足条件
  1632. {
  1633. decimal number = 0;
  1634. if(prizeSourceField.Contains("/"))
  1635. {
  1636. number = decimal.Parse(prizeSourceField.Split('/')[1]);
  1637. prizeSourceField = prizeSourceField.Split('/')[0];
  1638. }
  1639. string prizeSourceData = "";
  1640. if(prizeSourceField.Contains(","))
  1641. {
  1642. string[] prizeSourceFieldList = prizeSourceField.Split(',');
  1643. foreach(string subField in prizeSourceFieldList)
  1644. {
  1645. string val = GetQueryTableData(condiDic, subField);
  1646. prizeSourceData += val + ",";
  1647. }
  1648. prizeSourceData = prizeSourceData.TrimEnd(',');
  1649. }
  1650. else
  1651. {
  1652. prizeSourceData = GetQueryTableData(condiDic, prizeSourceField);
  1653. }
  1654. if(string.IsNullOrEmpty(prizeSourceData)) prizeSourceData = "0";
  1655. if(prizeSourceField.Contains("/") && number > 0)
  1656. {
  1657. decimal prizeSourceDataNum = decimal.Parse(prizeSourceData) / number;
  1658. prizeSourceData = prizeSourceDataNum.ToString("f2");
  1659. }
  1660. var amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField == prizeSourceData);
  1661. if(amountSet != null)
  1662. {
  1663. prizePercent = amountSet.prizePercent;
  1664. prizeAmount = amountSet.prizeAmount;
  1665. }
  1666. if(prizeSourceData.Contains(","))
  1667. {
  1668. string checkField = prizeSourceData.Split(',')[0] + ",";
  1669. amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField.StartsWith(checkField) && m.prizeSourceField.EndsWith(",%"));
  1670. if(amountSet != null)
  1671. {
  1672. prizePercent = amountSet.prizePercent;
  1673. prizeAmount = amountSet.prizeAmount;
  1674. prizeSourceData = prizeSourceData.Split(',')[1];
  1675. }
  1676. }
  1677. if(prizePercent > 0) prizeAmt += decimal.Parse(Function.CheckNum(prizeSourceData)) * prizePercent;
  1678. if(prizeAmount > 0) prizeAmt += prizeAmount;
  1679. decimal getPrizeAmount = prizeAmt;
  1680. if(set.levelDiffFlag) prizeAmt -= loopAmount;
  1681. setLogStep(sub.id, "发放金额", prizeAmt);
  1682. if(prizeAmt > 0)
  1683. {
  1684. setLogPrizeAmount(sub.id, prizeAmt);
  1685. var req = getRequestParams(projectId, content);
  1686. var requestParamField = req[sub.requestParamField];
  1687. var sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == requestParamField);
  1688. if(!sendFlag)
  1689. {
  1690. PriRecord item = new PriRecord()
  1691. {
  1692. createDate = DateTime.Now,
  1693. projectId = projectId,
  1694. listId = sub.id,
  1695. prizeAmount = prizeAmt,
  1696. prizeObjId = prizeObjectId,
  1697. requestParamField = content,
  1698. batchNo = batchNo,
  1699. };
  1700. recordService.Add(item);
  1701. string prizeOutContent = Newtonsoft.Json.JsonConvert.SerializeObject(item);
  1702. setLogFieldValue(sub.id, "prizeOutContent", prizeOutContent);
  1703. setLogFieldValue(sub.id, "prizeOutUrl", project.noticeUrl);
  1704. loopAmount = getPrizeAmount;
  1705. if(project.requestMode == "http" && !string.IsNullOrEmpty(project.noticeUrl))
  1706. {
  1707. Function.PostWebRequest(project.noticeUrl, prizeOutContent, "application/json");
  1708. }
  1709. else if(project.requestMode == "mq")
  1710. {}
  1711. else
  1712. {
  1713. prizeToDatabase(projectId, sub.id, content, condiDic, prizeAmt); //入库
  1714. }
  1715. }
  1716. }
  1717. }
  1718. // if(!sub.recursionFlag)
  1719. // {
  1720. setLogStatus(sub.id, op ? 1 : 0);
  1721. // }
  1722. return prizeAmt;
  1723. }
  1724. //递归条件判断
  1725. public static List<QueryCondition> loopCondition(int projectId, PriList sub, string objId, string content)
  1726. {
  1727. List<QueryCondition> dic = new();
  1728. var queryTableService = App.GetService<IPriRecursionStartTableService>();
  1729. var queryFieldService = App.GetService<IPriRecursionStartFieldService>();
  1730. var queryReturnFieldService = App.GetService<IPriRecursionStartReturnFieldService>();
  1731. int passCount = 0;
  1732. //查询表
  1733. var queryTables = queryTableService.GetList(m => m.listId == sub.id);
  1734. int allCount = queryTables.Count;
  1735. foreach(var queryTable in queryTables)
  1736. {
  1737. //查询返回字段
  1738. string fields = "1";
  1739. Dictionary<string, string> fieldDic = new();
  1740. var returnFields = queryReturnFieldService.GetList(m => m.objectTableId == queryTable.id);
  1741. if(returnFields.Count > 0)
  1742. {
  1743. fields = "";
  1744. foreach(var returnField in returnFields)
  1745. {
  1746. if(returnField.fieldReturnKind == "2")
  1747. {
  1748. fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1749. }
  1750. else if(returnField.fieldReturnKind == "3")
  1751. {
  1752. fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1753. }
  1754. else if(returnField.fieldReturnKind == "4")
  1755. {
  1756. fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1757. }
  1758. else
  1759. {
  1760. fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1761. }
  1762. fieldDic.Add(queryTable.tableEnName + "_" + returnField.fieldEnName, returnField.fieldName);
  1763. }
  1764. fields = fields.TrimEnd(',');
  1765. }
  1766. //查询匹配条件
  1767. string condi = "";
  1768. var queryFields = queryFieldService.GetList(m => m.objectTableId == queryTable.id);
  1769. foreach(var queryField in queryFields)
  1770. {
  1771. string fieldEnName = queryField.fieldEnName;
  1772. string fieldQueryKind = queryField.fieldQueryKind;
  1773. string fieldQueryModel = queryField.fieldQueryModel;
  1774. string fieldQueryValue = queryField.fieldQueryValue;
  1775. if(fieldQueryModel == "loop_field") fieldQueryValue = objId;
  1776. string fieldQueryValueType = queryField.fieldQueryValueType;
  1777. if(fieldQueryKind == "1") //模糊匹配
  1778. {
  1779. condi += " and " + fieldEnName + " like ";
  1780. if(fieldQueryModel == "request_param")
  1781. {
  1782. Dictionary<string, string> req = getRequestParams(projectId, content);
  1783. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1784. condi += "'%" + val + "%'";
  1785. }
  1786. else if(fieldQueryModel == "fixed_value")
  1787. {
  1788. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  1789. }
  1790. else if(fieldQueryModel == "db_field")
  1791. {
  1792. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  1793. }
  1794. }
  1795. else if(fieldQueryKind == "2") //精确匹配
  1796. {
  1797. condi += " and " + fieldEnName + "=";
  1798. string val = fieldQueryValue;
  1799. if(fieldQueryModel == "request_param")
  1800. {
  1801. Dictionary<string, string> req = getRequestParams(projectId, content);
  1802. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1803. }
  1804. else if(fieldQueryModel == "fixed_value")
  1805. {
  1806. val = GetExpressionVal(fieldQueryValue);
  1807. }
  1808. else if(fieldQueryModel == "db_field")
  1809. {
  1810. val = GetDbExpressionVal(fieldQueryValue);
  1811. }
  1812. if(fieldQueryValueType == "text")
  1813. {
  1814. val = "'" + val + "'";
  1815. }
  1816. condi += val;
  1817. }
  1818. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1819. {
  1820. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  1821. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  1822. string val = "";
  1823. string[] valList = fieldQueryValue.Split(',');
  1824. if(fieldQueryModel == "request_param")
  1825. {
  1826. Dictionary<string, string> req = getRequestParams(projectId, content);
  1827. foreach(string subval in valList)
  1828. {
  1829. if(fieldQueryValueType == "text")
  1830. {
  1831. val += "'" + req[subval] + "',";
  1832. }
  1833. else
  1834. {
  1835. val += req[subval] + ",";
  1836. }
  1837. }
  1838. }
  1839. else if(fieldQueryModel == "fixed_value")
  1840. {
  1841. foreach(string subval in valList)
  1842. {
  1843. if(fieldQueryValueType == "text")
  1844. {
  1845. val += "'" + GetExpressionVal(subval) + "',";
  1846. }
  1847. else
  1848. {
  1849. val += GetExpressionVal(subval) + ",";
  1850. }
  1851. }
  1852. }
  1853. else if(fieldQueryModel == "db_field")
  1854. {
  1855. foreach(string subval in valList)
  1856. {
  1857. if(fieldQueryValueType == "text")
  1858. {
  1859. val += "'" + GetDbExpressionVal(subval) + "',";
  1860. }
  1861. else
  1862. {
  1863. val += GetDbExpressionVal(subval) + ",";
  1864. }
  1865. }
  1866. }
  1867. val = val.TrimEnd(',');
  1868. condi += val + ")";
  1869. }
  1870. else if(fieldQueryKind == "3") //范围匹配
  1871. {
  1872. string[] val = fieldQueryValue.Split(':');
  1873. if(fieldQueryModel == "request_param")
  1874. {
  1875. Dictionary<string, string> req = getRequestParams(projectId, content);
  1876. if(fieldQueryValueType == "number")
  1877. {
  1878. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  1879. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  1880. }
  1881. else
  1882. {
  1883. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  1884. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  1885. }
  1886. }
  1887. else if(fieldQueryModel == "fixed_value")
  1888. {
  1889. if(fieldQueryValueType == "number")
  1890. {
  1891. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1892. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1893. }
  1894. else
  1895. {
  1896. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  1897. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  1898. }
  1899. }
  1900. else if(fieldQueryModel == "db_field")
  1901. {
  1902. if(fieldQueryValueType == "number")
  1903. {
  1904. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1905. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1906. }
  1907. else
  1908. {
  1909. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  1910. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  1911. }
  1912. }
  1913. }
  1914. else if(fieldQueryKind == "4") //取反匹配
  1915. {
  1916. condi += " and " + fieldEnName + "!=";
  1917. string val = "";
  1918. if(fieldQueryModel == "request_param")
  1919. {
  1920. Dictionary<string, string> req = getRequestParams(projectId, content);
  1921. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1922. }
  1923. else if(fieldQueryModel == "fixed_value")
  1924. {
  1925. val = GetExpressionVal(fieldQueryValue);
  1926. }
  1927. else if(fieldQueryModel == "db_field")
  1928. {
  1929. val = GetDbExpressionVal(fieldQueryValue);
  1930. }
  1931. if(fieldQueryValueType == "text")
  1932. {
  1933. val = "'" + val + "'";
  1934. }
  1935. condi += val;
  1936. }
  1937. }
  1938. var db = initDb(queryTable.databaseId);
  1939. string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
  1940. var items = db.Ado.GetDataTable(sql);
  1941. if(items.Rows.Count > 0)
  1942. {
  1943. foreach(string field in fieldDic.Keys)
  1944. {
  1945. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  1946. {
  1947. FieldName = fieldDic[field],
  1948. FieldEnName = field,
  1949. Value = items.Rows[0][field].ToString()
  1950. });
  1951. }
  1952. }
  1953. }
  1954. return dic;
  1955. }
  1956. //奖励入库
  1957. public static void prizeToDatabase(int projectId, int listId, string content, List<QueryCondition> condiDic, decimal prize_amt)
  1958. {
  1959. var prizeInTableService = App.GetService<IPriPrizeInTableService>();
  1960. var prizeInFieldService = App.GetService<IPriPrizeInFieldService>();
  1961. var prizeInQueryFieldService = App.GetService<IPriPrizeInQueryFieldService>();
  1962. //入库表
  1963. var prizeInTables = prizeInTableService.GetList(m => m.listId == listId);
  1964. foreach(var prizeInTable in prizeInTables)
  1965. {
  1966. var db = initDb(prizeInTable.databaseId);
  1967. Dictionary<string, object> doFields = new();
  1968. //入库字段
  1969. var prizeInFields = prizeInFieldService.GetList(m => m.inTableId == prizeInTable.id);
  1970. foreach(var prizeInField in prizeInFields)
  1971. {
  1972. string fieldEnName = prizeInField.fieldEnName;
  1973. string fieldQueryModel = prizeInField.fieldQueryModel;
  1974. string fieldQueryValue = prizeInField.fieldQueryValue;
  1975. string fieldQueryValueType = prizeInField.fieldQueryValueType;
  1976. if(fieldQueryModel == "request_param")
  1977. {
  1978. Dictionary<string, string> req = getRequestParams(projectId, content);
  1979. fieldQueryValue = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1980. }
  1981. else if(fieldQueryModel == "query_field")
  1982. {
  1983. fieldQueryValue = GetQueryTableData(condiDic, fieldQueryValue);
  1984. }
  1985. else if(fieldQueryModel == "fixed_value")
  1986. {
  1987. fieldQueryValue = GetExpressionVal(fieldQueryValue);
  1988. }
  1989. else if(fieldQueryModel == "db_field")
  1990. {
  1991. fieldQueryValue = GetDbExpressionVal(fieldQueryValue);
  1992. }
  1993. else if(fieldQueryModel == "prize_amt")
  1994. {
  1995. fieldQueryValue = prize_amt.ToString();
  1996. }
  1997. if(fieldQueryValueType == "text") doFields.Add(fieldEnName, fieldQueryValue);
  1998. if(fieldQueryValueType == "int") doFields.Add(fieldEnName, int.Parse(fieldQueryValue));
  1999. if(fieldQueryValueType == "number") doFields.Add(fieldEnName, decimal.Parse(fieldQueryValue));
  2000. if(fieldQueryValueType == "datetime") doFields.Add(fieldEnName, DateTime.Parse(fieldQueryValue));
  2001. if(fieldQueryValueType == "bool") doFields.Add(fieldEnName, bool.Parse(fieldQueryValue));
  2002. }
  2003. //查询匹配条件
  2004. string condi = "";
  2005. var queryFields = prizeInQueryFieldService.GetList(m => m.inTableId == prizeInTable.id);
  2006. foreach(var queryField in queryFields)
  2007. {
  2008. string fieldEnName = queryField.fieldEnName;
  2009. string fieldQueryKind = queryField.fieldQueryKind;
  2010. string fieldQueryModel = queryField.fieldQueryModel;
  2011. string fieldQueryValue = queryField.fieldQueryValue;
  2012. string fieldQueryValueType = queryField.fieldQueryValueType;
  2013. if(fieldQueryKind == "1") //模糊匹配
  2014. {
  2015. condi += " and " + fieldEnName + " like ";
  2016. if(fieldQueryModel == "request_param")
  2017. {
  2018. Dictionary<string, string> req = getRequestParams(projectId, content);
  2019. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2020. condi += "'%" + val + "%'";
  2021. }
  2022. else if(fieldQueryModel == "fixed_value")
  2023. {
  2024. condi += "'%" + fieldQueryValue + "%'";
  2025. }
  2026. else if(fieldQueryModel == "query_field")
  2027. {
  2028. condi += "'%" + GetQueryTableData(condiDic, fieldQueryValue) + "%'";
  2029. }
  2030. }
  2031. else if(fieldQueryKind == "2") //精确匹配
  2032. {
  2033. condi += " and " + fieldEnName + "=";
  2034. string val = "";
  2035. if(fieldQueryModel == "request_param")
  2036. {
  2037. Dictionary<string, string> req = getRequestParams(projectId, content);
  2038. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2039. }
  2040. else if(fieldQueryModel == "fixed_value")
  2041. {
  2042. val = fieldQueryValue;
  2043. }
  2044. else if(fieldQueryModel == "query_field")
  2045. {
  2046. val = GetQueryTableData(condiDic, fieldQueryValue);
  2047. }
  2048. if(fieldQueryValueType == "text")
  2049. {
  2050. val = "'" + val + "'";
  2051. }
  2052. condi += val;
  2053. }
  2054. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  2055. {
  2056. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  2057. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  2058. string val = "";
  2059. string[] valList = fieldQueryValue.Split(',');
  2060. if(fieldQueryModel == "request_param")
  2061. {
  2062. Dictionary<string, string> req = getRequestParams(projectId, content);
  2063. foreach(string sub in valList)
  2064. {
  2065. if(fieldQueryValueType == "text")
  2066. {
  2067. val += "'" + req[sub] + "',";
  2068. }
  2069. else
  2070. {
  2071. val += req[sub] + ",";
  2072. }
  2073. }
  2074. }
  2075. else if(fieldQueryModel == "fixed_value")
  2076. {
  2077. foreach(string sub in valList)
  2078. {
  2079. if(fieldQueryValueType == "text")
  2080. {
  2081. val += "'" + GetExpressionVal(sub) + "',";
  2082. }
  2083. else
  2084. {
  2085. val += GetExpressionVal(sub) + ",";
  2086. }
  2087. }
  2088. }
  2089. else if(fieldQueryModel == "query_field")
  2090. {
  2091. foreach(string sub in valList)
  2092. {
  2093. if(fieldQueryValueType == "text")
  2094. {
  2095. val += "'" + GetQueryTableData(condiDic, sub) + "',";
  2096. }
  2097. else
  2098. {
  2099. val += GetQueryTableData(condiDic, sub) + ",";
  2100. }
  2101. }
  2102. }
  2103. else if(fieldQueryModel == "db_field")
  2104. {
  2105. foreach(string sub in valList)
  2106. {
  2107. if(fieldQueryValueType == "text")
  2108. {
  2109. val += "'" + GetDbExpressionVal(sub) + "',";
  2110. }
  2111. else
  2112. {
  2113. val += GetDbExpressionVal(sub) + ",";
  2114. }
  2115. }
  2116. }
  2117. val = val.TrimEnd(',');
  2118. condi += val + ")";
  2119. }
  2120. else if(fieldQueryKind == "3") //范围匹配
  2121. {
  2122. string[] val = fieldQueryValue.Split(':');
  2123. if(fieldQueryModel == "request_param")
  2124. {
  2125. Dictionary<string, string> req = getRequestParams(projectId, content);
  2126. if(fieldQueryValueType == "number")
  2127. {
  2128. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  2129. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  2130. }
  2131. else
  2132. {
  2133. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  2134. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  2135. }
  2136. }
  2137. else if(fieldQueryModel == "fixed_value")
  2138. {
  2139. if(fieldQueryValueType == "number")
  2140. {
  2141. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  2142. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  2143. }
  2144. else
  2145. {
  2146. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + val[0] + "'";
  2147. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + val[1] + "'";
  2148. }
  2149. }
  2150. }
  2151. else if(fieldQueryKind == "4") //取反匹配
  2152. {
  2153. condi += " and " + fieldEnName + "!=";
  2154. string val = "";
  2155. if(fieldQueryModel == "request_param")
  2156. {
  2157. Dictionary<string, string> req = getRequestParams(projectId, content);
  2158. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2159. }
  2160. else if(fieldQueryModel == "fixed_value")
  2161. {
  2162. val = fieldQueryValue;
  2163. }
  2164. if(fieldQueryValueType == "text")
  2165. {
  2166. val = "'" + val + "'";
  2167. }
  2168. condi += val;
  2169. }
  2170. }
  2171. // if(prizeInTable.excuteKind == "add") db.Insertable(doFields).AS(prizeInTable.tableEnName).ExecuteCommand();
  2172. // if(prizeInTable.excuteKind == "update") db.Updateable(doFields).AS(prizeInTable.tableEnName).Where("1=1" + condi).ExecuteCommand();
  2173. Function.WriteLog(DateTime.Now.ToString() + "\n" + prizeInTable.excuteKind + "\n" + prizeInTable.tableEnName + "\n" + Newtonsoft.Json.JsonConvert.SerializeObject(doFields) + "\n" + condi + "\n\n", "奖励入库数据");
  2174. }
  2175. }
  2176. //固定值表达式
  2177. public static string GetExpressionVal(string str)
  2178. {
  2179. if(str == "#{now}#") return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2180. if(str == "#{today}#") return DateTime.Now.ToString("yyyy-MM-dd");
  2181. if(str == "#{this_month}#") return DateTime.Now.ToString("yyyy-MM");
  2182. 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");
  2183. 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");
  2184. if(str.StartsWith("#{today") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  2185. if(str.StartsWith("#{today") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  2186. if(str.StartsWith("#{this_month") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  2187. if(str.StartsWith("#{this_month") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  2188. 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");
  2189. 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");
  2190. return str;
  2191. }
  2192. //库内字段值表达式
  2193. public static string GetDbExpressionVal(string str)
  2194. {
  2195. string[] data = str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',');
  2196. if(str.StartsWith("#{") && str.EndsWith("DAY}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " DAY)";
  2197. if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " MONTH)";
  2198. return str;
  2199. }
  2200. //四则混合运算
  2201. public static string GetComputeVal(List<QueryCondition> condiDic, string expresssion)
  2202. {
  2203. if (expresssion.Contains("+") || expresssion.Contains("-") || expresssion.Contains("*") || expresssion.Contains("/") || expresssion.Contains("(") || expresssion.Contains(")"))
  2204. {
  2205. string[] returnFields = expresssion.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  2206. foreach (string returnField in returnFields)
  2207. {
  2208. if(condiDic.Any(m => m.FieldEnName == returnField))
  2209. {
  2210. string val = GetQueryTableData(condiDic, returnField);
  2211. expresssion = expresssion.Replace(returnField, val);
  2212. }
  2213. }
  2214. DataTable dt = new();
  2215. return dt.Compute(expresssion, "false").ToString();
  2216. }
  2217. return expresssion;
  2218. }
  2219. //获取查询条件数据
  2220. public static string GetQueryTableData(List<QueryCondition> condiDic, string key)
  2221. {
  2222. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).Value.ToString() : "0";
  2223. }
  2224. public static string GetQueryTableTitle(List<QueryCondition> condiDic, string key)
  2225. {
  2226. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).FieldName : "";
  2227. }
  2228. //合并字典
  2229. public static void MergeCondiDic(List<QueryCondition> condiDic, List<QueryCondition> condiDic1)
  2230. {
  2231. foreach(QueryCondition sub in condiDic1)
  2232. {
  2233. condiDic.Add(sub);
  2234. }
  2235. }
  2236. //记录日志
  2237. public static void addLog(int projectId, int listId, int prizeIn, string requestParam, string prizeInUrl)
  2238. {
  2239. var logService = App.GetService<IPriLogService>();
  2240. logService.Add(new PriLog()
  2241. {
  2242. createDate = DateTime.Now,
  2243. projectId = projectId,
  2244. listId = listId,
  2245. batchNo = batchNo,
  2246. prizeIn = prizeIn,
  2247. requestParam = requestParam,
  2248. prizeInUrl = prizeInUrl,
  2249. });
  2250. }
  2251. public static void setLogPrizeAmount(int listId, decimal prizeAmount)
  2252. {
  2253. var logService = App.GetService<IPriLogService>();
  2254. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2255. if(log != null)
  2256. {
  2257. log.prizeAmount = prizeAmount;
  2258. logService.Update(log);
  2259. }
  2260. }
  2261. public static void setLogStep(int listId, Dictionary<string, object> step)
  2262. {
  2263. var logService = App.GetService<IPriLogService>();
  2264. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2265. if(log != null)
  2266. {
  2267. log.stepList += Newtonsoft.Json.JsonConvert.SerializeObject(step) + ",";
  2268. logService.Update(log);
  2269. }
  2270. }
  2271. public static void setLogStep(int listId, string key, object val)
  2272. {
  2273. var logService = App.GetService<IPriLogService>();
  2274. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2275. if(log != null)
  2276. {
  2277. log.stepList += "\"" + key + "\":" + Newtonsoft.Json.JsonConvert.SerializeObject(val) + ",";
  2278. logService.Update(log);
  2279. }
  2280. }
  2281. public static void setLogStatus(int listId, int status)
  2282. {
  2283. var logService = App.GetService<IPriLogService>();
  2284. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2285. if(log != null)
  2286. {
  2287. log.status = status;
  2288. logService.Update(log);
  2289. }
  2290. }
  2291. public static void setLogFieldValue(int listId, string field, string content)
  2292. {
  2293. var logService = App.GetService<IPriLogService>();
  2294. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2295. if(log != null)
  2296. {
  2297. if(field == "errLog") log.errLog = content;
  2298. if(field == "prizeOutContent") log.prizeOutContent = content;
  2299. if(field == "prizeOutUrl") log.prizeOutUrl = content;
  2300. if(field == "stepListIndex") log.stepListIndex = content;
  2301. logService.Update(log);
  2302. }
  2303. }
  2304. public static string getQueryKind(string kind)
  2305. {
  2306. if(kind == "1") return "模糊匹配";
  2307. if(kind == "2") return "精确匹配";
  2308. if(kind == "4") return "取反匹配";
  2309. if(kind == "5") return "数组匹配";
  2310. if(kind == "6") return "数组排除";
  2311. if(kind == "3") return "范围匹配";
  2312. return kind;
  2313. }
  2314. public static string getQueryModel(string model)
  2315. {
  2316. if(model == "request_param") return "入参";
  2317. if(model == "query_field") return "条件匹配返回字段";
  2318. if(model == "loop_field") return "循环递归字段";
  2319. if(model == "loop_condition_field") return "循环递归条件字段";
  2320. if(model == "fixed_value") return "固定值";
  2321. if(model == "db_field") return "库内字段";
  2322. return model;
  2323. }
  2324. }
  2325. }