mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-15 13:43:48 +08:00
fix 优化deleted_by字段的crud生成功能
fix 优化数据`hotgo.sql`文件字段默认值和初始数据 fix 修复web端字典空数据可能引发的潜在问题
This commit is contained in:
@@ -33,6 +33,7 @@ type SysGenCurdDemoColumns struct {
|
||||
Status string // 状态
|
||||
CreatedBy string // 创建者
|
||||
UpdatedBy string // 更新者
|
||||
DeletedBy string // 删除者
|
||||
CreatedAt string // 创建时间
|
||||
UpdatedAt string // 修改时间
|
||||
DeletedAt string // 删除时间
|
||||
@@ -53,6 +54,7 @@ var sysGenCurdDemoColumns = SysGenCurdDemoColumns{
|
||||
Status: "status",
|
||||
CreatedBy: "created_by",
|
||||
UpdatedBy: "updated_by",
|
||||
DeletedBy: "deleted_by",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
DeletedAt: "deleted_at",
|
||||
|
||||
@@ -34,6 +34,7 @@ var defaultEditSwitch = map[string]bool{
|
||||
"tree": false,
|
||||
"created_by": false,
|
||||
"updated_by": false,
|
||||
"deleted_by": false,
|
||||
"created_at": false,
|
||||
"updated_at": false,
|
||||
"deleted_at": false,
|
||||
|
||||
@@ -256,7 +256,7 @@ func IsSelectFormMode(formMode string) bool {
|
||||
|
||||
func HasColumn(fields []*sysin.GenCodesColumnListModel, column string) bool {
|
||||
for _, field := range fields {
|
||||
if field.GoName == column {
|
||||
if field.Name == column {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -273,14 +273,14 @@ func HasColumnWithFormMode(fields []*sysin.GenCodesColumnListModel, formMode str
|
||||
}
|
||||
|
||||
func HasMaxSort(fields []*sysin.GenCodesColumnListModel) bool {
|
||||
return HasColumn(fields, "Sort")
|
||||
return HasColumn(fields, "sort")
|
||||
}
|
||||
|
||||
func HasStatus(headOps []string, fields []*sysin.GenCodesColumnListModel) bool {
|
||||
if !gstr.InArray(headOps, "status") {
|
||||
return false
|
||||
}
|
||||
return HasColumn(fields, "Status")
|
||||
return HasColumn(fields, "status")
|
||||
}
|
||||
|
||||
func HasSwitch(fields []*sysin.GenCodesColumnListModel) bool {
|
||||
|
||||
@@ -23,6 +23,7 @@ const (
|
||||
LogicEditUnique = "\t// 验证'%s'唯一\n\tif err = hgorm.IsUnique(ctx, &dao.%s, g.Map{dao.%s.Columns().%s: in.%s}, \"%s已存在\", in.Id); err != nil {\n\t\treturn\n\t}\n"
|
||||
LogicSwitchUpdate = "g.Map{\n\t\tin.Key: in.Value,\n%s}"
|
||||
LogicStatusUpdate = "g.Map{\n\t\tdao.%s.Columns().Status: in.Status,\n%s}"
|
||||
LogicDeletedUpdate = "g.Map{\n%s}"
|
||||
)
|
||||
|
||||
func (l *gCurd) logicTplData(ctx context.Context, in *CurdPreviewInput) (data g.Map, err error) {
|
||||
@@ -35,9 +36,31 @@ func (l *gCurd) logicTplData(ctx context.Context, in *CurdPreviewInput) (data g.
|
||||
data["switchFields"] = l.generateLogicSwitchFields(ctx, in)
|
||||
data["switchUpdate"] = l.generateLogicSwitchUpdate(ctx, in)
|
||||
data["statusUpdate"] = l.generateLogicStatusUpdate(ctx, in)
|
||||
data["deletedUpdate"] = l.generateLogicDeletedUpdate(ctx, in)
|
||||
return
|
||||
}
|
||||
|
||||
func (l *gCurd) generateLogicDeletedUpdate(ctx context.Context, in *CurdPreviewInput) string {
|
||||
isDestroy := false
|
||||
var update string
|
||||
for _, field := range in.masterFields {
|
||||
if field.GoName == "DeletedBy" {
|
||||
update += "\t\tdao." + in.In.DaoName + ".Columns().DeletedBy: contexts.GetUserId(ctx),\n"
|
||||
isDestroy = true
|
||||
}
|
||||
if field.GoName == "DeletedAt" {
|
||||
update += "\t\tdao." + in.In.DaoName + ".Columns().DeletedAt: gtime.Now(),\n"
|
||||
}
|
||||
}
|
||||
|
||||
if !isDestroy {
|
||||
return ""
|
||||
}
|
||||
|
||||
update += "\t"
|
||||
return fmt.Sprintf(LogicDeletedUpdate, update)
|
||||
}
|
||||
|
||||
func (l *gCurd) generateLogicStatusUpdate(ctx context.Context, in *CurdPreviewInput) string {
|
||||
var update string
|
||||
for _, field := range in.masterFields {
|
||||
|
||||
@@ -81,6 +81,7 @@ var MemberSummary = gdb.HookHandler{
|
||||
var (
|
||||
createdByIds []int64
|
||||
updatedByIds []int64
|
||||
deletedByIds []int64
|
||||
memberIds []int64
|
||||
)
|
||||
|
||||
@@ -91,6 +92,9 @@ var MemberSummary = gdb.HookHandler{
|
||||
if record["updated_by"].Int64() > 0 {
|
||||
updatedByIds = append(updatedByIds, record["updated_by"].Int64())
|
||||
}
|
||||
if record["deleted_by"].Int64() > 0 {
|
||||
deletedByIds = append(deletedByIds, record["deleted_by"].Int64())
|
||||
}
|
||||
if record["member_id"].Int64() > 0 {
|
||||
memberIds = append(memberIds, record["member_id"].Int64())
|
||||
}
|
||||
@@ -98,6 +102,7 @@ var MemberSummary = gdb.HookHandler{
|
||||
|
||||
memberIds = append(memberIds, createdByIds...)
|
||||
memberIds = append(memberIds, updatedByIds...)
|
||||
memberIds = append(memberIds, deletedByIds...)
|
||||
memberIds = convert.UniqueSlice(memberIds)
|
||||
if len(memberIds) == 0 {
|
||||
return
|
||||
@@ -128,6 +133,9 @@ var MemberSummary = gdb.HookHandler{
|
||||
if record["updated_by"].Int64() > 0 {
|
||||
record["updatedBySumma"] = gvar.New(findMember(record["updated_by"]))
|
||||
}
|
||||
if record["deleted_by"].Int64() > 0 {
|
||||
record["deletedBySumma"] = gvar.New(findMember(record["deleted_by"]))
|
||||
}
|
||||
if record["member_id"].Int64() > 0 {
|
||||
record["memberBySumma"] = gvar.New(findMember(record["member_id"]))
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
@@ -161,7 +162,10 @@ func (s *sSysCurdDemo) Edit(ctx context.Context, in *sysin.CurdDemoEditInp) (err
|
||||
// Delete 删除CURD列表
|
||||
func (s *sSysCurdDemo) Delete(ctx context.Context, in *sysin.CurdDemoDeleteInp) (err error) {
|
||||
|
||||
if _, err = s.Model(ctx).WherePri(in.Id).Delete(); err != nil {
|
||||
if _, err = s.Model(ctx).WherePri(in.Id).Data(g.Map{
|
||||
dao.SysGenCurdDemo.Columns().DeletedBy: contexts.GetUserId(ctx),
|
||||
dao.SysGenCurdDemo.Columns().DeletedAt: gtime.Now(),
|
||||
}).Update(); err != nil {
|
||||
err = gerror.Wrap(err, "删除CURD列表失败,请稍后重试!")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ type SysGenCurdDemo struct {
|
||||
Status interface{} // 状态
|
||||
CreatedBy interface{} // 创建者
|
||||
UpdatedBy interface{} // 更新者
|
||||
DeletedBy interface{} // 删除者
|
||||
CreatedAt *gtime.Time // 创建时间
|
||||
UpdatedAt *gtime.Time // 修改时间
|
||||
DeletedAt *gtime.Time // 删除时间
|
||||
|
||||
@@ -23,6 +23,7 @@ type SysGenCurdDemo struct {
|
||||
Status int `json:"status" orm:"status" description:"状态"`
|
||||
CreatedBy int64 `json:"createdBy" orm:"created_by" description:"创建者"`
|
||||
UpdatedBy int64 `json:"updatedBy" orm:"updated_by" description:"更新者"`
|
||||
DeletedBy int64 `json:"deletedBy" orm:"deleted_by" description:"删除者"`
|
||||
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"`
|
||||
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"修改时间"`
|
||||
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"删除时间"`
|
||||
|
||||
@@ -27,8 +27,8 @@ type CurdDemoUpdateFields struct {
|
||||
Image string `json:"image" dc:"单图"`
|
||||
Attachfile string `json:"attachfile" dc:"附件"`
|
||||
CityId int64 `json:"cityId" dc:"所在城市"`
|
||||
Sort int `json:"sort" dc:"排序"`
|
||||
Switch int `json:"switch" dc:"显示开关"`
|
||||
Sort int `json:"sort" dc:"排序"`
|
||||
UpdatedBy int64 `json:"updatedBy" dc:"更新者"`
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ type CurdDemoInsertFields struct {
|
||||
Image string `json:"image" dc:"单图"`
|
||||
Attachfile string `json:"attachfile" dc:"附件"`
|
||||
CityId int64 `json:"cityId" dc:"所在城市"`
|
||||
Sort int `json:"sort" dc:"排序"`
|
||||
Switch int `json:"switch" dc:"显示开关"`
|
||||
Sort int `json:"sort" dc:"排序"`
|
||||
CreatedBy int64 `json:"createdBy" dc:"创建者"`
|
||||
}
|
||||
|
||||
@@ -123,13 +123,13 @@ type CurdDemoListModel struct {
|
||||
Description string `json:"description" dc:"描述"`
|
||||
Image string `json:"image" dc:"单图"`
|
||||
Attachfile string `json:"attachfile" dc:"附件"`
|
||||
Sort int `json:"sort" dc:"排序"`
|
||||
Switch int `json:"switch" dc:"显示开关"`
|
||||
Sort int `json:"sort" dc:"排序"`
|
||||
CreatedBy int64 `json:"createdBy" dc:"创建者"`
|
||||
CreatedBySumma *hook.MemberSumma `json:"createdBySumma" dc:"创建者摘要信息"`
|
||||
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
|
||||
UpdatedBy int64 `json:"updatedBy" dc:"更新者"`
|
||||
UpdatedBySumma *hook.MemberSumma `json:"updatedBySumma" dc:"更新者摘要信息"`
|
||||
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
|
||||
UpdatedAt *gtime.Time `json:"updatedAt" dc:"修改时间"`
|
||||
TestCategoryName string `json:"testCategoryName" dc:"关联分类"`
|
||||
}
|
||||
@@ -142,11 +142,11 @@ type CurdDemoExportModel struct {
|
||||
Image string `json:"image" dc:"单图"`
|
||||
Attachfile string `json:"attachfile" dc:"附件"`
|
||||
CityId int64 `json:"cityId" dc:"所在城市"`
|
||||
Sort int `json:"sort" dc:"排序"`
|
||||
Switch int `json:"switch" dc:"显示开关"`
|
||||
Sort int `json:"sort" dc:"排序"`
|
||||
CreatedBy int64 `json:"createdBy" dc:"创建者"`
|
||||
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
|
||||
UpdatedBy int64 `json:"updatedBy" dc:"更新者"`
|
||||
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
|
||||
TestCategoryName string `json:"testCategoryName" dc:"关联分类"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user