Эх сурвалжийг харах

fix:查询数据为空时列表赋值修改

duxin 3 жил өмнө
parent
commit
a192992711

+ 19 - 22
rpc/consumer/internal/logic/mypublishlistlogic.go

@@ -32,6 +32,7 @@ func (l *MyPublishListLogic) MyPublishList(in *consumer.MyPublishListReq) (*cons
 		quryname                                       string
 		data                                           consumer.MyPublishListResp
 		amount, inReview, approved, auditFailed, total int64
+		ListData                                       consumer.MyPublishListData
 	)
 	if in.Match != "" {
 		quryname = ` and title LIKE '%` + in.Match + `%' `
@@ -86,35 +87,31 @@ func (l *MyPublishListLogic) MyPublishList(in *consumer.MyPublishListReq) (*cons
 	allData := model.Mysql.SelectBySql(`SELECT a.id,a.type,a.title,a.create_time,a.published,a.status  from (SELECT id,type,title,create_time,status,published  from information WHERE is_del = 1 and user_id= "`+in.UserId+`" `+quryname+`
 			union all
 			SELECT id,type,title,create_time,status,published  from supply_info WHERE is_del = 1 and user_id= "`+in.UserId+`" `+quryname+` ) a  order by a.create_time desc limit ?,?`, offset, in.PageSize)
-	if allData == nil || len(*allData) == 0 {
-		return &data, nil
-	}
-
-	var ListData consumer.MyPublishListData
-	for _, v := range *allData {
-		var vs = consumer.ListResp{}
-		vs.Id = se.SE.EncodeString(mc.InterfaceToStr(v["id"])) //信息id加密
-		vs.ReviewStatus = 1
-		status := mc.IntAll(v["status"])
-		published := mc.IntAll(v["published"])
-		//1 审核中 2 已发布(审核通过)3 status(-1,-2) 审核不通过
-		if published == 2 {
-			vs.ReviewStatus = 2
-		} else if status == -2 || status == -1 {
-			vs.ReviewStatus = 3
+	if allData != nil && len(*allData) >= 0 {
+		for _, v := range *allData {
+			var vs = consumer.ListResp{}
+			vs.Id = se.SE.EncodeString(mc.InterfaceToStr(v["id"])) //信息id加密
+			vs.ReviewStatus = 1
+			status := mc.IntAll(v["status"])
+			published := mc.IntAll(v["published"])
+			//1 审核中 2 已发布(审核通过)3 status(-1,-2) 审核不通过
+			if published == 2 {
+				vs.ReviewStatus = 2
+			} else if status == -2 || status == -1 {
+				vs.ReviewStatus = 3
+			}
+			ListData.Total = total
+			vs.MsgType = mc.Int64All(v["type"])
+			vs.CreateTime = mc.InterfaceToStr(v["create_time"])
+			vs.Title = mc.InterfaceToStr(v["title"])
+			ListData.List = append(ListData.List, &vs)
 		}
-		ListData.Total = total
-		vs.MsgType = mc.Int64All(v["type"])
-		vs.CreateTime = mc.InterfaceToStr(v["create_time"])
-		vs.Title = mc.InterfaceToStr(v["title"])
-		ListData.List = append(ListData.List, &vs)
 	}
 
 	ListData.Amount = amount
 	ListData.Approved = approved
 	ListData.InReview = inReview
 	ListData.AuditFailed = auditFailed
-
 	data.Results = &ListData
 	return &data, nil
 }

+ 23 - 28
rpc/manager/internal/logic/infolistlogic.go

@@ -34,6 +34,7 @@ func (l *InfoListLogic) InfoList(in *manager.InfoListReq) (*manager.InfoListResp
 		query     []string
 		queryInfo string
 		count     int64
+		results   = []*manager.InfoList{}
 	)
 	if in.MsgType != 0 {
 		query = append(query, `type=`+common.InterfaceToStr(in.MsgType)+` `)
@@ -94,36 +95,30 @@ func (l *InfoListLogic) InfoList(in *manager.InfoListReq) (*manager.InfoListResp
 	allData := model.Mysql.SelectBySql(`SELECT a.id,a.type,a.status,a.phone,a.contact_person,a.contact_person,a.title,a.create_time  from (SELECT id,type,status,phone,contact_person,contact_phone,title,create_time  from information `+queryInfo+`
 			union all
 			SELECT id,type,status,phone,contact_person,contact_phone,title,create_time  from supply_info `+queryInfo+` ) a  order by a.create_time limit ?,? `, offset, in.PageSize)
-	if allData == nil || len(*allData) == 0 {
-		return &manager.InfoListResp{
-			ErrCode: 0,
-			ErrMsg:  "暂无数据",
-			Data:    nil,
-		}, nil
-	}
-
-	results := []*manager.InfoList{}
-	for _, v := range *allData {
-		res := manager.InfoList{}
-		var contact manager.Contact
-		if common.IntAll(v["type"]) == 1 || common.IntAll(v["type"]) == 2 {
-			res.Checked = model.Sensitive.Information
-		} else {
-			res.Checked = model.Sensitive.SupplyInfo
+	if allData != nil && len(*allData) > 0 {
+		for _, v := range *allData {
+			res := manager.InfoList{}
+			var contact manager.Contact
+			if common.IntAll(v["type"]) == 1 || common.IntAll(v["type"]) == 2 {
+				res.Checked = model.Sensitive.Information
+			} else {
+				res.Checked = model.Sensitive.SupplyInfo
+			}
+			res.Id = se.SE.EncodeString(common.InterfaceToStr(v["id"])) //信息id加密
+			res.Title = common.InterfaceToStr(v["title"])
+			res.MsgType = common.Int64All(v["type"])
+			res.Phone = common.InterfaceToStr(v["phone"])
+			res.ReviewStatus = common.Int64All(v["status"])
+			res.Published = common.Int64All(v["published"])
+			res.IsDel = common.Int64All(v["published"])
+			res.ApplyTime = common.InterfaceToStr(v["create_time"])
+			contact.Name = common.InterfaceToStr(v["contact_person"])
+			contact.Phone = common.InterfaceToStr(v["contact_phone"])
+			res.Contact = &contact
+			results = append(results, &res)
 		}
-		res.Id = se.SE.EncodeString(common.InterfaceToStr(v["id"])) //信息id加密
-		res.Title = common.InterfaceToStr(v["title"])
-		res.MsgType = common.Int64All(v["type"])
-		res.Phone = common.InterfaceToStr(v["phone"])
-		res.ReviewStatus = common.Int64All(v["status"])
-		res.Published = common.Int64All(v["published"])
-		res.IsDel = common.Int64All(v["published"])
-		res.ApplyTime = common.InterfaceToStr(v["create_time"])
-		contact.Name = common.InterfaceToStr(v["contact_person"])
-		contact.Phone = common.InterfaceToStr(v["contact_phone"])
-		res.Contact = &contact
-		results = append(results, &res)
 	}
+
 	data := manager.Data{}
 	data.Count = count
 	data.List = results