Forráskód Böngészése

信息发布后台功能

zangkai 5 éve
szülő
commit
31cdaa78b8

+ 8 - 10
backend/src/dashoo.cn/modi_webapi/app/api/information/information.go

@@ -2,7 +2,6 @@ package information
 
 import (
 	"dashoo.cn/micro_libary/response"
-	"dashoo.cn/modi_webapi/app/model/base"
 	"dashoo.cn/modi_webapi/app/model/information"
 	service "dashoo.cn/modi_webapi/app/service/information"
 	"github.com/gogf/gf/net/ghttp"
@@ -56,17 +55,16 @@ func (c *Controller) Save(r *ghttp.Request) {
 func (c *Controller) DeleteById(r *ghttp.Request) {
 	// tenant 租户模式
 	tenant := r.Header.Get("Tenant")
-	Ids := r.GetInts("ids")
+	id := r.GetInt("id")
+	glog.Info(id)
 
 	// 初始化学生service
 	servcie, err := service.NewInformationService(tenant)
 	if err != nil {
 		response.Json(r, 1, err.Error())
 	}
-	delReq := new(base.DeleteReq)
-	delReq.Ids = Ids
-	delReq.IsDel = 1
-	if err := servcie.Delete(delReq); err != nil {
+
+	if err := servcie.Delete(id); err != nil {
 		response.Json(r, 1, err.Error())
 	} else {
 		response.Json(r, 0, "删除成功")
@@ -78,15 +76,15 @@ func (c *Controller) GetDetailById(r *ghttp.Request) {
 	// tenant 租户模式
 	tenant := r.Header.Get("Tenant")
 	// 学生id
-	StId := r.GetInt("id")
-	glog.Info(StId)
+	id := r.GetInt("id")
+	glog.Info(id)
 	// 初始化学生service
 	servcie, err := service.NewInformationService(tenant)
 	if err != nil {
 		response.Json(r, 1, err.Error())
 	}
 	// 调用service方法
-	if information, err := servcie.GetByID(StId); err != nil {
+	if information, err := servcie.GetByID(id); err != nil {
 		response.Json(r, 1, err.Error())
 	} else {
 		response.Json(r, 0, "ok", information)
@@ -114,7 +112,7 @@ func (c *Controller) GetPageList(r *ghttp.Request) {
 	} else {
 		var records response.PagedRecords
 		records.Current = selectPageReq.Page.Current
-		records.Size = selectPageReq.Page.PagesSize
+		records.Size = selectPageReq.Page.Size
 		if total > 0 {
 			records.Total = total
 			records.Records = informationList

+ 2 - 0
backend/src/dashoo.cn/modi_webapi/app/common/commonstring.go

@@ -2,10 +2,12 @@ package common
 
 type whereString struct {
 	ValidWhere string
+	Invalid    string
 }
 
 var WhereString whereString
 
 func init() {
 	WhereString.ValidWhere = "IsDel = 0"
+	WhereString.Invalid = "IsDel = 1"
 }

+ 3 - 11
backend/src/dashoo.cn/modi_webapi/app/model/base/base.go

@@ -1,16 +1,8 @@
 package base
 
-import "github.com/gogf/gf/os/gtime"
-
 // 分页请求结构体
 type PageInfo struct {
-	Current   int `protobuf:"varint,1,opt,name=current,proto3" json:"current,omitempty"`
-	PagesSize int `protobuf:"varint,2,opt,name=pages_size,json=pagesSize,proto3" json:"pages_size,omitempty"`
-}
-
-// 删除请求结构体
-type DeleteReq struct {
-	Ids        []int       // 批量删除,id以逗号隔开
-	IsDel      int         `orm:"IsDel"`      // 是否删除 0未删除 1已删除
-	UpdateTime *gtime.Time `orm:"UpdateTime"` //
+	Current int `json:"current,omitempty"` //分页当前页
+	Total   int `json:"total,omitempty"`   //结果总数
+	Size    int `json:"size,omitempty"`    //分页记录数条数
 }

+ 8 - 7
backend/src/dashoo.cn/modi_webapi/app/model/information/information.go

@@ -19,17 +19,18 @@ type SearchEntity struct {
 
 // 新增/修改信息请求参数
 type AddOrUpdateReq struct {
-	Id         int
-	Title      string      `v:"required"` // 信息标题
-	Status     int         `v:"required"`
-	IsDel      int         `orm:"IsDel"`       // 是否删除 0未删除 1已删除
-	Content    string      `v:"required"`      // 信息内容               // 是否删除 0未删除 1已删除
-	CreateTime *gtime.Time `orm:"CreatedTime"` //
-	UpdateTime *gtime.Time `orm:"UpdatedTime"` //
+	Id         int         `json:"id"`
+	Title      string      `v:"required"     json:"title"` // 信息标题
+	Status     int         `v:"required"     json:"status"`
+	IsDel      int         `orm:"IsDel"`                     // 是否删除 0未删除 1已删除
+	Content    string      `v:"required"     json:"content"` // 信息内容
+	CreateTime *gtime.Time `orm:"CreatedTime"`               //
+	UpdateTime *gtime.Time `orm:"UpdatedTime"`               //
 }
 
 type SelectPageReq struct {
 	Tenant  string         `protobuf:"bytes,1,opt,name=tenant,proto3" json:"tenant,omitempty"`
+	Id      int            `orm:"Id,primary"    json:"id"`      //
 	Title   string         `orm:"Title"         json:"title"`   //
 	Content string         `orm:"Content"       json:"content"` //
 	Status  int            `orm:"Status"        json:"status"`  //

+ 5 - 7
backend/src/dashoo.cn/modi_webapi/app/service/information/information.go

@@ -3,7 +3,6 @@ package service
 import (
 	"dashoo.cn/micro_libary/db"
 	"dashoo.cn/modi_webapi/app/common"
-	"dashoo.cn/modi_webapi/app/model/base"
 	"dashoo.cn/modi_webapi/app/model/information"
 	"database/sql"
 	"fmt"
@@ -43,7 +42,7 @@ func (s InformationService) GetPageList(param *information.SelectPageReq) (list
 	}
 	// todo more 增加查询条件
 	// 查询列表
-	model := s.SafeModel.Page(int(param.Page.Current), int(param.Page.PagesSize)).Where(where)
+	model := s.SafeModel.Page(int(param.Page.Current), int(param.Page.Size)).Where(where)
 	var result []*information.SearchEntity
 	err = model.Structs(&result)
 	// 如果未查到列表返回空
@@ -73,18 +72,17 @@ func (s InformationService) Update(param *information.AddOrUpdateReq) (*informat
 // GetByID 通过id获取信息
 func (s InformationService) GetByID(id int) (res *information.SearchEntity, err error) {
 	// 关联查询
-	model := s.SafeModel.Where("s.Id", id).Where("s.IsDel", 0)
+	where := common.WhereString.ValidWhere
+	model := s.SafeModel.Where("id", id).Where(where)
 	var result *information.SearchEntity
 	err = model.Struct(&result)
 	return result, nil
 }
 
 // 删除信息
-func (s InformationService) Delete(param *base.DeleteReq) error {
-	dIds := param.Ids
+func (s InformationService) Delete(id int) error {
 	//设置更新时间
-	param.UpdateTime = gtime.Now()
-	if _, err := s.SafeModel.WherePri(dIds).Update("IsDel = 1"); err != nil {
+	if _, err := s.SafeModel.WherePri(id).Update(common.WhereString.Invalid); err != nil {
 		return err
 	}
 	return nil