123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- package service
- import (
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/date"
- entity "bp.jydev.jianyu360.cn/BaseService/biService/entity"
- "bp.jydev.jianyu360.cn/BaseService/biService/rpc/pb"
- "crypto/rand"
- "errors"
- "fmt"
- "github.com/gogf/gf/v2/util/gconv"
- "log"
- "math/big"
- "strings"
- "time"
- )
- func MaterialSave(in *pb.MaterialSaveReq, title, content string) (msgId, mId int64, err error) {
- if len(strings.Split(in.ReceiveUserId, ",")) < 1 {
- return 0, 0, errors.New("物料发送人员为空")
- }
- //先插入message_log
- saveMsg := map[string]interface{}{
- "msg_type": "14",
- "title": title,
- "content": content,
- "send_mode": 2,
- "send_time": time.Now().Format(date.Date_Full_Layout),
- "send_status": 4,
- "update_time": time.Now().Format(date.Date_Full_Layout),
- "link": "",
- "isdel": 1,
- "update_user": in.CreateUser,
- "sign": 1,
- "group_id": 11,
- "createtime": time.Now().Format(date.Date_Full_Layout),
- }
- msgId = entity.JyMysql.Insert("message_send_log", saveMsg)
- if msgId < 0 {
- return 0, 0, errors.New("插入消息表message_send_log出错")
- }
- saveMap := map[string]interface{}{
- "task_name": in.TaskName,
- "task_description": in.TaskDescription,
- "material_content": in.MaterialContent,
- "qrcode_url": in.QrcodeUrl,
- "receive_user_name": in.ReceiveUserName,
- "receive_position_id": in.ReceiveUserId,
- "file_url": in.FileUrl,
- "createtime": time.Now().Format(date.Date_Full_Layout),
- "create_user": in.CreateUser,
- "msg_id": msgId,
- "img_webpage": in.ImgWebpage,
- }
- mId = entity.BiService.Insert("operating_materials", saveMap)
- if mId < 0 {
- return 0, 0, errors.New("插入物料表operating_materials出错")
- }
- return msgId, mId, nil
- }
- func GetSendUserId(positionIds string, entId int64) []string {
- //拿职位id找mgoid
- userIdArr := []string{}
- query := fmt.Sprintf("SELECT userid FROM data_service.user_system WHERE position_id in (%s) AND ent_id = %d", positionIds, entId)
- log.Println("查找分发人的sql", query)
- useridMap := entity.JyBiTidb.SelectBySql(query)
- if useridMap != nil && len(*useridMap) > 0 {
- for _, val := range *useridMap {
- userIdArr = append(userIdArr, gconv.String(val["userid"]))
- }
- }
- return userIdArr
- }
- func PersonImageSave(imgUrl string, msgId, positionId, materialsId int64) bool {
- saveMap := map[string]interface{}{
- "file_url": imgUrl,
- "msg_id": msgId,
- "position_id": positionId,
- "materials_id": materialsId,
- "createtime": time.Now().Format(date.Date_Full_Layout),
- }
- return entity.BiService.Insert("operating_materials_attachment", saveMap) > 0
- }
- func GetPersonCode(positionId int64, name, userId string) string {
- //根据职位id获取到对应的渠道码
- code := ""
- data := entity.JyBiTidb.FindOne("dwd_d_userbase_belongto_rulecode", map[string]interface{}{"user_id": positionId}, "code", "")
- if data != nil && len(*data) > 0 {
- code = gconv.String((*data)["code"])
- } else {
- //没有code,生成一个
- code = generateRandomString(6)
- entity.JyBiMysql.Insert("dwd_d_userbase_belongto_rulecode", map[string]interface{}{
- "code": code,
- "pcode": "04",
- "level": "2",
- "name": name,
- "remark": "人员渠道码",
- "SZ_LEVEL": 1,
- "SZ_LEAF": 1,
- "SZ_PID0": "04",
- "SZ_PID1": code,
- "position_id": positionId,
- "user_id": userId,
- })
- }
- return code
- }
- func generateRandomString(length int) string {
- const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
- b := make([]byte, length)
- for i := range b {
- // 安全地生成随机索引 (0 到 len(charset)-1)
- idx, _ := rand.Int(rand.Reader, big.NewInt(int64(len(charset))))
- b[i] = charset[idx.Int64()]
- }
- return string(b)
- }
- func GetUserIds(positionIds string) map[int]string {
- res := map[int]string{}
- data := entity.BiService.SelectBySql("SELECT userid,position_id FROM data_service.`user_system` FROM status = 1 AND position_id in (?)", positionIds)
- if data != nil && len(*data) > 0 {
- for _, v := range *data {
- res[common.IntAll(v["position_id"])] = common.InterfaceToStr(v["userid"])
- }
- }
- return res
- }
|