|
@@ -1,4 +1,5 @@
|
|
|
-using Common;
|
|
|
+using System.Data;
|
|
|
+using Common;
|
|
|
using Infrastructure;
|
|
|
using LitJson;
|
|
|
using Microsoft.Extensions.Localization;
|
|
@@ -491,14 +492,15 @@ namespace Util
|
|
|
//奖励发放
|
|
|
public static void prizeSend(int projectId, string prizeIds, string prizeObjectId, string content)
|
|
|
{
|
|
|
+ var loopSetService = App.GetService<IPriLoopSetService>();
|
|
|
+ var recursionStartTableService = App.GetService<IPriRecursionStartTableService>();
|
|
|
+ var recursionStartConditionService = App.GetService<IPriRecursionStartConditionService>();
|
|
|
var priList = prizeList(projectId, prizeIds);
|
|
|
foreach(var sub in priList)
|
|
|
{
|
|
|
var recursionFlag = sub.recursionFlag; //是否递归
|
|
|
if(recursionFlag)
|
|
|
{
|
|
|
- var loopSetService = App.GetService<IPriLoopSetService>();
|
|
|
- var recursionStartTableService = App.GetService<IPriRecursionStartTableService>();
|
|
|
var loopSet = loopSetService.GetFirst(m => m.listId == sub.id) ?? new PriLoopSet();
|
|
|
var recursionStartTable = recursionStartTableService.GetFirst(m => m.listId == sub.id) ?? new PriRecursionStartTable();
|
|
|
var tableEnName = loopSet.tableEnName; //递归查询表
|
|
@@ -510,10 +512,145 @@ namespace Util
|
|
|
bool op = true;
|
|
|
while(!string.IsNullOrEmpty(objId) && objId != "0" && op)
|
|
|
{
|
|
|
- if(loopCondition(projectId, sub, objId, content))
|
|
|
+ Dictionary<string, object> condiDic = loopCondition(projectId, sub, objId, content);
|
|
|
+ if(condiDic.Count > 0)
|
|
|
{
|
|
|
- prizeSendDo(projectId, sub, objId, content);
|
|
|
- op = afterPrizeFlag;
|
|
|
+ bool prizeFlag = true;
|
|
|
+ var conditions = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id);
|
|
|
+ if(conditions.Count > 0)
|
|
|
+ {
|
|
|
+ int allCount = conditions.Count; //所有奖励条件数
|
|
|
+ int passCount = 0; //通过条件数
|
|
|
+ foreach(var condition in conditions)
|
|
|
+ {
|
|
|
+ var returnFieldId = condition.returnFieldId; //条件返回字段
|
|
|
+ var fieldQueryKind = condition.fieldQueryKind; //匹配条件
|
|
|
+ var fieldQueryModel = condition.fieldQueryModel; //匹配方式
|
|
|
+ var fieldQueryValue = condition.fieldQueryValue; //匹配值
|
|
|
+ var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
|
|
|
+
|
|
|
+ string checkObj = "";
|
|
|
+ if(returnFieldId.Contains(","))
|
|
|
+ {
|
|
|
+ string[] returnFieldIdList = returnFieldId.Split(',');
|
|
|
+ foreach(string subField in returnFieldIdList)
|
|
|
+ {
|
|
|
+ checkObj += condiDic.ContainsKey(subField) + ",";
|
|
|
+ }
|
|
|
+ checkObj = checkObj.TrimEnd(',');
|
|
|
+ }
|
|
|
+ else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
|
|
|
+ {
|
|
|
+ string expresssion = returnFieldId;
|
|
|
+ string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
|
|
|
+ foreach(string returnField in returnFields)
|
|
|
+ {
|
|
|
+ string val = condiDic.ContainsKey(returnFieldId) ? condiDic[returnFieldId].ToString() : "0";
|
|
|
+ expresssion = expresssion.Replace(returnField, val);
|
|
|
+ }
|
|
|
+ DataTable dt = new DataTable();
|
|
|
+ checkObj = dt.Compute(expresssion, "false").ToString();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ checkObj = condiDic.ContainsKey(returnFieldId) ? condiDic[returnFieldId].ToString() : "0";
|
|
|
+ }
|
|
|
+ var checkVal = fieldQueryValue;
|
|
|
+
|
|
|
+ if(fieldQueryKind == "1") //模糊匹配
|
|
|
+ {
|
|
|
+ if(fieldQueryValueType == "text")
|
|
|
+ {
|
|
|
+ if(checkObj.ToString().Contains(GetExpressionVal(checkVal))) passCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(fieldQueryKind == "2") //精确匹配
|
|
|
+ {
|
|
|
+ if(fieldQueryValueType == "int")
|
|
|
+ {
|
|
|
+ if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal))) passCount += 1;
|
|
|
+ }
|
|
|
+ else if(fieldQueryValueType == "number")
|
|
|
+ {
|
|
|
+ if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(checkObj.ToString() == GetExpressionVal(checkVal)) passCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(fieldQueryKind == "3") //范围匹配
|
|
|
+ {
|
|
|
+ string[] val = checkVal.Split(':');
|
|
|
+ if(fieldQueryModel == "request_param")
|
|
|
+ {
|
|
|
+ Dictionary<string, string> req = getRequestParams(projectId, content);
|
|
|
+ if(fieldQueryValueType == "number")
|
|
|
+ {
|
|
|
+ if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(req[val[0]])) && (decimal)checkObj <= decimal.Parse(Function.CheckNum(req[val[1]]))) passCount += 1;
|
|
|
+ else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(req[val[0]]))) passCount += 1;
|
|
|
+ else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj <= decimal.Parse(Function.CheckNum(req[val[1]]))) passCount += 1;
|
|
|
+ }
|
|
|
+ else if(fieldQueryValueType == "int")
|
|
|
+ {
|
|
|
+ if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (int)checkObj >= int.Parse(Function.CheckInt(req[val[0]])) && (int)checkObj <= int.Parse(Function.CheckInt(req[val[1]]))) passCount += 1;
|
|
|
+ else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (int)checkObj >= int.Parse(Function.CheckInt(req[val[0]]))) passCount += 1;
|
|
|
+ else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (int)checkObj <= int.Parse(Function.CheckInt(req[val[1]]))) passCount += 1;
|
|
|
+ }
|
|
|
+ else if(fieldQueryValueType.StartsWith("date"))
|
|
|
+ {
|
|
|
+ if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj >= DateTime.Parse(req[val[0]]) && (DateTime)checkObj <= DateTime.Parse(req[val[1]])) passCount += 1;
|
|
|
+ else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj >= DateTime.Parse(req[val[0]])) passCount += 1;
|
|
|
+ else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj <= DateTime.Parse(req[val[1]])) passCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(fieldQueryModel == "fixed_value")
|
|
|
+ {
|
|
|
+ if(fieldQueryValueType == "number")
|
|
|
+ {
|
|
|
+ if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(val[0])) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(val[1]))) passCount += 1;
|
|
|
+ else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(val[0]))) passCount += 1;
|
|
|
+ else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(val[1]))) passCount += 1;
|
|
|
+ }
|
|
|
+ else if(fieldQueryValueType == "int")
|
|
|
+ {
|
|
|
+ if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (int)checkObj >= int.Parse(Function.CheckInt(val[0])) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(val[1]))) passCount += 1;
|
|
|
+ else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(val[0]))) passCount += 1;
|
|
|
+ else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(val[1]))) passCount += 1;
|
|
|
+ }
|
|
|
+ else if(fieldQueryValueType.StartsWith("date"))
|
|
|
+ {
|
|
|
+ if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (DateTime)checkObj >= DateTime.Parse(GetExpressionVal(val[0])) && (DateTime)checkObj <= DateTime.Parse(GetExpressionVal(val[1]))) passCount += 1;
|
|
|
+ else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && (DateTime)checkObj >= DateTime.Parse(GetExpressionVal(val[0]))) passCount += 1;
|
|
|
+ else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (DateTime)checkObj <= DateTime.Parse(GetExpressionVal(val[1]))) passCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(fieldQueryKind == "4") //取反匹配
|
|
|
+ {
|
|
|
+ if(fieldQueryValueType == "int")
|
|
|
+ {
|
|
|
+ if((int)checkObj != int.Parse(Function.CheckInt(checkVal))) passCount += 1;
|
|
|
+ }
|
|
|
+ else if(fieldQueryValueType == "number")
|
|
|
+ {
|
|
|
+ if((decimal)checkObj != decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
|
|
|
+ }
|
|
|
+ else if(fieldQueryValueType == "text")
|
|
|
+ {
|
|
|
+ if(checkObj.ToString() != GetExpressionVal(checkVal)) passCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(loopSet.conditionMode == "all" && passCount == allCount) prizeFlag = true;
|
|
|
+ else if(loopSet.conditionMode == "one" && passCount == 1) prizeFlag = true;
|
|
|
+ else prizeFlag = false;
|
|
|
+ }
|
|
|
+ if(prizeFlag)
|
|
|
+ {
|
|
|
+ prizeSendDo(projectId, sub, objId, content);
|
|
|
+ op = afterPrizeFlag;
|
|
|
+ }
|
|
|
}
|
|
|
var parent = db.Ado.GetScalar("select " + parentField + " from " + tableEnName + " where " + sonField + "=" + objId);
|
|
|
if(parent != null)
|
|
@@ -719,11 +856,12 @@ namespace Util
|
|
|
}
|
|
|
|
|
|
//递归条件判断
|
|
|
- public static bool loopCondition(int projectId, PriList sub, string objId, string content)
|
|
|
+ public static Dictionary<string, object> loopCondition(int projectId, PriList sub, string objId, string content)
|
|
|
{
|
|
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
|
|
var queryTableService = App.GetService<IPriRecursionStartTableService>();
|
|
|
var queryFieldService = App.GetService<IPriRecursionStartFieldService>();
|
|
|
+ var queryReturnFieldService = App.GetService<IPriRecursionStartReturnFieldService>();
|
|
|
int passCount = 0;
|
|
|
//查询表
|
|
|
var queryTables = queryTableService.GetList(m => m.listId == sub.id);
|
|
@@ -732,6 +870,31 @@ namespace Util
|
|
|
{
|
|
|
//查询返回字段
|
|
|
string fields = "1";
|
|
|
+ var returnFields = queryReturnFieldService.GetList(m => m.objectTableId == queryTable.id);
|
|
|
+ if(returnFields.Count > 0)
|
|
|
+ {
|
|
|
+ fields = "";
|
|
|
+ foreach(var returnField in returnFields)
|
|
|
+ {
|
|
|
+ if(returnField.fieldReturnKind == "2")
|
|
|
+ {
|
|
|
+ fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
|
|
|
+ }
|
|
|
+ else if(returnField.fieldReturnKind == "3")
|
|
|
+ {
|
|
|
+ fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
|
|
|
+ }
|
|
|
+ else if(returnField.fieldReturnKind == "4")
|
|
|
+ {
|
|
|
+ fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fields = fields.TrimEnd(',');
|
|
|
+ }
|
|
|
|
|
|
//查询匹配条件
|
|
|
string condi = "";
|
|
@@ -906,13 +1069,17 @@ namespace Util
|
|
|
}
|
|
|
|
|
|
var db = initDb(queryTable.databaseId);
|
|
|
- var item = db.Ado.GetScalar("select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi);
|
|
|
- if(item != null) passCount += 1;
|
|
|
+ string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
|
|
|
+ var items = db.Ado.GetDataTable(sql);
|
|
|
+ if(items.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ foreach(System.Data.DataColumn item in items.Columns)
|
|
|
+ {
|
|
|
+ dic.Add(item.ColumnName, items.Rows[0][item.ColumnName].ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- bool op = false;
|
|
|
- if(sub.conditionMode == "all" && passCount == allCount) op = true;
|
|
|
- else if(sub.conditionMode == "one" && passCount == 1) op = true;
|
|
|
- return op;
|
|
|
+ return dic;
|
|
|
}
|
|
|
|
|
|
//奖励入库
|