mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 10:13:01 +00:00
feat✨ :添加行政区域基础数据
This commit is contained in:
@@ -0,0 +1,189 @@
|
|||||||
|
package syschinaareadata
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"go-admin/app/admin/service"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"go-admin/app/admin/models"
|
||||||
|
"go-admin/app/admin/service/dto"
|
||||||
|
"go-admin/common/actions"
|
||||||
|
"go-admin/common/apis"
|
||||||
|
"go-admin/common/log"
|
||||||
|
"go-admin/tools"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SysChinaAreaData struct {
|
||||||
|
apis.Api
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) {
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
d := new(dto.SysChinaAreaDataSearch)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询列表
|
||||||
|
err = d.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//数据权限检查
|
||||||
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
|
||||||
|
list := make([]models.SysChinaAreaData, 0)
|
||||||
|
var count int64
|
||||||
|
serviceStudent := service.SysChinaAreaData{}
|
||||||
|
serviceStudent.MsgID = msgID
|
||||||
|
serviceStudent.Orm = db
|
||||||
|
err = serviceStudent.GetSysChinaAreaDataPage(d, p, &list, &count)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) {
|
||||||
|
control := new(dto.SysChinaAreaDataById)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
//查看详情
|
||||||
|
err = control.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var object models.SysChinaAreaData
|
||||||
|
|
||||||
|
//数据权限检查
|
||||||
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
|
||||||
|
serviceSysChinaAreaData := service.SysChinaAreaData{}
|
||||||
|
serviceSysChinaAreaData.MsgID = msgID
|
||||||
|
serviceSysChinaAreaData.Orm = db
|
||||||
|
err = serviceSysChinaAreaData.GetSysChinaAreaData(control, p, &object)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.OK(c, object, "查看成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) {
|
||||||
|
control := new(dto.SysChinaAreaDataControl)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
//新增操作
|
||||||
|
err = control.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
object, err := control.Generate()
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 设置创建人
|
||||||
|
object.SetCreateBy(tools.GetUserId(c))
|
||||||
|
|
||||||
|
serviceSysChinaAreaData := service.SysChinaAreaData{}
|
||||||
|
serviceSysChinaAreaData.Orm = db
|
||||||
|
serviceSysChinaAreaData.MsgID = msgID
|
||||||
|
err = serviceSysChinaAreaData.InsertSysChinaAreaData(object)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
e.Error(c, http.StatusInternalServerError, err, "创建失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.OK(c, object.GetId(), "创建成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) {
|
||||||
|
control := new(dto.SysChinaAreaDataControl)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
//更新操作
|
||||||
|
err = control.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
object, err := control.Generate()
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
object.SetUpdateBy(tools.GetUserId(c))
|
||||||
|
|
||||||
|
//数据权限检查
|
||||||
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
|
||||||
|
serviceSysChinaAreaData := service.SysChinaAreaData{}
|
||||||
|
serviceSysChinaAreaData.Orm = db
|
||||||
|
serviceSysChinaAreaData.MsgID = msgID
|
||||||
|
err = serviceSysChinaAreaData.UpdateSysChinaAreaData(object, p)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.OK(c, object.GetId(), "更新成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) {
|
||||||
|
control := new(dto.SysChinaAreaDataById)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
//删除操作
|
||||||
|
err = control.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("MsgID[%s] Bind error: %s", msgID, err)
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置编辑人
|
||||||
|
control.SetUpdateBy(tools.GetUserId(c))
|
||||||
|
|
||||||
|
// 数据权限检查
|
||||||
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
|
||||||
|
serviceSysChinaAreaData := service.SysChinaAreaData{}
|
||||||
|
serviceSysChinaAreaData.Orm = db
|
||||||
|
serviceSysChinaAreaData.MsgID = msgID
|
||||||
|
err = serviceSysChinaAreaData.RemoveSysChinaAreaData(control, p)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.OK(c, control.GetId(), "删除成功")
|
||||||
|
}
|
||||||
@@ -19,17 +19,17 @@ func Preview(c *gin.Context) {
|
|||||||
id, err := tools2.StringToInt(c.Param("tableId"))
|
id, err := tools2.StringToInt(c.Param("tableId"))
|
||||||
tools2.HasError(err, "", -1)
|
tools2.HasError(err, "", -1)
|
||||||
table.TableId = id
|
table.TableId = id
|
||||||
t1, err := template.ParseFiles("template/v3/model.go.template")
|
t1, err := template.ParseFiles("template/v4/model.go.template")
|
||||||
tools2.HasError(err, "", -1)
|
tools2.HasError(err, "", -1)
|
||||||
t2, err := template.ParseFiles("template/v3/no_actions/apis.go.template")
|
t2, err := template.ParseFiles("template/v4/no_actions/apis.go.template")
|
||||||
tools2.HasError(err, "", -1)
|
tools2.HasError(err, "", -1)
|
||||||
t3, err := template.ParseFiles("template/v3/js.go.template")
|
t3, err := template.ParseFiles("template/v4/js.go.template")
|
||||||
tools2.HasError(err, "", -1)
|
tools2.HasError(err, "", -1)
|
||||||
t4, err := template.ParseFiles("template/v3/vue.go.template")
|
t4, err := template.ParseFiles("template/v4/vue.go.template")
|
||||||
tools2.HasError(err, "", -1)
|
tools2.HasError(err, "", -1)
|
||||||
t5, err := template.ParseFiles("template/v3/no_actions/router_check_role.go.template")
|
t5, err := template.ParseFiles("template/v4/no_actions/router_check_role.go.template")
|
||||||
tools2.HasError(err, "", -1)
|
tools2.HasError(err, "", -1)
|
||||||
t6, err := template.ParseFiles("template/v3/dto.go.template")
|
t6, err := template.ParseFiles("template/v4/dto.go.template")
|
||||||
tools2.HasError(err, "", -1)
|
tools2.HasError(err, "", -1)
|
||||||
tab, _ := table.Get()
|
tab, _ := table.Get()
|
||||||
var b1 bytes.Buffer
|
var b1 bytes.Buffer
|
||||||
@@ -76,7 +76,7 @@ func GenCodeV3(c *gin.Context) {
|
|||||||
|
|
||||||
func NOActionsGenV3(tab tools.SysTables) {
|
func NOActionsGenV3(tab tools.SysTables) {
|
||||||
|
|
||||||
basePath := "template/v3/"
|
basePath := "template/v4/"
|
||||||
routerFile := basePath + "no_actions/router_check_role.go.template"
|
routerFile := basePath + "no_actions/router_check_role.go.template"
|
||||||
|
|
||||||
if tab.IsAuth == 2 {
|
if tab.IsAuth == 2 {
|
||||||
@@ -130,7 +130,7 @@ func NOActionsGenV3(tab tools.SysTables) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ActionsGenV3(tab tools.SysTables) {
|
func ActionsGenV3(tab tools.SysTables) {
|
||||||
basePath := "template/v3/"
|
basePath := "template/v4/"
|
||||||
routerFile := basePath + "actions/router_check_role.go.template"
|
routerFile := basePath + "actions/router_check_role.go.template"
|
||||||
|
|
||||||
if tab.IsAuth == 2 {
|
if tab.IsAuth == 2 {
|
||||||
|
|||||||
@@ -36,5 +36,5 @@ func (e *SysFileDir) Generate() models.ActiveRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *SysFileDir) GetId() interface{} {
|
func (e *SysFileDir) GetId() interface{} {
|
||||||
return e.ID
|
return e.Id
|
||||||
}
|
}
|
||||||
@@ -27,5 +27,5 @@ func (e *SysFileInfo) Generate() models.ActiveRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *SysFileInfo) GetId() interface{} {
|
func (e *SysFileInfo) GetId() interface{} {
|
||||||
return e.ID
|
return e.Id
|
||||||
}
|
}
|
||||||
@@ -25,5 +25,5 @@ func (e *SysCategory) Generate() models.ActiveRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *SysCategory) GetId() interface{} {
|
func (e *SysCategory) GetId() interface{} {
|
||||||
return e.ID
|
return e.Id
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-admin/common/models"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SysChinaAreaData struct {
|
||||||
|
models.Model
|
||||||
|
models.ControlBy
|
||||||
|
|
||||||
|
PId string `json:"pId" gorm:"type:int(11);comment:上级编码"`
|
||||||
|
Name string `json:"name" gorm:"type:varchar(128);comment:名称"`
|
||||||
|
CreateTime time.Time `json:"createTime" gorm:"type:timestamp;comment:CreateTime"`
|
||||||
|
UpdateTime time.Time `json:"updateTime" gorm:"type:timestamp;comment:UpdateTime"`
|
||||||
|
DeleteTime time.Time `json:"deleteTime" gorm:"type:timestamp;comment:DeleteTime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (SysChinaAreaData) TableName() string {
|
||||||
|
return "sys_china_area_data"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysChinaAreaData) Generate() models.ActiveRecord {
|
||||||
|
o := *e
|
||||||
|
return &o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysChinaAreaData) GetId() interface{} {
|
||||||
|
return e.Id
|
||||||
|
}
|
||||||
@@ -25,5 +25,5 @@ func (e *SysConfig) Generate() models.ActiveRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *SysConfig) GetId() interface{} {
|
func (e *SysConfig) GetId() interface{} {
|
||||||
return e.ID
|
return e.Id
|
||||||
}
|
}
|
||||||
@@ -33,5 +33,5 @@ func (e *SysLoginLog) Generate() models.ActiveRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *SysLoginLog) GetId() interface{} {
|
func (e *SysLoginLog) GetId() interface{} {
|
||||||
return e.ID
|
return e.Id
|
||||||
}
|
}
|
||||||
@@ -41,5 +41,5 @@ func (e *SysOperaLog) Generate() models.ActiveRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *SysOperaLog) GetId() interface{} {
|
func (e *SysOperaLog) GetId() interface{} {
|
||||||
return e.ID
|
return e.Id
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"go-admin/app/admin/apis/syschinaareadata"
|
||||||
|
"go-admin/app/admin/middleware"
|
||||||
|
jwt "go-admin/pkg/jwtauth"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
routerCheckRole = append(routerCheckRole, registerSysChinaAreaDataRouter)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 需认证的路由代码
|
||||||
|
func registerSysChinaAreaDataRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||||
|
api := &syschinaareadata.SysChinaAreaData{}
|
||||||
|
r := v1.Group("/syschinaareadata").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||||
|
{
|
||||||
|
r.GET("", api.GetSysChinaAreaDataList)
|
||||||
|
r.GET("/:id", api.GetSysChinaAreaData)
|
||||||
|
r.POST("", api.InsertSysChinaAreaData)
|
||||||
|
r.PUT("/:id", api.UpdateSysChinaAreaData)
|
||||||
|
r.DELETE("", api.DeleteSysChinaAreaData)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,7 +35,7 @@ func (m *SysCategorySearch) Generate() dto.Index {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SysCategoryControl struct {
|
type SysCategoryControl struct {
|
||||||
ID int `uri:"ID" comment:"标识"` // 标识
|
ID int `uri:"Id" comment:"标识"` // 标识
|
||||||
|
|
||||||
Name string `json:"name" comment:"名称"`
|
Name string `json:"name" comment:"名称"`
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ func (s *SysCategoryControl) Generate() dto.Control {
|
|||||||
|
|
||||||
func (s *SysCategoryControl) GenerateM() (common.ActiveRecord, error) {
|
func (s *SysCategoryControl) GenerateM() (common.ActiveRecord, error) {
|
||||||
return &models.SysCategory{
|
return &models.SysCategory{
|
||||||
Model: common.Model{ID: s.ID},
|
Model: common.Model{Id: s.ID},
|
||||||
Name: s.Name,
|
Name: s.Name,
|
||||||
Img: s.Img,
|
Img: s.Img,
|
||||||
Sort: s.Sort,
|
Sort: s.Sort,
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func (m *SysConfigSearch) Bind(ctx *gin.Context) error {
|
|||||||
|
|
||||||
// SysConfigControl 增、改使用的结构体
|
// SysConfigControl 增、改使用的结构体
|
||||||
type SysConfigControl struct {
|
type SysConfigControl struct {
|
||||||
ID int `uri:"ID" comment:"编码"` // 编码
|
ID int `uri:"Id" comment:"编码"` // 编码
|
||||||
ConfigName string `json:"configName" comment:""`
|
ConfigName string `json:"configName" comment:""`
|
||||||
ConfigKey string `uri:"configKey" json:"configKey" comment:""`
|
ConfigKey string `uri:"configKey" json:"configKey" comment:""`
|
||||||
ConfigValue string `json:"configValue" comment:""`
|
ConfigValue string `json:"configValue" comment:""`
|
||||||
@@ -67,7 +67,7 @@ func (s *SysConfigControl) Bind(ctx *gin.Context) error {
|
|||||||
// Generate 结构体数据转化 从 SysConfigControl 至 system.SysConfig 对应的模型
|
// Generate 结构体数据转化 从 SysConfigControl 至 system.SysConfig 对应的模型
|
||||||
func (s *SysConfigControl) Generate() (*system.SysConfig, error) {
|
func (s *SysConfigControl) Generate() (*system.SysConfig, error) {
|
||||||
return &system.SysConfig{
|
return &system.SysConfig{
|
||||||
Model: common.Model{ID: s.ID},
|
Model: common.Model{Id: s.ID},
|
||||||
ConfigName: s.ConfigName,
|
ConfigName: s.ConfigName,
|
||||||
ConfigKey: s.ConfigKey,
|
ConfigKey: s.ConfigKey,
|
||||||
ConfigValue: s.ConfigValue,
|
ConfigValue: s.ConfigValue,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
type SysFileDirSearch struct {
|
type SysFileDirSearch struct {
|
||||||
dto.Pagination `search:"-"`
|
dto.Pagination `search:"-"`
|
||||||
|
|
||||||
ID int `form:"ID" search:"type:exact;column:id;table:sys_file_dir" comment:"标识"`
|
ID int `form:"Id" search:"type:exact;column:id;table:sys_file_dir" comment:"标识"`
|
||||||
Label string `form:"label" search:"type:exact;column:label;table:sys_file_dir" comment:"目录名称"`
|
Label string `form:"label" search:"type:exact;column:label;table:sys_file_dir" comment:"目录名称"`
|
||||||
PId string `form:"pId" search:"type:exact;column:p_id;table:sys_file_dir" comment:"上级目录"`
|
PId string `form:"pId" search:"type:exact;column:p_id;table:sys_file_dir" comment:"上级目录"`
|
||||||
//Sort string `form:"sort" search:"type:exact;column:sort;table:sys_file_dir" comment:"排序"`
|
//Sort string `form:"sort" search:"type:exact;column:sort;table:sys_file_dir" comment:"排序"`
|
||||||
@@ -39,7 +39,7 @@ func (m *SysFileDirSearch) Generate() dto.Index {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SysFileDirControl struct {
|
type SysFileDirControl struct {
|
||||||
ID int `uri:"ID" comment:"标识"` // 标识
|
ID int `uri:"Id" comment:"标识"` // 标识
|
||||||
Label string `json:"label" comment:"目录名称"`
|
Label string `json:"label" comment:"目录名称"`
|
||||||
PId int `json:"pId" comment:"上级目录"`
|
PId int `json:"pId" comment:"上级目录"`
|
||||||
Sort string `json:"sort" comment:"排序"`
|
Sort string `json:"sort" comment:"排序"`
|
||||||
@@ -69,7 +69,7 @@ func (s *SysFileDirControl) Generate() dto.Control {
|
|||||||
|
|
||||||
func (s *SysFileDirControl) GenerateM() (common.ActiveRecord, error) {
|
func (s *SysFileDirControl) GenerateM() (common.ActiveRecord, error) {
|
||||||
return &models.SysFileDir{
|
return &models.SysFileDir{
|
||||||
Model: common.Model{ID: s.ID},
|
Model: common.Model{Id: s.ID},
|
||||||
Label: s.Label,
|
Label: s.Label,
|
||||||
PId: s.PId,
|
PId: s.PId,
|
||||||
//Sort: s.Sort,
|
//Sort: s.Sort,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
type SysFileInfoSearch struct {
|
type SysFileInfoSearch struct {
|
||||||
dto.Pagination `search:"-"`
|
dto.Pagination `search:"-"`
|
||||||
ID int `form:"ID" search:"type:exact;column:id;table:sys_file_info" comment:"标识"`
|
ID int `form:"Id" search:"type:exact;column:id;table:sys_file_info" comment:"标识"`
|
||||||
Type string `form:"type" search:"type:exact;column:type;table:sys_file_info" comment:"类型"`
|
Type string `form:"type" search:"type:exact;column:type;table:sys_file_info" comment:"类型"`
|
||||||
Name string `form:"name" search:"type:exact;column:name;table:sys_file_info" comment:"名称"`
|
Name string `form:"name" search:"type:exact;column:name;table:sys_file_info" comment:"名称"`
|
||||||
PId string `form:"pId" search:"type:exact;column:p_id;table:sys_file_info" comment:"目录"`
|
PId string `form:"pId" search:"type:exact;column:p_id;table:sys_file_info" comment:"目录"`
|
||||||
@@ -34,7 +34,7 @@ type SysFileInfoControl struct {
|
|||||||
|
|
||||||
func (s *SysFileInfoControl) Generate() (*models.SysFileInfo, error) {
|
func (s *SysFileInfoControl) Generate() (*models.SysFileInfo, error) {
|
||||||
return &models.SysFileInfo{
|
return &models.SysFileInfo{
|
||||||
Model: common.Model{ID: s.ID},
|
Model: common.Model{Id: s.ID},
|
||||||
Type: s.Type,
|
Type: s.Type,
|
||||||
Name: s.Name,
|
Name: s.Name,
|
||||||
Size: s.Size,
|
Size: s.Size,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func (m *SysLoginLogSearch) Bind(ctx *gin.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SysLoginLogControl struct {
|
type SysLoginLogControl struct {
|
||||||
ID int `uri:"ID" comment:"主键"` // 主键
|
ID int `uri:"Id" comment:"主键"` // 主键
|
||||||
Username string `json:"username" comment:"用户名"`
|
Username string `json:"username" comment:"用户名"`
|
||||||
Status string `json:"status" comment:"状态"`
|
Status string `json:"status" comment:"状态"`
|
||||||
Ipaddr string `json:"ipaddr" comment:"ip地址"`
|
Ipaddr string `json:"ipaddr" comment:"ip地址"`
|
||||||
@@ -62,7 +62,7 @@ func (s *SysLoginLogControl) Bind(ctx *gin.Context) error {
|
|||||||
|
|
||||||
func (s *SysLoginLogControl) Generate() (*system.SysLoginLog, error) {
|
func (s *SysLoginLogControl) Generate() (*system.SysLoginLog, error) {
|
||||||
return &system.SysLoginLog{
|
return &system.SysLoginLog{
|
||||||
Model: common.Model{ID: s.ID},
|
Model: common.Model{Id: s.ID},
|
||||||
Username: s.Username,
|
Username: s.Username,
|
||||||
Status: s.Status,
|
Status: s.Status,
|
||||||
Ipaddr: s.Ipaddr,
|
Ipaddr: s.Ipaddr,
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func (m *SysOperaLogSearch) Bind(ctx *gin.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SysOperaLogControl struct {
|
type SysOperaLogControl struct {
|
||||||
ID int `uri:"ID" comment:"编码"` // 编码
|
ID int `uri:"Id" comment:"编码"` // 编码
|
||||||
Title string `json:"title" comment:"操作模块"`
|
Title string `json:"title" comment:"操作模块"`
|
||||||
BusinessType string `json:"businessType" comment:"操作类型"`
|
BusinessType string `json:"businessType" comment:"操作类型"`
|
||||||
BusinessTypes string `json:"businessTypes" comment:""`
|
BusinessTypes string `json:"businessTypes" comment:""`
|
||||||
@@ -72,7 +72,7 @@ func (s *SysOperaLogControl) Bind(ctx *gin.Context) error {
|
|||||||
|
|
||||||
func (s *SysOperaLogControl) Generate() (*system.SysOperaLog, error) {
|
func (s *SysOperaLogControl) Generate() (*system.SysOperaLog, error) {
|
||||||
return &system.SysOperaLog{
|
return &system.SysOperaLog{
|
||||||
Model: common.Model{ID: s.ID},
|
Model: common.Model{Id: s.ID},
|
||||||
Title: s.Title,
|
Title: s.Title,
|
||||||
BusinessType: s.BusinessType,
|
BusinessType: s.BusinessType,
|
||||||
BusinessTypes: s.BusinessTypes,
|
BusinessTypes: s.BusinessTypes,
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"go-admin/app/admin/models"
|
||||||
|
"go-admin/common/dto"
|
||||||
|
"go-admin/common/log"
|
||||||
|
common "go-admin/common/models"
|
||||||
|
"go-admin/tools"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SysChinaAreaDataSearch struct {
|
||||||
|
dto.Pagination `search:"-"`
|
||||||
|
PId string `form:"pId" search:"type:exact;column:p_id;table:sys_china_area_data" comment:"上级编码"`
|
||||||
|
|
||||||
|
Name string `form:"name" search:"type:exact;column:name;table:sys_china_area_data" comment:"名称"`
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SysChinaAreaDataSearch) GetNeedSearch() interface{} {
|
||||||
|
return *m
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SysChinaAreaDataSearch) Bind(ctx *gin.Context) error {
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||||
|
err := ctx.ShouldBind(m)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("MsgID[%s] ShouldBind error: %s", msgID, err.Error())
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
type SysChinaAreaDataControl struct {
|
||||||
|
|
||||||
|
Id int `uri:"id" comment:"编码"` // 编码
|
||||||
|
|
||||||
|
PId string `json:"pId" comment:"上级编码"`
|
||||||
|
|
||||||
|
|
||||||
|
Name string `json:"name" comment:"名称"`
|
||||||
|
|
||||||
|
|
||||||
|
CreateTime time.Time `json:"createTime" comment:""`
|
||||||
|
|
||||||
|
|
||||||
|
UpdateTime time.Time `json:"updateTime" comment:""`
|
||||||
|
|
||||||
|
|
||||||
|
DeleteTime time.Time `json:"deleteTime" comment:""`
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysChinaAreaDataControl) Bind(ctx *gin.Context) error {
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||||
|
err := ctx.ShouldBindUri(s)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ctx.ShouldBind(s)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysChinaAreaDataControl) Generate() (*models.SysChinaAreaData, error) {
|
||||||
|
return &models.SysChinaAreaData{
|
||||||
|
|
||||||
|
Model: common.Model{ Id: s.Id },
|
||||||
|
PId: s.PId,
|
||||||
|
Name: s.Name,
|
||||||
|
CreateTime: s.CreateTime,
|
||||||
|
UpdateTime: s.UpdateTime,
|
||||||
|
DeleteTime: s.DeleteTime,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysChinaAreaDataControl) GetId() interface{} {
|
||||||
|
return s.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
type SysChinaAreaDataById struct {
|
||||||
|
Id int `uri:"id"`
|
||||||
|
Ids []int `json:"ids"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysChinaAreaDataById) GetId() interface{} {
|
||||||
|
if len(s.Ids) > 0 {
|
||||||
|
s.Ids = append(s.Ids, s.Id)
|
||||||
|
return s.Ids
|
||||||
|
}
|
||||||
|
return s.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysChinaAreaDataById) Bind(ctx *gin.Context) error {
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||||
|
err := ctx.ShouldBindUri(s)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ctx.ShouldBind(s)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysChinaAreaDataById) SetUpdateBy(id int) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -149,11 +149,11 @@ func SysFileDirCall(list *[]models.SysFileDirL, m models.SysFileDirL) models.Sys
|
|||||||
listGroup := *list
|
listGroup := *list
|
||||||
min := make([]models.SysFileDirL, 0)
|
min := make([]models.SysFileDirL, 0)
|
||||||
for j := 0; j < len(listGroup); j++ {
|
for j := 0; j < len(listGroup); j++ {
|
||||||
if m.ID != listGroup[j].PId {
|
if m.Id != listGroup[j].PId {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mi := models.SysFileDirL{}
|
mi := models.SysFileDirL{}
|
||||||
mi.ID = listGroup[j].ID
|
mi.Id = listGroup[j].Id
|
||||||
mi.PId = listGroup[j].PId
|
mi.PId = listGroup[j].PId
|
||||||
mi.Label = listGroup[j].Label
|
mi.Label = listGroup[j].Label
|
||||||
//mi.Sort = listGroup[j].Sort
|
//mi.Sort = listGroup[j].Sort
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"go-admin/app/admin/models"
|
||||||
|
"go-admin/common/actions"
|
||||||
|
cDto "go-admin/common/dto"
|
||||||
|
"go-admin/common/log"
|
||||||
|
"go-admin/app/admin/service/dto"
|
||||||
|
"go-admin/common/service"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SysChinaAreaData struct {
|
||||||
|
service.Service
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSysChinaAreaDataPage 获取SysChinaAreaData列表
|
||||||
|
func (e *SysChinaAreaData) GetSysChinaAreaDataPage(c *dto.SysChinaAreaDataSearch, p *actions.DataPermission, list *[]models.SysChinaAreaData, count *int64) error {
|
||||||
|
var err error
|
||||||
|
var data models.SysChinaAreaData
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
err = e.Orm.Model(&data).
|
||||||
|
Scopes(
|
||||||
|
cDto.MakeCondition(c.GetNeedSearch()),
|
||||||
|
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
||||||
|
actions.Permission(data.TableName(), p),
|
||||||
|
).
|
||||||
|
Find(list).Limit(-1).Offset(-1).
|
||||||
|
Count(count).Error
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSysChinaAreaData 获取SysChinaAreaData对象
|
||||||
|
func (e *SysChinaAreaData) GetSysChinaAreaData(d *dto.SysChinaAreaDataById, p *actions.DataPermission, model *models.SysChinaAreaData) error {
|
||||||
|
var err error
|
||||||
|
var data models.SysChinaAreaData
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
db := e.Orm.Model(&data).
|
||||||
|
Scopes(
|
||||||
|
actions.Permission(data.TableName(), p),
|
||||||
|
).
|
||||||
|
First(model, d.GetId())
|
||||||
|
err = db.Error
|
||||||
|
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
err = errors.New("查看对象不存在或无权查看")
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if db.Error != nil {
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// InsertSysChinaAreaData 创建SysChinaAreaData对象
|
||||||
|
func (e *SysChinaAreaData) InsertSysChinaAreaData(model *models.SysChinaAreaData) error {
|
||||||
|
var err error
|
||||||
|
var data models.SysChinaAreaData
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
err = e.Orm.Model(&data).
|
||||||
|
Create(model).Error
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateSysChinaAreaData 修改SysChinaAreaData对象
|
||||||
|
func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *models.SysChinaAreaData, p *actions.DataPermission) error {
|
||||||
|
var err error
|
||||||
|
var data models.SysChinaAreaData
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
db := e.Orm.Model(&data).
|
||||||
|
Scopes(
|
||||||
|
actions.Permission(data.TableName(), p),
|
||||||
|
).Where(c.GetId()).Updates(c)
|
||||||
|
if db.Error != nil {
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if db.RowsAffected == 0 {
|
||||||
|
return errors.New("无权更新该数据")
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveSysChinaAreaData 删除SysChinaAreaData
|
||||||
|
func (e *SysChinaAreaData) RemoveSysChinaAreaData(d *dto.SysChinaAreaDataById, p *actions.DataPermission) error {
|
||||||
|
var err error
|
||||||
|
var data models.SysChinaAreaData
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
db := e.Orm.Model(&data).
|
||||||
|
Scopes(
|
||||||
|
actions.Permission(data.TableName(), p),
|
||||||
|
).Delete(&data, d.GetId())
|
||||||
|
if db.Error != nil {
|
||||||
|
err = db.Error
|
||||||
|
log.Errorf("MsgID[%s] Delete error: %s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if db.RowsAffected == 0 {
|
||||||
|
err = errors.New("无权删除该数据")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -29,9 +29,9 @@ func _1599190683670Test(db *gorm.DB, version string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
list4 := []system.SysConfig{
|
list4 := []system.SysConfig{
|
||||||
{Model: common.Model{ID: 1}, ModelTime: common.ModelTime{CreatedAt: time.Now(), UpdatedAt: time.Now()}, ControlBy: common.ControlBy{CreateBy: 1, UpdateBy: 1}, ConfigName: "主框架页-默认皮肤样式名称", ConfigKey: "sys_index_skinName", ConfigValue: "skin-blue", ConfigType: "Y", Remark: "蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow"},
|
{Model: common.Model{Id: 1}, ModelTime: common.ModelTime{CreatedAt: time.Now(), UpdatedAt: time.Now()}, ControlBy: common.ControlBy{CreateBy: 1, UpdateBy: 1}, ConfigName: "主框架页-默认皮肤样式名称", ConfigKey: "sys_index_skinName", ConfigValue: "skin-blue", ConfigType: "Y", Remark: "蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow"},
|
||||||
{Model: common.Model{ID: 2}, ModelTime: common.ModelTime{CreatedAt: time.Now(), UpdatedAt: time.Now()}, ControlBy: common.ControlBy{CreateBy: 1, UpdateBy: 1}, ConfigName: "用户管理-账号初始密码", ConfigKey: "sys.user.initPassword", ConfigValue: "123456", ConfigType: "Y", Remark: "初始化密码 123456"},
|
{Model: common.Model{Id: 2}, ModelTime: common.ModelTime{CreatedAt: time.Now(), UpdatedAt: time.Now()}, ControlBy: common.ControlBy{CreateBy: 1, UpdateBy: 1}, ConfigName: "用户管理-账号初始密码", ConfigKey: "sys.user.initPassword", ConfigValue: "123456", ConfigType: "Y", Remark: "初始化密码 123456"},
|
||||||
{Model: common.Model{ID: 3}, ModelTime: common.ModelTime{CreatedAt: time.Now(), UpdatedAt: time.Now()}, ControlBy: common.ControlBy{CreateBy: 1, UpdateBy: 1}, ConfigName: "主框架页-侧边栏主题", ConfigKey: "sys_index_sideTheme", ConfigValue: "theme-dark", ConfigType: "Y", Remark: "深色主题theme-dark,浅色主题theme-light"},
|
{Model: common.Model{Id: 3}, ModelTime: common.ModelTime{CreatedAt: time.Now(), UpdatedAt: time.Now()}, ControlBy: common.ControlBy{CreateBy: 1, UpdateBy: 1}, ConfigName: "主框架页-侧边栏主题", ConfigKey: "sys_index_sideTheme", ConfigValue: "theme-dark", ConfigType: "Y", Remark: "深色主题theme-dark,浅色主题theme-light"},
|
||||||
}
|
}
|
||||||
|
|
||||||
list5 := []models.Post{
|
list5 := []models.Post{
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ func (e *ControlBy) SetUpdateBy(updateBy int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Model struct {
|
type Model struct {
|
||||||
ID int `json:"id" gorm:"primaryKey;autoIncrement;comment:主键编码"`
|
Id int `json:"id" gorm:"primaryKey;autoIncrement;comment:主键编码"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ModelTime struct {
|
type ModelTime struct {
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ require (
|
|||||||
gorm.io/driver/postgres v1.0.6-0.20201208020313-1ed927cfab53
|
gorm.io/driver/postgres v1.0.6-0.20201208020313-1ed927cfab53
|
||||||
gorm.io/driver/sqlite v1.1.5-0.20201206014648-c84401fbe3ba
|
gorm.io/driver/sqlite v1.1.5-0.20201206014648-c84401fbe3ba
|
||||||
gorm.io/gorm v1.20.12
|
gorm.io/gorm v1.20.12
|
||||||
gorm.io/plugin/dbresolver v1.1.0
|
|
||||||
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0
|
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0
|
||||||
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 // indirect
|
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ func (s *{{.ClassName}}Control) Generate() (*models.{{.ClassName}}, error) {
|
|||||||
{{ range .Columns -}}
|
{{ range .Columns -}}
|
||||||
{{$x := .Pk}}
|
{{$x := .Pk}}
|
||||||
{{- if ($x) }}
|
{{- if ($x) }}
|
||||||
Model: gorm.Model{ID: s.ID},
|
Model: common.Model{ {{.GoField}}: s.{{.GoField}} },
|
||||||
{{- else if eq .GoField "CreatedAt" -}}
|
{{- else if eq .GoField "CreatedAt" -}}
|
||||||
{{- else if eq .GoField "UpdatedAt" -}}
|
{{- else if eq .GoField "UpdatedAt" -}}
|
||||||
{{- else if eq .GoField "DeletedAt" -}}
|
{{- else if eq .GoField "DeletedAt" -}}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type {{.ClassName}} struct {
|
type {{.ClassName}} struct {
|
||||||
gorm.Model
|
models.Model
|
||||||
models.ControlBy
|
models.ControlBy
|
||||||
{{ range .Columns -}}
|
{{ range .Columns -}}
|
||||||
{{$x := .Pk}}
|
{{$x := .Pk}}
|
||||||
|
|||||||
Reference in New Issue
Block a user