material.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/date"
  4. entity "bp.jydev.jianyu360.cn/BaseService/biService/entity"
  5. "bp.jydev.jianyu360.cn/BaseService/biService/rpc/pb"
  6. "errors"
  7. "fmt"
  8. "github.com/gogf/gf/v2/util/gconv"
  9. "log"
  10. "strings"
  11. "time"
  12. )
  13. func MaterialSave(in *pb.MaterialSaveReq, title, content string) (msgId, mId int64, err error) {
  14. if len(strings.Split(in.ReceiveUserId, ",")) < 1 {
  15. return 0, 0, errors.New("物料发送人员为空")
  16. }
  17. //先插入message_log
  18. saveMsg := map[string]interface{}{
  19. "msg_type": "14",
  20. "title": title,
  21. "content": content,
  22. "send_mode": 2,
  23. "send_time": time.Now().Format(date.Date_Full_Layout),
  24. "send_status": 4,
  25. "update_time": time.Now().Format(date.Date_Full_Layout),
  26. "link": "",
  27. "isdel": 1,
  28. "update_user": in.CreateUser,
  29. "Sign": 1,
  30. "group_id": 11,
  31. "createtime": time.Now().Format(date.Date_Full_Layout),
  32. }
  33. msgId = entity.JyMysql.Insert("message_send_log", saveMsg)
  34. if msgId < 0 {
  35. return 0, 0, errors.New("插入消息表message_send_log出错")
  36. }
  37. saveMap := map[string]interface{}{
  38. "task_name": in.TaskName,
  39. "task_description": in.TaskDescription,
  40. "material_content": in.MaterialContent,
  41. "qrcode_url": in.QrcodeUrl,
  42. "receive_user_name": in.ReceiveUserName,
  43. "receive_position_id": in.ReceiveUserId,
  44. "file_url": in.FileUrl,
  45. "createtime": time.Now().Format(date.Date_Full_Layout),
  46. "create_user": in.CreateUser,
  47. "msg_id": msgId,
  48. "img_webpage": in.ImgWebpage,
  49. }
  50. mId = entity.BiService.Insert("operating_materials", saveMap)
  51. if mId < 0 {
  52. return 0, 0, errors.New("插入物料表operating_materials出错")
  53. }
  54. return msgId, mId, nil
  55. }
  56. func GetSendUserId(positionIds string, entId int64) []string {
  57. //拿职位id找mgoid
  58. userIdArr := []string{}
  59. query := fmt.Sprintf("SELECT userid FROM `dwd_f_userbase_id_mapping` WHERE position_id in (%s) AND ent_id = %d", positionIds, entId)
  60. log.Println("查找分发人的sql", query)
  61. useridMap := entity.JyBiTidb.SelectBySql(query)
  62. if useridMap != nil && len(*useridMap) > 0 {
  63. for _, val := range *useridMap {
  64. userIdArr = append(userIdArr, gconv.String(val["userid"]))
  65. }
  66. }
  67. return userIdArr
  68. }