ソースを参照

feat:部门多分配设置优先级修改

duxin 2 年 前
コミット
32e56eba88
1 ファイル変更46 行追加2 行削除
  1. 46 2
      jyBXSubscribe/rpc/model/distributor.go

+ 46 - 2
jyBXSubscribe/rpc/model/distributor.go

@@ -53,10 +53,32 @@ func Distributor(region []string, entId, entUserId int) []*User {
 				ss = append(ss, v)
 				continue
 			}
+			var rule_id string
+			var deptNo bool
 			//有区域限制 过滤筛选
-			rules := IC.MainMysql.FindOne("entniche_user_rule", map[string]interface{}{"user_id": v.Id, "dept_id": v.Dept_id}, "rule_id", "")
+			rules := IC.MainMysql.Find("entniche_user_rule", map[string]interface{}{"user_id": v.Id}, "rule_id,dept_id", "", -1, -1)
 			if rules != nil && len(*rules) > 0 {
-				data, ok := IC.Mgo.FindById("entniche_distribute", common.InterfaceToStr((*rules)["rule_id"]), "")
+				if len(*rules) > 1 { //多条规则 查询优先级最高的规则
+					//获取部门优先级
+					var ids = []int{entInfo.Dept.Id}
+					departSort(&ids, entInfo.Dept.Id)
+					Reverse(ids)
+					for _, v1 := range ids {
+						for _, v2 := range *rules {
+							if v1 == common.IntAll(v2["dept_id"]) {
+								deptNo = true
+								rule_id = common.InterfaceToStr(v2["rule_id"])
+								break
+							}
+						}
+						if deptNo {
+							break
+						}
+					}
+				} else {
+					rule_id = common.InterfaceToStr((*rules)[0]["rule_id"])
+				}
+				data, ok := IC.Mgo.FindById("entniche_distribute", rule_id, "")
 				if ok && data != nil && len(*data) > 0 {
 					o_area, _ := (*data)["o_area"].(map[string]interface{})
 					if regionCheck(o_area, regions) {
@@ -132,3 +154,25 @@ func regionCheck(o_area map[string]interface{}, regions []string) bool {
 		return regionBool
 	}
 }
+
+func departSort(ids *[]int, deptId int) {
+	list := IC.MainMysql.FindOne("entniche_department", map[string]interface{}{"id": deptId}, "id,pid", "")
+	if list != nil && len(*list) > 0 {
+		pid := common.IntAll((*list)["pid"])
+		if pid != 0 {
+			*ids = append(*ids, pid)
+			departSort(ids, pid)
+		}
+	}
+}
+
+// 数组倒序函数
+func Reverse(arr []int) {
+	var temp int
+	length := len(arr)
+	for i := 0; i < length/2; i++ {
+		temp = arr[i]
+		arr[i] = arr[length-1-i]
+		arr[length-1-i] = temp
+	}
+}