-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
627 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package system | ||
|
||
import ( | ||
"anew-server/dto/request" | ||
"anew-server/dto/response" | ||
"anew-server/dto/service" | ||
"anew-server/pkg/common" | ||
"anew-server/pkg/utils" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// 查询所有字典 | ||
func GetDicts(c *gin.Context) { | ||
// 绑定参数 | ||
var req request.DictListReq | ||
err := c.Bind(&req) | ||
if err != nil { | ||
response.FailWithCode(response.ParmError) | ||
return | ||
} | ||
// 创建服务 | ||
s := service.New() | ||
dicts := s.GetDicts(&req) | ||
if req.Key != "" || req.Value != "" || req.Status != nil || req.TypeKey != "" { | ||
var newResp []response.DictTreeResp | ||
utils.Struct2StructByJson(dicts, &newResp) | ||
response.SuccessWithData(newResp) | ||
} else { | ||
var resp []response.DictTreeResp | ||
resp = service.GenDictTree(nil, dicts) | ||
response.SuccessWithData(resp) | ||
} | ||
} | ||
|
||
// 创建字典 | ||
func CreateDict(c *gin.Context) { | ||
user := GetCurrentUser(c) | ||
// 绑定参数 | ||
var req request.CreateDictReq | ||
err := c.Bind(&req) | ||
if err != nil { | ||
response.FailWithCode(response.ParmError) | ||
return | ||
} | ||
|
||
// 参数校验 | ||
err = common.NewValidatorError(common.Validate.Struct(req), req.FieldTrans()) | ||
if err != nil { | ||
response.FailWithMsg(err.Error()) | ||
return | ||
} | ||
// 记录当前创建人信息 | ||
req.Creator = user.Name | ||
// 创建服务 | ||
s := service.New() | ||
err = s.CreateDict(&req) | ||
if err != nil { | ||
response.FailWithMsg(err.Error()) | ||
return | ||
} | ||
response.Success() | ||
} | ||
|
||
// 更新字典 | ||
func UpdateDictById(c *gin.Context) { | ||
// 绑定参数 | ||
var req request.UpdateDictReq | ||
err := c.Bind(&req) | ||
if err != nil { | ||
response.FailWithCode(response.ParmError) | ||
return | ||
} | ||
DictId := utils.Str2Uint(c.Param("DictId")) | ||
if DictId == 0 { | ||
response.FailWithMsg("字典编号不正确") | ||
return | ||
} | ||
// 创建服务 | ||
s := service.New() | ||
// 更新数据 | ||
err = s.UpdateDictById(DictId, req) | ||
if err != nil { | ||
response.FailWithMsg(err.Error()) | ||
return | ||
} | ||
response.Success() | ||
} | ||
|
||
// 批量删除字典 | ||
func BatchDeleteDictByIds(c *gin.Context) { | ||
var req request.IdsReq | ||
err := c.Bind(&req) | ||
if err != nil { | ||
response.FailWithCode(response.ParmError) | ||
return | ||
} | ||
|
||
// 创建服务 | ||
s := service.New() | ||
// 删除数据 | ||
err = s.DeleteDictByIds(req.Ids) | ||
if err != nil { | ||
response.FailWithMsg(err.Error()) | ||
return | ||
} | ||
response.Success() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package request | ||
|
||
// 创建字典结构体 | ||
type CreateDictReq struct { | ||
Key string `json:"key" validate:"required"` | ||
Value string `json:"value" validate:"required"` | ||
Desc string `json:"desc"` | ||
ParentId uint `json:"parent_id"` | ||
Creator string `json:"creator"` | ||
} | ||
|
||
// 修改字典 | ||
type UpdateDictReq struct { | ||
Key string `json:"key" validate:"required"` | ||
Value string `json:"value" validate:"required"` | ||
Desc string `json:"desc"` | ||
ParentId uint `json:"parent_id"` | ||
Status *bool `json:"status"` | ||
} | ||
|
||
type DictListReq struct { | ||
Key string `json:"key" form:"key"` | ||
Value string `json:"value" form:"value"` | ||
Desc string `json:"desc" form:"desc"` | ||
Creator string `json:"creator" form:"creator"` | ||
Status *bool `json:"status" form:"status"` | ||
TypeKey string `json:"type_key" form:"type_key"` | ||
} | ||
|
||
// 翻译需要校验的字段名称 | ||
func (s CreateDictReq) FieldTrans() map[string]string { | ||
m := make(map[string]string, 0) | ||
m["Key"] = "字典Key" | ||
m["Value"] = "字典Value" | ||
return m | ||
} | ||
|
||
// 翻译需要校验的字段名称 | ||
func (s UpdateDictReq) FieldTrans() map[string]string { | ||
m := make(map[string]string, 0) | ||
m["Key"] = "字典Key" | ||
m["Value"] = "字典Value" | ||
return m | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package response | ||
|
||
// 字典树信息响应, | ||
|
||
type DictTreeResp struct { | ||
Id uint `json:"id"` | ||
ParentId uint `json:"parent_id"` | ||
Key string `json:"key"` | ||
Value string `json:"value"` | ||
Desc string `json:"desc"` | ||
Creator string `json:"creator"` | ||
Status bool `json:"status"` | ||
Children []DictTreeResp `json:"children,omitempty"` //tag:omitempty 为空的值不显示 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.