Browse Source

wip:消息分发接口开发

wangkaiyue 2 years ago
parent
commit
5a74916ef7

+ 13 - 3
jyBXSubscribe/api/internal/logic/msgDistributorLogic.go

@@ -2,6 +2,7 @@ package logic
 
 
 import (
 import (
 	"context"
 	"context"
+	"jyBXSubscribe/rpc/type/bxsubscribe"
 
 
 	"jyBXSubscribe/api/internal/svc"
 	"jyBXSubscribe/api/internal/svc"
 	"jyBXSubscribe/api/internal/types"
 	"jyBXSubscribe/api/internal/types"
@@ -24,7 +25,16 @@ func NewMsgDistributorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ms
 }
 }
 
 
 func (l *MsgDistributorLogic) MsgDistributor(req *types.MsgDistributor) (resp *types.CommonResp, err error) {
 func (l *MsgDistributorLogic) MsgDistributor(req *types.MsgDistributor) (resp *types.CommonResp, err error) {
-	// todo: add your logic here and delete this line
-
-	return
+	res, err := l.svcCtx.Suscribe.MsgDistributor(l.ctx, &bxsubscribe.MsgDistributorReq{
+		AppId:     req.AppId,
+		EntId:     req.EntId,
+		EntUserId: req.EntUserId,
+		MessageId: req.MessageId,
+		Staffs:    req.Staffs,
+	})
+	return &types.CommonResp{
+		Err_code: res.ErrorCode,
+		Err_msg:  res.ErrorMsg,
+		Data:     nil,
+	}, err
 }
 }

+ 69 - 3
jyBXSubscribe/rpc/internal/logic/msgdistributorlogic.go

@@ -1,7 +1,12 @@
 package logic
 package logic
 
 
 import (
 import (
+	"app.yhyue.com/moapp/jybase/common"
 	"context"
 	"context"
+	"database/sql"
+	IC "jyBXSubscribe/rpc/init"
+	"jyBXSubscribe/rpc/model"
+	"strings"
 
 
 	"jyBXSubscribe/rpc/internal/svc"
 	"jyBXSubscribe/rpc/internal/svc"
 	"jyBXSubscribe/rpc/type/bxsubscribe"
 	"jyBXSubscribe/rpc/type/bxsubscribe"
@@ -25,7 +30,68 @@ func NewMsgDistributorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ms
 
 
 // 信息分发
 // 信息分发
 func (l *MsgDistributorLogic) MsgDistributor(in *bxsubscribe.MsgDistributorReq) (*bxsubscribe.StatusResp, error) {
 func (l *MsgDistributorLogic) MsgDistributor(in *bxsubscribe.MsgDistributorReq) (*bxsubscribe.StatusResp, error) {
-	// todo: add your logic here and delete this line
-
-	return &bxsubscribe.StatusResp{}, nil
+	userEnt := model.EntInfo(common.IntAll(in.EntId), common.IntAll(in.EntUserId))
+	if !(userEnt.Role_admin_system || userEnt.Role_admin_department) {
+		return &bxsubscribe.StatusResp{ErrorCode: -1, ErrorMsg: "无权限"}, nil
+	}
+	//根据信息查询区域列表
+	var regin, infoIds []string
+	var pushCas []*model.PushCa
+	for _, id := range strings.Split(in.MessageId, ",") {
+		if id != "" {
+			infoIds = append(infoIds, id)
+			pushCas = append(pushCas, &model.PushCa{InfoId: id})
+		}
+	}
+	if len(infoIds) == 0 || in.Staffs == "" {
+		return &bxsubscribe.StatusResp{ErrorCode: -1, ErrorMsg: "缺少参数"}, nil
+	}
+	infoList := model.NewSubscribePush().GetInfoByIds(IC.MgoBidding, IC.DB.Mongo.Bidding.Collection, IC.DB.Mongo.Bidding.CollectionBack, pushCas)
+	for _, info := range infoList {
+		if info.Area != "" && info.Area != "全国" {
+			regin = append(regin, info.Area)
+		}
+	}
+	//区域人员校验
+	userArr := model.Distributor(regin, common.IntAll(in.EntId), common.IntAll(in.EntUserId))
+	for _, uid := range strings.Split(in.Staffs, ",") {
+		check := false
+		for _, user := range userArr {
+			if user.Id == common.IntAll(uid) {
+				check = true
+				break
+			}
+		}
+		if !check {
+			return &bxsubscribe.StatusResp{ErrorCode: -1, ErrorMsg: "选择人员异常"}, nil
+		}
+	}
+	//查询分发信息内容
+	msgRes := IC.BaseServiceMysql.SelectBySql("SELECT p.* FROM pushentniche p,(SELECT infoid,MIN(id) as id FROM pushentniche WHERE infoid in ('5f4f603fc01454407374b7d2','5f4f1860c014544073748bbe') GROUP BY infoid) b WHERE p.id=b.id", strings.Join(infoIds, "','"))
+	if msgRes == nil || len(*msgRes) == 0 {
+		return &bxsubscribe.StatusResp{ErrorCode: -1, ErrorMsg: "获取分发信息内容异常"}, nil
+	}
+	//分发数据库修改
+	ok := IC.BaseServiceMysql.ExecTx("分发数据库修改", func(tx *sql.Tx) bool {
+		insertRow := []string{"entid", "deptid", "infoid", "matchkeys", "date", "type", "product", "matchways", "matchitems", "disid", "source", "userid", "isvisit", "visittime"}
+		msgItems := []string{"entid", "deptid", "infoid", "matchkeys", "date", "type", "product", "matchways", "matchitems", "disid"}
+		for _, m := range *msgRes {
+			var msgValues, insertValue []interface{}
+			for _, key := range msgItems {
+				msgValues = append(msgValues, m[key])
+			}
+			for _, uid := range userArr {
+				insertValue = append(insertValue, msgValues)
+				insertValue = append(insertValue, []interface{}{3, uid, nil, nil})
+			}
+			if affected, _ := IC.BaseServiceMysql.InsertBatchByTx(tx, "pushentniche", insertRow, insertValue); affected == 0 {
+				return false
+			}
+		}
+		return true
+	})
+	if !ok {
+		return &bxsubscribe.StatusResp{ErrorCode: -1, ErrorMsg: "数据分发异常"}, nil
+	}
+	return &bxsubscribe.StatusResp{Status: 1}, nil
 }
 }

+ 5 - 0
jyBXSubscribe/rpc/model/push.go

@@ -510,6 +510,7 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 		}
 		}
 
 
 		if spqp.IsEnt {
 		if spqp.IsEnt {
+
 			isNew := 1
 			isNew := 1
 			//商机管理判断
 			//商机管理判断
 			newCount := IC.MainMysql.CountBySql("select  count(id) from  entniche_info where  id =? and  isNew != 1 and  status=1", spqp.EntId)
 			newCount := IC.MainMysql.CountBySql("select  count(id) from  entniche_info where  id =? and  isNew != 1 and  status=1", spqp.EntId)
@@ -525,6 +526,10 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 			}
 			}
 			//判断是企业管理员还是部门管理员 部门管理员获取所有子部门
 			//判断是企业管理员还是部门管理员 部门管理员获取所有子部门
 			userEnt := EntInfo(common.IntAll(spqp.EntId), common.IntAll(spqp.EntUserId))
 			userEnt := EntInfo(common.IntAll(spqp.EntId), common.IntAll(spqp.EntUserId))
+			if !(userEnt.Role_admin_system || userEnt.Role_admin_department) {
+				result = []*bxsubscribe.SubscribeInfo{}
+				return
+			}
 			if userEnt.Role_admin_department && len(spqp.Staffs) == 0 { //部门管理员 获取所有部门和子部门员工
 			if userEnt.Role_admin_department && len(spqp.Staffs) == 0 { //部门管理员 获取所有部门和子部门员工
 				users := GetDisUsers(common.IntAll(spqp.EntId), userEnt.Dept.Id)
 				users := GetDisUsers(common.IntAll(spqp.EntId), userEnt.Dept.Id)
 				var userIds []string
 				var userIds []string