Browse Source

fix:优化列表查询判断

duxin 3 years ago
parent
commit
1e15de242f

+ 20 - 20
rpc/consumer/internal/logic/mypublishlistlogic.go

@@ -29,64 +29,64 @@ func NewMyPublishListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MyP
 func (l *MyPublishListLogic) MyPublishList(in *consumer.MyPublishListReq) (*consumer.MyPublishListResp, error) {
 	// todo: add your logic here and delete this line
 	var (
-		quryname                                       string
+		quryName                                       string
 		data                                           consumer.MyPublishListResp
 		amount, inReview, approved, auditFailed, total int64
 		ListData                                       consumer.MyPublishListData
 	)
 	if in.Match != "" {
-		quryname = ` and title LIKE '%` + in.Match + `%' `
+		quryName = ` and title LIKE '%` + in.Match + `%' `
 	}
 	if in.MsgType != 0 {
-		quryname = quryname + ` and type=` + mc.InterfaceToStr(in.MsgType)
+		quryName = quryName + ` and type=` + mc.InterfaceToStr(in.MsgType)
 	}
 	if in.PageIndex == 1 {
 		//全部
-		amount = model.Mysql.CountBySql(`SELECT count(1)  from (SELECT id from information WHERE is_del = 1  and user_id= "` + in.UserId + `" ` + quryname + `
+		amount = model.Mysql.CountBySql(`SELECT count(1)  from (SELECT id from information WHERE is_del = 1  and user_id= "` + in.UserId + `" ` + quryName + `
 			union all
-			SELECT id from supply_info WHERE is_del = 1  and user_id= "` + in.UserId + `" ` + quryname + `) a`)
+			SELECT id from supply_info WHERE is_del = 1  and user_id= "` + in.UserId + `" ` + quryName + `) a`)
 		//审核中
-		inReview = model.Mysql.CountBySql(`SELECT count(1)  from (SELECT id  from information WHERE is_del = 1  and user_id= "` + in.UserId + `" ` + quryname + ` and status in (0,1,2,3,4) and published = 1
+		inReview = model.Mysql.CountBySql(`SELECT count(1)  from (SELECT id  from information WHERE is_del = 1  and user_id= "` + in.UserId + `" ` + quryName + ` and status in (0,1,2,3,4) and published = 1
 			union all
-			SELECT id  from supply_info WHERE is_del = 1  and user_id= "` + in.UserId + `" ` + quryname + `  and status in (0,1,2,3,4) and published = 1) a`)
+			SELECT id  from supply_info WHERE is_del = 1  and user_id= "` + in.UserId + `" ` + quryName + `  and status in (0,1,2,3,4) and published = 1) a`)
 		//审核通过
-		approved = model.Mysql.CountBySql(`SELECT count(1)  from (SELECT id  from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryname + ` and published = 2
+		approved = model.Mysql.CountBySql(`SELECT count(1)  from (SELECT id  from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + ` and published = 2
 			union all
-			SELECT id  from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryname + ` and published = 2) a`)
+			SELECT id  from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + ` and published = 2) a`)
 		//审核不通过
-		auditFailed = model.Mysql.CountBySql(`SELECT count(1)  from (SELECT id  from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryname + ` and status in (-1,-2) and published = 1` + `
+		auditFailed = model.Mysql.CountBySql(`SELECT count(1)  from (SELECT id  from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + ` and status in (-1,-2) and published = 1` + `
 			union all
-			SELECT id  from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryname + `  and status in (-1,-2) and published = 1) a`)
+			SELECT id  from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + `  and status in (-1,-2) and published = 1) a`)
 	}
 
 	if in.ReviewStatus != 0 {
 		if in.ReviewStatus == 1 {
-			quryname = quryname + ` and status in (0,1,2,3,4) and published = 1`
+			quryName = quryName + ` and status in (0,1,2,3,4) and published = 1`
 		} else if in.ReviewStatus == 2 {
-			quryname = quryname + ` and published = 2`
+			quryName = quryName + ` and published = 2`
 		} else if in.ReviewStatus == 3 {
-			quryname = quryname + ` and status in (-1,-2)`
+			quryName = quryName + ` and status in (-1,-2)`
 		}
 	}
 
-	if in.PageSize == 0 {
+	if in.PageSize <= 0 {
 		in.PageSize = 10
 	}
 	var offset int
-	if in.PageIndex == 1 {
+	if in.PageIndex <= 1 {
 		offset = 0
 	} else {
 		offset = mc.IntAll((in.PageIndex - 1) * in.PageSize)
 	}
 	if in.PageIndex == 1 {
-		count := model.Mysql.CountBySql(`SELECT count(1)  from (SELECT id,type,title,create_time,status,published  from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryname + `
+		count := model.Mysql.CountBySql(`SELECT count(1)  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`)
+			SELECT id,type,title,create_time,status,published  from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + ` ) a`)
 		total = mc.Int64All(mc.MathCeil(mc.Float64All(count) / mc.Float64All(in.PageSize)))
 	}
-	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+`
+	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)
+			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 {
 		for _, v := range *allData {
 			var vs = consumer.ListResp{}

+ 2 - 5
rpc/manager/internal/logic/infolistlogic.go

@@ -75,19 +75,16 @@ func (l *InfoListLogic) InfoList(in *manager.InfoListReq) (*manager.InfoListResp
 		queryInfo = fmt.Sprintf(" where %s", strings.Join(query, " and "))
 		//querySup = fmt.Sprintf(" where %s", strings.Join(supQuery, " and "))
 	}
-	if in.PageSize == 0 {
+	if in.PageSize <= 0 {
 		in.PageSize = 10
 	}
-	if in.PageIndex == 0 {
-		in.PageIndex = 1
-	}
 	if in.PageIndex == 1 {
 		count = model.Mysql.CountBySql(`SELECT count(1)  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`)
 	}
 	var offset int
-	if in.PageIndex == 1 {
+	if in.PageIndex <= 1 {
 		offset = 0
 	} else {
 		offset = common.IntAll((in.PageIndex - 1) * in.PageSize)