PrizeDo.cs 159 KB

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