Ver Fonte

fix:sql修改

duxin há 2 anos atrás
pai
commit
c5760489fa
2 ficheiros alterados com 31 adições e 10 exclusões
  1. 5 4
      service/chat_group.go
  2. 26 6
      service/message_mail_box.go

+ 5 - 4
service/chat_group.go

@@ -9,7 +9,7 @@ import (
 
 type ChatGroupService struct{}
 
-//企业用户查询
+// 企业用户查询
 func EntPerson(entId int64, isAll bool) (map[string]string, map[string]string, map[int]string) {
 	phoneData := map[string]string{}
 	nameData := map[string]string{}
@@ -40,7 +40,7 @@ func EntPerson(entId int64, isAll bool) (map[string]string, map[string]string, m
 		positionList := IC.BaseMysql.SelectBySql("SELECT a.phone,b.id FROM base_user a LEFT JOIN base_position b ON a.id = b.user_id WHERE b.ent_id = ?", entId)
 		if positionList != nil && len(*positionList) > 0 {
 			for _, v := range *positionList {
-				positionData[common.IntAll(v["positionId"])] = phoneData[common.ObjToString(v["phone"])]
+				positionData[common.IntAll(v["id"])] = phoneData[common.ObjToString(v["phone"])]
 			}
 		}
 	}
@@ -48,9 +48,10 @@ func EntPerson(entId int64, isAll bool) (map[string]string, map[string]string, m
 	return phoneData, nameData, positionData
 }
 
-//用户名换取职位标识(测试)
+// 用户名换取职位标识(测试)
 func NameToPositionIdp(userName string, entId int64) string {
-	personList := IC.MainMysql.SelectBySql(fmt.Sprintf(" select GROUP_CONCAT(phone) as phone from %s where ent_id=%d and name like '%s'  ", util.ENTNICHE_USER, entId, userName))
+	name := "and name like '%" + userName + "%'"
+	personList := IC.MainMysql.SelectBySql(fmt.Sprintf(" select GROUP_CONCAT(phone) as phone from %s where ent_id=%d %s", util.ENTNICHE_USER, entId, name))
 	if len(*personList) > 0 {
 		phoneStr := (*personList)[0]["phone"]
 		positionArr := IC.BaseMysql.SelectBySql(fmt.Sprintf("select  GROUP_CONCAT(b.id) as positionIdArr from  %s a INNER JOIN  base_position b  on  b.type=1 and    find_in_set(a.phone,'%s') and  b.ent_id=%d  and  a.id=b.user_id ", util.BASE_USER, phoneStr, entId))

+ 26 - 6
service/message_mail_box.go

@@ -107,21 +107,22 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 			if positionIdArr != "" {
 				oneNameSql = " AND find_in_set(b.id,'" + positionIdArr + "')" //1v1搜索成员id
 				//存在满足成员名时 重新定义搜索sql 并兼容群名称不满足但成员名满足时也展示 并展示部分满足群员名
-				name := fmt.Sprintf(" AND (c.position_id IN ( %s ) or b.name like '%"+in.NameSearch+"%')", positionIdArr)
+				nameSearch := " or b.name like '%" + in.NameSearch + "%')"
+				name := fmt.Sprintf(" AND (c.position_id IN ( %s ) %s", positionIdArr, nameSearch)
 				GroupNameSql = fmt.Sprintf(` (
 						SELECT
 							a.chat_group_id as id,
 							GROUP_CONCAT( distinct c.position_id ) as groupMember,
-							GROUP_CONCAT( distinct b.name ) as name,
+							GROUP_CONCAT( distinct b.name ) as name
 						FROM
 						socialize_chat_group_person a
 						INNER JOIN socialize_chat_group b ON a.position_id=%d AND a.chat_group_id = b.id AND b.isdismiss = 0 
-						INNER JOIN socialize_chat_group_person c ON AND a.chat_group_id = c.chat_group_id 	%s
+						INNER JOIN socialize_chat_group_person c ON  a.chat_group_id = c.chat_group_id 	%s
 						GROUP BY
 						a.chat_group_id)`, in.PositionId, name) //群搜索
 			}
 		}
-
+		log.Println("用户列表展示", in.NameSearch, in.EntId, oneNameSql)
 		//1v1 无搜索时 或搜索有结果时
 		if in.NameSearch == "" || oneNameSql != "" {
 			oneSql = fmt.Sprintf(`(SELECT
@@ -188,10 +189,29 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 						) `, GroupNameSql, in.PositionId)
 		switch in.QueryType {
 		case 1: //分享列表
-			allSql = strings.Join(append(sqlArr, oneSql, groupSql), " UNION ALL ")
+			if oneSql != "" {
+				sqlArr = append(sqlArr, oneSql)
+			}
+			if groupSql != "" {
+				sqlArr = append(sqlArr, groupSql)
+			}
+			if len(sqlArr) > 1 {
+				allSql = strings.Join(sqlArr, " UNION ALL ")
+			} else {
+				allSql = sqlArr[0]
+			}
 		default:
 			//历史会话列表
-			allSql = strings.Join(append(sqlArr, oneSql, groupSql, serviceSql), " UNION ALL ")
+			if oneSql != "" {
+				sqlArr = append(sqlArr, oneSql)
+			}
+			if groupSql != "" {
+				sqlArr = append(sqlArr, groupSql)
+			}
+			if serviceSql != "" {
+				sqlArr = append(sqlArr, serviceSql)
+			}
+			allSql = strings.Join(sqlArr, " UNION ALL ")
 		}
 		sqlStr = fmt.Sprintf(`SELECT * FROM(
 						%s