Browse Source

wip:消息分发接口自测提交

wangkaiyue 2 năm trước cách đây
mục cha
commit
6ae194ffec

+ 1 - 1
jyBXSubscribe/api/internal/logic/msgDistributorLogic.go

@@ -35,6 +35,6 @@ func (l *MsgDistributorLogic) MsgDistributor(req *types.MsgDistributor) (resp *t
 	return &types.CommonResp{
 		Err_code: res.ErrorCode,
 		Err_msg:  res.ErrorMsg,
-		Data:     nil,
+		Data:     res.Status,
 	}, err
 }

+ 22 - 13
jyBXSubscribe/rpc/internal/logic/msgdistributorlogic.go

@@ -2,11 +2,14 @@ package logic
 
 import (
 	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/encrypt"
 	"context"
 	"database/sql"
+	"fmt"
 	IC "jyBXSubscribe/rpc/init"
 	"jyBXSubscribe/rpc/model"
 	"strings"
+	"time"
 
 	"jyBXSubscribe/rpc/internal/svc"
 	"jyBXSubscribe/rpc/type/bxsubscribe"
@@ -35,12 +38,16 @@ func (l *MsgDistributorLogic) MsgDistributor(in *bxsubscribe.MsgDistributorReq)
 		return &bxsubscribe.StatusResp{ErrorCode: -1, ErrorMsg: "无权限"}, nil
 	}
 	//根据信息查询区域列表
-	var regin, infoIds []string
+	var regin, infoIds, staffs []string
+	staffs = strings.Split(in.Staffs, ",")
 	var pushCas []*model.PushCa
-	for _, id := range strings.Split(in.MessageId, ",") {
-		if id != "" {
-			infoIds = append(infoIds, id)
-			pushCas = append(pushCas, &model.PushCa{InfoId: id})
+	for _, eid := range strings.Split(in.MessageId, ",") {
+		if eid != "" {
+			array := encrypt.DecodeArticleId2ByCheck(eid)
+			if len(array) == 1 && array[0] != "" {
+				infoIds = append(infoIds, array[0])
+				pushCas = append(pushCas, &model.PushCa{InfoId: array[0]})
+			}
 		}
 	}
 	if len(infoIds) == 0 || in.Staffs == "" {
@@ -54,7 +61,7 @@ func (l *MsgDistributorLogic) MsgDistributor(in *bxsubscribe.MsgDistributorReq)
 	}
 	//区域人员校验
 	userArr := model.Distributor(regin, common.IntAll(in.EntId), common.IntAll(in.EntUserId))
-	for _, uid := range strings.Split(in.Staffs, ",") {
+	for _, uid := range staffs {
 		check := false
 		for _, user := range userArr {
 			if user.Id == common.IntAll(uid) {
@@ -67,24 +74,26 @@ func (l *MsgDistributorLogic) MsgDistributor(in *bxsubscribe.MsgDistributorReq)
 		}
 	}
 	//查询分发信息内容
-	msgRes := IC.BaseServiceMysql.SelectBySql("SELECT p.* FROM pushentniche p,(SELECT infoid,MIN(id) as id FROM pushentniche WHERE infoid in ('?') GROUP BY infoid) b WHERE p.id=b.id", strings.Join(infoIds, "','"))
+	msgRes := IC.BaseServiceMysql.SelectBySql(fmt.Sprintf("SELECT p.* FROM pushentniche p,(SELECT infoid,MIN(id) as id FROM pushentniche WHERE infoid in ('%s') and entid =? GROUP BY infoid) b WHERE p.id=b.id", strings.Join(infoIds, "','")), in.EntId)
 	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"}
+		insertRow := []string{"entid", "deptid", "infoid", "matchkeys", "type", "product", "matchways", "matchitems", "disid", "source", "date", "userid", "isvisit", "visittime"}
+		msgItems := []string{"entid", "deptid", "infoid", "matchkeys", "type", "product", "matchways", "matchitems", "disid"}
+		dateNew := time.Now().Unix()
 		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})
+			for _, uid := range staffs {
+				insertValue = append(insertValue, msgValues...)
+				insertValue = append(insertValue, []interface{}{3, dateNew, uid, nil, nil}...)
 			}
-			if affected, _ := IC.BaseServiceMysql.InsertBatchByTx(tx, "pushentniche", insertRow, insertValue); affected == 0 {
+			affected, _ := IC.BaseServiceMysql.InsertBatchByTx(tx, "pushentniche", insertRow, insertValue)
+			if affected == 0 {
 				return false
 			}
 		}

+ 8 - 8
jyBXSubscribe/rpc/model/push.go

@@ -124,7 +124,7 @@ type KeyParam struct {
 }
 
 func (spqp *SubPushQueryParam) IsEmpty() bool {
-	return (spqp.SelectTime == "" || spqp.SelectTime == "all") && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == ""
+	return (spqp.SelectTime == "" || spqp.SelectTime == "all") && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == "" && len(spqp.Staffs) == 0 && spqp.Source == "" && spqp.IsRead == ""
 }
 
 type subscribePush struct {
@@ -266,7 +266,7 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
 	start := (spqp.PageNum - 1) * spqp.PageSize
 	end := start + spqp.PageSize
 	//时间是今天,没有别的过滤条件--首先读取当前推送缓存数据 其次查询数据库
-	if nowFormat == date.FormatDateByInt64(&starttime, date.Date_Short_Layout) && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == "" {
+	if nowFormat == date.FormatDateByInt64(&starttime, date.Date_Short_Layout) && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == "" && len(spqp.Staffs) == 0 && spqp.Source == "" && spqp.IsRead == "" {
 		subPush := &SubPush{}
 		var err error
 		if spqp.IsEnt == false {
@@ -376,7 +376,7 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 		// 是否已读
 		if spqp.IsRead != "" {
 			if spqp.IsRead == "0" {
-				userStr += " and a.isvisit=0"
+				userStr += " and a.isvisit IS NULL"
 			} else if spqp.IsRead == "1" {
 				userStr += " and a.isvisit=1"
 			}
@@ -520,9 +520,9 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 			}
 			if isNew == 1 {
 				//企业主体是企业的企业查询
-				userStr = fmt.Sprintf("   a.entid='%s' and (a.source > 1) ", spqp.EntId)
+				userStr += fmt.Sprintf(" and  a.entid='%s' and (a.source > 1) ", spqp.EntId)
 			} else {
-				userStr = fmt.Sprintf("   a.entid='%s' ", spqp.EntId)
+				userStr += fmt.Sprintf(" and  a.entid='%s' ", spqp.EntId)
 			}
 			//判断是企业管理员还是部门管理员 部门管理员获取所有子部门
 			userEnt := EntInfo(common.IntAll(spqp.EntId), common.IntAll(spqp.EntUserId))
@@ -550,13 +550,13 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 			//查询数量(需要去重)
 			if len(querys) > 1 {
 				//countSql = fmt.Sprintf("select count(1) as count from %s  a STRAIGHT_JOIN %s b ON %s and a.infoid = b.infoid  %s where %s", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, userStr, leftJoinStr, strings.Join(querys, " and "))
-				countSql = fmt.Sprintf("SELECT count(1) AS count FROM (SELECT DISTINCT matchkeys,infoid FROM %s a WHERE 1=1 and %s )  a STRAIGHT_JOIN %s b ON  a.infoid = b.infoid  %s where %s", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, Baseinfo, leftJoinStr, strings.Join(querys, " and "))
+				countSql = fmt.Sprintf("SELECT count(1) AS count FROM (SELECT DISTINCT matchkeys,infoid FROM %s a WHERE 1=1 %s )  a STRAIGHT_JOIN %s b ON  a.infoid = b.infoid  %s where %s", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, Baseinfo, leftJoinStr, strings.Join(querys, " and "))
 			} else {
 				//countSql = fmt.Sprintf("select count(1) as count from %s  a where %s", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr)
-				countSql = fmt.Sprintf("SELECT count(1) AS count FROM ( SELECT DISTINCT matchkeys,infoid FROM %s a WHERE %s ) AS data", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr)
+				countSql = fmt.Sprintf("SELECT count(1) AS count FROM ( SELECT DISTINCT matchkeys,infoid FROM %s a WHERE 1=1 %s ) AS data", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr)
 			}
 			//列表查询
-			findSql = fmt.Sprintf("select a.infoid,a.matchkeys,b.isvalidfile as attachment_count from (SELECT DISTINCT matchkeys,infoid FROM %s a WHERE 1=1 and %s ) a STRAIGHT_JOIN %s b ON a.infoid = b.infoid  %s where %s"+
+			findSql = fmt.Sprintf("select a.infoid,a.matchkeys,b.isvalidfile as attachment_count from (SELECT DISTINCT matchkeys,infoid FROM %s a WHERE 1=1 %s ) a STRAIGHT_JOIN %s b ON a.infoid = b.infoid  %s where %s"+
 				" order by b.publishtime desc", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, Baseinfo, leftJoinStr, strings.Join(querys, " and "))
 		} else {
 			if spqp.BuySubject == 1 {