PrizeDo.cs 155 KB

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