chat_group.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
  5. IC "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/init"
  6. "fmt"
  7. )
  8. type ChatGroupService struct{}
  9. // 企业用户查询
  10. func EntPerson(entId int64, isAll bool) (map[string]string, map[string]string, map[int]string) {
  11. phoneData := map[string]string{}
  12. nameData := map[string]string{}
  13. positionData := map[int]string{}
  14. if entId == 0 { //个人身份 企业查询默认为nil
  15. return phoneData, nameData, positionData
  16. }
  17. //在职人员查询
  18. 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
  19. LEFT JOIN entniche_user_role b on a.id = b.user_id
  20. WHERE a.ent_id = %d`, util.UserRoleOne, util.ENTNICHE_USER, entId))
  21. if personList != nil && len(*personList) > 0 {
  22. for _, v := range *personList {
  23. phoneData[common.InterfaceToStr(v["phone"])] = common.InterfaceToStr(v["name"])
  24. nameData[common.InterfaceToStr(v["name"])] = common.InterfaceToStr(v["phone"])
  25. }
  26. }
  27. //离职人员查看
  28. if isAll {
  29. departData, _ := IC.Mgo.Find(util.ENTNICHE_DELETE, map[string]interface{}{
  30. "tablename": "entniche_user",
  31. "ent_id": entId,
  32. }, "", `{"name":1,"phone":1}`, false, -1, -1)
  33. if departData != nil && len(*departData) > 0 {
  34. for _, v := range *departData {
  35. if phoneData[common.InterfaceToStr(v["phone"])] == "" {
  36. phoneData[common.InterfaceToStr(v["phone"])] = common.InterfaceToStr(v["name"])
  37. }
  38. if nameData[common.InterfaceToStr(v["name"])] == "" {
  39. nameData[common.InterfaceToStr(v["name"])] = common.InterfaceToStr(v["phone"])
  40. }
  41. }
  42. }
  43. //查询企业人员职位
  44. positionList := IC.BaseMysql.SelectBySql(fmt.Sprintf(`SELECT b.phone,a.id FROM base_position a
  45. INNER JOIN base_user b ON a.ent_id = %d
  46. AND a.user_id = b.id`, entId))
  47. if positionList != nil && len(*positionList) > 0 {
  48. for _, v := range *positionList {
  49. positionData[common.IntAll(v["id"])] = phoneData[common.ObjToString(v["phone"])]
  50. }
  51. }
  52. }
  53. return phoneData, nameData, positionData
  54. }
  55. // 用户名换取职位标识(测试)
  56. func NameToPositionIdp(userName string, entId int64) string {
  57. name := "and name like '%" + userName + "%'"
  58. personList := IC.MainMysql.SelectBySql(fmt.Sprintf(" select GROUP_CONCAT(phone) as phone from %s where ent_id=%d %s", util.ENTNICHE_USER, entId, name))
  59. if len(*personList) > 0 {
  60. phoneStr := (*personList)[0]["phone"]
  61. 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))
  62. if len(*positionArr) > 0 {
  63. return common.ObjToString((*positionArr)[0]["positionIdArr"])
  64. }
  65. }
  66. return ""
  67. }