PrizeDo.cs 153 KB

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