Jianghan пре 1 година
родитељ
комит
016514d2eb
3 измењених фајлова са 46 додато и 35 уклоњено
  1. 3 2
      clueSync/config.go
  2. 4 1
      clueSync/config.json
  3. 39 32
      clueSync/sendMail.go

+ 3 - 2
clueSync/config.go

@@ -128,8 +128,9 @@ type (
 			UserName string `json:"user	Name"`
 			Password string `json:"password"`
 		} `json:"es"`
-		AllocationCap int64 `json:"allocationCap"`
-		WarningValue  int64 `json:"warningValue"`
+		AllocationCap int64             `json:"allocationCap"`
+		WarningValue  int64             `json:"warningValue"`
+		NameToMail    map[string]string `json:"nameToMail"`
 	}
 )
 

+ 4 - 1
clueSync/config.json

@@ -120,5 +120,8 @@
     "password": ""
   },
   "warningValue": 350,
-  "allocationCap": 1
+  "allocationCap": 1,
+  "nameToMail": {
+    "王江含": "wangjianghan@topnet.net.cn"
+  }
 }

+ 39 - 32
clueSync/sendMail.go

@@ -9,21 +9,21 @@ import (
 )
 
 var (
-	selfMail = `SELECT b.mail FROM jianyu.entniche_user b WHERE b.id IN (SELECT a.ent_user_id FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a WHERE a.position_id = ?)`
+	selfMail = `SELECT b.mail, b.name FROM jianyu.entniche_user b WHERE b.id IN (SELECT a.ent_user_id FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a WHERE a.position_id = ?)`
 	infoSelf = `SELECT a.name, a.SZ_PID1, a.SZ_PID2, a.dept_name, b.role_id FROM Jianyu_subjectdb_test_test.dwd_d_crm_department_level_succbi a INNER JOIN Jianyu_subjectdb_test_test.dwd_f_crm_personnel_management b ON b.position_id = a.position_id WHERE a.position_id = ? AND a.resign = 0`
-	topMail  = `SELECT d.mail FROM jianyu.entniche_user d WHERE d.id IN (SELECT b.ent_user_id FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi b INNER JOIN Jianyu_subjectdb_test.dwd_f_crm_personnel_management c
+	topMail  = `SELECT d.mail, d.name FROM jianyu.entniche_user d WHERE d.id IN (SELECT b.ent_user_id FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi b INNER JOIN Jianyu_subjectdb_test.dwd_f_crm_personnel_management c
 		ON b.position_id  = c.position_id AND c.resign = 0 WHERE b.SZ_PID3 IN (SELECT a.SZ_PID3 FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a WHERE a.position_id = ?) AND c.role_id = 3)`
-	topMail3 = `SELECT d.mail FROM jianyu.entniche_user d WHERE d.id IN ( SELECT a.ent_user_id FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a INNER JOIN Jianyu_subjectdb_test.dwd_f_crm_personnel_management b
+	topMail3 = `SELECT d.mail, d.name FROM jianyu.entniche_user d WHERE d.id IN ( SELECT a.ent_user_id FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a INNER JOIN Jianyu_subjectdb_test.dwd_f_crm_personnel_management b
 		ON a.position_id = b.position_id WHERE a.dept_name = '销售三部' AND a.resign = 0 AND b.role_id = 3)`
 	dmInfo = `SELECT b.dept_name FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi b WHERE b.position_id IN (SELECT a.position_id FROM Jianyu_subjectdb_test.dwd_f_crm_personnel_management a
 		WHERE assign_type = 1) GROUP BY b.dept_name`
 	dmInfoCount = `SELECT COUNT(*) as num FROM Jianyu_subjectdb_test.dwd_f_crm_clue_info b WHERE b.position_id IN (SELECT a.position_id FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a WHERE dept_name = ? AND resign = 0) GROUP BY b.position_id HAVING num < ?`
 	dmInfoMail  = `SELECT a.*, c.mail, (b.send_mail >> 2) & 1 AS flag_1, (b.send_mail >> 3) & 1 AS flag_2 FROM Jianyu_subjectdb_test_test.dwd_d_crm_department_level_succbi a INNER JOIN Jianyu_subjectdb_test_test.dwd_f_crm_personnel_management b ON a.position_id = b.position_id INNER JOIN jianyu.entniche_user c ON c.id = a.ent_user_id WHERE a.dept_name = ? AND a.resign = 0 AND b.role_id = 3`
-	xgMail      = `SELECT c.mail FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a INNER JOIN Jianyu_subjectdb_test.dwd_f_crm_personnel_management b ON a.position_id = b.position_id INNER JOIN jianyu.entniche_user c ON c.id = a.ent_user_id WHERE b.role_id = 5 AND b.resign = 0`
+	xgMail      = `SELECT c.mail, c.name FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a INNER JOIN Jianyu_subjectdb_test.dwd_f_crm_personnel_management b ON a.position_id = b.position_id INNER JOIN jianyu.entniche_user c ON c.id = a.ent_user_id WHERE b.role_id = 5 AND b.resign = 0`
 	// 所有参与线索分配人员的邮箱
-	allMail = `SELECT c.mail FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a INNER JOIN Jianyu_subjectdb_test.dwd_f_crm_personnel_management b ON a.position_id = b.position_id INNER JOIN jianyu.entniche_user c ON c.id = a.ent_user_id WHERE b.assign_type = 1 AND b.resign = 0`
+	allMail = `SELECT c.mail, c.name FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a INNER JOIN Jianyu_subjectdb_test.dwd_f_crm_personnel_management b ON a.position_id = b.position_id INNER JOIN jianyu.entniche_user c ON c.id = a.ent_user_id WHERE b.assign_type = 1 AND b.resign = 0`
 	// 超管
-	cgMail = `SELECT c.mail FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a INNER JOIN Jianyu_subjectdb_test.dwd_f_crm_personnel_management b ON a.position_id = b.position_id INNER JOIN jianyu.entniche_user c ON c.id = a.ent_user_id WHERE b.role_id = 4 AND b.resign = 0`
+	cgMail = `SELECT c.mail, c.name FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a INNER JOIN Jianyu_subjectdb_test.dwd_f_crm_personnel_management b ON a.position_id = b.position_id INNER JOIN jianyu.entniche_user c ON c.id = a.ent_user_id WHERE b.role_id = 4 AND b.resign = 0`
 )
 
 // @Author jianghan
@@ -88,7 +88,7 @@ func WarningDm() {
 		posid := common.ObjToString((*info2)[0]["position_id"])
 		var toCc []string // 销管
 		for _, m2 := range *TiDb.SelectBySql(xgMail) {
-			if m3 := common.ObjToString(m2["mail"]); m3 != "" {
+			if m3 := getMailAds(common.ObjToString(m2["mail"]), common.ObjToString(m2["name"])); m3 != "" {
 				toCc = append(toCc, m3)
 			}
 		}
@@ -127,7 +127,10 @@ func WillWarningByPp(posid int64) {
 	toMail := ""
 	toCc := ""
 
-	toMail = getMailAds(posid)
+	info := TiDb.SelectBySql(selfMail, posid)
+	if info != nil && len(*info) > 0 {
+		toMail = getMailAds(common.ObjToString((*info)[0]["mail"]), common.ObjToString((*info)[0]["name"]))
+	}
 	if toMail == "" {
 		log.Println("未查询到邮箱地址, position id: ", posid)
 		return
@@ -156,7 +159,7 @@ func WillWarningByAll() {
 	content := "所有参与线上线索自动分配的电销人员,私海线索都已达到%d条,请及时提醒销售部门将无需跟进的销售线索退回公海"
 	var to []string // 销管
 	for _, m2 := range *TiDb.SelectBySql(xgMail) {
-		if m3 := common.ObjToString(m2["mail"]); m3 != "" {
+		if m3 := getMailAds(common.ObjToString(m2["mail"]), common.ObjToString(m2["name"])); m3 != "" {
 			to = append(to, m3)
 		}
 	}
@@ -174,7 +177,10 @@ func ExceedLimitByPp(posid int64) {
 	toMail := ""
 	toCc := ""
 	content = fmt.Sprintf(content, cfg.AllocationCap)
-	toMail = getMailAds(posid)
+	info := TiDb.SelectBySql(selfMail, posid)
+	if info != nil && len(*info) > 0 {
+		toMail = getMailAds(common.ObjToString((*info)[0]["mail"]), common.ObjToString((*info)[0]["name"]))
+	}
 	if toMail == "" {
 		log.Println("未查询到邮箱地址, position id: ", posid)
 		return
@@ -203,18 +209,18 @@ func AutoReleaseNots() {
 
 	var to []string
 	for _, m := range *TiDb.SelectBySql(allMail) {
-		if m1 := common.ObjToString(m["mail"]); m1 != "" {
+		if m1 := getMailAds(common.ObjToString(m["mail"]), common.ObjToString(m["name"])); m1 != "" {
 			to = append(to, m1)
 		}
 	}
 	var toCc []string // 销管+高级电销经理+超管
 	for _, m2 := range *TiDb.SelectBySql(xgMail) {
-		if m3 := common.ObjToString(m2["mail"]); m3 != "" {
+		if m3 := getMailAds(common.ObjToString(m2["mail"]), common.ObjToString(m2["name"])); m3 != "" {
 			toCc = append(toCc, m3)
 		}
 	}
 	for _, m2 := range *TiDb.SelectBySql(cgMail) {
-		if m3 := common.ObjToString(m2["mail"]); m3 != "" {
+		if m3 := getMailAds(common.ObjToString(m2["mail"]), common.ObjToString(m2["name"])); m3 != "" {
 			toCc = append(toCc, m3)
 		}
 	}
@@ -231,18 +237,18 @@ func CantBeAssignedNots() {
 
 	var to []string
 	for _, m := range *TiDb.SelectBySql(allMail) {
-		if m1 := common.ObjToString(m["mail"]); m1 != "" {
+		if m1 := getMailAds(common.ObjToString(m["mail"]), common.ObjToString(m["name"])); m1 != "" {
 			to = append(to, m1)
 		}
 	}
 	var toCc []string // 销管+高级电销经理+超管
 	for _, m2 := range *TiDb.SelectBySql(xgMail) {
-		if m3 := common.ObjToString(m2["mail"]); m3 != "" {
+		if m3 := getMailAds(common.ObjToString(m2["mail"]), common.ObjToString(m2["name"])); m3 != "" {
 			toCc = append(toCc, m3)
 		}
 	}
 	for _, m2 := range *TiDb.SelectBySql(cgMail) {
-		if m3 := common.ObjToString(m2["mail"]); m3 != "" {
+		if m3 := getMailAds(common.ObjToString(m2["mail"]), common.ObjToString(m2["name"])); m3 != "" {
 			toCc = append(toCc, m3)
 		}
 	}
@@ -272,7 +278,10 @@ func OrderCreateFail(posid int64, bname string) {
 	toMail := ""
 	toCc := ""
 	content = fmt.Sprintf(content, cfg.AllocationCap, cfg.AllocationCap, bname)
-	toMail = getMailAds(posid)
+	info := TiDb.SelectBySql(selfMail, posid)
+	if info != nil && len(*info) > 0 {
+		toMail = getMailAds(common.ObjToString((*info)[0]["mail"]), common.ObjToString((*info)[0]["name"]))
+	}
 	if toMail == "" {
 		log.Println("未查询到邮箱地址, position id: ", posid)
 		return
@@ -291,7 +300,10 @@ func AssFail(posid int64, ent, iname string) {
 	toMail := ""
 	toCc := ""
 	content = fmt.Sprintf(content, cfg.AllocationCap, ent, iname)
-	toMail = getMailAds(posid)
+	info := TiDb.SelectBySql(selfMail, posid)
+	if info != nil && len(*info) > 0 {
+		toMail = getMailAds(common.ObjToString((*info)[0]["mail"]), common.ObjToString((*info)[0]["name"]))
+	}
 	if toMail == "" {
 		log.Println("未查询到邮箱地址, position id: ", posid)
 		return
@@ -336,14 +348,14 @@ func getCc(posid int64) (to string) {
 		if common.IntAll((*info)[0]["role_id"]) == 1 {
 			m := TiDb.SelectBySql(topMail3)
 			if m != nil && len(*m) > 0 {
-				to = common.ObjToString((*m)[0]["mail"])
+				to = getMailAds(common.ObjToString((*m)[0]["mail"]), common.ObjToString((*m)[0]["name"]))
 			}
 		}
 	} else {
 		if common.IntAll((*info)[0]["role_id"]) == 2 {
 			m := TiDb.SelectBySql(topMail, posid)
 			if m != nil && len(*m) > 0 {
-				to = common.ObjToString((*m)[0]["mail"])
+				to = getMailAds(common.ObjToString((*m)[0]["mail"]), common.ObjToString((*m)[0]["name"]))
 			}
 		} else {
 			to = "shenbingyi@topnet.net.cn"
@@ -353,18 +365,13 @@ func getCc(posid int64) (to string) {
 }
 
 // @Author jianghan
-// @Description 获取邮箱地址
+// @Description 获取配置文件邮箱地址
 // @Date 2024/5/13
-func getMailAds(posid int64) string {
-	sql := `SELECT a.ent_user_id FROM Jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a WHERE a.position_id = ?`
-	sql1 := `SELECT mail FROM jianyu.entniche_user WHERE id = ?`
-	info := TiDb.SelectBySql(sql, posid)
-	if info != nil && len(*info) > 0 {
-		id := common.Int64All((*info)[0]["ent_user_id"])
-		info1 := Mysql.SelectBySql(sql1, id)
-		if info1 != nil && len(*info1) > 0 {
-			return common.ObjToString((*info1)[0]["mail"])
-		}
+func getMailAds(name, mail string) string {
+	log.Println("getMailAds", name, mail)
+	if cfg.NameToMail != nil && len(cfg.NameToMail) > 0 {
+		return cfg.NameToMail[name]
+	} else {
+		return mail
 	}
-	return ""
 }