Browse Source

信息发布相关功能

zangkai 5 năm trước cách đây
mục cha
commit
a63f0b33e9

+ 124 - 0
backend/src/dashoo.cn/modi_webapi/app/api/information/information.go

@@ -0,0 +1,124 @@
+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"
+	"github.com/gogf/gf/os/glog"
+)
+
+// 信息管理API管理对象
+type Controller struct {
+}
+
+// 注册请求参数,用于前后端交互参数格式约定
+type GetListRequest struct {
+	information.SearchReq
+}
+
+//保存及修改信息
+func (c *Controller) Save(r *ghttp.Request) {
+	// tenant 租户模式
+	tenant := r.Header.Get("Tenant")
+	var addOrUpdateReq *information.AddOrUpdateReq
+	// 赋值并// 校验参数
+	if err := r.Parse(&addOrUpdateReq); err != nil {
+		response.Json(r, -1, err.Error())
+	}
+
+	// 初始化学生service
+	servcie, err := service.NewInformationService(tenant)
+	if err != nil {
+		response.Json(r, 1, err.Error())
+	}
+
+	// 判断是新增还是删除,获取的id为空新增,不为空则更新
+	if addOrUpdateReq.Id > 0 {
+		if newStudent, err := servcie.Update(addOrUpdateReq); err != nil {
+			response.Json(r, 1, err.Error())
+		} else {
+			response.Json(r, 0, "更新成功", newStudent)
+		}
+	} else {
+		addOrUpdateReq.Id = 0
+		if newId, err := servcie.Add(addOrUpdateReq); err != nil {
+			response.Json(r, 1, err.Error())
+		} else {
+			response.Json(r, 0, "新建成功", newId)
+		}
+	}
+
+}
+
+// DeleteStudentById 删除信息,更新信息删除状态isDel=1
+func (c *Controller) DeleteById(r *ghttp.Request) {
+	// tenant 租户模式
+	tenant := r.Header.Get("Tenant")
+	Ids := r.GetInts("ids")
+
+	// 初始化学生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 {
+		response.Json(r, 1, err.Error())
+	} else {
+		response.Json(r, 0, "删除成功")
+	}
+}
+
+// GetDetailById 根据id信息详情
+func (c *Controller) GetDetailById(r *ghttp.Request) {
+	// tenant 租户模式
+	tenant := r.Header.Get("Tenant")
+	// 学生id
+	StId := r.GetInt("id")
+	glog.Info(StId)
+	// 初始化学生service
+	servcie, err := service.NewInformationService(tenant)
+	if err != nil {
+		response.Json(r, 1, err.Error())
+	}
+	// 调用service方法
+	if information, err := servcie.GetByID(StId); err != nil {
+		response.Json(r, 1, err.Error())
+	} else {
+		response.Json(r, 0, "ok", information)
+	}
+
+}
+
+// GetPageList 分页查询信息列表
+func (c *Controller) GetPageList(r *ghttp.Request) {
+	// tenant 租户模式
+	tenant := r.Header.Get("Tenant")
+	// 初始化学生service
+	servcie, err := service.NewInformationService(tenant)
+	if err != nil {
+		response.Json(r, 1, err.Error())
+	}
+	// 分页查询信息列表
+	var selectPageReq information.SelectPageReq
+	// 赋值并// 校验参数
+	if err := r.Parse(&selectPageReq); err != nil {
+		response.Json(r, -1, err.Error())
+	}
+	if informationList, total, err := servcie.GetPageList(&selectPageReq); err != nil {
+		response.Json(r, -1, err.Error())
+	} else {
+		var records response.PagedRecords
+		records.Current = selectPageReq.Page.Current
+		records.Size = selectPageReq.Page.PagesSize
+		if total > 0 {
+			records.Total = total
+			records.Records = informationList
+		}
+		response.Json(r, 0, "ok", records)
+	}
+}

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

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

+ 57 - 0
backend/src/dashoo.cn/modi_webapi/app/common/utils.go

@@ -0,0 +1,57 @@
+package common
+
+import (
+	"bytes"
+	"strings"
+)
+
+// UnMarshal 驼峰转下划线字符串
+func UnMarshal(name string) string {
+	const (
+		lower = false
+		upper = true
+	)
+
+	if name == "" {
+		return ""
+	}
+
+	var (
+		value                                    = name
+		buf                                      = bytes.NewBufferString("")
+		lastCase, currCase, nextCase, nextNumber bool
+	)
+
+	for i, v := range value[:len(value)-1] {
+		nextCase = bool(value[i+1] >= 'A' && value[i+1] <= 'Z')
+		nextNumber = bool(value[i+1] >= '0' && value[i+1] <= '9')
+
+		if i > 0 {
+			if currCase == upper {
+				if lastCase == upper && (nextCase == upper || nextNumber == upper) {
+					buf.WriteRune(v)
+				} else {
+					if value[i-1] != '_' && value[i+1] != '_' {
+						buf.WriteRune('_')
+					}
+					buf.WriteRune(v)
+				}
+			} else {
+				buf.WriteRune(v)
+				if i == len(value)-2 && (nextCase == upper && nextNumber == lower) {
+					buf.WriteRune('_')
+				}
+			}
+		} else {
+			currCase = upper
+			buf.WriteRune(v)
+		}
+		lastCase = currCase
+		currCase = nextCase
+	}
+
+	buf.WriteByte(value[len(value)-1])
+
+	s := strings.ToLower(buf.String())
+	return s
+}

+ 16 - 0
backend/src/dashoo.cn/modi_webapi/app/model/base/base.go

@@ -0,0 +1,16 @@
+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"` //
+}

+ 39 - 0
backend/src/dashoo.cn/modi_webapi/app/model/information/information.go

@@ -0,0 +1,39 @@
+package information
+
+import "github.com/gogf/gf/os/gtime"
+import "dashoo.cn/modi_webapi/app/model/base"
+
+// 查询信息列表
+type SearchReq struct {
+	Title string
+}
+
+// 查询信息
+type SearchEntity struct {
+	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"`      //
+	CreateTime *gtime.Time `orm:"CreatedTime"   json:"createdtime"` //
+}
+
+// 新增/修改信息请求参数
+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"` //
+}
+
+type SelectPageReq struct {
+	Tenant  string         `protobuf:"bytes,1,opt,name=tenant,proto3" json:"tenant,omitempty"`
+	Title   string         `orm:"Title"         json:"title"`   //
+	Content string         `orm:"Content"       json:"content"` //
+	Status  int            `orm:"Status"        json:"status"`  //
+	Page    *base.PageInfo `protobuf:"bytes,3,opt,name=page" json:"page,omitempty"`
+	Prop    string         `json:prop`
+	Order   string         `json:order`
+}

+ 62 - 0
backend/src/dashoo.cn/modi_webapi/app/model/information/information_entity.go

@@ -0,0 +1,62 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. You may not really want to edit it.
+// ==========================================================================
+
+package information
+
+import (
+	"database/sql"
+	"github.com/gogf/gf/database/gdb"
+	"github.com/gogf/gf/os/gtime"
+)
+
+// Entity is the golang structure for table class.
+type Entity struct {
+	Id         int         `orm:"id,primary"  json:"id"`          //
+	Name       string      `orm:"name"        json:"name"`        // 班级名称
+	IsDel      int         `orm:"is_del"      json:"is_del"`      // 是否删除:1删除0未删除
+	CreateTime *gtime.Time `orm:"create_time" json:"create_time"` // 创建时间
+	UpdateTime *gtime.Time `orm:"update_time" json:"update_time"` // 更新时间
+}
+
+// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+// the data and where attributes for empty values.
+func (r *Entity) OmitEmpty() *arModel {
+	return Model.Data(r).OmitEmpty()
+}
+
+// Inserts does "INSERT...INTO..." statement for inserting current object into table.
+func (r *Entity) Insert() (result sql.Result, err error) {
+	return Model.Data(r).Insert()
+}
+
+// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
+func (r *Entity) InsertIgnore() (result sql.Result, err error) {
+	return Model.Data(r).InsertIgnore()
+}
+
+// Replace does "REPLACE...INTO..." statement for inserting current object into table.
+// If there's already another same record in the table (it checks using primary key or unique index),
+// it deletes it and insert this one.
+func (r *Entity) Replace() (result sql.Result, err error) {
+	return Model.Data(r).Replace()
+}
+
+// Save does "INSERT...INTO..." statement for inserting/updating current object into table.
+// It updates the record if there's already another same record in the table
+// (it checks using primary key or unique index).
+func (r *Entity) Save() (result sql.Result, err error) {
+	return Model.Data(r).Save()
+}
+
+// Update does "UPDATE...WHERE..." statement for updating current object from table.
+// It updates the record if there's already another same record in the table
+// (it checks using primary key or unique index).
+func (r *Entity) Update() (result sql.Result, err error) {
+	return Model.Data(r).Where(gdb.GetWhereConditionOfStruct(r)).Update()
+}
+
+// Delete does "DELETE FROM...WHERE..." statement for deleting current object from table.
+func (r *Entity) Delete() (result sql.Result, err error) {
+	return Model.Where(gdb.GetWhereConditionOfStruct(r)).Delete()
+}

+ 351 - 0
backend/src/dashoo.cn/modi_webapi/app/model/information/information_model.go

@@ -0,0 +1,351 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. You may not really want to edit it.
+// ==========================================================================
+
+package information
+
+import (
+	"database/sql"
+	"github.com/gogf/gf/database/gdb"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/frame/gmvc"
+	"time"
+)
+
+// arModel is a active record design model for table information operations.
+type arModel struct {
+	gmvc.M
+}
+
+var (
+	// Table is the table name of information.
+	Table = "information"
+	// Model is the model object of information.
+	Model = &arModel{g.DB("default").Table(Table).Safe()}
+	// Columns defines and stores column names for table information.
+	Columns = struct {
+		Id         string //
+		Name       string // 班级名称
+		IsDel      string // 是否删除:1删除0未删除
+		CreateTime string // 创建时间
+		UpdateTime string // 更新时间
+	}{
+		Id:         "id",
+		Name:       "name",
+		IsDel:      "is_del",
+		CreateTime: "create_time",
+		UpdateTime: "update_time",
+	}
+)
+
+// FindOne is a convenience method for Model.FindOne.
+// See Model.FindOne.
+func FindOne(where ...interface{}) (*Entity, error) {
+	return Model.FindOne(where...)
+}
+
+// FindAll is a convenience method for Model.FindAll.
+// See Model.FindAll.
+func FindAll(where ...interface{}) ([]*Entity, error) {
+	return Model.FindAll(where...)
+}
+
+// FindValue is a convenience method for Model.FindValue.
+// See Model.FindValue.
+func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
+	return Model.FindValue(fieldsAndWhere...)
+}
+
+// FindArray is a convenience method for Model.FindArray.
+// See Model.FindArray.
+func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
+	return Model.FindArray(fieldsAndWhere...)
+}
+
+// FindCount is a convenience method for Model.FindCount.
+// See Model.FindCount.
+func FindCount(where ...interface{}) (int, error) {
+	return Model.FindCount(where...)
+}
+
+// Insert is a convenience method for Model.Insert.
+func Insert(data ...interface{}) (result sql.Result, err error) {
+	return Model.Insert(data...)
+}
+
+// InsertIgnore is a convenience method for Model.InsertIgnore.
+func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
+	return Model.InsertIgnore(data...)
+}
+
+// Replace is a convenience method for Model.Replace.
+func Replace(data ...interface{}) (result sql.Result, err error) {
+	return Model.Replace(data...)
+}
+
+// Save is a convenience method for Model.Save.
+func Save(data ...interface{}) (result sql.Result, err error) {
+	return Model.Save(data...)
+}
+
+// Update is a convenience method for Model.Update.
+func Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
+	return Model.Update(dataAndWhere...)
+}
+
+// Delete is a convenience method for Model.Delete.
+func Delete(where ...interface{}) (result sql.Result, err error) {
+	return Model.Delete(where...)
+}
+
+// As sets an alias name for current table.
+func (m *arModel) As(as string) *arModel {
+	return &arModel{m.M.As(as)}
+}
+
+// TX sets the transaction for current operation.
+func (m *arModel) TX(tx *gdb.TX) *arModel {
+	return &arModel{m.M.TX(tx)}
+}
+
+// Master marks the following operation on master node.
+func (m *arModel) Master() *arModel {
+	return &arModel{m.M.Master()}
+}
+
+// Slave marks the following operation on slave node.
+// Note that it makes sense only if there's any slave node configured.
+func (m *arModel) Slave() *arModel {
+	return &arModel{m.M.Slave()}
+}
+
+// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
+func (m *arModel) LeftJoin(table ...string) *arModel {
+	return &arModel{m.M.LeftJoin(table...)}
+}
+
+// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
+func (m *arModel) RightJoin(table ...string) *arModel {
+	return &arModel{m.M.RightJoin(table...)}
+}
+
+// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
+func (m *arModel) InnerJoin(table ...string) *arModel {
+	return &arModel{m.M.InnerJoin(table...)}
+}
+
+// Fields sets the operation fields of the model, multiple fields joined using char ','.
+func (m *arModel) Fields(fields string) *arModel {
+	return &arModel{m.M.Fields(fields)}
+}
+
+// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
+func (m *arModel) FieldsEx(fields string) *arModel {
+	return &arModel{m.M.FieldsEx(fields)}
+}
+
+// Option sets the extra operation option for the model.
+func (m *arModel) Option(option int) *arModel {
+	return &arModel{m.M.Option(option)}
+}
+
+// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+// the data and where attributes for empty values.
+func (m *arModel) OmitEmpty() *arModel {
+	return &arModel{m.M.OmitEmpty()}
+}
+
+// Filter marks filtering the fields which does not exist in the fields of the operated table.
+func (m *arModel) Filter() *arModel {
+	return &arModel{m.M.Filter()}
+}
+
+// Where sets the condition statement for the model. The parameter <where> can be type of
+// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
+// multiple conditions will be joined into where statement using "AND".
+// Eg:
+// Where("uid=10000")
+// Where("uid", 10000)
+// Where("money>? AND name like ?", 99999, "vip_%")
+// Where("uid", 1).Where("name", "john")
+// Where("status IN (?)", g.Slice{1,2,3})
+// Where("age IN(?,?)", 18, 50)
+// Where(User{ Id : 1, UserName : "john"})
+func (m *arModel) Where(where interface{}, args ...interface{}) *arModel {
+	return &arModel{m.M.Where(where, args...)}
+}
+
+// And adds "AND" condition to the where statement.
+func (m *arModel) And(where interface{}, args ...interface{}) *arModel {
+	return &arModel{m.M.And(where, args...)}
+}
+
+// Or adds "OR" condition to the where statement.
+func (m *arModel) Or(where interface{}, args ...interface{}) *arModel {
+	return &arModel{m.M.Or(where, args...)}
+}
+
+// Group sets the "GROUP BY" statement for the model.
+func (m *arModel) Group(groupBy string) *arModel {
+	return &arModel{m.M.Group(groupBy)}
+}
+
+// Order sets the "ORDER BY" statement for the model.
+func (m *arModel) Order(orderBy string) *arModel {
+	return &arModel{m.M.Order(orderBy)}
+}
+
+// Limit sets the "LIMIT" statement for the model.
+// The parameter <limit> can be either one or two number, if passed two number is passed,
+// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
+// statement.
+func (m *arModel) Limit(limit ...int) *arModel {
+	return &arModel{m.M.Limit(limit...)}
+}
+
+// Offset sets the "OFFSET" statement for the model.
+// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
+func (m *arModel) Offset(offset int) *arModel {
+	return &arModel{m.M.Offset(offset)}
+}
+
+// Page sets the paging number for the model.
+// The parameter <page> is started from 1 for paging.
+// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
+func (m *arModel) Page(page, limit int) *arModel {
+	return &arModel{m.M.Page(page, limit)}
+}
+
+// Batch sets the batch operation number for the model.
+func (m *arModel) Batch(batch int) *arModel {
+	return &arModel{m.M.Batch(batch)}
+}
+
+// Cache sets the cache feature for the model. It caches the result of the sql, which means
+// if there's another same sql request, it just reads and returns the result from cache, it
+// but not committed and executed into the database.
+//
+// If the parameter <duration> < 0, which means it clear the cache with given <name>.
+// If the parameter <duration> = 0, which means it never expires.
+// If the parameter <duration> > 0, which means it expires after <duration>.
+//
+// The optional parameter <name> is used to bind a name to the cache, which means you can later
+// control the cache like changing the <duration> or clearing the cache with specified <name>.
+//
+// Note that, the cache feature is disabled if the model is operating on a transaction.
+func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
+	return &arModel{m.M.Cache(duration, name...)}
+}
+
+// Data sets the operation data for the model.
+// The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
+// Eg:
+// Data("uid=10000")
+// Data("uid", 10000)
+// Data(g.Map{"uid": 10000, "name":"john"})
+// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
+func (m *arModel) Data(data ...interface{}) *arModel {
+	return &arModel{m.M.Data(data...)}
+}
+
+// All does "SELECT FROM ..." statement for the model.
+// It retrieves the records from table and returns the result as []*Entity.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+func (m *arModel) All(where ...interface{}) ([]*Entity, error) {
+	all, err := m.M.All(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*Entity
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// One retrieves one record from table and returns the result as *Entity.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+func (m *arModel) One(where ...interface{}) (*Entity, error) {
+	one, err := m.M.One(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *Entity
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
+// Also see Model.WherePri and Model.One.
+func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
+	one, err := m.M.FindOne(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *Entity
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindAll retrieves and returns Result by by Model.WherePri and Model.All.
+// Also see Model.WherePri and Model.All.
+func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
+	all, err := m.M.FindAll(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*Entity
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// Chunk iterates the table with given size and callback function.
+func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
+	m.M.Chunk(limit, func(result gdb.Result, err error) bool {
+		var entities []*Entity
+		err = result.Structs(&entities)
+		if err == sql.ErrNoRows {
+			return false
+		}
+		return callback(entities, err)
+	})
+}
+
+// LockUpdate sets the lock for update for current operation.
+func (m *arModel) LockUpdate() *arModel {
+	return &arModel{m.M.LockUpdate()}
+}
+
+// LockShared sets the lock in share mode for current operation.
+func (m *arModel) LockShared() *arModel {
+	return &arModel{m.M.LockShared()}
+}
+
+// Unscoped enables/disables the soft deleting feature.
+func (m *arModel) Unscoped() *arModel {
+	return &arModel{m.M.Unscoped()}
+}

+ 102 - 0
backend/src/dashoo.cn/modi_webapi/app/service/information/information.go

@@ -0,0 +1,102 @@
+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"
+	"github.com/gogf/gf/errors/gerror"
+	"github.com/gogf/gf/os/gtime"
+)
+
+// 班级定义
+type InformationService struct {
+	db.ServiceBase
+}
+
+// NewinformationService 初始化informationService
+func NewInformationService(tenant string) (InformationService, error) {
+	var servcie InformationService
+	err := servcie.Init(tenant, information.Table)
+	return servcie, err
+}
+
+// GetPageList 分页信息列表
+func (s InformationService) GetPageList(param *information.SelectPageReq) (list []*information.SearchEntity, total int, err error) {
+
+	where := common.WhereString.ValidWhere
+	if title := param.Title; title != "" {
+		where += fmt.Sprintf(" AND title LIKE '%%%v%%'", title)
+	}
+	if content := param.Content; content != "" {
+		where += fmt.Sprintf(" AND content LIKE '%%%v%%'", content)
+	}
+	if status := param.Status; status > -1 {
+		where += fmt.Sprintf(" AND Status = %v", param.Status)
+	}
+	// 查询总数
+	total, err = s.SafeModel.Where(where).Count()
+	if err != nil {
+		return nil, -1, gerror.New("读取行数失败")
+	}
+	// todo more 增加查询条件
+	// 查询列表
+	model := s.SafeModel.Page(int(param.Page.Current), int(param.Page.PagesSize)).Where(where)
+	var result []*information.SearchEntity
+	err = model.Structs(&result)
+	// 如果未查到列表返回空
+	if err == sql.ErrNoRows {
+		return nil, 0, nil
+	}
+	return result, total, err
+
+}
+
+// Update 更新信息
+func (s InformationService) Update(param *information.AddOrUpdateReq) (*information.SearchEntity, error) {
+	information, err := s.GetByID(param.Id)
+	if err != nil {
+		return nil, err
+	}
+
+	// 设置更新时间
+	param.UpdateTime = gtime.Now()
+	param.CreateTime = information.CreateTime
+	if _, err = s.SafeModel.WherePri(param.Id).Update(param); err != nil {
+		return nil, err
+	}
+	return information, nil
+}
+
+// GetByID 通过id获取信息
+func (s InformationService) GetByID(id int) (res *information.SearchEntity, err error) {
+	// 关联查询
+	model := s.SafeModel.Where("s.Id", id).Where("s.IsDel", 0)
+	var result *information.SearchEntity
+	err = model.Struct(&result)
+	return result, nil
+}
+
+// 删除信息
+func (s InformationService) Delete(param *base.DeleteReq) error {
+	dIds := param.Ids
+	//设置更新时间
+	param.UpdateTime = gtime.Now()
+	if _, err := s.SafeModel.WherePri(dIds).Update("IsDel = 1"); err != nil {
+		return err
+	}
+	return nil
+}
+
+// Add 新增信息
+func (s InformationService) Add(param *information.AddOrUpdateReq) (id int64, err error) {
+	param.CreateTime = gtime.Now()
+	if result, err := s.SafeModel.Insert(param); err != nil {
+		return 0, err
+	} else {
+		id, _ = result.LastInsertId()
+	}
+	return id, nil
+}

+ 4 - 0
backend/src/dashoo.cn/modi_webapi/config/config.toml

@@ -12,6 +12,10 @@
 [database]
     [[database.default]]
         Debug = true
+#          link = "mysql:modi_user:Y6Ba64w1Hezo@tcp(39.98.34.197:3307)/modi_db"
+        link = "mysql:l_lims_u:TmBT65FNAAqJoBMl@tcp(rm-8vbk16zx2rbfu6jt6uo.mysql.zhangbei.rds.aliyuncs.com)/l_lims"
+    [[database.CU6zmPWhZp]]
+        Debug = true
 #          link = "mysql:modi_user:Y6Ba64w1Hezo@tcp(39.98.34.197:3307)/modi_db"
         link = "mysql:l_lims_u:TmBT65FNAAqJoBMl@tcp(rm-8vbk16zx2rbfu6jt6uo.mysql.zhangbei.rds.aliyuncs.com)/l_lims"
 

+ 7 - 8
backend/src/dashoo.cn/modi_webapi/library/gtoken/gtoken.go

@@ -49,7 +49,7 @@ type GfToken struct {
 	// 认证验证方法 return true 继续执行,否则结束执行
 	AuthBeforeFunc func(r *ghttp.Request) bool
 	// 认证返回方法
-	AuthAfterFunc    func(r *ghttp.Request, respData Resp)
+	AuthAfterFunc func(r *ghttp.Request, respData Resp)
 }
 
 // Init 初始化
@@ -168,8 +168,6 @@ func (m *GfToken) Start() bool {
 	return true
 }
 
-
-
 // 判断路径是否需要进行认证拦截
 // return true 需要认证
 func (m *GfToken) AuthPath(urlPath string) bool {
@@ -243,7 +241,7 @@ func (m *GfToken) GetOrGenToken(tenant, userKey, uuid string, resp *Resp) error
 	rsp, err := authClient.GetToken(context.TODO(), &auth.Request{
 		Tenant:  tenant,
 		UserKey: userKey,
-		Uuid: uuid,
+		Uuid:    uuid,
 		Data:    "",
 	})
 	if err != nil {
@@ -287,10 +285,11 @@ func (m *GfToken) Login(r *ghttp.Request) {
 		glog.Error("[GToken]Login tenant is empty")
 		return
 	}
-	if uuid == "" {
-		glog.Error("[GToken]Login uuid is empty")
-		return
-	}
+	// todo
+	//if uuid == "" {
+	//	glog.Error("[GToken]Login uuid is empty")
+	//	return
+	//}
 	respToken := new(Resp)
 	err := m.GetOrGenToken(tenant, userKey, uuid, respToken)
 	if err != nil {

+ 4 - 2
backend/src/dashoo.cn/modi_webapi/router/router.go

@@ -1,8 +1,9 @@
 package router
 
 import (
-	"dashoo.cn/modi_webapi/app/api/instrument"
 	"dashoo.cn/modi_webapi/app/api/demo"
+	"dashoo.cn/modi_webapi/app/api/information"
+	"dashoo.cn/modi_webapi/app/api/instrument"
 	"dashoo.cn/modi_webapi/app/api/microDemo"
 	"dashoo.cn/modi_webapi/app/api/neo"
 	"dashoo.cn/modi_webapi/app/api/system/item"
@@ -45,7 +46,7 @@ func init() {
 		{"ALL", "/permission", new(permission.Controller)},
 		{"ALL", "/organize", new(organize.Controller)},
 		{"ALL", "/menu", new(menu.Controller)},
-		{"All", "/instrument", new ( instrument.Controller) },
+		{"All", "/instrument", new(instrument.Controller)},
 		// 配置测试路由
 		{"ALL", "/class", new(demo.ClassController)},
 		{"ALL", "/student", new(demo.StudentController)},
@@ -59,6 +60,7 @@ func init() {
 		{"ALL", "/itemdetail", new(ItemDetail.ItemDetailController)},
 		// ====== 08-12 add 配置字典相关 e =====
 
+		{"ALL", "/information", new(information.Controller)},
 	})
 
 	//var u user.Controller