PrizeDo.cs 156 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761
  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. using System.Text.RegularExpressions;
  13. namespace Util
  14. {
  15. public class PrizeDo
  16. {
  17. public static string batchNo = "";
  18. public static string publicStep = "";
  19. public static bool logFlag = true;
  20. //发奖入口
  21. public static void sendPrize(string queueName, string content)
  22. {
  23. batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(3);
  24. publicStep = "";
  25. string priObjString = prizeInSet(queueName);
  26. if(!string.IsNullOrEmpty(priObjString))
  27. {
  28. string[] priObjData = priObjString.Split('|');
  29. string priListIds = priObjData[0];
  30. int projectId = int.Parse(priObjData[1]);
  31. int prizeInId = int.Parse(priObjData[2]);
  32. var projectService = App.GetService<IPriProjectService>();
  33. var project = projectService.GetFirst(m => m.id == projectId) ?? new PriProject();
  34. logFlag = project.logFlag;
  35. prizeSend(projectId, prizeInId, priListIds, content, queueName);
  36. }
  37. }
  38. //接收入参
  39. public static Dictionary<string, string> getRequestParams(int projectId, string content)
  40. {
  41. Dictionary<string, string> dic = new();
  42. JsonData jsonData = JsonMapper.ToObject(content);
  43. var paramService = App.GetService<IPriProjectParamService>();
  44. var paramList = paramService.GetList(m => m.projectId == projectId);
  45. foreach(var param in paramList)
  46. {
  47. if(content.Contains("\"" + param.fieldEnName + "\"")) dic.Add(param.fieldEnName, jsonData[param.fieldEnName].ToString());
  48. }
  49. return dic;
  50. }
  51. public static string getRequestParams(int projectId, string content, string key)
  52. {
  53. JsonData jsonData = JsonMapper.ToObject(content);
  54. var paramService = App.GetService<IPriProjectParamService>();
  55. var param = paramService.GetFirst(m => m.projectId == projectId && m.fieldEnName == key);
  56. if(param != null)
  57. {
  58. return jsonData[param.fieldEnName].ToString();
  59. }
  60. return "0";
  61. }
  62. //数据库链接
  63. public static SqlSugarClient initDb(int id)
  64. {
  65. var databaseSetService = App.GetService<IPriDatabaseSetService>();
  66. var connectionString = databaseSetService.GetFirst(m => m.id == id);
  67. string server = connectionString.ipAddress;
  68. int port = connectionString.port;
  69. string user = connectionString.userId;
  70. string password = connectionString.password;
  71. string database = connectionString.databaseName;
  72. var db = new SqlSugarClient(new ConnectionConfig()
  73. {
  74. ConnectionString = "server=" + server + ";port=" + port + ";user=" + user + ";password=" + password + ";database=" + database + ";charset=utf8;",
  75. DbType = SqlSugar.DbType.MySql,
  76. IsAutoCloseConnection = true,
  77. });
  78. return db;
  79. }
  80. //查询条件匹配数据
  81. public static List<QueryCondition> condition(int listId, int projectId, List<int> ids, string content, Dictionary<string, string> startData)
  82. {
  83. List<QueryCondition> dic = new();
  84. var queryTableService = App.GetService<IPriQueryTableService>();
  85. var queryFieldService = App.GetService<IPriQueryFieldService>();
  86. var returnFieldService = App.GetService<IPriReturnFieldService>();
  87. //查询表
  88. var queryTables = queryTableService.GetList(m => ids.Contains(m.id) && m.startDataFlag == false);
  89. foreach(var queryTable in queryTables)
  90. {
  91. string sql = "";
  92. Dictionary<string, string> fieldDic = new();
  93. if(string.IsNullOrEmpty(queryTable.customSql))
  94. {
  95. string tableEnName = queryTable.tableEnName;
  96. if(tableEnName.Contains("#{")) tableEnName = MatchExpressionVal(tableEnName);
  97. //查询返回字段
  98. string fields = "";
  99. var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id);
  100. foreach(var returnField in returnFields)
  101. {
  102. string aliasName = returnField.fieldAliasName;
  103. if(string.IsNullOrEmpty(aliasName)) aliasName = tableEnName + "_" + returnField.fieldEnName;
  104. if(returnField.fieldReturnKind == "2")
  105. {
  106. fields += "count(" + returnField.fieldEnName + ") " + aliasName + ",";
  107. }
  108. else if(returnField.fieldReturnKind == "3")
  109. {
  110. fields += "sum(" + returnField.fieldEnName + ") " + aliasName + ",";
  111. }
  112. else if(returnField.fieldReturnKind == "4")
  113. {
  114. fields += "avg(" + returnField.fieldEnName + ") " + aliasName + ",";
  115. }
  116. else if(returnField.fieldReturnKind == "5")
  117. {
  118. fields += "max(" + returnField.fieldEnName + ") " + aliasName + ",";
  119. }
  120. else if(returnField.fieldReturnKind == "6")
  121. {
  122. fields += "min(" + returnField.fieldEnName + ") " + aliasName + ",";
  123. }
  124. else if(returnField.fieldReturnKind == "7")
  125. {
  126. fields += GetDbExpressionVal(returnField.fieldEnName, projectId, content, dic, startData) + ",";
  127. }
  128. else
  129. {
  130. fields += returnField.fieldEnName + " " + aliasName + ",";
  131. }
  132. fieldDic.Add(aliasName, returnField.fieldName);
  133. }
  134. fields = fields.TrimEnd(',');
  135. //查询匹配条件
  136. string condi = "";
  137. var queryFields = queryFieldService.GetList(m => m.queryTableId == queryTable.id);
  138. foreach(var queryField in queryFields)
  139. {
  140. string fieldEnName = queryField.fieldEnName;
  141. string fieldQueryKind = queryField.fieldQueryKind;
  142. string fieldQueryModel = queryField.fieldQueryModel;
  143. string fieldQueryValue = queryField.fieldQueryValue;
  144. string fieldQueryValueType = queryField.fieldQueryValueType;
  145. if(fieldQueryKind == "1") //模糊匹配
  146. {
  147. condi += " and " + fieldEnName + " like ";
  148. if(fieldQueryModel == "request_param")
  149. {
  150. condi += "'%" + getRequestParams(projectId, content, fieldQueryValue) + "%'";
  151. }
  152. else if(fieldQueryModel == "fixed_value")
  153. {
  154. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  155. }
  156. else if(fieldQueryModel == "db_field")
  157. {
  158. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  159. }
  160. else if(fieldQueryModel == "query_field")
  161. {
  162. string val = GetQueryTableData(dic, fieldQueryValue);
  163. condi += "'%" + val + "%'";
  164. }
  165. else if(fieldQueryModel == "querystart_list_field")
  166. {
  167. string val = GetStartData(startData, fieldQueryValue);
  168. condi += "'%" + val + "%'";
  169. }
  170. }
  171. else if(fieldQueryKind == "2") //精确匹配
  172. {
  173. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is null";
  174. else
  175. {
  176. condi += " and " + fieldEnName + "=";
  177. string val = "";
  178. if(fieldQueryModel == "request_param")
  179. {
  180. Dictionary<string, string> req = getRequestParams(projectId, content);
  181. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  182. }
  183. else if(fieldQueryModel == "fixed_value")
  184. {
  185. val = GetExpressionVal(fieldQueryValue);
  186. }
  187. else if(fieldQueryModel == "db_field")
  188. {
  189. val = GetDbExpressionVal(fieldQueryValue);
  190. }
  191. else if(fieldQueryModel == "query_field")
  192. {
  193. val = GetQueryTableData(dic, fieldQueryValue);
  194. }
  195. else if(fieldQueryModel == "querystart_list_field")
  196. {
  197. val = GetStartData(startData, fieldQueryValue);
  198. }
  199. if(fieldQueryValueType == "text")
  200. {
  201. val = "'" + val + "'";
  202. }
  203. condi += val;
  204. }
  205. }
  206. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  207. {
  208. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  209. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  210. string val = "";
  211. string[] valList = fieldQueryValue.Split(',');
  212. if(fieldQueryModel == "request_param")
  213. {
  214. Dictionary<string, string> req = getRequestParams(projectId, content);
  215. foreach(string sub in valList)
  216. {
  217. if(fieldQueryValueType == "text")
  218. {
  219. val += "'" + req[sub] + "',";
  220. }
  221. else
  222. {
  223. val += req[sub] + ",";
  224. }
  225. }
  226. }
  227. else if(fieldQueryModel == "fixed_value")
  228. {
  229. foreach(string sub in valList)
  230. {
  231. if(fieldQueryValueType == "text")
  232. {
  233. val += "'" + GetExpressionVal(sub) + "',";
  234. }
  235. else
  236. {
  237. val += GetExpressionVal(sub) + ",";
  238. }
  239. }
  240. }
  241. else if(fieldQueryModel == "db_field")
  242. {
  243. foreach(string sub in valList)
  244. {
  245. if(fieldQueryValueType == "text")
  246. {
  247. val += "'" + GetDbExpressionVal(sub) + "',";
  248. }
  249. else
  250. {
  251. val += GetDbExpressionVal(sub) + ",";
  252. }
  253. }
  254. }
  255. else if(fieldQueryModel == "query_field")
  256. {
  257. foreach(string sub in valList)
  258. {
  259. string dicVal = GetQueryTableData(dic, sub);
  260. if(fieldQueryValueType == "text")
  261. {
  262. val += "'" + dicVal + "',";
  263. }
  264. else
  265. {
  266. val += dicVal + ",";
  267. }
  268. }
  269. }
  270. else if(fieldQueryModel == "querystart_list_field")
  271. {
  272. foreach(string sub in valList)
  273. {
  274. string dicVal = GetStartData(startData, sub);
  275. if(fieldQueryValueType == "text")
  276. {
  277. val += "'" + dicVal + "',";
  278. }
  279. else
  280. {
  281. val += dicVal + ",";
  282. }
  283. }
  284. }
  285. val = val.TrimEnd(',');
  286. condi += val + ")";
  287. }
  288. else if(fieldQueryKind == "3") //范围匹配
  289. {
  290. string[] val = fieldQueryValue.Split(':');
  291. if(fieldQueryModel == "request_param")
  292. {
  293. Dictionary<string, string> req = getRequestParams(projectId, content);
  294. if(fieldQueryValueType == "number")
  295. {
  296. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  297. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  298. }
  299. else
  300. {
  301. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  302. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  303. }
  304. }
  305. else if(fieldQueryModel == "fixed_value")
  306. {
  307. if(fieldQueryValueType == "number")
  308. {
  309. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  310. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  311. }
  312. else
  313. {
  314. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  315. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  316. }
  317. }
  318. else if(fieldQueryModel == "db_field")
  319. {
  320. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + GetDbExpressionVal(val[0]);
  321. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + GetDbExpressionVal(val[1]);
  322. }
  323. else if(fieldQueryModel == "query_field")
  324. {
  325. string valLeft = val[0];
  326. string valRight = val[1];
  327. string dicValLeft = GetQueryTableData(dic, valLeft);
  328. string dicValRight = GetQueryTableData(dic, valRight);
  329. if(fieldQueryValueType == "number")
  330. {
  331. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft;
  332. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight;
  333. }
  334. else
  335. {
  336. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'";
  337. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'";
  338. }
  339. }
  340. else if(fieldQueryModel == "querystart_list_field")
  341. {
  342. string valLeft = val[0];
  343. string valRight = val[1];
  344. string dicValLeft = GetStartData(startData, valLeft);
  345. string dicValRight = GetStartData(startData, valRight);
  346. if(fieldQueryValueType == "number")
  347. {
  348. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft;
  349. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight;
  350. }
  351. else
  352. {
  353. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'";
  354. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'";
  355. }
  356. }
  357. }
  358. else if(fieldQueryKind == "4") //取反匹配
  359. {
  360. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is not null";
  361. else
  362. {
  363. condi += " and " + fieldEnName + "!=";
  364. string val = "";
  365. if(fieldQueryModel == "request_param")
  366. {
  367. Dictionary<string, string> req = getRequestParams(projectId, content);
  368. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  369. }
  370. else if(fieldQueryModel == "fixed_value")
  371. {
  372. val = GetExpressionVal(fieldQueryValue);
  373. }
  374. else if(fieldQueryModel == "db_field")
  375. {
  376. val = GetDbExpressionVal(fieldQueryValue);
  377. }
  378. else if(fieldQueryModel == "query_field")
  379. {
  380. val = GetQueryTableData(dic, fieldQueryValue);
  381. }
  382. else if(fieldQueryModel == "querystart_list_field")
  383. {
  384. val = GetStartData(startData, fieldQueryValue);
  385. }
  386. if(fieldQueryValueType == "text")
  387. {
  388. val = "'" + val + "'";
  389. }
  390. condi += val;
  391. }
  392. }
  393. }
  394. sql = "select " + fields + " from " + tableEnName + " where 1=1" + condi;
  395. if(!string.IsNullOrEmpty(queryTable.orderBy))
  396. {
  397. sql += " order by " + queryTable.orderBy;
  398. }
  399. sql += " limit 1";
  400. }
  401. else
  402. {
  403. sql = queryTable.customSql;
  404. sql = GetDbExpressionVal(sql, projectId, content, dic, startData);
  405. }
  406. var db = initDb(queryTable.databaseId);
  407. var items = db.Ado.GetDataTable(sql);
  408. if(items.Rows.Count > 0)
  409. {
  410. if(string.IsNullOrEmpty(queryTable.customSql))
  411. {
  412. foreach(string field in fieldDic.Keys)
  413. {
  414. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  415. {
  416. FieldName = fieldDic[field],
  417. FieldEnName = field,
  418. Value = items.Rows[0][field].ToString()
  419. });
  420. }
  421. }
  422. else
  423. {
  424. foreach(DataColumn column in items.Columns)
  425. {
  426. string field = column.ColumnName;
  427. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  428. {
  429. FieldName = field,
  430. FieldEnName = field,
  431. Value = items.Rows[0][field].ToString()
  432. });
  433. }
  434. }
  435. }
  436. }
  437. return dic;
  438. }
  439. public static DataTable conditionList(int listId, int projectId, List<int> ids, string content, int skip = 0, int size = 1000)
  440. {
  441. List<QueryCondition> dic = new();
  442. var queryTableService = App.GetService<IPriQueryTableService>();
  443. var queryFieldService = App.GetService<IPriQueryFieldService>();
  444. var returnFieldService = App.GetService<IPriReturnFieldService>();
  445. //查询表
  446. var queryTable = queryTableService.GetFirst(m => ids.Contains(m.id) && m.startDataFlag == true);
  447. if (queryTable != null)
  448. {
  449. string groupBy = "";
  450. string tableEnName = queryTable.tableEnName;
  451. if(tableEnName.Contains("#{")) tableEnName = MatchExpressionVal(tableEnName);
  452. //查询返回字段
  453. string fields = "";
  454. Dictionary<string, string> fieldDic = new();
  455. var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id);
  456. foreach(var returnField in returnFields)
  457. {
  458. if(returnField.fieldReturnKind == "2")
  459. {
  460. fields += "count(" + returnField.fieldEnName + ") " + tableEnName + "_" + returnField.fieldEnName.Split('+')[0] + ",";
  461. }
  462. else if(returnField.fieldReturnKind == "3")
  463. {
  464. fields += "sum(" + returnField.fieldEnName + ") " + tableEnName + "_" + returnField.fieldEnName.Split('+')[0] + ",";
  465. }
  466. else if(returnField.fieldReturnKind == "4")
  467. {
  468. fields += "avg(" + returnField.fieldEnName + ") " + tableEnName + "_" + returnField.fieldEnName.Split('+')[0] + ",";
  469. }
  470. else if(returnField.fieldReturnKind == "5")
  471. {
  472. fields += "max(" + returnField.fieldEnName + ") " + tableEnName + "_" + returnField.fieldEnName.Split('+')[0] + ",";
  473. }
  474. else if(returnField.fieldReturnKind == "6")
  475. {
  476. fields += "min(" + returnField.fieldEnName + ") " + tableEnName + "_" + returnField.fieldEnName.Split('+')[0] + ",";
  477. }
  478. else
  479. {
  480. fields += returnField.fieldEnName + " " + tableEnName + "_" + returnField.fieldEnName + ",";
  481. }
  482. fieldDic.Add(tableEnName + "_" + returnField.fieldEnName, returnField.fieldName);
  483. }
  484. fields = fields.TrimEnd(',');
  485. //查询匹配条件
  486. string condi = "";
  487. var queryFields = queryFieldService.GetList(m => m.queryTableId == queryTable.id);
  488. foreach(var queryField in queryFields)
  489. {
  490. string fieldEnName = queryField.fieldEnName;
  491. string fieldQueryKind = queryField.fieldQueryKind;
  492. string fieldQueryModel = queryField.fieldQueryModel;
  493. string fieldQueryValue = queryField.fieldQueryValue;
  494. string fieldQueryValueType = queryField.fieldQueryValueType;
  495. //拼装聚合字段
  496. if(queryField.groupByFlag)
  497. {
  498. groupBy += queryField.fieldEnName + ",";
  499. }
  500. else
  501. {
  502. if(fieldQueryKind == "1") //模糊匹配
  503. {
  504. condi += " and " + fieldEnName + " like ";
  505. if(fieldQueryModel == "request_param")
  506. {
  507. Dictionary<string, string> req = getRequestParams(projectId, content);
  508. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  509. condi += "'%" + val + "%'";
  510. }
  511. else if(fieldQueryModel == "fixed_value")
  512. {
  513. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  514. }
  515. else if(fieldQueryModel == "db_field")
  516. {
  517. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  518. }
  519. else if(fieldQueryModel == "query_field")
  520. {
  521. string val = GetQueryTableData(dic, fieldQueryValue);
  522. condi += "'%" + val + "%'";
  523. }
  524. }
  525. else if(fieldQueryKind == "2") //精确匹配
  526. {
  527. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is null";
  528. else
  529. {
  530. condi += " and " + fieldEnName + "=";
  531. string val = "";
  532. if(fieldQueryModel == "request_param")
  533. {
  534. Dictionary<string, string> req = getRequestParams(projectId, content);
  535. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  536. }
  537. else if(fieldQueryModel == "fixed_value")
  538. {
  539. val = GetExpressionVal(fieldQueryValue);
  540. }
  541. else if(fieldQueryModel == "db_field")
  542. {
  543. val = GetDbExpressionVal(fieldQueryValue);
  544. }
  545. else if(fieldQueryModel == "query_field")
  546. {
  547. val = GetQueryTableData(dic, fieldQueryValue);
  548. }
  549. if(fieldQueryValueType == "text")
  550. {
  551. val = "'" + val + "'";
  552. }
  553. condi += val;
  554. }
  555. }
  556. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  557. {
  558. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  559. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  560. string val = "";
  561. string[] valList = fieldQueryValue.Split(',');
  562. if(fieldQueryModel == "request_param")
  563. {
  564. Dictionary<string, string> req = getRequestParams(projectId, content);
  565. foreach(string sub in valList)
  566. {
  567. if(fieldQueryValueType == "text")
  568. {
  569. val += "'" + req[sub] + "',";
  570. }
  571. else
  572. {
  573. val += req[sub] + ",";
  574. }
  575. }
  576. }
  577. else if(fieldQueryModel == "fixed_value")
  578. {
  579. foreach(string sub in valList)
  580. {
  581. if(fieldQueryValueType == "text")
  582. {
  583. val += "'" + GetExpressionVal(sub) + "',";
  584. }
  585. else
  586. {
  587. val += GetExpressionVal(sub) + ",";
  588. }
  589. }
  590. }
  591. else if(fieldQueryModel == "db_field")
  592. {
  593. foreach(string sub in valList)
  594. {
  595. if(fieldQueryValueType == "text")
  596. {
  597. val += "'" + GetDbExpressionVal(sub) + "',";
  598. }
  599. else
  600. {
  601. val += GetDbExpressionVal(sub) + ",";
  602. }
  603. }
  604. }
  605. else if(fieldQueryModel == "query_field")
  606. {
  607. foreach(string sub in valList)
  608. {
  609. string dicVal = GetQueryTableData(dic, sub);
  610. if(fieldQueryValueType == "text")
  611. {
  612. val += "'" + dicVal + "',";
  613. }
  614. else
  615. {
  616. val += dicVal + ",";
  617. }
  618. }
  619. }
  620. val = val.TrimEnd(',');
  621. condi += val + ")";
  622. }
  623. else if(fieldQueryKind == "3") //范围匹配
  624. {
  625. string[] val = fieldQueryValue.Split(':');
  626. if(fieldQueryModel == "request_param")
  627. {
  628. Dictionary<string, string> req = getRequestParams(projectId, content);
  629. if(fieldQueryValueType == "number")
  630. {
  631. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  632. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  633. }
  634. else
  635. {
  636. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  637. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  638. }
  639. }
  640. else if(fieldQueryModel == "fixed_value")
  641. {
  642. if(fieldQueryValueType == "number")
  643. {
  644. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  645. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  646. }
  647. else
  648. {
  649. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  650. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  651. }
  652. }
  653. else if(fieldQueryModel == "db_field")
  654. {
  655. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + GetDbExpressionVal(val[0]);
  656. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + GetDbExpressionVal(val[1]);
  657. }
  658. else if(fieldQueryModel == "query_field")
  659. {
  660. string valLeft = val[0];
  661. string valRight = val[1];
  662. string dicValLeft = GetQueryTableData(dic, valLeft);
  663. string dicValRight = GetQueryTableData(dic, valRight);
  664. if(fieldQueryValueType == "number")
  665. {
  666. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft;
  667. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight;
  668. }
  669. else
  670. {
  671. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'";
  672. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'";
  673. }
  674. }
  675. }
  676. else if(fieldQueryKind == "4") //取反匹配
  677. {
  678. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is not null";
  679. else
  680. {
  681. condi += " and " + fieldEnName + "!=";
  682. string val = "";
  683. if(fieldQueryModel == "request_param")
  684. {
  685. Dictionary<string, string> req = getRequestParams(projectId, content);
  686. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  687. }
  688. else if(fieldQueryModel == "fixed_value")
  689. {
  690. val = GetExpressionVal(fieldQueryValue);
  691. }
  692. else if(fieldQueryModel == "db_field")
  693. {
  694. val = GetDbExpressionVal(fieldQueryValue);
  695. }
  696. else if(fieldQueryModel == "query_field")
  697. {
  698. val = GetQueryTableData(dic, fieldQueryValue);
  699. }
  700. if(fieldQueryValueType == "text")
  701. {
  702. val = "'" + val + "'";
  703. }
  704. condi += val;
  705. }
  706. }
  707. }
  708. }
  709. if(!string.IsNullOrEmpty(groupBy)) groupBy = " group by " + groupBy.TrimEnd(',') + " order by " + groupBy.TrimEnd(',');
  710. var db = initDb(queryTable.databaseId);
  711. if(!string.IsNullOrEmpty(queryTable.tableEnName))
  712. {
  713. groupBy += " " + queryTable.tableEnName;
  714. }
  715. string sql = "select " + fields + " from " + tableEnName + " where 1=1" + condi + groupBy + " limit " + skip + "," + size;
  716. var items = db.Ado.GetDataTable(sql);
  717. return items;
  718. }
  719. return new DataTable();
  720. }
  721. //奖励发放对象
  722. public static string prizeObject(int listId, int prizeObjectTag, string content)
  723. {
  724. Dictionary<string, object> logStepDic = new();
  725. Dictionary<string, object> dic = new();
  726. var prizeObjectTableService = App.GetService<IPriPrizeObjectTableService>();
  727. var prizeObjectFieldService = App.GetService<IPriPrizeObjectFieldService>();
  728. //查询表
  729. var prizeObjectTable = prizeObjectTableService.GetFirst(m => m.id == prizeObjectTag) ?? new PriPrizeObjectTable();
  730. //查询返回字段
  731. string field = prizeObjectTable.selectField;
  732. int projectId = prizeObjectTable.projectId;
  733. logStepDic.Add("奖励发放对象说明", prizeObjectTable.note);
  734. //查询匹配条件
  735. string condi = "";
  736. List<Dictionary<string, object>> condiDics = new();
  737. var queryFields = prizeObjectFieldService.GetList(m => m.objectTableId == prizeObjectTable.id);
  738. foreach(var queryField in queryFields)
  739. {
  740. string fieldName = queryField.fieldName;
  741. string fieldEnName = queryField.fieldEnName;
  742. string fieldQueryKind = queryField.fieldQueryKind;
  743. string fieldQueryModel = queryField.fieldQueryModel;
  744. string fieldQueryValue = queryField.fieldQueryValue;
  745. string fieldQueryValueType = queryField.fieldQueryValueType;
  746. Dictionary<string, object> condiDic = new();
  747. condiDic.Add("字段名称", fieldName);
  748. condiDic.Add("匹配条件", getQueryKind(fieldQueryKind));
  749. condiDic.Add("匹配方式", getQueryModel(fieldQueryModel));
  750. if(fieldQueryKind == "1") //模糊匹配
  751. {
  752. condi += " and " + fieldEnName + " like ";
  753. if(fieldQueryModel == "request_param")
  754. {
  755. Dictionary<string, string> req = getRequestParams(projectId, content);
  756. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  757. condi += "'%" + val + "%'";
  758. condiDic.Add("匹配值", val);
  759. }
  760. else if(fieldQueryModel == "fixed_value")
  761. {
  762. string val = GetExpressionVal(fieldQueryValue);
  763. condi += "'%" + val + "%'";
  764. condiDic.Add("匹配值", val);
  765. }
  766. else if(fieldQueryModel == "db_field")
  767. {
  768. string val = GetDbExpressionVal(fieldQueryValue);
  769. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  770. condiDic.Add("匹配值", val);
  771. }
  772. }
  773. else if(fieldQueryKind == "2") //精确匹配
  774. {
  775. condi += " and " + fieldEnName + "=";
  776. string val = "";
  777. if(fieldQueryModel == "request_param")
  778. {
  779. Dictionary<string, string> req = getRequestParams(projectId, content);
  780. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  781. }
  782. else if(fieldQueryModel == "fixed_value")
  783. {
  784. val = GetExpressionVal(fieldQueryValue);
  785. }
  786. else if(fieldQueryModel == "db_field")
  787. {
  788. val = GetDbExpressionVal(fieldQueryValue);
  789. }
  790. if(fieldQueryValueType == "text")
  791. {
  792. val = "'" + val + "'";
  793. }
  794. condi += val;
  795. condiDic.Add("匹配值", val);
  796. }
  797. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  798. {
  799. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  800. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  801. string val = "";
  802. string[] valList = fieldQueryValue.Split(',');
  803. if(fieldQueryModel == "request_param")
  804. {
  805. Dictionary<string, string> req = getRequestParams(projectId, content);
  806. foreach(string sub in valList)
  807. {
  808. if(fieldQueryValueType == "text")
  809. {
  810. val += "'" + req[sub] + "',";
  811. }
  812. else
  813. {
  814. val += req[sub] + ",";
  815. }
  816. }
  817. }
  818. else if(fieldQueryModel == "fixed_value")
  819. {
  820. foreach(string sub in valList)
  821. {
  822. if(fieldQueryValueType == "text")
  823. {
  824. val += "'" + GetExpressionVal(sub) + "',";
  825. }
  826. else
  827. {
  828. val += GetExpressionVal(sub) + ",";
  829. }
  830. }
  831. }
  832. else if(fieldQueryModel == "db_field")
  833. {
  834. foreach(string sub in valList)
  835. {
  836. if(fieldQueryValueType == "text")
  837. {
  838. val += "'" + GetDbExpressionVal(sub) + "',";
  839. }
  840. else
  841. {
  842. val += GetDbExpressionVal(sub) + ",";
  843. }
  844. }
  845. }
  846. val = val.TrimEnd(',');
  847. condi += val + ")";
  848. condiDic.Add("匹配值", val);
  849. }
  850. else if(fieldQueryKind == "3") //范围匹配
  851. {
  852. string[] val = fieldQueryValue.Split(':');
  853. if(fieldQueryModel == "request_param")
  854. {
  855. Dictionary<string, string> req = getRequestParams(projectId, content);
  856. if(fieldQueryValueType == "number")
  857. {
  858. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  859. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  860. }
  861. else
  862. {
  863. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  864. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  865. }
  866. }
  867. else if(fieldQueryModel == "fixed_value")
  868. {
  869. if(fieldQueryValueType == "number")
  870. {
  871. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  872. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  873. }
  874. else
  875. {
  876. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  877. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  878. }
  879. }
  880. else if(fieldQueryModel == "db_field")
  881. {
  882. if(fieldQueryValueType == "number")
  883. {
  884. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  885. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  886. }
  887. else
  888. {
  889. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  890. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  891. }
  892. }
  893. condiDic.Add("匹配值", val);
  894. }
  895. else if(fieldQueryKind == "4") //取反匹配
  896. {
  897. condi += " and " + fieldEnName + "!=";
  898. string val = "";
  899. if(fieldQueryModel == "request_param")
  900. {
  901. Dictionary<string, string> req = getRequestParams(projectId, content);
  902. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  903. }
  904. else if(fieldQueryModel == "fixed_value")
  905. {
  906. val = GetExpressionVal(fieldQueryValue);
  907. }
  908. else if(fieldQueryModel == "db_field")
  909. {
  910. val = GetDbExpressionVal(fieldQueryValue);
  911. }
  912. if(fieldQueryValueType == "text")
  913. {
  914. val = "'" + val + "'";
  915. }
  916. condi += val;
  917. condiDic.Add("匹配值", val);
  918. }
  919. condiDics.Add(condiDic);
  920. }
  921. logStepDic.Add("奖励发放对象查询条件", condiDics);
  922. string result = "0";
  923. var db = initDb(prizeObjectTable.databaseId);
  924. var item = db.Ado.GetScalar("select " + field + " from " + prizeObjectTable.tableEnName + " where 1=1" + condi);
  925. if(item != null)
  926. {
  927. result = item.ToString();
  928. }
  929. logStepDic.Add("奖励发放对象", result);
  930. setLogStep(listId, "奖励发放对象", logStepDic);
  931. return result;
  932. }
  933. //奖励发放入口
  934. public static string prizeInSet(string queueName)
  935. {
  936. Dictionary<string, object> dic = new();
  937. var prizeInSetService = App.GetService<IPriPrizeInSetService>();
  938. //查询表
  939. var prizeInSet = prizeInSetService.GetFirst(m => m.mqQueueName == queueName) ?? new PriPrizeInSet();
  940. if(prizeInSet.id > 0)
  941. {
  942. return prizeInSet.prizeListIds + "|" + prizeInSet.projectId + "|" + prizeInSet.id;
  943. }
  944. return "";
  945. }
  946. //奖励列表
  947. public static List<PriList> prizeList(int projectId, string prizeIds)
  948. {
  949. List<int> ids = Tools.SpitIntArrary(prizeIds, ',').ToList();
  950. var priListService = App.GetService<IPriListService>();
  951. var priList = priListService.GetList(m => m.projectId == projectId && ids.Contains(m.id)).ToList();
  952. return priList;
  953. }
  954. //奖励发放
  955. public static void prizeSend(int projectId, int prizeInId, string prizeIds, string content, string queueName)
  956. {
  957. var queryTableService = App.GetService<IPriQueryTableService>();
  958. var priList = prizeList(projectId, prizeIds);
  959. foreach(var sub in priList)
  960. {
  961. try
  962. {
  963. List<int> ids = Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList();
  964. var queryTable = queryTableService.GetFirst(m => ids.Contains(m.id) && m.startDataFlag == true);
  965. if (queryTable != null)
  966. {
  967. int page = 0;
  968. int size = queryTable.stepCount;
  969. if(size == 0) size = 20;
  970. bool op = true;
  971. while(op)
  972. {
  973. int skip = page * size;
  974. DataTable query = conditionList(sub.id, projectId, ids, content, skip, size);
  975. if(query.Rows.Count > 0)
  976. {
  977. foreach(DataRow dr in query.Rows)
  978. {
  979. Dictionary<string, string> startData = new();
  980. foreach(DataColumn dc in query.Columns)
  981. {
  982. startData.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
  983. }
  984. prizeSendSub(sub, projectId, prizeInId, prizeIds, content, queueName, startData);
  985. }
  986. page += 1;
  987. }
  988. else
  989. {
  990. op = false;
  991. }
  992. }
  993. }
  994. else
  995. {
  996. prizeSendSub(sub, projectId, prizeInId, prizeIds, content, queueName, new Dictionary<string, string>());
  997. }
  998. }
  999. catch(Exception ex)
  1000. {
  1001. setLogFieldValue(sub.id, "errLog", ex.ToString());
  1002. }
  1003. }
  1004. }
  1005. //执行每个奖励发放逻辑
  1006. public static void prizeSendSub(PriList sub, int projectId, int prizeInId, string prizeIds, string content, string queueName, Dictionary<string, string> startData)
  1007. {
  1008. var loopSetService = App.GetService<IPriLoopSetService>();
  1009. var recursionStartTableService = App.GetService<IPriRecursionStartTableService>();
  1010. var recursionStartConditionService = App.GetService<IPriRecursionStartConditionService>();
  1011. addLog(projectId, sub.id, prizeInId, content, queueName); //初始化日志
  1012. string prizeObjectId = prizeObject(sub.id, sub.prizeObj, content);
  1013. var recursionFlag = sub.recursionFlag; //是否递归
  1014. setLogStep(sub.id, "是否递归", recursionFlag ? "是" : "否");
  1015. if(recursionFlag)
  1016. {
  1017. List<QueryCondition> queryCondiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content, startData);
  1018. setLogStep(sub.id, "查询原始数据", queryCondiDic);
  1019. var loopSet = loopSetService.GetFirst(m => m.listId == sub.id) ?? new PriLoopSet();
  1020. var recursionStartTable = recursionStartTableService.GetFirst(m => m.listId == sub.id) ?? new PriRecursionStartTable();
  1021. var tableEnName = loopSet.tableEnName; //递归查询表
  1022. var parentField = loopSet.parentField; //父字段
  1023. var sonField = loopSet.sonField; //子字段
  1024. var afterPrizeFlag = loopSet.afterPrizeFlag; //发奖后是否继续
  1025. var db = initDb(loopSet.databaseId);
  1026. string objId = prizeObjectId;
  1027. bool op = true;
  1028. int index = 0;
  1029. loopAmount = 0;
  1030. List<Dictionary<string, object>> loopLogDic = new();
  1031. while(!string.IsNullOrEmpty(objId) && objId != "0" && op)
  1032. {
  1033. Dictionary<string, object> loopLog = new();
  1034. List<QueryCondition> condiDic = loopCondition(projectId, sub, objId, content);
  1035. loopLog.Add("查询" + objId + "匹配数据", condiDic);
  1036. if(condiDic.Count > 0)
  1037. {
  1038. bool prizeFlag = false;
  1039. List<Dictionary<string, object>> logStepDics = new();
  1040. var groupNos = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id).ToList().Select(m => m.groupNo).Distinct().ToList();
  1041. foreach(var groupNo in groupNos)
  1042. {
  1043. var conditions = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id && m.groupNo == groupNo);
  1044. if(conditions.Count > 0)
  1045. {
  1046. int allCount = conditions.Count; //所有奖励条件数
  1047. int passCount = 0; //通过条件数
  1048. foreach(var condition in conditions)
  1049. {
  1050. if(condition.startIndex <= index)
  1051. {
  1052. Dictionary<string, object> logStepDic = new();
  1053. var returnFieldId = condition.returnFieldId; //条件返回字段
  1054. returnFieldId = MatchExpressionVal(returnFieldId);
  1055. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  1056. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  1057. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  1058. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  1059. string checkObj = "";
  1060. string checkTitle = "";
  1061. if(returnFieldId.Contains(","))
  1062. {
  1063. string[] returnFieldIdList = returnFieldId.Split(',');
  1064. foreach(string subField in returnFieldIdList)
  1065. {
  1066. string val = GetQueryTableData(condiDic, subField);
  1067. checkObj += val + ",";
  1068. string title = GetQueryTableTitle(condiDic, subField);
  1069. checkTitle += title + ",";
  1070. }
  1071. checkObj = checkObj.TrimEnd(',');
  1072. checkTitle = checkTitle.TrimEnd(',');
  1073. }
  1074. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  1075. {
  1076. string expresssion = returnFieldId;
  1077. checkTitle = returnFieldId;
  1078. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  1079. foreach(string returnField in returnFields)
  1080. {
  1081. string val = GetQueryTableData(condiDic, returnField);
  1082. expresssion = expresssion.Replace(returnField, val);
  1083. string title = GetQueryTableTitle(condiDic, returnField);
  1084. checkTitle = checkTitle.Replace(returnField, title);
  1085. }
  1086. DataTable dt = new();
  1087. checkObj = dt.Compute(expresssion, "false").ToString();
  1088. }
  1089. else
  1090. {
  1091. checkObj = GetQueryTableData(condiDic, returnFieldId);
  1092. checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
  1093. }
  1094. logStepDic.Add("标题", checkTitle);
  1095. logStepDic.Add("匹配条件", getQueryKind(fieldQueryKind));
  1096. logStepDic.Add("匹配方式", getQueryModel(fieldQueryModel));
  1097. logStepDic.Add("匹配值", fieldQueryValue);
  1098. logStepDic.Add("实际值", checkObj);
  1099. var checkVal = fieldQueryValue;
  1100. bool passFlag = false;
  1101. if(fieldQueryKind == "1") //模糊匹配
  1102. {
  1103. if(fieldQueryValueType == "text")
  1104. {
  1105. if(checkObj.ToString().Contains(GetExpressionVal(checkVal)))
  1106. {
  1107. passCount += 1; passFlag = true;
  1108. }
  1109. }
  1110. }
  1111. else if(fieldQueryKind == "2") //精确匹配
  1112. {
  1113. if(fieldQueryValueType == "int")
  1114. {
  1115. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal)))
  1116. {
  1117. passCount += 1; passFlag = true;
  1118. }
  1119. }
  1120. else if(fieldQueryValueType == "number")
  1121. {
  1122. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal)))
  1123. {
  1124. passCount += 1; passFlag = true;
  1125. }
  1126. }
  1127. else
  1128. {
  1129. if(checkObj.ToString() == GetExpressionVal(checkVal))
  1130. {
  1131. passCount += 1; passFlag = true;
  1132. }
  1133. }
  1134. }
  1135. else if(fieldQueryKind == "3") //范围匹配
  1136. {
  1137. string[] val = checkVal.Split(':');
  1138. string valLeft = val[0];
  1139. string valRight = val[1];
  1140. if(fieldQueryModel == "request_param")
  1141. {
  1142. Dictionary<string, string> req = getRequestParams(projectId, content);
  1143. if(fieldQueryValueType == "number")
  1144. {
  1145. 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])))
  1146. {
  1147. passCount += 1; passFlag = true;
  1148. }
  1149. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])))
  1150. {
  1151. passCount += 1; passFlag = true;
  1152. }
  1153. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight])))
  1154. {
  1155. passCount += 1; passFlag = true;
  1156. }
  1157. }
  1158. else if(fieldQueryValueType == "int")
  1159. {
  1160. 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])))
  1161. {
  1162. passCount += 1; passFlag = true;
  1163. }
  1164. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])))
  1165. {
  1166. passCount += 1; passFlag = true;
  1167. }
  1168. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight])))
  1169. {
  1170. passCount += 1; passFlag = true;
  1171. }
  1172. }
  1173. else if(fieldQueryValueType.StartsWith("date"))
  1174. {
  1175. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1176. {
  1177. passCount += 1; passFlag = true;
  1178. }
  1179. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]))
  1180. {
  1181. passCount += 1; passFlag = true;
  1182. }
  1183. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1184. {
  1185. passCount += 1; passFlag = true;
  1186. }
  1187. }
  1188. }
  1189. else if(fieldQueryModel == "fixed_value")
  1190. {
  1191. string checkValLeft = valLeft.Replace("#{", "").Replace("}#", "");
  1192. string checkValRight = valRight.Replace("#{", "").Replace("}#", "");
  1193. if(checkValLeft.Contains(",")) checkValLeft = checkValLeft.Split(',')[0];
  1194. if(checkValRight.Contains(",")) checkValRight = checkValRight.Split(',')[0];
  1195. valLeft = GetExpressionVal(valLeft);
  1196. valRight = GetExpressionVal(valRight);
  1197. if(fieldQueryValueType == "number")
  1198. {
  1199. 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)))
  1200. {
  1201. passCount += 1; passFlag = true;
  1202. }
  1203. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1204. {
  1205. passCount += 1; passFlag = true;
  1206. }
  1207. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1208. {
  1209. passCount += 1; passFlag = true;
  1210. }
  1211. }
  1212. else if(fieldQueryValueType == "int")
  1213. {
  1214. 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)))
  1215. {
  1216. passCount += 1; passFlag = true;
  1217. }
  1218. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1219. {
  1220. passCount += 1; passFlag = true;
  1221. }
  1222. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1223. {
  1224. passCount += 1; passFlag = true;
  1225. }
  1226. }
  1227. else if(fieldQueryValueType.StartsWith("date"))
  1228. {
  1229. if(valLeft == "0") valLeft = "";
  1230. if(valRight == "0") valRight = "";
  1231. if(checkObj != "0" && checkObj != "")
  1232. {
  1233. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  1234. {
  1235. passCount += 1; passFlag = true;
  1236. }
  1237. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1238. {
  1239. passCount += 1; passFlag = true;
  1240. }
  1241. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  1242. {
  1243. passCount += 1; passFlag = true;
  1244. }
  1245. }
  1246. }
  1247. }
  1248. else if(fieldQueryModel == "query_field")
  1249. {
  1250. valLeft = GetComputeVal(queryCondiDic, valLeft);
  1251. valRight = GetComputeVal(queryCondiDic, valRight);
  1252. if(fieldQueryValueType == "number")
  1253. {
  1254. 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)))
  1255. {
  1256. passCount += 1; passFlag = true;
  1257. }
  1258. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1259. {
  1260. passCount += 1; passFlag = true;
  1261. }
  1262. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1263. {
  1264. passCount += 1; passFlag = true;
  1265. }
  1266. }
  1267. else if(fieldQueryValueType == "int")
  1268. {
  1269. 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)))
  1270. {
  1271. passCount += 1; passFlag = true;
  1272. }
  1273. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1274. {
  1275. passCount += 1; passFlag = true;
  1276. }
  1277. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1278. {
  1279. passCount += 1; passFlag = true;
  1280. }
  1281. }
  1282. else if(fieldQueryValueType.StartsWith("date"))
  1283. {
  1284. if(valLeft == "0") valLeft = "";
  1285. if(valRight == "0") valRight = "";
  1286. if(checkObj != "0" && checkObj != "")
  1287. {
  1288. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  1289. {
  1290. passCount += 1; passFlag = true;
  1291. }
  1292. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1293. {
  1294. passCount += 1; passFlag = true;
  1295. }
  1296. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(valRight)))
  1297. {
  1298. passCount += 1; passFlag = true;
  1299. }
  1300. }
  1301. }
  1302. }
  1303. }
  1304. else if(fieldQueryKind == "4") //取反匹配
  1305. {
  1306. if(fieldQueryValueType == "int")
  1307. {
  1308. if(int.Parse(checkObj) != int.Parse(Function.CheckInt(checkVal)))
  1309. {
  1310. passCount += 1; passFlag = true;
  1311. }
  1312. }
  1313. else if(fieldQueryValueType == "number")
  1314. {
  1315. if(decimal.Parse(checkObj) != decimal.Parse(Function.CheckNum(checkVal)))
  1316. {
  1317. passCount += 1; passFlag = true;
  1318. }
  1319. }
  1320. else if(fieldQueryValueType == "text")
  1321. {
  1322. if(checkObj.ToString() != GetExpressionVal(checkVal))
  1323. {
  1324. passCount += 1; passFlag = true;
  1325. }
  1326. }
  1327. }
  1328. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1329. {
  1330. string val = ",";
  1331. string[] valList = checkVal.Split(',');
  1332. if(fieldQueryModel == "request_param")
  1333. {
  1334. Dictionary<string, string> req = getRequestParams(projectId, content);
  1335. foreach(string subVal in valList)
  1336. {
  1337. val += req[subVal] + ",";
  1338. }
  1339. }
  1340. else if(fieldQueryModel == "fixed_value")
  1341. {
  1342. foreach(string subVal in valList)
  1343. {
  1344. val += GetExpressionVal(subVal) + ",";
  1345. }
  1346. }
  1347. else if(fieldQueryModel == "db_field")
  1348. {
  1349. foreach(string subVal in valList)
  1350. {
  1351. val += GetDbExpressionVal(subVal) + ",";
  1352. }
  1353. }
  1354. if(fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ","))
  1355. {
  1356. passCount += 1; passFlag = true;
  1357. }
  1358. if(fieldQueryKind == "6" && !val.Contains("," + checkObj.ToString() + ","))
  1359. {
  1360. passCount += 1; passFlag = true;
  1361. }
  1362. }
  1363. logStepDic.Add("状态", passFlag ? "通过" : "未通过");
  1364. logStepDics.Add(logStepDic);
  1365. }
  1366. }
  1367. if(loopSet.conditionMode == "all" && passCount == allCount) prizeFlag = true;
  1368. else if(loopSet.conditionMode == "one" && passCount >= 1) prizeFlag = true;
  1369. else if(loopSet.conditionMode == "two" && passCount >= 2) prizeFlag = true;
  1370. else if(loopSet.conditionMode == "three" && passCount >= 3) prizeFlag = true;
  1371. // else prizeFlag = false;
  1372. }
  1373. // else
  1374. // {
  1375. // prizeFlag = false;
  1376. // }
  1377. }
  1378. loopLog.Add(objId + "匹配情况", logStepDics);
  1379. loopLog.Add("匹配结果", prizeFlag);
  1380. if(prizeFlag)
  1381. {
  1382. decimal prizeAmt = prizeSendDo(projectId, sub, objId, content, loopSet, startData);
  1383. op = afterPrizeFlag;
  1384. }
  1385. }
  1386. loopLogDic.Add(loopLog);
  1387. var parent = db.Ado.GetScalar("select " + parentField + " from " + tableEnName + " where " + sonField + "=" + objId);
  1388. if(parent != null)
  1389. {
  1390. objId = parent.ToString();
  1391. }
  1392. else
  1393. {
  1394. objId = "0";
  1395. }
  1396. index += 1;
  1397. }
  1398. setLogStep(sub.id, "向上递归流程", loopLogDic);
  1399. }
  1400. else
  1401. {
  1402. prizeSendDo(projectId, sub, prizeObjectId, content, new PriLoopSet(), startData);
  1403. }
  1404. }
  1405. static decimal loopAmount = 0;
  1406. public static decimal prizeSendDo(int projectId, PriList sub, string prizeObjectId, string content, PriLoopSet set, Dictionary<string, string> startData)
  1407. {
  1408. var projectService = App.GetService<IPriProjectService>();
  1409. var recordService = App.GetService<IPriRecordService>();
  1410. var conditionService = App.GetService<IPriConditionService>();
  1411. var returnFieldService = App.GetService<IPriReturnFieldService>();
  1412. // var queryTableService = App.GetService<IPriQueryTableService>();
  1413. var amountSetService = App.GetService<IPriListAmountSetService>();
  1414. var project = projectService.GetFirst(m => m.id == projectId) ?? new PriProject();
  1415. //查询匹配条件
  1416. List<QueryCondition> condiDic = condition(sub.id, projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content, startData);
  1417. if(sub.prizeSourceFieldType == "loop") MergeCondiDic(condiDic, loopCondition(projectId, sub, prizeObjectId, content));
  1418. setLogStep(sub.id, "发放奖励查询来源数据", condiDic);
  1419. var prizeSourceField = sub.prizeSourceField; //奖励金额来源字段(对应条件匹配返回字段)
  1420. var prizePercent = sub.prizePercent; //奖励比例
  1421. var prizeAmount = sub.prizeAmount; //奖励固定值
  1422. var prizeContent = sub.prizeContent; //奖励内容
  1423. var conditionMode = sub.conditionMode; //条件模式
  1424. var recursionFlag = sub.recursionFlag; //是否递归
  1425. var prizeCode = sub.prizeCode; //奖励代码
  1426. prizeSourceField = MatchExpressionVal(prizeSourceField);
  1427. bool op = false;
  1428. var groupNos = conditionService.GetList(m => m.listId == sub.id).ToList().Select(m => m.groupNo).Distinct().ToList();
  1429. foreach(var groupNo in groupNos)
  1430. {
  1431. var conditions = conditionService.GetList(m => m.listId == sub.id && m.groupNo == groupNo);
  1432. setLogStep(sub.id, "发放奖励匹配条件", condiDic);
  1433. int allCount = conditions.Count; //所有奖励条件数
  1434. int passCount = 0; //通过条件数
  1435. List<Dictionary<string, object>> logStepDics = new();
  1436. foreach(var condition in conditions)
  1437. {
  1438. Dictionary<string, object> logStepDic = new();
  1439. var returnFieldId = condition.returnFieldId; //条件返回字段
  1440. returnFieldId = MatchExpressionVal(returnFieldId);
  1441. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  1442. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  1443. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  1444. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  1445. string checkObj = "";
  1446. string checkTitle = "";
  1447. if(returnFieldId.Contains(","))
  1448. {
  1449. string[] returnFieldIdList = returnFieldId.Split(',');
  1450. foreach(string subField in returnFieldIdList)
  1451. {
  1452. string val = GetQueryTableData(condiDic, subField);
  1453. checkObj += val + ",";
  1454. string title = GetQueryTableTitle(condiDic, subField);
  1455. checkTitle += title + ",";
  1456. }
  1457. checkObj = checkObj.TrimEnd(',');
  1458. checkTitle = checkTitle.TrimEnd(',');
  1459. }
  1460. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  1461. {
  1462. string expresssion = returnFieldId;
  1463. checkTitle = returnFieldId;
  1464. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  1465. foreach(string returnField in returnFields)
  1466. {
  1467. string val = GetQueryTableData(condiDic, returnField);
  1468. expresssion = expresssion.Replace(returnField, val);
  1469. string title = GetQueryTableTitle(condiDic, returnField);
  1470. checkTitle = checkTitle.Replace(returnField, title);
  1471. }
  1472. DataTable dt = new();
  1473. checkObj = dt.Compute(expresssion, "false").ToString();
  1474. }
  1475. else
  1476. {
  1477. checkObj = GetQueryTableData(condiDic, returnFieldId);
  1478. checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
  1479. }
  1480. // if(!sub.recursionFlag)
  1481. // {
  1482. logStepDic.Add("标题", checkTitle);
  1483. logStepDic.Add("匹配条件", getQueryKind(fieldQueryKind));
  1484. logStepDic.Add("匹配方式", getQueryModel(fieldQueryModel));
  1485. logStepDic.Add("匹配值", fieldQueryValue);
  1486. logStepDic.Add("实际值", checkObj);
  1487. // }
  1488. string checkVal = fieldQueryValue;
  1489. bool passFlag = false;
  1490. if(fieldQueryKind == "1") //模糊匹配
  1491. {
  1492. if(fieldQueryValueType == "text")
  1493. {
  1494. if(checkObj.ToString().Contains(GetExpressionVal(checkVal)))
  1495. {
  1496. passCount += 1; passFlag = true;
  1497. }
  1498. }
  1499. }
  1500. else if(fieldQueryKind == "2") //精确匹配
  1501. {
  1502. if(fieldQueryValueType == "int")
  1503. {
  1504. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal)))
  1505. {
  1506. passCount += 1; passFlag = true;
  1507. }
  1508. }
  1509. else if(fieldQueryValueType == "number")
  1510. {
  1511. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal)))
  1512. {
  1513. passCount += 1; passFlag = true;
  1514. }
  1515. }
  1516. else
  1517. {
  1518. if(checkObj.ToString() == GetExpressionVal(checkVal))
  1519. {
  1520. passCount += 1; passFlag = true;
  1521. }
  1522. }
  1523. }
  1524. else if(fieldQueryKind == "3") //范围匹配
  1525. {
  1526. string[] val = checkVal.Split(':');
  1527. string valLeft = val[0];
  1528. string valRight = val[1];
  1529. if(fieldQueryModel == "request_param")
  1530. {
  1531. Dictionary<string, string> req = getRequestParams(projectId, content);
  1532. if(fieldQueryValueType == "number")
  1533. {
  1534. 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])))
  1535. {
  1536. passCount += 1; passFlag = true;
  1537. }
  1538. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])))
  1539. {
  1540. passCount += 1; passFlag = true;
  1541. }
  1542. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[valRight])))
  1543. {
  1544. passCount += 1; passFlag = true;
  1545. }
  1546. }
  1547. else if(fieldQueryValueType == "int")
  1548. {
  1549. 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])))
  1550. {
  1551. passCount += 1; passFlag = true;
  1552. }
  1553. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])))
  1554. {
  1555. passCount += 1; passFlag = true;
  1556. }
  1557. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[valRight])))
  1558. {
  1559. passCount += 1; passFlag = true;
  1560. }
  1561. }
  1562. else if(fieldQueryValueType.StartsWith("date"))
  1563. {
  1564. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1565. {
  1566. passCount += 1; passFlag = true;
  1567. }
  1568. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]))
  1569. {
  1570. passCount += 1; passFlag = true;
  1571. }
  1572. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1573. {
  1574. passCount += 1; passFlag = true;
  1575. }
  1576. }
  1577. }
  1578. else if(fieldQueryModel == "fixed_value")
  1579. {
  1580. valLeft = GetExpressionVal(valLeft);
  1581. valRight = GetExpressionVal(valRight);
  1582. if(fieldQueryValueType == "number")
  1583. {
  1584. 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)))
  1585. {
  1586. passCount += 1; passFlag = true;
  1587. }
  1588. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1589. {
  1590. passCount += 1; passFlag = true;
  1591. }
  1592. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1593. {
  1594. passCount += 1; passFlag = true;
  1595. }
  1596. }
  1597. else if(fieldQueryValueType == "int")
  1598. {
  1599. 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)))
  1600. {
  1601. passCount += 1; passFlag = true;
  1602. }
  1603. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1604. {
  1605. passCount += 1; passFlag = true;
  1606. }
  1607. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1608. {
  1609. passCount += 1; passFlag = true;
  1610. }
  1611. }
  1612. else if(fieldQueryValueType.StartsWith("date"))
  1613. {
  1614. if(valLeft == "0") valLeft = "";
  1615. if(valRight == "0") valRight = "";
  1616. if(checkObj != "0" && checkObj != "")
  1617. {
  1618. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1619. {
  1620. passCount += 1; passFlag = true;
  1621. }
  1622. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1623. {
  1624. passCount += 1; passFlag = true;
  1625. }
  1626. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1627. {
  1628. passCount += 1; passFlag = true;
  1629. }
  1630. }
  1631. }
  1632. }
  1633. else if(fieldQueryModel == "query_field")
  1634. {
  1635. string checkValLeft = valLeft.Replace("#{", "").Replace("}#", "");
  1636. string checkValRight = valRight.Replace("#{", "").Replace("}#", "");
  1637. if(checkValLeft.Contains(",")) checkValLeft = checkValLeft.Split(',')[0];
  1638. if(checkValRight.Contains(",")) checkValRight = checkValRight.Split(',')[0];
  1639. if(!string.IsNullOrEmpty(valLeft)) valLeft = valLeft.Replace(checkValLeft, GetQueryTableData(condiDic, checkValLeft));
  1640. if(!string.IsNullOrEmpty(valRight)) valRight = valRight.Replace(checkValRight, GetQueryTableData(condiDic, checkValRight));
  1641. valLeft = GetExpressionVal(valLeft);
  1642. valRight = GetExpressionVal(valRight);
  1643. if(fieldQueryValueType == "number")
  1644. {
  1645. 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)))
  1646. {
  1647. passCount += 1; passFlag = true;
  1648. }
  1649. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  1650. {
  1651. passCount += 1; passFlag = true;
  1652. }
  1653. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(valRight)))
  1654. {
  1655. passCount += 1; passFlag = true;
  1656. }
  1657. }
  1658. else if(fieldQueryValueType == "int")
  1659. {
  1660. 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)))
  1661. {
  1662. passCount += 1; passFlag = true;
  1663. }
  1664. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  1665. {
  1666. passCount += 1; passFlag = true;
  1667. }
  1668. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(valRight)))
  1669. {
  1670. passCount += 1; passFlag = true;
  1671. }
  1672. }
  1673. else if(fieldQueryValueType.StartsWith("date"))
  1674. {
  1675. if(valLeft == "0") valLeft = "";
  1676. if(valRight == "0") valRight = "";
  1677. if(checkObj != "0" && checkObj != "")
  1678. {
  1679. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1680. {
  1681. passCount += 1; passFlag = true;
  1682. }
  1683. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1684. {
  1685. passCount += 1; passFlag = true;
  1686. }
  1687. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1688. {
  1689. passCount += 1; passFlag = true;
  1690. }
  1691. }
  1692. }
  1693. }
  1694. }
  1695. else if(fieldQueryKind == "4") //取反匹配
  1696. {
  1697. if(fieldQueryValueType == "int")
  1698. {
  1699. if(int.Parse(Function.CheckNum(checkObj.ToString())) != int.Parse(Function.CheckInt(checkVal)))
  1700. {
  1701. passCount += 1; passFlag = true;
  1702. }
  1703. }
  1704. else if(fieldQueryValueType == "number")
  1705. {
  1706. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) != decimal.Parse(Function.CheckNum(checkVal)))
  1707. {
  1708. passCount += 1; passFlag = true;
  1709. }
  1710. }
  1711. else if(fieldQueryValueType == "text")
  1712. {
  1713. if(checkObj.ToString() != GetExpressionVal(checkVal))
  1714. {
  1715. passCount += 1; passFlag = true;
  1716. }
  1717. }
  1718. }
  1719. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1720. {
  1721. string val = ",";
  1722. string[] valList = checkVal.Split(',');
  1723. if(fieldQueryModel == "request_param")
  1724. {
  1725. Dictionary<string, string> req = getRequestParams(projectId, content);
  1726. foreach(string subVal in valList)
  1727. {
  1728. val += req[subVal] + ",";
  1729. }
  1730. }
  1731. else if(fieldQueryModel == "fixed_value")
  1732. {
  1733. foreach(string subVal in valList)
  1734. {
  1735. val += GetExpressionVal(subVal) + ",";
  1736. }
  1737. }
  1738. else if(fieldQueryModel == "db_field")
  1739. {
  1740. foreach(string subVal in valList)
  1741. {
  1742. val += GetDbExpressionVal(subVal) + ",";
  1743. }
  1744. }
  1745. if (fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ","))
  1746. {
  1747. passCount += 1; passFlag = true;
  1748. }
  1749. if(fieldQueryKind == "6" && !val.Contains("," + checkObj.ToString() + ","))
  1750. {
  1751. passCount += 1; passFlag = true;
  1752. }
  1753. }
  1754. // if(!sub.recursionFlag)
  1755. // {
  1756. logStepDic.Add("状态", passFlag ? "通过" : "未通过");
  1757. logStepDics.Add(logStepDic);
  1758. // }
  1759. }
  1760. setLogStep(sub.id, "匹配结果", logStepDics);
  1761. if(conditionMode == "all" && passCount == allCount && passCount > 0) op = true;
  1762. else if(conditionMode == "one" && passCount >= 1) op = true;
  1763. else if(conditionMode == "two" && passCount >= 2) op = true;
  1764. else if(conditionMode == "three" && passCount >= 3) op = true;
  1765. }
  1766. decimal prizeAmt = 0;
  1767. setLogStep(sub.id, "是否通过", op ? "是" : "否");
  1768. if(op) //满足条件
  1769. {
  1770. bool repeatFlag = sub.repeatFlag;
  1771. decimal number = 0;
  1772. if(prizeSourceField.Contains("/"))
  1773. {
  1774. number = decimal.Parse(prizeSourceField.Split('/')[1]);
  1775. prizeSourceField = prizeSourceField.Split('/')[0];
  1776. }
  1777. string prizeSourceData = "";
  1778. if(prizeSourceField.Contains(","))
  1779. {
  1780. string[] prizeSourceFieldList = prizeSourceField.Split(',');
  1781. foreach(string subField in prizeSourceFieldList)
  1782. {
  1783. string val = GetQueryTableData(condiDic, subField);
  1784. prizeSourceData += val + ",";
  1785. }
  1786. prizeSourceData = prizeSourceData.TrimEnd(',');
  1787. }
  1788. else
  1789. {
  1790. prizeSourceData = GetQueryTableData(condiDic, prizeSourceField);
  1791. }
  1792. if(string.IsNullOrEmpty(prizeSourceData)) prizeSourceData = "0";
  1793. if(prizeSourceField.Contains("/") && number > 0)
  1794. {
  1795. decimal prizeSourceDataNum = decimal.Parse(prizeSourceData) / number;
  1796. prizeSourceData = prizeSourceDataNum.ToString("f2");
  1797. }
  1798. var amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField == prizeSourceData);
  1799. if(amountSet != null)
  1800. {
  1801. prizePercent = amountSet.prizePercent;
  1802. prizeAmount = amountSet.prizeAmount;
  1803. prizeCode = amountSet.prizeCode;
  1804. repeatFlag = amountSet.repeatFlag;
  1805. }
  1806. if(prizeSourceData.Contains(","))
  1807. {
  1808. string checkField = prizeSourceData.Split(',')[0] + ",";
  1809. amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField.StartsWith(checkField) && m.prizeSourceField.EndsWith(",%"));
  1810. if(amountSet != null)
  1811. {
  1812. prizePercent = amountSet.prizePercent;
  1813. prizeAmount = amountSet.prizeAmount;
  1814. prizeCode = amountSet.prizeCode;
  1815. repeatFlag = amountSet.repeatFlag;
  1816. prizeSourceData = prizeSourceData.Split(',')[1];
  1817. }
  1818. }
  1819. if(prizePercent > 0) prizeAmt += decimal.Parse(Function.CheckNum(prizeSourceData)) * prizePercent;
  1820. if(prizeAmount > 0) prizeAmt += prizeAmount;
  1821. decimal getPrizeAmount = prizeAmt;
  1822. if(set.levelDiffFlag) prizeAmt -= loopAmount;
  1823. setLogStep(sub.id, "发放金额", prizeAmt);
  1824. if(prizeAmt > 0)
  1825. {
  1826. prizeAmt = Util.PublicFunction.NumberFormat(prizeAmt);
  1827. setLogPrizeAmount(sub.id, prizeAmt);
  1828. var req = getRequestParams(projectId, content);
  1829. var requestParamField = req[sub.requestParamField];
  1830. var sendFlag = false;
  1831. if(!repeatFlag) sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.prizeCode == prizeCode && m.requestParamField == content);
  1832. if(!sendFlag)
  1833. {
  1834. PriRecord item = new PriRecord()
  1835. {
  1836. createDate = DateTime.Now,
  1837. projectId = projectId,
  1838. listId = sub.id,
  1839. prizeAmount = prizeAmt,
  1840. prizeCode = prizeCode,
  1841. prizeObjId = prizeObjectId,
  1842. requestParamField = content,
  1843. batchNo = batchNo,
  1844. };
  1845. recordService.Add(item);
  1846. Dictionary<string, object> prizeItem = new Dictionary<string, object>();
  1847. prizeItem.Add("prize_date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1848. prizeItem.Add("prize_name", sub.prizeName);
  1849. prizeItem.Add("prize_code", prizeCode);
  1850. prizeItem.Add("batch_no", batchNo);
  1851. prizeItem.Add("request_param_field", content);
  1852. List<Dictionary<string, object>> prizeItemList = new List<Dictionary<string, object>>();
  1853. Dictionary<string, object> prizeItemSub = new Dictionary<string, object>();
  1854. prizeItemSub.Add("prize_amount", prizeAmt);
  1855. prizeItemSub.Add("prize_obj", prizeObjectId);
  1856. prizeItemList.Add(prizeItemSub);
  1857. prizeItem.Add("prize_list", prizeItemList);
  1858. string prizeOutContent = Newtonsoft.Json.JsonConvert.SerializeObject(prizeItem);
  1859. setLogFieldValue(sub.id, "prizeOutContent", prizeOutContent);
  1860. setLogFieldValue(sub.id, "prizeOutUrl", project.noticeUrl);
  1861. loopAmount = getPrizeAmount;
  1862. if(project.requestMode == "http" && !string.IsNullOrEmpty(project.noticeUrl))
  1863. {
  1864. int status = -1;
  1865. string noticeJson = Function.PostWebRequest(project.noticeUrl, prizeOutContent, "application/json");
  1866. Function.WriteLog(noticeJson, "通知返回报文");
  1867. JsonData jsonObj = JsonMapper.ToObject(noticeJson);
  1868. if(jsonObj["status"].ToString() == "1")
  1869. {
  1870. status = 1;
  1871. }
  1872. Function.WriteLog(status.ToString(), "通知返回报文");
  1873. var sendItem = recordService.GetFirst(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == content);
  1874. if(sendItem != null)
  1875. {
  1876. Function.WriteLog("in", "通知返回报文");
  1877. sendItem.status = status;
  1878. recordService.Update(sendItem);
  1879. Function.WriteLog("end", "通知返回报文");
  1880. }
  1881. }
  1882. else if(project.requestMode == "mq")
  1883. {}
  1884. else if(project.requestMode == "db")
  1885. {
  1886. prizeToDatabase(projectId, sub.id, content, condiDic, prizeAmt, startData); //入库
  1887. }
  1888. }
  1889. }
  1890. }
  1891. // if(!sub.recursionFlag)
  1892. // {
  1893. setLogStatus(sub.id, op ? 1 : 0);
  1894. // }
  1895. return prizeAmt;
  1896. }
  1897. //递归条件判断
  1898. public static List<QueryCondition> loopCondition(int projectId, PriList sub, string objId, string content)
  1899. {
  1900. List<QueryCondition> dic = new();
  1901. var queryTableService = App.GetService<IPriRecursionStartTableService>();
  1902. var queryFieldService = App.GetService<IPriRecursionStartFieldService>();
  1903. var queryReturnFieldService = App.GetService<IPriRecursionStartReturnFieldService>();
  1904. int passCount = 0;
  1905. //查询表
  1906. var queryTables = queryTableService.GetList(m => m.listId == sub.id);
  1907. int allCount = queryTables.Count;
  1908. foreach(var queryTable in queryTables)
  1909. {
  1910. //查询返回字段
  1911. string fields = "1";
  1912. string tableEnName = queryTable.tableEnName;
  1913. if(tableEnName.Contains("#{")) tableEnName = MatchExpressionVal(tableEnName);
  1914. Dictionary<string, string> fieldDic = new();
  1915. var returnFields = queryReturnFieldService.GetList(m => m.objectTableId == queryTable.id);
  1916. if(returnFields.Count > 0)
  1917. {
  1918. fields = "";
  1919. foreach(var returnField in returnFields)
  1920. {
  1921. string aliasName = returnField.fieldAliasName;
  1922. if(string.IsNullOrEmpty(aliasName)) aliasName = tableEnName + "_" + returnField.fieldEnName;
  1923. if(returnField.fieldReturnKind == "2")
  1924. {
  1925. fields += "count(" + returnField.fieldEnName + ") " + aliasName + ",";
  1926. }
  1927. else if(returnField.fieldReturnKind == "3")
  1928. {
  1929. fields += "sum(" + returnField.fieldEnName + ") " + aliasName + ",";
  1930. }
  1931. else if(returnField.fieldReturnKind == "4")
  1932. {
  1933. fields += "avg(" + returnField.fieldEnName + ") " + aliasName + ",";
  1934. }
  1935. else if(returnField.fieldReturnKind == "5")
  1936. {
  1937. fields += "max(" + returnField.fieldEnName + ") " + aliasName + ",";
  1938. }
  1939. else if(returnField.fieldReturnKind == "6")
  1940. {
  1941. fields += "min(" + returnField.fieldEnName + ") " + aliasName + ",";
  1942. }
  1943. else
  1944. {
  1945. fields += returnField.fieldEnName + " " + aliasName + ",";
  1946. }
  1947. fieldDic.Add(aliasName, returnField.fieldName);
  1948. }
  1949. fields = fields.TrimEnd(',');
  1950. }
  1951. //查询匹配条件
  1952. string condi = "";
  1953. var queryFields = queryFieldService.GetList(m => m.objectTableId == queryTable.id);
  1954. foreach(var queryField in queryFields)
  1955. {
  1956. string fieldEnName = queryField.fieldEnName;
  1957. string fieldQueryKind = queryField.fieldQueryKind;
  1958. string fieldQueryModel = queryField.fieldQueryModel;
  1959. string fieldQueryValue = queryField.fieldQueryValue;
  1960. if(fieldQueryModel == "loop_field") fieldQueryValue = objId;
  1961. string fieldQueryValueType = queryField.fieldQueryValueType;
  1962. if(fieldQueryKind == "1") //模糊匹配
  1963. {
  1964. condi += " and " + fieldEnName + " like ";
  1965. if(fieldQueryModel == "request_param")
  1966. {
  1967. Dictionary<string, string> req = getRequestParams(projectId, content);
  1968. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1969. condi += "'%" + val + "%'";
  1970. }
  1971. else if(fieldQueryModel == "fixed_value")
  1972. {
  1973. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  1974. }
  1975. else if(fieldQueryModel == "db_field")
  1976. {
  1977. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  1978. }
  1979. }
  1980. else if(fieldQueryKind == "2") //精确匹配
  1981. {
  1982. condi += " and " + fieldEnName + "=";
  1983. string val = fieldQueryValue;
  1984. if(fieldQueryModel == "request_param")
  1985. {
  1986. Dictionary<string, string> req = getRequestParams(projectId, content);
  1987. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1988. }
  1989. else if(fieldQueryModel == "fixed_value")
  1990. {
  1991. val = GetExpressionVal(fieldQueryValue);
  1992. }
  1993. else if(fieldQueryModel == "db_field")
  1994. {
  1995. val = GetDbExpressionVal(fieldQueryValue);
  1996. }
  1997. if(fieldQueryValueType == "text")
  1998. {
  1999. val = "'" + val + "'";
  2000. }
  2001. condi += val;
  2002. }
  2003. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  2004. {
  2005. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  2006. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  2007. string val = "";
  2008. string[] valList = fieldQueryValue.Split(',');
  2009. if(fieldQueryModel == "request_param")
  2010. {
  2011. Dictionary<string, string> req = getRequestParams(projectId, content);
  2012. foreach(string subval in valList)
  2013. {
  2014. if(fieldQueryValueType == "text")
  2015. {
  2016. val += "'" + req[subval] + "',";
  2017. }
  2018. else
  2019. {
  2020. val += req[subval] + ",";
  2021. }
  2022. }
  2023. }
  2024. else if(fieldQueryModel == "fixed_value")
  2025. {
  2026. foreach(string subval in valList)
  2027. {
  2028. if(fieldQueryValueType == "text")
  2029. {
  2030. val += "'" + GetExpressionVal(subval) + "',";
  2031. }
  2032. else
  2033. {
  2034. val += GetExpressionVal(subval) + ",";
  2035. }
  2036. }
  2037. }
  2038. else if(fieldQueryModel == "db_field")
  2039. {
  2040. foreach(string subval in valList)
  2041. {
  2042. if(fieldQueryValueType == "text")
  2043. {
  2044. val += "'" + GetDbExpressionVal(subval) + "',";
  2045. }
  2046. else
  2047. {
  2048. val += GetDbExpressionVal(subval) + ",";
  2049. }
  2050. }
  2051. }
  2052. val = val.TrimEnd(',');
  2053. condi += val + ")";
  2054. }
  2055. else if(fieldQueryKind == "3") //范围匹配
  2056. {
  2057. string[] val = fieldQueryValue.Split(':');
  2058. if(fieldQueryModel == "request_param")
  2059. {
  2060. Dictionary<string, string> req = getRequestParams(projectId, content);
  2061. if(fieldQueryValueType == "number")
  2062. {
  2063. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  2064. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  2065. }
  2066. else
  2067. {
  2068. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  2069. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  2070. }
  2071. }
  2072. else if(fieldQueryModel == "fixed_value")
  2073. {
  2074. if(fieldQueryValueType == "number")
  2075. {
  2076. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  2077. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  2078. }
  2079. else
  2080. {
  2081. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  2082. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  2083. }
  2084. }
  2085. else if(fieldQueryModel == "db_field")
  2086. {
  2087. if(fieldQueryValueType == "number")
  2088. {
  2089. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  2090. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  2091. }
  2092. else
  2093. {
  2094. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  2095. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  2096. }
  2097. }
  2098. }
  2099. else if(fieldQueryKind == "4") //取反匹配
  2100. {
  2101. condi += " and " + fieldEnName + "!=";
  2102. string val = "";
  2103. if(fieldQueryModel == "request_param")
  2104. {
  2105. Dictionary<string, string> req = getRequestParams(projectId, content);
  2106. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2107. }
  2108. else if(fieldQueryModel == "fixed_value")
  2109. {
  2110. val = GetExpressionVal(fieldQueryValue);
  2111. }
  2112. else if(fieldQueryModel == "db_field")
  2113. {
  2114. val = GetDbExpressionVal(fieldQueryValue);
  2115. }
  2116. if(fieldQueryValueType == "text")
  2117. {
  2118. val = "'" + val + "'";
  2119. }
  2120. condi += val;
  2121. }
  2122. }
  2123. var db = initDb(queryTable.databaseId);
  2124. string sql = "select " + fields + " from " + tableEnName + " where 1=1" + condi;
  2125. if(!string.IsNullOrEmpty(queryTable.orderBy))
  2126. {
  2127. sql += " order by " + queryTable.orderBy;
  2128. }
  2129. sql += " limit 1";
  2130. var items = db.Ado.GetDataTable(sql);
  2131. if(items.Rows.Count > 0)
  2132. {
  2133. foreach(string field in fieldDic.Keys)
  2134. {
  2135. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  2136. {
  2137. FieldName = fieldDic[field],
  2138. FieldEnName = field,
  2139. Value = items.Rows[0][field].ToString()
  2140. });
  2141. }
  2142. }
  2143. }
  2144. return dic;
  2145. }
  2146. //奖励入库
  2147. public static void prizeToDatabase(int projectId, int listId, string content, List<QueryCondition> condiDic, decimal prize_amt, Dictionary<string, string> startData)
  2148. {
  2149. var prizeInTableService = App.GetService<IPriPrizeInTableService>();
  2150. var prizeInFieldService = App.GetService<IPriPrizeInFieldService>();
  2151. var prizeInQueryFieldService = App.GetService<IPriPrizeInQueryFieldService>();
  2152. //入库表
  2153. var prizeInTables = prizeInTableService.GetList(m => m.listId == listId);
  2154. foreach(var prizeInTable in prizeInTables)
  2155. {
  2156. var db = initDb(prizeInTable.databaseId);
  2157. Dictionary<string, object> doFields = new();
  2158. List<string> inFields = new();
  2159. //入库字段
  2160. var prizeInFields = prizeInFieldService.GetList(m => m.inTableId == prizeInTable.id);
  2161. foreach(var prizeInField in prizeInFields)
  2162. {
  2163. string fieldEnName = prizeInField.fieldEnName;
  2164. string fieldQueryModel = prizeInField.fieldQueryModel;
  2165. string fieldQueryValue = prizeInField.fieldQueryValue;
  2166. string fieldQueryValueType = prizeInField.fieldQueryValueType;
  2167. if(fieldQueryModel == "request_param")
  2168. {
  2169. Dictionary<string, string> req = getRequestParams(projectId, content);
  2170. fieldQueryValue = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2171. }
  2172. else if(fieldQueryModel == "query_field")
  2173. {
  2174. fieldQueryValue = GetQueryTableData(condiDic, fieldQueryValue);
  2175. }
  2176. else if(fieldQueryModel == "querystart_list_field")
  2177. {
  2178. fieldQueryValue = GetStartData(startData, fieldQueryValue);
  2179. }
  2180. else if(fieldQueryModel == "query_all_field")
  2181. {
  2182. if (fieldQueryValue.Contains("+") || fieldQueryValue.Contains("-") || fieldQueryValue.Contains("*") || fieldQueryValue.Contains("/") || fieldQueryValue.Contains("(") || fieldQueryValue.Contains(")"))
  2183. {
  2184. string[] texts = fieldQueryValue.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  2185. foreach (string text in texts)
  2186. {
  2187. string val = GetStartData(startData, text);
  2188. if(string.IsNullOrEmpty(val)) val = GetQueryTableData(condiDic, text);
  2189. fieldQueryValue = fieldQueryValue.Replace(text, val);
  2190. }
  2191. DataTable dt = new();
  2192. fieldQueryValue = dt.Compute(fieldQueryValue, "false").ToString();
  2193. }
  2194. else
  2195. {
  2196. string val = GetStartData(startData, fieldQueryValue);
  2197. if(string.IsNullOrEmpty(val)) val = GetQueryTableData(condiDic, fieldQueryValue);
  2198. fieldQueryValue = val;
  2199. }
  2200. }
  2201. else if(fieldQueryModel == "fixed_value")
  2202. {
  2203. fieldQueryValue = GetExpressionVal(fieldQueryValue);
  2204. }
  2205. else if(fieldQueryModel == "db_field")
  2206. {
  2207. fieldQueryValue = GetDbExpressionVal(fieldQueryValue);
  2208. }
  2209. else if(fieldQueryModel == "prize_amt")
  2210. {
  2211. fieldQueryValue = prize_amt.ToString();
  2212. }
  2213. if(fieldQueryValueType == "text") doFields.Add(fieldEnName, fieldQueryValue);
  2214. if(fieldQueryValueType == "int") doFields.Add(fieldEnName, int.Parse(fieldQueryValue));
  2215. if(fieldQueryValueType == "number") doFields.Add(fieldEnName, decimal.Parse(fieldQueryValue));
  2216. if(fieldQueryValueType == "datetime") doFields.Add(fieldEnName, DateTime.Parse(fieldQueryValue));
  2217. if(fieldQueryValueType == "bool") doFields.Add(fieldEnName, bool.Parse(fieldQueryValue));
  2218. inFields.Add(fieldEnName + "#cut#" + fieldQueryValue + "#cut#" + fieldQueryValueType + "#cut#" + prizeInField.fieldInModel);
  2219. }
  2220. //查询匹配条件
  2221. string condi = "";
  2222. var queryFields = prizeInQueryFieldService.GetList(m => m.inTableId == prizeInTable.id);
  2223. foreach(var queryField in queryFields)
  2224. {
  2225. string fieldEnName = queryField.fieldEnName;
  2226. string fieldQueryKind = queryField.fieldQueryKind;
  2227. string fieldQueryModel = queryField.fieldQueryModel;
  2228. string fieldQueryValue = queryField.fieldQueryValue;
  2229. string fieldQueryValueType = queryField.fieldQueryValueType;
  2230. if(fieldQueryKind == "1") //模糊匹配
  2231. {
  2232. condi += " and " + fieldEnName + " like ";
  2233. if(fieldQueryModel == "request_param")
  2234. {
  2235. Dictionary<string, string> req = getRequestParams(projectId, content);
  2236. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2237. condi += "'%" + val + "%'";
  2238. }
  2239. else if(fieldQueryModel == "fixed_value")
  2240. {
  2241. condi += "'%" + fieldQueryValue + "%'";
  2242. }
  2243. else if(fieldQueryModel == "query_field")
  2244. {
  2245. condi += "'%" + GetQueryTableData(condiDic, fieldQueryValue) + "%'";
  2246. }
  2247. else if(fieldQueryModel == "querystart_list_field")
  2248. {
  2249. condi += "'%" + GetStartData(startData, fieldQueryValue) + "%'";
  2250. }
  2251. }
  2252. else if(fieldQueryKind == "2") //精确匹配
  2253. {
  2254. condi += " and " + fieldEnName + "=";
  2255. string val = "";
  2256. if(fieldQueryModel == "request_param")
  2257. {
  2258. Dictionary<string, string> req = getRequestParams(projectId, content);
  2259. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2260. }
  2261. else if(fieldQueryModel == "fixed_value")
  2262. {
  2263. val = fieldQueryValue;
  2264. }
  2265. else if(fieldQueryModel == "query_field")
  2266. {
  2267. val = GetQueryTableData(condiDic, fieldQueryValue);
  2268. }
  2269. else if(fieldQueryModel == "querystart_list_field")
  2270. {
  2271. val = GetStartData(startData, fieldQueryValue);
  2272. }
  2273. if(fieldQueryValueType == "text")
  2274. {
  2275. val = "'" + val + "'";
  2276. }
  2277. condi += val;
  2278. }
  2279. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  2280. {
  2281. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  2282. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  2283. string val = "";
  2284. string[] valList = fieldQueryValue.Split(',');
  2285. if(fieldQueryModel == "request_param")
  2286. {
  2287. Dictionary<string, string> req = getRequestParams(projectId, content);
  2288. foreach(string sub in valList)
  2289. {
  2290. if(fieldQueryValueType == "text")
  2291. {
  2292. val += "'" + req[sub] + "',";
  2293. }
  2294. else
  2295. {
  2296. val += req[sub] + ",";
  2297. }
  2298. }
  2299. }
  2300. else if(fieldQueryModel == "fixed_value")
  2301. {
  2302. foreach(string sub in valList)
  2303. {
  2304. if(fieldQueryValueType == "text")
  2305. {
  2306. val += "'" + GetExpressionVal(sub) + "',";
  2307. }
  2308. else
  2309. {
  2310. val += GetExpressionVal(sub) + ",";
  2311. }
  2312. }
  2313. }
  2314. else if(fieldQueryModel == "query_field")
  2315. {
  2316. foreach(string sub in valList)
  2317. {
  2318. if(fieldQueryValueType == "text")
  2319. {
  2320. val += "'" + GetQueryTableData(condiDic, sub) + "',";
  2321. }
  2322. else
  2323. {
  2324. val += GetQueryTableData(condiDic, sub) + ",";
  2325. }
  2326. }
  2327. }
  2328. else if(fieldQueryModel == "querystart_list_field")
  2329. {
  2330. foreach(string sub in valList)
  2331. {
  2332. if(fieldQueryValueType == "text")
  2333. {
  2334. val += "'" + GetStartData(startData, sub) + "',";
  2335. }
  2336. else
  2337. {
  2338. val += GetStartData(startData, sub) + ",";
  2339. }
  2340. }
  2341. }
  2342. else if(fieldQueryModel == "db_field")
  2343. {
  2344. foreach(string sub in valList)
  2345. {
  2346. if(fieldQueryValueType == "text")
  2347. {
  2348. val += "'" + GetDbExpressionVal(sub) + "',";
  2349. }
  2350. else
  2351. {
  2352. val += GetDbExpressionVal(sub) + ",";
  2353. }
  2354. }
  2355. }
  2356. val = val.TrimEnd(',');
  2357. condi += val + ")";
  2358. }
  2359. else if(fieldQueryKind == "3") //范围匹配
  2360. {
  2361. string[] val = fieldQueryValue.Split(':');
  2362. if(fieldQueryModel == "request_param")
  2363. {
  2364. Dictionary<string, string> req = getRequestParams(projectId, content);
  2365. if(fieldQueryValueType == "number")
  2366. {
  2367. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  2368. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  2369. }
  2370. else
  2371. {
  2372. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  2373. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  2374. }
  2375. }
  2376. else if(fieldQueryModel == "fixed_value")
  2377. {
  2378. if(fieldQueryValueType == "number")
  2379. {
  2380. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  2381. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  2382. }
  2383. else
  2384. {
  2385. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + val[0] + "'";
  2386. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + val[1] + "'";
  2387. }
  2388. }
  2389. }
  2390. else if(fieldQueryKind == "4") //取反匹配
  2391. {
  2392. condi += " and " + fieldEnName + "!=";
  2393. string val = "";
  2394. if(fieldQueryModel == "request_param")
  2395. {
  2396. Dictionary<string, string> req = getRequestParams(projectId, content);
  2397. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  2398. }
  2399. else if(fieldQueryModel == "fixed_value")
  2400. {
  2401. val = fieldQueryValue;
  2402. }
  2403. if(fieldQueryValueType == "text")
  2404. {
  2405. val = "'" + val + "'";
  2406. }
  2407. condi += val;
  2408. }
  2409. }
  2410. if(prizeInTable.excuteKind == "add") db.Insertable(doFields).AS(prizeInTable.tableEnName).ExecuteCommand();
  2411. if(prizeInTable.excuteKind == "update") db.Updateable(doFields).AS(prizeInTable.tableEnName).Where("1=1" + condi).ExecuteCommand();
  2412. if(prizeInTable.excuteKind == "update_or_add")
  2413. {
  2414. string doSql = "";
  2415. var check = db.Ado.GetDataTable("select 1 from " + prizeInTable.tableEnName + " where 1=1" + condi);
  2416. if(check.Rows.Count > 0)
  2417. {
  2418. string fieldString = "";
  2419. foreach(var inField in inFields)
  2420. {
  2421. string[] inFieldData = inField.Split(new string[]{ "#cut#" }, StringSplitOptions.None);
  2422. string fieldEnName = inFieldData[0];
  2423. string fieldQueryValue = inFieldData[1];
  2424. string fieldQueryValueType = inFieldData[2];
  2425. string fieldInModel = inFieldData[3];
  2426. if(fieldQueryValueType == "int" || fieldQueryValueType == "number" || fieldQueryValueType == "bool")
  2427. {
  2428. if(fieldInModel == "add")
  2429. {
  2430. fieldString += fieldEnName + "=" + fieldEnName + "+" + fieldQueryValue;
  2431. }
  2432. else
  2433. {
  2434. fieldString += fieldEnName + "=" + fieldQueryValue;
  2435. }
  2436. }
  2437. else
  2438. {
  2439. if(fieldInModel == "add")
  2440. {
  2441. fieldString += fieldEnName + "=" + "concat(" + fieldEnName + ", '" + fieldQueryValue + "')";
  2442. }
  2443. else
  2444. {
  2445. fieldString += fieldEnName + "=" + "'" + fieldQueryValue + "'";
  2446. }
  2447. }
  2448. fieldString += ",";
  2449. }
  2450. if(!string.IsNullOrEmpty(fieldString))
  2451. {
  2452. fieldString = fieldString.TrimEnd(',');
  2453. }
  2454. doSql = "update " + prizeInTable.tableEnName + " set " + fieldString + " where 1=1" + condi;
  2455. }
  2456. else
  2457. {
  2458. string fieldString = "";
  2459. string valString = "";
  2460. foreach(var fieldEnName in doFields.Keys)
  2461. {
  2462. fieldString += fieldEnName;
  2463. if(typeof(int) == doFields[fieldEnName].GetType() || typeof(decimal) == doFields[fieldEnName].GetType())
  2464. {
  2465. valString += doFields[fieldEnName].ToString();
  2466. }
  2467. else
  2468. {
  2469. valString += "'" + doFields[fieldEnName].ToString() + "'";
  2470. }
  2471. fieldString += ",";
  2472. valString += ",";
  2473. }
  2474. if(!string.IsNullOrEmpty(fieldString))
  2475. {
  2476. fieldString = fieldString.TrimEnd(',');
  2477. valString = valString.TrimEnd(',');
  2478. }
  2479. doSql = "insert into " + prizeInTable.tableEnName + " (" + fieldString + ") values (" + valString + ")";
  2480. }
  2481. db.Ado.ExecuteCommand(doSql);
  2482. }
  2483. Function.WriteLog(DateTime.Now.ToString() + "\n" + prizeInTable.excuteKind + "\n" + prizeInTable.tableEnName + "\n" + Newtonsoft.Json.JsonConvert.SerializeObject(doFields) + "\n" + condi + "\n\n", "奖励入库数据");
  2484. }
  2485. }
  2486. //固定值表达式
  2487. public static string GetExpressionVal(string str)
  2488. {
  2489. if(str == "#{now}#") return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2490. if(str == "#{today}#") return DateTime.Now.ToString("yyyy-MM-dd");
  2491. if(str == "#{this_month}#") return DateTime.Now.ToString("yyyy-MM");
  2492. 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");
  2493. 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");
  2494. if(str.StartsWith("#{today") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  2495. if(str.StartsWith("#{today") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  2496. if(str.StartsWith("#{this_month") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  2497. if(str.StartsWith("#{this_month") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  2498. 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");
  2499. 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");
  2500. if(str.StartsWith("#{") && str.EndsWith("}#"))
  2501. {
  2502. string[] data = str.Replace("#{", "").Replace("}#", "").Split(',');
  2503. string tag = data[0];
  2504. string format = data[data.Length - 1];
  2505. if(tag == "now" && format.StartsWith("yyyy"))
  2506. {
  2507. if(data.Length == 2)
  2508. {
  2509. return DateTime.Now.ToString(format);
  2510. }
  2511. else if(data.Length == 4)
  2512. {
  2513. if(data[2] == "DAY") return DateTime.Now.AddDays(int.Parse(data[1])).ToString(format);
  2514. if(data[2] == "MONTH") return DateTime.Now.AddMonths(int.Parse(data[1])).ToString(format);
  2515. }
  2516. }
  2517. }
  2518. return str;
  2519. }
  2520. public static string MatchExpressionVal(string str)
  2521. {
  2522. MatchCollection mc = Regex.Matches(str, "#\\{.*?\\}#");
  2523. foreach(Match m in mc)
  2524. {
  2525. str = str.Replace(m.Value, GetExpressionVal(m.Value));
  2526. }
  2527. return str;
  2528. }
  2529. //库内字段值表达式
  2530. public static string GetDbExpressionVal(string str)
  2531. {
  2532. string[] data = str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',');
  2533. if(str.StartsWith("#{") && str.EndsWith("DAY}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " DAY)";
  2534. if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " MONTH)";
  2535. return str;
  2536. }
  2537. public static string GetDbExpressionVal(string str, int projectId, string content, List<QueryCondition> dic, Dictionary<string, string> startData)
  2538. {
  2539. MatchCollection mc = Regex.Matches(str, "\\$\\{.*?\\}");
  2540. foreach(Match m in mc)
  2541. {
  2542. string matchValue = m.Value.Replace("${", "").Replace("}", "");
  2543. string val = "";
  2544. if(string.IsNullOrEmpty(val) || val == "0") val = getRequestParams(projectId, content, matchValue);
  2545. if(string.IsNullOrEmpty(val) || val == "0") val = GetQueryTableData(dic, matchValue);
  2546. if(string.IsNullOrEmpty(val) || val == "0") val = GetStartData(startData, matchValue);
  2547. str = str.Replace(m.Value, val);
  2548. }
  2549. return str;
  2550. }
  2551. //四则混合运算
  2552. public static string GetComputeVal(List<QueryCondition> condiDic, string expresssion)
  2553. {
  2554. if (expresssion.Contains("+") || expresssion.Contains("-") || expresssion.Contains("*") || expresssion.Contains("/") || expresssion.Contains("(") || expresssion.Contains(")"))
  2555. {
  2556. string[] returnFields = expresssion.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  2557. foreach (string returnField in returnFields)
  2558. {
  2559. if(condiDic.Any(m => m.FieldEnName == returnField))
  2560. {
  2561. string val = GetQueryTableData(condiDic, returnField);
  2562. expresssion = expresssion.Replace(returnField, val);
  2563. }
  2564. }
  2565. DataTable dt = new();
  2566. return dt.Compute(expresssion, "false").ToString();
  2567. }
  2568. return expresssion;
  2569. }
  2570. //获取查询条件数据
  2571. public static string GetQueryTableData(List<QueryCondition> condiDic, string key)
  2572. {
  2573. if(key.Contains("#{"))
  2574. {
  2575. Match m = Regex.Match(key, "\\$\\{.*?\\}\\$");
  2576. if(m.Success)
  2577. {
  2578. string keyString = m.Value.Replace("${", "").Replace("}$", "");
  2579. string val = condiDic.Any(m => m.FieldEnName == keyString) ? condiDic.FirstOrDefault(m => m.FieldEnName == keyString).Value.ToString() : "0";
  2580. key = key.Replace(m.Value, val);
  2581. key = GetExpressionVal(key);
  2582. return key;
  2583. }
  2584. }
  2585. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).Value.ToString() : "0";
  2586. }
  2587. public static string GetQueryTableTitle(List<QueryCondition> condiDic, string key)
  2588. {
  2589. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).FieldName : "";
  2590. }
  2591. public static string GetStartData(Dictionary<string, string> startData, string key)
  2592. {
  2593. return startData.ContainsKey(key) ? startData[key] : "";
  2594. }
  2595. //合并字典
  2596. public static void MergeCondiDic(List<QueryCondition> condiDic, List<QueryCondition> condiDic1)
  2597. {
  2598. foreach(QueryCondition sub in condiDic1)
  2599. {
  2600. condiDic.Add(sub);
  2601. }
  2602. }
  2603. //记录日志
  2604. public static void addLog(int projectId, int listId, int prizeIn, string requestParam, string prizeInUrl)
  2605. {
  2606. if(!logFlag) return;
  2607. var logService = App.GetService<IPriLogService>();
  2608. logService.Add(new PriLog()
  2609. {
  2610. createDate = DateTime.Now,
  2611. projectId = projectId,
  2612. listId = listId,
  2613. batchNo = batchNo,
  2614. prizeIn = prizeIn,
  2615. requestParam = requestParam,
  2616. prizeInUrl = prizeInUrl,
  2617. });
  2618. }
  2619. public static void setLogPrizeAmount(int listId, decimal prizeAmount)
  2620. {
  2621. if(!logFlag) return;
  2622. var logService = App.GetService<IPriLogService>();
  2623. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2624. if(log != null)
  2625. {
  2626. log.prizeAmount = prizeAmount;
  2627. logService.Update(log);
  2628. }
  2629. }
  2630. public static void setLogStep(int listId, Dictionary<string, object> step)
  2631. {
  2632. if(!logFlag) return;
  2633. var logService = App.GetService<IPriLogService>();
  2634. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2635. if(log != null)
  2636. {
  2637. log.stepList += Newtonsoft.Json.JsonConvert.SerializeObject(step) + ",";
  2638. logService.Update(log);
  2639. }
  2640. }
  2641. public static void setLogStep(int listId, string key, object val)
  2642. {
  2643. if(!logFlag) return;
  2644. var logService = App.GetService<IPriLogService>();
  2645. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2646. if(log != null)
  2647. {
  2648. log.stepList += "\"" + key + "\":" + Newtonsoft.Json.JsonConvert.SerializeObject(val) + ",";
  2649. logService.Update(log);
  2650. }
  2651. }
  2652. public static void setLogStatus(int listId, int status)
  2653. {
  2654. if(!logFlag) return;
  2655. var logService = App.GetService<IPriLogService>();
  2656. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2657. if(log != null)
  2658. {
  2659. log.status = status;
  2660. logService.Update(log);
  2661. }
  2662. }
  2663. public static void setLogFieldValue(int listId, string field, string content)
  2664. {
  2665. if(!logFlag) return;
  2666. var logService = App.GetService<IPriLogService>();
  2667. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  2668. if(log != null)
  2669. {
  2670. if(field == "errLog") log.errLog = content;
  2671. if(field == "prizeOutContent") log.prizeOutContent = content;
  2672. if(field == "prizeOutUrl") log.prizeOutUrl = content;
  2673. if(field == "stepListIndex") log.stepListIndex = content;
  2674. logService.Update(log);
  2675. }
  2676. }
  2677. public static string getQueryKind(string kind)
  2678. {
  2679. if(kind == "1") return "模糊匹配";
  2680. if(kind == "2") return "精确匹配";
  2681. if(kind == "4") return "取反匹配";
  2682. if(kind == "5") return "数组匹配";
  2683. if(kind == "6") return "数组排除";
  2684. if(kind == "3") return "范围匹配";
  2685. return kind;
  2686. }
  2687. public static string getQueryModel(string model)
  2688. {
  2689. if(model == "request_param") return "入参";
  2690. if(model == "query_field") return "条件匹配返回字段";
  2691. if(model == "loop_field") return "循环递归字段";
  2692. if(model == "loop_condition_field") return "循环递归条件字段";
  2693. if(model == "fixed_value") return "固定值";
  2694. if(model == "db_field") return "库内字段";
  2695. return model;
  2696. }
  2697. }
  2698. }