From 3acb8ad2cebf8f198c935849f0b4d67577b4082d Mon Sep 17 00:00:00 2001 From: yxh Date: Fri, 28 Feb 2020 23:06:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E5=85=B8=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/admin/cms_menu.go | 13 + app/controller/admin/cms_news.go | 12 + app/controller/admin/config_dict.go | 183 +++++++++ .../admin/sys_dict_data/sys_dict_data.go | 30 ++ .../sys_dict_data/sys_dict_data_entity.go | 65 ++++ .../sys_dict_data/sys_dict_data_model.go | 367 ++++++++++++++++++ .../admin/sys_dict_type/sys_dict_type.go | 28 ++ .../sys_dict_type/sys_dict_type_entity.go | 60 +++ .../sys_dict_type/sys_dict_type_model.go | 367 ++++++++++++++++++ app/service/admin/dict_service/dict_data.go | 137 +++++++ app/service/admin/dict_service/dict_type.go | 134 +++++++ config/config.toml | 1 + data/db.sql | 16 +- library/utils/function.go | 10 + router/router.go | 3 + test/demo2_test.go | 10 +- 16 files changed, 1427 insertions(+), 9 deletions(-) create mode 100644 app/controller/admin/cms_menu.go create mode 100644 app/controller/admin/cms_news.go create mode 100644 app/controller/admin/config_dict.go create mode 100644 app/model/admin/sys_dict_data/sys_dict_data.go create mode 100644 app/model/admin/sys_dict_data/sys_dict_data_entity.go create mode 100644 app/model/admin/sys_dict_data/sys_dict_data_model.go create mode 100644 app/model/admin/sys_dict_type/sys_dict_type.go create mode 100644 app/model/admin/sys_dict_type/sys_dict_type_entity.go create mode 100644 app/model/admin/sys_dict_type/sys_dict_type_model.go create mode 100644 app/service/admin/dict_service/dict_data.go create mode 100644 app/service/admin/dict_service/dict_type.go diff --git a/app/controller/admin/cms_menu.go b/app/controller/admin/cms_menu.go new file mode 100644 index 0000000..9edc8e4 --- /dev/null +++ b/app/controller/admin/cms_menu.go @@ -0,0 +1,13 @@ +package admin + +import ( + "gfast/library/response" + "github.com/gogf/gf/net/ghttp" +) + +//cms栏目管理 +type CmsMenu struct{} + +func (c *CmsMenu) MenuList(r *ghttp.Request) { + response.SusJson(true, r, "栏目列表") +} diff --git a/app/controller/admin/cms_news.go b/app/controller/admin/cms_news.go new file mode 100644 index 0000000..50d11c7 --- /dev/null +++ b/app/controller/admin/cms_news.go @@ -0,0 +1,12 @@ +package admin + +import ( + "gfast/library/response" + "github.com/gogf/gf/net/ghttp" +) + +type CmsNews struct{} + +func (c CmsNews) NewsList(r *ghttp.Request) { + response.SusJson(true, r, "信息列表") +} diff --git a/app/controller/admin/config_dict.go b/app/controller/admin/config_dict.go new file mode 100644 index 0000000..7a84d22 --- /dev/null +++ b/app/controller/admin/config_dict.go @@ -0,0 +1,183 @@ +package admin + +import ( + "gfast/app/model/admin/sys_dict_data" + "gfast/app/model/admin/sys_dict_type" + "gfast/app/service/admin/dict_service" + "gfast/app/service/admin/user_service" + "gfast/library/response" + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/util/gvalid" +) + +type Dict struct{} + +//字典列表 +func (c *Dict) DictList(r *ghttp.Request) { + var req *sys_dict_type.SelectPageReq + //获取参数 + if err := r.Parse(&req); err != nil { + response.FailJson(true, r, err.(*gvalid.Error).FirstString()) + } + + total, page, list, err := dict_service.SelectListByPage(req) + if err != nil { + response.FailJson(true, r, err.Error()) + } + result := g.Map{ + "currentPage": page, + "total": total, + "list": list, + "searchStatus": map[string]string{"": "所有", "0": "停用", "1": "正常"}, + } + response.SusJson(true, r, "字典列表", result) +} + +//添加字典 +func (c *Dict) DictAdd(r *ghttp.Request) { + if r.Method == "POST" { + var req *sys_dict_type.AddReq + //获取参数 + if err := r.Parse(&req); err != nil { + response.FailJson(true, r, err.(*gvalid.Error).FirstString()) + } + if !dict_service.CheckDictTypeUniqueAll(req.DictType) { + response.FailJson(true, r, "字典类型已经存在") + } + userId := user_service.GetLoginID(r) //获取登陆用户id + _, err := dict_service.AddSave(req, userId) + if err != nil { + g.Log().Error(err.Error()) + response.FailJson(true, r, "字典类型添加失败") + } + response.SusJson(true, r, "添加字典成功") + } +} + +//修改字典 +func (c *Dict) DictEdit(r *ghttp.Request) { + if r.Method == "POST" { + var req *sys_dict_type.EditReq + //获取参数 + if err := r.Parse(&req); err != nil { + response.FailJson(true, r, err.(*gvalid.Error).FirstString()) + } + if !dict_service.CheckDictTypeUnique(req) { + response.FailJson(true, r, "字典类型已经存在") + } + userId := user_service.GetLoginID(r) //获取登陆用户id + _, err := dict_service.EditSave(req, userId) + if err != nil { + response.FailJson(true, r, err.Error()) + } + response.SusJson(true, r, "修改成功") + } + id := r.GetInt("id") + entity, err := dict_service.GetDictById(id) + if err != nil { + response.FailJson(true, r, "字典类型添加失败") + } + response.SusJson(true, r, "ok", g.Map{"dict": entity}) +} + +//字典数据列表 +func (c *Dict) DictDataList(r *ghttp.Request) { + var req *sys_dict_data.SelectDataPageReq + //获取参数 + if err := r.Parse(&req); err != nil { + response.FailJson(true, r, err.(*gvalid.Error).FirstString()) + } + + total, page, list, err := dict_service.SelectDataListByPage(req) + if err != nil { + response.FailJson(true, r, err.Error()) + } + result := g.Map{ + "currentPage": page, + "total": total, + "list": list, + "searchStatus": map[string]string{"": "所有", "0": "停用", "1": "正常"}, + } + response.SusJson(true, r, "ok", result) +} + +//添加数据字典 +func (c *Dict) DictDataAdd(r *ghttp.Request) { + if r.Method == "POST" { + var req *sys_dict_data.AddDataReq + //获取参数 + if err := r.Parse(&req); err != nil { + response.FailJson(true, r, err.(*gvalid.Error).FirstString()) + } + userId := user_service.GetLoginID(r) //获取登陆用户id + _, err := dict_service.AddSaveData(req, userId) + if err != nil { + response.FailJson(true, r, err.Error()) + } + response.SusJson(true, r, "添加字典数据成功") + } + dictType := r.GetQueryString("dictType") + res := g.Map{ + "listClassSelector": g.Map{"default": "默认", "primary": "主要", "success": "成功", "info": "信息", + "warning": "警告", "danger": "危险"}, + "dictType": dictType, + } + response.SusJson(true, r, "ok", res) +} + +//修改字典数据 +func (c *Dict) DictDataEdit(r *ghttp.Request) { + if r.Method == "POST" { + var req *sys_dict_data.EditDataReq + //获取参数 + if err := r.Parse(&req); err != nil { + response.FailJson(true, r, err.(*gvalid.Error).FirstString()) + } + userId := user_service.GetLoginID(r) + _, err := dict_service.EditSaveData(req, userId) + if err != nil { + response.FailJson(true, r, err.Error()) + } + response.SusJson(true, r, "修改字典数据成功") + + } + dictCode := r.GetInt("dictCode") + dictData, err := dict_service.GetDictDataById(dictCode) + if err != nil { + response.FailJson(true, r, err.Error()) + } + res := g.Map{ + "listClassSelector": g.Map{"default": "默认", "primary": "主要", "success": "成功", "info": "信息", + "warning": "警告", "danger": "危险"}, + "dictType": dictData.DictType, + "dictData": dictData, + } + response.SusJson(true, r, "ok", res) +} + +//删除字典 +func (c *Dict) DictDelete(r *ghttp.Request) { + dictIds := r.GetInts("dictIds") + if len(dictIds) == 0 { + response.FailJson(true, r, "删除失败") + } + err := dict_service.DeleteDictByIds(dictIds) + if err != nil { + response.FailJson(true, r, "删除失败") + } + response.SusJson(true, r, "删除成功") +} + +//删除字典数据 +func (c *Dict) DictDataDelete(r *ghttp.Request) { + dictCodes := r.GetInts("dictCode") + if len(dictCodes) == 0 { + response.FailJson(true, r, "删除失败") + } + err := dict_service.DeleteDictDataByIds(dictCodes) + if err != nil { + response.FailJson(true, r, "删除失败") + } + response.SusJson(true, r, "删除成功") +} diff --git a/app/model/admin/sys_dict_data/sys_dict_data.go b/app/model/admin/sys_dict_data/sys_dict_data.go new file mode 100644 index 0000000..24fc2cb --- /dev/null +++ b/app/model/admin/sys_dict_data/sys_dict_data.go @@ -0,0 +1,30 @@ +package sys_dict_data + +// Fill with you ideas below. + +//新增字典数据页面请求参数 +type AddDataReq struct { + DictLabel string `p:"dictLabel" v:"required#字典标签不能为空"` + DictValue string `p:"dictValue" v:"required#字典键值不能为空"` + DictType string `p:"dictType" v:"required#字典类型不能为空"` + DictSort int `p:"dictSort" v:"integer#排序只能为整数"` + CssClass string `p:"cssClass"` + ListClass string `p:"listClass" v:"required#回显样式不能为空"` + IsDefault int `p:"isDefault" v:"required|in:0,1#系统默认不能为空|默认值只能为0或1"` + Status int `p:"status" v:"required|in:0,1#状态不能为空|状态只能为0或1"` + Remark string `p:"remark"` +} + +type EditDataReq struct { + DictCode int `p:"dictCode" v:"required|min:1#主键ID不能为空|主键ID不能小于1"` + AddDataReq +} + +//分页请求参数 +type SelectDataPageReq struct { + DictType string `p:"dictType"` //字典名称 + DictLabel string `p:"dictLabel"` //字典标签 + Status string `p:"status"` //状态 + PageNum int `p:"page"` //当前页码 + PageSize int `p:"pageSize"` //每页数 +} diff --git a/app/model/admin/sys_dict_data/sys_dict_data_entity.go b/app/model/admin/sys_dict_data/sys_dict_data_entity.go new file mode 100644 index 0000000..3786390 --- /dev/null +++ b/app/model/admin/sys_dict_data/sys_dict_data_entity.go @@ -0,0 +1,65 @@ +// ========================================================================== +// This is auto-generated by gf cli tool. You may not really want to edit it. +// ========================================================================== + +package sys_dict_data + +import ( + "database/sql" + "github.com/gogf/gf/database/gdb" +) + +// Entity is the golang structure for table qxkj_sys_dict_data. +type Entity struct { + DictCode int64 `orm:"dict_code,primary" json:"dict_code"` // 字典编码 + DictSort int `orm:"dict_sort" json:"dict_sort"` // 字典排序 + DictLabel string `orm:"dict_label" json:"dict_label"` // 字典标签 + DictValue string `orm:"dict_value" json:"dict_value"` // 字典键值 + DictType string `orm:"dict_type" json:"dict_type"` // 字典类型 + CssClass string `orm:"css_class" json:"css_class"` // 样式属性(其他样式扩展) + ListClass string `orm:"list_class" json:"list_class"` // 表格回显样式 + IsDefault int `orm:"is_default" json:"is_default"` // 是否默认(1是 0否) + Status int `orm:"status" json:"status"` // 状态(0正常 1停用) + CreateBy int `orm:"create_by" json:"create_by"` // 创建者 + CreateTime uint64 `orm:"create_time" json:"create_time"` // 创建时间 + UpdateBy int `orm:"update_by" json:"update_by"` // 更新者 + UpdateTime uint64 `orm:"update_time" json:"update_time"` // 更新时间 + Remark string `orm:"remark" json:"remark"` // 备注 +} + +// 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() +} + +// 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() +} diff --git a/app/model/admin/sys_dict_data/sys_dict_data_model.go b/app/model/admin/sys_dict_data/sys_dict_data_model.go new file mode 100644 index 0000000..bf21a80 --- /dev/null +++ b/app/model/admin/sys_dict_data/sys_dict_data_model.go @@ -0,0 +1,367 @@ +// ========================================================================== +// This is auto-generated by gf cli tool. You may not really want to edit it. +// ========================================================================== + +package sys_dict_data + +import ( + "database/sql" + "github.com/gogf/gf/database/gdb" + "github.com/gogf/gf/frame/g" + "time" +) + +// arModel is a active record design model for table qxkj_sys_dict_data operations. +type arModel struct { + M *gdb.Model +} + +var ( + // Table is the table name of qxkj_sys_dict_data. + Table = "qxkj_sys_dict_data" + // Model is the model object of qxkj_sys_dict_data. + Model = &arModel{g.DB("default").Table(Table).Safe()} +) + +// 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...) +} + +// 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...) +} + +// 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. +func (m *arModel) LeftJoin(joinTable string, on string) *arModel { + return &arModel{m.M.LeftJoin(joinTable, on)} +} + +// RightJoin does "RIGHT JOIN ... ON ..." statement on the model. +func (m *arModel) RightJoin(joinTable string, on string) *arModel { + return &arModel{m.M.RightJoin(joinTable, on)} +} + +// InnerJoin does "INNER JOIN ... ON ..." statement on the model. +func (m *arModel) InnerJoin(joinTable string, on string) *arModel { + return &arModel{m.M.InnerJoin(joinTable, on)} +} + +// 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 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 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 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 < 0, which means it clear the cache with given . +// If the parameter = 0, which means it never expires. +// If the parameter > 0, which means it expires after . +// +// The optional parameter is used to bind a name to the cache, which means you can later +// control the cache like changing the or clearing the cache with specified . +// +// Note that, the cache feature is disabled if the model is operating on a transaction. +func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(expire, name...)} +} + +// Data sets the operation data for the model. +// The parameter 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...)} +} + +// Insert does "INSERT INTO ..." statement for the model. +// The optional parameter is the same as the parameter of Model.Data function, +// see Model.Data. +func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) { + return m.M.Insert(data...) +} + +// Replace does "REPLACE INTO ..." statement for the model. +// The optional parameter is the same as the parameter of Model.Data function, +// see Model.Data. +func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) { + return m.M.Replace(data...) +} + +// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. +// It updates the record if there's primary or unique index in the saving data, +// or else it inserts a new record into the table. +// +// The optional parameter is the same as the parameter of Model.Data function, +// see Model.Data. +func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) { + return m.M.Save(data...) +} + +// Update does "UPDATE ... " statement for the model. +// +// If the optional parameter is given, the dataAndWhere[0] is the updated +// data field, and dataAndWhere[1:] is treated as where condition fields. +// Also see Model.Data and Model.Where functions. +func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) { + return m.M.Update(dataAndWhere...) +} + +// Delete does "DELETE FROM ... " statement for the model. +// The optional parameter is the same as the parameter of Model.Where function, +// see Model.Where. +func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) { + return m.M.Delete(where...) +} + +// Count does "SELECT COUNT(x) FROM ..." statement for the model. +// The optional parameter is the same as the parameter of Model.Where function, +// see Model.Where. +func (m *arModel) Count(where ...interface{}) (int, error) { + return m.M.Count(where...) +} + +// 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 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 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 +} + +// Value retrieves a specified record value from table and returns the result as interface type. +// It returns nil if there's no record found with the given conditions from table. +// +// If the optional parameter is given, the fieldsAndWhere[0] is the selected fields +// and fieldsAndWhere[1:] is treated as where condition fields. +// Also see Model.Fields and Model.Where functions. +func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) { + return m.M.Value(fieldsAndWhere...) +} + +// 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 +} + +// FindValue retrieves and returns single field value by Model.WherePri and Model.Value. +// Also see Model.WherePri and Model.Value. +func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { + return m.M.FindValue(fieldsAndWhere...) +} + +// FindCount retrieves and returns the record number by Model.WherePri and Model.Count. +// Also see Model.WherePri and Model.Count. +func (m *arModel) FindCount(where ...interface{}) (int, error) { + return m.M.FindCount(where...) +} + +// 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) + }) +} diff --git a/app/model/admin/sys_dict_type/sys_dict_type.go b/app/model/admin/sys_dict_type/sys_dict_type.go new file mode 100644 index 0000000..80db190 --- /dev/null +++ b/app/model/admin/sys_dict_type/sys_dict_type.go @@ -0,0 +1,28 @@ +package sys_dict_type + +// Fill with you ideas below. + +//新增操作请求参数 +type AddReq struct { + DictName string `p:"dictName" v:"required#字典名称不能为空"` + DictType string `p:"dictType" v:"required#字典类型不能为空"` + Status uint `p:"status" v:"required|in:0,1#状态不能为空|状态只能为0或1"` + Remark string `p:"remark"` +} + +//修改操作请求参数 +type EditReq struct { + DictId int64 `p:"dictId" v:"required|min:1#主键ID不能为空|主键ID必须为大于0的值"` + AddReq +} + +//分页请求参数 +type SelectPageReq struct { + DictName string `p:"dictName"` //字典名称 + DictType string `p:"dictType"` //字典类型 + Status string `p:"status"` //字典状态 + BeginTime string `p:"beginTime"` //开始时间 + EndTime string `p:"endTime"` //结束时间 + PageNum int `p:"page"` //当前页码 + PageSize int `p:"pageSize"` //每页数 +} diff --git a/app/model/admin/sys_dict_type/sys_dict_type_entity.go b/app/model/admin/sys_dict_type/sys_dict_type_entity.go new file mode 100644 index 0000000..8f1381c --- /dev/null +++ b/app/model/admin/sys_dict_type/sys_dict_type_entity.go @@ -0,0 +1,60 @@ +// ========================================================================== +// This is auto-generated by gf cli tool. You may not really want to edit it. +// ========================================================================== + +package sys_dict_type + +import ( + "database/sql" + "github.com/gogf/gf/database/gdb" +) + +// Entity is the golang structure for table qxkj_sys_dict_type. +type Entity struct { + DictId uint64 `orm:"dict_id,primary" json:"dict_id"` // 字典主键 + DictName string `orm:"dict_name" json:"dict_name"` // 字典名称 + DictType string `orm:"dict_type,unique" json:"dict_type"` // 字典类型 + Status uint `orm:"status" json:"status"` // 状态(0正常 1停用) + CreateBy uint `orm:"create_by" json:"create_by"` // 创建者 + CreateTime uint64 `orm:"create_time" json:"create_time"` // 创建时间 + UpdateBy uint `orm:"update_by" json:"update_by"` // 更新者 + UpdateTime uint64 `orm:"update_time" json:"update_time"` // 更新时间 + Remark string `orm:"remark" json:"remark"` // 备注 +} + +// 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() +} + +// 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() +} diff --git a/app/model/admin/sys_dict_type/sys_dict_type_model.go b/app/model/admin/sys_dict_type/sys_dict_type_model.go new file mode 100644 index 0000000..cb857d1 --- /dev/null +++ b/app/model/admin/sys_dict_type/sys_dict_type_model.go @@ -0,0 +1,367 @@ +// ========================================================================== +// This is auto-generated by gf cli tool. You may not really want to edit it. +// ========================================================================== + +package sys_dict_type + +import ( + "database/sql" + "github.com/gogf/gf/database/gdb" + "github.com/gogf/gf/frame/g" + "time" +) + +// arModel is a active record design model for table qxkj_sys_dict_type operations. +type arModel struct { + M *gdb.Model +} + +var ( + // Table is the table name of qxkj_sys_dict_type. + Table = "qxkj_sys_dict_type" + // Model is the model object of qxkj_sys_dict_type. + Model = &arModel{g.DB("default").Table(Table).Safe()} +) + +// 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...) +} + +// 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...) +} + +// 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. +func (m *arModel) LeftJoin(joinTable string, on string) *arModel { + return &arModel{m.M.LeftJoin(joinTable, on)} +} + +// RightJoin does "RIGHT JOIN ... ON ..." statement on the model. +func (m *arModel) RightJoin(joinTable string, on string) *arModel { + return &arModel{m.M.RightJoin(joinTable, on)} +} + +// InnerJoin does "INNER JOIN ... ON ..." statement on the model. +func (m *arModel) InnerJoin(joinTable string, on string) *arModel { + return &arModel{m.M.InnerJoin(joinTable, on)} +} + +// 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 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 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 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 < 0, which means it clear the cache with given . +// If the parameter = 0, which means it never expires. +// If the parameter > 0, which means it expires after . +// +// The optional parameter is used to bind a name to the cache, which means you can later +// control the cache like changing the or clearing the cache with specified . +// +// Note that, the cache feature is disabled if the model is operating on a transaction. +func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(expire, name...)} +} + +// Data sets the operation data for the model. +// The parameter 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...)} +} + +// Insert does "INSERT INTO ..." statement for the model. +// The optional parameter is the same as the parameter of Model.Data function, +// see Model.Data. +func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) { + return m.M.Insert(data...) +} + +// Replace does "REPLACE INTO ..." statement for the model. +// The optional parameter is the same as the parameter of Model.Data function, +// see Model.Data. +func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) { + return m.M.Replace(data...) +} + +// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. +// It updates the record if there's primary or unique index in the saving data, +// or else it inserts a new record into the table. +// +// The optional parameter is the same as the parameter of Model.Data function, +// see Model.Data. +func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) { + return m.M.Save(data...) +} + +// Update does "UPDATE ... " statement for the model. +// +// If the optional parameter is given, the dataAndWhere[0] is the updated +// data field, and dataAndWhere[1:] is treated as where condition fields. +// Also see Model.Data and Model.Where functions. +func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) { + return m.M.Update(dataAndWhere...) +} + +// Delete does "DELETE FROM ... " statement for the model. +// The optional parameter is the same as the parameter of Model.Where function, +// see Model.Where. +func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) { + return m.M.Delete(where...) +} + +// Count does "SELECT COUNT(x) FROM ..." statement for the model. +// The optional parameter is the same as the parameter of Model.Where function, +// see Model.Where. +func (m *arModel) Count(where ...interface{}) (int, error) { + return m.M.Count(where...) +} + +// 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 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 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 +} + +// Value retrieves a specified record value from table and returns the result as interface type. +// It returns nil if there's no record found with the given conditions from table. +// +// If the optional parameter is given, the fieldsAndWhere[0] is the selected fields +// and fieldsAndWhere[1:] is treated as where condition fields. +// Also see Model.Fields and Model.Where functions. +func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) { + return m.M.Value(fieldsAndWhere...) +} + +// 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 +} + +// FindValue retrieves and returns single field value by Model.WherePri and Model.Value. +// Also see Model.WherePri and Model.Value. +func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { + return m.M.FindValue(fieldsAndWhere...) +} + +// FindCount retrieves and returns the record number by Model.WherePri and Model.Count. +// Also see Model.WherePri and Model.Count. +func (m *arModel) FindCount(where ...interface{}) (int, error) { + return m.M.FindCount(where...) +} + +// 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) + }) +} diff --git a/app/service/admin/dict_service/dict_data.go b/app/service/admin/dict_service/dict_data.go new file mode 100644 index 0000000..c97a675 --- /dev/null +++ b/app/service/admin/dict_service/dict_data.go @@ -0,0 +1,137 @@ +package dict_service + +import ( + "gfast/app/model/admin/sys_dict_data" + "gfast/app/model/admin/sys_dict_type" + "gfast/library/utils" + "github.com/gogf/gf/errors/gerror" + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/util/gconv" +) + +//添加字典数据操作 +func AddSaveData(req *sys_dict_data.AddDataReq, userId int) (int64, error) { + var entity sys_dict_data.Entity + entity.DictType = req.DictType + entity.Status = req.Status + entity.DictLabel = req.DictLabel + entity.CssClass = req.CssClass + entity.DictSort = req.DictSort + entity.DictValue = req.DictValue + entity.IsDefault = req.IsDefault + entity.ListClass = req.ListClass + entity.Remark = req.Remark + entity.CreateTime = gconv.Uint64(gtime.Timestamp()) + entity.CreateBy = userId + result, err := entity.Insert() + if err != nil { + g.Log().Error(err) + return 0, gerror.New("添加失败") + } + id, err := result.LastInsertId() + if err != nil { + g.Log().Error(err) + return 0, gerror.New("添加失败") + } + return id, nil +} + +//修改字典数据操作 +func EditSaveData(req *sys_dict_data.EditDataReq, userId int) (int64, error) { + entity, err := GetDictDataById(req.DictCode) + if err != nil { + return 0, err + } + entity.DictType = req.DictType + entity.Status = req.Status + entity.DictLabel = req.DictLabel + entity.CssClass = req.CssClass + entity.DictSort = req.DictSort + entity.DictValue = req.DictValue + entity.IsDefault = req.IsDefault + entity.ListClass = req.ListClass + entity.Remark = req.Remark + entity.UpdateTime = gconv.Uint64(gtime.Timestamp()) + entity.UpdateBy = userId + result, err := entity.Update() + if err != nil { + g.Log().Error(err) + return 0, gerror.New("修改失败") + } + return result.RowsAffected() +} + +//通过字典数据主键获取数据 +func GetDictDataById(dictCode int) (*sys_dict_data.Entity, error) { + entity, err := sys_dict_data.Model.FindOne("dict_code", dictCode) + if err != nil { + g.Log().Error(err) + return nil, gerror.New("获取字典数据失败") + } + if entity == nil { + return nil, gerror.New("获取字典数据失败") + } + return entity, nil +} + +//字典数据列表查询分页 +func SelectDataListByPage(req *sys_dict_data.SelectDataPageReq) (total, page int, list []*sys_dict_data.Entity, err error) { + model := sys_dict_data.Model + if req != nil { + if req.DictLabel != "" { + model = model.Where("dict_label like ?", "%"+req.DictLabel+"%") + } + if req.Status != "" { + model = model.Where("status = ", gconv.Int(req.Status)) + } + if req.DictType != "" { + model = model.Where("dict_type = ?", req.DictType) + } + total, err = model.Count() + if err != nil { + g.Log().Error(err) + err = gerror.New("获取总行数失败") + return + } + if req.PageNum == 0 { + req.PageNum = 1 + } + } + page = req.PageNum + if req.PageSize == 0 { + req.PageSize = utils.AdminPageNum + } + list, err = model.Page(page, req.PageSize).Order("dict_sort asc,dict_code asc").All() + if err != nil { + g.Log().Error(err) + err = gerror.New("获取数据失败") + return + } + return +} + +//删除字典 +func DeleteDictByIds(ids []int) error { + discs, err := sys_dict_type.Model.Where("dict_id in(?)", ids).All() + if err != nil { + g.Log().Error(err) + return gerror.New("没有要删除的数据") + } + //删除字典下的数据 + for _, v := range discs { + sys_dict_data.Model.Delete("dict_type=?", v.DictType) + v.Delete() + } + return nil +} + +//删除字典数据 +func DeleteDictDataByIds(ids []int) error { + _, err := sys_dict_data.Model.Delete("dict_code in (?)", ids) + if err != nil { + g.Log().Error(err) + return gerror.New("删除失败") + } + return nil +} diff --git a/app/service/admin/dict_service/dict_type.go b/app/service/admin/dict_service/dict_type.go new file mode 100644 index 0000000..2e34918 --- /dev/null +++ b/app/service/admin/dict_service/dict_type.go @@ -0,0 +1,134 @@ +package dict_service + +import ( + "gfast/app/model/admin/sys_dict_type" + "gfast/library/utils" + "github.com/gogf/gf/errors/gerror" + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/util/gconv" +) + +//检查字典类型是否唯一 +func CheckDictTypeUniqueAll(dictType string) bool { + dict, err := sys_dict_type.Model.FindOne("dict_type=?", dictType) + if err != nil { + g.Log().Error(err) + return false + } + if dict != nil { + return false + } + return true +} + +//根据主键判断是否唯一 +func CheckDictTypeUnique(dictType *sys_dict_type.EditReq) bool { + dict, err := sys_dict_type.Model.FindOne("dict_type=? and dict_id!=?", dictType.DictType, dictType.DictId) + if err != nil { + g.Log().Error(err) + return false + } + if dict != nil { + return false + } + return true +} + +//添加数据 +func AddSave(req *sys_dict_type.AddReq, userId int) (int64, error) { + var entity sys_dict_type.Entity + entity.Status = req.Status + entity.DictType = req.DictType + entity.DictName = req.DictName + entity.Remark = req.Remark + entity.CreateTime = gconv.Uint64(gtime.Timestamp()) + entity.CreateBy = gconv.Uint(userId) + + result, err := entity.Insert() + if err != nil { + return 0, err + } + id, err := result.LastInsertId() + if err != nil || id <= 0 { + return 0, err + } + return id, nil +} + +//修改保存字典类型 +func EditSave(req *sys_dict_type.EditReq, userId int) (int64, error) { + entity, err := GetDictById(gconv.Int(req.DictId)) + if err != nil || entity == nil { + return 0, err + } + entity.DictType = req.DictType + entity.DictName = req.DictName + entity.Status = req.Status + entity.Remark = req.Remark + entity.UpdateBy = gconv.Uint(userId) + entity.UpdateTime = gconv.Uint64(gtime.Timestamp()) + res, err := entity.Update() + if err != nil { + g.Log().Error(err) + return 0, gerror.New("更新失败") + } + return res.RowsAffected() +} + +//字典列表查询分页 +func SelectListByPage(req *sys_dict_type.SelectPageReq) (total, page int, list []*sys_dict_type.Entity, err error) { + model := sys_dict_type.Model + if req != nil { + if req.DictType != "" { + model = model.Where("dict_name like ?", "%"+req.DictName+"%") + } + + if req.Status != "" { + model = model.Where("status = ", gconv.Int(req.Status)) + } + + if req.BeginTime != "" { + model = model.Where("create_time >=?", utils.StrToTimestamp(req.BeginTime)) + } + + if req.EndTime != "" { + model = model.Where("create_time<=?", utils.StrToTimestamp(req.EndTime)) + } + } + total, err = model.Count() + if err != nil { + g.Log().Error(err) + err = gerror.New("获取总行数失败") + return + } + if req.PageNum == 0 { + req.PageNum = 1 + } + page = req.PageNum + if req.PageSize == 0 { + req.PageSize = utils.AdminPageNum + } + list, err = model.Page(page, req.PageSize).Order("dict_id asc").All() + if err != nil { + g.Log().Error(err) + err = gerror.New("获取数据失败") + return + } + return +} + +//通过id获取字典数据 +func GetDictById(id int) (dict *sys_dict_type.Entity, err error) { + dict, err = sys_dict_type.Model.FindOne("dict_id=?", id) + if err != nil { + g.Log().Error(err) + err = gerror.New("获取字典数据失败") + return + } + if dict == nil { + err = gerror.New("获取字典数据失败") + return + } + return +} diff --git a/config/config.toml b/config/config.toml index e1eb4b8..0abcb60 100644 --- a/config/config.toml +++ b/config/config.toml @@ -1,6 +1,7 @@ # 数据库连接 [database] link = "mysql:root:123456@tcp(127.0.0.1:3306)/gfast" + charset = "utf8mb4" #数据库编码 maxIdle = "10" #连接池最大闲置的连接数 maxOpen = "10" #连接池最大打开的连接数 maxLifetime = "30" #(单位秒)连接对象可重复使用的时间长度 diff --git a/data/db.sql b/data/db.sql index 24f5756..8be92ce 100644 --- a/data/db.sql +++ b/data/db.sql @@ -39,7 +39,7 @@ CREATE TABLE `casbin_rule` ( LOCK TABLES `casbin_rule` WRITE; /*!40000 ALTER TABLE `casbin_rule` DISABLE KEYS */; -INSERT INTO `casbin_rule` VALUES ('p','g_27','r_5','All','','',''),('p','g_27','r_9','All','','',''),('p','g_27','r_10','All','','',''),('g','u_31','g_1','','','',''),('g','u_31','g_2','','','',''),('p','g_1','r_5','All','','',''),('p','g_1','r_9','All','','',''),('p','g_1','r_10','All','','',''),('p','g_2','r_11','All','','',''),('p','g_2','r_12','All','','',''),('p','g_2','r_42','All','','',''); +INSERT INTO `casbin_rule` VALUES ('p','g_2','r_5','All','','',''),('p','g_2','r_9','All','','',''),('p','g_2','r_41','All','','',''),('p','g_2','r_42','All','','',''),('p','g_2','r_43','All','','',''),('p','g_2','r_10','All','','',''),('p','g_2','r_11','All','','',''),('p','g_2','r_47','All','','',''),('p','g_2','r_48','All','','',''),('p','g_2','r_49','All','','',''),('p','g_2','r_12','All','','',''),('p','g_2','r_50','All','','',''),('p','g_2','r_51','All','','',''),('p','g_2','r_52','All','','',''),('p','g_2','r_53','All','','',''),('p','g_2','r_57','All','','',''),('p','g_2','r_58','All','','',''),('p','g_2','r_59','All','','',''),('p','g_2','r_60','All','','',''),('p','g_2','r_61','All','','',''),('p','g_2','r_62','All','','',''),('g','u_31','g_1','','','',''),('g','u_31','g_2','','','',''),('p','g_1','r_46','All','','',''),('p','g_1','r_63','All','','',''),('p','g_1','r_64','All','','',''),('p','g_1','r_65','All','','',''),('p','g_1','r_5','All','','',''),('p','g_1','r_9','All','','',''),('p','g_1','r_41','All','','',''),('p','g_1','r_42','All','','',''),('p','g_1','r_43','All','','',''),('p','g_1','r_10','All','','',''),('p','g_1','r_11','All','','',''),('p','g_1','r_47','All','','',''),('p','g_1','r_48','All','','',''),('p','g_1','r_49','All','','',''),('p','g_1','r_12','All','','',''),('p','g_1','r_50','All','','',''),('p','g_1','r_51','All','','',''),('p','g_1','r_52','All','','',''),('p','g_1','r_53','All','','',''),('p','g_1','r_57','All','','',''),('p','g_1','r_58','All','','',''),('p','g_1','r_59','All','','',''),('p','g_1','r_60','All','','',''),('p','g_1','r_61','All','','',''),('p','g_1','r_62','All','','',''); /*!40000 ALTER TABLE `casbin_rule` ENABLE KEYS */; UNLOCK TABLES; @@ -68,7 +68,7 @@ CREATE TABLE `qxkj_auth_rule` ( UNIQUE KEY `name` (`name`) USING BTREE, KEY `pid` (`pid`), KEY `weigh` (`weigh`) -) ENGINE=MyISAM AUTO_INCREMENT=45 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='菜单节点表'; +) ENGINE=MyISAM AUTO_INCREMENT=66 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='菜单节点表'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -77,7 +77,7 @@ CREATE TABLE `qxkj_auth_rule` ( LOCK TABLES `qxkj_auth_rule` WRITE; /*!40000 ALTER TABLE `qxkj_auth_rule` DISABLE KEYS */; -INSERT INTO `qxkj_auth_rule` VALUES (5,'file',0,'auth','权限管理','fa fa-group','','',1,1497429920,1497430092,99,1),(9,'file',5,'auth/admin','管理员管理','fa fa-user','','Admin tips',1,1497429920,1497430320,118,1),(10,'file',5,'auth/adminlog','管理员日志','fa fa-list-alt','','Admin log tips',1,1497429920,1497430307,113,1),(11,'file',5,'auth/group','角色组','fa fa-group','','Group tips',1,1497429920,1497429920,109,1),(12,'file',5,'auth/rule','菜单规则','fa fa-bars','','Rule tips',1,1497429920,1497430581,104,1),(43,'file',9,'auth/admin/del','删除','fa fa-circle-o','','',0,1497429920,1497429920,114,1),(42,'file',9,'auth/admin/edit','修改','fa fa-circle-o','','',0,1497429920,1497429920,115,1),(41,'file',9,'auth/admin/add','添加','fa fa-circle-o','','',0,1497429920,1497429920,116,1),(40,'file',9,'auth/admin/index','查看','fa fa-circle-o','','Admin tips',0,1497429920,1497429920,117,1),(44,'file',5,'test/test','测试菜单','fa fa-circle-o','','备注',0,1581752604,1581758616,100,0); +INSERT INTO `qxkj_auth_rule` VALUES (5,'file',0,'/system/auth','权限管理','fa fa-users','','',1,1497429920,1582706271,80,1),(9,'file',5,'/system/auth/user-list','管理员管理','fa fa-user','','Admin tips',1,1497429920,1497430320,118,1),(10,'file',5,'/system/auth/adminlog','管理员日志','fa fa-list-alt','','Admin log tips',1,1497429920,1582731276,113,1),(11,'file',5,'/system/auth/role-list','角色组','fa fa-group','','Group tips',1,1497429920,1582706904,109,1),(12,'file',5,'/system/auth/menu-list','菜单规则','fa fa-bars','','Rule tips',1,1497429920,1582731459,104,1),(43,'file',9,'/system/auth/delete-admin','删除','fa fa-circle-o','','',0,1497429920,1582706783,1,1),(42,'file',9,'/system/auth/edit-user','修改','fa fa-circle-o','','',0,1497429920,1582706817,2,1),(41,'file',9,'/system/auth/add-user','添加','fa fa-circle-o','','',0,1497429920,1582726029,3,1),(47,'file',11,'/system/auth/add-role','添加角色','el-icon-document-add','','',0,1582706959,1582706959,50,1),(50,'file',12,'/system/auth/add-menu','添加菜单','el-icon-document-add','','',0,1582726105,1582726105,50,1),(46,'file',0,'/system/index/index','系统首页','el-icon-s-grid','noCheck','',1,1582704520,1582726295,100,1),(48,'file',11,'/system/auth/edit-role','修改角色','fa fa-pencil','','',0,1582706999,1582726035,50,1),(49,'file',11,'/system/auth/delete-role','删除角色','fa fa-institution','','',0,1582707051,1582726040,50,1),(51,'file',12,'/system/auth/edit-menu','修改菜单','fa fa-pencil','','',0,1582726145,1582726145,50,1),(52,'file',12,'/system/auth/delete-menu','删除菜单','fa fa-institution','','',0,1582726194,1582726194,50,1),(53,'file',12,'/system/auth/menu-sort','菜单排序','fa fa-list-ul','','',0,1582726229,1582726229,50,1),(57,'file',0,'/system/cms','CMS管理','fa fa-list','','',1,1582731636,1582731636,70,1),(58,'file',57,'/system/cms/menu-list','栏目管理','fa fa-list-ul','','',1,1582731762,1582732995,50,1),(59,'file',57,'/system/cms/news-list','内容管理','fa fa-th-list','','',1,1582731800,1582733003,50,1),(60,'file',57,'/system/cms/mode-list','模型管理','fa fa-codepen','','',1,1582731832,1582733011,50,1),(61,'file',57,'/system/cms/special-list','专题管理','fa fa-hand-pointer-o','','',1,1582732334,1582733018,50,1),(62,'file',57,'/system/cms/single-list','单页管理','fa fa-file-o','','',1,1582732373,1582733025,50,1),(63,'file',0,'/system/config','系统配置','fa fa-wrench','','',1,1582773590,1582773600,90,1),(64,'file',63,'/system/config/dict-list','字典管理','fa fa-sitemap','','',1,1582773640,1582773640,50,1),(65,'file',63,'/system/config/params-list','参数管理','fa fa-list-ul','','',1,1582773725,1582773725,50,1); /*!40000 ALTER TABLE `qxkj_auth_rule` ENABLE KEYS */; UNLOCK TABLES; @@ -100,7 +100,7 @@ CREATE TABLE `qxkj_role` ( PRIMARY KEY (`id`), KEY `parent_id` (`parent_id`), KEY `status` (`status`) -) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb4 COMMENT='角色表'; +) ENGINE=InnoDB AUTO_INCREMENT=173 DEFAULT CHARSET=utf8mb4 COMMENT='角色表'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -109,7 +109,7 @@ CREATE TABLE `qxkj_role` ( LOCK TABLES `qxkj_role` WRITE; /*!40000 ALTER TABLE `qxkj_role` DISABLE KEYS */; -INSERT INTO `qxkj_role` VALUES (1,0,1,1329633709,1581673885,0,'超级管理员','备注'),(2,0,1,1329633709,1581674154,0,'普通管理员','备注'),(3,0,1,0,0,0,'站点管理员','站点管理人员'),(4,0,1,0,0,0,'初级管理员','初级管理员'),(5,0,1,0,0,0,'高级管理员','高级管理员'),(6,0,0,0,0,0,'超级管理员','超级管理员'),(7,0,1,0,0,0,'系统管理员','包含所有系统设置权限'),(8,0,1,0,0,0,'区级管理员',''),(26,1,1,1580975018,1580975018,0,'测试组','备注'),(27,1,1,0,1581064765,0,'修改测试','备注'); +INSERT INTO `qxkj_role` VALUES (1,0,1,1329633709,1582773740,0,'超级管理员','备注'),(2,0,1,1329633709,1582732392,0,'普通管理员','备注'),(3,0,1,0,0,0,'站点管理员','站点管理人员'),(4,0,1,0,0,0,'初级管理员','初级管理员'),(5,0,1,0,0,0,'高级管理员','高级管理员'),(6,0,1,0,0,0,'超级管理员','超级管理员'),(7,0,1,0,0,0,'系统管理员','包含所有系统设置权限'),(8,0,1,0,0,0,'区级管理员',''); /*!40000 ALTER TABLE `qxkj_role` ENABLE KEYS */; UNLOCK TABLES; @@ -138,7 +138,7 @@ CREATE TABLE `qxkj_user` ( UNIQUE KEY `user_login` (`user_name`) USING BTREE, UNIQUE KEY `mobile` (`mobile`) USING BTREE, KEY `user_nickname` (`user_nickname`) -) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8mb4 COMMENT='用户表'; +) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=utf8mb4 COMMENT='用户表'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -147,7 +147,7 @@ CREATE TABLE `qxkj_user` ( LOCK TABLES `qxkj_user` WRITE; /*!40000 ALTER TABLE `qxkj_user` DISABLE KEYS */; -INSERT INTO `qxkj_user` VALUES (1,'admin','18687460581','超级管理员',0,1557715675,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'yxh669@qq.com',0,'',1581491047,'192.168.31.221'),(2,'yixiaohu','13699885599','易小虎',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'yxh@qq.com',1,'',1581513065,'192.168.31.221'),(3,'zs','16399669855','张三',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'zs@qq.com',0,'',1559293160,'127.0.0.1'),(4,'qlgl','13758596696','测试',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'qlgl@qq.com',0,'',1559293134,'127.0.0.1'),(5,'test','13845696696','测试2',0,0,'9OFlt5qzzvCiZWhe7ilcLA==',1,'123@qq.com',0,'',0,''),(6,'18999998889','13755866654','刘大大',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'1223@qq.com',0,'',0,''),(7,'zmm','13788566696','张明明',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'11123@qq.com',0,'',0,''),(8,'lxx','13756566696','李小小',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'123333@qq.com',0,'',1571729563,'127.0.0.1'),(10,'xmm','13588999969','小秘密',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(14,'cd_19','123154564','看金利科技',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(15,'lmm','135877545454','刘敏敏',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(16,'ldn','13899658874','李大牛',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(20,'dbc','13877555566','大百词',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(22,'yxfmlbb','15969423326','袁学飞',0,1557715675,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'yxh6691@qq.com',0,'',1565059554,'127.0.0.1'),(23,'wangming','13699888855','王明',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(24,'zhk','13699885591','综合科',0,0,'IZNU7Pn91/++830Pi6HAWA==',1,'',0,'',1569288069,'192.168.0.146'),(28,'demo3','18699888855','测试账号1',0,1581314035,'9OFlt5qzzvCiZWhe7ilcLA==',1,'',0,'',0,''),(31,'demo','18699888856','测试账号1',0,1581314770,'9OFlt5qzzvCiZWhe7ilcLA==',1,'',0,'',1581911691,'192.168.31.221'); +INSERT INTO `qxkj_user` VALUES (1,'admin','18687460581','超级管理员',0,1557715675,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'yxh669@qq.com',0,'',1581491047,'192.168.31.221'),(2,'yixiaohu','13699885599','易小虎',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'yxh@qq.com',1,'',1582190234,'[::1]'),(3,'zs','16399669855','张三',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'zs@qq.com',0,'',1559293160,'127.0.0.1'),(4,'qlgl','13758596696','测试',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'qlgl@qq.com',0,'',1559293134,'127.0.0.1'),(5,'test','13845696696','测试2',0,0,'9OFlt5qzzvCiZWhe7ilcLA==',1,'123@qq.com',0,'',0,''),(6,'18999998889','13755866654','刘大大',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'1223@qq.com',0,'',0,''),(7,'zmm','13788566696','张明明',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'11123@qq.com',0,'',0,''),(8,'lxx','13756566696','李小小',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'123333@qq.com',0,'',1571729563,'127.0.0.1'),(10,'xmm','13588999969','小秘密',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(14,'cd_19','123154564','看金利科技',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(15,'lmm','135877545454','刘敏敏',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(16,'ldn','13899658874','李大牛',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(20,'dbc','13877555566','大百词',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(22,'yxfmlbb','15969423326','袁学飞',0,1557715675,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'yxh6691@qq.com',0,'',1565059554,'127.0.0.1'),(23,'wangming','13699888855','王明',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(24,'zhk','13699885591','综合科',0,0,'IZNU7Pn91/++830Pi6HAWA==',1,'',0,'',1569288069,'192.168.0.146'),(28,'demo3','18699888855','测试账号1',0,1581314035,'9OFlt5qzzvCiZWhe7ilcLA==',1,'',0,'',0,''),(31,'demo','18699888856','测试账号1',0,1581314770,'9OFlt5qzzvCiZWhe7ilcLA==',1,'56@qq.com',0,'',1582772787,'192.168.31.221'),(32,'demo100','18699888859','测试账号1',0,1582103659,'9OFlt5qzzvCiZWhe7ilcLA==',1,'',0,'',0,''),(33,'demo110','18699888853','测试账号1',0,1582109337,'9OFlt5qzzvCiZWhe7ilcLA==',1,'',0,'',0,''),(34,'demo101','13855774455','测试账号1',0,1582110232,'9OFlt5qzzvCiZWhe7ilcLA==',1,'',0,'',0,''),(38,'demo103','18699888833','测试账号103',0,1582188923,'9OFlt5qzzvCiZWhe7ilcLA==',1,'',0,'',1582188938,'[::1]'); /*!40000 ALTER TABLE `qxkj_user` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -160,4 +160,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2020-02-17 15:06:29 +-- Dump completed on 2020-02-27 11:23:06 diff --git a/library/utils/function.go b/library/utils/function.go index 7ffb504..5992357 100644 --- a/library/utils/function.go +++ b/library/utils/function.go @@ -166,3 +166,13 @@ func signIn(username, password string, r *ghttp.Request) (error, *user.QxkjUser) qxkjUser.Update() return nil, &returnData } + +//日期字符串转时间戳(秒) +func StrToTimestamp(dateStr string) int64 { + tm, err := gtime.StrToTime(dateStr) + if err != nil { + g.Log().Error(err) + return 0 + } + return tm.Timestamp() +} diff --git a/router/router.go b/router/router.go index e4d9957..a53bbdc 100644 --- a/router/router.go +++ b/router/router.go @@ -16,4 +16,7 @@ func init() { systemGroup.Middleware(MiddlewareAuth) //后台权限验证 systemGroup.ALL("/index", new(admin.Index)) systemGroup.ALL("/auth", new(admin.Auth)) + systemGroup.ALL("/cms", new(admin.CmsMenu)) + systemGroup.ALL("/cms", new(admin.CmsNews)) + systemGroup.ALL("/config", new(admin.Dict)) } diff --git a/test/demo2_test.go b/test/demo2_test.go index d2ad02d..e0abe3d 100644 --- a/test/demo2_test.go +++ b/test/demo2_test.go @@ -1,6 +1,8 @@ package test import ( + "fmt" + "github.com/gogf/gf/os/gtime" "testing" ) @@ -9,5 +11,11 @@ func TestDemo2(t *testing.T) { } func test21(t *testing.T) { - + str := "2018.02.09 20:46:17" + tm, err := gtime.StrToTime(str) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(tm.Timestamp()) }