PrizeDo.cs 175 KB

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