package service import ( "app.yhyue.com/moapp/jybase/common" util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity" IC "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/init" "fmt" ) 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{} positionData := map[int]string{} if entId == 0 { //个人身份 企业查询默认为nil return phoneData, nameData, positionData } //在职人员查询 personList := IC.MainMysql.SelectBySql(fmt.Sprintf(`SELECT a.phone,IF(a.name = "我" AND b.role_id = 1 ,"%s",a.name) AS name,b.role_id FROM %s a LEFT JOIN entniche_user_role b on a.id = b.user_id WHERE a.ent_id = %d`, util.UserRoleOne, util.ENTNICHE_USER, entId)) if personList != nil && len(*personList) > 0 { for _, v := range *personList { phoneData[common.InterfaceToStr(v["phone"])] = common.InterfaceToStr(v["name"]) nameData[common.InterfaceToStr(v["name"])] = common.InterfaceToStr(v["phone"]) } } //离职人员查看 if isAll { departData, _ := IC.Mgo.Find(util.ENTNICHE_DELETE, map[string]interface{}{ "tablename": "entniche_user", "ent_id": entId, }, "", `{"name":1,"phone":1}`, false, -1, -1) if departData != nil && len(*departData) > 0 { for _, v := range *departData { if phoneData[common.InterfaceToStr(v["phone"])] == "" { phoneData[common.InterfaceToStr(v["phone"])] = common.InterfaceToStr(v["name"]) } if nameData[common.InterfaceToStr(v["name"])] == "" { nameData[common.InterfaceToStr(v["name"])] = common.InterfaceToStr(v["phone"]) } } } //查询企业人员职位 positionList := IC.BaseMysql.SelectBySql(fmt.Sprintf(`SELECT b.phone,a.id FROM base_position a INNER JOIN base_user b ON a.ent_id = %d AND a.user_id = b.id`, entId)) if positionList != nil && len(*positionList) > 0 { for _, v := range *positionList { positionData[common.IntAll(v["id"])] = phoneData[common.ObjToString(v["phone"])] } } } return phoneData, nameData, positionData } // 用户名换取职位标识(测试) func NameToPositionIdp(userName string, entId int64) string { 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)) if len(*positionArr) > 0 { return common.ObjToString((*positionArr)[0]["positionIdArr"]) } } return "" }